sync.order.cs 617 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. namespace SiteCore.Handler
  48. {
  49. public partial class sync
  50. {
  51. public void get_erp_orderlist()
  52. {
  53. string poscode = CurrentUser.UserPost.Post.Code;
  54. DataStruct dStruct = GetPostStruct();
  55. //apiHelper.Api_SyncOrderByTime("598825");
  56. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  57. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  58. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  59. //banniuApiHelper.sendLogisticsInfo(null);
  60. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  61. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  62. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  63. //int sid = commonHelper.autoDistributeToSupplier(entity);
  64. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  65. //tmcHelper.Api_TmcTradeMsg("{\r\n \"content\": {\r\n \"businessType\": \"GUARANTEE\",\r\n \"buyerMemo\": \"\",\r\n \"consolidateType\": \"\",\r\n \"createTime\": 1744882656361,\r\n \"deliveryType\": \"OFFLINE\",\r\n \"discountFee\": 0.0,\r\n \"flag\": \"NONE\",\r\n \"latestDeliveryTime\": 1744882656361,\r\n \"lines\": [\r\n {\r\n \"mark2\": [],\r\n \"num\": 4,\r\n \"outerId\": \"\",\r\n \"payment\": 60.0,\r\n \"picUrl\": \"https://img.alicdn.com/bao/uploaded/i4/2209226402185/O1CN011Zh53V1S0mQKgHJyF_!!4611686018427382153-0-item_pic.jpg\",\r\n \"platServiceFee\": 0.0,\r\n \"price\": 10.0,\r\n \"refOlId\": \"1111122222333338942\",\r\n \"refSkuId\": \"0\",\r\n \"refSpuId\": \"908453435193\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellPrice\": 10.0,\r\n \"singleFee\": 10.0,\r\n \"standards\": \"测试内部\",\r\n \"status\": \"NOT_SHIPPED\",\r\n \"title\": \"【老客户订单2】测试老客户订单内部\",\r\n \"totalFee\": 60.0,\r\n \"totalPrice\": 60.0,\r\n \"totalSellPrice\": 60.0\r\n }\r\n ],\r\n \"logisticsOrderNo\": \"\",\r\n \"mark2\": [],\r\n \"modifyTime\": 1744882656361,\r\n \"openBuyerId\": \"AAG1RHraABkUZRPgSx3g7Eam\",\r\n \"openBuyerNick\": \"0**\",\r\n \"openSellerNick\": \"海角七旗舰店\",\r\n \"orderSource\": \"SYNC\",\r\n \"orderTime\": 1744882656361,\r\n \"payTime\": 1744882656361,\r\n \"payment\": 100.0,\r\n \"platServiceFee\": 0.0,\r\n \"posCode\": \"HJQ\",\r\n \"posId\": 663281,\r\n \"postFee\": 0.0,\r\n \"props\": {\r\n \"payType\": \"ALI_PAY\",\r\n \"govSubsidyAmount\": 0\r\n },\r\n \"receivedPayment\": 0.0,\r\n \"receiverCity\": \"龙岩市\",\r\n \"receiverCountry\": \"中国\",\r\n \"receiverDistrict\": \"新罗区\",\r\n \"receiverId\": \"d1b65912ef886228ac4ada4b65055e52$\",\r\n \"receiverState\": \"福建省\",\r\n \"receiverTown\": \"西陂街道\",\r\n \"refOid\": \"1111122222333338942\",\r\n \"refType\": \"TB\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellerMemo\": \"\",\r\n \"serviceFee\": 0.0,\r\n \"status\": \"NOT_SHIPPED\",\r\n \"totalFee\": 100.0,\r\n \"totalPrice\": 100.0,\r\n \"totalSellPrice\": 100.0,\r\n \"type\": \"SALE\"\r\n }\r\n}");
  66. //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}}");
  67. /*string sql = "SELECT spuId,tid FROM [dbo].[CE_ErpTradeSpu] where isSync is null ";
  68. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  69. DataTable dataTable = dataSet == null ? new DataTable() : dataSet.Tables[0];
  70. foreach (DataRow dr in dataTable.Rows)
  71. {
  72. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByTid(dr["tid"].ToString());
  73. CeErpTradeOrder ceErpTradeOrder = CeErpTradeOrder.GetBySpuId(dr["spuId"].ToString());
  74. CeErpTradeSpu ceErpTradeSpu = CeErpTradeSpu.GetBySpuId(dr["spuId"].ToString());
  75. dataSendSpuBean bean = new dataSendSpuBean();
  76. bean.ShortText1728890680485 = ceErpTradeOrder.title;
  77. bean.ShortText1728890649488 = dr["spuId"].ToString();
  78. bean.shopId = ceErpTradeCell.ShopId.ToString();
  79. ceErpTradeSpu.shopId = ceErpTradeCell.ShopId;
  80. ceErpTradeSpu.isSync = false;
  81. bean.Date1728891156995 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  82. dataResponseVo response = dataHelper.sendSpuInfo(bean);
  83. if (response != null)
  84. {
  85. if ("0".Equals(response.errcode))
  86. {
  87. ceErpTradeSpu.isSync = true;
  88. }
  89. else
  90. {
  91. ceErpTradeSpu.message = response.errmsg;
  92. }
  93. }
  94. ceErpTradeSpu.Update();
  95. }*/
  96. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  97. List<string> lw = new List<string>();
  98. string tid = GetPostString("ctid");
  99. string date1 = GetPostString("date1");
  100. //12-1 修改
  101. string urgent = GetPostString("urgent");
  102. string back = GetPostString("back");
  103. string offlineSearch = GetPostString("offlineSearch");
  104. int paramsCount = 0;
  105. if (!string.IsNullOrWhiteSpace(urgent))
  106. {
  107. if (urgent.Equals("true"))
  108. {
  109. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  110. }
  111. }
  112. if (!string.IsNullOrWhiteSpace(back))
  113. {
  114. if (back.Equals("true"))
  115. {
  116. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  117. }
  118. }
  119. if (!string.IsNullOrWhiteSpace(offlineSearch))
  120. {
  121. if (offlineSearch.Equals("true"))
  122. {
  123. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  124. }
  125. }
  126. //end
  127. string date2 = GetPostString("date2");
  128. string buyernick = GetPostString("buyer_nick");
  129. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  130. {
  131. if (tid.Length <= 0 && buyernick.Length <= 0)
  132. {
  133. return;
  134. }
  135. }
  136. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  137. {
  138. if (tid.Length > 0)
  139. {
  140. string select_tid = getTidByCtid(tid);
  141. lw.Add(string.Format("tid='{0}'", select_tid));
  142. }
  143. if (buyernick.Length > 0)
  144. {
  145. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  146. }
  147. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  148. if (dw.Length > 0)
  149. {
  150. lw.Add(dw);
  151. }
  152. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  153. {
  154. string usershop = CurrentUser.User.pemShop;
  155. lw.Add(string.Format("ShopId in ({0})", usershop));
  156. }
  157. }
  158. else
  159. {
  160. if (ex_psize == 0)
  161. {
  162. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  163. }
  164. if (PKey != "admin")
  165. {
  166. string usershop = CurrentUser.User.pemShop;
  167. lw.Add(string.Format("ShopId in ({0})", usershop));
  168. paramsCount++;
  169. }
  170. }
  171. string uploaddate1 = GetPostString("uploaddate1");
  172. string uploaddate2 = GetPostString("uploaddate2");
  173. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  174. if (update.Length > 0) lw.Add(update);
  175. string deliverydate1 = GetPostString("deliverydate1");
  176. string deliverydate2 = GetPostString("deliverydate2");
  177. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  178. if (deliverydate.Length > 0)
  179. {
  180. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  181. };
  182. string shopname = GetPostString("shopname");
  183. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  184. string addwechat = GetPostString("addwechat");
  185. if (addwechat.Length > 0)
  186. {
  187. int addWt = Convert.ToInt32(addwechat);
  188. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  189. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  190. }
  191. string customer = GetPostString("customer");
  192. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  193. string design = GetPostString("design");
  194. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  195. string orderState = GetPostString("orderState");
  196. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  197. string address = GetPostString("address");
  198. 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));
  199. string sellermemo = GetPostString("seller_memo");
  200. if (sellermemo.Length > 0)
  201. {
  202. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  203. }
  204. string backReason = GetPostString("backReason");
  205. if (backReason.Length > 0)
  206. {
  207. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  208. }
  209. string apdate1 = GetPostString("apdate1");
  210. string apdate2 = GetPostString("apdate2");
  211. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  212. if (dwap.Length > 0) lw.Add(dwap);
  213. string price1 = GetPostString("price1");
  214. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  215. string price2 = GetPostString("price2");
  216. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  217. string isoldcustomer = GetPostString("isoldcus");
  218. string spudata = GetPostString("spudata");
  219. if ("0".Equals(spudata))
  220. {
  221. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  222. }
  223. if ("1".Equals(spudata))
  224. {
  225. lw.Add(string.Format("spu_id <> ''"));
  226. }
  227. string finishdate1 = GetPostString("finishdate1");
  228. string finishdate2 = GetPostString("finishdate2");
  229. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  230. bool isFinish = false;
  231. if (finishdate.Length > 0)
  232. {
  233. lw.Add(finishdate);
  234. isFinish = true;
  235. paramsCount++;
  236. }
  237. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  238. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  239. if (ex_psize > 0)
  240. {
  241. int UserID = CurrentUser.UserID;
  242. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  243. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  244. {
  245. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  246. }
  247. dStruct.Order = "pay_time desc";
  248. }
  249. string isNew = GetPostString("isNew");
  250. if (isNew == "true")
  251. {
  252. lw.Add(string.Format("IsNew = {0}", 1));
  253. }
  254. string overtime = GetPostString("overtime");
  255. if (overtime == "1")
  256. {
  257. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  258. }
  259. String usePost = CurrentUser.UserPost.Post.Code;
  260. if (usePost.Equals("Operation") == true)
  261. {
  262. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  263. }
  264. else
  265. {
  266. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  267. }
  268. //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";
  269. if (dStruct.PageSize == 100000)
  270. {
  271. dStruct.Order = "";
  272. }
  273. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  274. DataTable dt = null;
  275. string tablename = "view_orderlist";
  276. if (isFinish)
  277. {
  278. tablename = "view_orderlist_end";
  279. }
  280. dt = WebCache.GetData(tablename, dStruct);
  281. if (dt != null && dt.Rows.Count > 0)
  282. {
  283. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  284. foreach (DataRow dr in dt.Rows)
  285. {
  286. try
  287. {
  288. if (dr["refund_fees"] != null)
  289. {
  290. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  291. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  292. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  293. if (payment == refund_fees)
  294. {
  295. dr["refund_fees"] = Math.Round(refund_fees, 2);
  296. }
  297. else if (refund_fees == total_fee)
  298. {
  299. dr["refund_fees"] = payment;
  300. }
  301. else
  302. {
  303. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  304. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  305. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  306. }
  307. }
  308. // 对象操作
  309. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  310. ceErpTradeCell.ctid = dr["ctid"].ToString();
  311. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  312. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  313. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  314. if (dStruct.PageSize != 100000)
  315. {
  316. if (dr["DispatchSort"].ToString() == "2")
  317. {
  318. dr["gongchuang"] = 200;
  319. }
  320. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  321. {
  322. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  323. dr["gongchuang"] = response.code;
  324. }
  325. }
  326. }
  327. catch (NullReferenceException ex)
  328. {
  329. // 处理空引用异常
  330. dr["refund_fees"] = "0.00";
  331. }
  332. }
  333. }
  334. writeGridDataTableJson(dStruct.TotalCount, dt);
  335. }
  336. public void get_erp_orderlist_sumprice()
  337. {
  338. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  339. return;
  340. List<string> lw = new List<string>();
  341. string tid = GetPostString("ctid");
  342. string date1 = GetPostString("date1");
  343. string date2 = GetPostString("date2");
  344. if (tid.Length > 0 || date1.Length > 0)
  345. {
  346. lw.Add(string.Format("ctid like '%{0}%'", tid));
  347. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  348. if (dw.Length > 0) lw.Add(dw);
  349. }
  350. else
  351. {
  352. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  353. }
  354. string shopname = GetPostString("shopname");
  355. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  356. string buyernick = GetPostString("buyer_nick");
  357. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  358. string customer = GetPostString("customer");
  359. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  360. string design = GetPostString("design");
  361. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  362. string orderState = GetPostString("orderState");
  363. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  364. string address = GetPostString("address");
  365. 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));
  366. string sellermemo = GetPostString("seller_memo");
  367. if (sellermemo.Length > 0)
  368. {
  369. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  370. }
  371. string apdate1 = GetPostString("apdate1");
  372. string apdate2 = GetPostString("apdate2");
  373. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  374. if (dwap.Length > 0) lw.Add(dwap);
  375. string price1 = GetPostString("price1");
  376. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  377. string price2 = GetPostString("price2");
  378. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  379. string isoldcustomer = GetPostString("isoldcus");
  380. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  381. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  382. if (PKey != "admin")
  383. {
  384. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  385. lw.Add(string.Format("shopId in ({0})", usershop));
  386. }
  387. //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";
  388. string mainWhere = string.Join(" and ", lw.ToArray());
  389. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  390. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  391. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  392. decimal total = 0;
  393. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  394. {
  395. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  396. }
  397. var res = new
  398. {
  399. data = total
  400. };
  401. string ro_jsond = JsonConvert.SerializeObject(res);
  402. returnSuccess(ro_jsond);
  403. return;
  404. }
  405. public void get_erp_CustomerServiceGather()
  406. {
  407. string userWhere = "", orderWhere = "";
  408. List<string> lw = new List<string>();
  409. string customer = GetPostString("customer");
  410. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  411. string shopname = GetPostString("shopname");
  412. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  413. string date1 = GetPostString("date1");
  414. string date2 = GetPostString("date2");
  415. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  416. if (dw.Length > 0) lw.Add(dw);
  417. orderWhere = string.Join(" and ", lw.ToArray());
  418. 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 " +
  419. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  420. "left join " +
  421. "( " +
  422. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  423. ") as b on a.ID = b.CustomerUserId " +
  424. "left join " +
  425. "( " +
  426. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  427. ") as d on a.ID = d.CustomerUserId " +
  428. "left join " +
  429. "( " +
  430. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  431. ") as e on a.ID = e.CustomerUserId " +
  432. "left join " +
  433. "( " +
  434. " select CustomerUserId, RefundCount, RefundSum from " +
  435. " ( " +
  436. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  437. " from CE_ErpTradeRefund a " +
  438. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  439. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  440. " group by CustomerUserId " +
  441. " ) as a " +
  442. ") as f on a.ID = f.CustomerUserId " +
  443. "where a.PostCode = 'CustomerService'",
  444. userWhere, orderWhere);
  445. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  446. writeGridDataTableJson(dt.Rows.Count, dt);
  447. //writeGridDataTableJson(dt.Rows.Count, dt);
  448. }
  449. //设计汇总
  450. public void get_erp_DesignerGather()
  451. {
  452. string userWhere = "", orderWhere = "";
  453. List<string> lw = new List<string>();
  454. string Designer = GetPostString("designer");
  455. int org = GetPostInt("org");
  456. if (Designer.Length > 0)
  457. {
  458. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  459. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  460. }
  461. else if (org > 0)
  462. {
  463. userWhere = string.Format(" where OrgID ={0}", org);
  464. }
  465. string shopname = GetPostString("shopname");
  466. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  467. string state = GetPostString("state");
  468. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  469. string OrderArea = GetPostString("order_area");
  470. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  471. string date1 = GetPostString("date1");
  472. string date2 = GetPostString("date2");
  473. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  474. if (dw.Length > 0) lw.Add(dw);
  475. string UpDate1 = GetPostString("UpDate1");
  476. string UpDate2 = GetPostString("UpDate2");
  477. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  478. if (dw.Length > 0) lw.Add(dw);
  479. orderWhere = string.Join(" and ", lw.ToArray());
  480. 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 (" +
  481. "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 " +
  482. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  483. "left join " +
  484. "( " +
  485. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  486. ") as b on a.ID = b.DesignUserId " +
  487. "left join " +
  488. "( " +
  489. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  490. ") as d on a.ID = d.DesignUserId " +
  491. "left join " +
  492. "( " +
  493. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  494. ") as e on a.ID = e.DesignUserId " +
  495. "left join " +
  496. "( " +
  497. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  498. ") as g on a.ID = g.DesignUserId " +
  499. "left join " +
  500. "( " +
  501. " select CustomerUserId, RefundCount, RefundSum from " +
  502. " ( " +
  503. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  504. " from CE_ErpTradeRefund a " +
  505. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  506. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  507. " group by CustomerUserId " +
  508. " ) as a " +
  509. ") as f on a.ID = f.CustomerUserId " +
  510. "where a.PostCode = 'Designer') as z",
  511. userWhere, orderWhere);
  512. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  513. writeGridDataTableJson(dt.Rows.Count, dt);
  514. }
  515. //删除tradecell的订单
  516. public void del_erp_cellorder()
  517. {
  518. if (UrlPostParmsCheck("ctid"))
  519. {
  520. string eid = GetPostString("ctid");
  521. CeErpTradeCell.DelByCtid(eid);
  522. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  523. returnSuccessMsg("删除成功");
  524. }
  525. }
  526. public void clear_erp_refundstate()
  527. {
  528. if (UrlPostParmsCheck("ids"))
  529. {
  530. string eids = GetPostString("ids");
  531. string[] ctidList = eids.Split(',');
  532. foreach (string ctid in ctidList)
  533. {
  534. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  535. if (entity != null)
  536. {
  537. entity.IsRefund = 0;
  538. entity.Update();
  539. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  540. }
  541. else
  542. continue;
  543. }
  544. returnSuccessMsg("操作成功");
  545. return;
  546. }
  547. returnErrorMsg("缺少必要参数");
  548. }
  549. public void set_erp_urgency()
  550. {
  551. if (UrlPostParmsCheck("ctid"))
  552. {
  553. string eid = GetPostString("ctid");
  554. CeErpTradeCell entity = null;
  555. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  556. if (entity != null)
  557. {
  558. string utime = GetPostString("urgencytime");
  559. if (utime.Length > 0)
  560. {
  561. entity.UrgencyTime = Convert.ToDateTime(utime);
  562. }
  563. else
  564. {
  565. returnErrorMsg("请选择加急时间");
  566. return;
  567. }
  568. if (entity.OrderState <= 4)
  569. {
  570. //entity.seller_memo = entity.seller_memo + "-加急";
  571. string smemo = entity.seller_memo;
  572. int kindex = smemo.IndexOf(")");
  573. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  574. if (lastoneStr != "-")
  575. {
  576. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  577. }
  578. string prememo = smemo.Substring(0, kindex + 2);
  579. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  580. int lastkindex = lastmemo.IndexOf("(");
  581. DateTime urgtime = Convert.ToDateTime(utime);
  582. string newlastmemo = "";
  583. if (lastkindex == 0)
  584. {
  585. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  586. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  587. }
  588. else
  589. {
  590. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  591. }
  592. entity.seller_memo = prememo + newlastmemo;
  593. }
  594. entity.IsUrgency = true;
  595. entity.UpdateTime = DateTime.Now;
  596. entity.Update();
  597. ApiVo apiVo = new ApiVo();
  598. apiVo.orderNumber = entity.ctid;
  599. apiVo.actionName = "changeDesign";
  600. apiVo.orderRemarks = entity.seller_memo;
  601. apiVo.remarkSign = 3;
  602. designHelper.API_WorkCore(apiVo); //changeDesign
  603. CeErpSukuraData.createInfo(entity.ctid, 7);
  604. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  605. returnSuccessMsg("设置成功!");
  606. return;
  607. }
  608. returnErrorMsg("找不到记录");
  609. }
  610. }
  611. public void set_erp_reset()
  612. {
  613. if (UrlPostParmsCheck("ctid"))
  614. {
  615. string eid = GetPostString("ctid");
  616. CeErpTradeCell entity = null;
  617. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  618. if (entity != null)
  619. {
  620. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  621. {
  622. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  623. {
  624. returnErrorMsg("财务要求已下单已发货无法重置");
  625. return;
  626. }
  627. }
  628. entity.IsUrgency = false;
  629. entity.seller_memo = "";
  630. entity.OtherMemo = "";
  631. entity.OrderState = 0;
  632. entity.IsReturn = 0;
  633. //entity.IsRefund = 0;
  634. entity.MemoOpt = 0;
  635. entity.AfterSaleState = 0;
  636. entity.AfterSaleResponsible = "";
  637. entity.AfterSaleUserId = 0;
  638. entity.IsNeedBill = 0;
  639. entity.CustomerUserId = 0;
  640. entity.DesignUserId = 0;
  641. entity.SupplierId = 0;
  642. entity.PlaceUserId = 0;
  643. entity.ptid = "";
  644. entity.IsSample = 0;
  645. entity.IsXianHuo = 0;
  646. entity.isDianziOrder = 0;
  647. entity.DispatchSort = 0;
  648. entity.FinishPlaceTime = null;
  649. entity.Update();
  650. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  651. if (trade != null)
  652. {
  653. trade.seller_memo = "";
  654. trade.Update();
  655. }
  656. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  657. returnSuccessMsg("重置成功!");
  658. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  659. if (desginBill != null)
  660. {
  661. desginBill.isDel = 1;
  662. desginBill.Update();
  663. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  664. }
  665. ApiVo apiVo = new ApiVo();
  666. apiVo.orderNumber = entity.ctid;
  667. apiVo.actionName = "resetDesign";
  668. designHelper.API_WorkCore(apiVo);//resetDesign
  669. return;
  670. }
  671. returnErrorMsg("找不到记录");
  672. }
  673. }
  674. public void save_erp_sellermemo()
  675. {
  676. if (UrlPostParmsCheck("ctid"))
  677. {
  678. string ctid = GetPostString("ctid");
  679. CeErpTradeCell entity = null;
  680. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  681. if (entity != null)
  682. {
  683. string memo = GetPostString("seller_memo");
  684. memo = memo.Replace(" ", "");
  685. if (memo.Contains("补差"))
  686. {
  687. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  688. return;
  689. }
  690. if (entity.seller_memo != memo)
  691. {
  692. if (entity.IsSample == 2)
  693. {
  694. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  695. return;
  696. }
  697. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  698. {
  699. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  700. {
  701. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  702. return;
  703. }
  704. }
  705. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  706. }
  707. commonHelper.getCytPrice(entity);
  708. int memoopt = GetPostInt("MemoOpt");
  709. Boolean ismemoopt = false;
  710. if (memoopt > 0)
  711. {
  712. string stropt = "";
  713. if (memoopt == 1)
  714. {
  715. stropt = "“改稿”";
  716. ismemoopt = true;
  717. }
  718. else if (memoopt == 2)
  719. {
  720. stropt = "“定稿”";
  721. }
  722. else if (memoopt == 3)
  723. {
  724. stropt = "“查货”";
  725. CeErpSukuraData.createInfo(entity.ctid, 6);
  726. }
  727. entity.MemoOpt = Convert.ToInt32(memoopt);
  728. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  729. }
  730. if (entity.OrderState < 5)
  731. {
  732. memo = memo.Replace("(", "(");
  733. memo = memo.Replace(")", ")");
  734. }
  735. entity.DispatchSort = 0;
  736. entity.seller_memo = memo;
  737. entity.UpdateTime = DateTime.Now;
  738. entity.Update();
  739. ApiVo apiVo = new ApiVo();
  740. apiVo.orderNumber = entity.ctid;
  741. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  742. apiVo.orderRemarks = memo;
  743. apiVo.remarkSign = memoopt;
  744. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  745. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  746. returnSuccessMsg("保存成功!");
  747. return;
  748. }
  749. returnErrorMsg("找不到记录");
  750. }
  751. }
  752. public void ins_erp_checkorder()
  753. {
  754. if (UrlPostParmsCheck("ctid"))
  755. {
  756. string ctid = GetPostString("ctid");
  757. CeErpTradeCell entity = null;
  758. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  759. if (entity != null)
  760. {
  761. if (entity.OrderState < 6)
  762. {
  763. returnErrorMsg("下单完成后才可查货");
  764. return;
  765. }
  766. /*if (entity.OrderState > 6)
  767. {
  768. returnErrorMsg("订单已发货");
  769. return;
  770. }*/
  771. if (entity.FinishPlaceTime != null)
  772. {
  773. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  774. {
  775. returnErrorMsg("下单时间不足,无法查货");
  776. return;
  777. }
  778. }
  779. entity.MemoOpt = 3;
  780. entity.CheckOrderTime = DateTime.Now;
  781. entity.UpdateTime = DateTime.Now;
  782. entity.Update();
  783. CeErpSukuraData.createInfo(entity.ctid, 6);
  784. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  785. returnSuccessMsg("操作成功!");
  786. return;
  787. }
  788. returnErrorMsg("找不到记录");
  789. }
  790. }
  791. public void save_erp_othermemo()
  792. {
  793. if (UrlPostParmsCheck("ctid"))
  794. {
  795. string ctid = GetPostString("ctid");
  796. CeErpTradeCell entity = null;
  797. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  798. if (entity != null)
  799. {
  800. entity.OtherMemo = GetPostString("otherMemo");
  801. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  802. {
  803. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  804. StringBuilder sql = new StringBuilder();
  805. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  806. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  807. if (dt != null && dt.Rows.Count > 0)
  808. {
  809. foreach (DataRow dr in dt.Rows)
  810. {
  811. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  812. {
  813. //品类一直
  814. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  815. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  816. if (ceErpSampleCustomer == null)
  817. {
  818. ceErpSampleCustomer = new CeErpSampleCustomer();
  819. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  820. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  821. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  822. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  823. ceErpSampleCustomer.shopId = entity.ShopId;
  824. }
  825. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  826. ceErpSampleCustomer.lastTid = entity.tid;
  827. if (ceErpSampleCustomer.ID > 0)
  828. {
  829. ceErpSampleCustomer.Update();
  830. }
  831. else
  832. {
  833. ceErpSampleCustomer.Create();
  834. }
  835. }
  836. }
  837. }
  838. }
  839. //if (entity.IsOldCustomer == 1)
  840. //{
  841. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  842. //{
  843. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  844. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  845. //}
  846. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  847. //{
  848. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  849. // {
  850. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  851. // {
  852. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  853. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  854. // }
  855. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  856. // {
  857. // entity.OrderState = 2;
  858. // entity.DesignUserId = 0;
  859. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  860. // }
  861. // else
  862. // {
  863. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  864. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  865. // }
  866. // }
  867. //}
  868. //}
  869. entity.Update();
  870. returnSuccessMsg("保存成功!");
  871. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  872. return;
  873. }
  874. returnErrorMsg("找不到记录");
  875. }
  876. }
  877. public void save_erp_customermemo()
  878. {
  879. if (UrlPostParmsCheck("ctid"))
  880. {
  881. string ctid = GetPostString("ctid");
  882. CeErpTradeCell entity = null;
  883. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  884. if (entity != null)
  885. {
  886. entity.CustomerMemo = GetPostString("CustomerMemo");
  887. entity.Update();
  888. ApiVo apiVo = new ApiVo();
  889. apiVo.orderNumber = entity.ctid;
  890. apiVo.actionName = "followRemarks";
  891. apiVo.orderRemarks = entity.CustomerMemo;
  892. designHelper.API_WorkCore(apiVo);//followRemarks
  893. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  894. returnSuccessMsg("保存成功!");
  895. return;
  896. }
  897. returnErrorMsg("找不到记录");
  898. }
  899. }
  900. public void upd_erp_addmemotag()
  901. {
  902. if (UrlPostParmsCheck("ctid"))
  903. {
  904. ;
  905. string eid = GetPostString("ctid");
  906. string sfTagstr = GetPostString("memotag");
  907. CeErpTradeCell entity = null;
  908. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  909. if (entity != null)
  910. {
  911. ApiVo apiVo = new ApiVo();
  912. if (entity.OrderState == 0)
  913. {
  914. returnErrorMsg("请先领单");
  915. return;
  916. }
  917. //撤销顺丰
  918. if (sfTagstr == "撤销顺丰")
  919. {
  920. entity.IsSF = 0;
  921. string reMsg = "";
  922. string oldmemo = entity.seller_memo;
  923. if (entity.OrderState < 5)
  924. {
  925. oldmemo = oldmemo.Replace("顺丰到付", "");
  926. oldmemo = oldmemo.Replace("顺丰寄付", "");
  927. entity.seller_memo = oldmemo;
  928. }
  929. else
  930. {
  931. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  932. {
  933. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  934. }
  935. }
  936. entity.Update();
  937. apiVo.orderNumber = entity.ctid;
  938. apiVo.actionName = "orderRemarks";
  939. apiVo.orderRemarks = entity.seller_memo;
  940. apiVo.isSf = entity.IsSF.ToString();
  941. designHelper.API_WorkCore(apiVo);//orderRemarks
  942. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  943. returnSuccessMsg("撤销成功!" + reMsg);
  944. return;
  945. }
  946. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  947. {
  948. //string oldmemo = entity.seller_memo;
  949. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  950. string sfStr = GetPostString("memotag");
  951. string smemo = entity.seller_memo;
  952. int kindex = smemo.IndexOf(")");
  953. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  954. if (lastoneStr != "-")
  955. {
  956. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  957. }
  958. string prememo = smemo.Substring(0, kindex + 2);
  959. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  960. int lastkindex = lastmemo.IndexOf("(");
  961. string newlastmemo = "";
  962. if (lastkindex == 0)
  963. {
  964. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  965. newlastmemo = "(" + sfStr + "." + useLastmemo;
  966. }
  967. else
  968. {
  969. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  970. }
  971. entity.seller_memo = prememo + newlastmemo;
  972. }
  973. string sfTagMSg = "";
  974. if (sfTagstr == "顺丰寄付")
  975. {
  976. entity.IsSF = 1;
  977. sfTagMSg = "顺丰寄付";
  978. }
  979. else if (sfTagstr == "顺丰到付")
  980. {
  981. entity.IsSF = 2;
  982. sfTagMSg = "顺丰到付";
  983. }
  984. entity.Update();
  985. apiVo = new ApiVo();
  986. apiVo.orderNumber = entity.ctid;
  987. apiVo.actionName = "orderRemarks";
  988. apiVo.orderRemarks = entity.seller_memo;
  989. apiVo.isSf = entity.IsSF.ToString();
  990. designHelper.API_WorkCore(apiVo);//orderRemarks
  991. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  992. returnSuccessMsg("标记成功!");
  993. return;
  994. }
  995. returnErrorMsg("找不到记录");
  996. }
  997. }
  998. public void upd_erp_ordertag()
  999. {
  1000. if (UrlPostParmsCheck("ctid"))
  1001. {
  1002. string eid = GetPostString("ctid");
  1003. CeErpTradeCell entity = null;
  1004. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1005. if (entity != null)
  1006. {
  1007. int tag = GetPostInt("wechattag");
  1008. //if(tag==4 && entity.IsSample == 2)
  1009. //{
  1010. // returnErrorMsg("补差价单不能标记微信单");
  1011. // return;
  1012. //}
  1013. entity.wechatTag = tag;
  1014. entity.Update();
  1015. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1016. if (tag == 1)
  1017. {
  1018. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1019. if (cash == null)
  1020. {
  1021. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1022. cash = new CeErpReturnCash();
  1023. cash.tid = entity.tid;
  1024. cash.seller_nick = main.seller_nick;
  1025. cash.payment = trade.payment;
  1026. cash.buyer_nick = main.buyer_nick;
  1027. cash.cashstate = 0;
  1028. cash.rtype = "微信返现";
  1029. cash.returnprice = 0;
  1030. cash.created = DateTime.Now;
  1031. cash.con = "订单标记微信单";
  1032. cash.img = "";
  1033. cash.applyuserid = CurrentUser.UserID;
  1034. cash.Create();
  1035. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1036. }
  1037. else
  1038. {
  1039. cash.cashstate = 0;
  1040. cash.Update();
  1041. }
  1042. CeErpSukuraData.createInfo(entity.ctid, 9);
  1043. }
  1044. else if (tag == 2)
  1045. {
  1046. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1047. if (cash == null)
  1048. {
  1049. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1050. cash = new CeErpReturnCash();
  1051. cash.tid = entity.tid;
  1052. cash.seller_nick = main.seller_nick;
  1053. cash.payment = trade.payment;
  1054. cash.buyer_nick = main.buyer_nick;
  1055. cash.cashstate = 0;
  1056. cash.rtype = "推购返现";
  1057. cash.returnprice = 5;
  1058. cash.created = DateTime.Now;
  1059. cash.con = "订单标记推购单";
  1060. cash.img = "";
  1061. cash.applyuserid = CurrentUser.UserID;
  1062. cash.Create();
  1063. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1064. }
  1065. else
  1066. {
  1067. cash.cashstate = 0;
  1068. cash.Update();
  1069. }
  1070. CeErpSukuraData.createInfo(entity.ctid, 9);
  1071. }
  1072. else if (tag == 3)
  1073. {
  1074. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1075. if (pers == null)
  1076. {
  1077. pers = new CeErpPersuade();
  1078. pers.ctid = entity.ctid;
  1079. pers.pstate = 0;
  1080. pers.created = DateTime.Now;
  1081. pers.applyuserid = CurrentUser.UserID;
  1082. pers.Create();
  1083. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1084. }
  1085. else
  1086. {
  1087. pers.pstate = 0;
  1088. pers.Update();
  1089. }
  1090. }
  1091. else if (tag == 4 || tag == 5)
  1092. {
  1093. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1094. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1095. if (pers == null)
  1096. {
  1097. pers = new CeErpStayGoods();
  1098. pers.t_id = entity.tid;
  1099. pers.status = "待审核";
  1100. pers.audit_type = 0;
  1101. if (tag == 4)
  1102. {
  1103. pers.stay_type = "微信推购";
  1104. }
  1105. else
  1106. {
  1107. pers.stay_type = "旺旺推购";
  1108. }
  1109. if (entity.IsXianHuo == 0)
  1110. {
  1111. pers.product_id = entity.ProductId;
  1112. }
  1113. pers.wangwang = main.buyer_nick;
  1114. pers.shop_name = main.seller_nick;
  1115. pers.creata_time = DateTime.Now;
  1116. pers.create_u_id = CurrentUser.UserID;
  1117. pers.create_u_name = CurrentUser.UserName;
  1118. pers.Create();
  1119. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1120. }
  1121. else
  1122. {
  1123. pers.audit_type = 0;
  1124. pers.Update();
  1125. }
  1126. CeErpSukuraData.createInfo(entity.ctid, 10);
  1127. }
  1128. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1129. returnSuccessMsg("标记成功!");
  1130. return;
  1131. }
  1132. returnErrorMsg("找不到记录");
  1133. }
  1134. }
  1135. public void upd_erp_ordertag_cancel()
  1136. {
  1137. if (UrlPostParmsCheck("ctid"))
  1138. {
  1139. string eid = GetPostString("ctid");
  1140. CeErpTradeCell entity = null;
  1141. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1142. if (entity != null)
  1143. {
  1144. entity.wechatTag = 0;
  1145. entity.Update();
  1146. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1147. if (pers != null)
  1148. {
  1149. pers.status = "取消推购";
  1150. pers.audit_type = 3;
  1151. pers.Update();
  1152. }
  1153. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1154. returnSuccessMsg("标记成功!");
  1155. return;
  1156. }
  1157. returnErrorMsg("找不到记录");
  1158. }
  1159. }
  1160. public void upd_erp_addweichattag()
  1161. {
  1162. if (UrlPostParmsCheck("ctid"))
  1163. {
  1164. ;
  1165. string eid = GetPostString("ctid");
  1166. CeErpTradeCell entity = null;
  1167. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1168. if (entity != null)
  1169. {
  1170. if (entity.IsAddWechat > 0)
  1171. {
  1172. returnErrorMsg("此单已经标记过了");
  1173. return;
  1174. }
  1175. 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);
  1176. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1177. if (dt.Rows.Count > 0)
  1178. {
  1179. entity.IsAddWechat = 2;
  1180. }
  1181. else
  1182. {
  1183. entity.IsAddWechat = 1;
  1184. }
  1185. entity.Update();
  1186. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1187. returnSuccessMsg("标记成功!");
  1188. return;
  1189. }
  1190. returnErrorMsg("找不到记录");
  1191. }
  1192. }
  1193. public void upd_erp_getmyorder()
  1194. {
  1195. if (UrlPostParmsCheck("ctid"))
  1196. {
  1197. ;
  1198. string eid = GetPostString("ctid");
  1199. CeErpTradeCell entity = null;
  1200. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1201. if (entity != null)
  1202. {
  1203. if (entity.ctid.IndexOf("C") != -1)
  1204. {
  1205. StringBuilder sql = new StringBuilder();
  1206. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1207. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1208. if (dt.Rows.Count > 0)
  1209. {
  1210. decimal total = 0;
  1211. foreach (DataRow dr in dt.Rows)
  1212. {
  1213. total += Convert.ToDecimal(dr["payment"]);
  1214. }
  1215. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1216. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1217. {
  1218. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1219. return;
  1220. }
  1221. }
  1222. }
  1223. if (entity.OrderState == -1)
  1224. {
  1225. returnErrorMsg("待审核订单无法领取!");
  1226. return;
  1227. }
  1228. entity.CustomerUserId = CurrentUser.UserID;
  1229. if (entity.OrderState < 2)
  1230. {
  1231. entity.OrderState = 2;
  1232. if (entity.ShopId != 0)
  1233. {
  1234. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1235. }
  1236. }
  1237. entity.UpdateTime = DateTime.Now;
  1238. entity.Update();
  1239. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1240. returnSuccessMsg("领单成功!");
  1241. return;
  1242. }
  1243. returnErrorMsg("找不到记录");
  1244. }
  1245. }
  1246. public void getmyorder_from_init()
  1247. {
  1248. if (UrlPostParmsCheck("ctid"))
  1249. {
  1250. string eid = GetPostString("ctid");
  1251. CeErpTradeCell entity = null;
  1252. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1253. if (entity != null)
  1254. {
  1255. string sellerMemo = GetPostString("sellerMemo");
  1256. if (sellerMemo.Length > 0)
  1257. {
  1258. entity.seller_memo = sellerMemo;
  1259. }
  1260. string oterhMemo = GetPostString("otherMemo");
  1261. if (oterhMemo.Length > 0)
  1262. {
  1263. entity.OtherMemo = oterhMemo;
  1264. }
  1265. int urg = GetPostInt("urgency");
  1266. entity.IsUrgency = (urg == 1 ? true : false);
  1267. int wechat = GetPostInt("wechat");
  1268. int command = GetPostInt("command");
  1269. if (wechat == 1)
  1270. {
  1271. entity.wechatTag = 1;
  1272. }
  1273. if (command == 1)
  1274. {
  1275. entity.wechatTag = 2;
  1276. }
  1277. string pPro = GetPostString("pprofession");
  1278. if (pPro.Length > 0)
  1279. {
  1280. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1281. string spro = GetPostString("profession");
  1282. if (spro.Length > 0)
  1283. {
  1284. entity.ProfessionId = Convert.ToInt32(spro);
  1285. }
  1286. }
  1287. string proId = GetPostString("productId");
  1288. if (proId.Length > 0)
  1289. {
  1290. entity.ProductId = Convert.ToInt32(proId);
  1291. }
  1292. entity.Material = GetPostString("material");
  1293. entity.Craft = GetPostString("craft");
  1294. entity.CustomerUserId = CurrentUser.UserID;
  1295. if (entity.OrderState < 2)
  1296. {
  1297. entity.OrderState = 2;
  1298. if (entity.ShopId != 0)
  1299. {
  1300. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1301. }
  1302. }
  1303. entity.Update();
  1304. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1305. returnSuccessMsg("领单成功!");
  1306. return;
  1307. }
  1308. returnErrorMsg("找不到记录");
  1309. }
  1310. }
  1311. public void upd_erp_setrelationorder()
  1312. {
  1313. if (UrlPostParmsCheck("ctid"))
  1314. {
  1315. ;
  1316. string eid = GetPostString("ctid");
  1317. string ftid = GetPostString("ftid");
  1318. CeErpTradeCell entity = null;
  1319. CeErpTradeCell fentity = null;
  1320. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1321. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1322. if (fentity == null)
  1323. {
  1324. returnErrorMsg("找不到关联的主订单");
  1325. return;
  1326. }
  1327. if (entity != null)
  1328. {
  1329. if (entity.OrderState >= 5)
  1330. {
  1331. returnErrorMsg("本单已经设计完成无法关联");
  1332. return;
  1333. }
  1334. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1335. {
  1336. returnErrorMsg("线下单续审核后才能关联!");
  1337. return;
  1338. }
  1339. entity.ptid = ftid;
  1340. entity.OrderState = fentity.OrderState;
  1341. //entity.status = fentity.status;
  1342. entity.CustomerUserId = fentity.CustomerUserId;
  1343. entity.DesignUserId = fentity.DesignUserId;
  1344. entity.seller_memo = "补差价单:" + ftid;
  1345. entity.IsSample = 2;
  1346. entity.Update();
  1347. ApiVo apiVo = new ApiVo();
  1348. apiVo.orderNumber = ftid;
  1349. apiVo.payment = entity.payment;
  1350. apiVo.actionName = "repairDesign";
  1351. designHelper.API_WorkCore(apiVo);//repairDesign
  1352. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1353. returnSuccessMsg("关联成功!");
  1354. return;
  1355. }
  1356. else
  1357. returnErrorMsg("找不到记录");
  1358. }
  1359. }
  1360. public void download_erp_neworder()
  1361. {
  1362. string seller = GetPostString("seller_nick");
  1363. string tid = GetPostString("tid");
  1364. if (seller.Length <= 0 || tid.Length <= 0)
  1365. {
  1366. returnErrorMsg("数据错误");
  1367. }
  1368. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1369. //{
  1370. // returnErrorMsg("找不到店铺Sessionkey");
  1371. //}
  1372. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1373. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1374. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1375. if (res.IndexOf("refOid") == -1)
  1376. {
  1377. returnErrorMsg("下载订单数据失败");
  1378. return;
  1379. }
  1380. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1381. returnSuccessMsg("下载完成");
  1382. //tmcHelper.createNewOrder(res);
  1383. //CeErpTrade entr = null;
  1384. //entr = CeErpTrade.Get(tid);
  1385. //if (entr != null)
  1386. //{
  1387. // returnSuccess("下载成功");
  1388. // //下载成功之后,Cell表生成对应的订单;
  1389. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1390. //}
  1391. //else
  1392. //{
  1393. // returnErrorMsg("下载失败或者创建订单失败");
  1394. //}
  1395. }
  1396. public void set_erp_atersale()
  1397. {
  1398. if (UrlPostParmsCheck("ctid"))
  1399. {
  1400. string eid = GetPostString("ctid");
  1401. string reason = GetPostString("AfterSaleReason");
  1402. CeErpTradeCell entity = null;
  1403. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1404. if (entity != null)
  1405. {
  1406. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1407. {
  1408. returnErrorMsg("此订单已经在售后");
  1409. return;
  1410. }
  1411. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1412. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1413. entity.AfterSaleTime = DateTime.Now;
  1414. entity.Update();
  1415. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1416. returnSuccessMsg("转售后成功!");
  1417. return;
  1418. }
  1419. returnErrorMsg("找不到记录");
  1420. }
  1421. }
  1422. public void set_erp_withdraw()
  1423. {
  1424. if (UrlPostParmsCheck("ctid"))
  1425. {
  1426. try
  1427. {
  1428. string eid = GetPostString("ctid");//商品id
  1429. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1430. CeWithdraw ceWithdrawSelect = null;
  1431. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1432. if (ceWithdrawSelect != null)
  1433. {
  1434. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1435. {
  1436. ceWithdrawSelect.status = -1;
  1437. ceWithdrawSelect.Update();
  1438. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1439. returnSuccessMsg("重新发起审核成功");
  1440. return;
  1441. }
  1442. else
  1443. {
  1444. returnSuccessMsg("请勿重复申请!");
  1445. return;
  1446. }
  1447. }
  1448. else
  1449. {
  1450. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1451. if (string.IsNullOrEmpty(CustomerUserId))
  1452. {
  1453. CustomerUserId = "-1";
  1454. }
  1455. int Userid = CurrentUser.UserID;//用户id
  1456. CeWithdraw ceWithdraw = new CeWithdraw();
  1457. ceWithdraw.tid = eid;
  1458. ceWithdraw.userid = Userid;
  1459. ceWithdraw.providerid = CustomerUserId;
  1460. ceWithdraw.status = 3;
  1461. ceWithdraw.creationtime = DateTime.Now;
  1462. ceWithdraw.Create();
  1463. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1464. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1465. return;
  1466. }
  1467. }
  1468. catch
  1469. {
  1470. returnErrorMsg("申请撤回订单失败");
  1471. return;
  1472. }
  1473. }
  1474. }
  1475. public void ins_erp_billinfo()
  1476. {
  1477. if (UrlPostParmsCheck("ctid"))
  1478. {
  1479. string eid = GetPostString("ctid");
  1480. CeErpTradeCell entity = null;
  1481. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1482. if (entity != null)
  1483. {
  1484. CeErpBill bill = CeErpBill.GetByTid(eid);
  1485. bool isHave = false;
  1486. if (bill != null)
  1487. {
  1488. isHave = true;
  1489. if (bill.state != 4)
  1490. {
  1491. returnErrorMsg("此单已经申请过发票了");
  1492. return;
  1493. }
  1494. }
  1495. if (entity.IsNeedBill == 0)
  1496. {
  1497. entity.IsNeedBill = 1;
  1498. }
  1499. entity.Update();
  1500. string errjson = "";
  1501. try
  1502. {
  1503. CeErpBill bill_entity = new CeErpBill();
  1504. bill_entity.tid = entity.tid;
  1505. bill_entity.title = GetPostString("title");
  1506. string taxstr = GetPostString("tax");
  1507. taxstr = taxstr.Replace(" ", "");
  1508. bill_entity.tax = taxstr;
  1509. bill_entity.bank = GetPostString("bank");
  1510. string bankacstr = GetPostString("bankac");
  1511. bankacstr = bankacstr.Replace(" ", "");
  1512. bill_entity.bankac = bankacstr;
  1513. bill_entity.address = GetPostString("address");
  1514. bill_entity.phone = GetPostString("phone");
  1515. bill_entity.price = GetPostString("price");
  1516. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1517. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1518. {
  1519. billCount += 1;
  1520. }
  1521. string prebill = "ltb";
  1522. for (int idx = 1; idx <= billCount; idx++)
  1523. {
  1524. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1525. string billoid = prebill + idx + dtstr;
  1526. bill_entity.billOrderId += billoid;
  1527. if (idx < billCount)
  1528. {
  1529. bill_entity.billOrderId += ",";
  1530. }
  1531. }
  1532. bill_entity.productId = GetPostInt("ProductName");
  1533. bill_entity.num = GetPostInt("num");
  1534. bill_entity.unit = GetPostString("unit");
  1535. bill_entity.type = GetPostString("type");
  1536. bill_entity.sendType = GetPostString("SendType");
  1537. bill_entity.email = GetPostString("email");
  1538. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1539. bill_entity.shopName = GetPostString("ShopName");
  1540. bill_entity.applymemo = GetPostString("applyMemo");
  1541. bill_entity.createTime = DateTime.Now;
  1542. bill_entity.state = 0;
  1543. bill_entity.userId = CurrentUser.UserID;
  1544. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1545. bill_entity.Create();
  1546. }
  1547. catch (Exception ex)
  1548. {
  1549. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1550. returnErrorMsg("创建发票出错!");
  1551. return;
  1552. }
  1553. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1554. returnSuccessMsg("发票申请成功!");
  1555. return;
  1556. }
  1557. returnErrorMsg("找不到记录");
  1558. }
  1559. }
  1560. public void ins_erp_neworder()
  1561. {
  1562. if (UrlPostParmsCheck("receiver_name"))
  1563. {
  1564. CeErpTrade entity = new CeErpTrade();
  1565. string plat_form = GetPostString("platform");
  1566. string preStr = "N_";
  1567. if (plat_form == "拼多多")
  1568. {
  1569. preStr = "P_";
  1570. }
  1571. else if (plat_form == "阿里巴巴")
  1572. {
  1573. preStr = "A_";
  1574. }
  1575. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1576. entity.seller_nick = GetPostString("seller_nick");
  1577. entity.buyer_nick = GetPostString("buyer_nick");
  1578. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1579. entity.total_fee = entity.payment;
  1580. entity.pay_time = DateTime.Now;
  1581. entity.status = "NOT_SHIPPED";
  1582. entity.receiver_name = GetPostString("receiver_name");
  1583. entity.receiver_mobile = GetPostString("receiver_mobile");
  1584. entity.receiver_state = GetPostString("receiver_state");
  1585. entity.receiver_city = GetPostString("receiver_city");
  1586. entity.receiver_district = GetPostString("receiver_district");
  1587. entity.receiver_address = GetPostString("receiver_address");
  1588. if (entity.receiver_state == "" || entity.receiver_city == "")
  1589. {
  1590. returnErrorMsg("收件地址不能为空");
  1591. return;
  1592. }
  1593. int shopId = 0;
  1594. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1595. if (nShop != null)
  1596. {
  1597. shopId = nShop.ID;
  1598. }
  1599. if (shopId != 34 && entity.payment == 0)
  1600. {
  1601. returnErrorMsg("公司自用的单金额才能为0");
  1602. return;
  1603. }
  1604. entity.Create();
  1605. CeErpTradeCell entitycell = new CeErpTradeCell();
  1606. entitycell.ctid = entity.tid;
  1607. entitycell.tid = entity.tid;
  1608. entitycell.ShopId = shopId;
  1609. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1610. entitycell.OrderState = 0;
  1611. entitycell.pay_time = entity.pay_time;
  1612. entitycell.IsOffLineOrder = 1;
  1613. entitycell.Create();
  1614. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1615. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1616. return;
  1617. }
  1618. }
  1619. public void ins_erp_neworder2()
  1620. {
  1621. if (UrlPostParmsCheck("receiver_name"))
  1622. {
  1623. //string plat_form = GetPostString("platform");
  1624. string preStr = "X_";
  1625. string memo = GetPostString("memo");
  1626. string productId = GetPostString("productId");
  1627. string primg = GetPostString("proofimg");
  1628. string sellerNick = GetPostString("seller_nick");
  1629. string addFrom = GetPostString("addfrom");
  1630. if (addFrom == "1")
  1631. {
  1632. preStr = "N_";
  1633. }
  1634. int shopId = 0;
  1635. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1636. if (nShop != null)
  1637. {
  1638. shopId = nShop.ID;
  1639. }
  1640. else
  1641. {
  1642. returnErrorMsg("找不到对应店铺");
  1643. return;
  1644. }
  1645. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1646. {
  1647. returnErrorMsg("必须上传付款凭证");
  1648. return;
  1649. }
  1650. CeErpTrade entity = new CeErpTrade();
  1651. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1652. entity.seller_nick = sellerNick;
  1653. entity.buyer_nick = GetPostString("buyer_nick");
  1654. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1655. entity.total_fee = entity.payment;
  1656. entity.pay_time = DateTime.Now;
  1657. entity.status = "NOT_SHIPPED";
  1658. entity.receiver_name = GetPostString("receiver_name");
  1659. entity.receiver_mobile = GetPostString("receiver_mobile");
  1660. entity.receiver_state = GetPostString("receiver_state");
  1661. entity.receiver_city = GetPostString("receiver_city");
  1662. entity.receiver_district = GetPostString("receiver_district");
  1663. entity.receiver_address = GetPostString("receiver_address");
  1664. entity.seller_memo = memo;
  1665. entity.orderFrom = 20;
  1666. entity.orderType = 15;
  1667. if (entity.receiver_state == "" || entity.receiver_city == "")
  1668. {
  1669. returnErrorMsg("收件地址不能为空");
  1670. return;
  1671. }
  1672. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1673. {
  1674. returnErrorMsg("公司自用的单金额才能为0");
  1675. return;
  1676. }
  1677. entity.Create();
  1678. string toWhere = GetPostString("towhere");
  1679. CeErpTradeCell entitycell = new CeErpTradeCell();
  1680. entitycell.ctid = entity.tid;
  1681. //唯一标识
  1682. entitycell.OrderSn = entity.tid;
  1683. string orderSn = dataHelper.getSaleOrderSn();
  1684. if (orderSn != "")
  1685. {
  1686. entitycell.OrderSn = orderSn;
  1687. }
  1688. entitycell.tid = entity.tid;
  1689. //if (preStr == "X_")
  1690. //{
  1691. entitycell.IsOffLineOrder = 1;
  1692. //}
  1693. entitycell.CustomerUserId = CurrentUser.UserID;
  1694. entitycell.PayProofImg = primg;
  1695. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1696. entitycell.ProductId = Convert.ToInt32(productId);
  1697. entitycell.ShopId = shopId;
  1698. entitycell.UpdateTime = DateTime.Now;
  1699. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1700. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1701. {
  1702. entitycell.IsXianHuo = 1;
  1703. }
  1704. entitycell.pay_time = entity.pay_time;
  1705. if (toWhere == "1")
  1706. {
  1707. entitycell.OrderState = 2;
  1708. }
  1709. else
  1710. {
  1711. entitycell.OrderState = 6;
  1712. entitycell.FinishPlaceTime = entitycell.pay_time;
  1713. }
  1714. if (shopId == 94)
  1715. {
  1716. entitycell.OrderState = 4;
  1717. entitycell.WaitDesignTime = entitycell.pay_time;
  1718. entitycell.StartDesignTime = entitycell.pay_time;
  1719. entitycell.DesignUserId = 218;
  1720. }
  1721. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1722. {
  1723. entitycell.OrderState = -1;//修改12-5
  1724. CeWithdraw ceWithdraw = new CeWithdraw();
  1725. ceWithdraw.tid = entity.tid;
  1726. ceWithdraw.providerid = "-1";
  1727. ceWithdraw.status = -1;
  1728. ceWithdraw.creationtime = DateTime.Now;
  1729. ceWithdraw.userid = 1337;
  1730. ceWithdraw.Create();
  1731. }
  1732. entitycell.Create();
  1733. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1734. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1735. {
  1736. addPlaceRegist(entitycell, CurrentUser.UserID);
  1737. }
  1738. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1739. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1740. return;
  1741. }
  1742. }
  1743. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1744. {
  1745. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1746. entity.PlactTime = tradecell.pay_time;
  1747. entity.AddUserId = userid;
  1748. entity.FileName = tradecell.seller_memo;
  1749. entity.Supplier = 24;
  1750. entity.CreateTime = DateTime.Now;
  1751. entity.Did = tradecell.ctid;
  1752. entity.tid = tradecell.tid;
  1753. entity.splitTag = tradecell.SplitTag;
  1754. entity.CurState = "未完成";
  1755. entity.Create();
  1756. }
  1757. public void get_erp_offlinelist()
  1758. {
  1759. DataStruct dStruct = GetPostStruct();
  1760. List<string> lw = new List<string>();
  1761. string tid = GetPostString("ctid");
  1762. string date1 = GetPostString("date1");
  1763. string date2 = GetPostString("date2");
  1764. if (tid.Length > 0 || date1.Length > 0)
  1765. {
  1766. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1767. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1768. if (dw.Length > 0) lw.Add(dw);
  1769. }
  1770. else
  1771. {
  1772. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1773. }
  1774. string shopname = GetPostString("shopname");
  1775. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1776. string buyernick = GetPostString("buyer_nick");
  1777. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1778. string customer = GetPostString("customer");
  1779. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1780. string design = GetPostString("design");
  1781. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1782. string orderState = GetPostString("orderState");
  1783. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1784. string address = GetPostString("address");
  1785. 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));
  1786. string sellermemo = GetPostString("seller_memo");
  1787. if (sellermemo.Length > 0)
  1788. {
  1789. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1790. }
  1791. string price1 = GetPostString("price1");
  1792. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1793. string price2 = GetPostString("price2");
  1794. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1795. //if (PKey != "admin")
  1796. //{
  1797. // string usershop = CurrentUser.User.pemShop;
  1798. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1799. //}
  1800. //if (ex_psize > 0)
  1801. //{
  1802. dStruct.Order = "pay_time desc";
  1803. //}
  1804. //else
  1805. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1806. lw.Add(string.Format("IsOffLineOrder=1"));
  1807. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1808. DataTable dt = null;
  1809. dt = WebCache.GetData("view_erptradecell", dStruct);
  1810. writeGridDataTableJson(dStruct.TotalCount, dt);
  1811. }
  1812. public void get_erp_returncashrecord()
  1813. {
  1814. DataStruct dStruct = GetPostStruct();
  1815. List<string> lw = new List<string>();
  1816. string tid = GetPostString("ctid");
  1817. if (tid.Length > 0)
  1818. {
  1819. lw.Add(string.Format("tid like '%{0}%'", tid));
  1820. dStruct.Order = "id desc";
  1821. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1822. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1823. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1824. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1825. return;
  1826. }
  1827. returnErrorMsg("id数据错误!");
  1828. }
  1829. public void ins_erp_returncashrecord()
  1830. {
  1831. if (UrlPostParmsCheck("tid"))
  1832. {
  1833. string tid = GetPostString("tid");
  1834. string retype = GetPostString("type");
  1835. StringBuilder sql = new StringBuilder();
  1836. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1837. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1838. if (dt.Rows.Count > 0)
  1839. {
  1840. returnErrorMsg("相同返现类型记录已存在");
  1841. return;
  1842. }
  1843. CeErpReturnCash entity = new CeErpReturnCash();
  1844. entity.tid = tid;
  1845. entity.seller_nick = GetPostString("seller_nick");
  1846. string pment = GetPostString("payment");
  1847. if (pment.Length > 0)
  1848. {
  1849. entity.payment = Convert.ToDouble(pment);
  1850. }
  1851. entity.buyer_nick = GetPostString("buyer_nick");
  1852. entity.cashstate = 0;
  1853. entity.rtype = retype;
  1854. string rPrice = GetPostString("returnprice");
  1855. if (rPrice.Length > 0)
  1856. {
  1857. entity.returnprice = Convert.ToDouble(rPrice);
  1858. }
  1859. entity.created = DateTime.Now;
  1860. entity.con = GetPostString("con");
  1861. entity.img = GetPostString("img");
  1862. entity.applyuserid = CurrentUser.UserID;
  1863. entity.Create();
  1864. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1865. returnSuccessMsg("操作成功!");
  1866. return;
  1867. }
  1868. }
  1869. public void set_erp_predelivery()
  1870. {
  1871. if (UrlPostParmsCheck("ctid"))
  1872. {
  1873. string eid = GetPostString("ctid");
  1874. CeErpTradeCell entity = null;
  1875. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1876. if (entity != null)
  1877. {
  1878. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1879. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1880. //{
  1881. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1882. // return;
  1883. //}
  1884. entity.IsPreDelivery = 1;
  1885. entity.Update();
  1886. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1887. returnSuccessMsg("预发货成功!");
  1888. return;
  1889. //string shop = GetPostString("seller_nick");
  1890. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1891. //string comName = GetPostString("comName");
  1892. //string comCode = GetPostString("comCode");
  1893. //string outSid = GetPostString("outSid");//运单号
  1894. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1895. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1896. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1897. //string apires = "";
  1898. //if (deliveryType == "虚拟发货")
  1899. //{
  1900. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1901. //}
  1902. //else
  1903. //{
  1904. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1905. //}
  1906. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1907. ////{
  1908. //if (apires.IndexOf("发货成功") != -1)
  1909. //{
  1910. // if (deliveryType != "虚拟发货")
  1911. // {
  1912. // //还要插入快递信息到 快递信息表
  1913. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1914. // exinfo.tid = eid;
  1915. // exinfo.out_sid = outSid;
  1916. // exinfo.company_code = comCode;
  1917. // exinfo.company_name = comName;
  1918. // exinfo.delivery_memo = deliveryMemo;
  1919. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1920. // exinfo.deliveryType = deliveryType;
  1921. // exinfo.Create();
  1922. // }
  1923. // returnSuccessMsg("发货成功!");
  1924. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1925. //}
  1926. //else
  1927. //{
  1928. // returnErrorMsg("淘宝发货失败!!");
  1929. //}
  1930. //return;
  1931. }
  1932. returnErrorMsg("找不到订单记录");
  1933. }
  1934. }
  1935. public void get_erp_unusuallist()
  1936. {
  1937. DataStruct dStruct = GetPostStruct();
  1938. List<string> lw = new List<string>();
  1939. string tid = GetPostString("ctid");
  1940. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1941. string shopname = GetPostString("shopname");
  1942. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1943. string buyernick = GetPostString("buyer_nick");
  1944. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1945. string ResponsibleMan = GetPostString("responsible");
  1946. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1947. string date1 = GetPostString("date1");
  1948. string date2 = GetPostString("date2");
  1949. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1950. if (dw.Length > 0) lw.Add(dw);
  1951. string price1 = GetPostString("price1");
  1952. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1953. string price2 = GetPostString("price2");
  1954. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1955. string orderState = GetPostString("orderState");
  1956. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1957. string sellermemo = GetPostString("seller_memo");
  1958. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1959. lw.Add(string.Format("UnusualTag > 0"));
  1960. lw.Add(string.Format("IsRefund<={0}", 1));
  1961. dStruct.Order = "pay_time desc";
  1962. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1963. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1964. writeGridDataTableJson(dStruct.TotalCount, dt);
  1965. }
  1966. public void set_erp_unusualtonomal()
  1967. {
  1968. if (UrlPostParmsCheck("ctid"))
  1969. {
  1970. string eid = GetPostString("ctid");
  1971. CeErpTradeCell entity = null;
  1972. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1973. if (entity != null)
  1974. {
  1975. entity.UnusualTag = -1;
  1976. entity.Update();
  1977. returnSuccessMsg("忽略成功!");
  1978. return;
  1979. }
  1980. returnErrorMsg("找不到记录");
  1981. }
  1982. }
  1983. public void ins_erp_unusualreason()
  1984. {
  1985. if (UrlPostParmsCheck("ctid"))
  1986. {
  1987. string eid = GetPostString("ctid");
  1988. CeErpTradeCell entity = null;
  1989. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1990. if (entity != null)
  1991. {
  1992. entity.MemoOpt = 4;
  1993. entity.UnusualCon = GetPostString("con");
  1994. entity.Update();
  1995. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1996. if (trade != null)
  1997. {
  1998. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  1999. }
  2000. //查货是否超时
  2001. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2002. if (ceErpTradeCellExtend == null)
  2003. {
  2004. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2005. ceErpTradeCellExtend.ctid = entity.ctid;
  2006. }
  2007. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2008. {
  2009. ceErpTradeCellExtend.CheckOut += 1;
  2010. }
  2011. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2012. if (ceErpTradeCellExtend.ID > 0)
  2013. {
  2014. ceErpTradeCellExtend.Update();
  2015. }
  2016. else
  2017. {
  2018. ceErpTradeCellExtend.Create();
  2019. }
  2020. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2021. returnSuccessMsg("操作成功!");
  2022. return;
  2023. }
  2024. returnErrorMsg("找不到记录");
  2025. }
  2026. }
  2027. public void upd_erp_sampleorder()
  2028. {
  2029. if (UrlPostParmsCheck("ctid"))
  2030. {
  2031. string eid = GetPostString("ctid");
  2032. string[] eArr = eid.Split(',');
  2033. if (eArr.Length > 1)
  2034. {
  2035. List<string> eLst = new List<string>();
  2036. for (int i = 0; i < eArr.Length; i++)
  2037. {
  2038. eLst.Add("'" + eArr[i] + "'");
  2039. }
  2040. eid = string.Join(",", eLst.ToArray());
  2041. }
  2042. else
  2043. {
  2044. eid = "'" + eid + "'";
  2045. }
  2046. StringBuilder sql = new StringBuilder();
  2047. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2048. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2049. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2050. if (dt.Rows.Count > 0)
  2051. {
  2052. string errmsg = "";
  2053. foreach (DataRow dr in dt.Rows)
  2054. {
  2055. StringBuilder sqlsb = new StringBuilder();
  2056. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2057. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2058. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2059. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2060. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2061. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2062. {
  2063. continue;
  2064. }
  2065. else
  2066. {
  2067. string emsg = commonHelper.KeepChinese(apires);
  2068. errmsg += emsg;
  2069. }
  2070. }
  2071. if (errmsg.Length > 0)
  2072. {
  2073. returnErrorMsg(errmsg);
  2074. return;
  2075. }
  2076. returnSuccessMsg("操作成功");
  2077. return;
  2078. }
  2079. returnErrorMsg("找不到记录");
  2080. }
  2081. }
  2082. public void upd_erp_transcustomer()
  2083. {
  2084. if (UrlPostParmsCheck("ctid"))
  2085. {
  2086. string eid = GetPostString("ctid");
  2087. int userid = GetPostInt("CustomerUserId");
  2088. CeErpTradeCell entity = null;
  2089. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2090. if (entity != null)
  2091. {
  2092. //string[] mlist = entity.seller_memo.Split('-');
  2093. //string sql = "select * from view_erpuser where id=" + userid;
  2094. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2095. //if (dt != null && dt.Rows.Count > 0)
  2096. //{
  2097. // string nmemo = "";
  2098. // for(int i = 0; i < mlist.Length - 1; i++)
  2099. // {
  2100. // nmemo += mlist[i];
  2101. // nmemo += "-";
  2102. // }
  2103. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2104. // entity.seller_memo = nmemo;
  2105. //}
  2106. entity.CustomerUserId = userid;
  2107. entity.Update();
  2108. returnSuccessMsg("操作成功!");
  2109. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2110. return;
  2111. }
  2112. returnErrorMsg("找不到记录");
  2113. }
  2114. }
  2115. public void upd_erp_transdesigner()
  2116. {
  2117. if (UrlPostParmsCheck("ctid"))
  2118. {
  2119. string eids = GetPostString("ctid");
  2120. string[] ctidList = eids.Split(',');
  2121. int userid = GetPostInt("DesignUserId");
  2122. foreach (string ctid in ctidList)
  2123. {
  2124. CeErpTradeCell entity = null;
  2125. CeErpDesignerBill entitys = null;
  2126. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2127. entitys = CeErpDesignerBill.GetByTid(ctid);
  2128. if (entity != null)
  2129. {
  2130. if (entity.OrderState > 4)
  2131. {
  2132. continue;
  2133. }
  2134. //存在退款不能流转
  2135. if (entity.IsRefund > 0)
  2136. {
  2137. continue;
  2138. }
  2139. entity.DesignUserId = userid;
  2140. entity.WaitDesignTime = DateTime.Now;
  2141. entity.Update();
  2142. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2143. }
  2144. }
  2145. returnSuccessMsg("操作成功!");
  2146. }
  2147. }
  2148. public void upd_erp_distributedesigner()
  2149. {
  2150. if (UrlPostParmsCheck("ctid"))
  2151. {
  2152. string eid = GetPostString("ctid");
  2153. int userid = GetPostInt("DesignUserId");
  2154. string[] idlist = eid.Split(',');
  2155. if (idlist.Length <= 0)
  2156. {
  2157. returnErrorMsg("订单不能为空");
  2158. return;
  2159. }
  2160. foreach (string ctid in idlist)
  2161. {
  2162. CeErpTradeCell entity = null;
  2163. CeErpDesignerBill entitys = null;
  2164. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2165. else continue;
  2166. if (entity != null)
  2167. {
  2168. if (userid == 2125 || userid == 3542)
  2169. { }
  2170. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2171. {
  2172. returnErrorMsg("金额错误的订单无法指派");
  2173. return;
  2174. }
  2175. if (entity.OrderState >= 5)
  2176. {
  2177. returnErrorMsg("已经设计完成无法指派");
  2178. return;
  2179. }
  2180. if (entity.OrderState == -1)
  2181. {
  2182. returnErrorMsg("审核中的订单无法指派");
  2183. return;
  2184. }
  2185. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2186. {
  2187. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2188. return;
  2189. }
  2190. //157赖橙帆 159林晨 73 静之颖
  2191. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && CurrentUser.UserID != 157 && CurrentUser.UserID != 159 && CurrentUser.UserID != 1479 && CurrentUser.UserID != 73)
  2192. {
  2193. returnErrorMsg("指派设计共创无法再次指派!");
  2194. return;
  2195. }
  2196. entity.OrderState = 3;
  2197. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  2198. if (entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  2199. {
  2200. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2201. entity.SupplierId = suid;
  2202. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2203. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2204. }
  2205. if (userid == 2125 && entity.seller_memo != "")
  2206. {
  2207. apiDesign.API_GetPrintData_CreateOrder(entity);
  2208. }
  2209. if (userid == 3542 && entity.seller_memo != "")
  2210. {
  2211. string userPost = CurrentUser.UserPost.Post.Code;
  2212. if (CurrentUser.UserID == 73)
  2213. {
  2214. userPost = "SysAdmin";
  2215. }
  2216. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2217. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2218. if (response.msg != "设计共创:成功")
  2219. {
  2220. returnErrorMsg(response.msg);
  2221. return;
  2222. }
  2223. entity.DispatchSort = 2;
  2224. }
  2225. else
  2226. {
  2227. if (entity.DispatchSort == 2)
  2228. {
  2229. ApiVo apiVo = new ApiVo();
  2230. apiVo.actionName = "closeDesign";
  2231. apiVo.orderNumber = entity.ctid;
  2232. designHelper.API_WorkCore(apiVo);//closeDesign
  2233. }
  2234. entity.DispatchSort = 0;
  2235. }
  2236. entity.DesignUserId = userid;
  2237. entity.WaitDesignTime = DateTime.Now;
  2238. entity.UpdateTime = DateTime.Now;
  2239. entity.Update();
  2240. string name = commonHelper.getUserNameById(userid);
  2241. commonHelper.UpdateRelationOrder(entity.ctid);
  2242. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2243. }
  2244. }
  2245. returnSuccessMsg("操作成功!");
  2246. return;
  2247. }
  2248. }
  2249. public string getTidByCtid(string ctid)
  2250. {
  2251. string tid = "";
  2252. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2253. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2254. if (dataTable != null && dataTable.Rows.Count > 0)
  2255. {
  2256. tid = dataTable.Rows[0]["tid"].ToString();
  2257. }
  2258. return tid;
  2259. }
  2260. public List<string> getTidByCtidLike(string ctid)
  2261. {
  2262. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2263. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2264. List<string> list = new List<string>();
  2265. if (dataTable != null && dataTable.Rows.Count > 0)
  2266. {
  2267. foreach (DataRow item in dataTable.Rows)
  2268. {
  2269. list.Add("'" + item["tid"].ToString() + "'");
  2270. }
  2271. }
  2272. return list;
  2273. }
  2274. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2275. {
  2276. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2277. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2278. List<string> list = new List<string>();
  2279. if (dataTable != null && dataTable.Rows.Count > 0)
  2280. {
  2281. foreach (DataRow item in dataTable.Rows)
  2282. {
  2283. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2284. {
  2285. continue;
  2286. }
  2287. list.Add("'" + item["receiverId"].ToString() + "'");
  2288. }
  2289. }
  2290. return list;
  2291. }
  2292. public void get_erp_myorderlist()
  2293. {
  2294. DataStruct dStruct = GetPostStruct();
  2295. List<string> lw = new List<string>();
  2296. string tid = GetPostString("ctid");
  2297. if (tid.Length > 0)
  2298. {
  2299. string select_tid = getTidByCtid(tid);
  2300. lw.Add(string.Format("tid='{0}'", select_tid));
  2301. }
  2302. else
  2303. {
  2304. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2305. }
  2306. //12-1 修改
  2307. string urgent = GetPostString("urgent");
  2308. string back = GetPostString("back");
  2309. string offlineSearch = GetPostString("offlineSearch");
  2310. if (!string.IsNullOrWhiteSpace(urgent))
  2311. {
  2312. if (urgent.Equals("true"))
  2313. {
  2314. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2315. }
  2316. }
  2317. if (!string.IsNullOrWhiteSpace(back))
  2318. {
  2319. if (back.Equals("true"))
  2320. {
  2321. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2322. }
  2323. }
  2324. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2325. {
  2326. if (offlineSearch.Equals("true"))
  2327. {
  2328. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2329. }
  2330. }
  2331. //end
  2332. string shopname = GetPostString("shopname");
  2333. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2334. string buyernick = GetPostString("buyer_nick");
  2335. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2336. string design = GetPostString("design");
  2337. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2338. string orderState = GetPostString("orderState");
  2339. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2340. string sellermemo = GetPostString("seller_memo");
  2341. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2342. string date1 = GetPostString("date1");
  2343. string date2 = GetPostString("date2");
  2344. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2345. if (dw.Length > 0) lw.Add(dw);
  2346. string price1 = GetPostString("price1");
  2347. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2348. string price2 = GetPostString("price2");
  2349. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2350. string urgency = GetPostString("urgency");
  2351. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2352. string after = GetPostString("after");
  2353. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2354. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2355. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2356. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2357. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2358. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2359. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2360. if (dt != null && dt.Rows.Count > 0)
  2361. {
  2362. foreach (DataRow dr in dt.Rows)
  2363. {
  2364. try
  2365. {
  2366. // 对象操作
  2367. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2368. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2369. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2370. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2371. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2372. if (dStruct.PageSize != 100000)
  2373. {
  2374. if (dr["DispatchSort"].ToString() == "2")
  2375. {
  2376. dr["gongchuang"] = 200;
  2377. }
  2378. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2379. {
  2380. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2381. dr["gongchuang"] = response.code;
  2382. }
  2383. }
  2384. }
  2385. catch (NullReferenceException ex)
  2386. {
  2387. }
  2388. }
  2389. }
  2390. writeGridDataTableJson(dStruct.TotalCount, dt);
  2391. }
  2392. public void get_erp_myreturnorderlist()
  2393. {
  2394. DataStruct dStruct = GetPostStruct();
  2395. List<string> lw = new List<string>();
  2396. string tid = GetPostString("ctid");
  2397. if (tid.Length > 0)
  2398. {
  2399. string select_tid = getTidByCtid(tid);
  2400. lw.Add(string.Format("tid='{0}'", select_tid));
  2401. }
  2402. else
  2403. {
  2404. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2405. }
  2406. string shopname = GetPostString("shopname");
  2407. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2408. string buyernick = GetPostString("buyer_nick");
  2409. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2410. string design = GetPostString("design");
  2411. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2412. string orderState = GetPostString("orderState");
  2413. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2414. string sellermemo = GetPostString("seller_memo");
  2415. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2416. string date1 = GetPostString("date1");
  2417. string date2 = GetPostString("date2");
  2418. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2419. if (dw.Length > 0) lw.Add(dw);
  2420. string price1 = GetPostString("price1");
  2421. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2422. string price2 = GetPostString("price2");
  2423. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2424. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2425. {
  2426. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2427. }
  2428. else
  2429. {
  2430. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2431. }
  2432. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2433. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2434. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2435. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2436. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2437. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2438. if (dt != null && dt.Rows.Count > 0)
  2439. {
  2440. foreach (DataRow dr in dt.Rows)
  2441. {
  2442. try
  2443. {
  2444. // 对象操作
  2445. if (dStruct.PageSize != 100000)
  2446. {
  2447. if (dr["DispatchSort"].ToString() == "2")
  2448. {
  2449. dr["gongchuang"] = 200;
  2450. }
  2451. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2452. {
  2453. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2454. dr["gongchuang"] = response.code;
  2455. }
  2456. }
  2457. }
  2458. catch (NullReferenceException ex)
  2459. {
  2460. // 处理空引用异常
  2461. }
  2462. }
  2463. }
  2464. writeGridDataTableJson(dStruct.TotalCount, dt);
  2465. }
  2466. public void get_erp_myorderlist_pregather()
  2467. {
  2468. string date1 = GetPostString("date1");
  2469. string date2 = GetPostString("date2");
  2470. int userId = CurrentUser.UserID; //客服id
  2471. string orderWhere = "";
  2472. List<string> lw = new List<string>();
  2473. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2474. if (dw.Length > 0) lw.Add(dw);
  2475. lw.Add(string.Format("CustomerUserId={0}", userId));
  2476. lw.Add(string.Format("OrderState<9"));
  2477. orderWhere = string.Join(" and ", lw.ToArray());
  2478. string orderWhere2 = "";
  2479. List<string> lw2 = new List<string>();
  2480. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2481. if (dw2.Length > 0) lw2.Add(dw2);
  2482. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2483. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2484. string sql = string.Format("select *" +
  2485. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2486. "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 " +
  2487. "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 " +
  2488. "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");
  2489. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2490. //writeGridDataTableJson(dt.Rows.Count, dt);
  2491. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2492. }
  2493. public void upd_erp_publishorder()
  2494. {
  2495. if (UrlPostParmsCheck("ctid"))
  2496. {
  2497. string eid = GetPostString("ctid");
  2498. CeErpTradeCell entity = null;
  2499. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2500. if (entity != null)
  2501. {
  2502. entity.OrderState = 0; //发布后,变为待抢单
  2503. entity.Update();
  2504. commonHelper.UpdateRelationOrder(entity.ctid);
  2505. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2506. returnSuccessMsg("发布成功!");
  2507. return;
  2508. }
  2509. returnErrorMsg("找不到记录");
  2510. }
  2511. }
  2512. public void get_erp_my_tiporder()
  2513. {
  2514. StringBuilder sql = new StringBuilder();
  2515. int userId = 0;
  2516. if (CurrentUser != null) userId = CurrentUser.UserID;
  2517. string posCode = CurrentUser.UserPost.Post.Code;
  2518. string isTipedAfterSaleVerify = GetPostString("af");
  2519. DataTable dt = new DataTable();
  2520. if (posCode != "Supplier")
  2521. {
  2522. if (posCode == "CustomerService" || posCode == "Director")
  2523. {
  2524. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2525. }
  2526. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2527. {
  2528. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2529. }
  2530. else
  2531. {
  2532. string teamIds = CurrentUser.User.TeamIds;
  2533. if (teamIds == "")
  2534. {
  2535. teamIds = "0";
  2536. }
  2537. 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);
  2538. }
  2539. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2540. }
  2541. if (dt.Rows.Count <= 0)
  2542. {
  2543. string key = "aftersale_order_" + userId;
  2544. if (RedisHelper.HasKey(key))
  2545. {
  2546. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2547. dt.Columns.Add("ctid", typeof(string));
  2548. dt.Columns.Add("IsReadTag", typeof(int));
  2549. foreach (var i in list)
  2550. {
  2551. DataRow data = dt.NewRow();
  2552. data["ctid"] = i;
  2553. data["IsReadTag"] = 4;
  2554. dt.Rows.Add(data);
  2555. }
  2556. RedisHelper.StringDelete(key);
  2557. }
  2558. }
  2559. if (dt.Rows.Count <= 0)
  2560. {
  2561. sql = new StringBuilder();
  2562. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2563. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2564. }
  2565. if (posCode == "Supplier")
  2566. {
  2567. string ids = CurrentUser.User.pemVend;
  2568. if (ids != null && ids.Length > 0)
  2569. {
  2570. string[] ids_list = ids.Split(',');
  2571. foreach (var item in ids_list)
  2572. {
  2573. string key = "return_order_" + item;
  2574. if (RedisHelper.HasKey(key))
  2575. {
  2576. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2577. dt.Columns.Add("ctid", typeof(string));
  2578. dt.Columns.Add("IsReadTag", typeof(int));
  2579. foreach (var i in list)
  2580. {
  2581. DataRow data = dt.NewRow();
  2582. data["ctid"] = i;
  2583. data["IsReadTag"] = 1;
  2584. dt.Rows.Add(data);
  2585. }
  2586. RedisHelper.StringDelete(key);
  2587. }
  2588. }
  2589. }
  2590. if (dt.Rows.Count <= 0)
  2591. {
  2592. sql = new StringBuilder();
  2593. 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);
  2594. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2595. }
  2596. }
  2597. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2598. }
  2599. public void reset_erp_tiporder()
  2600. {
  2601. string ids = GetPostString("ids");
  2602. string[] ctidList = ids.Split(',');
  2603. foreach (string ctid in ctidList)
  2604. {
  2605. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2606. if (enty != null)
  2607. {
  2608. enty.IsReadTag = 0;
  2609. enty.Update();
  2610. }
  2611. }
  2612. returnSuccessMsg("成功!");
  2613. return;
  2614. }
  2615. public void get_erp_designlist()
  2616. {
  2617. DataStruct dStruct = GetPostStruct();
  2618. List<string> lw = new List<string>();
  2619. string tid = GetPostString("ctid");
  2620. if (tid.Length > 0)
  2621. {
  2622. string select_tid = getTidByCtid(tid);
  2623. lw.Add(string.Format("tid='{0}'", select_tid));
  2624. }
  2625. string shopname = GetPostString("shopname");
  2626. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2627. string buyernick = GetPostString("buyer_nick");
  2628. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2629. string customer = GetPostString("customer");
  2630. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2631. string design = GetPostString("design");
  2632. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2633. string orderState = GetPostString("orderState");
  2634. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2635. lw.Add(string.Format("OrderState<6"));
  2636. string address = GetPostString("address");
  2637. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2638. string sellermemo = GetPostString("seller_memo");
  2639. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2640. string date1 = GetPostString("date1");
  2641. string date2 = GetPostString("date2");
  2642. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2643. if (dw.Length > 0) lw.Add(dw);
  2644. string apdate1 = GetPostString("apdate1");
  2645. string apdate2 = GetPostString("apdate2");
  2646. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2647. if (dwap.Length > 0) lw.Add(dwap);
  2648. string price1 = GetPostString("price1");
  2649. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2650. string price2 = GetPostString("price2");
  2651. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2652. string designTime = GetPostString("designtime");
  2653. if (designTime.Length > 0)
  2654. {
  2655. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2656. }
  2657. string usershop = CurrentUser.User.pemShop;
  2658. if (usershop.Length > 0)
  2659. {
  2660. lw.Add(string.Format("shopId in ({0})", usershop));
  2661. }
  2662. int myOrgid = CurrentUser.UserPost.OrgID;
  2663. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2664. if (myOrgCode.IndexOf("Designer") != -1)
  2665. {
  2666. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2667. {
  2668. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2669. }
  2670. else
  2671. {
  2672. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2673. }
  2674. }
  2675. else
  2676. {
  2677. string orgId = GetPostString("designerhd");
  2678. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2679. }
  2680. if (tid.Length > 0 || buyernick.Length > 0)
  2681. {
  2682. lw.Add(string.Format("OrderState >= 3"));
  2683. }
  2684. else
  2685. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2686. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2687. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2688. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2689. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2690. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2691. if (dt != null && dt.Rows.Count > 0)
  2692. {
  2693. foreach (DataRow dr in dt.Rows)
  2694. {
  2695. try
  2696. {
  2697. // 对象操作
  2698. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2699. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2700. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2701. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2702. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2703. if (dStruct.PageSize != 100000)
  2704. {
  2705. if (dr["DispatchSort"].ToString() == "2")
  2706. {
  2707. dr["gongchuang"] = 200;
  2708. }
  2709. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2710. {
  2711. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2712. dr["gongchuang"] = response.code;
  2713. }
  2714. }
  2715. }
  2716. catch (NullReferenceException ex)
  2717. {
  2718. }
  2719. }
  2720. }
  2721. writeGridDataTableJson(dStruct.TotalCount, dt);
  2722. }
  2723. public void get_erp_mydesignlist()
  2724. {
  2725. DataStruct dStruct = GetPostStruct();
  2726. List<string> lw = new List<string>();
  2727. string tid = GetPostString("ctid");
  2728. if (tid.Length > 0)
  2729. {
  2730. string select_tid = getTidByCtid(tid);
  2731. lw.Add(string.Format("tid='{0}'", select_tid));
  2732. }
  2733. string shopname = GetPostString("shopname");
  2734. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2735. string buyernick = GetPostString("buyer_nick");
  2736. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2737. string customer = GetPostString("customer");
  2738. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2739. string orderState = GetPostString("orderState");
  2740. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2741. //lw.Add(string.Format("OrderState<6"));
  2742. string date1 = GetPostString("date1");
  2743. string date2 = GetPostString("date2");
  2744. string dw = GetDateWhere("pay_time", date1, date2);
  2745. if (dw.Length > 0) lw.Add(dw);
  2746. string apdate1 = GetPostString("apdate1");
  2747. string apdate2 = GetPostString("apdate2");
  2748. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2749. if (dwap.Length > 0) lw.Add(dwap);
  2750. string price1 = GetPostString("price1");
  2751. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2752. string price2 = GetPostString("price2");
  2753. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2754. string olddownload = GetPostString("olddown");
  2755. if (olddownload == "1")
  2756. {
  2757. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2758. }
  2759. else if (olddownload == "2")
  2760. {
  2761. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2762. }
  2763. string sellermemo = GetPostString("seller_memo");
  2764. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2765. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2766. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2767. {
  2768. if (CurrentUser.User.TeamIds.Length > 0)
  2769. {
  2770. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2771. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2772. else
  2773. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2774. }
  2775. else
  2776. {
  2777. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2778. }
  2779. }
  2780. if (tid.Length <= 0)
  2781. {
  2782. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2783. }
  2784. lw.Add(string.Format("IsReturn!=3"));
  2785. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2786. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2787. string teamids = CurrentUser.User.TeamIds.ToString();
  2788. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2789. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2790. if (dt != null && dt.Rows.Count > 0)
  2791. {
  2792. foreach (DataRow dr in dt.Rows)
  2793. {
  2794. try
  2795. {
  2796. // 对象操作
  2797. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2798. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2799. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2800. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2801. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2802. if (dStruct.PageSize != 100000)
  2803. {
  2804. if (dr["DispatchSort"].ToString() == "2")
  2805. {
  2806. dr["gongchuang"] = 200;
  2807. }
  2808. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2809. {
  2810. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2811. dr["gongchuang"] = response.code;
  2812. }
  2813. }
  2814. }
  2815. catch (NullReferenceException ex)
  2816. {
  2817. }
  2818. }
  2819. }
  2820. writeGridDataTableJson(dStruct.TotalCount, dt);
  2821. }
  2822. public void set_erp_startdesign()
  2823. {
  2824. if (UrlPostParmsCheck("ctid"))
  2825. {
  2826. string eid = GetPostString("ctid");
  2827. CeErpTradeCell entity = null;
  2828. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2829. if (entity != null)
  2830. {
  2831. if (entity.OrderState != 3)
  2832. {
  2833. returnErrorMsg("请刷新,订单已经设计了");
  2834. return;
  2835. }
  2836. entity.StartDesignTime = DateTime.Now;
  2837. entity.OrderState = 4;
  2838. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2839. {
  2840. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2841. entity.SupplierId = suid;
  2842. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2843. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2844. }
  2845. entity.UpdateTime = DateTime.Now;
  2846. //entity.MakeSupplier = suname;
  2847. entity.Update();
  2848. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2849. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2850. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2851. commonHelper.getCytPrice(entity);
  2852. returnSuccessMsg("操作成功!");
  2853. return;
  2854. }
  2855. returnErrorMsg("找不到记录");
  2856. }
  2857. }
  2858. public void ins_erp_designselfmemo()
  2859. {
  2860. if (UrlPostParmsCheck("ctid"))
  2861. {
  2862. string eid = GetPostString("ctid");
  2863. string con = GetPostString("con");
  2864. CeErpTradeCell entity = null;
  2865. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2866. if (entity != null)
  2867. {
  2868. entity.DesignSelfMemo = con;
  2869. entity.Update();
  2870. returnSuccessMsg("操作成功!");
  2871. return;
  2872. }
  2873. returnErrorMsg("找不到记录");
  2874. }
  2875. }
  2876. public void ins_erp_designprice()
  2877. {
  2878. if (UrlPostParmsCheck("ctid"))
  2879. {
  2880. string eid = GetPostString("ctid");
  2881. int uid = CurrentUser.UserID;
  2882. string userName = CurrentUser.UserName;
  2883. CeErpTradeCell entity = null;
  2884. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2885. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2886. if (entitys == null)
  2887. {
  2888. entitys = new CeErpDesignerBill();
  2889. }
  2890. if (entity != null)
  2891. {
  2892. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2893. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2894. entity.StartDesignTime = DateTime.Now;
  2895. entity.OrderState = 4;
  2896. string suname = "";
  2897. if (entity.SupplierId == 0)
  2898. {
  2899. int sid = commonHelper.autoDistributeToSupplier(entity);
  2900. entity.SupplierId = sid;
  2901. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2902. }
  2903. entity.Update();
  2904. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2905. if (ceErpUserPost != null)
  2906. {
  2907. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2908. if (ceErpPost != null)
  2909. {
  2910. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2911. {
  2912. entitys.tid = entity.ctid;
  2913. entitys.oid = entity.tid;
  2914. entitys.uid = uid;
  2915. entitys.userName = userName;
  2916. entitys.designerType = 1;
  2917. entitys.designerTypeText = "内部设计师";
  2918. entitys.price = Convert.ToDouble(GetPostString("price"));
  2919. entitys.designNum = GetPostInt("designNum");
  2920. entitys.modifyNum = GetPostInt("modifyNum");
  2921. entitys.designSize = GetPostString("designSize");
  2922. entitys.modifySize = GetPostString("modifySize");
  2923. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2924. {
  2925. entitys.create_time = DateTime.Now;
  2926. entitys.create_u_id = uid;
  2927. entitys.create_u_name = userName;
  2928. entitys.Save();
  2929. }
  2930. else
  2931. {
  2932. entitys.update_time = DateTime.Now;
  2933. entitys.update_u_id = uid;
  2934. entitys.update_u_name = userName;
  2935. entitys.Update();
  2936. }
  2937. }
  2938. }
  2939. }
  2940. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2941. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2942. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2943. if (suname != "")
  2944. {
  2945. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2946. }
  2947. commonHelper.getCytPrice(entity);
  2948. returnSuccessMsg("操作成功!");
  2949. return;
  2950. }
  2951. returnErrorMsg("找不到记录");
  2952. }
  2953. }
  2954. public void upload_erp_filecomplete()
  2955. {
  2956. if (UrlPostParmsCheck("ctid"))
  2957. {
  2958. string eid = GetPostString("ctid");
  2959. CeErpTradeCell entity = null;
  2960. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2961. if (entity != null)
  2962. {
  2963. entity.OrderState = 5; //设计完成
  2964. entity.Update();
  2965. returnSuccessMsg(eid + "上传成功,设计完成!");
  2966. return;
  2967. }
  2968. returnErrorMsg("找不到订单记录");
  2969. }
  2970. }
  2971. public void get_erp_designovertimelist()
  2972. {
  2973. DataStruct dStruct = GetPostStruct();
  2974. List<string> lw = new List<string>();
  2975. string tid = GetPostString("ctid");
  2976. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  2977. string shopname = GetPostString("shopname");
  2978. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2979. string buyernick = GetPostString("buyer_nick");
  2980. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2981. string ResponsibleMan = GetPostString("responsible");
  2982. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2983. string date1 = GetPostString("date1");
  2984. string date2 = GetPostString("date2");
  2985. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2986. if (dw.Length > 0) lw.Add(dw);
  2987. string price1 = GetPostString("price1");
  2988. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2989. string price2 = GetPostString("price2");
  2990. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2991. string orderState = GetPostString("orderState");
  2992. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2993. string sellermemo = GetPostString("seller_memo");
  2994. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2995. lw.Add(string.Format("UnusualTag=3"));
  2996. lw.Add(string.Format("IsRefund<={0}", 1));
  2997. dStruct.Order = "WaitDesignTime desc";
  2998. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2999. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3000. writeGridDataTableJson(dStruct.TotalCount, dt);
  3001. }
  3002. //设计管理 获取抢单大厅列表
  3003. public void get_erp_grabinglist()
  3004. {
  3005. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3006. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3007. bool oldOrder = false;
  3008. if (org != null)
  3009. {
  3010. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3011. }
  3012. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3013. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3014. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3015. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3016. //先处理订单数据
  3017. if (dt.Rows.Count > 0)
  3018. {
  3019. Dictionary<string, int> design = null;
  3020. int count = 0;
  3021. foreach (DataRow row in dt.Rows)
  3022. {
  3023. if (map.ContainsKey(row["ShopId"].ToString()))
  3024. {
  3025. map.TryGetValue(row["ShopId"].ToString(), out design);
  3026. }
  3027. else
  3028. {
  3029. design = new Dictionary<string, int>();
  3030. }
  3031. if (design.ContainsKey(row["ProductId"].ToString()))
  3032. {
  3033. design.TryGetValue(row["ProductId"].ToString(), out count);
  3034. }
  3035. count++;
  3036. design[row["ProductId"].ToString()] = count;
  3037. map[row["ShopId"].ToString()] = design;
  3038. }
  3039. }
  3040. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3041. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3042. //把店铺排序和技能排序分类
  3043. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3044. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3045. if (design_dt.Rows.Count > 0)
  3046. {
  3047. Dictionary<string, string> design = null;
  3048. List<string> shopIds = null;
  3049. foreach (DataRow row in design_dt.Rows)
  3050. {
  3051. if ("0".Equals(row["designId"].ToString()))
  3052. {
  3053. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3054. {
  3055. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3056. }
  3057. else
  3058. {
  3059. shopIds = new List<string>();
  3060. }
  3061. shopIds.Add(row["shopId"].ToString());
  3062. shop_orders[row["orders"].ToString()] = shopIds;
  3063. }
  3064. else
  3065. {
  3066. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3067. {
  3068. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3069. }
  3070. else
  3071. {
  3072. design = new Dictionary<string, string>();
  3073. }
  3074. design[row["orders"].ToString()] = row["designId"].ToString();
  3075. design_orders[row["shopId"].ToString()] = design;
  3076. }
  3077. }
  3078. //处理成key value后根据key排序
  3079. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3080. foreach (List<string> val in shop_orders.Values)
  3081. {
  3082. if (val != null)
  3083. {
  3084. foreach (string key in val)
  3085. {
  3086. if (design_orders.ContainsKey(key.ToString()))
  3087. {
  3088. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3089. }
  3090. }
  3091. }
  3092. }
  3093. }
  3094. //校验哪个优先级有订单
  3095. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3096. foreach (string key in shop_orders.Keys)
  3097. {
  3098. List<string> ids = null;
  3099. shop_orders.TryGetValue(key, out ids);
  3100. //id为shopid
  3101. foreach (string id in ids)
  3102. {
  3103. Dictionary<string, int> list = null;
  3104. Dictionary<string, string> desing = null;
  3105. map.TryGetValue(id, out list);
  3106. design_orders.TryGetValue(id, out desing);
  3107. if (list != null && desing != null)
  3108. {
  3109. foreach (var item in desing)
  3110. {
  3111. int count = 0;
  3112. if (list.ContainsKey(item.Value))
  3113. {
  3114. list.TryGetValue(item.Value, out count);
  3115. if (count > 0)
  3116. {
  3117. designIds[id] = item.Value;
  3118. break;
  3119. }
  3120. }
  3121. }
  3122. }
  3123. }
  3124. if (designIds.Count > 0)
  3125. {
  3126. break;
  3127. }
  3128. }
  3129. DataTable table = new DataTable();
  3130. table.Columns.Add("tid", typeof(string));
  3131. table.Columns.Add("ctid", typeof(string));
  3132. table.Columns.Add("seller_nick", typeof(string));
  3133. table.Columns.Add("productName", typeof(string));
  3134. table.Columns.Add("pay_time", typeof(string));
  3135. table.Columns.Add("seller_memo", typeof(string));
  3136. if (designIds.Count > 0)
  3137. {
  3138. string shopId = "";
  3139. string productId = "";
  3140. foreach (var designInfo in designIds)
  3141. {
  3142. shopId = designInfo.Key;
  3143. productId = designInfo.Value;
  3144. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3145. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3146. if (dt.Rows.Count > 0)
  3147. {
  3148. foreach (DataRow row in dt.Rows)
  3149. {
  3150. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3151. {
  3152. DataRow data = table.NewRow();
  3153. data["ctid"] = row["ctid"].ToString();
  3154. data["tid"] = row["tid"].ToString();
  3155. data["seller_nick"] = ceErpShop.ShopName;
  3156. data["pay_time"] = row["pay_time"].ToString();
  3157. data["seller_memo"] = row["seller_memo"].ToString();
  3158. data["productName"] = ceErpProduct.PType;
  3159. table.Rows.Add(data);
  3160. }
  3161. }
  3162. }
  3163. }
  3164. }
  3165. writeGridDataTableJson(table.Rows.Count, table);
  3166. }
  3167. private object rushLockObject = new object();
  3168. public void set_erp_grabingorder()
  3169. {
  3170. if (UrlPostParmsCheck("ctid"))
  3171. {
  3172. int total = CurrentUser.User.Person.Total;
  3173. int userId = CurrentUser.User.ID;
  3174. int noFinish = CurrentUser.User.Person.NoFinish;
  3175. int finalization = CurrentUser.User.Person.Finalization;
  3176. string eids = GetPostString("ctid");
  3177. string key = "RushKey_" + userId;
  3178. int count = 0;
  3179. if (erpRedis.RedisHelper.KeyExists(key))
  3180. {
  3181. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3182. if (redisCount != null)
  3183. {
  3184. count = Convert.ToInt32(redisCount);
  3185. }
  3186. }
  3187. if (count >= total)
  3188. {
  3189. returnErrorMsg("半小时内已经抢" + total + "单");
  3190. return;
  3191. }
  3192. string[] ctidlist = eids.Split(',');
  3193. if (count + ctidlist.Length > total)
  3194. {
  3195. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3196. return;
  3197. }
  3198. int itag = 0;
  3199. lock (rushLockObject)
  3200. {
  3201. if (ctidlist.Length > 0)
  3202. {
  3203. string[] dtList = new string[ctidlist.Length];
  3204. for (int i = 0; i < ctidlist.Length; i++)
  3205. {
  3206. dtList[i] = "'" + ctidlist[i] + "'";
  3207. }
  3208. 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"));
  3209. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3210. if (dt_user.Rows.Count > 0)
  3211. {
  3212. int doing = 0;//未定稿
  3213. int finish = 0;//已完成
  3214. foreach (DataRow dr in dt_user.Rows)
  3215. {
  3216. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3217. {
  3218. doing++;
  3219. }
  3220. else
  3221. {
  3222. finish++;
  3223. }
  3224. }
  3225. if (doing >= noFinish)
  3226. {
  3227. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3228. return;
  3229. }
  3230. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3231. {
  3232. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3233. return;
  3234. }
  3235. }
  3236. //校验选择单子状态
  3237. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3238. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3239. if (dt.Rows.Count > 0)
  3240. {
  3241. List<string> list = new List<string>();
  3242. foreach (DataRow dr in dt.Rows)
  3243. {
  3244. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3245. {
  3246. list.Add(dr["ctid"].ToString());
  3247. }
  3248. }
  3249. if (list.Count > 0)
  3250. {
  3251. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3252. return;
  3253. }
  3254. }
  3255. foreach (string ctid in ctidlist)
  3256. {
  3257. CeErpTradeCell entity = null;
  3258. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3259. if (entity != null)
  3260. {
  3261. entity.OrderState = 3;
  3262. entity.DesignUserId = CurrentUser.UserID;
  3263. entity.WaitDesignTime = DateTime.Now;
  3264. entity.StartDesignTime = DateTime.Now;
  3265. entity.Update();
  3266. commonHelper.UpdateRelationOrder(entity.ctid);
  3267. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3268. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3269. itag++;
  3270. }
  3271. }
  3272. }
  3273. }
  3274. count += ctidlist.Length;
  3275. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3276. if (itag == 0)
  3277. returnErrorMsg("没有找到相关订单");
  3278. else
  3279. returnSuccessMsg("抢单成功!");
  3280. return;
  3281. }
  3282. }
  3283. public void get_erp_waitorderlist()
  3284. {
  3285. DataStruct dStruct = GetPostStruct();
  3286. List<string> lw = new List<string>();
  3287. string tid = GetPostString("ctid");
  3288. if (tid.Length > 0)
  3289. {
  3290. string select_tid = getTidByCtid(tid);
  3291. lw.Add(string.Format("tid='{0}'", select_tid));
  3292. }
  3293. string shopname = GetPostString("shopname");
  3294. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3295. string buyernick = GetPostString("buyer_nick");
  3296. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3297. string customer = GetPostString("customer");
  3298. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3299. string design = GetPostString("design");
  3300. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3301. string orderState = GetPostString("orderState");
  3302. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3303. string supplier = GetPostString("supplier");
  3304. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3305. string sellermemo = GetPostString("seller_memo");
  3306. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3307. string otherMemo = GetPostString("otherMemo");
  3308. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3309. string address = GetPostString("address");
  3310. 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));
  3311. string date1 = GetPostString("date1");
  3312. string date2 = GetPostString("date2");
  3313. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3314. if (dw.Length > 0) lw.Add(dw);
  3315. string price1 = GetPostString("price1");
  3316. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3317. string price2 = GetPostString("price2");
  3318. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3319. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3320. lw.Add(string.Format("IsSample != 2 "));
  3321. lw.Add(string.Format("OrderState = 5 "));
  3322. lw.Add(string.Format("IsRefund<={0}", 1));
  3323. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3324. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3325. string pagesize = GetPostString("pagesize");
  3326. if (pagesize != null)
  3327. {
  3328. dStruct.PageSize = 200;
  3329. }
  3330. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3331. if (dt != null)
  3332. {
  3333. foreach (DataRow dr in dt.Rows)
  3334. {
  3335. 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();
  3336. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3337. {
  3338. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3339. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3340. entity.SupplierId = suid;
  3341. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3342. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3343. entity.Update();
  3344. }
  3345. }
  3346. }
  3347. writeGridDataTableJson(dStruct.TotalCount, dt);
  3348. }
  3349. public void get_erp_supplierwaitorderlist()
  3350. {
  3351. DataStruct dStruct = GetPostStruct();
  3352. List<string> lw = new List<string>();
  3353. string tid = GetPostString("ctid");
  3354. if (tid.Length > 0)
  3355. {
  3356. string select_tid = getTidByCtid(tid);
  3357. lw.Add(string.Format("tid='{0}'", select_tid));
  3358. }
  3359. string shopname = GetPostString("shopname");
  3360. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3361. string sellermemo = GetPostString("seller_memo");
  3362. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3363. string date1 = GetPostString("date1");
  3364. string date2 = GetPostString("date2");
  3365. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3366. if (dw.Length > 0) lw.Add(dw);
  3367. lw.Add(string.Format("OrderState = 5 "));
  3368. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3369. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3370. {
  3371. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3372. }
  3373. string supplier = GetPostString("supplier");
  3374. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3375. {
  3376. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3377. }
  3378. lw.Add(string.Format("IsRefund<={0}", 1));
  3379. dStruct.Order = "FinishDesignTime desc";
  3380. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3381. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3382. if (dt != null)
  3383. {
  3384. foreach (DataRow dr in dt.Rows)
  3385. {
  3386. 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();
  3387. }
  3388. }
  3389. writeGridDataTableJson(dStruct.TotalCount, dt);
  3390. }
  3391. public void upd_erp_verifytosupplier()
  3392. {
  3393. if (UrlPostParmsCheck("ctid"))
  3394. {
  3395. string eids = GetPostString("ctid");
  3396. CeErpTradeCell entity = null;
  3397. string[] eidsList = eids.Split(',');
  3398. if (eidsList.Length <= 0)
  3399. {
  3400. returnErrorMsg("订单号不能空");
  3401. return;
  3402. }
  3403. List<string> tLst = new List<string>();
  3404. foreach (string ctidstr in eidsList)
  3405. {
  3406. tLst.Add("'" + ctidstr + "'");
  3407. CeErpDataSendOrderInfo.createObject(ctidstr);
  3408. }
  3409. string needtids = string.Join(",", tLst.ToArray());
  3410. StringBuilder sql = new StringBuilder();
  3411. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3412. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3413. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3414. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3415. returnSuccessMsg("操作成功!");
  3416. return;
  3417. /**foreach (string ctidstr in eidsList)
  3418. {
  3419. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3420. if (entity != null)
  3421. {
  3422. if (entity.SupplierId == 0)
  3423. {
  3424. continue;
  3425. }
  3426. entity.IsVerifyToSupplier = true;
  3427. if (entity.IsReturn == 1) //1是供应商打回
  3428. {
  3429. entity.IsReturn = 0;
  3430. }
  3431. entity.FinishPlaceTime = DateTime.Now;
  3432. entity.PlaceUserId = CurrentUser.UserID;
  3433. entity.Update();
  3434. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3435. }
  3436. }
  3437. returnSuccessMsg("操作成功!");
  3438. return;**/
  3439. }
  3440. }
  3441. public void upd_erp_supplierback()
  3442. {
  3443. if (UrlPostParmsCheck("ctid"))
  3444. {
  3445. string eid = GetPostString("ctid");
  3446. string reason = GetPostString("returnreason");
  3447. CeErpTradeCell entity = null;
  3448. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3449. if (entity != null)
  3450. {
  3451. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3452. {
  3453. string key = "return_order_" + entity.SupplierId;
  3454. List<string> list = new List<string>();
  3455. if (RedisHelper.HasKey(key))
  3456. {
  3457. object data = RedisHelper.StringGet(key);
  3458. list = Convert.ToString(data).Split(',').ToList();
  3459. }
  3460. list.Add(eid);
  3461. RedisHelper.StringSet(key, string.Join(",", list));
  3462. }
  3463. entity.IsVerifyToSupplier = false;
  3464. entity.IsReturn = 1;
  3465. entity.ReturnTime = DateTime.Now;
  3466. entity.ReturnReason = reason;
  3467. if (entity.OrderState == 6)
  3468. {
  3469. entity.OrderState = 5;
  3470. }
  3471. entity.Update();
  3472. CeErpSukuraData.createInfo(entity.ctid, 5);
  3473. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3474. returnSuccessMsg("操作成功!");
  3475. return;
  3476. }
  3477. returnErrorMsg("找不到订单记录");
  3478. }
  3479. }
  3480. public void upd_erp_toaftersaleorder()
  3481. {
  3482. if (UrlPostParmsCheck("ctid"))
  3483. {
  3484. string eid = GetPostString("ctid");
  3485. string reason = GetPostString("returnreason");
  3486. CeErpTradeCell entity = null;
  3487. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3488. if (entity != null)
  3489. {
  3490. if (entity.isAfterSaleOrder != 1)
  3491. {
  3492. returnErrorMsg("带S的售后单才能打回给售后");
  3493. return;
  3494. }
  3495. if (entity.OrderState >= 5)
  3496. {
  3497. returnErrorMsg("已经设计完成了不能打回给售后");
  3498. return;
  3499. }
  3500. entity.OrderState = 0;
  3501. entity.IsReturn = 3;
  3502. entity.ReturnTime = DateTime.Now;
  3503. entity.UpdateTime = DateTime.Now;
  3504. entity.ReturnReason = reason;
  3505. entity.Update();
  3506. CeErpSukuraData.createInfo(entity.ctid, 5);
  3507. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3508. returnSuccessMsg("操作成功!");
  3509. return;
  3510. }
  3511. returnErrorMsg("找不到订单记录");
  3512. }
  3513. }
  3514. public void upd_erp_aftersaletodesign()
  3515. {
  3516. if (UrlPostParmsCheck("ctid"))
  3517. {
  3518. string eid = GetPostString("ctid");
  3519. CeErpTradeCell entity = null;
  3520. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3521. if (entity != null)
  3522. {
  3523. entity.OrderState = 3;
  3524. entity.IsReturn = 0;
  3525. entity.UpdateTime = DateTime.Now;
  3526. entity.Update();
  3527. CeErpSukuraData.createInfo(entity.ctid, 5);
  3528. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3529. returnSuccessMsg("操作成功!");
  3530. return;
  3531. }
  3532. returnErrorMsg("找不到订单记录");
  3533. }
  3534. }
  3535. public void assign_erp_supplier()
  3536. {
  3537. if (UrlPostParmsCheck("ctid"))
  3538. {
  3539. string eids = GetPostString("ctid");
  3540. int sid = GetPostInt("SupplierName");
  3541. string fromTag = GetPostString("tag");
  3542. string[] eidList = eids.Split(',');
  3543. if (eidList.Length <= 0)
  3544. {
  3545. returnErrorMsg("指派不能为空");
  3546. return;
  3547. }
  3548. string errMsg = "";
  3549. string suname = commonHelper.getSupplierNameById(sid);
  3550. foreach (string ctid in eidList)
  3551. {
  3552. CeErpTradeCell entity = null;
  3553. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3554. if (entity != null)
  3555. {
  3556. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3557. {
  3558. errMsg += (ctid + "指派失败!!!");
  3559. continue;
  3560. }
  3561. entity.SupplierId = sid;
  3562. entity.Update();
  3563. commonHelper.UpdateRelationOrder(entity.ctid);
  3564. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3565. if (entity.OrderState >= 6)
  3566. {
  3567. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3568. //{
  3569. // string msl = entity.MakeSupplier;
  3570. // string[] mslist = msl.Split(',');
  3571. // 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);
  3572. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3573. //}
  3574. //else
  3575. //{
  3576. StringBuilder sql = new StringBuilder();
  3577. 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);
  3578. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3579. //}
  3580. }
  3581. }
  3582. else
  3583. {
  3584. continue;
  3585. }
  3586. }
  3587. if (errMsg.Length > 0)
  3588. {
  3589. returnErrorMsg(errMsg);
  3590. return;
  3591. }
  3592. returnSuccessMsg("操作成功!");
  3593. return;
  3594. }
  3595. }
  3596. public void assign_erp_makesupplier()
  3597. {
  3598. if (UrlPostParmsCheck("ctid"))
  3599. {
  3600. string eids = GetPostString("ctid");
  3601. string sname = GetPostString("SupplierName");
  3602. string[] eidList = eids.Split(',');
  3603. if (eidList.Length <= 0)
  3604. {
  3605. returnErrorMsg("指派不能为空");
  3606. return;
  3607. }
  3608. List<string> tLst = new List<string>();
  3609. foreach (string ctid in eidList)
  3610. {
  3611. CeErpTradeCell entity = null;
  3612. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3613. if (entity != null)
  3614. {
  3615. entity.MakeSupplier = sname;
  3616. entity.Update();
  3617. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3618. tLst.Add("'" + ctid + "'");
  3619. }
  3620. else
  3621. {
  3622. continue;
  3623. }
  3624. }
  3625. string ctids = string.Join(",", tLst.ToArray());
  3626. StringBuilder sql2 = new StringBuilder();
  3627. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3628. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3629. returnSuccessMsg("操作成功!");
  3630. return;
  3631. }
  3632. }
  3633. public void ins_erp_returnreason()
  3634. {
  3635. if (UrlPostParmsCheck("ctid"))
  3636. {
  3637. string eid = GetPostString("ctid");
  3638. CeErpTradeCell entity = null;
  3639. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3640. string userpost = CurrentUser.UserPost.Post.Code;
  3641. if (entity != null)
  3642. {
  3643. bool isPlace = false;
  3644. if (entity.OrderState > 6)
  3645. {
  3646. returnErrorMsg("已发货无法打回!");
  3647. return;
  3648. }
  3649. if (entity.OrderState == 6)
  3650. {
  3651. isPlace = true;
  3652. }
  3653. bool isNeedUpdateCell2 = false;
  3654. if (entity.OrderState >= 6)
  3655. {
  3656. isNeedUpdateCell2 = true;
  3657. }
  3658. int returnTag = 2;
  3659. if (userpost == "Supplier")
  3660. {
  3661. returnTag = 1;
  3662. }
  3663. int toType = GetPostInt("totype");
  3664. string fromType = "3";
  3665. if (entity.OrderState < 5)
  3666. {
  3667. fromType = "3";
  3668. }
  3669. else
  3670. {
  3671. fromType = "4";
  3672. }
  3673. if (entity.IsXianHuo == 0)
  3674. {
  3675. if (returnTag == 2)
  3676. {
  3677. if (toType == 1)
  3678. {
  3679. entity.OrderState = 0;
  3680. entity.ReturnUserType = 1;
  3681. string clearman = GetPostString("clearman");
  3682. if (!string.IsNullOrEmpty(clearman))
  3683. {
  3684. entity.DesignUserId = 0;
  3685. }
  3686. }
  3687. else
  3688. {
  3689. entity.OrderState = 3;
  3690. entity.ReturnUserType = 2;
  3691. }
  3692. entity.IsReadTag = 1;
  3693. }
  3694. else if (returnTag == 1)
  3695. {
  3696. entity.OrderState = 5;
  3697. }
  3698. entity.IsVerifyToSupplier = false;
  3699. }
  3700. if (entity.IsXianHuo == 1)
  3701. {
  3702. entity.OrderState = 5;
  3703. }
  3704. entity.UnusualTag = 0;
  3705. entity.UnusualTime = null;
  3706. entity.UnusualCon = "";
  3707. entity.IsReturn = returnTag;
  3708. entity.ReturnTime = DateTime.Now;
  3709. entity.UpdateTime = DateTime.Now;
  3710. entity.ReturnReason = GetPostString("returnreason");
  3711. entity.Update();
  3712. if (entity.OrderState == 3)
  3713. {
  3714. ApiVo apiVo = new ApiVo();
  3715. apiVo.orderNumber = entity.ctid;
  3716. apiVo.actionName = "rebutDesign";
  3717. apiVo.orderRemarks = entity.ReturnReason;
  3718. designHelper.API_WorkCore(apiVo);//rebutDesign
  3719. }
  3720. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3721. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3722. {
  3723. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3724. }
  3725. CeErpSukuraData.createInfo(entity.ctid, 5);
  3726. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3727. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3728. if (isPlace)
  3729. {
  3730. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3731. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3732. if (dth != null && dth.Rows.Count > 0)
  3733. {
  3734. dataSendOrderBean dataSendOrderBean = null;
  3735. foreach (DataRow item in dth.Rows)
  3736. {
  3737. try
  3738. {
  3739. dataSendOrderBean = new dataSendOrderBean();
  3740. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3741. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3742. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3743. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3744. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3745. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3746. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3747. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3748. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3749. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3750. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3751. dataSendOrderBean.Radio1723534706288 = "打回";
  3752. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3753. if (result != null)
  3754. {
  3755. if ("0".Equals(result.errcode))
  3756. {
  3757. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3758. }
  3759. else
  3760. {
  3761. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3762. }
  3763. }
  3764. }
  3765. catch (Exception ex)
  3766. {
  3767. }
  3768. }
  3769. }
  3770. }
  3771. if (isNeedUpdateCell2)
  3772. {
  3773. if (entity.MakeSupplier.IndexOf(",") != -1)
  3774. {
  3775. StringBuilder sql2 = new StringBuilder();
  3776. 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);
  3777. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3778. }
  3779. else
  3780. {
  3781. StringBuilder sql2 = new StringBuilder();
  3782. 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);
  3783. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3784. }
  3785. }
  3786. returnSuccessMsg("操作成功!");
  3787. return;
  3788. }
  3789. returnErrorMsg("找不到订单记录");
  3790. }
  3791. }
  3792. public void cyt_erp_returnreason()
  3793. {
  3794. if (UrlPostParmsCheck("ctid"))
  3795. {
  3796. string eid = GetPostString("ctid");
  3797. CeErpTradeCell entity = null;
  3798. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3799. string userpost = CurrentUser.UserPost.Post.Code;
  3800. if (entity != null)
  3801. {
  3802. if (entity.OrderState > 6)
  3803. {
  3804. returnErrorMsg("已发货无法打回!");
  3805. return;
  3806. }
  3807. JObject jsonObject = new JObject
  3808. {
  3809. { "Userid", "77886" },
  3810. { "Pwd", "lt666888" },
  3811. { "LTOrderId",eid }
  3812. };
  3813. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3814. JObject jsonObjects = JObject.Parse(response);
  3815. string msg = (string)jsonObjects["msg"];
  3816. if (msg != "取消成功")
  3817. {
  3818. returnErrorMsg(msg);
  3819. return;
  3820. }
  3821. bool isNeedUpdateCell2 = false;
  3822. if (entity.OrderState >= 6)
  3823. {
  3824. isNeedUpdateCell2 = true;
  3825. }
  3826. int returnTag = 2;
  3827. if (userpost == "Supplier")
  3828. {
  3829. returnTag = 1;
  3830. }
  3831. if (entity.IsXianHuo == 0)
  3832. {
  3833. if (returnTag == 2)
  3834. {
  3835. int toType = GetPostInt("totype");
  3836. if (toType == 1)
  3837. {
  3838. entity.OrderState = 0;
  3839. entity.ReturnUserType = 1;
  3840. }
  3841. else
  3842. {
  3843. entity.OrderState = 4;
  3844. entity.ReturnUserType = 2;
  3845. }
  3846. entity.IsReadTag = 1;
  3847. }
  3848. else if (returnTag == 1)
  3849. {
  3850. entity.OrderState = 5;
  3851. }
  3852. entity.IsVerifyToSupplier = false;
  3853. }
  3854. entity.UnusualTag = 0;
  3855. entity.UnusualTime = null;
  3856. entity.UnusualCon = "";
  3857. entity.IsReturn = returnTag;
  3858. entity.ReturnTime = DateTime.Now;
  3859. entity.ReturnReason = GetPostString("returnreason");
  3860. entity.Update();
  3861. if (entity.OrderState == 4)
  3862. {
  3863. ApiVo apiVo = new ApiVo();
  3864. apiVo.orderNumber = entity.ctid;
  3865. apiVo.actionName = "rebutDesign";
  3866. apiVo.orderRemarks = entity.ReturnReason;
  3867. designHelper.API_WorkCore(apiVo);//rebutDesign
  3868. }
  3869. CeErpSukuraData.createInfo(entity.ctid, 5);
  3870. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3871. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3872. if (isNeedUpdateCell2)
  3873. {
  3874. if (entity.MakeSupplier.IndexOf(",") != -1)
  3875. {
  3876. StringBuilder sql2 = new StringBuilder();
  3877. 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);
  3878. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3879. }
  3880. else
  3881. {
  3882. StringBuilder sql2 = new StringBuilder();
  3883. 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);
  3884. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3885. }
  3886. }
  3887. returnSuccessMsg("操作成功!");
  3888. return;
  3889. }
  3890. returnErrorMsg("找不到订单记录");
  3891. }
  3892. }
  3893. public void upd_erp_xianhuoreturntag()
  3894. {
  3895. if (UrlPostParmsCheck("ctid"))
  3896. {
  3897. string eids = GetPostString("ctid");
  3898. string[] ctids = eids.Split(',');
  3899. foreach (string ctid in ctids)
  3900. {
  3901. CeErpTradeCell entity = null;
  3902. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3903. if (entity != null)
  3904. {
  3905. entity.IsReturn = 0;
  3906. entity.Update();
  3907. CeErpSukuraData.createInfo(entity.ctid, 5);
  3908. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3909. }
  3910. }
  3911. returnSuccessMsg("操作成功!");
  3912. return;
  3913. }
  3914. }
  3915. public void get_erp_waitdeliverylist()
  3916. {
  3917. DataStruct dStruct = GetPostStruct();
  3918. List<string> lw = new List<string>();
  3919. string tid = GetPostString("ctid");
  3920. if (tid.Length > 0)
  3921. {
  3922. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3923. if (tid.Length > 5)
  3924. {
  3925. List<string> tids = getTidByCtidLike(tid);
  3926. if (tids.Count > 0 && tids.Count < 10)
  3927. {
  3928. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3929. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  3930. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  3931. {
  3932. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  3933. }
  3934. }
  3935. }
  3936. lw.Add(tid_sql);
  3937. }
  3938. string shopname = GetPostString("shopname");
  3939. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3940. string buyernick = GetPostString("buyer_nick");
  3941. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3942. //if (tid.Length == 0 && buyernick.Length == 0)
  3943. //{
  3944. // lw.Add(string.Format("IsRefund<={0}", 1));
  3945. //}
  3946. string customer = GetPostString("customer");
  3947. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3948. string design = GetPostString("design");
  3949. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3950. string orderState = GetPostString("orderState");
  3951. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3952. string address = GetPostString("address");
  3953. 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));
  3954. string sellermemo = GetPostString("seller_memo");
  3955. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3956. string supplier = GetPostString("supplier");
  3957. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3958. string OrderArea = GetPostString("order_area");
  3959. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3960. string placedate1 = GetPostString("placedate1");
  3961. string placedate2 = GetPostString("placedate2");
  3962. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3963. if (fdw.Length > 0) lw.Add(fdw);
  3964. string price1 = GetPostString("price1");
  3965. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3966. string price2 = GetPostString("price2");
  3967. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3968. string unusualCon = GetPostString("unusualcon");
  3969. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3970. string otherMemo = GetPostString("otherMemo");
  3971. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3972. string posTag = CurrentUser.UserPost.Post.Code;
  3973. if (posTag == "Supplier")
  3974. {
  3975. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3976. }
  3977. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  3978. lw.Add(string.Format("type != 'PDD' "));
  3979. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3980. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3981. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3982. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3983. writeGridDataTableJson(dStruct.TotalCount, dt);
  3984. }
  3985. public void get_erp_changedeliverylist()
  3986. {
  3987. DataStruct dStruct = GetPostStruct();
  3988. List<string> lw = new List<string>();
  3989. string tid = GetPostString("ctid");
  3990. if (tid.Length > 0)
  3991. {
  3992. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3993. if (tid.Length > 5)
  3994. {
  3995. List<string> tids = getTidByCtidLike(tid);
  3996. if (tids.Count > 0 && tids.Count < 10)
  3997. {
  3998. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3999. }
  4000. }
  4001. lw.Add(tid_sql);
  4002. }
  4003. string shopname = GetPostString("shopname");
  4004. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4005. string buyernick = GetPostString("buyer_nick");
  4006. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4007. //if (tid.Length == 0 && buyernick.Length == 0)
  4008. //{
  4009. // lw.Add(string.Format("IsRefund<={0}", 1));
  4010. //}
  4011. string customer = GetPostString("customer");
  4012. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4013. string design = GetPostString("design");
  4014. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4015. string orderState = GetPostString("orderState");
  4016. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4017. string address = GetPostString("address");
  4018. 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));
  4019. string sellermemo = GetPostString("seller_memo");
  4020. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4021. string supplier = GetPostString("supplier");
  4022. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4023. string OrderArea = GetPostString("order_area");
  4024. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4025. string placedate1 = GetPostString("placedate1");
  4026. string placedate2 = GetPostString("placedate2");
  4027. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4028. if (fdw.Length > 0) lw.Add(fdw);
  4029. string price1 = GetPostString("price1");
  4030. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4031. string price2 = GetPostString("price2");
  4032. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4033. string unusualCon = GetPostString("unusualcon");
  4034. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4035. string otherMemo = GetPostString("otherMemo");
  4036. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4037. string posTag = CurrentUser.UserPost.Post.Code;
  4038. if (posTag == "Supplier")
  4039. {
  4040. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4041. }
  4042. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4043. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4044. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4045. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4046. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4047. /*if (tid.Length > 0)
  4048. {
  4049. List<string> tids = new List<string>();
  4050. if (dt != null && dt.Rows.Count > 0)
  4051. {
  4052. foreach (DataRow item in dt.Rows)
  4053. {
  4054. tids.Add("'" + item["tid"] + "'");
  4055. }
  4056. }
  4057. if (tids.Count > 0)
  4058. {
  4059. lw.RemoveAt(0);
  4060. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4061. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4062. dt = WebCache.GetData("view_erptradecell", dStruct);
  4063. }
  4064. }*/
  4065. writeGridDataTableJson(dStruct.TotalCount, dt);
  4066. }
  4067. public void get_erp_pddderiving()
  4068. {
  4069. DataStruct dStruct = GetPostStruct();
  4070. List<string> lw = new List<string>();
  4071. string tid = GetPostString("ctid");
  4072. if (tid.Length > 0)
  4073. {
  4074. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4075. if (tid.Length > 5)
  4076. {
  4077. List<string> tids = getTidByCtidLike(tid);
  4078. if (tids.Count > 0 && tids.Count < 10)
  4079. {
  4080. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4081. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4082. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4083. {
  4084. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4085. }
  4086. }
  4087. }
  4088. lw.Add(tid_sql);
  4089. }
  4090. string shopname = GetPostString("shopname");
  4091. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4092. string buyernick = GetPostString("buyer_nick");
  4093. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4094. //if (tid.Length == 0 && buyernick.Length == 0)
  4095. //{
  4096. // lw.Add(string.Format("IsRefund<={0}", 1));
  4097. //}
  4098. string customer = GetPostString("customer");
  4099. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4100. string design = GetPostString("design");
  4101. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4102. string orderState = GetPostString("orderState");
  4103. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4104. string address = GetPostString("address");
  4105. 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));
  4106. string sellermemo = GetPostString("seller_memo");
  4107. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4108. string supplier = GetPostString("supplier");
  4109. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4110. string OrderArea = GetPostString("order_area");
  4111. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4112. string placedate1 = GetPostString("placedate1");
  4113. string placedate2 = GetPostString("placedate2");
  4114. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4115. if (fdw.Length > 0) lw.Add(fdw);
  4116. string price1 = GetPostString("price1");
  4117. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4118. string price2 = GetPostString("price2");
  4119. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4120. string unusualCon = GetPostString("unusualcon");
  4121. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4122. string posTag = CurrentUser.UserPost.Post.Code;
  4123. if (posTag == "Supplier")
  4124. {
  4125. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4126. }
  4127. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4128. lw.Add(string.Format("type = 'PDD' "));
  4129. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4130. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4131. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4132. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4133. /*if (tid.Length > 0)
  4134. {
  4135. List<string> tids = new List<string>();
  4136. if (dt != null && dt.Rows.Count > 0)
  4137. {
  4138. foreach (DataRow item in dt.Rows)
  4139. {
  4140. tids.Add("'" + item["tid"] + "'");
  4141. }
  4142. }
  4143. if (tids.Count > 0)
  4144. {
  4145. lw.RemoveAt(0);
  4146. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4147. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4148. dt = WebCache.GetData("view_erptradecell", dStruct);
  4149. }
  4150. }*/
  4151. writeGridDataTableJson(dStruct.TotalCount, dt);
  4152. }
  4153. public void get_erp_jdderiving()
  4154. {
  4155. DataStruct dStruct = GetPostStruct();
  4156. List<string> lw = new List<string>();
  4157. string tid = GetPostString("ctid");
  4158. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4159. string shopname = GetPostString("shopname");
  4160. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4161. string buyernick = GetPostString("buyer_nick");
  4162. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4163. //if (tid.Length == 0 && buyernick.Length == 0)
  4164. //{
  4165. // lw.Add(string.Format("IsRefund<={0}", 1));
  4166. //}
  4167. string customer = GetPostString("customer");
  4168. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4169. string design = GetPostString("design");
  4170. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4171. string orderState = GetPostString("orderState");
  4172. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4173. string address = GetPostString("address");
  4174. 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));
  4175. string sellermemo = GetPostString("seller_memo");
  4176. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4177. string supplier = GetPostString("supplier");
  4178. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4179. string OrderArea = GetPostString("order_area");
  4180. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4181. string placedate1 = GetPostString("placedate1");
  4182. string placedate2 = GetPostString("placedate2");
  4183. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4184. if (fdw.Length > 0) lw.Add(fdw);
  4185. string price1 = GetPostString("price1");
  4186. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4187. string price2 = GetPostString("price2");
  4188. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4189. string unusualCon = GetPostString("unusualcon");
  4190. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4191. string posTag = CurrentUser.UserPost.Post.Code;
  4192. if (posTag == "Supplier")
  4193. {
  4194. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4195. }
  4196. lw.Add(string.Format("OrderState = 6 "));
  4197. lw.Add(string.Format("type = 'JD' "));
  4198. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4199. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4200. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4201. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4202. writeGridDataTableJson(dStruct.TotalCount, dt);
  4203. }
  4204. public void get_erp_demoorderlist()
  4205. {
  4206. DataStruct dStruct = GetPostStruct();
  4207. List<string> lw = new List<string>();
  4208. string tid = GetPostString("ctid");
  4209. if (tid.Length > 0)
  4210. {
  4211. string select_tid = getTidByCtid(tid);
  4212. lw.Add(string.Format("tid='{0}'", select_tid));
  4213. }
  4214. string shopname = GetPostString("shopname");
  4215. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4216. string buyernick = GetPostString("buyer_nick");
  4217. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4218. string customer = GetPostString("customer");
  4219. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4220. string design = GetPostString("design");
  4221. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4222. string orderState = GetPostString("orderState");
  4223. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4224. string address = GetPostString("address");
  4225. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4226. string sellermemo = GetPostString("seller_memo");
  4227. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4228. string supplier = GetPostString("supplier");
  4229. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4230. string OrderArea = GetPostString("order_area");
  4231. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4232. string date1 = GetPostString("date1");
  4233. string date2 = GetPostString("date2");
  4234. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4235. if (dw.Length > 0) lw.Add(dw);
  4236. string price1 = GetPostString("price1");
  4237. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4238. string price2 = GetPostString("price2");
  4239. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4240. string posTag = CurrentUser.UserPost.Post.Code;
  4241. if (posTag == "Supplier")
  4242. {
  4243. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4244. }
  4245. //lw.Add(string.Format("OrderState = 6 "));
  4246. lw.Add(string.Format("IsSample={0}", 3));
  4247. lw.Add(string.Format("IsRefund<={0}", 1));
  4248. dStruct.Order = "pay_time desc";
  4249. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4250. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4251. writeGridDataTableJson(dStruct.TotalCount, dt);
  4252. }
  4253. public void save_erp_checkmemo()
  4254. {
  4255. if (UrlPostParmsCheck("ctid"))
  4256. {
  4257. string ctid = GetPostString("ctid");
  4258. CeErpTradeCell entity = null;
  4259. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4260. if (entity != null)
  4261. {
  4262. entity.CheckMemo = GetPostString("CheckMemo");
  4263. entity.Update();
  4264. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4265. if (trade != null)
  4266. {
  4267. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4268. }
  4269. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4270. returnSuccessMsg("保存成功!");
  4271. return;
  4272. }
  4273. returnErrorMsg("找不到记录");
  4274. }
  4275. }
  4276. public void get_erp_returnlist()
  4277. {
  4278. DataStruct dStruct = GetPostStruct();
  4279. List<string> lw = new List<string>();
  4280. string tid = GetPostString("ctid");
  4281. if (tid.Length > 0)
  4282. {
  4283. string select_tid = getTidByCtid(tid);
  4284. lw.Add(string.Format("tid='{0}'", select_tid));
  4285. }
  4286. string shopname = GetPostString("shopname");
  4287. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4288. string buyernick = GetPostString("buyer_nick");
  4289. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4290. string customer = GetPostString("customer");
  4291. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4292. string design = GetPostString("design");
  4293. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4294. string orderState = GetPostString("orderState");
  4295. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4296. string address = GetPostString("address");
  4297. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4298. string sellermemo = GetPostString("seller_memo");
  4299. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4300. string supplier = GetPostString("supplier");
  4301. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4302. string date1 = GetPostString("date1");
  4303. string date2 = GetPostString("date2");
  4304. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4305. if (dw.Length > 0) lw.Add(dw);
  4306. string bdate1 = GetPostString("backdate1");
  4307. string bdate2 = GetPostString("backdate2");
  4308. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4309. if (dw_back.Length > 0) lw.Add(dw_back);
  4310. string price1 = GetPostString("price1");
  4311. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4312. string price2 = GetPostString("price2");
  4313. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4314. lw.Add(string.Format("IsReturn>0"));
  4315. lw.Add(string.Format("IsXianHuo=0"));
  4316. lw.Add(string.Format("IsReturn!=3"));
  4317. string backtype = GetPostString("backtype");
  4318. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4319. dStruct.Order = "FinishDesignTime desc";
  4320. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4321. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4322. writeGridDataTableJson(dStruct.TotalCount, dt);
  4323. }
  4324. public void get_erp_today_sumreturn()
  4325. {
  4326. DataStruct dStruct = GetPostStruct();
  4327. List<string> lw = new List<string>();
  4328. string bdate1 = GetPostString("returnTimeS");
  4329. string bdate2 = GetPostString("returnTimeE");
  4330. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4331. if (dw_back.Length > 0) lw.Add(dw_back);
  4332. lw.Add(string.Format("IsReturn=0"));
  4333. lw.Add(string.Format("IsXianHuo=0"));
  4334. string mainWhere = string.Join(" and ", lw.ToArray());
  4335. string sql = "";
  4336. if (dw_back.Length > 0)
  4337. {
  4338. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4339. }
  4340. else
  4341. {
  4342. 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 + "'";
  4343. }
  4344. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4345. decimal total = 0, today_finish = 0;
  4346. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4347. {
  4348. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4349. }
  4350. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4351. {
  4352. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4353. }
  4354. var res = new
  4355. {
  4356. data = total,
  4357. data1 = today_finish,
  4358. };
  4359. string ro_jsond = JsonConvert.SerializeObject(res);
  4360. returnSuccess(ro_jsond);
  4361. return;
  4362. }
  4363. public void get_erp_allreturnlist()
  4364. {
  4365. DataStruct dStruct = GetPostStruct();
  4366. List<string> lw = new List<string>();
  4367. string tid = GetPostString("ctid");
  4368. if (tid.Length > 0)
  4369. {
  4370. string select_tid = getTidByCtid(tid);
  4371. lw.Add(string.Format("tid='{0}'", select_tid));
  4372. }
  4373. string shopname = GetPostString("shopname");
  4374. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4375. string buyernick = GetPostString("buyer_nick");
  4376. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4377. string customer = GetPostString("customer");
  4378. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4379. string design = GetPostString("design");
  4380. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4381. string orderState = GetPostString("orderState");
  4382. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4383. string address = GetPostString("address");
  4384. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4385. string sellermemo = GetPostString("seller_memo");
  4386. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4387. string supplier = GetPostString("supplier");
  4388. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4389. string date1 = GetPostString("date1");
  4390. string date2 = GetPostString("date2");
  4391. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4392. if (dw.Length > 0) lw.Add(dw);
  4393. string bdate1 = GetPostString("backdate1");
  4394. string bdate2 = GetPostString("backdate2");
  4395. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4396. if (dw_back.Length > 0) lw.Add(dw_back);
  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 backreason = GetPostString("backreason");
  4402. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4403. lw.Add(string.Format("IsXianHuo=0"));
  4404. lw.Add(string.Format("ReturnTime != ''"));
  4405. string backtype = GetPostString("backtype");
  4406. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4407. dStruct.Order = "FinishDesignTime desc";
  4408. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4409. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4410. writeGridDataTableJson(dStruct.TotalCount, dt);
  4411. }
  4412. public void get_erp_aftersalereturnlist()
  4413. {
  4414. DataStruct dStruct = GetPostStruct();
  4415. List<string> lw = new List<string>();
  4416. string tid = GetPostString("ctid");
  4417. if (tid.Length > 0)
  4418. {
  4419. string select_tid = getTidByCtid(tid);
  4420. lw.Add(string.Format("tid='{0}'", select_tid));
  4421. }
  4422. string shopname = GetPostString("shopname");
  4423. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4424. string buyernick = GetPostString("buyer_nick");
  4425. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4426. string customer = GetPostString("customer");
  4427. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4428. string design = GetPostString("design");
  4429. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4430. string orderState = GetPostString("orderState");
  4431. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4432. string address = GetPostString("address");
  4433. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4434. string sellermemo = GetPostString("seller_memo");
  4435. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4436. string supplier = GetPostString("supplier");
  4437. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4438. string date1 = GetPostString("date1");
  4439. string date2 = GetPostString("date2");
  4440. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4441. if (dw.Length > 0) lw.Add(dw);
  4442. string bdate1 = GetPostString("backdate1");
  4443. string bdate2 = GetPostString("backdate2");
  4444. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4445. if (dw_back.Length > 0) lw.Add(dw_back);
  4446. string price1 = GetPostString("price1");
  4447. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4448. string price2 = GetPostString("price2");
  4449. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4450. lw.Add(string.Format("IsReturn=3"));
  4451. string backtype = GetPostString("backtype");
  4452. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4453. string backreason = GetPostString("backreason");
  4454. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4455. dStruct.Order = "ReturnTime desc";
  4456. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4457. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4458. writeGridDataTableJson(dStruct.TotalCount, dt);
  4459. }
  4460. public void get_erp_xianhuoreturnlist()
  4461. {
  4462. DataStruct dStruct = GetPostStruct();
  4463. List<string> lw = new List<string>();
  4464. string tid = GetPostString("ctid");
  4465. if (tid.Length > 0)
  4466. {
  4467. string select_tid = getTidByCtid(tid);
  4468. lw.Add(string.Format("tid='{0}'", select_tid));
  4469. }
  4470. string shopname = GetPostString("shopname");
  4471. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4472. string buyernick = GetPostString("buyer_nick");
  4473. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4474. string customer = GetPostString("customer");
  4475. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4476. string design = GetPostString("design");
  4477. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4478. string orderState = GetPostString("orderState");
  4479. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4480. string address = GetPostString("address");
  4481. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4482. string sellermemo = GetPostString("seller_memo");
  4483. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4484. string supplier = GetPostString("supplier");
  4485. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4486. string OrderArea = GetPostString("order_area");
  4487. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4488. string date1 = GetPostString("date1");
  4489. string date2 = GetPostString("date2");
  4490. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4491. if (dw.Length > 0) lw.Add(dw);
  4492. string price1 = GetPostString("price1");
  4493. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4494. string price2 = GetPostString("price2");
  4495. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4496. string posTag = CurrentUser.UserPost.Post.Code;
  4497. if (posTag == "Supplier")
  4498. {
  4499. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4500. }
  4501. lw.Add(string.Format("OrderState=6 "));
  4502. lw.Add(string.Format("IsXianHuo=1 "));
  4503. lw.Add(string.Format("IsReturn>0 "));
  4504. lw.Add(string.Format("IsReturn!=3"));
  4505. lw.Add(string.Format("IsRefund<={0}", 1));
  4506. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4507. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4508. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4509. writeGridDataTableJson(dStruct.TotalCount, dt);
  4510. }
  4511. public void set_erp_orderdelivery()
  4512. {
  4513. if (UrlPostParmsCheck("ctid"))
  4514. {
  4515. string eid = GetPostString("ctid");
  4516. CeErpTradeCell entity = null;
  4517. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4518. if (entity != null)
  4519. {
  4520. if (entity.OrderState >= 7)
  4521. {
  4522. returnErrorMsg("此单已发货,无需重复发货");
  4523. return;
  4524. }
  4525. if (entity.OrderState != 6)
  4526. {
  4527. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4528. return;
  4529. }
  4530. string shop = GetPostString("seller_nick");
  4531. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4532. string comName = GetPostString("comName");
  4533. string comCode = GetPostString("comCode");
  4534. string outSid = GetPostString("outSid");
  4535. string deliveryType = GetPostString("deliveryType");
  4536. string deliveryMemo = GetPostString("deliveryMemo");
  4537. outSid = outSid.Trim();
  4538. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4539. if (mainEn == null)
  4540. {
  4541. returnErrorMsg("找不到原始订单记录");
  4542. return;
  4543. }
  4544. bool isInitOrderDeliv = false;
  4545. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4546. {
  4547. isInitOrderDeliv = true;
  4548. }
  4549. string apires = "";
  4550. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4551. 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)
  4552. {
  4553. apires = "发货成功true";
  4554. }
  4555. else
  4556. {
  4557. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4558. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4559. }
  4560. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4561. {
  4562. entity.OrderState = 7;//发货后订单已发货
  4563. entity.OutSid = outSid;
  4564. entity.MemoOpt = 0;
  4565. entity.UpdateTime = DateTime.Now;
  4566. entity.FinishDeliveryTime = DateTime.Now;
  4567. entity.Update();
  4568. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4569. commonHelper.UpdateRelationOrder(entity.ctid);
  4570. //还要插入快递信息到 快递信息表
  4571. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4572. exinfo.tid = eid;
  4573. exinfo.out_sid = outSid;
  4574. exinfo.company_code = comCode;
  4575. exinfo.company_name = comName;
  4576. exinfo.delivery_memo = deliveryMemo;
  4577. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4578. exinfo.deliveryType = deliveryType;
  4579. exinfo.Create();
  4580. returnSuccessMsg("发货操作成功!");
  4581. commonHelper.UpdateRelationOrder(entity.ctid);
  4582. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4583. CeErpSukuraData.createInfo(entity.ctid, 4);
  4584. if (entity.SupplierId == 64)
  4585. {
  4586. commonHelper.sendCytExpress(exinfo);
  4587. }
  4588. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4589. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4590. }
  4591. else
  4592. {
  4593. string errmsg = commonHelper.KeepChinese(apires);
  4594. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4595. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4596. }
  4597. return;
  4598. }
  4599. returnErrorMsg("找不到订单记录");
  4600. }
  4601. }
  4602. public void set_erp_multidelivery()
  4603. {
  4604. string eids = GetPostString("tids");
  4605. string[] eidList = eids.Split(',');
  4606. if (eidList.Length <= 0)
  4607. {
  4608. returnErrorMsg("发货不能为空");
  4609. return;
  4610. }
  4611. foreach (string ctid in eidList)
  4612. {
  4613. if (ctid.Length <= 0) continue;
  4614. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4615. if (expInfo != null)
  4616. {
  4617. StringBuilder sql = new StringBuilder();
  4618. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4619. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4620. if (dt.Rows.Count > 0)
  4621. {
  4622. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4623. {
  4624. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4625. expInfo.state = "异常";
  4626. expInfo.isMultiDelivery = 1;
  4627. expInfo.Update();
  4628. continue;
  4629. }
  4630. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4631. {
  4632. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4633. expInfo.state = "异常";
  4634. expInfo.Update();
  4635. continue;
  4636. }
  4637. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4638. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4639. bool isInitOrderDeliv = false;
  4640. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4641. {
  4642. isInitOrderDeliv = true;
  4643. expInfo.isMultiDelivery = 1;
  4644. }
  4645. if (ctid.IndexOf("N") != -1)
  4646. {
  4647. StringBuilder sqlbucha = new StringBuilder();
  4648. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4649. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4650. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4651. commonHelper.UpdateRelationOrder(ctid);
  4652. expInfo.delivery_memo = "发货成功";
  4653. expInfo.state = "发货成功";
  4654. expInfo.isMultiDelivery = 1;
  4655. expInfo.Update();
  4656. }
  4657. else
  4658. {
  4659. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4660. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4661. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4662. {
  4663. expInfo.delivery_memo = "发货成功";
  4664. expInfo.state = "发货成功";
  4665. expInfo.isMultiDelivery = 1;
  4666. expInfo.Update();
  4667. commonHelper.UpdateRelationOrder(ctid);
  4668. CeErpSukuraData.createInfo(ctid, 4);
  4669. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4670. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4671. }
  4672. else
  4673. {
  4674. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4675. expInfo.state = "异常";
  4676. expInfo.Update();
  4677. }
  4678. }
  4679. }
  4680. }
  4681. }
  4682. returnSuccessMsg("操作完成");
  4683. }
  4684. public void reset_erp_memoopt()
  4685. {
  4686. if (UrlPostParmsCheck("ctid"))
  4687. {
  4688. string eid = GetPostString("ctid");
  4689. CeErpTradeCell entity = null;
  4690. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4691. if (entity != null)
  4692. {
  4693. string stropt = "";
  4694. if (entity.MemoOpt == 1)
  4695. {
  4696. stropt = "“改稿”";
  4697. }
  4698. else if (entity.MemoOpt == 2)
  4699. {
  4700. stropt = "“定稿”";
  4701. }
  4702. else if (entity.MemoOpt == 3)
  4703. {
  4704. stropt = "“完成查货”";
  4705. CeErpSukuraData.createInfo(entity.ctid, 6);
  4706. }
  4707. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4708. entity.UpdateTime = DateTime.Now;
  4709. entity.MemoOpt = 0;
  4710. entity.Update();
  4711. returnSuccessMsg("操作成功!");
  4712. return;
  4713. }
  4714. returnErrorMsg("找不到记录");
  4715. }
  4716. }
  4717. public void get_erp_deliveryunusual()
  4718. {
  4719. DataStruct dStruct = GetPostStruct();
  4720. List<string> lw = new List<string>();
  4721. string tid = GetPostString("ctid");
  4722. if (tid.Length > 0)
  4723. {
  4724. string select_tid = getTidByCtid(tid);
  4725. lw.Add(string.Format("tid='{0}'", select_tid));
  4726. }
  4727. string shopname = GetPostString("shopname");
  4728. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4729. string buyernick = GetPostString("buyer_nick");
  4730. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4731. string customer = GetPostString("customer");
  4732. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4733. string design = GetPostString("design");
  4734. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4735. string sellermemo = GetPostString("seller_memo");
  4736. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4737. string supplier = GetPostString("supplier");
  4738. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4739. string date1 = GetPostString("date1");
  4740. string date2 = GetPostString("date2");
  4741. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4742. if (dw.Length > 0) lw.Add(dw);
  4743. string placedate1 = GetPostString("placedate1");
  4744. string placedate2 = GetPostString("placedate2");
  4745. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4746. if (dw_place.Length > 0) lw.Add(dw_place);
  4747. string price1 = GetPostString("price1");
  4748. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4749. string price2 = GetPostString("price2");
  4750. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4751. string unusualCon = GetPostString("unusualcon");
  4752. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4753. string posTag = CurrentUser.UserPost.Post.Code;
  4754. if (posTag == "Supplier")
  4755. {
  4756. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4757. }
  4758. lw.Add(string.Format("OrderState = 6"));
  4759. lw.Add(string.Format("UnusualTag = 5"));
  4760. lw.Add(string.Format("IsRefund<={0}", 1));
  4761. dStruct.Order = "FinishPlaceTime desc";
  4762. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4763. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4764. writeGridDataTableJson(dStruct.TotalCount, dt);
  4765. }
  4766. public void get_erp_deliveryedlist()
  4767. {
  4768. DataStruct dStruct = GetPostStruct();
  4769. List<string> lw = new List<string>();
  4770. string tid = GetPostString("ctid");
  4771. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4772. string shopname = GetPostString("shopname");
  4773. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4774. string buyernick = GetPostString("buyer_nick");
  4775. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4776. string customer = GetPostString("customer");
  4777. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4778. string design = GetPostString("design");
  4779. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4780. string sellermemo = GetPostString("seller_memo");
  4781. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4782. string logistics = GetPostString("logistics");
  4783. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4784. string date1 = GetPostString("date1");
  4785. string date2 = GetPostString("date2");
  4786. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4787. //if (dw.Length > 0) lw.Add(dw);
  4788. string placedate1 = GetPostString("placedate1");
  4789. string placedate2 = GetPostString("placedate2");
  4790. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4791. if (fdw.Length > 0) lw.Add(fdw);
  4792. string devdate1 = GetPostString("deliverydate1");
  4793. string devdate2 = GetPostString("deliverydate2");
  4794. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4795. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4796. string price1 = GetPostString("price1");
  4797. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4798. string price2 = GetPostString("price2");
  4799. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4800. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4801. {
  4802. if (tid.Length > 0)
  4803. {
  4804. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4805. if (tid.Length > 5)
  4806. {
  4807. List<string> tids = getTidByCtidLike(tid);
  4808. if (tids.Count > 0 && tids.Count < 10)
  4809. {
  4810. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4811. }
  4812. }
  4813. lw.Add(tid_sql);
  4814. }
  4815. if (buyernick.Length > 0)
  4816. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4817. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4818. if (dw.Length > 0) lw.Add(dw);
  4819. }
  4820. else
  4821. {
  4822. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4823. }
  4824. string posTag = CurrentUser.UserPost.Post.Code;
  4825. if (posTag == "Supplier")
  4826. {
  4827. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4828. }
  4829. else
  4830. {
  4831. string supplier = GetPostString("supplier");
  4832. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4833. }
  4834. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4835. lw.Add(string.Format("type != 'PDD' "));
  4836. lw.Add(string.Format("IsRefund!={0}", 2));
  4837. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4838. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4839. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4840. /*if (tid.Length > 0)
  4841. {
  4842. List<string> tids = new List<string>();
  4843. if (dt != null && dt.Rows.Count > 0)
  4844. {
  4845. foreach (DataRow item in dt.Rows)
  4846. {
  4847. tids.Add("'" + item["tid"] + "'");
  4848. }
  4849. }
  4850. if (tids.Count > 0)
  4851. {
  4852. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4853. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4854. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4855. dt = WebCache.GetData("view_erptradecell", dStruct);
  4856. }
  4857. }*/
  4858. if (dt != null)
  4859. {
  4860. foreach (DataRow dr in dt.Rows)
  4861. {
  4862. 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();
  4863. }
  4864. }
  4865. writeGridDataTableJson(dStruct.TotalCount, dt);
  4866. }
  4867. public void get_erp_pdddeliveryed()
  4868. {
  4869. DataStruct dStruct = GetPostStruct();
  4870. List<string> lw = new List<string>();
  4871. string tid = GetPostString("ctid");
  4872. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4873. string shopname = GetPostString("shopname");
  4874. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4875. string buyernick = GetPostString("buyer_nick");
  4876. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4877. string customer = GetPostString("customer");
  4878. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4879. string design = GetPostString("design");
  4880. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4881. string sellermemo = GetPostString("seller_memo");
  4882. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4883. string logistics = GetPostString("logistics");
  4884. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4885. string date1 = GetPostString("date1");
  4886. string date2 = GetPostString("date2");
  4887. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4888. //if (dw.Length > 0) lw.Add(dw);
  4889. string placedate1 = GetPostString("placedate1");
  4890. string placedate2 = GetPostString("placedate2");
  4891. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4892. if (fdw.Length > 0) lw.Add(fdw);
  4893. string devdate1 = GetPostString("deliverydate1");
  4894. string devdate2 = GetPostString("deliverydate2");
  4895. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4896. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4897. string price1 = GetPostString("price1");
  4898. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4899. string price2 = GetPostString("price2");
  4900. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4901. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4902. {
  4903. if (tid.Length > 0)
  4904. {
  4905. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4906. if (tid.Length > 5)
  4907. {
  4908. List<string> tids = getTidByCtidLike(tid);
  4909. if (tids.Count > 0 && tids.Count < 10)
  4910. {
  4911. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4912. }
  4913. }
  4914. lw.Add(tid_sql);
  4915. }
  4916. if (buyernick.Length > 0)
  4917. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4918. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4919. if (dw.Length > 0) lw.Add(dw);
  4920. }
  4921. else
  4922. {
  4923. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4924. }
  4925. string posTag = CurrentUser.UserPost.Post.Code;
  4926. if (posTag == "Supplier")
  4927. {
  4928. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4929. }
  4930. else
  4931. {
  4932. string supplier = GetPostString("supplier");
  4933. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4934. }
  4935. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4936. lw.Add(string.Format("type = 'PDD' "));
  4937. lw.Add(string.Format("IsRefund!={0}", 2));
  4938. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4939. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4940. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4941. /* if (tid.Length > 0)
  4942. {
  4943. List<string> tids = new List<string>();
  4944. if (dt != null && dt.Rows.Count > 0)
  4945. {
  4946. foreach (DataRow item in dt.Rows)
  4947. {
  4948. tids.Add("'" + item["tid"] + "'");
  4949. }
  4950. }
  4951. if (tids.Count > 0)
  4952. {
  4953. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4954. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4955. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4956. dt = WebCache.GetData("view_erptradecell", dStruct);
  4957. }
  4958. }*/
  4959. foreach (DataRow dr in dt.Rows)
  4960. {
  4961. 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();
  4962. }
  4963. writeGridDataTableJson(dStruct.TotalCount, dt);
  4964. }
  4965. public void get_erp_jddeliveryed()
  4966. {
  4967. DataStruct dStruct = GetPostStruct();
  4968. List<string> lw = new List<string>();
  4969. string tid = GetPostString("ctid");
  4970. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4971. string shopname = GetPostString("shopname");
  4972. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4973. string buyernick = GetPostString("buyer_nick");
  4974. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4975. string customer = GetPostString("customer");
  4976. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4977. string design = GetPostString("design");
  4978. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4979. string sellermemo = GetPostString("seller_memo");
  4980. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4981. string date1 = GetPostString("date1");
  4982. string date2 = GetPostString("date2");
  4983. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4984. //if (dw.Length > 0) lw.Add(dw);
  4985. string placedate1 = GetPostString("placedate1");
  4986. string placedate2 = GetPostString("placedate2");
  4987. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4988. if (fdw.Length > 0) lw.Add(fdw);
  4989. string devdate1 = GetPostString("deliverydate1");
  4990. string devdate2 = GetPostString("deliverydate2");
  4991. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4992. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4993. string price1 = GetPostString("price1");
  4994. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4995. string price2 = GetPostString("price2");
  4996. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4997. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4998. {
  4999. if (tid.Length > 0)
  5000. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5001. if (buyernick.Length > 0)
  5002. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5003. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5004. if (dw.Length > 0) lw.Add(dw);
  5005. }
  5006. else
  5007. {
  5008. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5009. }
  5010. string posTag = CurrentUser.UserPost.Post.Code;
  5011. if (posTag == "Supplier")
  5012. {
  5013. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5014. }
  5015. else
  5016. {
  5017. string supplier = GetPostString("supplier");
  5018. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5019. }
  5020. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5021. lw.Add(string.Format("type = 'JD' "));
  5022. lw.Add(string.Format("IsRefund!={0}", 2));
  5023. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5024. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5025. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5026. foreach (DataRow dr in dt.Rows)
  5027. {
  5028. 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();
  5029. }
  5030. writeGridDataTableJson(dStruct.TotalCount, dt);
  5031. }
  5032. public void get_erp_allplacelist()
  5033. {
  5034. DataStruct dStruct = GetPostStruct();
  5035. List<string> lw = new List<string>();
  5036. string tid = GetPostString("ctid");
  5037. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5038. string shopname = GetPostString("shopname");
  5039. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5040. string buyernick = GetPostString("buyer_nick");
  5041. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5042. string customer = GetPostString("customer");
  5043. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5044. string design = GetPostString("design");
  5045. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5046. string sellermemo = GetPostString("seller_memo");
  5047. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5048. string supplier = GetPostString("supplier");
  5049. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5050. string date1 = GetPostString("date1");
  5051. string date2 = GetPostString("date2");
  5052. string pldate1 = GetPostString("placedate1");
  5053. string pldate2 = GetPostString("placedate2");
  5054. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5055. //if (dw.Length > 0) lw.Add(dw);
  5056. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5057. {
  5058. if (tid.Length > 0)
  5059. {
  5060. string select_tid = getTidByCtid(tid);
  5061. lw.Add(string.Format("tid='{0}'", select_tid));
  5062. }
  5063. if (buyernick.Length > 0)
  5064. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5065. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5066. if (dw.Length > 0) lw.Add(dw);
  5067. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5068. if (dw_place.Length > 0) lw.Add(dw_place);
  5069. }
  5070. else
  5071. {
  5072. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5073. {
  5074. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5075. }
  5076. }
  5077. string price1 = GetPostString("price1");
  5078. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5079. string price2 = GetPostString("price2");
  5080. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5081. string posTag = CurrentUser.UserPost.Post.Code;
  5082. if (posTag == "Supplier")
  5083. {
  5084. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5085. }
  5086. lw.Add(string.Format("OrderState >= 6"));
  5087. lw.Add(string.Format("IsSample != 2 "));
  5088. //lw.Add(string.Format("isDianziOrder = 0 "));
  5089. lw.Add(string.Format("SupplierId > 0 "));
  5090. //lw.Add(string.Format("IsRefund<={0}", 1));
  5091. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5092. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5093. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5094. foreach (DataRow dr in dt.Rows)
  5095. {
  5096. 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();
  5097. }
  5098. writeGridDataTableJson(dStruct.TotalCount, dt);
  5099. }
  5100. public void get_erp_financeallplacelist()
  5101. {
  5102. DataStruct dStruct = GetPostStruct();
  5103. List<string> lw = new List<string>();
  5104. string tid = GetPostString("ctid");
  5105. string shopname = GetPostString("shopname");
  5106. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5107. string buyernick = GetPostString("buyer_nick");
  5108. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5109. string customer = GetPostString("customer");
  5110. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5111. string design = GetPostString("design");
  5112. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5113. string sellermemo = GetPostString("seller_memo");
  5114. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5115. string supplier = GetPostString("supplier");
  5116. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5117. string date1 = GetPostString("date1");
  5118. string date2 = GetPostString("date2");
  5119. string pldate1 = GetPostString("placedate1");
  5120. string pldate2 = GetPostString("placedate2");
  5121. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5122. {
  5123. if (tid.Length > 0)
  5124. {
  5125. string select_tid = getTidByCtid(tid);
  5126. lw.Add(string.Format("tid='{0}'", select_tid));
  5127. }
  5128. if (buyernick.Length > 0)
  5129. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5130. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5131. if (dw.Length > 0) lw.Add(dw);
  5132. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5133. if (dw_place.Length > 0) lw.Add(dw_place);
  5134. }
  5135. else
  5136. {
  5137. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5138. {
  5139. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5140. }
  5141. }
  5142. string price1 = GetPostString("price1");
  5143. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5144. string price2 = GetPostString("price2");
  5145. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5146. string posTag = CurrentUser.UserPost.Post.Code;
  5147. if (posTag == "Supplier")
  5148. {
  5149. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5150. }
  5151. //lw.Add(string.Format("OrderState >= 6"));
  5152. lw.Add(string.Format("IsSample != 2 "));
  5153. lw.Add(string.Format("isDianziOrder = 0 "));
  5154. //lw.Add(string.Format("IsRefund<={0}", 1));
  5155. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5156. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5157. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5158. foreach (DataRow dr in dt.Rows)
  5159. {
  5160. 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();
  5161. }
  5162. writeGridDataTableJson(dStruct.TotalCount, dt);
  5163. }
  5164. public void get_erp_expresslist()
  5165. {
  5166. int listtype = GetInt("ltype");
  5167. DataStruct dStruct = GetPostStruct();
  5168. List<string> lw = new List<string>();
  5169. string tid = GetPostString("tid");
  5170. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5171. string outsid = GetPostString("out_sid");
  5172. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5173. string importer = GetPostString("ImportUserName");
  5174. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5175. string file = GetPostString("import_file");
  5176. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5177. string printman = GetPostString("printman");
  5178. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5179. string date1 = GetPostString("date1");
  5180. string date2 = GetPostString("date2");
  5181. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5182. if (dw.Length > 0) lw.Add(dw);
  5183. string fdate1 = GetPostString("finishdate1");
  5184. string fdate2 = GetPostString("finishdate2");
  5185. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5186. if (fdw.Length > 0) lw.Add(fdw);
  5187. string supplierId = GetPostString("supplierId");
  5188. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5189. if (listtype == 1)
  5190. {
  5191. lw.Add(string.Format("importUserId !=0"));
  5192. }
  5193. string posTag = CurrentUser.UserPost.Post.Code;
  5194. if (posTag == "Supplier")
  5195. {
  5196. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5197. }
  5198. if (dStruct.PageSize != 100000)
  5199. {
  5200. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5201. }
  5202. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5203. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5204. writeGridDataTableJson(dStruct.TotalCount, dt);
  5205. }
  5206. public void set_erp_buchaorderdelivery()
  5207. {
  5208. if (UrlPostParmsCheck("ctid"))
  5209. {
  5210. string eid = GetPostString("ctid");
  5211. CeErpTradeCell entity = null;
  5212. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5213. if (entity != null)
  5214. {
  5215. if (entity.IsSample != 2)
  5216. {
  5217. returnErrorMsg("补差价单才能标记为已发货");
  5218. return;
  5219. }
  5220. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5221. entity.OrderState = 7;
  5222. entity.Update();
  5223. returnSuccessMsg("操作成功!");
  5224. return;
  5225. }
  5226. returnErrorMsg("找不到记录");
  5227. }
  5228. }
  5229. public void get_stdtemplates()
  5230. {
  5231. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5232. //string res = taobaoHelper.test();
  5233. string res = apiHelper.API_PrintTemplate();
  5234. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5235. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5236. {
  5237. int sidx = res.IndexOf("error_code");
  5238. int eidx = res.IndexOf("success");
  5239. string msg = res.Substring(sidx, eidx - sidx);
  5240. returnErrorMsg(msg);
  5241. return;
  5242. }
  5243. if (res.Length <= 0)
  5244. {
  5245. returnErrorMsg("模板数据为空!");
  5246. return;
  5247. }
  5248. ReturnSuccess(res);
  5249. }
  5250. public void cancel_print_order()
  5251. {
  5252. if (UrlPostParmsCheck("ctid"))
  5253. {
  5254. string ctid = GetPostString("ctid");
  5255. CeErpTradeCell entity = null;
  5256. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5257. if (entity != null)
  5258. {
  5259. string res = "";
  5260. string code = entity.LastBillWaybillCode;
  5261. if (code == "")
  5262. {
  5263. code = entity.OutSid;
  5264. }
  5265. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5266. XLog.SaveLog(0, "取消面单" + res);
  5267. }
  5268. }
  5269. }
  5270. public void set_erp_printwaybill()
  5271. {
  5272. if (UrlPostParmsCheck("ctid"))
  5273. {
  5274. string ctid = GetPostString("ctid");
  5275. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5276. string cpName = GetPostString("cpname");
  5277. string isTogether = GetPostString("together");
  5278. //var res_obj = new
  5279. //{
  5280. // restype = 1,
  5281. // 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\"}"
  5282. //};
  5283. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5284. //ReturnSuccess(ro_json);
  5285. //return;
  5286. bool isUseLastWayBillCode = false;
  5287. CeErpTradeCell entity = null;
  5288. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5289. if (entity != null)
  5290. {
  5291. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5292. {
  5293. isUseLastWayBillCode = true;
  5294. }
  5295. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5296. {
  5297. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5298. return;
  5299. }
  5300. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5301. {
  5302. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5303. return;
  5304. }
  5305. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5306. {
  5307. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5308. return;
  5309. }
  5310. }
  5311. string res = "";
  5312. Api_waybill_code_response_Obj fullObj = null;
  5313. string pData_str = "";
  5314. string curUseWayBillCode = "";
  5315. if (isUseLastWayBillCode == false)
  5316. {
  5317. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5318. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5319. if (res.IndexOf("failure") != -1)
  5320. {
  5321. //int idx = res.IndexOf("sub_message");
  5322. //int idx2 = res.IndexOf("flag");
  5323. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5324. string errMsgNeed = commonHelper.KeepChinese(res);
  5325. var res_objd = new
  5326. {
  5327. restype = 0,
  5328. data = "获取面单失败" + errMsgNeed
  5329. };
  5330. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5331. returnSuccess(ro_jsond);
  5332. if (res.IndexOf("停发") != -1)
  5333. {
  5334. entity.UnusualCon = "物流停发";
  5335. entity.Update();
  5336. }
  5337. //returnErrorMsg("获取面单失败,"+emsg);
  5338. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5339. return;
  5340. }
  5341. else if (res.IndexOf("errorMsg") != -1)
  5342. {
  5343. //int idx = res.IndexOf("errorMsg");
  5344. //int idx2 = res.IndexOf("}]}");
  5345. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5346. string errMsgNeed = commonHelper.KeepChinese(res);
  5347. var res_objf = new
  5348. {
  5349. restype = 0,
  5350. data = "获取面单失败2" + errMsgNeed
  5351. };
  5352. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5353. if (res.IndexOf("停发") != -1)
  5354. {
  5355. entity.UnusualCon = "物流停发";
  5356. entity.Update();
  5357. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5358. if (trade != null)
  5359. {
  5360. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5361. }
  5362. }
  5363. returnSuccess(ro_jsonf);
  5364. //returnErrorMsg("获取面单失败," + emsg);
  5365. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5366. return;
  5367. }
  5368. try
  5369. {
  5370. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5371. //res = res.Replace(" ", "");
  5372. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5373. }
  5374. catch (Exception ex)
  5375. {
  5376. XLog.SaveLog(0, "生成fullObj" + res);
  5377. var res_objf = new
  5378. {
  5379. restype = 0,
  5380. data = "生成fullObj发生错误" + ex.Message
  5381. };
  5382. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5383. returnSuccess(ro_jsonf);
  5384. return;
  5385. }
  5386. if (fullObj.response.data.content.Count > 0)
  5387. {
  5388. ContentItem codeObj = fullObj.response.data.content[0];
  5389. if (cpCode.IndexOf("SFFQ-") != -1)
  5390. {
  5391. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5392. }
  5393. else
  5394. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5395. curUseWayBillCode = codeObj.waybillCode;
  5396. }
  5397. else
  5398. {
  5399. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5400. var res_objf = new
  5401. {
  5402. restype = 0,
  5403. data = "生成fullObj找不到快递单号waybillCode"
  5404. };
  5405. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5406. returnSuccess(ro_jsonf);
  5407. return;
  5408. }
  5409. }
  5410. else
  5411. {
  5412. //使用上次打印的快递单号
  5413. if (cpCode == "SFFQ-LY")
  5414. {
  5415. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5416. }
  5417. else
  5418. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5419. curUseWayBillCode = entity.LastBillWaybillCode;
  5420. }
  5421. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5422. {
  5423. var res_obje = new
  5424. {
  5425. restype = 0,
  5426. data = "获取加密打印数据失败"
  5427. };
  5428. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5429. returnSuccess(ro_jsone);
  5430. entity.LastBillCpCode = cpCode;
  5431. entity.LastBillWaybillCode = curUseWayBillCode;
  5432. entity.Update();
  5433. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5434. //returnErrorMsg("获取加密打印数据失败");
  5435. return;
  5436. }
  5437. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5438. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5439. string btnType = "";
  5440. string errorMsg = "";
  5441. if (entity != null)
  5442. {
  5443. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5444. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5445. //cpcode是 YTO-CAINIAO
  5446. //string comCode = cpCode.Split('-')[0].ToString();
  5447. string apires = "";
  5448. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5449. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5450. {
  5451. if (ctid.IndexOf("N") != -1)
  5452. {
  5453. apires = "发货成功";
  5454. }
  5455. else
  5456. {
  5457. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5458. }
  5459. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5460. //打单后发货
  5461. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5462. {
  5463. try
  5464. {
  5465. btnType = "待发货";
  5466. entity.OutSid = curUseWayBillCode;
  5467. entity.OrderState = 7;
  5468. entity.IsUrgency = false;
  5469. entity.LastBillCpCode = "";
  5470. entity.LastBillWaybillCode = "";
  5471. entity.FinishDeliveryTime = DateTime.Now;
  5472. entity.IsReturn = 0;
  5473. entity.MemoOpt = 0;
  5474. entity.UpdateTime = DateTime.Now;
  5475. entity.Update();
  5476. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5477. //还要插入快递信息到 快递信息表
  5478. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5479. exinfo.tid = entity.ctid;
  5480. exinfo.out_sid = curUseWayBillCode;
  5481. exinfo.company_code = cpCode;
  5482. exinfo.company_name = cpName;
  5483. exinfo.supplierUserName = supplierName;
  5484. exinfo.deliveryType = "发货成功";
  5485. exinfo.print_time = DateTime.Now;
  5486. exinfo.printUser = CurrentUser.UserName;
  5487. exinfo.postData = pData_str;
  5488. exinfo.Create();
  5489. commonHelper.UpdateRelationOrder(entity.ctid);
  5490. CeErpSukuraData.createInfo(ctid, 4);
  5491. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5492. if (entity.SupplierId == 64)
  5493. {
  5494. commonHelper.sendCytExpress(exinfo);
  5495. }
  5496. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5497. if (!string.IsNullOrEmpty(isTogether))
  5498. {
  5499. if (Convert.ToInt32(isTogether) > 0)
  5500. {
  5501. StringBuilder sqlsb = new StringBuilder();
  5502. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}' where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5503. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5504. }
  5505. }
  5506. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5507. }
  5508. catch (Exception ex)
  5509. {
  5510. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5511. }
  5512. }
  5513. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5514. {
  5515. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5516. if (entity.OrderState == 6)
  5517. {
  5518. entity.OrderState = 7;
  5519. }
  5520. entity.UpdateTime = DateTime.Now;
  5521. entity.FinishDeliveryTime = DateTime.Now;
  5522. btnType = "已发货";
  5523. entity.Update();
  5524. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5525. exinfo.tid = entity.ctid;
  5526. exinfo.out_sid = curUseWayBillCode;
  5527. exinfo.company_code = cpCode;
  5528. exinfo.company_name = cpName;
  5529. exinfo.supplierUserName = supplierName;
  5530. exinfo.deliveryType = "发货成功";
  5531. exinfo.print_time = DateTime.Now;
  5532. exinfo.printUser = CurrentUser.UserName;
  5533. exinfo.postData = pData_str;
  5534. exinfo.Create();
  5535. commonHelper.UpdateRelationOrder(entity.ctid);
  5536. CeErpSukuraData.createInfo(entity.ctid, 4);
  5537. if (entity.SupplierId == 64)
  5538. {
  5539. commonHelper.sendCytExpress(exinfo);
  5540. }
  5541. if (!string.IsNullOrEmpty(isTogether))
  5542. {
  5543. if (Convert.ToInt32(isTogether) > 0)
  5544. {
  5545. StringBuilder sqlsb = new StringBuilder();
  5546. 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);
  5547. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5548. }
  5549. }
  5550. //不处理
  5551. }
  5552. else
  5553. {
  5554. entity.UpdateTime = DateTime.Now;
  5555. entity.LastBillCpCode = cpCode;
  5556. entity.LastBillWaybillCode = curUseWayBillCode;
  5557. entity.Update();
  5558. string errmsg = commonHelper.KeepChinese(apires);
  5559. var res_objz = new
  5560. {
  5561. restype = 0,
  5562. data = "打单后发货失败"
  5563. };
  5564. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5565. returnSuccess(ro_jsonz);
  5566. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5567. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5568. return;
  5569. }
  5570. }
  5571. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5572. {
  5573. StringBuilder allSql = new StringBuilder();
  5574. allSql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,tid from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  5575. if (string.IsNullOrEmpty(mainEn.receiverId))
  5576. {
  5577. allSql.AppendFormat(" and (tid='{0}');", entity.tid);
  5578. }
  5579. else
  5580. {
  5581. //查询同车间同状态下的收货地址相同的单子
  5582. allSql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}') );", entity.tid, mainEn.receiverId, entity.IsSF);
  5583. }
  5584. DataTable dt = DbHelper.DbConn.ExecuteDataset(allSql.ToString()).Tables[0];
  5585. List<string> list = new List<string>();
  5586. List<string> send_list = new List<string>();
  5587. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5588. CeErpTrade ceErpTrade = new CeErpTrade();
  5589. foreach (DataRow row in dt.Rows)
  5590. {
  5591. list.Add("'" + row["ctid"] + "'");
  5592. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5593. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5594. if (ctid.IndexOf("N") != -1)
  5595. {
  5596. apires = "发货成功";
  5597. }
  5598. else
  5599. {
  5600. if (!send_list.Contains(ceErpTrade.tid))
  5601. {
  5602. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5603. }
  5604. else
  5605. {
  5606. apires = "发货成功";
  5607. }
  5608. }
  5609. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5610. {
  5611. send_list.Add(ceErpTrade.tid);
  5612. try
  5613. {
  5614. btnType = "待发货";
  5615. ceErpTradeCell.OutSid = curUseWayBillCode;
  5616. ceErpTradeCell.OrderState = 7;
  5617. ceErpTradeCell.IsUrgency = false;
  5618. ceErpTradeCell.LastBillCpCode = "";
  5619. ceErpTradeCell.LastBillWaybillCode = "";
  5620. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5621. ceErpTradeCell.IsReturn = 0;
  5622. ceErpTradeCell.MemoOpt = 0;
  5623. ceErpTradeCell.UpdateTime = DateTime.Now;
  5624. ceErpTradeCell.Update();
  5625. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5626. //还要插入快递信息到 快递信息表
  5627. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5628. exinfo.tid = ceErpTradeCell.ctid;
  5629. exinfo.out_sid = curUseWayBillCode;
  5630. exinfo.company_code = cpCode;
  5631. exinfo.company_name = cpName;
  5632. exinfo.supplierUserName = supplierName;
  5633. exinfo.deliveryType = "发货成功";
  5634. exinfo.print_time = DateTime.Now;
  5635. exinfo.printUser = CurrentUser.UserName;
  5636. exinfo.postData = pData_str;
  5637. exinfo.Create();
  5638. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5639. CeErpSukuraData.createInfo(ctid, 4);
  5640. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5641. if (ceErpTradeCell.SupplierId == 64)
  5642. {
  5643. commonHelper.sendCytExpress(exinfo);
  5644. }
  5645. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5646. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5647. }
  5648. catch (Exception ex)
  5649. {
  5650. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5651. }
  5652. }
  5653. else
  5654. {
  5655. ceErpTradeCell.UpdateTime = DateTime.Now;
  5656. ceErpTradeCell.LastBillCpCode = cpCode;
  5657. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5658. ceErpTradeCell.Update();
  5659. string errmsg = commonHelper.KeepChinese(apires);
  5660. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5661. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5662. }
  5663. }
  5664. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5665. }
  5666. }
  5667. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5668. var res_obj = new
  5669. {
  5670. restype = 1,
  5671. data = pData_str,
  5672. errorMsg
  5673. };
  5674. string ro_json = JsonConvert.SerializeObject(res_obj);
  5675. ReturnSuccess(ro_json);
  5676. return;
  5677. }
  5678. }
  5679. private string GetUTF8String(byte[] vs)
  5680. {
  5681. throw new NotImplementedException();
  5682. }
  5683. public void set_erp_printwaybill_cn()
  5684. {
  5685. if (UrlPostParmsCheck("ctid"))
  5686. {
  5687. string ctid = GetPostString("ctid");
  5688. string cpCode = GetPostString("cpcode");
  5689. string cpName = GetPostString("cpname");
  5690. string tempUrl = GetPostString("tempurl");
  5691. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5692. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5693. //string res = taobaoHelper.test();
  5694. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5695. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5696. {
  5697. int sidx = res.IndexOf("errorMsg");
  5698. int eidx = res.IndexOf("}");
  5699. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5700. var res_objzxx = new
  5701. {
  5702. restype = 0,
  5703. data = msg
  5704. };
  5705. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5706. returnSuccess(ro_jsonzxx);
  5707. //returnErrorMsg(msg);
  5708. return;
  5709. }
  5710. int idx = res.IndexOf("waybillCode");
  5711. int idx2 = res.IndexOf("printData");
  5712. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5713. string eid = GetPostString("ctid");
  5714. CeErpTradeCell entity = null;
  5715. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5716. if (entity != null)
  5717. {
  5718. string osid = entity.OutSid;
  5719. entity.OutSid = osid + "," + outsid;
  5720. entity.FinishDeliveryTime = DateTime.Now;
  5721. entity.OrderState = 7;
  5722. entity.UpdateTime = DateTime.Now;
  5723. entity.IsReturn = 0;
  5724. entity.Update();
  5725. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5726. exinfo.tid = entity.ctid;
  5727. exinfo.out_sid = outsid;
  5728. exinfo.company_code = cpCode;
  5729. exinfo.company_name = cpName;
  5730. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5731. exinfo.deliveryType = "发货成功";
  5732. exinfo.print_time = DateTime.Now;
  5733. exinfo.printUser = CurrentUser.UserName;
  5734. exinfo.Create();
  5735. if (entity.SupplierId == 64)
  5736. {
  5737. commonHelper.sendCytExpress(exinfo);
  5738. }
  5739. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5740. }
  5741. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5742. var res_objz = new
  5743. {
  5744. restype = 1,
  5745. data = res
  5746. };
  5747. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5748. returnSuccess(ro_jsonz);
  5749. //ReturnSuccess(res);
  5750. }
  5751. }
  5752. ////打单,打印面单 获取面单号
  5753. //public void set_erp_printwaybill()
  5754. //{
  5755. // if (UrlPostParmsCheck("ctid"))
  5756. // {
  5757. // string ctid = GetPostString("ctid");
  5758. // string cpCode = GetPostString("cpcode");
  5759. // string tempUrl = GetPostString("tempurl");
  5760. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5761. // //string res = taobaoHelper.test();
  5762. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5763. // if (res.IndexOf("error_response") != -1)
  5764. // {
  5765. // int sidx = res.IndexOf("sub_msg");
  5766. // int eidx = res.IndexOf("request_id");
  5767. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5768. // returnErrorMsg(msg);
  5769. // return;
  5770. // }
  5771. // int idx = res.IndexOf("waybill_code");
  5772. // int idx2 = res.IndexOf("}]}");
  5773. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5774. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5775. // ReturnSuccess(res);
  5776. // }
  5777. //}
  5778. public void cancel_erp_aftersale()
  5779. {
  5780. if (UrlPostParmsCheck("ctid"))
  5781. {
  5782. string eid = GetPostString("ctid");
  5783. CeErpTradeCell entity = null;
  5784. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5785. if (entity != null)
  5786. {
  5787. //有过处理的售后,取消也不能删除 售 字,保留
  5788. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5789. {
  5790. entity.AfterSaleState = 4;
  5791. }
  5792. else
  5793. entity.AfterSaleState = 0;
  5794. entity.UpdateTime = DateTime.Now;
  5795. entity.Update();
  5796. returnSuccessMsg("操作成功!");
  5797. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5798. return;
  5799. }
  5800. returnErrorMsg("找不到订单记录");
  5801. }
  5802. }
  5803. public void get_erp_aftersalelist()
  5804. {
  5805. DataStruct dStruct = GetPostStruct();
  5806. List<string> lw = new List<string>();
  5807. int st = GetInt("st");
  5808. string tid = GetPostString("ctid");
  5809. if (st == 3)
  5810. {
  5811. if (tid.Length > 0)
  5812. {
  5813. string select_tid = getTidByCtid(tid);
  5814. lw.Add(string.Format("tid='{0}'", select_tid));
  5815. }
  5816. }
  5817. else
  5818. {
  5819. if (tid.Length > 0)
  5820. {
  5821. string select_tid = getTidByCtid(tid);
  5822. lw.Add(string.Format("tid='{0}'", select_tid));
  5823. }
  5824. }
  5825. string shopname = GetPostString("shopname");
  5826. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5827. string buyernick = GetPostString("buyer_nick");
  5828. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5829. string sellermemo = GetPostString("seller_memo");
  5830. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5831. string orderState = GetPostString("orderState");
  5832. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5833. string afterState = GetPostString("afterstate");
  5834. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5835. string date1 = GetPostString("date1");
  5836. string date2 = GetPostString("date2");
  5837. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5838. if (dw.Length > 0) lw.Add(dw);
  5839. string price1 = GetPostString("price1");
  5840. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5841. string price2 = GetPostString("price2");
  5842. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5843. //lw.Add(string.Format("IsRefund!={0}", 1));
  5844. string reason = GetPostString("reason");
  5845. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5846. string method = GetPostString("method");
  5847. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5848. string handler = GetPostString("handler");
  5849. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5850. string handledate1 = GetPostString("handledate1");
  5851. string handledate2 = GetPostString("handledate2");
  5852. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5853. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5854. string finish1 = GetPostString("finishdate1");
  5855. string finish2 = GetPostString("finishdate2");
  5856. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5857. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5858. string afterdate1 = GetPostString("afterdate1");
  5859. string afterdate2 = GetPostString("afterdate2");
  5860. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5861. if (afterDate.Length > 0) lw.Add(afterDate);
  5862. string supplier = GetPostString("supplier");
  5863. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5864. string responsible = GetPostString("responsibleman");
  5865. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5866. string customer = GetPostString("customer");
  5867. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5868. string design = GetPostString("design");
  5869. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5870. string afterMemoType = GetPostString("aftermemotype");
  5871. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5872. string posCode = CurrentUser.UserPost.Post.Code;
  5873. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5874. //{
  5875. // string vstate = GetPostString("vstate");
  5876. // if (vstate.Length > 0)
  5877. // {
  5878. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5879. // }
  5880. // if (posCode == "Supplier")
  5881. // {
  5882. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5883. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5884. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5885. // }
  5886. // else
  5887. // {
  5888. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5889. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5890. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5891. // {
  5892. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5893. // }
  5894. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5895. // {
  5896. // int orgid = CurrentUser.UserPost.OrgID;
  5897. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5898. // }
  5899. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5900. // {
  5901. // string shopid = CurrentUser.User.pemShop;
  5902. // lw.Add(string.Format("shopId in ({0})", shopid));
  5903. // }
  5904. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5905. // //{
  5906. // // int org_id = CurrentUser.UserPost.OrgID;
  5907. // // lw.Add(string.Format("OrgID={0}", org_id));
  5908. // //}
  5909. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5910. // }
  5911. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5912. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5913. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5914. //}
  5915. if (st == 5)
  5916. {
  5917. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5918. {
  5919. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5920. {
  5921. string shopid = CurrentUser.User.pemShop;
  5922. lw.Add(string.Format("shopId in ({0})", shopid));
  5923. }
  5924. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5925. {
  5926. int mrOrgid = CurrentUser.UserPost.OrgID;
  5927. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5928. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5929. }
  5930. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5931. //{
  5932. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5933. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5934. //}
  5935. else
  5936. {
  5937. string userIdStr = "";
  5938. if (posCode == "CustomerService")
  5939. {
  5940. userIdStr = CurrentUser.UserID + "_k";
  5941. }
  5942. else if (posCode == "Designer" || posCode == "wxDesigner")
  5943. {
  5944. userIdStr = CurrentUser.UserID + "_s";
  5945. }
  5946. else if (posCode == "Place")
  5947. {
  5948. userIdStr = CurrentUser.UserID + "_x";
  5949. }
  5950. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5951. }
  5952. }
  5953. string placedate1 = GetPostString("placedate1");
  5954. string placedate2 = GetPostString("placedate2");
  5955. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5956. if (dwplace.Length > 0) lw.Add(dwplace);
  5957. string supState = GetPostString("supState");
  5958. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  5959. string searchType = GetPostString("searchType");
  5960. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  5961. {
  5962. lw.Add(string.Format("BackNum>1"));
  5963. }
  5964. lw.Add(string.Format("AfterSaleState>0"));
  5965. if (ex_psize > 0)
  5966. {
  5967. if (CurrentUser.UserPost.Post.Code == "Finance")
  5968. dStruct.Order = "pay_time desc";
  5969. else
  5970. dStruct.Order = "HandleTime desc";
  5971. }
  5972. else
  5973. dStruct.Order = "HandleTime desc";
  5974. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5975. DataTable dt = WebCache.GetData("view_test", dStruct);
  5976. writeGridDataTableJson(dStruct.TotalCount, dt);
  5977. }
  5978. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  5979. //{
  5980. // lw.Add(string.Format("AfterSaleState=4"));
  5981. // string code = CurrentUser.UserPost.Post.Code;
  5982. // if (code == "CustomerService")
  5983. // {
  5984. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  5985. // }
  5986. // else if (code == "Designer" || code == "DesignerMr")
  5987. // {
  5988. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  5989. // }
  5990. // else if (code == "Place" || code == "PlaceMr")
  5991. // {
  5992. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  5993. // }
  5994. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5995. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5996. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5997. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5998. //}
  5999. //else //处理中的售后,待处理和处理中合并
  6000. //{
  6001. // if (afterState.Length <= 0)
  6002. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6003. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6004. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6005. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6006. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6007. //}
  6008. }
  6009. public void get_erp_disagreeftersalelist()
  6010. {
  6011. DataStruct dStruct = GetPostStruct();
  6012. List<string> lw = new List<string>();
  6013. int st = 2;
  6014. string tid = GetPostString("ctid");
  6015. if (tid.Length > 0)
  6016. {
  6017. string select_tid = getTidByCtid(tid);
  6018. lw.Add(string.Format("tid='{0}'", select_tid));
  6019. }
  6020. string shopname = GetPostString("shopname");
  6021. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6022. string buyernick = GetPostString("buyer_nick");
  6023. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6024. string sellermemo = GetPostString("seller_memo");
  6025. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6026. string orderState = GetPostString("orderState");
  6027. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6028. string afterState = GetPostString("afterstate");
  6029. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6030. string date1 = GetPostString("date1");
  6031. string date2 = GetPostString("date2");
  6032. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6033. if (dw.Length > 0) lw.Add(dw);
  6034. string price1 = GetPostString("price1");
  6035. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6036. string price2 = GetPostString("price2");
  6037. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6038. //lw.Add(string.Format("IsRefund!={0}", 1));
  6039. string reason = GetPostString("reason");
  6040. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6041. string method = GetPostString("method");
  6042. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6043. string handler = GetPostString("handler");
  6044. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6045. string handledate1 = GetPostString("handledate1");
  6046. string handledate2 = GetPostString("handledate2");
  6047. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6048. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6049. string afterdate1 = GetPostString("afterdate1");
  6050. string afterdate2 = GetPostString("afterdate2");
  6051. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6052. if (afterDate.Length > 0) lw.Add(afterDate);
  6053. string backdate1 = GetPostString("backdate1");
  6054. string backdate2 = GetPostString("backdate2");
  6055. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6056. if (backDate.Length > 0) lw.Add(backDate);
  6057. string supplier = GetPostString("supplier");
  6058. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6059. string responsible = GetPostString("responsibleman");
  6060. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6061. string customer = GetPostString("customer");
  6062. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6063. string design = GetPostString("design");
  6064. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6065. string afterSaleMemo = GetPostString("afterSaleMemo");
  6066. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6067. string afterMemoType = GetPostString("aftermemotype");
  6068. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6069. string aftersakereason = GetPostString("aftersakereason");
  6070. if (aftersakereason.Length > 0)
  6071. {
  6072. if (aftersakereason == "1")
  6073. {
  6074. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6075. }
  6076. if (aftersakereason == "2")
  6077. {
  6078. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6079. }
  6080. }
  6081. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6082. string poscode = CurrentUser.UserPost.Post.Code;
  6083. if (poscode != "SysAdmin")
  6084. {
  6085. string shopid = CurrentUser.User.pemShop;
  6086. lw.Add(string.Format("shopId in ({0})", shopid));
  6087. }
  6088. string searchType = GetPostString("searchType");
  6089. if (searchType == "wait")
  6090. {
  6091. lw.Add(string.Format("HandleTime is null"));
  6092. }
  6093. if (searchType == "handling")
  6094. {
  6095. lw.Add(string.Format("HandleTime is not null "));
  6096. }
  6097. if (searchType == "back" || searchType == "puBack")
  6098. {
  6099. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6100. }
  6101. if (searchType == "reBack")
  6102. {
  6103. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6104. }
  6105. if (searchType == "moreBack")
  6106. {
  6107. lw.Add(string.Format("backNum > 1"));
  6108. }
  6109. lw.Add(string.Format("(AfterSaleState=5)"));
  6110. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6111. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6112. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6113. writeGridDataTableJson(dStruct.TotalCount, dt);
  6114. }
  6115. public void get_erp_handlingaftersalelist()
  6116. {
  6117. DataStruct dStruct = GetPostStruct();
  6118. List<string> lw = new List<string>();
  6119. int st = 2;
  6120. string tid = GetPostString("ctid");
  6121. if (tid.Length > 0)
  6122. {
  6123. string select_tid = getTidByCtid(tid);
  6124. lw.Add(string.Format("tid='{0}'", select_tid));
  6125. }
  6126. string shopname = GetPostString("shopname");
  6127. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6128. string buyernick = GetPostString("buyer_nick");
  6129. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6130. string sellermemo = GetPostString("seller_memo");
  6131. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6132. string orderState = GetPostString("orderState");
  6133. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6134. string afterState = GetPostString("afterstate");
  6135. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6136. string date1 = GetPostString("date1");
  6137. string date2 = GetPostString("date2");
  6138. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6139. if (dw.Length > 0) lw.Add(dw);
  6140. string price1 = GetPostString("price1");
  6141. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6142. string price2 = GetPostString("price2");
  6143. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6144. //lw.Add(string.Format("IsRefund!={0}", 1));
  6145. string reason = GetPostString("reason");
  6146. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6147. string method = GetPostString("method");
  6148. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6149. string handler = GetPostString("handler");
  6150. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6151. string handledate1 = GetPostString("handledate1");
  6152. string handledate2 = GetPostString("handledate2");
  6153. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6154. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6155. string afterdate1 = GetPostString("afterdate1");
  6156. string afterdate2 = GetPostString("afterdate2");
  6157. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6158. if (afterDate.Length > 0) lw.Add(afterDate);
  6159. string supplier = GetPostString("supplier");
  6160. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6161. string responsible = GetPostString("responsibleman");
  6162. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6163. string customer = GetPostString("customer");
  6164. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6165. string design = GetPostString("design");
  6166. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6167. string afterSaleMemo = GetPostString("afterSaleMemo");
  6168. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6169. string afterMemoType = GetPostString("aftermemotype");
  6170. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6171. string afterresult = GetPostString("afterresult");
  6172. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6173. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6174. string poscode = CurrentUser.UserPost.Post.Code;
  6175. if (poscode != "SysAdmin")
  6176. {
  6177. string shopid = CurrentUser.User.pemShop;
  6178. lw.Add(string.Format("shopId in ({0})", shopid));
  6179. }
  6180. string searchType = GetPostString("searchType");
  6181. if (searchType == "wait")
  6182. {
  6183. lw.Add(string.Format("HandleTime is null"));
  6184. }
  6185. if (searchType == "documentary")
  6186. {
  6187. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6188. }
  6189. if (searchType == "handling")
  6190. {
  6191. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6192. }
  6193. if (searchType == "back" || searchType == "puBack")
  6194. {
  6195. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6196. }
  6197. if (searchType == "reBack")
  6198. {
  6199. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6200. }
  6201. if (afterState.Length <= 0)
  6202. {
  6203. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6204. }
  6205. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6206. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6207. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6208. writeGridDataTableJson(dStruct.TotalCount, dt);
  6209. }
  6210. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6211. //public void get_erp_back_handlingaftersalelist()
  6212. //{
  6213. // DataStruct dStruct = GetPostStruct();
  6214. // List<string> lw = new List<string>();
  6215. // string tid = GetPostString("ctid");
  6216. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6217. // string shopname = GetPostString("shopname");
  6218. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6219. // string buyernick = GetPostString("buyer_nick");
  6220. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6221. // string sellermemo = GetPostString("seller_memo");
  6222. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6223. // string orderState = GetPostString("orderState");
  6224. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6225. // string afterState = GetPostString("afterstate");
  6226. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6227. // string date1 = GetPostString("date1");
  6228. // string date2 = GetPostString("date2");
  6229. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6230. // if (dw.Length > 0) lw.Add(dw);
  6231. // string price1 = GetPostString("price1");
  6232. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6233. // string price2 = GetPostString("price2");
  6234. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6235. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6236. // string reason = GetPostString("reason");
  6237. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6238. // string method = GetPostString("method");
  6239. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6240. // string handler = GetPostString("handler");
  6241. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6242. // string handledate1 = GetPostString("handledate1");
  6243. // string handledate2 = GetPostString("handledate2");
  6244. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6245. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6246. // string afterdate1 = GetPostString("afterdate1");
  6247. // string afterdate2 = GetPostString("afterdate2");
  6248. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6249. // if (afterDate.Length > 0) lw.Add(afterDate);
  6250. // string supplier = GetPostString("supplier");
  6251. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6252. // string responsible = GetPostString("responsibleman");
  6253. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6254. // string customer = GetPostString("customer");
  6255. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6256. // string design = GetPostString("design");
  6257. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6258. // string afterMemoType = GetPostString("aftermemotype");
  6259. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6260. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6261. // if (afterState.Length <= 0)
  6262. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6263. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6264. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6265. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6266. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6267. //}
  6268. public void get_erp_aftersaleverifylist()
  6269. {
  6270. DataStruct dStruct = GetPostStruct();
  6271. List<string> lw = new List<string>();
  6272. string tid = GetPostString("ctid");
  6273. if (tid.Length > 0)
  6274. {
  6275. string select_tid = getTidByCtid(tid);
  6276. lw.Add(string.Format("tid='{0}'", select_tid));
  6277. }
  6278. string shopname = GetPostString("shopname");
  6279. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6280. string buyernick = GetPostString("buyer_nick");
  6281. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6282. string sellermemo = GetPostString("seller_memo");
  6283. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6284. string orderState = GetPostString("orderState");
  6285. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6286. //lw.Add(string.Format("IsRefund!={0}", 1));
  6287. string reason = GetPostString("reason");
  6288. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6289. string method = GetPostString("method");
  6290. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6291. string handler = GetPostString("handler");
  6292. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6293. string handledate1 = GetPostString("handledate1");
  6294. string handledate2 = GetPostString("handledate2");
  6295. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6296. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6297. string finish1 = GetPostString("finishdate1");
  6298. string finish2 = GetPostString("finishdate2");
  6299. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6300. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6301. string supplier = GetPostString("supplier");
  6302. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6303. string responsible = GetPostString("responsibleman");
  6304. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6305. string posCode = CurrentUser.UserPost.Post.Code;
  6306. string vstate = GetPostString("vstate");
  6307. if (vstate.Length > 0)
  6308. {
  6309. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6310. }
  6311. if (posCode == "Supplier")
  6312. {
  6313. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6314. lw.Add(string.Format("VerifyState = 0"));
  6315. lw.Add("type = 1");
  6316. lw.Add(string.Format("AfterSaleState={0}", 3));
  6317. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6318. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6319. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6320. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6321. writeGridDataTableJson(dStruct.TotalCount, dt);
  6322. }
  6323. else if (posCode == "logistics")
  6324. {
  6325. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6326. lw.Add(string.Format("VerifyState = 0"));
  6327. lw.Add("type = 2");
  6328. lw.Add(string.Format("AfterSaleState={0}", 3));
  6329. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6330. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6331. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6332. writeGridDataTableJson(dStruct.TotalCount, dt);
  6333. }
  6334. else
  6335. {
  6336. lw.Add(string.Format("(AfterSaleState = 3)"));
  6337. string reasonState = GetPostString("reasonState");
  6338. lw.Add("type = 0");
  6339. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6340. || posCode == "Summarize" || posCode == "Finance")
  6341. {
  6342. if (reasonState == "2")
  6343. {
  6344. lw.Add("VerifyState = 3");
  6345. }
  6346. else if (reasonState == "1")
  6347. {
  6348. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6349. }
  6350. else
  6351. {
  6352. lw.Add("VerifyState in (0,3)");
  6353. }
  6354. //不加条件,可以看全部
  6355. }
  6356. 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")
  6357. {
  6358. int orgid = CurrentUser.UserPost.OrgID;
  6359. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6360. if (string.IsNullOrEmpty(manageOrgId))
  6361. {
  6362. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6363. }
  6364. else
  6365. {
  6366. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6367. }
  6368. if (reasonState == "1")
  6369. {
  6370. lw.Add("VerifyState = 3");
  6371. }
  6372. else if (reasonState == "2")
  6373. {
  6374. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6375. }
  6376. else
  6377. {
  6378. }
  6379. }
  6380. else
  6381. {
  6382. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6383. }
  6384. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6385. //{
  6386. // int org_id = CurrentUser.UserPost.OrgID;
  6387. // lw.Add(string.Format("OrgID={0}", org_id));
  6388. //}
  6389. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6390. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6391. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6392. writeGridDataTableJson(dStruct.TotalCount, dt);
  6393. }
  6394. }
  6395. public void get_erp_finishaftersalelist()
  6396. {
  6397. DataStruct dStruct = GetPostStruct();
  6398. List<string> lw = new List<string>();
  6399. int st = 4;
  6400. string tid = GetPostString("ctid");
  6401. if (tid.Length > 0)
  6402. {
  6403. string select_tid = getTidByCtid(tid);
  6404. lw.Add(string.Format("tid='{0}'", select_tid));
  6405. }
  6406. string shopname = GetPostString("shopname");
  6407. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6408. //lw.Add(string.Format("IsRefund!={0}", 1));
  6409. string reason = GetPostString("reason");
  6410. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6411. string method = GetPostString("method");
  6412. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6413. string buyernick = GetPostString("buyer_nick");
  6414. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6415. string handler = GetPostString("handler");
  6416. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6417. string handledate1 = GetPostString("handledate1");
  6418. string handledate2 = GetPostString("handledate2");
  6419. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6420. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6421. string finish1 = GetPostString("finishdate1");
  6422. string finish2 = GetPostString("finishdate2");
  6423. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6424. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6425. string supplier = GetPostString("supplier");
  6426. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6427. string responsible = GetPostString("responsibleman");
  6428. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6429. string vstate = GetPostString("vstate");
  6430. if (vstate.Length > 0)
  6431. {
  6432. if ("3".Equals(vstate))
  6433. {
  6434. lw.Add(string.Format("IsTem=1"));
  6435. }
  6436. else
  6437. {
  6438. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6439. }
  6440. }
  6441. lw.Add(string.Format("AfterSaleState=4"));
  6442. string code = CurrentUser.UserPost.Post.Code;
  6443. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6444. {
  6445. //不加条件,可以看全部
  6446. }
  6447. else if (code == "Supplier")
  6448. {
  6449. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6450. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6451. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6452. }
  6453. else if (code == "logistics")
  6454. {
  6455. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6456. lw.Add("type = 2");
  6457. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6458. }
  6459. 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")
  6460. {
  6461. int orgid = CurrentUser.UserPost.OrgID;
  6462. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6463. if (string.IsNullOrEmpty(manageOrgIds))
  6464. {
  6465. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6466. }
  6467. else
  6468. {
  6469. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6470. }
  6471. }
  6472. else
  6473. {
  6474. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6475. }
  6476. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6477. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6478. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6479. writeGridDataTableJson(dStruct.TotalCount, dt);
  6480. }
  6481. public void handle_erp_aftersale()
  6482. {
  6483. if (UrlPostParmsCheck("ctid"))
  6484. {
  6485. string eid = GetPostString("ctid");
  6486. string responStr = GetPostString("AfterSaleResponsible");
  6487. if (responStr.Length <= 0)
  6488. {
  6489. returnErrorMsg("售后责任人不能为空");
  6490. return;
  6491. }
  6492. bool isDesign = false;
  6493. double designFree = 0.00;
  6494. int responsibleId = 0;
  6495. CeErpTradeCell entity = null;
  6496. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6497. if (entity != null)
  6498. {
  6499. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6500. string afterMethod = GetPostString("AfterSaleMethod");
  6501. if (isNeedNewOrder == 1)
  6502. {
  6503. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6504. bool ishav = true;
  6505. if (newentity == null)
  6506. {
  6507. newentity = entity.Clone() as CeErpTradeCell;
  6508. ishav = false;
  6509. newentity.ctid = "S_" + entity.ctid;
  6510. newentity.OrderState = 0;
  6511. //唯一标识
  6512. newentity.OrderSn = newentity.ctid;
  6513. string orderSn = dataHelper.getSaleOrderSn();
  6514. if (orderSn != "")
  6515. {
  6516. newentity.OrderSn = orderSn;
  6517. }
  6518. }
  6519. newentity.UpdateTime = DateTime.Now;
  6520. newentity.AfterSaleState = 0;
  6521. newentity.AfterSaleMethod = afterMethod;
  6522. if (!ishav)
  6523. {
  6524. string memo_str = newentity.seller_memo;
  6525. memo_str = memo_str.Replace("(", "(");
  6526. memo_str = memo_str.Replace(")", ")");
  6527. int sIndex = memo_str.IndexOf("(");
  6528. int eIndex = memo_str.IndexOf(")");
  6529. if (sIndex == -1 || eIndex == -1)
  6530. {
  6531. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6532. return;
  6533. }
  6534. string first = memo_str.Substring(0, sIndex + 1);
  6535. string memoCtid = newentity.OrderSn;
  6536. //if (memoCtid.IndexOf("C") != -1)
  6537. //{
  6538. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6539. //if (CIdx.IndexOf("+") != -1)
  6540. //{
  6541. //CIdx = "C" + CIdx.Split('+')[1];
  6542. //}
  6543. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6544. //}
  6545. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6546. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6547. string newMemo = first + memoCtid + last;
  6548. newentity.seller_memo = newMemo;
  6549. newentity.FinishPlaceTime = null;
  6550. newentity.UnusualTag = 0;
  6551. newentity.UnusualCon = "";
  6552. newentity.UnusualTime = null;
  6553. newentity.AfterSaleMemo = "";
  6554. newentity.AfterSaleMethod = afterMethod;
  6555. newentity.AfterSalePreTime = null;
  6556. newentity.AfterSaleReason = "";
  6557. newentity.AfterSaleResponsible = "";
  6558. newentity.AfterSaleState = 0;
  6559. newentity.AfterSaleTime = null;
  6560. newentity.AfterSaleUserId = 0;
  6561. newentity.AfterSaleSupplierState = 0;
  6562. newentity.LastBillWaybillCode = "";
  6563. newentity.LastBillCpCode = "";
  6564. newentity.FinishAfterSaleTime = null;
  6565. newentity.HandleTime = null;
  6566. newentity.IsSF = 0;
  6567. newentity.IsOldCustomer = 0;
  6568. newentity.UrgencyTime = null;
  6569. newentity.ResponsibleUserId = "";
  6570. newentity.IsVerifyToSupplier = false;
  6571. newentity.payment = 0;
  6572. newentity.CheckMemo = "";
  6573. newentity.OutSid = "";
  6574. newentity.CheckOrderTime = null;
  6575. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6576. }
  6577. newentity.isAfterSaleOrder = 1;
  6578. newentity.IsRefund = 0;
  6579. string receiveMobile = GetPostString("receiver_mobile");
  6580. if (receiveMobile.Length > 0)
  6581. {
  6582. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6583. if (trade != null)
  6584. {
  6585. trade.receiver_name = GetPostString("receiver_name");
  6586. trade.receiver_mobile = receiveMobile;
  6587. trade.receiver_state = GetPostString("receiver_state");
  6588. trade.receiver_city = GetPostString("receiver_city");
  6589. trade.receiver_district = GetPostString("receiver_district");
  6590. trade.receiver_address = GetPostString("receiver_address");
  6591. newentity.IsOffLineOrder = 1;
  6592. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6593. }
  6594. }
  6595. string st = GetPostString("ToState");
  6596. if (st.Length > 0)
  6597. {
  6598. if (newentity.OrderState <= 3)
  6599. {
  6600. newentity.WaitDesignTime = DateTime.Now;
  6601. newentity.StartDesignTime = null;
  6602. newentity.FinishDesignTime = null;
  6603. newentity.OrderState = 3;
  6604. if (st == "下单员")
  6605. {
  6606. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6607. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6608. {
  6609. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6610. }
  6611. }
  6612. else
  6613. {
  6614. newentity.WaitDesignTime = DateTime.Now;
  6615. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6616. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6617. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6618. {
  6619. DataRow user = dt1.Rows[0];
  6620. //找主管
  6621. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6622. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6623. if (dt != null && dt.Rows.Count > 0)
  6624. {
  6625. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6626. newentity.DesignUserId = designMr;
  6627. string key = "aftersale_order_" + designMr;
  6628. if (RedisHelper.HasKey(key))
  6629. {
  6630. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6631. list.Add(newentity.ctid);
  6632. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6633. }
  6634. }
  6635. //账号正常
  6636. if (user["State"].ToString() == "0")
  6637. {
  6638. newentity.DesignUserId = entity.DesignUserId;
  6639. string key = "aftersale_order_" + entity.DesignUserId;
  6640. if (RedisHelper.HasKey(key))
  6641. {
  6642. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6643. list.Add(newentity.ctid);
  6644. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6645. }
  6646. }
  6647. }
  6648. }
  6649. }
  6650. if (entity.IsXianHuo == 1)
  6651. {
  6652. newentity.OrderState = 6;
  6653. entity.FinishPlaceTime = DateTime.Now;
  6654. }
  6655. }
  6656. if (ishav)
  6657. {
  6658. newentity.Update();
  6659. }
  6660. else
  6661. {
  6662. newentity.Create();
  6663. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6664. newCellExtend.ctid = newentity.ctid;
  6665. newCellExtend.orderFrom = 20;
  6666. newCellExtend.orderType = 30;
  6667. if (st == "下单员")
  6668. {
  6669. }
  6670. else
  6671. {
  6672. newCellExtend.ReprintTime = DateTime.Now;
  6673. }
  6674. newCellExtend.Create();
  6675. }
  6676. if (st != "下单员")
  6677. {
  6678. designHelper.API_GetPrintData_CreateOrder(newentity);
  6679. }
  6680. }
  6681. //处理售后扩展
  6682. string resIdStr = GetPostString("ResponsibleUserId");
  6683. string refundFees = GetPostString("refundFrees");
  6684. int IsComplain = GetPostInt("isComplain");
  6685. int IsBad = GetPostInt("isBad");
  6686. string IsOriginal = GetPostString("isOriginal");
  6687. double diffResultPrice = GetPostDouble("diffResultPrice");
  6688. string textResult = GetPostString("textResult");
  6689. string supplierResponsible = GetPostString("supplierResponsible");
  6690. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6691. if (ceErpTradeAfterSaleExtend == null)
  6692. {
  6693. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6694. ceErpTradeAfterSaleExtend.tid = eid;
  6695. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6696. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6697. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6698. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6699. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6700. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6701. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6702. ceErpTradeAfterSaleExtend.Create();
  6703. }
  6704. else
  6705. {
  6706. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6707. {
  6708. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6709. }
  6710. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6711. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6712. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6713. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6714. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6715. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6716. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6717. ceErpTradeAfterSaleExtend.Update();
  6718. }
  6719. int gysid = GetPostInt("ResponsibleSupId");
  6720. if (entity.AfterSaleUserId == 0)
  6721. {
  6722. entity.AfterSaleUserId = CurrentUser.UserID;
  6723. }
  6724. entity.ResponsibleUserId = resIdStr;
  6725. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6726. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6727. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6728. {
  6729. CeErpTradeResponsible.DelByTid(eid, -1);
  6730. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6731. int backNum = 0;
  6732. if (number != null)
  6733. {
  6734. backNum = number.BackNum;
  6735. }
  6736. char[] separator = { ',' };
  6737. string[] sArray = resIdStr.Split(separator);
  6738. string[] refundFreeList = { };
  6739. if (refundFees.Length > 0)
  6740. {
  6741. refundFreeList = refundFees.Split(separator);
  6742. }
  6743. int index = -1;
  6744. foreach (string i in sArray)
  6745. {
  6746. index++;
  6747. if (i.Length <= 0) continue;
  6748. char[] separator2 = { '_' };
  6749. string idstr = i.Split(separator2)[0];
  6750. string idtype = i.Split(separator2)[1];
  6751. double refudFree = 0;
  6752. if (refundFreeList.Length > 0)
  6753. {
  6754. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6755. }
  6756. if (idtype == "s")
  6757. {
  6758. isDesign = true;
  6759. designFree = refudFree;
  6760. }
  6761. int userId = Convert.ToInt32(idstr);
  6762. int type = 0;
  6763. if (idtype == "g")
  6764. {
  6765. type = 1;
  6766. }
  6767. if (idtype == "w")
  6768. {
  6769. type = 2;
  6770. }
  6771. if (idtype == "t")
  6772. {
  6773. type = 3;
  6774. }
  6775. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6776. if (ceErpTradeResponsible == null)
  6777. {
  6778. ceErpTradeResponsible = new CeErpTradeResponsible();
  6779. ceErpTradeResponsible.tid = eid;
  6780. ceErpTradeResponsible.UserId = userId;
  6781. ceErpTradeResponsible.createdTime = DateTime.Now;
  6782. ceErpTradeResponsible.type = type;
  6783. if (type == 1)
  6784. {
  6785. ceErpTradeResponsible.IsSup = 1;
  6786. }
  6787. if (type == 2)
  6788. {
  6789. ceErpTradeResponsible.IsFlow = 1;
  6790. }
  6791. }
  6792. ceErpTradeResponsible.RefundFee = refudFree;
  6793. ceErpTradeResponsible.VerifyState = 0;
  6794. if (userId == 2125 || idtype == "w")
  6795. {
  6796. ceErpTradeResponsible.VerifyState = 1;
  6797. }
  6798. if (idtype == "w" && userId == 101)
  6799. {
  6800. ceErpTradeResponsible.VerifyState = 0;
  6801. }
  6802. if (ceErpTradeResponsible.ID > 0)
  6803. {
  6804. ceErpTradeResponsible.Update();
  6805. }
  6806. else
  6807. {
  6808. ceErpTradeResponsible.Create();
  6809. }
  6810. if (isDesign)
  6811. {
  6812. responsibleId = ceErpTradeResponsible.ID;
  6813. }
  6814. }
  6815. CeErpTradeResponsible.NumByTid(backNum, eid);
  6816. }
  6817. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6818. if (ceErpTradeCellExtend != null)
  6819. {
  6820. ceErpTradeCellExtend.returnVisit = 0;
  6821. ceErpTradeCellExtend.Update();
  6822. }
  6823. if (entity.HandleTime != null)
  6824. {
  6825. if (entity.AfterSaleState == 1)
  6826. {
  6827. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6828. }
  6829. else
  6830. {
  6831. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6832. }
  6833. }
  6834. else
  6835. {
  6836. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6837. entity.HandleTime = DateTime.Now;
  6838. }
  6839. bool isCompale = false;
  6840. if (entity.AfterSaleState == 5)
  6841. {
  6842. isCompale = true;
  6843. entity.AfterSaleState = 3;
  6844. }
  6845. entity.AfterSaleSupplierState = 0;
  6846. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6847. {
  6848. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6849. }
  6850. string sImgs = GetPostString("img");
  6851. entity.AfterSaleSupplierImg = sImgs;
  6852. entity.supRefundType = GetPostString("supRefundType");
  6853. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6854. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6855. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6856. entity.AfterSaleMemoType = GetPostString("MemoType");
  6857. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6858. {
  6859. //entity.AfterSaleSupplierState = 2;
  6860. }
  6861. string df = GetPostString("DeductFee");
  6862. if (df == "")
  6863. {
  6864. df = "0";
  6865. }
  6866. string rf = GetPostString("RefundFee");
  6867. if (rf == "")
  6868. {
  6869. rf = "0";
  6870. }
  6871. string pm = GetPostString("AfterSalePayment");
  6872. if (pm == "")
  6873. {
  6874. pm = "0";
  6875. }
  6876. entity.AfterSalePayment = Convert.ToDouble(pm);
  6877. entity.DeductFee = Convert.ToDouble(df);
  6878. entity.RefundFee = Convert.ToDouble(rf);
  6879. entity.UpdateTime = DateTime.Now;
  6880. entity.Update();
  6881. string toState = GetPostString("ToState");
  6882. string original = GetPostString("isOriginal");
  6883. ApiVo apiVo = new ApiVo();
  6884. apiVo.orderNumber = entity.ctid;
  6885. apiVo.actionName = "afterDesign";
  6886. apiVo.orderRemarks = entity.AfterSaleMethod;
  6887. apiVo.reasonRemarks = entity.AfterSaleReason;
  6888. apiVo.isDesign = isDesign;
  6889. apiVo.designFree = designFree;
  6890. apiVo.responsibleId = responsibleId;
  6891. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6892. if (toState == "设计师")
  6893. {
  6894. apiVo.isOriginal = Convert.ToBoolean(original);
  6895. }
  6896. designHelper.API_WorkCore(apiVo);//afterDesign
  6897. CeErpMethod methodSql = new CeErpMethod();
  6898. methodSql.con = entity.AfterSaleMethod;
  6899. methodSql.addTime = DateTime.Now;
  6900. methodSql.Create();
  6901. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6902. CeErpMethod.ExecuteNonQuery(delsql);
  6903. if (isCompale)
  6904. {
  6905. aftersale_data_change(entity.ctid);
  6906. }
  6907. returnSuccessMsg("操作成功!");
  6908. return;
  6909. }
  6910. returnErrorMsg("找不到订单记录");
  6911. }
  6912. }
  6913. public void ins_erp_toresponsible()
  6914. {
  6915. if (UrlPostParmsCheck("ctid"))
  6916. {
  6917. string eid = GetPostString("ctid");
  6918. CeErpTradeCell entity = null;
  6919. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6920. if (entity != null)
  6921. {
  6922. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6923. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6924. {
  6925. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6926. return;
  6927. }
  6928. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6929. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6930. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6931. if (entity.AfterSalePreTime == null)
  6932. {
  6933. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6934. {
  6935. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6936. }
  6937. }
  6938. entity.AfterSalePreTime = DateTime.Now;
  6939. //预完成给售后主管审核客户问题直接完成
  6940. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6941. {
  6942. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6943. {
  6944. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6945. }
  6946. }
  6947. ceErpTradeAfterSaleExtend.Update();
  6948. entity.AfterSaleState = 2;
  6949. entity.UpdateTime = DateTime.Now;
  6950. entity.Update();
  6951. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  6952. aftersale_data_change(entity.ctid);
  6953. returnSuccessMsg("操作成功!");
  6954. return;
  6955. }
  6956. returnErrorMsg("找不到订单记录");
  6957. }
  6958. }
  6959. public void cancel_erp_aftersaleanddelnew()
  6960. {
  6961. if (UrlPostParmsCheck("ctid"))
  6962. {
  6963. string eid = GetPostString("ctid");
  6964. CeErpTradeCell entity = null;
  6965. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6966. if (entity != null)
  6967. {
  6968. entity.AfterSaleState = 0;
  6969. entity.AfterSaleReason = "";
  6970. entity.AfterSaleMethod = "";
  6971. entity.AfterSaleMemo = "";
  6972. entity.AfterSaleResponsible = "";
  6973. entity.ResponsibleUserId = "";
  6974. entity.DeductFee = 0;
  6975. entity.RefundFee = 0;
  6976. entity.IsArbitrate = 0;
  6977. CeErpTradeResponsible.DelByTid(eid, -1);
  6978. entity.Update();
  6979. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  6980. if (after != null)
  6981. {
  6982. if (after.OrderState < 5)
  6983. CeErpTradeCell.DelByCtid("S_" + eid);
  6984. }
  6985. returnSuccessMsg("操作成功!");
  6986. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  6987. return;
  6988. }
  6989. returnErrorMsg("找不到订单记录");
  6990. }
  6991. }
  6992. public void get_erp_aftersale_pregather()
  6993. {
  6994. List<string> lw = new List<string>();
  6995. int st = GetInt("st");
  6996. string tid = GetPostString("ctid");
  6997. if (tid.Length > 0)
  6998. {
  6999. string select_tid = getTidByCtid(tid);
  7000. lw.Add(string.Format("tid='{0}'", select_tid));
  7001. }
  7002. string shopname = GetPostString("shopname");
  7003. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7004. string buyernick = GetPostString("buyer_nick");
  7005. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7006. string sellermemo = GetPostString("seller_memo");
  7007. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7008. string orderState = GetPostString("orderState");
  7009. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7010. string reason = GetPostString("reason");
  7011. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7012. string method = GetPostString("method");
  7013. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7014. string handler = GetPostString("handler");
  7015. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7016. string handledate1 = GetPostString("handledate1");
  7017. string handledate2 = GetPostString("handledate2");
  7018. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7019. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7020. string supplier = GetPostString("supplier");
  7021. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7022. string responsible = GetPostString("responsibleman");
  7023. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7024. string customer = GetPostString("customer");
  7025. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7026. string design = GetPostString("design");
  7027. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7028. string afterMemoType = GetPostString("aftermemotype");
  7029. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7030. string afterSaleMemo = GetPostString("afterSaleMemo");
  7031. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7032. string afterresult = GetPostString("afterresult");
  7033. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7034. string poscode = CurrentUser.UserPost.Post.Code;
  7035. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7036. {
  7037. string shopid = CurrentUser.User.pemShop;
  7038. lw.Add(string.Format("shopId in ({0})", shopid));
  7039. }
  7040. var mainwhere = string.Join(" and ", lw.ToArray());
  7041. string ro_json = "";
  7042. string type = GetPostString("gather_type");
  7043. int number = 0;
  7044. if (poscode == "AfterSale")
  7045. {
  7046. //处理中
  7047. if (type == "Handling")
  7048. {
  7049. 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) : ""));
  7050. DataTable dt = null;
  7051. try
  7052. {
  7053. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7054. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7055. }
  7056. catch (Exception e)
  7057. {
  7058. dt = new DataTable();
  7059. }
  7060. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7061. return;
  7062. }
  7063. if (type == "Wait")
  7064. {
  7065. //待处理
  7066. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7067. DataTable dt1 = null;
  7068. try
  7069. {
  7070. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7071. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7072. }
  7073. catch (Exception e)
  7074. {
  7075. dt1 = new DataTable();
  7076. }
  7077. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7078. return;
  7079. }
  7080. if (type == "back")
  7081. {
  7082. //打回
  7083. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7084. DataTable dt2 = null;
  7085. try
  7086. {
  7087. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7088. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7089. }
  7090. catch (Exception e)
  7091. {
  7092. dt2 = new DataTable();
  7093. }
  7094. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7095. return;
  7096. }
  7097. if (type == "preCompletion")
  7098. {
  7099. //预完成
  7100. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7101. DataTable dt3 = null;
  7102. try
  7103. {
  7104. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7105. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7106. }
  7107. catch (Exception e)
  7108. {
  7109. dt3 = new DataTable();
  7110. }
  7111. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7112. return;
  7113. }
  7114. if (type == "documentary")
  7115. {
  7116. //跟单中
  7117. 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) : ""));
  7118. DataTable dt4 = null;
  7119. try
  7120. {
  7121. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7122. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7123. }
  7124. catch (Exception e)
  7125. {
  7126. dt4 = new DataTable();
  7127. }
  7128. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7129. return;
  7130. }
  7131. if (type == "reBack")
  7132. {
  7133. //被打回
  7134. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7135. DataTable dt1 = null;
  7136. try
  7137. {
  7138. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7139. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7140. }
  7141. catch (Exception e)
  7142. {
  7143. dt1 = new DataTable();
  7144. }
  7145. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7146. return;
  7147. }
  7148. }
  7149. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7150. {
  7151. if (type == "puBack")
  7152. {
  7153. //退回
  7154. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7155. DataTable dt = null;
  7156. try
  7157. {
  7158. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7159. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7160. }
  7161. catch (Exception e)
  7162. {
  7163. dt = new DataTable();
  7164. }
  7165. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7166. return;
  7167. }
  7168. if (type == "reBack")
  7169. {
  7170. //打回
  7171. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7172. DataTable dt1 = null;
  7173. try
  7174. {
  7175. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7176. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7177. }
  7178. catch (Exception e)
  7179. {
  7180. dt1 = new DataTable();
  7181. }
  7182. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7183. return;
  7184. }
  7185. if (type == "examEd")
  7186. {
  7187. //已审核
  7188. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7189. DataTable dt2 = null;
  7190. try
  7191. {
  7192. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7193. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7194. }
  7195. catch (Exception e)
  7196. {
  7197. dt2 = new DataTable();
  7198. }
  7199. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7200. return;
  7201. }
  7202. if (type == "waitExam")
  7203. {
  7204. //待审核
  7205. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7206. DataTable dt3 = null;
  7207. try
  7208. {
  7209. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7210. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7211. }
  7212. catch (Exception e)
  7213. {
  7214. dt3 = new DataTable();
  7215. }
  7216. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7217. return;
  7218. }
  7219. if (type == "Handling")
  7220. {
  7221. //处理中
  7222. 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) : ""));
  7223. DataTable dt4 = null;
  7224. try
  7225. {
  7226. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7227. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7228. }
  7229. catch (Exception e)
  7230. {
  7231. dt4 = new DataTable();
  7232. }
  7233. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7234. return;
  7235. }
  7236. if (type == "Wait")
  7237. {
  7238. //待处理
  7239. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7240. DataTable dt5 = null;
  7241. try
  7242. {
  7243. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7244. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7245. }
  7246. catch (Exception e)
  7247. {
  7248. dt5 = new DataTable();
  7249. }
  7250. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7251. return;
  7252. }
  7253. if (type == "documentary")
  7254. {
  7255. //跟单中
  7256. 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) : ""));
  7257. DataTable dt6 = null;
  7258. try
  7259. {
  7260. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7261. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7262. }
  7263. catch (Exception e)
  7264. {
  7265. dt6 = new DataTable();
  7266. }
  7267. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7268. return;
  7269. }
  7270. }
  7271. returnSuccess(ro_json);
  7272. }
  7273. public void end_erp_aftersale()
  7274. {
  7275. if (UrlPostParmsCheck("ctid"))
  7276. {
  7277. string eid = GetPostString("ctid");
  7278. CeErpTradeCell entity = null;
  7279. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7280. if (entity != null)
  7281. {
  7282. string stype = GetPostString("stype");
  7283. string typeStr = stype;
  7284. entity.AfterSaleState = 4;
  7285. entity.FinishAfterSaleTime = DateTime.Now;
  7286. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7287. entity.Update();
  7288. ApiVo apiVo = new ApiVo();
  7289. apiVo.orderNumber = entity.ctid;
  7290. apiVo.actionName = "afterOver";
  7291. designHelper.API_WorkCore(apiVo); //afterOver
  7292. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7293. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7294. CeErpSukuraData.createInfo(entity.ctid, 8);
  7295. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7296. returnSuccessMsg("操作成功!");
  7297. return;
  7298. }
  7299. returnErrorMsg("找不到订单记录");
  7300. }
  7301. }
  7302. public void ins_erp_finishaftersale()
  7303. {
  7304. if (UrlPostParmsCheck("id"))
  7305. {
  7306. string eid = GetPostString("id");
  7307. CeErpTradeResponsible entity = null;
  7308. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7309. if (entity != null)
  7310. {
  7311. entity.VerifyState = 1;
  7312. entity.VerifyTime = DateTime.Now;
  7313. entity.Update();
  7314. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7315. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7316. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7317. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7318. if (dt.Rows.Count <= 0)
  7319. {
  7320. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7321. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7322. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7323. CeErpSukuraData.createInfo(entity.tid, 8);
  7324. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7325. {
  7326. CeErpDesignerBill.Del(entity.tid);
  7327. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7328. }
  7329. }
  7330. returnSuccessMsg("操作成功!");
  7331. return;
  7332. }
  7333. returnErrorMsg("找不到订单记录");
  7334. }
  7335. }
  7336. public void upd_erp_arbitrateaftersale()
  7337. {
  7338. if (UrlPostParmsCheck("id"))
  7339. {
  7340. string eid = GetPostString("id");
  7341. CeErpTradeResponsible entity = null;
  7342. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7343. if (entity != null)
  7344. {
  7345. entity.IsArbitrate = 1;
  7346. entity.ArbitradeMemo = GetPostString("reason");
  7347. entity.VerifyState = 2;
  7348. entity.Update();
  7349. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7350. if (tradecell != null)
  7351. {
  7352. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7353. tradecell.IsArbitrate = 1;
  7354. tradecell.Update();
  7355. }
  7356. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7357. returnSuccessMsg("操作成功!");
  7358. return;
  7359. }
  7360. returnErrorMsg("找不到订单记录");
  7361. }
  7362. }
  7363. public void upd_erp_backaftersale()
  7364. {
  7365. if (UrlPostParmsCheck("tid"))
  7366. {
  7367. string eid = GetPostString("tid");
  7368. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7369. int backNum = 0;
  7370. if (number != null)
  7371. {
  7372. backNum = number.BackNum;
  7373. }
  7374. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7375. CeErpTradeCell entity = null;
  7376. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7377. if (entity != null)
  7378. {
  7379. entity.AfterSaleBackReason = GetPostString("backreason");
  7380. entity.AfterSaleState = 1;
  7381. entity.AfterSaleSupplierState = 0;
  7382. entity.UpdateTime = DateTime.Now;
  7383. entity.Update();
  7384. returnSuccessMsg("操作成功!");
  7385. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7386. return;
  7387. }
  7388. returnErrorMsg("找不到订单记录");
  7389. }
  7390. }
  7391. public void get_erp_supplieraftersalelist()
  7392. {
  7393. DataStruct dStruct = GetPostStruct();
  7394. List<string> lw = new List<string>();
  7395. string tid = GetPostString("ctid");
  7396. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7397. string shopname = GetPostString("shopname");
  7398. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7399. string buyernick = GetPostString("buyer_nick");
  7400. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7401. string sellermemo = GetPostString("seller_memo");
  7402. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7403. string orderState = GetPostString("orderState");
  7404. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7405. string afterState = GetPostString("afterstate");
  7406. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7407. string date1 = GetPostString("date1");
  7408. string date2 = GetPostString("date2");
  7409. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7410. if (dw.Length > 0) lw.Add(dw);
  7411. string price1 = GetPostString("price1");
  7412. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7413. string price2 = GetPostString("price2");
  7414. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7415. string reason = GetPostString("reason");
  7416. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7417. string method = GetPostString("method");
  7418. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7419. string handledate1 = GetPostString("handledate1");
  7420. string handledate2 = GetPostString("handledate2");
  7421. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7422. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7423. string handler = GetPostString("handler");
  7424. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7425. string afterdate1 = GetPostString("afterdate1");
  7426. string afterdate2 = GetPostString("afterdate2");
  7427. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7428. if (afterDate.Length > 0) lw.Add(afterDate);
  7429. string customer = GetPostString("customer");
  7430. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7431. string design = GetPostString("design");
  7432. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7433. string afterMemoType = GetPostString("aftermemotype");
  7434. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7435. string vstate = GetPostString("vstate");
  7436. if (vstate.Length > 0)
  7437. {
  7438. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7439. }
  7440. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7441. string supplier = GetPostString("supplier");
  7442. int supid = commonHelper.getSupplierIDByName(supplier);
  7443. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7444. string posCode = CurrentUser.UserPost.Post.Code;
  7445. if (posCode == "Supplier")
  7446. {
  7447. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7448. }
  7449. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7450. {
  7451. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7452. }
  7453. else
  7454. {
  7455. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7456. }
  7457. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7458. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7459. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7460. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7461. writeGridDataTableJson(dStruct.TotalCount, dt);
  7462. }
  7463. public void upd_erp_supverifyaftersale()
  7464. {
  7465. if (UrlPostParmsCheck("id"))
  7466. {
  7467. string id = GetPostString("id");
  7468. int st = GetPostInt("afterstate");
  7469. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7470. CeErpTradeCell entity = null;
  7471. if (ceErpTradeResponsible != null)
  7472. {
  7473. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7474. }
  7475. string afmemo = GetPostString("supmemo");
  7476. string image = GetPostString("image");
  7477. if (entity != null)
  7478. {
  7479. entity.AfterSaleSupplierState = st;
  7480. entity.AfterSaleSupplierMemo = afmemo;
  7481. if (st == 1)
  7482. {
  7483. ceErpTradeResponsible.VerifyState = 1;
  7484. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7485. ceErpTradeResponsible.Update();
  7486. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7487. if (isAll)
  7488. {
  7489. entity.AfterSaleState = 4;
  7490. entity.FinishAfterSaleTime = DateTime.Now;
  7491. }
  7492. }
  7493. else
  7494. {
  7495. CeErpTradeResponsible.dateByTid(entity.ctid);
  7496. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7497. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7498. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7499. if (num <= 1)
  7500. {
  7501. entity.AfterSaleState = 1;
  7502. }
  7503. else
  7504. {
  7505. entity.AfterSaleState = 5;
  7506. }
  7507. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7508. if (ceErpTradeAfterSaleExtend != null)
  7509. {
  7510. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7511. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7512. ceErpTradeAfterSaleExtend.Update();
  7513. }
  7514. else
  7515. {
  7516. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7517. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7518. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7519. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7520. ceErpTradeAfterSaleExtend.Create();
  7521. }
  7522. }
  7523. if (entity.AfterSaleState == 4)
  7524. {
  7525. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7526. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7527. {
  7528. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7529. }
  7530. ApiVo apiVo = new ApiVo();
  7531. apiVo.orderNumber = entity.ctid;
  7532. apiVo.actionName = "afterOver";
  7533. designHelper.API_WorkCore(apiVo); //afterOver
  7534. }
  7535. entity.UpdateTime = DateTime.Now;
  7536. entity.Update();
  7537. returnSuccessMsg("操作成功!");
  7538. CeErpSukuraData.createInfo(entity.ctid, 8);
  7539. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7540. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7541. return;
  7542. }
  7543. returnErrorMsg("找不到订单记录");
  7544. }
  7545. }
  7546. public void upd_erp_masteraftersale()
  7547. {
  7548. if (UrlPostParmsCheck("id"))
  7549. {
  7550. string id = GetPostString("id");
  7551. int st = GetPostInt("afterstate");
  7552. string afmemo = GetPostString("supmemo");
  7553. string image = GetPostString("image");
  7554. string textResult = GetPostString("textResult");
  7555. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7556. if (ceErpTradeResponsible != null)
  7557. {
  7558. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7559. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7560. ceErpTradeResponsible.Update();
  7561. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7562. if (entity != null)
  7563. {
  7564. entity.AfterSaleSupplierState = st;
  7565. entity.AfterSaleSupplierMemo = afmemo;
  7566. if (st == 1)
  7567. {
  7568. }
  7569. else
  7570. {
  7571. CeErpTradeResponsible.dateByTid(entity.ctid);
  7572. //退回到售后
  7573. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7574. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7575. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7576. if (num <= 1)
  7577. {
  7578. entity.AfterSaleState = 1;
  7579. }
  7580. else
  7581. {
  7582. entity.AfterSaleState = 5;
  7583. }
  7584. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7585. if (ceErpTradeAfterSaleExtend != null)
  7586. {
  7587. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7588. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7589. ceErpTradeAfterSaleExtend.Update();
  7590. }
  7591. else
  7592. {
  7593. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7594. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7595. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7596. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7597. ceErpTradeAfterSaleExtend.Create();
  7598. }
  7599. }
  7600. entity.UpdateTime = DateTime.Now;
  7601. entity.Update();
  7602. returnSuccessMsg("操作成功!");
  7603. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7604. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7605. return;
  7606. }
  7607. }
  7608. returnErrorMsg("找不到订单记录");
  7609. }
  7610. }
  7611. public void upd_erp_personaftersale()
  7612. {
  7613. if (UrlPostParmsCheck("id"))
  7614. {
  7615. //林小连
  7616. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7617. {
  7618. upd_erp_masteraftersale();
  7619. return;
  7620. }
  7621. string id = GetPostString("id");
  7622. int st = GetPostInt("afterstate");
  7623. string afmemo = GetPostString("supmemo");
  7624. string image = GetPostString("image");
  7625. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7626. if (ceErpTradeResponsible != null)
  7627. {
  7628. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7629. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7630. ceErpTradeResponsible.Update();
  7631. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7632. if (entity != null)
  7633. {
  7634. entity.AfterSaleSupplierMemo = afmemo;
  7635. entity.AfterSaleSupplierState = st;
  7636. if (st == 1)
  7637. {
  7638. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7639. if (isAll)
  7640. {
  7641. entity.AfterSaleState = 4;
  7642. entity.FinishAfterSaleTime = DateTime.Now;
  7643. }
  7644. }
  7645. else
  7646. {
  7647. CeErpTradeResponsible.dateByTid(entity.ctid);
  7648. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7649. if (ceErpTradeAfterSaleExtend != null)
  7650. {
  7651. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7652. ceErpTradeAfterSaleExtend.Update();
  7653. }
  7654. else
  7655. {
  7656. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7657. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7658. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7659. ceErpTradeAfterSaleExtend.Create();
  7660. }
  7661. //退回到主管
  7662. //entity.AfterSaleState = 2;
  7663. }
  7664. if (entity.AfterSaleState == 4)
  7665. {
  7666. ApiVo apiVo = new ApiVo();
  7667. apiVo.orderNumber = entity.ctid;
  7668. apiVo.actionName = "afterOver";
  7669. designHelper.API_WorkCore(apiVo); //afterOver
  7670. }
  7671. entity.UpdateTime = DateTime.Now;
  7672. entity.Update();
  7673. returnSuccessMsg("操作成功!");
  7674. CeErpSukuraData.createInfo(entity.ctid, 8);
  7675. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7676. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7677. return;
  7678. }
  7679. }
  7680. returnErrorMsg("找不到订单记录");
  7681. }
  7682. }
  7683. public void set_erp_supplierrefundtag()
  7684. {
  7685. if (UrlPostParmsCheck("ctid"))
  7686. {
  7687. string eid = GetPostString("ctid");
  7688. CeErpTradeCell entity = null;
  7689. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7690. if (entity != null)
  7691. {
  7692. entity.IsSupplierRefund = GetPostInt("tag");
  7693. entity.Update();
  7694. returnSuccessMsg("操作成功!");
  7695. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7696. return;
  7697. }
  7698. returnErrorMsg("找不到订单记录");
  7699. }
  7700. }
  7701. public void get_erp_refundlist()
  7702. {
  7703. DataStruct dStruct = GetPostStruct();
  7704. List<string> lw = new List<string>();
  7705. string tid = GetPostString("tid");
  7706. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7707. //string rid = GetPostString("refund_id");
  7708. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7709. string shopname = GetPostString("shopname");
  7710. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7711. string buyernick = GetPostString("buyer_nick");
  7712. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7713. string customer = GetPostString("customer");
  7714. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7715. string design = GetPostString("design");
  7716. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7717. string sellermemo = GetPostString("seller_memo");
  7718. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7719. //string date1 = GetPostString("date1");
  7720. //string date2 = GetPostString("date2");
  7721. //string dateType = GetPostString("dateType");
  7722. //if (dateType.Length > 0)
  7723. //{
  7724. // if (dateType == "1001") dateType = "0";
  7725. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7726. // if (searchDT.Count == 2)
  7727. // {
  7728. // date1 = searchDT[0].ToString();
  7729. // date2 = searchDT[1].ToString();
  7730. // }
  7731. //}
  7732. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7733. //if (dw.Length > 0) lw.Add(dw);
  7734. string redate1 = GetPostString("refunddate1");
  7735. string redate2 = GetPostString("refunddate2");
  7736. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7737. if (dwdate.Length > 0) lw.Add(dwdate);
  7738. string price1 = GetPostString("price1");
  7739. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7740. string price2 = GetPostString("price2");
  7741. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7742. string ispartrefund = GetPostString("ispartrefund");
  7743. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7744. string refundState = GetPostString("refundvstate");
  7745. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7746. int st = GetInt("st");
  7747. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7748. {
  7749. string responsible = GetPostString("responsibleman");
  7750. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7751. lw.Add(string.Format("RefundState>={0}", st));
  7752. string code = CurrentUser.UserPost.Post.Code;
  7753. if (code == "CustomerService")
  7754. {
  7755. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7756. }
  7757. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7758. {
  7759. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7760. }
  7761. else if (code == "Place" || code == "PlaceMr")
  7762. {
  7763. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7764. }
  7765. dStruct.Order = "RefundState asc,created desc";
  7766. }
  7767. else if (st == 10)
  7768. {
  7769. string responsible = GetPostString("responsibleman");
  7770. if (responsible == "空白")
  7771. {
  7772. lw.Add(string.Format("ResponsibleUserName = ''"));
  7773. }
  7774. else if (responsible.Length > 0)
  7775. {
  7776. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7777. }
  7778. lw.Add(string.Format("RefundState>=0"));
  7779. dStruct.Order = "created desc";
  7780. }
  7781. else
  7782. {
  7783. string responsible = GetPostString("responsibleman");
  7784. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7785. lw.Add(string.Format("RefundState={0}", st));
  7786. dStruct.Order = "created desc";
  7787. }
  7788. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7789. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7790. dt.Columns.Add("refund_fees");
  7791. foreach (DataRow dr in dt.Rows)
  7792. {
  7793. String status = dr["status"].ToString();
  7794. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7795. {
  7796. dr["refund_fees"] = dr["refund_fee"];
  7797. }
  7798. else
  7799. {
  7800. dr["refund_fees"] = "0.0";
  7801. }
  7802. }
  7803. writeGridDataTableJson(dStruct.TotalCount, dt);
  7804. }
  7805. public void get_erp_refunddesignlist()
  7806. {
  7807. DataStruct dStruct = GetPostStruct();
  7808. List<string> lw = new List<string>();
  7809. string tid = GetPostString("tid");
  7810. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7811. string shopname = GetPostString("shopname");
  7812. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7813. string buyernick = GetPostString("buyer_nick");
  7814. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7815. string customer = GetPostString("customer");
  7816. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7817. string design = GetPostString("design");
  7818. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7819. string sellermemo = GetPostString("seller_memo");
  7820. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7821. string redate1 = GetPostString("refunddate1");
  7822. string redate2 = GetPostString("refunddate2");
  7823. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7824. if (dwdate.Length > 0) lw.Add(dwdate);
  7825. string price1 = GetPostString("price1");
  7826. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7827. string price2 = GetPostString("price2");
  7828. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7829. string ispartrefund = GetPostString("ispartrefund");
  7830. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7831. string designerorg = GetPostString("designerorg");
  7832. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7833. string refundState = GetPostString("refundState");
  7834. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7835. int myOrgid = CurrentUser.UserPost.OrgID;
  7836. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7837. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7838. {
  7839. if (CurrentUser.User.TeamIds.Length > 0)
  7840. {
  7841. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7842. }
  7843. else
  7844. {
  7845. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7846. }
  7847. }
  7848. else if ("SysAdmin".Equals(myOrgCode))
  7849. {
  7850. }
  7851. else
  7852. {
  7853. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7854. {
  7855. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7856. }
  7857. else
  7858. {
  7859. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7860. }
  7861. }
  7862. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7863. dStruct.Order = "created desc";
  7864. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7865. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7866. dt.Columns.Add("refund_fees");
  7867. foreach (DataRow dr in dt.Rows)
  7868. {
  7869. String status = dr["status"].ToString();
  7870. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7871. {
  7872. dr["refund_fees"] = dr["refund_fee"];
  7873. }
  7874. else
  7875. {
  7876. dr["refund_fees"] = "0.0";
  7877. }
  7878. }
  7879. writeGridDataTableJson(dStruct.TotalCount, dt);
  7880. }
  7881. public void handle_erp_refundtag()
  7882. {
  7883. if (UrlPostParmsCheck("refund_id"))
  7884. {
  7885. string eid = GetPostString("refund_id");
  7886. string respMan = GetPostString("ResponsibleName");
  7887. if (respMan.Length <= 0)
  7888. {
  7889. returnErrorMsg("责任人不能为空");
  7890. return;
  7891. }
  7892. CeErpTradeRefund entity = null;
  7893. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7894. if (entity != null)
  7895. {
  7896. entity.ResponsibleUserName = respMan;
  7897. string userid = GetPostString("ResponsibleUserId");
  7898. if (userid.Length > 0)
  7899. {
  7900. entity.ResponsibleUserId = userid;
  7901. }
  7902. entity.Memo = GetPostString("Memo");
  7903. if (respMan.IndexOf("客服") != -1 ||
  7904. respMan.IndexOf("设计师") != -1 ||
  7905. respMan.IndexOf("下单员") != -1)
  7906. {
  7907. entity.RefundState = 2;
  7908. }
  7909. else
  7910. {
  7911. entity.RefundState = 3;
  7912. }
  7913. entity.modified = DateTime.Now;
  7914. entity.Update();
  7915. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7916. returnSuccessMsg("操作成功!");
  7917. return;
  7918. }
  7919. returnErrorMsg("找不到订单记录");
  7920. }
  7921. }
  7922. public void handle_erp_designrefundtag()
  7923. {
  7924. if (UrlPostParmsCheck("refund_id"))
  7925. {
  7926. string eid = GetPostString("refund_id");
  7927. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7928. if (ceErpTradeCellExtend == null)
  7929. {
  7930. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7931. ceErpTradeCellExtend.ctid = eid;
  7932. }
  7933. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7934. if (ceErpTradeCellExtend.ID > 0)
  7935. {
  7936. ceErpTradeCellExtend.Update();
  7937. }
  7938. else
  7939. {
  7940. ceErpTradeCellExtend.Create();
  7941. }
  7942. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7943. returnSuccessMsg("操作成功!");
  7944. return;
  7945. }
  7946. returnErrorMsg("找不到订单记录");
  7947. }
  7948. public void upd_erp_refundverify()
  7949. {
  7950. if (UrlPostParmsCheck("refund_id"))
  7951. {
  7952. string eid = GetPostString("refund_id");
  7953. CeErpTradeRefund entity = null;
  7954. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7955. if (entity != null)
  7956. {
  7957. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  7958. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  7959. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  7960. {
  7961. entity.RefundState = 2;
  7962. }
  7963. else
  7964. {
  7965. entity.RefundState = 3;
  7966. }
  7967. entity.Update();
  7968. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  7969. returnSuccessMsg("操作成功!");
  7970. return;
  7971. }
  7972. returnErrorMsg("找不到订单记录");
  7973. }
  7974. }
  7975. public void upd_erp_refundapprove()
  7976. {
  7977. if (UrlPostParmsCheck("refund_id"))
  7978. {
  7979. string eid = GetPostString("refund_id");
  7980. CeErpTradeRefund entity = null;
  7981. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7982. if (entity != null)
  7983. {
  7984. int apr = GetPostInt("approve");
  7985. if (apr == 0)
  7986. {
  7987. entity.RefundState = 1;
  7988. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  7989. }
  7990. else if (apr == 1)
  7991. {
  7992. entity.RefundState = 3;
  7993. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  7994. }
  7995. entity.modified = DateTime.Now;
  7996. entity.Update();
  7997. returnSuccessMsg("操作成功!");
  7998. return;
  7999. }
  8000. returnErrorMsg("找不到订单记录");
  8001. }
  8002. }
  8003. public void get_erp_billlist()
  8004. {
  8005. DataStruct dStruct = GetPostStruct();
  8006. List<string> lw = new List<string>();
  8007. string title = GetPostString("title");
  8008. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8009. string tid = GetPostString("tid");
  8010. string tids = GetPostString("tids");
  8011. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8012. if (tids.Length > 0)
  8013. {
  8014. tids = "'" + tids + "'";
  8015. tids = tids.Replace(",", "','");
  8016. lw.Add(string.Format("tid in ({0})", tids));
  8017. }
  8018. string shopname = GetPostString("shopname");
  8019. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8020. string buyernick = GetPostString("buyer_nick");
  8021. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8022. string customer = GetPostString("customer");
  8023. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8024. string date1 = GetPostString("date1");
  8025. string date2 = GetPostString("date2");
  8026. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8027. if (dw.Length > 0) lw.Add(dw);
  8028. string price1 = GetPostString("price1");
  8029. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8030. string price2 = GetPostString("price2");
  8031. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8032. string returndate1 = GetPostString("returndate1");
  8033. string returndate2 = GetPostString("returndate2");
  8034. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8035. if (dw1.Length > 0) lw.Add(dw1);
  8036. string billtype = GetPostString("billtype");
  8037. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8038. string billstate = GetPostString("billstate");
  8039. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8040. string usershop = CurrentUser.User.pemShop;
  8041. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8042. dStruct.Order = "createTime desc";
  8043. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8044. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8045. //foreach (DataRow dr in dt.Rows)
  8046. //{
  8047. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8048. //}
  8049. writeGridDataTableJson(dStruct.TotalCount, dt);
  8050. }
  8051. public void modify_erp_billinfo()
  8052. {
  8053. if (UrlPostParmsCheck("ID"))
  8054. {
  8055. string eid = GetPostString("ID");
  8056. CeErpBill bill_entity = null;
  8057. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8058. if (bill_entity != null)
  8059. {
  8060. bill_entity.tid = GetPostString("tid");
  8061. bill_entity.title = GetPostString("title");
  8062. bill_entity.tax = GetPostString("tax");
  8063. bill_entity.bank = GetPostString("bank");
  8064. bill_entity.bankac = GetPostString("bankac");
  8065. bill_entity.address = GetPostString("address");
  8066. bill_entity.phone = GetPostString("phone");
  8067. bill_entity.price = GetPostString("price");
  8068. bill_entity.productId = GetPostInt("ProductName");
  8069. bill_entity.num = GetPostInt("num");
  8070. bill_entity.unit = GetPostString("unit");
  8071. bill_entity.type = GetPostString("type");
  8072. bill_entity.sendType = GetPostString("SendType");
  8073. bill_entity.email = GetPostString("email");
  8074. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8075. bill_entity.shopName = GetPostString("ShopName");
  8076. bill_entity.applymemo = GetPostString("applymemo");
  8077. bill_entity.modifyTime = DateTime.Now;
  8078. bill_entity.createTime = DateTime.Now;
  8079. bill_entity.state = 0;
  8080. bill_entity.Update();
  8081. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8082. returnSuccessMsg("发票修改成功!");
  8083. return;
  8084. }
  8085. returnErrorMsg("找不到对应记录");
  8086. }
  8087. }
  8088. public void set_erp_invoicing()
  8089. {
  8090. if (UrlPostParmsCheck("id"))
  8091. {
  8092. try
  8093. {
  8094. string eid = GetPostString("id");
  8095. CeErpBill bill_entity = null;
  8096. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8097. if (bill_entity != null)
  8098. {
  8099. int ComId = GetPostInt("ComId");
  8100. //string memo = GetPostString("Memo");
  8101. int allInfo = GetPostInt("allinfo");
  8102. string clert = CurrentUser.User.Name;
  8103. //string detailValue = GetPostString("detailvalue");
  8104. string billId = bill_entity.billOrderId;
  8105. string[] billIdList = billId.Split(',');
  8106. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8107. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8108. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8109. {
  8110. billCount += 1;
  8111. }
  8112. if (billId.Length <= 0 || billIdList.Length != billCount)
  8113. {
  8114. bill_entity.billOrderId = "";
  8115. string prebill = "ltb";
  8116. for (int idx = 1; idx <= billCount; idx++)
  8117. {
  8118. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8119. string billoid = prebill + idx + dtstr;
  8120. bill_entity.billOrderId += billoid;
  8121. if (idx < billCount)
  8122. {
  8123. bill_entity.billOrderId += ",";
  8124. }
  8125. }
  8126. }
  8127. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8128. if (bill_entity.state == 5)
  8129. {
  8130. string errMsg = bill_entity.failerror;
  8131. string[] errlist = errMsg.Split('|');
  8132. string[] errTags = new string[errlist.Length];
  8133. for (int itag = 0; itag < errlist.Length; itag++)
  8134. {
  8135. if (errlist[itag].Length <= 0) continue;
  8136. errTags[itag] = errlist[itag].Split('&')[0];
  8137. }
  8138. for (int iii = 0; iii < errTags.Length; iii++)
  8139. {
  8140. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8141. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8142. if (billOrderList.Length >= erroBillOrderTag)
  8143. {
  8144. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8145. if (needModifyBillId.Length <= 19)
  8146. {
  8147. needModifyBillId = needModifyBillId + "1";
  8148. }
  8149. else
  8150. {
  8151. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8152. last = last + 1;
  8153. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8154. }
  8155. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8156. }
  8157. }
  8158. }
  8159. bool isHaveBillSucces = false;
  8160. string totalRes = "";
  8161. bill_entity.failerror = "";
  8162. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8163. {
  8164. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8165. totalRes += res;
  8166. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8167. {
  8168. isHaveBillSucces = true;
  8169. bill_entity.comId = ComId;
  8170. bill_entity.state = 1;
  8171. bill_entity.executeTime = DateTime.Now;
  8172. bill_entity.executeUser = clert;
  8173. }
  8174. else
  8175. {
  8176. bill_entity.state = 5;
  8177. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8178. }
  8179. }
  8180. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8181. bill_entity.Update();
  8182. if (isHaveBillSucces)
  8183. {
  8184. StringBuilder sql = new StringBuilder();
  8185. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8186. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8187. }
  8188. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8189. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8190. {
  8191. returnErrorMsg("开票失败");
  8192. }
  8193. else
  8194. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8195. return;
  8196. }
  8197. returnErrorMsg("找不到对应记录");
  8198. }
  8199. catch (Exception ex)
  8200. {
  8201. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8202. returnErrorMsg("操作失败");
  8203. }
  8204. }
  8205. }
  8206. public void get_erp_invoicing_back()
  8207. {
  8208. if (UrlPostParmsCheck("id"))
  8209. {
  8210. try
  8211. {
  8212. string id = GetPostString("id");
  8213. CeErpBill entiy = CeErpBill.Get(id);
  8214. if (entiy != null)
  8215. {
  8216. if (entiy.state == 0)
  8217. {
  8218. returnErrorMsg("发票还未开具");
  8219. return;
  8220. }
  8221. string[] billOrderList = entiy.billOrderId.Split(',');
  8222. int iTag = 0;
  8223. entiy.fplsh = "";
  8224. entiy.fpdm = "";
  8225. entiy.fphm = "";
  8226. foreach (string billOrderId in billOrderList)
  8227. {
  8228. iTag++;
  8229. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8230. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8231. {
  8232. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8233. try
  8234. {
  8235. Invoicing_get_response_Obj iObj = null;
  8236. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8237. if (iObj != null)
  8238. {
  8239. entiy.state = 2;
  8240. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8241. entiy.fpdm += iObj.list[0].c_fpdm;
  8242. entiy.fphm += iObj.list[0].c_fphm;
  8243. if (iTag < billOrderList.Length)
  8244. {
  8245. entiy.fplsh += ",";
  8246. entiy.fpdm += ",";
  8247. entiy.fphm += ",";
  8248. }
  8249. entiy.Update();
  8250. }
  8251. StringBuilder sql = new StringBuilder();
  8252. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8253. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8254. returnSuccessMsg("开票成功");
  8255. }
  8256. catch (Exception ex)
  8257. {
  8258. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8259. }
  8260. return;
  8261. }
  8262. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8263. {
  8264. var res_obj = new
  8265. {
  8266. data = "开票中"
  8267. };
  8268. string ro_json = JsonConvert.SerializeObject(res_obj);
  8269. returnSuccess(ro_json);
  8270. return;
  8271. }
  8272. else
  8273. {
  8274. int eidx = res.IndexOf("c_resultmsg");
  8275. int lidx = res.IndexOf("c_status");
  8276. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8277. entiy.state = 5;
  8278. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8279. entiy.Update();
  8280. returnErrorMsg("开票失败");
  8281. return;
  8282. }
  8283. }
  8284. }
  8285. }
  8286. catch (Exception ex)
  8287. {
  8288. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8289. }
  8290. return;
  8291. }
  8292. }
  8293. public void get_erp_invoicing()
  8294. {
  8295. if (UrlPostParmsCheck("id"))
  8296. {
  8297. try
  8298. {
  8299. string id = GetPostString("id");
  8300. CeErpBill entiy = CeErpBill.Get(id);
  8301. if (entiy != null)
  8302. {
  8303. if (entiy.state == 0)
  8304. {
  8305. returnErrorMsg("发票还未开具");
  8306. return;
  8307. }
  8308. if (entiy.sendType == "纸质发票")
  8309. {
  8310. if (entiy.img.Length <= 0)
  8311. {
  8312. returnErrorMsg("查无纸质发票");
  8313. return;
  8314. }
  8315. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8316. returnSuccess(returnres);
  8317. return;
  8318. }
  8319. string[] billOrderList = entiy.billOrderId.Split(',');
  8320. int iTag = 0;
  8321. string fpUrl = "";
  8322. entiy.fplsh = "";
  8323. entiy.fpdm = "";
  8324. entiy.fphm = "";
  8325. foreach (string billOrderId in billOrderList)
  8326. {
  8327. iTag++;
  8328. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8329. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8330. {
  8331. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8332. Invoicing_get_response_Obj iObj = null;
  8333. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8334. if (iObj != null)
  8335. {
  8336. //entiy.state = 2;
  8337. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8338. entiy.fpdm += iObj.list[0].c_fpdm;
  8339. entiy.fphm += iObj.list[0].c_fphm;
  8340. if (iTag < billOrderList.Length)
  8341. {
  8342. entiy.fplsh += ",";
  8343. entiy.fpdm += ",";
  8344. entiy.fphm += ",";
  8345. }
  8346. entiy.Update();
  8347. fpUrl += iObj.list[0].c_url + ",";
  8348. }
  8349. //returnSuccess(res);
  8350. StringBuilder sql = new StringBuilder();
  8351. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8352. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8353. }
  8354. else
  8355. {
  8356. int eidx = res.IndexOf("c_resultmsg");
  8357. //int lidx = res.IndexOf("c_status");
  8358. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8359. //开票失败
  8360. entiy.state = 5;
  8361. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8362. entiy.Update();
  8363. returnErrorMsg("开票失败");
  8364. return;
  8365. }
  8366. }
  8367. var returnObj = new
  8368. {
  8369. data = fpUrl
  8370. };
  8371. string ro_json = JsonConvert.SerializeObject(returnObj);
  8372. returnSuccess(ro_json);
  8373. }
  8374. }
  8375. catch (Exception ex)
  8376. {
  8377. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8378. }
  8379. return;
  8380. }
  8381. }
  8382. public void save_erp_billimg()
  8383. {
  8384. if (UrlPostParmsCheck("id"))
  8385. {
  8386. string eid = GetPostString("id");
  8387. CeErpBill bill_entity = null;
  8388. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8389. if (bill_entity != null)
  8390. {
  8391. bill_entity.img = GetPostString("img");
  8392. bill_entity.executeTime = DateTime.Now;
  8393. bill_entity.state = 2;
  8394. bill_entity.Update();
  8395. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8396. returnSuccessMsg("保存成功");
  8397. }
  8398. return;
  8399. }
  8400. }
  8401. public void upd_erp_billreturnback()
  8402. {
  8403. if (UrlPostParmsCheck("id"))
  8404. {
  8405. int eid = GetPostInt("id");
  8406. CeErpBill bill_entity = null;
  8407. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8408. if (bill_entity != null)
  8409. {
  8410. bill_entity.state = 3;
  8411. bill_entity.returnReason = GetPostString("reason");
  8412. bill_entity.Update();
  8413. returnSuccessMsg("驳回成功!");
  8414. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8415. }
  8416. return;
  8417. }
  8418. }
  8419. public void cancel_erp_bill()
  8420. {
  8421. if (UrlPostParmsCheck("id"))
  8422. {
  8423. int eid = GetPostInt("id");
  8424. int detailValue = GetPostInt("detailvalue");
  8425. CeErpBill bill_entity = null;
  8426. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8427. string cres = "";
  8428. string gres = "";
  8429. if (bill_entity != null)
  8430. {
  8431. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8432. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8433. {
  8434. int iTag = 0;
  8435. bill_entity.fplsh = "";
  8436. bill_entity.fpdm = "";
  8437. bill_entity.fphm = "";
  8438. foreach (string billOrderId in billOrderList)
  8439. {
  8440. iTag++;
  8441. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8442. if (gres.IndexOf("success") != -1)
  8443. {
  8444. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8445. Invoicing_get_response_Obj iObj = null;
  8446. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8447. if (iObj != null)
  8448. {
  8449. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8450. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8451. bill_entity.fphm += iObj.list[0].c_fphm;
  8452. if (iTag < billOrderList.Length)
  8453. {
  8454. bill_entity.fplsh += ",";
  8455. bill_entity.fpdm += ",";
  8456. bill_entity.fphm += ",";
  8457. }
  8458. bill_entity.Update();
  8459. }
  8460. }
  8461. else
  8462. {
  8463. returnErrorMsg(gres);
  8464. return;
  8465. }
  8466. }
  8467. }
  8468. if (bill_entity.sendType == "纸质发票")
  8469. {
  8470. //作废
  8471. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8472. //if (DateTime.Now.Month == extime.Month)
  8473. //{
  8474. //cres = taobaoHelper.cancel_invoicing(eid);
  8475. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8476. //{
  8477. bill_entity.state = 4;//已作废
  8478. bill_entity.Update();
  8479. returnSuccessMsg("发票已作废");
  8480. return;
  8481. //}
  8482. //else
  8483. //{
  8484. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8485. // bill_entity.Update();
  8486. // returnErrorMsg(cres);
  8487. // return;
  8488. //}
  8489. //}
  8490. //else
  8491. //{
  8492. // returnErrorMsg("纸质发票只能作废本月的发票");
  8493. // return;
  8494. //}
  8495. }
  8496. //红冲
  8497. int redTag = 0;
  8498. string[] fpdmList = bill_entity.fpdm.Split(',');
  8499. string[] fphmList = bill_entity.fphm.Split(',');
  8500. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8501. {
  8502. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8503. return;
  8504. }
  8505. foreach (string billOrderId in billOrderList)
  8506. {
  8507. redTag++;
  8508. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8509. cres += onecres;
  8510. cres += ",";
  8511. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8512. {
  8513. bill_entity.state = 4;//已作废
  8514. //bill_entity.Update();
  8515. //returnSuccessMsg("发票已红冲");
  8516. }
  8517. else if (onecres.IndexOf("重复冲红") != -1)
  8518. {
  8519. bill_entity.state = 4;//已作废
  8520. //bill_entity.Update();
  8521. //returnSuccessMsg("发票已红冲");
  8522. }
  8523. else
  8524. {
  8525. string errmsg = commonHelper.KeepChinese(onecres);
  8526. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8527. }
  8528. }
  8529. bill_entity.Update();
  8530. if (cres.IndexOf("失败") != -1)
  8531. returnErrorMsg("红冲失败");
  8532. else
  8533. returnSuccessMsg("发票已红冲");
  8534. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8535. return;
  8536. }
  8537. return;
  8538. }
  8539. }
  8540. public void del_erp_billorder()
  8541. {
  8542. if (UrlPostParmsCheck("id"))
  8543. {
  8544. string eid = GetPostString("id");
  8545. CeErpBill.Del(eid);
  8546. CeErpBill bill = CeErpBill.Get(eid);
  8547. if (bill != null)
  8548. {
  8549. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8550. }
  8551. returnSuccessMsg("删除成功");
  8552. }
  8553. }
  8554. public void finish_erp_bill()
  8555. {
  8556. if (UrlPostParmsCheck("ids"))
  8557. {
  8558. string eids = GetPostString("ids");
  8559. string[] list = eids.Split(',');
  8560. foreach (string eid in list)
  8561. {
  8562. CeErpBill bill = CeErpBill.Get(eid);
  8563. if (bill != null)
  8564. {
  8565. bill.state = 2;
  8566. bill.Update();
  8567. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8568. }
  8569. }
  8570. returnSuccessMsg("操作成功");
  8571. }
  8572. }
  8573. public void get_erp_returncash()
  8574. {
  8575. DataStruct dStruct = GetPostStruct();
  8576. List<string> lw = new List<string>();
  8577. string tid = GetPostString("tid");
  8578. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8579. string shopname = GetPostString("shopname");
  8580. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8581. string buyernick = GetPostString("buyer_nick");
  8582. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8583. string customer = GetPostString("customer");
  8584. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8585. string returndate1 = GetPostString("returndate1");
  8586. string returndate2 = GetPostString("returndate2");
  8587. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8588. if (dw.Length > 0) lw.Add(dw);
  8589. string finishDate1 = GetPostString("finishdate1");
  8590. string finishDate2 = GetPostString("finishdate2");
  8591. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8592. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8593. string returntype = GetPostString("returntype");
  8594. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8595. string returnvstate = GetPostString("returnvstate");
  8596. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8597. dStruct.Order = "created desc";
  8598. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8599. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8600. writeGridDataTableJson(dStruct.TotalCount, dt);
  8601. }
  8602. public void get_erp_staygoods()
  8603. {
  8604. DataStruct dStruct = GetPostStruct();
  8605. List<string> lw = new List<string>();
  8606. string tid = GetPostString("tid");
  8607. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8608. string shopname = GetPostString("shopname");
  8609. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8610. string wangwang = GetPostString("wangwang");
  8611. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8612. string customer = GetPostString("customer");
  8613. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8614. string returndate1 = GetPostString("returndate1");
  8615. string returndate2 = GetPostString("returndate2");
  8616. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8617. if (dw.Length > 0) lw.Add(dw);
  8618. string finishDate1 = GetPostString("finishdate1");
  8619. string finishDate2 = GetPostString("finishdate2");
  8620. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8621. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8622. string returnvstate = GetPostString("returnvstate");
  8623. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8624. string persuadetype = GetPostString("persuadetype");
  8625. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8626. string customerOrg = GetPostString("customerOrg");
  8627. if (customerOrg.Length > 0)
  8628. {
  8629. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8630. }
  8631. dStruct.Order = "creata_time desc";
  8632. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8633. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8634. writeGridDataTableJson(dStruct.TotalCount, dt);
  8635. }
  8636. public void upd_erp_staygoods()
  8637. {
  8638. if (UrlPostParmsCheck("id"))
  8639. {
  8640. int eid = GetPostInt("id");
  8641. CeErpStayGoods entity = null;
  8642. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8643. if (entity != null)
  8644. {
  8645. entity.audit_type = 1;
  8646. entity.audit_time = DateTime.Now;
  8647. entity.audit_u_id = CurrentUser.UserID;
  8648. entity.audit_u_name = CurrentUser.UserName;
  8649. entity.Update();
  8650. returnSuccessMsg("审核成功!");
  8651. return;
  8652. }
  8653. returnErrorMsg("找不到订单记录");
  8654. }
  8655. }
  8656. public void upd_erp_stayGoodsback()
  8657. {
  8658. if (UrlPostParmsCheck("id"))
  8659. {
  8660. int eid = GetPostInt("id");
  8661. CeErpStayGoods entity = null;
  8662. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8663. if (entity != null)
  8664. {
  8665. entity.audit_text = GetPostString("reason");
  8666. entity.audit_type = 2;
  8667. entity.audit_time = DateTime.Now;
  8668. entity.audit_u_id = CurrentUser.UserID;
  8669. entity.audit_u_name = CurrentUser.UserName;
  8670. entity.Update();
  8671. returnSuccessMsg("退回成功!");
  8672. return;
  8673. }
  8674. returnErrorMsg("找不到订单记录");
  8675. }
  8676. }
  8677. public void upd_erp_returncashverify()
  8678. {
  8679. if (UrlPostParmsCheck("ID"))
  8680. {
  8681. int eid = GetPostInt("ID");
  8682. CeErpReturnCash entity = null;
  8683. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8684. if (entity != null)
  8685. {
  8686. entity.cashstate = 1;
  8687. entity.verifytime = DateTime.Now;
  8688. entity.verifyuserid = CurrentUser.UserID;
  8689. entity.Update();
  8690. returnSuccessMsg("审核成功!");
  8691. return;
  8692. }
  8693. returnErrorMsg("找不到订单记录");
  8694. }
  8695. }
  8696. public void upd_all_erp_returncashverify()
  8697. {
  8698. if (UrlPostParmsCheck("ID"))
  8699. {
  8700. String[] list = GetPostString("ID").Split(',');
  8701. CeErpReturnCash entity = null;
  8702. for (int i = 0; i < list.Length; i++)
  8703. {
  8704. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8705. if (entity != null)
  8706. {
  8707. if (entity.cashstate == 1)
  8708. {
  8709. returnErrorMsg("已审核过的订单不需要在审核!");
  8710. return;
  8711. }
  8712. entity.cashstate = 1;
  8713. entity.verifytime = DateTime.Now;
  8714. entity.verifyuserid = CurrentUser.UserID;
  8715. entity.Update();
  8716. }
  8717. }
  8718. returnSuccessMsg("审核成功!");
  8719. return;
  8720. }
  8721. }
  8722. public void upd_erp_returncashback()
  8723. {
  8724. if (UrlPostParmsCheck("ID"))
  8725. {
  8726. int eid = GetPostInt("ID");
  8727. CeErpReturnCash entity = null;
  8728. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8729. if (entity != null)
  8730. {
  8731. entity.backreason = GetPostString("reason");
  8732. entity.cashstate = 2;
  8733. entity.verifytime = DateTime.Now;
  8734. entity.verifyuserid = CurrentUser.UserID;
  8735. entity.Update();
  8736. returnSuccessMsg("退回成功!");
  8737. return;
  8738. }
  8739. returnErrorMsg("找不到订单记录");
  8740. }
  8741. }
  8742. public void upd_erp_returnprice()
  8743. {
  8744. if (UrlPostParmsCheck("ID"))
  8745. {
  8746. int eid = GetPostInt("ID");
  8747. CeErpReturnCash entity = null;
  8748. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8749. if (entity != null)
  8750. {
  8751. if (entity.cashstate == 1)
  8752. {
  8753. returnErrorMsg("审核通过了不能改");
  8754. return;
  8755. }
  8756. entity.returnprice = GetPostDouble("returnprice");
  8757. entity.Update();
  8758. returnSuccessMsg("修改成功!");
  8759. return;
  8760. }
  8761. returnErrorMsg("找不到订单记录");
  8762. }
  8763. }
  8764. public void del_erp_returncash()
  8765. {
  8766. if (UrlPostParmsCheck("ID"))
  8767. {
  8768. int eid = GetPostInt("ID");
  8769. CeErpReturnCash.Del(eid);
  8770. returnSuccessMsg("操作成功");
  8771. return;
  8772. }
  8773. }
  8774. public void test_for_do_sql()
  8775. {
  8776. string sql = GetPostString("sqlstr");
  8777. if (sql.Length > 0)
  8778. {
  8779. try
  8780. {
  8781. DbHelper.DbConn.ExecuteNonQuery(sql);
  8782. var res_obj = new
  8783. {
  8784. data = "成功",
  8785. };
  8786. string ro_json = JsonConvert.SerializeObject(res_obj);
  8787. returnSuccess(ro_json);
  8788. }
  8789. catch (Exception ex)
  8790. {
  8791. var res_obj = new
  8792. {
  8793. data = ex.Message,
  8794. };
  8795. string ro_json = JsonConvert.SerializeObject(res_obj);
  8796. returnSuccess(ro_json);
  8797. }
  8798. }
  8799. }
  8800. public void get_user_info()
  8801. {
  8802. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8803. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8804. }
  8805. public void get_total_data()
  8806. {
  8807. int userId = CurrentUser.UserID;
  8808. string sql = "";
  8809. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8810. {
  8811. 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);
  8812. }
  8813. else
  8814. {
  8815. 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 " +
  8816. "(select ID from CE_ErpUser where ID = {0}) d " +
  8817. "left join " +
  8818. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8819. ") a on d.ID = a.id left join " +
  8820. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8821. ") b on a.id = b.id1 left join" +
  8822. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8823. ") c on a.id = c.id2;", userId);
  8824. }
  8825. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8826. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8827. }
  8828. public void get_date_area_total_data2()
  8829. {
  8830. int userId = CurrentUser.UserID;
  8831. string date_type = GetPostString("timetype");
  8832. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8833. string sql = "";
  8834. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8835. {
  8836. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8837. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8838. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8839. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8840. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8841. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8842. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8843. ") a on e.ID = a.id left join " +
  8844. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8845. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8846. ") b on a.id = b.id1 " +
  8847. "left join " +
  8848. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8849. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8850. ") c on a.id = c.id2 " +
  8851. "left join " +
  8852. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8853. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8854. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8855. }
  8856. else
  8857. {
  8858. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8859. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8860. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8861. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8862. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8863. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8864. ") a on e.ID = a.id left join " +
  8865. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8866. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8867. ") c on a.id = c.id2 " +
  8868. "left join " +
  8869. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8870. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8871. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8872. }
  8873. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8874. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8875. }
  8876. public void get_date_area_total_data()
  8877. {
  8878. int userId = CurrentUser.UserID;
  8879. string date_type = GetPostString("timetype");
  8880. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8881. string date1 = searchDT[0].ToString();
  8882. string date2 = searchDT[1].ToString();
  8883. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8884. {
  8885. SqlParameter[] sqlParameter ={
  8886. new SqlParameter("@userId", SqlDbType.Int,4),
  8887. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8888. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8889. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8890. };
  8891. sqlParameter[0].Value = userId;
  8892. sqlParameter[1].Value = date1;
  8893. sqlParameter[2].Value = date2;
  8894. sqlParameter[3].Direction = ParameterDirection.Output;
  8895. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8896. string res = sqlParameter[3].Value.ToString();
  8897. var res_obj = new
  8898. {
  8899. data = res
  8900. };
  8901. string ro_json = JsonConvert.SerializeObject(res_obj);
  8902. returnSuccess(ro_json);
  8903. }
  8904. else
  8905. {
  8906. SqlParameter[] sqlParameter ={
  8907. new SqlParameter("@userId", SqlDbType.Int,4),
  8908. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8909. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8910. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8911. };
  8912. sqlParameter[0].Value = userId;
  8913. sqlParameter[1].Value = date1;
  8914. sqlParameter[2].Value = date2;
  8915. sqlParameter[3].Direction = ParameterDirection.Output;
  8916. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8917. string res = sqlParameter[3].Value.ToString();
  8918. var res_obj = new
  8919. {
  8920. data = res
  8921. };
  8922. string ro_json = JsonConvert.SerializeObject(res_obj);
  8923. returnSuccess(ro_json);
  8924. }
  8925. //writeGridDataViewJson(dt.Rows.Count, dv);
  8926. }
  8927. public void get_order_list()
  8928. {
  8929. string strFields = GetPostString("paraFields");
  8930. string strOrder = GetPostString("paraOrder");
  8931. string strWhere = GetPostString("paraWhere");
  8932. string strPageSize = GetPostString("paraPageSize");
  8933. DataStruct dStruct = GetPostStruct();
  8934. dStruct.PageSize = int.Parse(strPageSize);
  8935. dStruct.Fileds = strFields;
  8936. dStruct.Order = strOrder;
  8937. dStruct.MainWhere = strWhere;
  8938. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8939. writeGridDataTableJson(dStruct.TotalCount, dt);
  8940. }
  8941. ////获取待开始订单列表
  8942. //public void get_wait_design_order_list()
  8943. //{
  8944. // string date_type = GetPostString("date_type");
  8945. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8946. // DataStruct dStruct = GetPostStruct();
  8947. // dStruct.PageSize = 1000;
  8948. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8949. // List<string> lw = new List<string>();
  8950. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8951. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  8952. // dStruct.Order = "WaitDesignTime asc";
  8953. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8954. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8955. // writeGridDataTableJson(dStruct.TotalCount, dt);
  8956. //}
  8957. //获取完成单量排名
  8958. public void get_finish_order_count_ranking()
  8959. {
  8960. /* string date_type = GetPostString("date_type");
  8961. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8962. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8963. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8964. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  8965. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8966. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8967. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8968. writeGridDataTableJson(0, new DataTable());
  8969. }
  8970. public void get_finish_order_amount_ranking()
  8971. {
  8972. /*string date_type = GetPostString("date_type");
  8973. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8974. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8975. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8976. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  8977. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8978. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8979. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8980. writeGridDataTableJson(0, new DataTable());
  8981. }
  8982. public void get_finish_refund_count_ranking()
  8983. {
  8984. string date_type = GetPostString("date_type");
  8985. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8986. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8987. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8988. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  8989. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8990. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8991. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8992. writeGridDataTableJson(dt.Rows.Count, dt);
  8993. }
  8994. public void get_finish_refund_amount_ranking()
  8995. {
  8996. string date_type = GetPostString("date_type");
  8997. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8998. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8999. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9000. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9001. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9002. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9003. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9004. writeGridDataTableJson(dt.Rows.Count, dt);
  9005. }
  9006. public void set_erp_finishorder_director()
  9007. {
  9008. if (UrlPostParmsCheck("ctid"))
  9009. {
  9010. string eid = GetPostString("ctid");
  9011. CeErpTradeCell entity = null;
  9012. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9013. if (entity != null)
  9014. {
  9015. entity.OrderState = 8;
  9016. entity.Update();
  9017. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9018. returnSuccessMsg("操作成功!");
  9019. return;
  9020. }
  9021. returnErrorMsg("找不到记录");
  9022. }
  9023. }
  9024. public void get_erp_placeregistlist()
  9025. {
  9026. DataStruct dStruct = GetPostStruct();
  9027. List<string> lw = new List<string>();
  9028. string outsid = GetPostString("outsid");
  9029. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9030. string memo = GetPostString("memo");
  9031. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9032. string filename = GetPostString("filename");
  9033. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9034. string islate = GetPostString("islate");
  9035. if (islate.Length > 0)
  9036. {
  9037. if (islate == "1")
  9038. lw.Add(string.Format("OutLate>0"));
  9039. else
  9040. lw.Add(string.Format("OutLate=0"));
  9041. }
  9042. string placedate1 = GetPostString("placedate1");
  9043. string placedate2 = GetPostString("placedate2");
  9044. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9045. if (dw.Length > 0) lw.Add(dw);
  9046. string deliveryDate1 = GetPostString("deliverydate1");
  9047. string deliveryDate2 = GetPostString("deliverydate2");
  9048. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9049. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9050. dStruct.Order = "ID desc";
  9051. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9052. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9053. writeGridDataTableJson(dStruct.TotalCount, dt);
  9054. }
  9055. public void ins_erp_placeregist()
  9056. {
  9057. if (UrlPostParmsCheck("id"))
  9058. {
  9059. string eid = GetPostString("id");
  9060. CeErpPlaceRegister entity = null;
  9061. if (eid == "0")//新增
  9062. {
  9063. entity = new CeErpPlaceRegister();
  9064. string xdTime = GetPostString("placeTime");
  9065. if (xdTime.Length > 0)
  9066. {
  9067. entity.PlactTime = Convert.ToDateTime(xdTime);
  9068. }
  9069. string fhTime = GetPostString("deliveryTime");
  9070. if (fhTime.Length > 0)
  9071. {
  9072. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9073. }
  9074. string preTime = GetPostString("preOutTime");
  9075. if (preTime.Length > 0)
  9076. {
  9077. entity.PreOutTime = Convert.ToDateTime(preTime);
  9078. }
  9079. entity.DeliveryCount = GetPostInt("deliveryCount");
  9080. entity.ReceiveCount = GetPostInt("receiveCount");
  9081. entity.OutSid = GetPostString("outSid");
  9082. entity.FileName = GetPostString("fileName");
  9083. entity.Memo = GetPostString("memo");
  9084. entity.AddUserId = CurrentUser.UserID;
  9085. entity.CreateTime = DateTime.Now;
  9086. entity.Img = GetPostString("img");
  9087. entity.Supplier = GetPostInt("supplier");
  9088. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9089. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9090. {
  9091. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9092. DateTime dt2 = (DateTime)entity.PreOutTime;
  9093. TimeSpan span = dt1.Subtract(dt2);
  9094. if (span.Days > 0)
  9095. {
  9096. entity.OutLate = span.Days;
  9097. }
  9098. }
  9099. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9100. entity.Create();
  9101. returnSuccessMsg("添加成功!");
  9102. return;
  9103. }
  9104. else //修改
  9105. {
  9106. entity = CeErpPlaceRegister.Get(eid);
  9107. if (entity != null)
  9108. {
  9109. string xdTime = GetPostString("placeTime");
  9110. if (xdTime.Length > 0)
  9111. {
  9112. entity.PlactTime = Convert.ToDateTime(xdTime);
  9113. }
  9114. string fhTime = GetPostString("deliveryTime");
  9115. if (fhTime.Length > 0)
  9116. {
  9117. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9118. }
  9119. string preTime = GetPostString("preOutTime");
  9120. if (preTime.Length > 0)
  9121. {
  9122. entity.PreOutTime = Convert.ToDateTime(preTime);
  9123. }
  9124. entity.DeliveryCount = GetPostInt("deliveryCount");
  9125. entity.ReceiveCount = GetPostInt("receiveCount");
  9126. if (entity.DeliveryCount == entity.ReceiveCount)
  9127. {
  9128. entity.CurState = "已完成";
  9129. }
  9130. else
  9131. {
  9132. entity.CurState = "未完成";
  9133. }
  9134. entity.OutSid = GetPostString("outSid");
  9135. entity.FileName = GetPostString("fileName");
  9136. entity.Memo = GetPostString("memo");
  9137. entity.Img = GetPostString("img");
  9138. entity.Supplier = GetPostInt("supplier");
  9139. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9140. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9141. {
  9142. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9143. DateTime dt2 = (DateTime)entity.PreOutTime;
  9144. TimeSpan span = dt1.Subtract(dt2);
  9145. if (span.Days > 0)
  9146. {
  9147. entity.OutLate = span.Days;
  9148. }
  9149. }
  9150. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9151. entity.Update();
  9152. returnSuccessMsg("修改成功");
  9153. return;
  9154. }
  9155. returnErrorMsg("找不到对应的记录");
  9156. return;
  9157. }
  9158. }
  9159. returnErrorMsg("缺少必要参数");
  9160. }
  9161. public void del_erp_placeregist()
  9162. {
  9163. string eid = GetPostString("id");
  9164. CeErpPlaceRegister.Del(eid);
  9165. returnSuccessMsg("删除成功!");
  9166. return;
  9167. }
  9168. public void ins_erp_placeregistbyorder()
  9169. {
  9170. string ctid = GetPostString("ctid");
  9171. if (ctid.Length > 0)
  9172. {
  9173. StringBuilder sql = new StringBuilder();
  9174. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9175. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9176. if (dt.Rows.Count > 0)
  9177. {
  9178. foreach (DataRow dr in dt.Rows)
  9179. {
  9180. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9181. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9182. entity.AddUserId = CurrentUser.UserID;
  9183. entity.tid = dr["tid"].ToString();
  9184. entity.Did = Convert.ToString(dr["ctid"]);
  9185. entity.splitTag = dr["SplitTag"].ToString();
  9186. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9187. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9188. if (pre_ctid.Length > 0)
  9189. {
  9190. sellmemo = sellmemo.Replace(pre_ctid, "");
  9191. }
  9192. sellmemo = sellmemo.Replace("[", "");
  9193. sellmemo = sellmemo.Replace("]", "");
  9194. entity.FileName = sellmemo;
  9195. string count = dr["ProductCount"].ToString();
  9196. int usecount = commonHelper.getIntCountFromString(count);
  9197. entity.DeliveryCount = usecount;
  9198. entity.CurState = "未完成";
  9199. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9200. {
  9201. entity.Supplier = 24;//dl手提袋定制
  9202. }
  9203. else
  9204. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9205. entity.CreateTime = DateTime.Now;
  9206. entity.Create();
  9207. }
  9208. returnSuccessMsg("操作成功");
  9209. return;
  9210. }
  9211. returnErrorMsg("没有找到对应订单");
  9212. return;
  9213. }
  9214. returnErrorMsg("缺少订单编号");
  9215. return;
  9216. }
  9217. public void get_erp_persuadelist()
  9218. {
  9219. DataStruct dStruct = GetPostStruct();
  9220. List<string> lw = new List<string>();
  9221. string ctid = GetPostString("ctid");
  9222. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9223. string shopname = GetPostString("shopname");
  9224. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9225. string buyernick = GetPostString("buyer_nick");
  9226. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9227. string customer = GetPostString("customer");
  9228. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9229. string returndate1 = GetPostString("returndate1");
  9230. string returndate2 = GetPostString("returndate2");
  9231. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9232. if (dw.Length > 0) lw.Add(dw);
  9233. string finishDate1 = GetPostString("finishdate1");
  9234. string finishDate2 = GetPostString("finishdate2");
  9235. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9236. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9237. string persuadetype = GetPostString("persuadetype");
  9238. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9239. string returnvstate = GetPostString("returnvstate");
  9240. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9241. dStruct.Order = "created desc";
  9242. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9243. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9244. writeGridDataTableJson(dStruct.TotalCount, dt);
  9245. }
  9246. public void upd_erp_returnpersuadeback()
  9247. {
  9248. if (UrlPostParmsCheck("ID"))
  9249. {
  9250. int eid = GetPostInt("ID");
  9251. CeErpPersuade entity = null;
  9252. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9253. if (entity != null)
  9254. {
  9255. entity.backreason = GetPostString("reason");
  9256. entity.pstate = 2;
  9257. entity.verifytime = DateTime.Now;
  9258. entity.verifyuserid = CurrentUser.UserID;
  9259. entity.Update();
  9260. returnSuccessMsg("退回成功!");
  9261. return;
  9262. }
  9263. returnErrorMsg("找不到订单记录");
  9264. }
  9265. }
  9266. public void upd_erp_returnpersuadeverify()
  9267. {
  9268. if (UrlPostParmsCheck("ID"))
  9269. {
  9270. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9271. {
  9272. returnErrorMsg("暂无权限审核");
  9273. return;
  9274. }
  9275. int eid = GetPostInt("ID");
  9276. CeErpPersuade entity = null;
  9277. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9278. if (entity != null)
  9279. {
  9280. entity.pstate = 1;
  9281. entity.verifytime = DateTime.Now;
  9282. entity.verifyuserid = CurrentUser.UserID;
  9283. entity.Update();
  9284. returnSuccessMsg("审核成功!");
  9285. return;
  9286. }
  9287. returnErrorMsg("找不到订单记录");
  9288. }
  9289. }
  9290. public void del_erp_persuade()
  9291. {
  9292. if (UrlPostParmsCheck("ID"))
  9293. {
  9294. int eid = GetPostInt("ID");
  9295. CeErpPersuade.Del(eid);
  9296. returnSuccessMsg("操作成功");
  9297. return;
  9298. }
  9299. }
  9300. public void get_erp_oldcustoupload()
  9301. {
  9302. DataStruct dStruct = GetPostStruct();
  9303. List<string> lw = new List<string>();
  9304. string buyernick = GetPostString("buyer_nick");
  9305. if (buyernick.Length > 0)
  9306. {
  9307. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9308. }
  9309. else
  9310. return;
  9311. dStruct.Order = "pay_time desc";
  9312. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9313. DataTable dt = null;
  9314. dt = WebCache.GetData("view_erptradecell", dStruct);
  9315. writeGridDataTableJson(dStruct.TotalCount, dt);
  9316. }
  9317. public void get_erp_checkorderlist()
  9318. {
  9319. DataStruct dStruct = GetPostStruct();
  9320. List<string> lw = new List<string>();
  9321. string tid = GetPostString("ctid");
  9322. if (tid.Length > 0)
  9323. {
  9324. string select_tid = getTidByCtid(tid);
  9325. lw.Add(string.Format("tid='{0}'", select_tid));
  9326. }
  9327. string shopname = GetPostString("shopname");
  9328. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9329. string buyernick = GetPostString("buyer_nick");
  9330. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9331. string customer = GetPostString("customer");
  9332. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9333. string design = GetPostString("design");
  9334. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9335. string orderState = GetPostString("orderState");
  9336. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9337. string address = GetPostString("address");
  9338. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9339. string sellermemo = GetPostString("seller_memo");
  9340. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9341. string supplier = GetPostString("supplier");
  9342. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9343. {
  9344. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9345. }
  9346. else
  9347. {
  9348. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9349. }
  9350. string date1 = GetPostString("date1");
  9351. string date2 = GetPostString("date2");
  9352. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9353. if (dw.Length > 0) lw.Add(dw);
  9354. string placedate1 = GetPostString("placedate1");
  9355. string placedate2 = GetPostString("placedate2");
  9356. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9357. if (fdw.Length > 0) lw.Add(fdw);
  9358. string price1 = GetPostString("price1");
  9359. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9360. string price2 = GetPostString("price2");
  9361. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9362. string checkst = GetPostString("checkstate");
  9363. if (checkst.Length > 0 && "10".Equals(checkst))
  9364. {
  9365. lw.Add(string.Format("CheckOut>0"));
  9366. }
  9367. else
  9368. {
  9369. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9370. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9371. }
  9372. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9373. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9374. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9375. writeGridDataTableJson(dStruct.TotalCount, dt);
  9376. }
  9377. public void ins_erp_startCheck()
  9378. {
  9379. if (UrlPostParmsCheck("ctid"))
  9380. {
  9381. string eid = GetPostString("ctid");
  9382. CeErpTradeCell entity = null;
  9383. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9384. if (entity != null)
  9385. {
  9386. entity.MemoOpt = 4;
  9387. entity.UpdateTime = DateTime.Now;
  9388. entity.Update();
  9389. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9390. CeErpSukuraData.createInfo(entity.ctid, 6);
  9391. returnSuccessMsg("操作成功!");
  9392. return;
  9393. }
  9394. returnErrorMsg("找不到记录");
  9395. }
  9396. }
  9397. public void upd_erp_sendXlw()
  9398. {
  9399. if (UrlPostParmsCheck("ctid"))
  9400. {
  9401. string eid = GetPostString("ctid");
  9402. CeErpTradeCell entity = null;
  9403. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9404. if (entity != null)
  9405. {
  9406. if (entity.IsSendGift == 1)
  9407. {
  9408. returnErrorMsg("请勿重复标记");
  9409. return;
  9410. }
  9411. entity.IsSendGift = 1;
  9412. entity.Update();
  9413. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9414. returnSuccessMsg("操作成功!");
  9415. return;
  9416. }
  9417. returnErrorMsg("找不到记录");
  9418. }
  9419. }
  9420. public void cancel_sendXlw()
  9421. {
  9422. if (UrlPostParmsCheck("ctid"))
  9423. {
  9424. string eid = GetPostString("ctid");
  9425. CeErpTradeCell entity = null;
  9426. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9427. if (entity != null)
  9428. {
  9429. if (entity.IsSendGift == 0)
  9430. {
  9431. returnErrorMsg("未标记小礼物");
  9432. return;
  9433. }
  9434. entity.IsSendGift = 0;
  9435. entity.Update();
  9436. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9437. returnSuccessMsg("操作成功!");
  9438. return;
  9439. }
  9440. returnErrorMsg("找不到记录");
  9441. }
  9442. }
  9443. public void get_erp_designbill()
  9444. {
  9445. DataStruct dStruct = GetPostStruct();
  9446. List<string> lw = new List<string>();
  9447. int isMy = GetInt("my");
  9448. if (isMy == 1)
  9449. {
  9450. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9451. }
  9452. string tid = GetPostString("tid");
  9453. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9454. string userName = GetPostString("design");
  9455. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9456. string price1 = GetPostString("price1");
  9457. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9458. string price2 = GetPostString("price2");
  9459. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9460. string rePrice1 = GetPostString("rePrice1");
  9461. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9462. string rePrice2 = GetPostString("rePrice2");
  9463. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9464. string designerType = GetPostString("designerType");
  9465. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9466. string orderState = GetPostString("orderState");
  9467. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9468. string endTime1 = GetPostString("endTime1");
  9469. string endTime2 = GetPostString("endTime2");
  9470. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9471. if (dw.Length > 0) lw.Add(dw);
  9472. string isDk = GetPostString("isDk");
  9473. if (isDk == "1")
  9474. {
  9475. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9476. }
  9477. else if (isDk == "0")
  9478. {
  9479. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9480. }
  9481. dStruct.Order = "oid, create_time desc";
  9482. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9483. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9484. writeGridDataTableJson(dStruct.TotalCount, dt);
  9485. }
  9486. public void upd_erp_designerbill()
  9487. {
  9488. if (UrlPostParmsCheck("ID"))
  9489. {
  9490. string eid = GetPostString("ID");
  9491. CeErpDesignerBill entity = null;
  9492. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9493. if (entity != null)
  9494. {
  9495. if (GetPostDouble("designerpirce") > 0)
  9496. {
  9497. entity.realPrice = GetPostDouble("designerpirce");
  9498. entity.update_time = DateTime.Now;
  9499. entity.update_u_id = CurrentUser.UserID;
  9500. entity.update_u_name = CurrentUser.UserName;
  9501. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9502. entity.Update();
  9503. returnSuccessMsg("操作成功!");
  9504. return;
  9505. }
  9506. else
  9507. {
  9508. entity.price = GetPostDouble("price");
  9509. entity.update_time = DateTime.Now;
  9510. entity.update_u_id = CurrentUser.UserID;
  9511. entity.update_u_name = CurrentUser.UserName;
  9512. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9513. entity.Update();
  9514. returnSuccessMsg("操作成功!");
  9515. return;
  9516. }
  9517. }
  9518. returnErrorMsg("找不到记录");
  9519. }
  9520. }
  9521. public void audit_erp_designerbill()
  9522. {
  9523. if (UrlPostParmsCheck("ID"))
  9524. {
  9525. string eid = GetPostString("ID");
  9526. CeErpDesignerBill entity = null;
  9527. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9528. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9529. if (entity != null)
  9530. {
  9531. entity.realPrice = GetPostDouble("designerpirce");
  9532. entity.update_time = DateTime.Now;
  9533. entity.update_u_id = CurrentUser.UserID;
  9534. entity.update_u_name = CurrentUser.UserName;
  9535. entity.isAudit = 1;
  9536. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9537. entity.Update();
  9538. if (orderEntity != null)
  9539. {
  9540. orderEntity.IsReadTag = 3;
  9541. orderEntity.Update();
  9542. }
  9543. returnSuccessMsg("操作成功!");
  9544. return;
  9545. }
  9546. returnErrorMsg("找不到记录");
  9547. }
  9548. }
  9549. public void all_audit_erp_designerbill()
  9550. {
  9551. if (UrlPostParmsCheck("idList"))
  9552. {
  9553. string[] list = GetPostString("idList").Split(',');
  9554. CeErpDesignerBill entity = null;
  9555. for (int i = 0; i < list.Length; i++)
  9556. {
  9557. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9558. if (entity == null) return;
  9559. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9560. if (orderEntity == null) return;
  9561. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9562. entity.update_time = DateTime.Now;
  9563. entity.update_u_id = CurrentUser.UserID;
  9564. entity.update_u_name = CurrentUser.UserName;
  9565. entity.isAudit = 1;
  9566. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9567. entity.Update();
  9568. orderEntity.IsReadTag = 3;
  9569. orderEntity.Update();
  9570. }
  9571. returnSuccessMsg("操作成功!");
  9572. return;
  9573. }
  9574. }
  9575. public void get_erp_sameorders()
  9576. {
  9577. if (UrlPostParmsCheck("ctid"))
  9578. {
  9579. string eid = GetPostString("ctid");
  9580. CeErpTradeCell entity = null;
  9581. entity = CeErpTradeCell.GetByCtid(eid);
  9582. if (entity != null)
  9583. {
  9584. StringBuilder sql = new StringBuilder();
  9585. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9586. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9587. var res = new
  9588. {
  9589. data = dt.Rows.Count
  9590. };
  9591. string ro_jsond = JsonConvert.SerializeObject(res);
  9592. returnSuccess(ro_jsond);
  9593. return;
  9594. }
  9595. returnErrorMsg("未找到订单");
  9596. return;
  9597. }
  9598. returnErrorMsg("缺少必要的参数");
  9599. }
  9600. public void get_erp_islasthavesameorder()
  9601. {
  9602. if (UrlPostParmsCheck("ctid"))
  9603. {
  9604. string eid = GetPostString("ctid");
  9605. string[] ctidList = eid.Split(',');
  9606. StringBuilder sql = new StringBuilder();
  9607. string tisCtid = "";
  9608. foreach (string ctid in ctidList)
  9609. {
  9610. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9611. if (entity != null)
  9612. {
  9613. sql = new StringBuilder();
  9614. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9615. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9616. if (dth.Rows.Count > 0)
  9617. {
  9618. tisCtid += entity.ctid;
  9619. tisCtid += ",";
  9620. }
  9621. }
  9622. }
  9623. if (tisCtid.Length > 0)
  9624. {
  9625. var res = new
  9626. {
  9627. data = tisCtid
  9628. };
  9629. string ro_jsond = JsonConvert.SerializeObject(res);
  9630. returnSuccess(ro_jsond);
  9631. }
  9632. else
  9633. {
  9634. var res = new
  9635. {
  9636. data = ""
  9637. };
  9638. string ro_jsond = JsonConvert.SerializeObject(res);
  9639. returnSuccess(ro_jsond);
  9640. }
  9641. return;
  9642. }
  9643. returnErrorMsg("缺少必要的参数");
  9644. }
  9645. public void file_client_down_url()
  9646. {
  9647. if (!UrlPostParmsCheck("userId"))
  9648. {
  9649. returnErrorMsg("缺少必要的参数");
  9650. }
  9651. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9652. }
  9653. public void checkout_form_data()
  9654. {
  9655. if (!UrlPostParmsCheck("tid"))
  9656. {
  9657. returnErrorMsg("缺少必要的参数");
  9658. }
  9659. string tid = GetPostString("tid");
  9660. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9661. if (ceErpOrderFormData != null)
  9662. {
  9663. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9664. returnSuccess(ro_jsond);
  9665. return;
  9666. }
  9667. returnErrorMsg("尚未有文件!");
  9668. }
  9669. public void back_supplier_audit()
  9670. {
  9671. int userId = CurrentUser.UserID;
  9672. StringBuilder sql = new StringBuilder();
  9673. 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);
  9674. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9675. if (dt.Rows.Count > 0)
  9676. {
  9677. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9678. }
  9679. else
  9680. {
  9681. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9682. }
  9683. }
  9684. public void back_supplier_query()
  9685. {
  9686. string eid = GetPostString("ctid");
  9687. if (eid != "")
  9688. {
  9689. StringBuilder sql = new StringBuilder();
  9690. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9691. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9692. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9693. }
  9694. else
  9695. {
  9696. returnErrorMsg("找不到订单记录");
  9697. return;
  9698. }
  9699. }
  9700. public void verified_to_order()
  9701. {
  9702. int userId = CurrentUser.UserID;
  9703. StringBuilder sql = new StringBuilder();
  9704. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9705. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9706. if (dt.Rows.Count > 0)
  9707. {
  9708. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9709. }
  9710. else
  9711. {
  9712. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9713. }
  9714. }
  9715. public void upd_supplier_audit()
  9716. {
  9717. if (UrlPostParmsCheck("ctid"))
  9718. {
  9719. string eid = GetPostString("ctid");
  9720. string reason = GetPostString("returnreason");
  9721. CeErpTradeCell entity = null;
  9722. CeWithdraw withdraw = null;
  9723. withdraw = CeWithdraw.GetByTid(eid);
  9724. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9725. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9726. {
  9727. if (withdraw != null)
  9728. {
  9729. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9730. {
  9731. returnSuccessMsg("您没有权限操作!");
  9732. return;
  9733. }
  9734. else
  9735. {
  9736. if (reason.Equals("1"))
  9737. {
  9738. if (entity.OrderState == -1)
  9739. {
  9740. if (entity.FinishPlaceTime == null)
  9741. {
  9742. entity.OrderState = 2;
  9743. }
  9744. else
  9745. {
  9746. entity.OrderState = 6;
  9747. }
  9748. }
  9749. entity.Update();
  9750. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9751. if (withdraw != null)
  9752. {
  9753. withdraw.status = int.Parse(reason);
  9754. withdraw.Update();
  9755. }
  9756. returnSuccessMsg("操作成功!");
  9757. return;
  9758. }
  9759. else
  9760. {
  9761. withdraw.status = int.Parse(reason);
  9762. withdraw.acknowledgingtime = DateTime.Now;
  9763. withdraw.Update();
  9764. returnSuccessMsg("查看详细请点击线下订单查询");
  9765. return;
  9766. }
  9767. }
  9768. }
  9769. // 第一个字符是 'N'
  9770. }
  9771. if (eid[0] != 'N')
  9772. {
  9773. }
  9774. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9775. {
  9776. entity.IsVerifyToSupplier = false;
  9777. entity.IsReturn = 1;
  9778. entity.ReturnTime = DateTime.Now;
  9779. entity.ReturnReason = reason;
  9780. if (entity.OrderState == 6)
  9781. {
  9782. entity.OrderState = 5;
  9783. }
  9784. entity.Update();
  9785. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9786. if (withdraw != null)
  9787. {
  9788. withdraw.status = int.Parse(reason);
  9789. withdraw.Update();
  9790. }
  9791. returnSuccessMsg("操作成功!");
  9792. return;
  9793. }
  9794. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9795. {
  9796. ;
  9797. if (withdraw != null)
  9798. {
  9799. withdraw.status = int.Parse(reason);
  9800. withdraw.acknowledgingtime = DateTime.Now;
  9801. withdraw.Update();
  9802. returnSuccessMsg("供应商取消撤回!");
  9803. return;
  9804. }
  9805. }
  9806. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9807. {
  9808. if (entity.OrderState == -1)
  9809. {
  9810. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9811. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9812. {
  9813. returnErrorMsg("订单spu没有确认无法通过审核!");
  9814. return;
  9815. }
  9816. if (entity.FinishPlaceTime == null)
  9817. {
  9818. entity.OrderState = 2;
  9819. }
  9820. else
  9821. {
  9822. entity.OrderState = 3;
  9823. }
  9824. commonHelper.getCytPrice(entity);
  9825. }
  9826. entity.Update();
  9827. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9828. if (withdraw != null)
  9829. {
  9830. withdraw.status = int.Parse(reason);
  9831. withdraw.Update();
  9832. }
  9833. returnSuccessMsg("操作成功!");
  9834. return;
  9835. }
  9836. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9837. {
  9838. if (withdraw == null)
  9839. {
  9840. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9841. return;
  9842. }
  9843. }
  9844. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9845. {
  9846. if (withdraw != null)
  9847. {
  9848. withdraw.status = int.Parse(reason);
  9849. withdraw.acknowledgingtime = DateTime.Now;
  9850. withdraw.Update();
  9851. returnSuccessMsg("查看详细请点击线下订单查询");
  9852. return;
  9853. }
  9854. }
  9855. return;
  9856. }
  9857. }
  9858. //校验报价
  9859. public void refund_order_tip()
  9860. {
  9861. int userid = CurrentUser.UserID;
  9862. int sectionId = CurrentUser.UserPost.OrgID;
  9863. StringBuilder sql = new StringBuilder();
  9864. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9865. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9866. List<string> ids = new List<string>();
  9867. if (dth.Rows.Count > 0)
  9868. {
  9869. foreach (DataRow dr in dth.Rows)
  9870. {
  9871. ids.Add(dr["ID"].ToString());
  9872. }
  9873. try
  9874. {
  9875. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9876. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9877. }
  9878. catch (Exception ex)
  9879. {
  9880. }
  9881. }
  9882. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9883. }
  9884. public void refund_order_Design()
  9885. {
  9886. int userid = CurrentUser.UserID;
  9887. int sectionId = CurrentUser.UserPost.OrgID;
  9888. StringBuilder sql = new StringBuilder();
  9889. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9890. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9891. List<string> ids = new List<string>();
  9892. if (dth.Rows.Count > 0)
  9893. {
  9894. foreach (DataRow dr in dth.Rows)
  9895. {
  9896. ids.Add(dr["ID"].ToString());
  9897. }
  9898. try
  9899. {
  9900. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9901. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9902. }
  9903. catch (Exception ex)
  9904. {
  9905. }
  9906. }
  9907. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9908. }
  9909. public void change_order_info()
  9910. {
  9911. int userid = CurrentUser.UserID;
  9912. StringBuilder sql = new StringBuilder();
  9913. 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);
  9914. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9915. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9916. }
  9917. public void change_win_mome()
  9918. {
  9919. if (UrlPostParmsCheck("id,ctid"))
  9920. {
  9921. string id = GetPostString("id");
  9922. string ctid = GetPostString("ctid");
  9923. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9924. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9925. if (ce == null || ceErpMessageTip == null)
  9926. {
  9927. returnSuccessMsg("未找到对应的订单!");
  9928. return;
  9929. }
  9930. if (ce.OrderState >= 5)
  9931. {
  9932. returnSuccessMsg("已上传文件无法修改!");
  9933. return;
  9934. }
  9935. int type = GetPostInt("type");
  9936. string content = GetPostString("content");
  9937. if (type == 0)
  9938. {
  9939. content = content.Replace("(", "(");
  9940. content = content.Replace(")", ")");
  9941. string check = MidStrEx(content, "(", ")").Trim();
  9942. if (string.IsNullOrEmpty(check))
  9943. {
  9944. returnSuccessMsg("文件名格式不正确");
  9945. return;
  9946. }
  9947. }
  9948. ce.DispatchSort = 0;
  9949. ce.seller_memo = content;
  9950. ce.Update();
  9951. ceErpMessageTip.isVisit = true;
  9952. ceErpMessageTip.Update();
  9953. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  9954. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  9955. ApiVo apiVo = new ApiVo();
  9956. apiVo.orderNumber = ce.ctid;
  9957. apiVo.actionName = "demandDesign";
  9958. apiVo.orderRemarks = content;
  9959. apiVo.demandExamine = type + 1;
  9960. designHelper.API_WorkCore(apiVo);//demandDesign
  9961. returnSuccessMsg("修改成功!");
  9962. }
  9963. }
  9964. public static string MidStrEx(string sourse, string startstr, string endstr)
  9965. {
  9966. string result = string.Empty;
  9967. int startindex, endindex;
  9968. try
  9969. {
  9970. startindex = sourse.IndexOf(startstr);
  9971. if (startindex == -1)
  9972. return result;
  9973. string tmpstr = sourse.Substring(startindex + startstr.Length);
  9974. endindex = tmpstr.IndexOf(endstr);
  9975. if (endindex == -1)
  9976. return result;
  9977. result = tmpstr.Remove(endindex);
  9978. }
  9979. catch (Exception ex)
  9980. {
  9981. Console.WriteLine("MidStrEx Err:" + ex.Message);
  9982. }
  9983. return result;
  9984. }
  9985. public void refund_order_list()
  9986. {
  9987. int userid = CurrentUser.UserID;
  9988. int sectionId = CurrentUser.UserPost.OrgID;
  9989. StringBuilder sql = new StringBuilder();
  9990. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  9991. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9992. DataStruct dStruct = GetPostStruct();
  9993. DataTable dt = null;
  9994. List<string> ids = new List<string>();
  9995. List<string> tids = new List<string>();
  9996. if (dth.Rows.Count > 0)
  9997. {
  9998. foreach (DataRow dr in dth.Rows)
  9999. {
  10000. tids.Add("'" + dr["tid"].ToString() + "'");
  10001. ids.Add(dr["id"].ToString());
  10002. }
  10003. try
  10004. {
  10005. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10006. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10007. List<string> lw = new List<string>();
  10008. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10009. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10010. dt = WebCache.GetData("view_orderlist", dStruct);
  10011. }
  10012. catch (Exception ex)
  10013. {
  10014. }
  10015. }
  10016. writeGridDataTableJson(dStruct.TotalCount, dt);
  10017. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10018. }
  10019. //新增
  10020. public void order_batch_downloads()
  10021. {
  10022. string ceid = GetPostString("tid");
  10023. String[] tid = ceid.Split(',');
  10024. order_batch_caiyingtong(tid);
  10025. /* (string success, string errors) = UploadFiles(tid);
  10026. returnSuccessMsg(success + errors);*/
  10027. return;
  10028. }
  10029. //报价接口
  10030. public void Get_To_Quote()
  10031. {
  10032. string ceid = GetPostString("ctid");
  10033. if (ceid != null)
  10034. {
  10035. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10036. if (entity != null)
  10037. {
  10038. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10039. {
  10040. return;
  10041. }
  10042. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10043. double price = 0;
  10044. if (cp == null)
  10045. {
  10046. JObject jsonObject12 = new JObject
  10047. {
  10048. { "UserId", "77886" },
  10049. { "Pwd", "lt666888" },
  10050. { "Filename", entity.seller_memo }
  10051. };
  10052. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10053. JObject jsonObjects1 = JObject.Parse(response1);
  10054. string ms1g = (string)jsonObjects1["msg"];
  10055. if (ms1g == "报价成功")
  10056. {
  10057. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10058. string data = (string)jsonObject1["price"];
  10059. 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 + "');";
  10060. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10061. returnSuccessMsg("获取报价成功:" + data);
  10062. price = Convert.ToDouble(data);
  10063. }
  10064. else
  10065. {
  10066. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10067. return;
  10068. }
  10069. }
  10070. String[] beizhu = entity.seller_memo.Split('-');
  10071. String chanp = "";
  10072. if (beizhu.Length > 0)
  10073. {
  10074. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10075. }
  10076. else
  10077. {
  10078. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10079. }
  10080. JObject jsonObject = new JObject
  10081. {
  10082. { "UserId", "77886" },
  10083. { "Pwd", "lt666888" },
  10084. { "Filename", chanp }
  10085. };
  10086. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10087. JObject jsonObjects = JObject.Parse(response);
  10088. string msg = (string)jsonObjects["msg"];
  10089. if (msg == "报价成功")
  10090. {
  10091. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10092. string data = (string)jsonObject1["price"];
  10093. 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 + "');";
  10094. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10095. returnSuccessMsg("获取报价成功:" + data);
  10096. price = Convert.ToDouble(data);
  10097. }
  10098. else
  10099. {
  10100. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10101. return;
  10102. }
  10103. if (price > 0)
  10104. {
  10105. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10106. if (ceErpTradeCellExtend == null)
  10107. {
  10108. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10109. ceErpTradeCellExtend.ctid = entity.ctid;
  10110. ceErpTradeCellExtend.payment_cyt = price;
  10111. ceErpTradeCellExtend.Create();
  10112. }
  10113. else
  10114. {
  10115. ceErpTradeCellExtend.payment_cyt = price;
  10116. ceErpTradeCellExtend.Update();
  10117. }
  10118. }
  10119. return;
  10120. }
  10121. }
  10122. else
  10123. {
  10124. returnErrorMsg("请至少选择一条数据");
  10125. return;
  10126. }
  10127. }
  10128. //新增
  10129. public void order_To_Supplier()
  10130. {
  10131. string ceid = GetPostString("tid");
  10132. String[] tid = ceid.Split(',');
  10133. if (tid.Length > 0)
  10134. {
  10135. try
  10136. {
  10137. for (int i = 0; i < tid.Length; i++)
  10138. {
  10139. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10140. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10141. entity.SupplierId = suid;
  10142. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10143. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10144. entity.Update();
  10145. }
  10146. }
  10147. catch (Exception ex)
  10148. {
  10149. returnErrorMsg("自动匹配供应商失败");
  10150. return;
  10151. }
  10152. }
  10153. else
  10154. {
  10155. returnErrorMsg("请至少选择一条数据");
  10156. return;
  10157. }
  10158. returnSuccessMsg("自动匹配供应商成功");
  10159. return;
  10160. }
  10161. public (string, string) UploadFiles(string[] urls)
  10162. {
  10163. string success = "";
  10164. string errors = "";
  10165. int userid = CurrentUser.UserID;
  10166. foreach (string url in urls)
  10167. {
  10168. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10169. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10170. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10171. {
  10172. JObject jsonObject = new JObject
  10173. {
  10174. { "Userid", "77886" },
  10175. { "pwd", "cyt86435015" },
  10176. { "content", base64FileContent },
  10177. { "ext", Path.GetExtension(fileName) }
  10178. };
  10179. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10180. JObject jsonObjects = JObject.Parse(response);
  10181. string msg = (string)jsonObjects["msg"];
  10182. if (msg.Equals("上传成功"))
  10183. {
  10184. success += url + " 上传成功";
  10185. }
  10186. else
  10187. {
  10188. errors += url + " 上传失败";
  10189. }
  10190. }
  10191. else
  10192. {
  10193. errors += url + " 格式出现问题";
  10194. }
  10195. }
  10196. if (urls.Length == 0)
  10197. {
  10198. return (success, errors);
  10199. }
  10200. return (success, errors);
  10201. }
  10202. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10203. {
  10204. return true; //总是接受
  10205. }
  10206. public static string HttpPost(string url, string param = null)
  10207. {
  10208. HttpWebRequest request;
  10209. //如果是发送HTTPS请求
  10210. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10211. {
  10212. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10213. request = WebRequest.Create(url) as HttpWebRequest;
  10214. request.ProtocolVersion = HttpVersion.Version10;
  10215. }
  10216. else
  10217. {
  10218. request = WebRequest.Create(url) as HttpWebRequest;
  10219. }
  10220. request.Method = "POST";
  10221. request.ContentType = "application/json";
  10222. request.Accept = "*/*";
  10223. request.Timeout = 120000;
  10224. request.AllowAutoRedirect = false;
  10225. StreamWriter requestStream = null;
  10226. WebResponse response = null;
  10227. string responseStr = null;
  10228. try
  10229. {
  10230. requestStream = new StreamWriter(request.GetRequestStream());
  10231. requestStream.Write(param);
  10232. requestStream.Close();
  10233. response = request.GetResponse();
  10234. if (response != null)
  10235. {
  10236. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10237. responseStr = reader.ReadToEnd();
  10238. reader.Close();
  10239. }
  10240. }
  10241. catch (Exception ex)
  10242. {
  10243. return ex.Message;
  10244. }
  10245. finally
  10246. {
  10247. request = null;
  10248. requestStream = null;
  10249. response = null;
  10250. }
  10251. return responseStr;
  10252. }
  10253. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10254. {
  10255. string base64FileContent;
  10256. string fileName;
  10257. using (WebClient webClient = new WebClient())
  10258. {
  10259. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10260. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10261. {
  10262. using (Stream stream = response.GetResponseStream())
  10263. {
  10264. using (MemoryStream memoryStream = new MemoryStream())
  10265. {
  10266. stream.CopyTo(memoryStream);
  10267. byte[] fileBytes = memoryStream.ToArray();
  10268. base64FileContent = Convert.ToBase64String(fileBytes);
  10269. fileName = response.Headers["Content-Disposition"];
  10270. if (!string.IsNullOrEmpty(fileName))
  10271. {
  10272. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10273. if (index >= 0)
  10274. {
  10275. fileName = fileName.Substring(index + 9).Trim('\"');
  10276. }
  10277. }
  10278. else
  10279. {
  10280. fileName = Path.GetFileName(downloadUrl);
  10281. }
  10282. }
  10283. }
  10284. }
  10285. }
  10286. return (fileName, base64FileContent);
  10287. }
  10288. //新增
  10289. public void order_batch_caiyingtong(string[] downloadUrls)
  10290. {
  10291. try
  10292. {
  10293. //遍历文件
  10294. DataStruct dStruct = GetPostStruct();
  10295. DataTable dt = null;
  10296. int userid = CurrentUser.UserID;
  10297. List<string> ids = new List<string>();//失败组
  10298. List<string> tids = new List<string>();
  10299. using (WebClient webClient = new WebClient())
  10300. {
  10301. foreach (var url in downloadUrls)
  10302. {
  10303. try
  10304. {
  10305. tids.Add("'" + url + "'");
  10306. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10307. if (entity != null)
  10308. {
  10309. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10310. if (cp == null)
  10311. {
  10312. JObject jsonObject = new JObject
  10313. {
  10314. { "Userid", "77886" },
  10315. { "pwd", "lt666888" },
  10316. { "Filename",entity.seller_memo }
  10317. };
  10318. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10319. JObject jsonObjects = JObject.Parse(response);
  10320. string msg = (string)jsonObjects["msg"];
  10321. if (msg == "报价成功")
  10322. {
  10323. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10324. DownloadAndConvertToBase64(url1);
  10325. }
  10326. else
  10327. {
  10328. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10329. }
  10330. }
  10331. else
  10332. {
  10333. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10334. JObject jsonObject = new JObject
  10335. {
  10336. { "Userid", "77886" },
  10337. { "pwd", "lt666888" },
  10338. { "Filename",chanp }
  10339. };
  10340. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10341. JObject jsonObjects = JObject.Parse(response);
  10342. string msg = (string)jsonObjects["msg"];
  10343. if (msg == "报价成功")
  10344. {
  10345. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10346. DownloadAndConvertToBase64(url1);
  10347. }
  10348. else
  10349. {
  10350. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10351. }
  10352. }
  10353. }
  10354. // 上传文件到FTP
  10355. }
  10356. catch (Exception ex)
  10357. {
  10358. Console.WriteLine($"An error occurred: {ex.Message}");
  10359. }
  10360. }
  10361. List<string> lw = new List<string>();
  10362. lw.Add(string.Format("( OrderState < 6 )"));
  10363. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10364. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10365. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10366. if (dt.Rows.Count > 0)
  10367. {
  10368. foreach (DataRow dr in dt.Rows)
  10369. {
  10370. ids.Add(dr["ctid"].ToString());
  10371. }
  10372. }
  10373. String ErrorMsgs = "";
  10374. foreach (String id in ids)
  10375. {
  10376. ErrorMsgs += id + ",";
  10377. }
  10378. if (ErrorMsgs.Length > 1)
  10379. {
  10380. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10381. }
  10382. if (ErrorMsgs.Length < 1)
  10383. {
  10384. ErrorMsgs = "上传成功";
  10385. returnSuccessMsg(ErrorMsgs);
  10386. }
  10387. else
  10388. {
  10389. returnErrorMsg("以下订单" + ErrorMsgs);
  10390. }
  10391. }
  10392. // 删除文件夹及其内容
  10393. /* Directory.Delete(localDirectory, true);*/
  10394. }
  10395. catch { }
  10396. }
  10397. public void get_center_data()
  10398. {
  10399. int userId = CurrentUser.UserID;
  10400. string postCode = CurrentUser.UserPost.Post.Code;
  10401. List<string> lw = new List<string>();
  10402. List<string> ww = new List<string>();
  10403. DateTime currentTime = DateTime.Now;
  10404. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10405. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10406. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10407. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10408. string sql = " SELECT ";
  10409. string startTime = "2023-10-01 11:22:31";
  10410. //设计
  10411. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10412. {
  10413. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10414. 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));
  10415. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10416. 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));
  10417. }
  10418. //客服
  10419. else if (postCode == "CustomerService" || postCode == "Director")
  10420. {
  10421. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10422. 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));
  10423. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10424. 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));
  10425. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10426. 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));
  10427. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10428. 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));
  10429. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10430. 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));
  10431. }
  10432. //售后
  10433. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10434. {
  10435. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10436. 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));
  10437. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10438. 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));
  10439. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10440. 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));
  10441. }
  10442. //下单部
  10443. else if (postCode == "Place" || postCode == "PlaceMr")
  10444. {
  10445. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10446. 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));
  10447. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10448. 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));
  10449. }
  10450. //车间
  10451. else if (postCode == "Supplier")
  10452. {
  10453. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10454. 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));
  10455. }
  10456. DataTable dt = new DataTable();
  10457. if (lw.Count > 0)
  10458. {
  10459. sql += string.Join(" , ", lw);
  10460. sql += " FROM ";
  10461. sql += string.Join(" , ", ww);
  10462. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10463. }
  10464. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10465. }
  10466. public void get_center_data_list()
  10467. {
  10468. int userId = CurrentUser.UserID;
  10469. string postCode = CurrentUser.UserPost.Post.Code;
  10470. string shopIds = CurrentUser.User.pemShop;
  10471. DataStruct dStruct = GetPostStruct();
  10472. List<string> lw = new List<string>();
  10473. DateTime currentTime = DateTime.Now;
  10474. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10475. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10476. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10477. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10478. string startTime = "2023-10-01 11:22:31";
  10479. int order_type = GetPostInt("order_type");
  10480. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10481. {
  10482. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10483. if (order_type == 0)
  10484. {
  10485. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10486. }
  10487. else if (order_type == 3)
  10488. {
  10489. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10490. }
  10491. else
  10492. {
  10493. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10494. }
  10495. }
  10496. //客服
  10497. if (postCode == "CustomerService" || postCode == "Director")
  10498. {
  10499. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10500. if (order_type == 0)
  10501. {
  10502. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10503. }
  10504. else if (order_type == 1)
  10505. {
  10506. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10507. }
  10508. else if (order_type == 2)
  10509. {
  10510. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10511. }
  10512. else if (order_type == 3)
  10513. {
  10514. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10515. }
  10516. else if (order_type == 4)
  10517. {
  10518. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10519. }
  10520. else
  10521. {
  10522. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10523. }
  10524. }
  10525. //售后
  10526. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10527. {
  10528. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10529. if (shopIds != "")
  10530. {
  10531. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10532. }
  10533. if (order_type == 2)
  10534. {
  10535. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10536. }
  10537. else if (order_type == 4)
  10538. {
  10539. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10540. }
  10541. else if (order_type == 5)
  10542. {
  10543. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10544. }
  10545. else
  10546. {
  10547. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10548. }
  10549. }
  10550. //下单部
  10551. if (postCode == "Place" || postCode == "PlaceMr")
  10552. {
  10553. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10554. if (shopIds != "")
  10555. {
  10556. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10557. }
  10558. else if (order_type == 1)
  10559. {
  10560. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10561. }
  10562. else if (order_type == 2)
  10563. {
  10564. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10565. }
  10566. else
  10567. {
  10568. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10569. }
  10570. }
  10571. //车间
  10572. if (postCode == "Supplier")
  10573. {
  10574. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10575. if (order_type == 5)
  10576. {
  10577. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10578. }
  10579. else
  10580. {
  10581. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10582. }
  10583. }
  10584. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10585. dStruct.Fileds = "tid,ctid";
  10586. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10587. writeGridDataTableJson(dStruct.TotalCount, dt);
  10588. }
  10589. public void aftersale_audit_master()
  10590. {
  10591. if (UrlPostParmsCheck("ctid"))
  10592. {
  10593. string ctid = GetPostString("ctid");
  10594. if (ctid.Length > 0)
  10595. {
  10596. bool result = aftersale_data_change(ctid);
  10597. if (result)
  10598. {
  10599. returnSuccessMsg("修改成功!");
  10600. return;
  10601. }
  10602. }
  10603. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10604. }
  10605. }
  10606. public void aftersale_batch_audit_master()
  10607. {
  10608. if (UrlPostParmsCheck("ctids"))
  10609. {
  10610. string ctids = GetPostString("ctids");
  10611. if (ctids.Length > 0)
  10612. {
  10613. List<string> list = new List<string>();
  10614. string[] ctid_list = ctids.Split(',');
  10615. foreach (var item in ctid_list)
  10616. {
  10617. bool result = aftersale_data_change(item);
  10618. if (!result)
  10619. {
  10620. list.Add(item);
  10621. }
  10622. }
  10623. if (list.Count > 0)
  10624. {
  10625. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10626. return;
  10627. }
  10628. returnSuccessMsg("修改成功!");
  10629. return;
  10630. }
  10631. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10632. }
  10633. }
  10634. public bool aftersale_data_change(string ctid)
  10635. {
  10636. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10637. if (ceErpTradeCell != null)
  10638. {
  10639. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10640. ceErpTradeCell.AfterSaleSupplierState = 0;
  10641. StringBuilder sql = new StringBuilder();
  10642. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10643. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10644. CeErpTradeResponsible.DelByTid(ctid, 0);
  10645. 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 == "不理赔")
  10646. {
  10647. CeErpTradeResponsible.DelByTid(ctid, 1);
  10648. ceErpTradeCell.AfterSaleSupplierState = 1;
  10649. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10650. ceErpTradeCell.AfterSaleState = 4;
  10651. }
  10652. else
  10653. {
  10654. ceErpTradeCell.AfterSaleState = 3;
  10655. }
  10656. bool needCyt = false;
  10657. if (dt != null)
  10658. {
  10659. if (dt.Rows.Count == 1)
  10660. {
  10661. bool isEnd = false;
  10662. foreach (DataRow dr in dt.Rows)
  10663. {
  10664. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10665. {
  10666. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10667. isEnd = true;
  10668. }
  10669. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10670. {
  10671. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10672. isEnd = true;
  10673. }
  10674. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10675. {
  10676. needCyt = true;
  10677. }
  10678. }
  10679. if (isEnd)
  10680. {
  10681. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10682. ceErpTradeCell.AfterSaleState = 4;
  10683. ceErpTradeCell.AfterSaleSupplierState = 1;
  10684. }
  10685. }
  10686. else
  10687. {
  10688. bool isAll = true;
  10689. foreach (DataRow dr in dt.Rows)
  10690. {
  10691. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10692. {
  10693. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10694. continue;
  10695. }
  10696. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10697. {
  10698. string path = "";
  10699. int OrgID = 0;
  10700. if (!Convert.IsDBNull(dr["OrgPath"]))
  10701. {
  10702. path = dr["OrgPath"].ToString();
  10703. }
  10704. if (!Convert.IsDBNull(dr["OrgID"]))
  10705. {
  10706. OrgID = Convert.ToInt32(dr["OrgID"]);
  10707. }
  10708. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10709. {
  10710. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10711. continue;
  10712. }
  10713. }
  10714. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10715. {
  10716. needCyt = true;
  10717. }
  10718. isAll = false;
  10719. }
  10720. if (isAll)
  10721. {
  10722. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10723. ceErpTradeCell.AfterSaleState = 4;
  10724. ceErpTradeCell.AfterSaleSupplierState = 1;
  10725. }
  10726. }
  10727. }
  10728. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10729. {
  10730. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10731. }
  10732. if (ceErpTradeCell.AfterSaleState == 4)
  10733. {
  10734. ApiVo apiVo = new ApiVo();
  10735. apiVo.orderNumber = ceErpTradeCell.ctid;
  10736. apiVo.actionName = "afterOver";
  10737. designHelper.API_WorkCore(apiVo); //afterOver
  10738. }
  10739. ceErpTradeCell.Update();
  10740. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10741. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10742. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10743. return true;
  10744. }
  10745. return false;
  10746. }
  10747. public void get_erp_wechatorder()
  10748. {
  10749. DataStruct dStruct = GetPostStruct();
  10750. List<string> lw = new List<string>();
  10751. string tid = GetPostString("tid");
  10752. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10753. string shopname = GetPostString("shopname");
  10754. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10755. string buyernick = GetPostString("buyer_nick");
  10756. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10757. string customer = GetPostString("customer");
  10758. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10759. string returndate1 = GetPostString("returndate1");
  10760. string returndate2 = GetPostString("returndate2");
  10761. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10762. if (dw.Length > 0) lw.Add(dw);
  10763. string finishDate1 = GetPostString("finishdate1");
  10764. string finishDate2 = GetPostString("finishdate2");
  10765. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10766. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10767. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10768. dStruct.Order = "created desc";
  10769. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10770. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10771. writeGridDataTableJson(dStruct.TotalCount, dt);
  10772. }
  10773. public void get_erp_wechatlist_sumprice()
  10774. {
  10775. DataStruct dStruct = GetPostStruct();
  10776. List<string> lw = new List<string>();
  10777. string tid = GetPostString("tid");
  10778. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10779. string shopname = GetPostString("shopname");
  10780. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10781. string buyernick = GetPostString("buyer_nick");
  10782. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10783. string customer = GetPostString("customer");
  10784. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10785. string returndate1 = GetPostString("returndate1");
  10786. string returndate2 = GetPostString("returndate2");
  10787. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10788. if (dw.Length > 0) lw.Add(dw);
  10789. string finishDate1 = GetPostString("finishdate1");
  10790. string finishDate2 = GetPostString("finishdate2");
  10791. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10792. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10793. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10794. string mainWhere = string.Join(" and ", lw.ToArray());
  10795. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10796. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10797. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10798. decimal total = 0;
  10799. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10800. {
  10801. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10802. }
  10803. var res = new
  10804. {
  10805. data = total
  10806. };
  10807. string ro_jsond = JsonConvert.SerializeObject(res);
  10808. returnSuccess(ro_jsond);
  10809. return;
  10810. }
  10811. public void get_erp_qr_waitdeliverylist()
  10812. {
  10813. DataStruct dStruct = GetPostStruct();
  10814. List<string> lw = new List<string>();
  10815. string tid = GetPostString("ctid");
  10816. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10817. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10818. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10819. var res_objz = new
  10820. {
  10821. restype = 1,
  10822. data = dt
  10823. };
  10824. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10825. returnSuccess(ro_jsonz);
  10826. }
  10827. public void get_erp_yield_list()
  10828. {
  10829. DataStruct dStruct = GetPostStruct();
  10830. List<string> lw = new List<string>();
  10831. string tid = GetPostString("ctid");
  10832. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10833. string shopname = GetPostString("shopname");
  10834. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10835. string buyernick = GetPostString("buyer_nick");
  10836. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10837. //if (tid.Length == 0 && buyernick.Length == 0)
  10838. //{
  10839. // lw.Add(string.Format("IsRefund<={0}", 1));
  10840. //}
  10841. string customer = GetPostString("customer");
  10842. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10843. string design = GetPostString("design");
  10844. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10845. string orderState = GetPostString("orderState");
  10846. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10847. string address = GetPostString("address");
  10848. 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));
  10849. string sellermemo = GetPostString("seller_memo");
  10850. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10851. string supplier = GetPostString("supplier");
  10852. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10853. string OrderArea = GetPostString("order_area");
  10854. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10855. string placedate1 = GetPostString("placedate1");
  10856. string placedate2 = GetPostString("placedate2");
  10857. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10858. if (fdw.Length > 0) lw.Add(fdw);
  10859. string price1 = GetPostString("price1");
  10860. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10861. string price2 = GetPostString("price2");
  10862. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10863. string unusualCon = GetPostString("unusualcon");
  10864. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10865. string posTag = CurrentUser.UserPost.Post.Code;
  10866. if (posTag == "Supplier")
  10867. {
  10868. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10869. }
  10870. lw.Add(string.Format("OrderState = 6 "));
  10871. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10872. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10873. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10874. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10875. writeGridDataTableJson(dStruct.TotalCount, dt);
  10876. }
  10877. public void change_erp_sup_state()
  10878. {
  10879. if (UrlPostParmsCheck("ctid"))
  10880. {
  10881. string ctid = GetPostString("ctid");
  10882. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10883. if (ceErpTradeCell != null)
  10884. {
  10885. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10886. if (ceErpTradeCellExtend == null)
  10887. {
  10888. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10889. ceErpTradeCellExtend.ctid = ctid;
  10890. ceErpTradeCellExtend.SupState = 1;
  10891. ceErpTradeCellExtend.Create();
  10892. }
  10893. else
  10894. {
  10895. ceErpTradeCellExtend.SupState = 1;
  10896. ceErpTradeCellExtend.Update();
  10897. }
  10898. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10899. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10900. return;
  10901. }
  10902. returnErrorMsg("找不到订单");
  10903. }
  10904. }
  10905. public void supplier_all_downs()
  10906. {
  10907. if (UrlPostParmsCheck("tids"))
  10908. {
  10909. string tids = GetPostString("tids");
  10910. if (tids != null && tids.Length > 0)
  10911. {
  10912. StringBuilder sql = new StringBuilder();
  10913. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10914. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10915. sql = new StringBuilder();
  10916. 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, "下载设计文件");
  10917. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10918. string[] list = tids.Split(',');
  10919. foreach (string ctid in list)
  10920. {
  10921. CeErpSukuraData.createInfo(ctid, 3);
  10922. }
  10923. designHelper.api_approveDesign(tids); //approveDesign
  10924. returnSuccessMsg("下载成功!");
  10925. return;
  10926. }
  10927. returnErrorMsg("下载订单更新失败");
  10928. }
  10929. }
  10930. public void uploaderFileSuccess()
  10931. {
  10932. if (UrlPostParmsCheck("fileName"))
  10933. {
  10934. string fileName = GetPostString("fileName");
  10935. ApiVo apiVo = new ApiVo();
  10936. apiVo.orderNumber = fileName;
  10937. apiVo.actionName = "finishDesign";
  10938. designHelper.API_WorkCore(apiVo);//finishDesign
  10939. returnSuccessMsg("");
  10940. }
  10941. }
  10942. public void get_sample2_order()
  10943. {
  10944. if (UrlPostParmsCheck("ctid"))
  10945. {
  10946. string ctid = GetPostString("ctid");
  10947. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10948. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10949. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10950. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10951. double total = 0.0;
  10952. double order_price = 0.0;
  10953. if (dt_bu.Rows.Count > 0)
  10954. {
  10955. foreach (DataRow dr in dt_bu.Rows)
  10956. {
  10957. total += Convert.ToDouble(dr["payment"]);
  10958. }
  10959. }
  10960. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  10961. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  10962. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  10963. string tid = ctid.Replace("S_", "");
  10964. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  10965. double paymant = 0.0;
  10966. if (entity != null)
  10967. {
  10968. paymant = entity.payment;
  10969. }
  10970. string return_reason = "";
  10971. if (dt_after != null && dt_after.Rows.Count > 0)
  10972. {
  10973. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  10974. }
  10975. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  10976. }
  10977. }
  10978. public void get_erp_design_status()
  10979. {
  10980. string designName = GetPostString("designName");
  10981. DataStruct dStruct = GetPostStruct();
  10982. if (designName.Length > 0)
  10983. {
  10984. 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";
  10985. sql_user += " and Name like '%" + designName + "%'";
  10986. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  10987. List<string> ids_list = new List<string>();
  10988. if (user_table.Rows.Count > 0)
  10989. {
  10990. foreach (DataRow item in user_table.Rows)
  10991. {
  10992. ids_list.Add(item["id"].ToString());
  10993. string ids_s = item["TeamIds"].ToString();
  10994. if (ids_s.Length > 0)
  10995. {
  10996. ids_list.AddRange(ids_s.Split(','));
  10997. }
  10998. }
  10999. }
  11000. HashSet<string> set = new HashSet<string>(ids_list);
  11001. ids_list = set.ToList();
  11002. if (ids_list.Count > 0)
  11003. {
  11004. 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));
  11005. dStruct.MainWhere = sql;
  11006. DataTable dt = null;
  11007. dt = WebCache.GetData("view_ErpUser", dStruct);
  11008. writeGridDataTableJson(dStruct.TotalCount, dt);
  11009. }
  11010. }
  11011. }
  11012. public void change_erp_order_price()
  11013. {
  11014. string ctid = GetPostString("ctid");
  11015. double price = GetPostDouble("price");
  11016. if (ctid.Length > 0)
  11017. {
  11018. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11019. if (ceErpTradeCellExtend == null)
  11020. {
  11021. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11022. ceErpTradeCellExtend.ctid = ctid;
  11023. ceErpTradeCellExtend.payment_cyt = price;
  11024. ceErpTradeCellExtend.Create();
  11025. }
  11026. else
  11027. {
  11028. ceErpTradeCellExtend.payment_cyt = price;
  11029. ceErpTradeCellExtend.Update();
  11030. }
  11031. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11032. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11033. {
  11034. ceErpDataSendOrderInfo.isSync = false;
  11035. ceErpDataSendOrderInfo.Update();
  11036. }
  11037. if (ceErpDataSendOrderInfo == null)
  11038. {
  11039. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11040. ceErpDataSendOrderInfo.isSync = false;
  11041. ceErpDataSendOrderInfo.ctid = ctid;
  11042. ceErpDataSendOrderInfo.Create();
  11043. }
  11044. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11045. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11046. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11047. if (dth != null && dth.Rows.Count > 0)
  11048. {
  11049. dataSendOrderBean dataSendOrderBean = null;
  11050. foreach (DataRow item in dth.Rows)
  11051. {
  11052. try
  11053. {
  11054. dataSendOrderBean = new dataSendOrderBean();
  11055. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11056. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11057. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11058. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11059. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11060. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11061. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11062. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11063. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11064. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11065. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11066. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11067. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11068. if (result != null)
  11069. {
  11070. if ("0".Equals(result.errcode))
  11071. {
  11072. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11073. }
  11074. else
  11075. {
  11076. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11077. }
  11078. }
  11079. }
  11080. catch (Exception ex)
  11081. {
  11082. }
  11083. }
  11084. }
  11085. returnSuccessMsg("修改成功!");
  11086. return;
  11087. }
  11088. returnErrorMsg("找不到订单");
  11089. }
  11090. public void find_he_together()
  11091. {
  11092. string ctid = GetPostString("ctid");
  11093. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11094. List<string> list = new List<string>();
  11095. if (ceErpTradeCell != null)
  11096. {
  11097. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11098. {
  11099. 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);
  11100. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11101. if (table != null && table.Rows.Count > 0)
  11102. {
  11103. foreach (TableRow row in table.Rows)
  11104. {
  11105. }
  11106. }
  11107. }
  11108. }
  11109. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11110. }
  11111. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11112. {
  11113. //chy----19
  11114. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11115. //GD-CYT-----64
  11116. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11117. //ZHX----3
  11118. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11119. //JK----97
  11120. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11121. //ZT----70
  11122. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11123. //LHCY-----98
  11124. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11125. //XD-----90
  11126. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11127. //CYCY-----14
  11128. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11129. };
  11130. //其他改名
  11131. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11132. {
  11133. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11134. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11135. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11136. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11137. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11138. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11139. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11140. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11141. };
  11142. //不统计
  11143. List<int> no_suppliers = new List<int>()
  11144. {
  11145. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11146. };
  11147. //配件单
  11148. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11149. {
  11150. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11151. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11152. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11153. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11154. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11155. {"旗杆",new List<string>(){ "班旗" } },
  11156. {"牙签",new List<string>(){ "不干胶" } }
  11157. };
  11158. public void get_place_order_data()
  11159. {
  11160. string date1 = GetPostString("date1");
  11161. string date2 = GetPostString("date2");
  11162. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11163. DateTime start = DateTime.Parse(starttime);
  11164. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11165. DateTime end = DateTime.Parse(endtime);
  11166. if (date1 != null && date1.Length > 0)
  11167. {
  11168. DateTime dateTime = DateTime.Parse(date1);
  11169. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11170. start = DateTime.Parse(starttime);
  11171. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11172. end = DateTime.Parse(endtime);
  11173. }
  11174. if (date2 != null && date2.Length > 0)
  11175. {
  11176. DateTime dateTime = DateTime.Parse(date2);
  11177. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11178. end = DateTime.Parse(endtime);
  11179. }
  11180. 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);
  11181. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11182. //不干胶-----1,卡片-----29
  11183. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11184. foreach (DataRow row in data.Rows)
  11185. {
  11186. int productId = Convert.ToInt32(row["ProductId"]);
  11187. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11188. if (no_suppliers.Contains(supplierId))
  11189. {
  11190. continue;
  11191. }
  11192. string seller_memo = row["seller_memo"].ToString();
  11193. bool ispj = false;//是否配件单
  11194. bool isfirst = true;//第一个配
  11195. maps.Keys.ForEach(key =>
  11196. {
  11197. //备注包含配件
  11198. if (seller_memo.Contains(key) && isfirst)
  11199. {
  11200. List<string> list = maps[key];
  11201. ispj = true;
  11202. isfirst = false;
  11203. for (int i = 0; i < list.Count; i++)
  11204. {
  11205. if (seller_memo.Contains(list[i]))
  11206. {
  11207. ispj = false;
  11208. break;
  11209. }
  11210. }
  11211. }
  11212. });
  11213. if (ispj)
  11214. {
  11215. continue;
  11216. }
  11217. seller_memo = seller_memo.Replace("UV", "uv");
  11218. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11219. //吊牌归到卡片
  11220. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11221. seller_memo = seller_memo.Replace("卡套", "卡片");
  11222. seller_memo = seller_memo.Replace("封套", "卡片");
  11223. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11224. seller_memo = seller_memo.Replace("腰封", "卡片");
  11225. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11226. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11227. seller_memo = seller_memo.Replace("横幅", "条幅");
  11228. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11229. string map_key = "";
  11230. string type = "";
  11231. if (supplierMap.ContainsKey(supplierId))
  11232. {
  11233. foreach (var kvp in supplierMap[supplierId])
  11234. {
  11235. if (seller_memo.Contains(kvp.Key))
  11236. {
  11237. map_key = kvp.Value;
  11238. type = kvp.Value;
  11239. break;
  11240. }
  11241. }
  11242. }
  11243. if (map_key == "")
  11244. {
  11245. type = "其他";
  11246. map_key = "其他";
  11247. }
  11248. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11249. {
  11250. map_key = suppliers[supplierId];
  11251. }
  11252. if (supplierId == 70)
  11253. {
  11254. supplierId = 70;
  11255. }
  11256. map_key += "_" + row["SupplierName"].ToString();
  11257. Dictionary<string, int> map = null;
  11258. if (other_map.ContainsKey(map_key))
  11259. {
  11260. other_map.TryGetValue(map_key, out map);
  11261. }
  11262. else
  11263. {
  11264. map = new Dictionary<string, int>();
  11265. map.Add("dayDev", 0);//当天出货
  11266. map.Add("dayTotal", 0);//下单总数
  11267. map.Add("payTotal", 0);//500以上
  11268. map.Add("today", 0);//当天出货数量
  11269. map.Add("unusua", 0);//异常数
  11270. other_map.Add(map_key, map);
  11271. other_map.TryGetValue(map_key, out map);
  11272. }
  11273. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11274. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11275. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11276. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11277. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11278. {
  11279. map["dayTotal"]++;
  11280. if (supplierId == 97)
  11281. {
  11282. supplierId = 97;
  11283. }
  11284. }
  11285. if (Convert.ToDecimal(row["payment"]) >= 500)
  11286. {
  11287. map["payTotal"]++;
  11288. }
  11289. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11290. {
  11291. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11292. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11293. {
  11294. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11295. {
  11296. map["today"]++;
  11297. }
  11298. }
  11299. else
  11300. {
  11301. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11302. {
  11303. map["today"]++;
  11304. }
  11305. else
  11306. {
  11307. if (supplierId == 119)
  11308. {
  11309. Debug.WriteLine(row["seller_memo"].ToString());
  11310. }
  11311. }
  11312. }
  11313. }
  11314. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11315. {
  11316. map["unusua"]++;
  11317. }
  11318. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11319. //GD-CYT-----64
  11320. DateTime two = palceTimeStart.AddHours(14);
  11321. DateTime three = palceTimeStart.AddHours(15);
  11322. DateTime four = palceTimeStart.AddHours(16);
  11323. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11324. {
  11325. //下午四点前 500-1000
  11326. string count = row["ProductCount"].ToString();
  11327. if (count != null && count.Length > 0)
  11328. {
  11329. int productCount = commonHelper.getPlaceProductCount(count);
  11330. if (productCount >= 500 && productCount <= 1000)
  11331. {
  11332. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11333. {
  11334. map["dayDev"]++;
  11335. }
  11336. }
  11337. }
  11338. }
  11339. //UV
  11340. else if ("uv".Equals(type))
  11341. {
  11342. //ZT----70
  11343. //ZHX----3
  11344. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11345. {
  11346. map["dayDev"]++;
  11347. }
  11348. //JK----97
  11349. //HZX----105
  11350. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11351. {
  11352. map["dayDev"]++;
  11353. if (supplierId == 97)
  11354. {
  11355. supplierId = 97;
  11356. }
  11357. }
  11358. }
  11359. //帆布---52|条幅---27
  11360. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11361. {
  11362. //LHCY-----98
  11363. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11364. {
  11365. map["dayDev"]++;
  11366. }
  11367. }
  11368. //条幅
  11369. else if ("条幅".Equals(type))
  11370. {
  11371. //XD-----90
  11372. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11373. {
  11374. map["dayDev"]++;
  11375. }
  11376. }
  11377. //桌布
  11378. else if ("桌布".Equals(type))
  11379. {
  11380. //XD-----90
  11381. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11382. {
  11383. map["dayDev"]++;
  11384. }
  11385. }
  11386. //DL---10
  11387. //AYTW---119
  11388. //FS-CYT-DY ----80
  11389. //JK----97
  11390. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11391. {
  11392. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11393. {
  11394. map["dayDev"]++;
  11395. }
  11396. }
  11397. }
  11398. DataTable dt = new DataTable();
  11399. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11400. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11401. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11402. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11403. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11404. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11405. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11406. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11407. other_map.Keys.ForEach(key =>
  11408. {
  11409. DataRow dr = dt.NewRow();
  11410. Dictionary<string, int> map = other_map[key];
  11411. string[] key_list = key.Split('_');
  11412. dr[0] = key_list[0];
  11413. dr[1] = key_list[1];
  11414. if (key_list.Length > 2)
  11415. {
  11416. dr[1] += "(" + key_list[2] + ")";
  11417. }
  11418. dr[2] = map["dayTotal"];
  11419. dr[3] = map["payTotal"];
  11420. dr[4] = map["today"];
  11421. dr[5] = map["unusua"];
  11422. dr[6] = map["dayDev"];
  11423. double rate = 0.00;
  11424. if (map["dayDev"] > 0)
  11425. {
  11426. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11427. }
  11428. dr[7] = rate.ToString();
  11429. dt.Rows.Add(dr);
  11430. });
  11431. DataView dv = new DataView(dt);
  11432. dv.Sort = "SupplierName";
  11433. //dv.Sort = "AllOrder desc";
  11434. DataTable dtNew = dv.ToTable();
  11435. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11436. }
  11437. public void check_order_desing_info()
  11438. {
  11439. string ctid = GetPostString("ctid");
  11440. if (!string.IsNullOrEmpty(ctid))
  11441. {
  11442. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11443. if (ceErpTradeCell != null)
  11444. {
  11445. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11446. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11447. return;
  11448. }
  11449. returnErrorMsg("找不到订单");
  11450. return;
  11451. }
  11452. returnErrorMsg("找不到订单");
  11453. }
  11454. public void get_timeout_detail()
  11455. {
  11456. string poscode = CurrentUser.UserPost.Post.Code;
  11457. DataStruct dStruct = GetPostStruct();
  11458. List<string> lw = new List<string>();
  11459. string id = GetPostString("id");
  11460. string pay_date1 = GetPostString("pay_date1");
  11461. string pay_date2 = GetPostString("pay_date2");
  11462. int type = GetPostInt("type");
  11463. if (type == 0)
  11464. {
  11465. if (pay_date1.Length > 0)
  11466. {
  11467. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11468. }
  11469. if (pay_date2.Length > 0)
  11470. {
  11471. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11472. }
  11473. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11474. }
  11475. if (type == 1)
  11476. {
  11477. if (pay_date1.Length > 0)
  11478. {
  11479. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11480. }
  11481. if (pay_date2.Length > 0)
  11482. {
  11483. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11484. }
  11485. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11486. }
  11487. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11488. DataTable dt = null;
  11489. dt = WebCache.GetData("view_orderlist", dStruct);
  11490. writeGridDataTableJson(dStruct.TotalCount, dt);
  11491. }
  11492. public void saveUrgentChargePrice()
  11493. {
  11494. string ctid = GetPostString("ctid");
  11495. if (!string.IsNullOrEmpty(ctid))
  11496. {
  11497. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11498. if (ceErpTradeCell != null)
  11499. {
  11500. double price = GetPostDouble("price");
  11501. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11502. if (ceErpTradeCellExtend == null)
  11503. {
  11504. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11505. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11506. }
  11507. ceErpTradeCellExtend.urgentCharge = price;
  11508. if (ceErpTradeCellExtend.ID > 0)
  11509. {
  11510. ceErpTradeCellExtend.Update();
  11511. }
  11512. else
  11513. {
  11514. ceErpTradeCellExtend.Save();
  11515. }
  11516. returnSuccessMsg("修改成功!");
  11517. return;
  11518. }
  11519. returnErrorMsg("找不到订单");
  11520. return;
  11521. }
  11522. returnErrorMsg("找不到订单");
  11523. }
  11524. public void finish_erp_order()
  11525. {
  11526. string ctid = GetPostString("ctid");
  11527. if (!string.IsNullOrEmpty(ctid))
  11528. {
  11529. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11530. {
  11531. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11532. if (ceErpTradeCell != null)
  11533. {
  11534. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11535. ceErpTradeCell.Update();
  11536. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11537. returnSuccessMsg("修改成功!");
  11538. return;
  11539. }
  11540. }
  11541. }
  11542. returnErrorMsg("找不到订单");
  11543. }
  11544. public void get_trade_order_list()
  11545. {
  11546. string tid = GetPostString("tid");
  11547. if (!string.IsNullOrEmpty(tid))
  11548. {
  11549. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11550. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11551. writeGridDataTableJson(data.Rows.Count, data);
  11552. return;
  11553. }
  11554. returnErrorMsg("找不到订单");
  11555. }
  11556. public void save_cell_spu()
  11557. {
  11558. string ctid = GetPostString("ctid");
  11559. string spu_id = GetPostString("spu_id");
  11560. if (!string.IsNullOrEmpty(ctid))
  11561. {
  11562. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11563. if (ceErpTradeCellExtend == null)
  11564. {
  11565. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11566. ceErpTradeCellExtend.ctid = ctid;
  11567. }
  11568. ceErpTradeCellExtend.spu_id = spu_id;
  11569. if (!string.IsNullOrEmpty(spu_id))
  11570. {
  11571. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id);
  11572. ceErpTradeCellExtend.ToType = result;
  11573. }
  11574. if (ceErpTradeCellExtend.ID == 0)
  11575. {
  11576. ceErpTradeCellExtend.Create();
  11577. }
  11578. else
  11579. {
  11580. ceErpTradeCellExtend.Update();
  11581. }
  11582. returnSuccessMsg("修改成功!");
  11583. return;
  11584. }
  11585. returnErrorMsg("找不到订单");
  11586. }
  11587. public void change_express_info()
  11588. {
  11589. string ctid = GetPostString("ctid");
  11590. string transNo = GetPostString("transNo");
  11591. string transCom = GetPostString("transCom");
  11592. if (!string.IsNullOrEmpty(ctid))
  11593. {
  11594. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11595. if (ceErpTradeCellExtend == null)
  11596. {
  11597. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11598. ceErpTradeCellExtend.ctid = ctid;
  11599. }
  11600. ceErpTradeCellExtend.modExpressNo = transNo;
  11601. ceErpTradeCellExtend.modExpressCom = transCom;
  11602. ceErpTradeCellExtend.readMod = 2;
  11603. if (ceErpTradeCellExtend.ID == 0)
  11604. {
  11605. ceErpTradeCellExtend.Create();
  11606. }
  11607. else
  11608. {
  11609. ceErpTradeCellExtend.Update();
  11610. }
  11611. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11612. returnSuccessMsg("修改成功!");
  11613. return;
  11614. }
  11615. returnErrorMsg("找不到订单");
  11616. }
  11617. public void get_change_express_list()
  11618. {
  11619. DataStruct dStruct = GetPostStruct();
  11620. List<string> lw = new List<string>();
  11621. int st = 2;
  11622. string tid = GetPostString("ctid");
  11623. if (tid.Length > 0)
  11624. {
  11625. string select_tid = getTidByCtid(tid);
  11626. lw.Add(string.Format("tid='{0}'", select_tid));
  11627. }
  11628. string shopname = GetPostString("shopname");
  11629. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11630. string buyernick = GetPostString("buyer_nick");
  11631. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11632. string sellermemo = GetPostString("seller_memo");
  11633. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11634. string supplier = GetPostString("supplier");
  11635. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11636. string customer = GetPostString("customer");
  11637. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11638. string design = GetPostString("design");
  11639. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11640. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11641. string poscode = CurrentUser.UserPost.Post.Code;
  11642. if (poscode != "SysAdmin")
  11643. {
  11644. string shopid = CurrentUser.User.pemShop;
  11645. lw.Add(string.Format("shopId in ({0})", shopid));
  11646. }
  11647. lw.Add("readMod = 2");
  11648. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11649. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11650. writeGridDataTableJson(dStruct.TotalCount, dt);
  11651. }
  11652. public void deal_express_complete()
  11653. {
  11654. string ctid = GetPostString("ctid");
  11655. if (!string.IsNullOrEmpty(ctid))
  11656. {
  11657. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11658. if (ceErpTradeCellExtend == null)
  11659. {
  11660. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11661. ceErpTradeCellExtend.ctid = ctid;
  11662. }
  11663. ceErpTradeCellExtend.readMod = 1;
  11664. if (ceErpTradeCellExtend.ID == 0)
  11665. {
  11666. ceErpTradeCellExtend.Create();
  11667. }
  11668. else
  11669. {
  11670. ceErpTradeCellExtend.Update();
  11671. }
  11672. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11673. returnSuccessMsg("修改成功!");
  11674. return;
  11675. }
  11676. returnErrorMsg("找不到订单");
  11677. }
  11678. public void aftersale_return_visit()
  11679. {
  11680. string ctid = GetPostString("ctid");
  11681. if (!string.IsNullOrEmpty(ctid))
  11682. {
  11683. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11684. if (ceErpTradeCellExtend == null)
  11685. {
  11686. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11687. ceErpTradeCellExtend.ctid = ctid;
  11688. }
  11689. ceErpTradeCellExtend.returnVisit = 1;
  11690. if (ceErpTradeCellExtend.ID == 0)
  11691. {
  11692. ceErpTradeCellExtend.Create();
  11693. }
  11694. else
  11695. {
  11696. ceErpTradeCellExtend.Update();
  11697. }
  11698. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11699. if (ceErpTradeAfterSaleExtend != null)
  11700. {
  11701. ceErpTradeAfterSaleExtend.TextResult = "";
  11702. ceErpTradeAfterSaleExtend.Update();
  11703. }
  11704. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11705. returnSuccessMsg("修改成功!");
  11706. return;
  11707. }
  11708. returnErrorMsg("找不到订单");
  11709. }
  11710. public void orderPlaceInfo()
  11711. {
  11712. string ctids = GetPostString("ctids");
  11713. string[] list = ctids.Split(',');
  11714. foreach (string ctid in list)
  11715. {
  11716. CeErpSukuraData.createInfo(ctid, 3);
  11717. }
  11718. StringBuilder sql = new StringBuilder();
  11719. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11720. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11721. designHelper.api_approveDesign(ctids); //approveDesign
  11722. returnSuccessMsg("");
  11723. }
  11724. public void get_issue_list()
  11725. {
  11726. DataStruct dStruct = GetPostStruct();
  11727. List<string> lw = new List<string>();
  11728. int st = 2;
  11729. string tid = GetPostString("ctid");
  11730. if (tid.Length > 0)
  11731. {
  11732. string select_tid = getTidByCtid(tid);
  11733. lw.Add(string.Format("tid='{0}'", select_tid));
  11734. }
  11735. string shopname = GetPostString("shopname");
  11736. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11737. string buyernick = GetPostString("buyer_nick");
  11738. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11739. string sellermemo = GetPostString("seller_memo");
  11740. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11741. string supplier = GetPostString("supplier");
  11742. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11743. string customer = GetPostString("customer");
  11744. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11745. string design = GetPostString("design");
  11746. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11747. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11748. string poscode = CurrentUser.UserPost.Post.Code;
  11749. if (poscode != "SysAdmin")
  11750. {
  11751. string shopid = CurrentUser.User.pemShop;
  11752. lw.Add(string.Format("shopId in ({0})", shopid));
  11753. }
  11754. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11755. {
  11756. lw.Add("IssueState = 1");
  11757. }
  11758. lw.Add("IssueState > 0");
  11759. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11760. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11761. writeGridDataTableJson(dStruct.TotalCount, dt);
  11762. }
  11763. public void saveIssueContent()
  11764. {
  11765. string ctid = GetPostString("ctid");
  11766. if (!string.IsNullOrEmpty(ctid))
  11767. {
  11768. string content = GetPostString("content");
  11769. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11770. if (ceErpTradeAfterSaleExtend == null)
  11771. {
  11772. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11773. ceErpTradeAfterSaleExtend.tid = ctid;
  11774. }
  11775. ceErpTradeAfterSaleExtend.IssueContent = content;
  11776. ceErpTradeAfterSaleExtend.IssueState = 1;
  11777. if (ceErpTradeAfterSaleExtend.ID > 0)
  11778. {
  11779. ceErpTradeAfterSaleExtend.Update();
  11780. }
  11781. else
  11782. {
  11783. ceErpTradeAfterSaleExtend.Create();
  11784. }
  11785. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11786. returnSuccessMsg("添加成功!");
  11787. return;
  11788. }
  11789. returnErrorMsg("找不到订单");
  11790. }
  11791. public void dealIssueContent()
  11792. {
  11793. string ctid = GetPostString("ctid");
  11794. if (!string.IsNullOrEmpty(ctid))
  11795. {
  11796. string content = GetPostString("content");
  11797. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11798. if (ceErpTradeAfterSaleExtend != null)
  11799. {
  11800. ceErpTradeAfterSaleExtend.IssueState = 2;
  11801. ceErpTradeAfterSaleExtend.Update();
  11802. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11803. returnSuccessMsg("修改完成!");
  11804. return;
  11805. }
  11806. }
  11807. returnErrorMsg("找不到订单");
  11808. }
  11809. public void set_tid_attachments()
  11810. {
  11811. string tid = GetPostString("tid");
  11812. string atta = GetPostString("atta");
  11813. if (!string.IsNullOrEmpty(tid))
  11814. {
  11815. if (string.IsNullOrEmpty(atta))
  11816. {
  11817. returnErrorMsg("文件地址为空");
  11818. return;
  11819. }
  11820. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11821. if (ceErpTradeCell != null)
  11822. {
  11823. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11824. if (ceErpTrade == null)
  11825. {
  11826. returnErrorMsg("找不到订单");
  11827. return;
  11828. }
  11829. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11830. bool isSend = false;
  11831. if (dt != null && dt.Rows.Count > 0)
  11832. {
  11833. foreach (DataRow row in dt.Rows)
  11834. {
  11835. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11836. {
  11837. isSend = true;
  11838. }
  11839. }
  11840. if (isSend)
  11841. {
  11842. returnErrorMsg("已发货无法修改");
  11843. return;
  11844. }
  11845. ceErpTrade.Attachments = atta;
  11846. ceErpTrade.Update();
  11847. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11848. returnSuccessMsg("上传成功!");
  11849. return;
  11850. }
  11851. }
  11852. }
  11853. returnErrorMsg("找不到订单");
  11854. }
  11855. public void get_tid_attachments()
  11856. {
  11857. string tid = GetPostString("tid");
  11858. if (!string.IsNullOrEmpty(tid))
  11859. {
  11860. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11861. if (ceErpTradeCell != null)
  11862. {
  11863. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11864. if (ceErpTrade == null)
  11865. {
  11866. returnErrorMsg("找不到订单");
  11867. return;
  11868. }
  11869. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11870. return;
  11871. }
  11872. }
  11873. returnErrorMsg("找不到订单");
  11874. }
  11875. public void check_erp_sameorders()
  11876. {
  11877. if (UrlPostParmsCheck("ctid"))
  11878. {
  11879. string eid = GetPostString("ctid");
  11880. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11881. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11882. if (entity != null && ceErpTrade != null)
  11883. {
  11884. if (entity.OrderState > 6)
  11885. {
  11886. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11887. return;
  11888. }
  11889. StringBuilder sql = new StringBuilder();
  11890. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  11891. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11892. {
  11893. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11894. }
  11895. else
  11896. {
  11897. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11898. }
  11899. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11900. List<string> ids = new List<string>();
  11901. if (dt != null && dt.Rows.Count > 1)
  11902. {
  11903. bool needhe = true;
  11904. foreach (DataRow dr in dt.Rows)
  11905. {
  11906. ids.Add("'" + dr["ctid"] + "'");
  11907. /* //备注有合包
  11908. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11909. {
  11910. needhe = true;
  11911. }
  11912. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11913. {
  11914. needhe = true;
  11915. }
  11916. //顺丰快递
  11917. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11918. {
  11919. needhe = true;
  11920. }*/
  11921. }
  11922. if (!needhe)
  11923. {
  11924. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11925. return;
  11926. }
  11927. sql = new StringBuilder();
  11928. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11929. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11930. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11931. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11932. foreach (DataRow dr in dt.Rows)
  11933. {
  11934. dr["dstate"] = 0;
  11935. dr["dnumber"] = 0;
  11936. foreach (DataRow row in dt1.Rows)
  11937. {
  11938. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  11939. {
  11940. dr["dstate"] = 2;
  11941. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  11942. }
  11943. }
  11944. if (eid.Equals(dr["ctid"].ToString()))
  11945. {
  11946. dr["dstate"] = 1;
  11947. }
  11948. }
  11949. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  11950. return;
  11951. }
  11952. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11953. return;
  11954. }
  11955. returnErrorMsg("未找到订单");
  11956. return;
  11957. }
  11958. returnErrorMsg("缺少必要的参数");
  11959. }
  11960. public void get_mark_number()
  11961. {
  11962. string eid = GetPostString("ctid");
  11963. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11964. if (entity != null)
  11965. {
  11966. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11967. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  11968. int current = 1;
  11969. if (ceErpDeliverMark == null)
  11970. {
  11971. StringBuilder sql = new StringBuilder();
  11972. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  11973. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11974. {
  11975. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11976. }
  11977. else
  11978. {
  11979. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11980. }
  11981. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11982. List<string> ids = new List<string>();
  11983. if (dt != null && dt.Rows.Count > 1)
  11984. {
  11985. foreach (DataRow dr in dt.Rows)
  11986. {
  11987. ids.Add("'" + dr["ctid"] + "'");
  11988. }
  11989. //查询已有的编号
  11990. sql = new StringBuilder();
  11991. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11992. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11993. if (dt1 == null || dt1.Rows.Count == 0)
  11994. {
  11995. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  11996. List<int> list_number = new List<int>();
  11997. foreach (DataRow row in numbers.Rows)
  11998. {
  11999. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12000. }
  12001. //查询空余编号
  12002. for (int i = 0; i < list_number.Count + 2; i++)
  12003. {
  12004. if (!list_number.Contains(current))
  12005. {
  12006. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12007. //防止查询过程中有新数据生成
  12008. if (ceErpDeliverMark1 == null)
  12009. {
  12010. break;
  12011. }
  12012. }
  12013. current++;
  12014. }
  12015. }
  12016. else
  12017. {
  12018. foreach (DataRow row in dt1.Rows)
  12019. {
  12020. current = Convert.ToInt32(row["markNumber"]);
  12021. }
  12022. }
  12023. ceErpDeliverMark = new CeErpDeliverMark();
  12024. ceErpDeliverMark.ctid = eid;
  12025. ceErpDeliverMark.createtime = DateTime.Now;
  12026. if (ceErpTrade != null)
  12027. {
  12028. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12029. }
  12030. ceErpDeliverMark.markNumber = current;
  12031. ceErpDeliverMark.Create();
  12032. }
  12033. }
  12034. else
  12035. {
  12036. current = ceErpDeliverMark.markNumber;
  12037. }
  12038. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12039. return;
  12040. }
  12041. }
  12042. }
  12043. }