sync.order.cs 715 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. using NPOI.POIFS.Properties;
  51. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  52. using static SiteCore.taoObj.Api_tmc_refund_info_Obj;
  53. using System.Threading.Tasks;
  54. using SiteCore.taoObj.WebApi;
  55. using System.Web.UI.WebControls.WebParts;
  56. namespace SiteCore.Handler
  57. {
  58. public partial class sync
  59. {
  60. public void get_erp_orderlist()
  61. {
  62. string poscode = CurrentUser.UserPost.Post.Code;
  63. DataStruct dStruct = GetPostStruct();
  64. //commonHelper.sendSpuData(CeErpTradeCell.GetByCtid("C1_2701711344045006369"),CeErpTradeCellExtend.getByTid("C1_2701711344045006369"));
  65. //commonHelper.setDeliveryUnusualOrder2();
  66. //string a = SecurityHelper.DecryptSymmetric("NNM8SwEgcu/yE70NElUXSQ==");
  67. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  68. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  69. //banniuApiHelper.sendLogisticsInfo(null);
  70. //commonHelper.autoDistributeToSupplier(CeErpTradeCell.GetByCode("260112211259328680"));
  71. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  72. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  73. //int sid = commonHelper.autoDistributeToSupplier(entity);
  74. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  75. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1776912122000,\"deliveryType\":\"OFFLINE\",\"discountFee\":5.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1777564800000,\"lines\":[{\"dividePostFee\":0.0,\"latestDeliveryTime\":1777564799999,\"mark2\":[],\"num\":7,\"outerId\":\"\",\"payment\":65.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i4/490100363/O1CN014sHEYw1EYItkQ1CXw_!!490100363.jpg\",\"platServiceFee\":0.0,\"price\":10.0,\"refOlId\":\"3297756000720015269\",\"refSkuId\":\"0\",\"refSpuId\":\"1013527964388\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":9.2857,\"singleFee\":9.29,\"spuOuterId\":\"\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"车贴定制宠物logo图案转印贴纸小狗diy创意商标车窗萌宠水晶标签\",\"totalFee\":65.0,\"totalPrice\":70.0,\"totalSellPrice\":65.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1776913673000,\"openBuyerId\":\"AAG5RHraABkUZRPgSx3AaocL\",\"openBuyerNick\":\"绿**\",\"openSellerNick\":\"琳19890725\",\"orderSource\":\"SYNC\",\"orderTime\":1776912119000,\"payTime\":1776912120000,\"payment\":65.0,\"platServiceFee\":0.0,\"posCode\":\"guliang\",\"posId\":598696,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"大连市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"甘井子区\",\"receiverId\":\"84b8064ffac769db909772facb5e84fb$\",\"receiverState\":\"辽宁省\",\"receiverTown\":\"凌水街道\",\"refOid\":\"3297756000720015269\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"120x120mm+120x150mm-2款各1个-UV转印贴-彩色-模切-绿葡萄妲己-龙井\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"sysTags\":[],\"totalFee\":65.0,\"totalPrice\":70.0,\"totalSellPrice\":65.0,\"type\":\"SALE\"}}");
  76. //refundTmcHelper.Api_TmcRefundMsg("{\"content\":{\"afterStatus\":\"SUCCESS\",\"createTime\":1735287446000,\"desc\":\"\",\"interceptInvestor\":\"NONE\",\"interceptStatus\":\"NONE\",\"interceptType\":\"NONE\",\"lines\":[{\"num\":2,\"outerId\":\"\",\"price\":50.0,\"refAid\":\"313001208133750610\",\"refAlId\":\"313001208133750610\",\"refBoughtSkuId\":\"\",\"refOid\":\"4181722704291751006\",\"refOlId\":\"4181722704291751006\",\"refSkuId\":\"0\",\"refSpuId\":\"865893808768\",\"refundFee\":98.86,\"refundStatus\":\"SUCCESS\",\"title\":\"新年会抽奖券定制2025蛇年公司活动正副可撕代金券打印纪念票根奖品兑换尾牙晚宴邀请卡号码牌创意入场券设计\",\"totalFee\":98.86,\"type\":1}],\"logisticsCompany\":\"\",\"logisticsOrderNo\":\"\",\"mark2\":[],\"openBuyerNick\":\"0**\",\"openSellerNick\":\"万慕办公旗舰店\",\"posCode\":\"wanmu\",\"posId\":598798,\"reason\":\"订单信息拍错(规格/尺码/颜色等)\",\"receiverCity\":\"\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"\",\"receiverId\":\"\",\"receiverState\":\"\",\"receiverTown\":\"\",\"receiverZip\":\"\",\"refAid\":\"313001208133750610\",\"refOid\":\"4181722704291751006\",\"refPlatform\":\"TB\",\"refType\":\"TMALL\",\"refundCreateTime\":1735287358000,\"refundFee\":\"98.86\",\"refundPhase\":\"ON_SALE\",\"refundTime\":1735289443000,\"refundUpdateTime\":1735289443000,\"refundVersion\":1735287358100,\"senderAddress\":\"\",\"senderCity\":\"\",\"senderCountry\":\"中国\",\"senderDistrict\":\"\",\"senderMobile\":\"\",\"senderName\":\"\",\"senderPhone\":\"\",\"senderState\":\"\",\"senderTown\":\"\",\"senderZip\":\"\",\"status\":\"SUCCESS\",\"statusCode\":\"SUCCESS\",\"statusName\":\"退款成功\",\"totalFee\":\"98.86\",\"type\":\"REFUND\",\"updateTime\":1735289479000}}");
  77. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  78. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  79. //preSalesHelper.dealMessageInfo("{\"bizOrder\":{\"id\":235819,\"parentId\":null,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderNo\":\"4624034580248409502\",\"shopId\":4,\"shopCode\":\"aolifu\",\"customerId\":345874,\"customerServiceId\":3184,\"thirdOrderId\":\"4624034580248409502\",\"orderPlatform\":\"TMALL\",\"openBuyerId\":\"AAEORHraABkUZRHgSx6ksuhU\",\"openBuyerNick\":\"tb278604202340\",\"openSellerNick\":\"奥丽芙旗舰店\",\"productUrl\":null,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"payAmount\":125.0,\"unrefundedAmount\":125.0,\"discountAmount\":5.0,\"csDiscountAmount\":-35.0,\"num\":13,\"province\":\"山西省\",\"city\":\"吕梁市\",\"area\":\"孝义市\",\"receiverTown\":\"孝义市\",\"address\":null,\"thirdReceiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"receiverName\":null,\"receiverMobile\":null,\"weChatId\":null,\"phone\":null,\"designContent\":\"\",\"designPics\":\"[]\",\"weChatQrPics\":\"[]\",\"addressFileUrl\":\"\",\"thirdFlag\":\"NONE\",\"remark\":null,\"sellerRemark\":\"\",\"buyerRemark\":\"\",\"timeoutRemark\":null,\"discountRemark\":null,\"status\":\"NOT_SHIPPED\",\"refundStatus\":0,\"internalStatus\":2,\"auditStatus\":null,\"auditUserId\":null,\"auditor\":null,\"customTag\":null,\"isRepurchase\":false,\"isOffline\":false,\"paymentFile\":null,\"orderTime\":\"2025-07-10 14:46:13\",\"modifyTime\":\"2025-07-10 14:46:37\",\"payTime\":\"2025-07-10 14:46:37\",\"confirmTime\":\"2025-07-10 14:51:23\",\"auditTime\":null,\"shippingTime\":null,\"finishTime\":null,\"erpCustomerServiceId\":3319,\"openBuyerID\":\"AAEORHraABkUZRHgSx6ksuhU\",\"orderFrom\":\"10\",\"receiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"bizOrderItems\":[{\"id\":310334,\"orderId\":235819,\"thirdOrderItemId\":\"4624034580248409502\",\"thirdSpuId\":\"740203900330\",\"thirdSkuId\":\"0\",\"title\":\"pvc贴纸定制防水不干胶圆形贴标自粘商标logo广告二维码标签印刷\",\"specification\":\"\",\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2433960672/O1CN01D0ZzzR1GppCHSoBjD_!!4611686018427382496-0-item_pic.jpg\",\"price\":10.0,\"sellPrice\":9.62,\"amount\":9.62,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"totalAmount\":125.0,\"num\":13,\"refundStatus\":\"NO_REFUND\"}],\"bizOrderSplits\":[{\"id\":151557,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328848\",\"splitNo\":\"C1_4624034580248409502\",\"splitInfoNo\":\"C2+1\",\"splitAmount\":52.64,\"quoteRecordId\":520208,\"quoteAmount\":40.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328848)-[C2+1]-80x20mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328848\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":40.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":80.00,\"width\":20.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"80x20mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":40.00,\"numberType\":\"\",\"isDianziOrder\":0},{\"id\":151558,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328853\",\"splitNo\":\"C2_4624034580248409502\",\"splitInfoNo\":\"C2+2\",\"splitAmount\":72.36,\"quoteRecordId\":520209,\"quoteAmount\":55.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328853)-[C2+2]-90x50mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328853\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":55.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":90.00,\"width\":50.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"90x50mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":55.00,\"numberType\":\"\",\"isDianziOrder\":0}]}}");
  80. /*string path = "C:\\Users\\231010\\Downloads\\tids.txt";
  81. string path1 = "C:\\Users\\231010\\Downloads\\tid.txt";
  82. string tids = File.ReadAllText(path);
  83. List<string> list = tids.Split(',').ToList();
  84. int index = 0;
  85. foreach (string item in list)
  86. {
  87. CeErpTrade ceErpTrade = CeErpTrade.Get(item.Replace("'", ""));
  88. try
  89. {
  90. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  91. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  92. {
  93. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  94. }
  95. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  96. List<string> tidList = new List<string>();
  97. if (dataTable != null && dataTable.Rows.Count > 0)
  98. {
  99. foreach (DataRow row in dataTable.Rows)
  100. {
  101. tidList.Add("'" + row["tid"].ToString() + "'");
  102. }
  103. }
  104. if (tidList.Count > 0)
  105. {
  106. sql = string.Format("SELECT count(*) as number FROM [dbo].[CE_ErpTradeCell] WITH(NOLOCK) WHERE tid in ({0}) AND IsSample = 0 ", string.Join(",", tidList));
  107. dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  108. if (dataTable != null && dataTable.Rows.Count > 0)
  109. {
  110. int count = Convert.ToInt32(dataTable.Rows[0]["number"]);
  111. if (count > 0)
  112. {
  113. Debug.WriteLine(index++);
  114. continue;
  115. }
  116. }
  117. }
  118. File.AppendAllText(path1, ceErpTrade.tid + "\n");
  119. }
  120. catch (Exception e)
  121. {
  122. File.AppendAllText(path1, "e:" + ceErpTrade.tid + "\n");
  123. }
  124. Debug.WriteLine(index++);
  125. }*/
  126. //string a = commonHelper.convertQNMemo("48x61mm-4款各40个-铜版纸-不干胶-覆膜模切-tb963561715-金陵-顺丰到付.粘成品.6.5cm牙签-老客户改稿找金陵拉群-16发", CeErpTradeCell.GetByCtid("2879265072537265386"));
  127. List<string> lw = new List<string>();
  128. string tid = GetPostString("ctid");
  129. string date1 = GetPostString("date1");
  130. //12-1 修改
  131. string urgent = GetPostString("urgent");
  132. string back = GetPostString("back");
  133. string offlineSearch = GetPostString("offlineSearch");
  134. int paramsCount = 0;
  135. if (!string.IsNullOrWhiteSpace(urgent))
  136. {
  137. if (urgent.Equals("true"))
  138. {
  139. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  140. }
  141. }
  142. if (!string.IsNullOrWhiteSpace(back))
  143. {
  144. if (back.Equals("true"))
  145. {
  146. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  147. }
  148. }
  149. if (!string.IsNullOrWhiteSpace(offlineSearch))
  150. {
  151. if (offlineSearch.Equals("true"))
  152. {
  153. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  154. }
  155. }
  156. //end
  157. string date2 = GetPostString("date2");
  158. string buyernick = GetPostString("buyer_nick");
  159. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  160. {
  161. if (tid.Length <= 0 && buyernick.Length <= 0)
  162. {
  163. return;
  164. }
  165. }
  166. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  167. {
  168. if (tid.Length > 0)
  169. {
  170. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  171. if (ceErpTradeCell != null)
  172. {
  173. tid = ceErpTradeCell.tid;
  174. }
  175. List<string> select_tid = getTidByCtidMore(tid);
  176. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  177. }
  178. if (buyernick.Length > 0)
  179. {
  180. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  181. }
  182. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  183. if (dw.Length > 0)
  184. {
  185. lw.Add(dw);
  186. }
  187. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  188. {
  189. string usershop = "0," + CurrentUser.User.pemShop;
  190. lw.Add(string.Format("ShopId in ({0})", usershop));
  191. }
  192. }
  193. else
  194. {
  195. if (ex_psize == 0)
  196. {
  197. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  198. }
  199. if (PKey != "admin" && poscode != "SysAdmin")
  200. {
  201. string usershop = "0," + CurrentUser.User.pemShop;
  202. lw.Add(string.Format("ShopId in ({0})", usershop));
  203. paramsCount++;
  204. }
  205. }
  206. string uploaddate1 = GetPostString("uploaddate1");
  207. string uploaddate2 = GetPostString("uploaddate2");
  208. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  209. if (update.Length > 0) lw.Add(update);
  210. string deliverydate1 = GetPostString("deliverydate1");
  211. string deliverydate2 = GetPostString("deliverydate2");
  212. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  213. if (deliverydate.Length > 0)
  214. {
  215. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  216. };
  217. string shopname = GetPostString("shopname");
  218. if (shopname.Length > 0)
  219. {
  220. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopname);
  221. if (ceErpShop != null)
  222. {
  223. lw.Add(string.Format("shopId = {0}", ceErpShop.ID));
  224. }
  225. }
  226. string addwechat = GetPostString("addwechat");
  227. if (addwechat.Length > 0)
  228. {
  229. int addWt = Convert.ToInt32(addwechat);
  230. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  231. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  232. }
  233. string customer = GetPostString("customer");
  234. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  235. string design = GetPostString("design");
  236. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  237. string orderState = GetPostString("orderState");
  238. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  239. string address = GetPostString("address");
  240. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  241. string sellermemo = GetPostString("seller_memo");
  242. if (sellermemo.Length > 0)
  243. {
  244. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  245. }
  246. string otherMemo = GetPostString("otherMemo");
  247. if (otherMemo.Length > 0)
  248. {
  249. lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  250. }
  251. string backReason = GetPostString("backReason");
  252. if (backReason.Length > 0)
  253. {
  254. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  255. }
  256. string apdate1 = GetPostString("apdate1");
  257. string apdate2 = GetPostString("apdate2");
  258. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  259. if (dwap.Length > 0) lw.Add(dwap);
  260. string price1 = GetPostString("price1");
  261. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  262. string price2 = GetPostString("price2");
  263. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  264. string isoldcustomer = GetPostString("isoldcus");
  265. string buyer_id = GetPostString("buyer_id");
  266. if (buyer_id.Length > 0) lw.Add(string.Format("buyer_id = '{0}'", buyer_id));
  267. string spudata = GetPostString("spudata");
  268. if ("0".Equals(spudata))
  269. {
  270. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  271. }
  272. if ("1".Equals(spudata))
  273. {
  274. lw.Add(string.Format("spu_id <> ''"));
  275. }
  276. string finishdate1 = GetPostString("finishdate1");
  277. string finishdate2 = GetPostString("finishdate2");
  278. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  279. bool isFinish = false;
  280. if (finishdate.Length > 0)
  281. {
  282. lw.Add(finishdate);
  283. isFinish = true;
  284. paramsCount++;
  285. }
  286. if (isoldcustomer.Length > 0)
  287. {
  288. if ("2".Equals(isoldcustomer))
  289. {
  290. lw.Add(string.Format("VipCustomer=1"));
  291. }
  292. else
  293. {
  294. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  295. }
  296. }
  297. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  298. if (ex_psize > 0)
  299. {
  300. int UserID = CurrentUser.UserID;
  301. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  302. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  303. {
  304. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  305. }
  306. dStruct.Order = "pay_time desc";
  307. }
  308. string isNew = GetPostString("isNew");
  309. if (isNew == "true")
  310. {
  311. lw.Add(string.Format("IsNew = {0}", 1));
  312. }
  313. string overtime = GetPostString("overtime");
  314. if (overtime == "1")
  315. {
  316. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  317. }
  318. String usePost = CurrentUser.UserPost.Post.Code;
  319. if (usePost.Equals("Operation") == true)
  320. {
  321. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  322. }
  323. else
  324. {
  325. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  326. }
  327. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  328. if (dStruct.PageSize == 100000)
  329. {
  330. dStruct.Order = "";
  331. }
  332. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  333. DataTable dt = null;
  334. string tablename = "view_orderlist";
  335. if (isFinish)
  336. {
  337. tablename = "view_orderlist_end";
  338. }
  339. dt = WebCache.GetData(tablename, dStruct);
  340. if (dt != null && dt.Rows.Count > 0)
  341. {
  342. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  343. foreach (DataRow dr in dt.Rows)
  344. {
  345. try
  346. {
  347. if (dr["refund_fees"] != null)
  348. {
  349. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  350. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  351. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  352. if (payment == refund_fees)
  353. {
  354. dr["refund_fees"] = Math.Round(refund_fees, 2);
  355. }
  356. else if (refund_fees == total_fee)
  357. {
  358. dr["refund_fees"] = payment;
  359. }
  360. else
  361. {
  362. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  363. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  364. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  365. }
  366. }
  367. // 对象操作
  368. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  369. ceErpTradeCell.ctid = dr["ctid"].ToString();
  370. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  371. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  372. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  373. if (dStruct.PageSize != 100000)
  374. {
  375. if (dr["DispatchSort"].ToString() == "2")
  376. {
  377. dr["gongchuang"] = 200;
  378. }
  379. else if ("外协".Equals(dr["ToType"].ToString()))
  380. {
  381. dr["gongchuang"] = 200;
  382. }
  383. else if ("内部".Equals(dr["ToType"].ToString()))
  384. {
  385. dr["gongchuang"] = -1;
  386. }
  387. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  388. {
  389. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  390. dr["gongchuang"] = response.code;
  391. }
  392. }
  393. }
  394. catch (NullReferenceException ex)
  395. {
  396. // 处理空引用异常
  397. dr["refund_fees"] = "0.00";
  398. }
  399. }
  400. }
  401. writeGridDataTableJson(dStruct.TotalCount, dt);
  402. }
  403. public void get_erp_orderlist_sumprice()
  404. {
  405. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  406. return;
  407. List<string> lw = new List<string>();
  408. string tid = GetPostString("ctid");
  409. string date1 = GetPostString("date1");
  410. string date2 = GetPostString("date2");
  411. if (tid.Length > 0 || date1.Length > 0)
  412. {
  413. lw.Add(string.Format("ctid like '%{0}%'", tid));
  414. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  415. if (dw.Length > 0) lw.Add(dw);
  416. }
  417. else
  418. {
  419. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  420. }
  421. string shopname = GetPostString("shopname");
  422. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  423. string buyernick = GetPostString("buyer_nick");
  424. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  425. string customer = GetPostString("customer");
  426. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  427. string design = GetPostString("design");
  428. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  429. string orderState = GetPostString("orderState");
  430. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  431. string address = GetPostString("address");
  432. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  433. string sellermemo = GetPostString("seller_memo");
  434. if (sellermemo.Length > 0)
  435. {
  436. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  437. }
  438. string apdate1 = GetPostString("apdate1");
  439. string apdate2 = GetPostString("apdate2");
  440. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  441. if (dwap.Length > 0) lw.Add(dwap);
  442. string price1 = GetPostString("price1");
  443. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  444. string price2 = GetPostString("price2");
  445. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  446. string isoldcustomer = GetPostString("isoldcus");
  447. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  448. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  449. if (PKey != "admin")
  450. {
  451. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  452. lw.Add(string.Format("shopId in ({0})", usershop));
  453. }
  454. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  455. string mainWhere = string.Join(" and ", lw.ToArray());
  456. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  457. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  458. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  459. decimal total = 0;
  460. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  461. {
  462. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  463. }
  464. var res = new
  465. {
  466. data = total
  467. };
  468. string ro_jsond = JsonConvert.SerializeObject(res);
  469. returnSuccess(ro_jsond);
  470. return;
  471. }
  472. public void get_erp_CustomerServiceGather()
  473. {
  474. string userWhere = "", orderWhere = "";
  475. List<string> lw = new List<string>();
  476. string customer = GetPostString("customer");
  477. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  478. string shopname = GetPostString("shopname");
  479. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  480. string date1 = GetPostString("date1");
  481. string date2 = GetPostString("date2");
  482. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  483. if (dw.Length > 0) lw.Add(dw);
  484. orderWhere = string.Join(" and ", lw.ToArray());
  485. string sql = string.Format("select a.Name CusName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitRelease,0) WaitRelease, isnull(e.WaitRob,0) WaitRob, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  486. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  487. "left join " +
  488. "( " +
  489. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  490. ") as b on a.ID = b.CustomerUserId " +
  491. "left join " +
  492. "( " +
  493. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  494. ") as d on a.ID = d.CustomerUserId " +
  495. "left join " +
  496. "( " +
  497. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  498. ") as e on a.ID = e.CustomerUserId " +
  499. "left join " +
  500. "( " +
  501. " select CustomerUserId, RefundCount, RefundSum from " +
  502. " ( " +
  503. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  504. " from CE_ErpTradeRefund a " +
  505. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  506. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  507. " group by CustomerUserId " +
  508. " ) as a " +
  509. ") as f on a.ID = f.CustomerUserId " +
  510. "where a.PostCode = 'CustomerService'",
  511. userWhere, orderWhere);
  512. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  513. writeGridDataTableJson(dt.Rows.Count, dt);
  514. //writeGridDataTableJson(dt.Rows.Count, dt);
  515. }
  516. //设计汇总
  517. public void get_erp_DesignerGather()
  518. {
  519. string userWhere = "", orderWhere = "";
  520. List<string> lw = new List<string>();
  521. string Designer = GetPostString("designer");
  522. int org = GetPostInt("org");
  523. if (Designer.Length > 0)
  524. {
  525. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  526. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  527. }
  528. else if (org > 0)
  529. {
  530. userWhere = string.Format(" where OrgID ={0}", org);
  531. }
  532. string shopname = GetPostString("shopname");
  533. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  534. string state = GetPostString("state");
  535. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  536. string OrderArea = GetPostString("order_area");
  537. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  538. string date1 = GetPostString("date1");
  539. string date2 = GetPostString("date2");
  540. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  541. if (dw.Length > 0) lw.Add(dw);
  542. string UpDate1 = GetPostString("UpDate1");
  543. string UpDate2 = GetPostString("UpDate2");
  544. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  545. if (dw.Length > 0) lw.Add(dw);
  546. orderWhere = string.Join(" and ", lw.ToArray());
  547. string sql = string.Format("select *,cast(cast(z.DesignFinish as float) / (case z.AllOrder when 0 then 1 else z.AllOrder end) * 100 as numeric(18,2)) as FinalizationRate from (" +
  548. "select a.Name DesignerName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitDesign,0) WaitDesign, isnull(e.Designing,0) Designing, isnull(g.DesignFinish,0) DesignFinish, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  549. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  550. "left join " +
  551. "( " +
  552. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  553. ") as b on a.ID = b.DesignUserId " +
  554. "left join " +
  555. "( " +
  556. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  557. ") as d on a.ID = d.DesignUserId " +
  558. "left join " +
  559. "( " +
  560. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  561. ") as e on a.ID = e.DesignUserId " +
  562. "left join " +
  563. "( " +
  564. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  565. ") as g on a.ID = g.DesignUserId " +
  566. "left join " +
  567. "( " +
  568. " select CustomerUserId, RefundCount, RefundSum from " +
  569. " ( " +
  570. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  571. " from CE_ErpTradeRefund a " +
  572. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  573. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  574. " group by CustomerUserId " +
  575. " ) as a " +
  576. ") as f on a.ID = f.CustomerUserId " +
  577. "where a.PostCode = 'Designer') as z",
  578. userWhere, orderWhere);
  579. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  580. writeGridDataTableJson(dt.Rows.Count, dt);
  581. }
  582. //删除tradecell的订单
  583. public void del_erp_cellorder()
  584. {
  585. if (UrlPostParmsCheck("ctid"))
  586. {
  587. string eid = GetPostString("ctid");
  588. CeErpTradeCell.DelByCtid(eid);
  589. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  590. returnSuccessMsg("删除成功");
  591. }
  592. }
  593. public void clear_erp_refundstate()
  594. {
  595. if (UrlPostParmsCheck("ids"))
  596. {
  597. string eids = GetPostString("ids");
  598. string[] ctidList = eids.Split(',');
  599. foreach (string ctid in ctidList)
  600. {
  601. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  602. if (entity != null)
  603. {
  604. entity.IsRefund = 0;
  605. entity.Update();
  606. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  607. }
  608. else
  609. continue;
  610. }
  611. returnSuccessMsg("操作成功");
  612. return;
  613. }
  614. returnErrorMsg("缺少必要参数");
  615. }
  616. public void set_erp_urgency()
  617. {
  618. if (UrlPostParmsCheck("ctid"))
  619. {
  620. string eid = GetPostString("ctid");
  621. CeErpTradeCell entity = null;
  622. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  623. if (entity != null)
  624. {
  625. double prices = commonHelper.calculationPrice(entity);
  626. if (prices <= 100)
  627. {
  628. returnErrorMsg("此订单金额不足100元,无法加急。");
  629. return;
  630. }
  631. string utime = GetPostString("urgencytime");
  632. if (utime.Length > 0)
  633. {
  634. entity.UrgencyTime = Convert.ToDateTime(utime);
  635. }
  636. else
  637. {
  638. returnErrorMsg("请选择加急时间");
  639. return;
  640. }
  641. if (entity.OrderState <= 4)
  642. {
  643. //entity.seller_memo = entity.seller_memo + "-加急";
  644. string smemo = entity.seller_memo;
  645. int kindex = smemo.IndexOf(")");
  646. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  647. if (lastoneStr != "-")
  648. {
  649. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  650. }
  651. string prememo = smemo.Substring(0, kindex + 2);
  652. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  653. int lastkindex = lastmemo.IndexOf("(");
  654. DateTime urgtime = Convert.ToDateTime(utime);
  655. string newlastmemo = "";
  656. if (lastkindex == 0)
  657. {
  658. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  659. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  660. }
  661. else
  662. {
  663. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  664. }
  665. entity.seller_memo = prememo + newlastmemo;
  666. }
  667. entity.IsUrgency = true;
  668. entity.UpdateTime = DateTime.Now;
  669. entity.Update();
  670. ApiVo apiVo = new ApiVo();
  671. apiVo.orderNumber = entity.ctid;
  672. apiVo.actionName = "changeDesign";
  673. apiVo.orderRemarks = entity.seller_memo;
  674. apiVo.remarkSign = 3;
  675. designHelper.API_WorkCore(apiVo); //changeDesign
  676. CeErpSukuraData.createInfo(entity.ctid, 7);
  677. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  678. returnSuccessMsg("设置成功!");
  679. return;
  680. }
  681. returnErrorMsg("找不到记录");
  682. }
  683. }
  684. public void set_erp_reset()
  685. {
  686. if (UrlPostParmsCheck("ctid"))
  687. {
  688. string eid = GetPostString("ctid");
  689. CeErpTradeCell entity = null;
  690. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  691. if (entity != null)
  692. {
  693. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  694. {
  695. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  696. {
  697. returnErrorMsg("财务要求已下单已发货无法重置");
  698. return;
  699. }
  700. }
  701. entity.IsUrgency = false;
  702. entity.seller_memo = "";
  703. entity.OtherMemo = "";
  704. entity.OrderState = 0;
  705. entity.IsReturn = 0;
  706. //entity.IsRefund = 0;
  707. entity.MemoOpt = 0;
  708. entity.AfterSaleState = 0;
  709. entity.AfterSaleResponsible = "";
  710. entity.AfterSaleUserId = 0;
  711. entity.IsNeedBill = 0;
  712. entity.CustomerUserId = 0;
  713. entity.DesignUserId = 0;
  714. entity.SupplierId = 0;
  715. entity.PlaceUserId = 0;
  716. entity.ptid = "";
  717. entity.IsSample = 0;
  718. entity.IsXianHuo = 0;
  719. entity.isDianziOrder = 0;
  720. entity.DispatchSort = 0;
  721. entity.IsVerifyToSupplier = false;
  722. entity.FinishPlaceTime = null;
  723. entity.Update();
  724. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  725. if (trade != null)
  726. {
  727. trade.seller_memo = "";
  728. trade.Update();
  729. }
  730. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  731. returnSuccessMsg("重置成功!");
  732. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  733. if (desginBill != null)
  734. {
  735. desginBill.isDel = 1;
  736. desginBill.Update();
  737. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  738. }
  739. ApiVo apiVo = new ApiVo();
  740. apiVo.orderNumber = entity.ctid;
  741. apiVo.actionName = "resetDesign";
  742. designHelper.API_WorkCore(apiVo);//resetDesign
  743. return;
  744. }
  745. returnErrorMsg("找不到记录");
  746. }
  747. }
  748. public void save_erp_sellermemo()
  749. {
  750. if (UrlPostParmsCheck("ctid"))
  751. {
  752. string ctid = GetPostString("ctid");
  753. CeErpTradeCell entity = null;
  754. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  755. if (entity != null)
  756. {
  757. string memo = GetPostString("seller_memo");
  758. string qn_memo = GetPostString("qn_memo");
  759. memo = memo.Replace(" ", "");
  760. if (memo.Contains("补差"))
  761. {
  762. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  763. return;
  764. }
  765. List<string> bitList = new List<string>
  766. {
  767. "\\","/",":","*","?", "\"","<" ,">","|"
  768. };
  769. bool isIn = false;
  770. foreach (string bit in bitList)
  771. {
  772. if (memo.Contains(bit))
  773. {
  774. isIn = true;
  775. }
  776. }
  777. if (isIn)
  778. {
  779. returnErrorMsg("不能使用 一些符合作为文件名");
  780. return;
  781. }
  782. if (entity.seller_memo != memo)
  783. {
  784. if (entity.IsSample == 2)
  785. {
  786. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  787. return;
  788. }
  789. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  790. {
  791. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  792. {
  793. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  794. return;
  795. }
  796. /*if (CurrentUser.UserPost.Post.Code != "Place")
  797. {
  798. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  799. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  800. {
  801. returnErrorMsg("售前系统订单无法再此修改!");
  802. return;
  803. }
  804. }*/
  805. }
  806. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  807. }
  808. if (!string.IsNullOrEmpty(qn_memo) && !(entity.IsSample > 0 || entity.ctid.Contains("N_") || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物")))
  809. {
  810. if (entity.OrderState >= 5)
  811. {
  812. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  813. return;
  814. }
  815. string delMemo = commonHelper.convertQNMemo(qn_memo, ref entity);
  816. if (string.IsNullOrEmpty(delMemo))
  817. {
  818. returnErrorMsg("备注不规范,无法识别");
  819. return;
  820. }
  821. memo = delMemo;
  822. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统千牛修改为:" + memo, entity.OrderState, 1);
  823. }
  824. //commonHelper.getCytPrice(entity);
  825. int memoopt = GetPostInt("MemoOpt");
  826. Boolean ismemoopt = false;
  827. if (memoopt > 0)
  828. {
  829. string stropt = "";
  830. if (memoopt == 1)
  831. {
  832. stropt = "“改稿”";
  833. ismemoopt = true;
  834. }
  835. else if (memoopt == 2)
  836. {
  837. stropt = "“定稿”";
  838. }
  839. else if (memoopt == 3)
  840. {
  841. stropt = "“查货”";
  842. CeErpSukuraData.createInfo(entity.ctid, 6);
  843. }
  844. entity.MemoOpt = Convert.ToInt32(memoopt);
  845. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  846. }
  847. if (entity.OrderState < 5)
  848. {
  849. memo = memo.Replace("(", "(");
  850. memo = memo.Replace(")", ")");
  851. }
  852. /* if (entity.OrderState < 3)
  853. {
  854. entity.DispatchSort = 0;
  855. }*/
  856. entity.seller_memo = memo;
  857. entity.UpdateTime = DateTime.Now;
  858. entity.Update();
  859. ApiVo apiVo = new ApiVo();
  860. apiVo.orderNumber = entity.ctid;
  861. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  862. apiVo.orderRemarks = memo;
  863. apiVo.remarkSign = memoopt;
  864. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  865. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  866. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  867. {
  868. //dataHelper.api_orderBack(entity.ctid, "0", "");
  869. }
  870. if (entity.seller_memo.Contains("改稿"))
  871. {
  872. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  873. }
  874. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  875. returnSuccessMsg("保存成功!");
  876. return;
  877. }
  878. returnErrorMsg("找不到记录");
  879. }
  880. }
  881. public void ins_erp_checkorder()
  882. {
  883. if (UrlPostParmsCheck("ctid"))
  884. {
  885. string ctid = GetPostString("ctid");
  886. CeErpTradeCell entity = null;
  887. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  888. if (entity != null)
  889. {
  890. if (entity.OrderState < 6)
  891. {
  892. returnErrorMsg("下单完成后才可查货");
  893. return;
  894. }
  895. /*if (entity.OrderState > 6)
  896. {
  897. returnErrorMsg("订单已发货");
  898. return;
  899. }*/
  900. if (entity.FinishPlaceTime != null)
  901. {
  902. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  903. {
  904. returnErrorMsg("下单时间不足,无法查货");
  905. return;
  906. }
  907. }
  908. entity.MemoOpt = 3;
  909. entity.CheckOrderTime = DateTime.Now;
  910. entity.UpdateTime = DateTime.Now;
  911. entity.Update();
  912. CeErpSukuraData.createInfo(entity.ctid, 6);
  913. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  914. returnSuccessMsg("操作成功!");
  915. return;
  916. }
  917. returnErrorMsg("找不到记录");
  918. }
  919. }
  920. public void save_erp_othermemo()
  921. {
  922. if (UrlPostParmsCheck("ctid"))
  923. {
  924. string ctid = GetPostString("ctid");
  925. CeErpTradeCell entity = null;
  926. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  927. if (entity != null)
  928. {
  929. entity.OtherMemo = GetPostString("otherMemo");
  930. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  931. {
  932. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  933. StringBuilder sql = new StringBuilder();
  934. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  935. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  936. if (dt != null && dt.Rows.Count > 0)
  937. {
  938. foreach (DataRow dr in dt.Rows)
  939. {
  940. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  941. {
  942. //品类一直
  943. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  944. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  945. if (ceErpSampleCustomer == null)
  946. {
  947. ceErpSampleCustomer = new CeErpSampleCustomer();
  948. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  949. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  950. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  951. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  952. ceErpSampleCustomer.shopId = entity.ShopId;
  953. }
  954. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  955. ceErpSampleCustomer.lastTid = entity.tid;
  956. if (ceErpSampleCustomer.ID > 0)
  957. {
  958. ceErpSampleCustomer.Update();
  959. }
  960. else
  961. {
  962. ceErpSampleCustomer.Create();
  963. }
  964. }
  965. }
  966. }
  967. }
  968. //if (entity.IsOldCustomer == 1)
  969. //{
  970. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  971. //{
  972. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  973. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  974. //}
  975. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  976. //{
  977. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  978. // {
  979. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  980. // {
  981. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  982. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  983. // }
  984. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  985. // {
  986. // entity.OrderState = 2;
  987. // entity.DesignUserId = 0;
  988. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  989. // }
  990. // else
  991. // {
  992. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  993. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  994. // }
  995. // }
  996. //}
  997. //}
  998. entity.UpdateTime = DateTime.Now;
  999. entity.Update();
  1000. returnSuccessMsg("保存成功!");
  1001. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  1002. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  1003. if (entity.OtherMemo.Contains("改稿"))
  1004. {
  1005. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1006. }
  1007. return;
  1008. }
  1009. returnErrorMsg("找不到记录");
  1010. }
  1011. }
  1012. public void save_erp_customermemo()
  1013. {
  1014. if (UrlPostParmsCheck("ctid"))
  1015. {
  1016. string ctid = GetPostString("ctid");
  1017. CeErpTradeCell entity = null;
  1018. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1019. if (entity != null)
  1020. {
  1021. entity.UpdateTime = DateTime.Now;
  1022. entity.CustomerMemo = GetPostString("CustomerMemo");
  1023. entity.Update();
  1024. ApiVo apiVo = new ApiVo();
  1025. apiVo.orderNumber = entity.ctid;
  1026. apiVo.actionName = "followRemarks";
  1027. apiVo.orderRemarks = entity.CustomerMemo;
  1028. designHelper.API_WorkCore(apiVo);//followRemarks
  1029. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  1030. returnSuccessMsg("保存成功!");
  1031. return;
  1032. }
  1033. returnErrorMsg("找不到记录");
  1034. }
  1035. }
  1036. public void upd_erp_addmemotag()
  1037. {
  1038. if (UrlPostParmsCheck("ctid"))
  1039. {
  1040. ;
  1041. string eid = GetPostString("ctid");
  1042. string sfTagstr = GetPostString("memotag");
  1043. CeErpTradeCell entity = null;
  1044. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1045. if (entity != null)
  1046. {
  1047. ApiVo apiVo = new ApiVo();
  1048. if (entity.OrderState == 0)
  1049. {
  1050. returnErrorMsg("请先领单");
  1051. return;
  1052. }
  1053. //撤销顺丰
  1054. if (sfTagstr == "撤销顺丰")
  1055. {
  1056. entity.IsSF = 0;
  1057. string reMsg = "";
  1058. string oldmemo = entity.seller_memo;
  1059. if (entity.OrderState < 5)
  1060. {
  1061. oldmemo = oldmemo.Replace("顺丰到付", "");
  1062. oldmemo = oldmemo.Replace("顺丰寄付", "");
  1063. entity.seller_memo = oldmemo;
  1064. }
  1065. else
  1066. {
  1067. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  1068. {
  1069. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  1070. }
  1071. }
  1072. entity.Update();
  1073. apiVo.orderNumber = entity.ctid;
  1074. apiVo.actionName = "orderRemarks";
  1075. apiVo.orderRemarks = entity.seller_memo;
  1076. apiVo.isSf = entity.IsSF.ToString();
  1077. designHelper.API_WorkCore(apiVo);//orderRemarks
  1078. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  1079. returnSuccessMsg("撤销成功!" + reMsg);
  1080. return;
  1081. }
  1082. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  1083. {
  1084. //string oldmemo = entity.seller_memo;
  1085. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1086. string sfStr = GetPostString("memotag");
  1087. string smemo = entity.seller_memo;
  1088. int kindex = smemo.IndexOf(")");
  1089. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1090. if (lastoneStr != "-")
  1091. {
  1092. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1093. }
  1094. string prememo = smemo.Substring(0, kindex + 2);
  1095. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1096. int lastkindex = lastmemo.IndexOf("(");
  1097. string newlastmemo = "";
  1098. if (lastkindex == 0)
  1099. {
  1100. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1101. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1102. }
  1103. else
  1104. {
  1105. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1106. }
  1107. entity.seller_memo = prememo + newlastmemo;
  1108. }
  1109. string sfTagMSg = "";
  1110. if (sfTagstr == "顺丰寄付")
  1111. {
  1112. entity.IsSF = 1;
  1113. sfTagMSg = "顺丰寄付";
  1114. }
  1115. else if (sfTagstr == "顺丰到付")
  1116. {
  1117. entity.IsSF = 2;
  1118. sfTagMSg = "顺丰到付";
  1119. }
  1120. if (entity.SupplierId == 19 && entity.OrderState == 6)
  1121. {
  1122. string deliveryWayName = "";
  1123. if (sfTagstr == "撤销顺丰")
  1124. {
  1125. sfTagstr = "普通快递";
  1126. }
  1127. if (sfTagstr == "顺丰寄付")
  1128. {
  1129. sfTagstr = "顺丰特快寄付";
  1130. }
  1131. if (sfTagstr == "顺丰到付")
  1132. {
  1133. sfTagstr = "顺丰特快到付";
  1134. }
  1135. string result = apichyHelper.updateExpressMark(entity.tid, sfTagstr);
  1136. if ("修改失败".Equals(result))
  1137. {
  1138. returnErrorMsg("修改失败");
  1139. return;
  1140. }
  1141. }
  1142. entity.Update();
  1143. apiVo = new ApiVo();
  1144. apiVo.orderNumber = entity.ctid;
  1145. apiVo.actionName = "orderRemarks";
  1146. apiVo.orderRemarks = entity.seller_memo;
  1147. apiVo.isSf = entity.IsSF.ToString();
  1148. designHelper.API_WorkCore(apiVo);//orderRemarks
  1149. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1150. returnSuccessMsg("标记成功!");
  1151. return;
  1152. }
  1153. returnErrorMsg("找不到记录");
  1154. }
  1155. }
  1156. public void upd_erp_ordertag()
  1157. {
  1158. if (UrlPostParmsCheck("ctid"))
  1159. {
  1160. string eid = GetPostString("ctid");
  1161. CeErpTradeCell entity = null;
  1162. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1163. if (entity != null)
  1164. {
  1165. int tag = GetPostInt("wechattag");
  1166. //if(tag==4 && entity.IsSample == 2)
  1167. //{
  1168. // returnErrorMsg("补差价单不能标记微信单");
  1169. // return;
  1170. //}
  1171. entity.wechatTag = tag;
  1172. entity.Update();
  1173. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1174. if (tag == 1)
  1175. {
  1176. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1177. if (cash == null)
  1178. {
  1179. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1180. cash = new CeErpReturnCash();
  1181. cash.tid = entity.tid;
  1182. cash.seller_nick = main.seller_nick;
  1183. cash.payment = trade.payment;
  1184. cash.buyer_nick = main.buyer_nick;
  1185. cash.cashstate = 0;
  1186. cash.rtype = "微信返现";
  1187. cash.returnprice = 0;
  1188. cash.created = DateTime.Now;
  1189. cash.con = "订单标记微信单";
  1190. cash.img = "";
  1191. cash.applyuserid = CurrentUser.UserID;
  1192. cash.Create();
  1193. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1194. }
  1195. else
  1196. {
  1197. cash.cashstate = 0;
  1198. cash.Update();
  1199. }
  1200. CeErpSukuraData.createInfo(entity.ctid, 9);
  1201. }
  1202. else if (tag == 2)
  1203. {
  1204. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1205. if (cash == null)
  1206. {
  1207. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1208. cash = new CeErpReturnCash();
  1209. cash.tid = entity.tid;
  1210. cash.seller_nick = main.seller_nick;
  1211. cash.payment = trade.payment;
  1212. cash.buyer_nick = main.buyer_nick;
  1213. cash.cashstate = 0;
  1214. cash.rtype = "推购返现";
  1215. cash.returnprice = 5;
  1216. cash.created = DateTime.Now;
  1217. cash.con = "订单标记推购单";
  1218. cash.img = "";
  1219. cash.applyuserid = CurrentUser.UserID;
  1220. cash.Create();
  1221. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1222. }
  1223. else
  1224. {
  1225. cash.cashstate = 0;
  1226. cash.Update();
  1227. }
  1228. CeErpSukuraData.createInfo(entity.ctid, 9);
  1229. }
  1230. else if (tag == 3)
  1231. {
  1232. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1233. if (pers == null)
  1234. {
  1235. pers = new CeErpPersuade();
  1236. pers.ctid = entity.ctid;
  1237. pers.pstate = 0;
  1238. pers.created = DateTime.Now;
  1239. pers.applyuserid = CurrentUser.UserID;
  1240. pers.Create();
  1241. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1242. }
  1243. else
  1244. {
  1245. pers.pstate = 0;
  1246. pers.Update();
  1247. }
  1248. }
  1249. else if (tag == 4 || tag == 5)
  1250. {
  1251. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1252. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1253. if (pers == null)
  1254. {
  1255. pers = CeErpStayGoods.GetByTid(entity.tid);
  1256. }
  1257. if (pers == null)
  1258. {
  1259. pers = new CeErpStayGoods();
  1260. pers.t_id = entity.tid;
  1261. pers.ctid = entity.ctid;
  1262. pers.status = "待审核";
  1263. pers.audit_type = 0;
  1264. if (tag == 4)
  1265. {
  1266. pers.stay_type = "微信推购";
  1267. }
  1268. else
  1269. {
  1270. pers.stay_type = "旺旺推购";
  1271. }
  1272. if (entity.IsXianHuo == 0)
  1273. {
  1274. pers.product_id = entity.ProductId;
  1275. }
  1276. pers.wangwang = main.buyer_nick;
  1277. pers.shop_name = main.seller_nick;
  1278. pers.creata_time = DateTime.Now;
  1279. pers.create_u_id = CurrentUser.UserID;
  1280. pers.create_u_name = CurrentUser.UserName;
  1281. pers.Create();
  1282. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1283. }
  1284. else
  1285. {
  1286. pers.ctid = entity.ctid;
  1287. pers.audit_type = 0;
  1288. pers.Update();
  1289. }
  1290. CeErpSukuraData.createInfo(entity.ctid, 10);
  1291. }
  1292. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1293. returnSuccessMsg("标记成功!");
  1294. return;
  1295. }
  1296. returnErrorMsg("找不到记录");
  1297. }
  1298. }
  1299. public void upd_erp_ordertag_cancel()
  1300. {
  1301. if (UrlPostParmsCheck("ctid"))
  1302. {
  1303. string eid = GetPostString("ctid");
  1304. CeErpTradeCell entity = null;
  1305. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1306. if (entity != null)
  1307. {
  1308. entity.wechatTag = 0;
  1309. entity.Update();
  1310. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1311. if (pers != null)
  1312. {
  1313. pers.status = "取消推购";
  1314. pers.audit_type = 3;
  1315. pers.Update();
  1316. }
  1317. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1318. returnSuccessMsg("标记成功!");
  1319. return;
  1320. }
  1321. returnErrorMsg("找不到记录");
  1322. }
  1323. }
  1324. public void upd_erp_addweichattag()
  1325. {
  1326. if (UrlPostParmsCheck("ctid"))
  1327. {
  1328. ;
  1329. string eid = GetPostString("ctid");
  1330. CeErpTradeCell entity = null;
  1331. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1332. if (entity != null)
  1333. {
  1334. if (entity.IsAddWechat > 0)
  1335. {
  1336. returnErrorMsg("此单已经标记过了");
  1337. return;
  1338. }
  1339. string sql = string.Format("select * from view_erptradecell where IsAddWechat>0 and buyer_nick=(select buyer_nick from ce_erptrade where tid='{0}')", entity.tid);
  1340. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1341. if (dt.Rows.Count > 0)
  1342. {
  1343. entity.IsAddWechat = 2;
  1344. }
  1345. else
  1346. {
  1347. entity.IsAddWechat = 1;
  1348. }
  1349. entity.Update();
  1350. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1351. returnSuccessMsg("标记成功!");
  1352. return;
  1353. }
  1354. returnErrorMsg("找不到记录");
  1355. }
  1356. }
  1357. public void upd_erp_getmyorder()
  1358. {
  1359. if (UrlPostParmsCheck("ctid"))
  1360. {
  1361. string eid = GetPostString("ctid");
  1362. CeErpTradeCell entity = null;
  1363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1364. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1365. /*if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1366. {
  1367. returnErrorMsg("台湾客户需填写身份证号!");
  1368. return;
  1369. }*/
  1370. if (commonHelper.isFarAddress(father.receiver_state) && father.delivery_paymant == 0)
  1371. {
  1372. returnErrorMsg("偏远地区需要填写物流费!");
  1373. return;
  1374. }
  1375. if (entity != null)
  1376. {
  1377. if (entity.ctid.IndexOf("C") != -1)
  1378. {
  1379. StringBuilder sql = new StringBuilder();
  1380. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1381. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1382. if (dt.Rows.Count > 0)
  1383. {
  1384. decimal total = 0;
  1385. foreach (DataRow dr in dt.Rows)
  1386. {
  1387. total += Convert.ToDecimal(dr["payment"]);
  1388. }
  1389. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1390. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1391. {
  1392. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1393. return;
  1394. }
  1395. }
  1396. }
  1397. if (entity.OrderState == -1)
  1398. {
  1399. returnErrorMsg("待审核订单无法领取!");
  1400. return;
  1401. }
  1402. entity.CustomerUserId = CurrentUser.UserID;
  1403. if (entity.OrderState < 2)
  1404. {
  1405. entity.OrderState = 2;
  1406. if (entity.ShopId != 0)
  1407. {
  1408. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1409. }
  1410. }
  1411. entity.UpdateTime = DateTime.Now;
  1412. entity.Update();
  1413. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1414. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1415. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1416. {
  1417. //dataHelper.api_orderBack(entity.ctid, "0", "");
  1418. }
  1419. returnSuccessMsg("领单成功!");
  1420. return;
  1421. }
  1422. returnErrorMsg("找不到记录");
  1423. }
  1424. }
  1425. public void getmyorder_from_init()
  1426. {
  1427. if (UrlPostParmsCheck("ctid"))
  1428. {
  1429. string eid = GetPostString("ctid");
  1430. CeErpTradeCell entity = null;
  1431. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1432. if (entity != null)
  1433. {
  1434. string sellerMemo = GetPostString("sellerMemo");
  1435. if (sellerMemo.Length > 0)
  1436. {
  1437. entity.seller_memo = sellerMemo;
  1438. }
  1439. string oterhMemo = GetPostString("otherMemo");
  1440. if (oterhMemo.Length > 0)
  1441. {
  1442. entity.OtherMemo = oterhMemo;
  1443. }
  1444. int urg = GetPostInt("urgency");
  1445. entity.IsUrgency = (urg == 1 ? true : false);
  1446. int wechat = GetPostInt("wechat");
  1447. int command = GetPostInt("command");
  1448. if (wechat == 1)
  1449. {
  1450. entity.wechatTag = 1;
  1451. }
  1452. if (command == 1)
  1453. {
  1454. entity.wechatTag = 2;
  1455. }
  1456. string pPro = GetPostString("pprofession");
  1457. if (pPro.Length > 0)
  1458. {
  1459. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1460. string spro = GetPostString("profession");
  1461. if (spro.Length > 0)
  1462. {
  1463. entity.ProfessionId = Convert.ToInt32(spro);
  1464. }
  1465. }
  1466. string proId = GetPostString("productId");
  1467. if (proId.Length > 0)
  1468. {
  1469. entity.ProductId = Convert.ToInt32(proId);
  1470. }
  1471. entity.Material = GetPostString("material");
  1472. entity.Craft = GetPostString("craft");
  1473. entity.CustomerUserId = CurrentUser.UserID;
  1474. if (entity.OrderState < 2)
  1475. {
  1476. entity.OrderState = 2;
  1477. if (entity.ShopId != 0)
  1478. {
  1479. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1480. }
  1481. }
  1482. entity.Update();
  1483. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1484. returnSuccessMsg("领单成功!");
  1485. return;
  1486. }
  1487. returnErrorMsg("找不到记录");
  1488. }
  1489. }
  1490. public void upd_erp_setrelationorder()
  1491. {
  1492. if (UrlPostParmsCheck("ctid"))
  1493. {
  1494. ;
  1495. string eid = GetPostString("ctid");
  1496. string ftid = GetPostString("ftid");
  1497. CeErpTradeCell entity = null;
  1498. CeErpTradeCell fentity = null;
  1499. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1500. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1501. if (fentity == null)
  1502. {
  1503. returnErrorMsg("找不到关联的主订单");
  1504. return;
  1505. }
  1506. if (entity != null)
  1507. {
  1508. if (entity.OrderState >= 5)
  1509. {
  1510. returnErrorMsg("本单已经设计完成无法关联");
  1511. return;
  1512. }
  1513. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1514. {
  1515. returnErrorMsg("线下单续审核后才能关联!");
  1516. return;
  1517. }
  1518. entity.ptid = ftid;
  1519. entity.OrderState = fentity.OrderState;
  1520. //entity.status = fentity.status;
  1521. entity.CustomerUserId = fentity.CustomerUserId;
  1522. entity.DesignUserId = fentity.DesignUserId;
  1523. entity.seller_memo = "补差价单:" + ftid;
  1524. entity.IsSample = 2;
  1525. entity.Update();
  1526. ApiVo apiVo = new ApiVo();
  1527. apiVo.orderNumber = ftid;
  1528. apiVo.payment = entity.payment;
  1529. apiVo.actionName = "repairDesign";
  1530. designHelper.API_WorkCore(apiVo);//repairDesign
  1531. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1532. returnSuccessMsg("关联成功!");
  1533. return;
  1534. }
  1535. else
  1536. returnErrorMsg("找不到记录");
  1537. }
  1538. }
  1539. public void download_erp_neworder()
  1540. {
  1541. string seller = GetPostString("seller_nick");
  1542. string tid = GetPostString("tid");
  1543. if (seller.Length <= 0 || tid.Length <= 0)
  1544. {
  1545. returnErrorMsg("数据错误");
  1546. }
  1547. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1548. //{
  1549. // returnErrorMsg("找不到店铺Sessionkey");
  1550. //}
  1551. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1552. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1553. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1554. if (res.IndexOf("refOid") == -1)
  1555. {
  1556. returnErrorMsg("下载订单数据失败");
  1557. return;
  1558. }
  1559. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1560. returnSuccessMsg("下载完成");
  1561. //tmcHelper.createNewOrder(res);
  1562. //CeErpTrade entr = null;
  1563. //entr = CeErpTrade.Get(tid);
  1564. //if (entr != null)
  1565. //{
  1566. // returnSuccess("下载成功");
  1567. // //下载成功之后,Cell表生成对应的订单;
  1568. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1569. //}
  1570. //else
  1571. //{
  1572. // returnErrorMsg("下载失败或者创建订单失败");
  1573. //}
  1574. }
  1575. public void set_erp_atersale()
  1576. {
  1577. if (UrlPostParmsCheck("ctid"))
  1578. {
  1579. string eid = GetPostString("ctid");
  1580. string reason = GetPostString("AfterSaleReason");
  1581. CeErpTradeCell entity = null;
  1582. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1583. if (entity != null)
  1584. {
  1585. /*if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1586. {
  1587. returnErrorMsg("此订单已经在售后");
  1588. return;
  1589. }*/
  1590. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1591. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1592. entity.AfterSaleTime = DateTime.Now;
  1593. entity.HandleTime = null;
  1594. entity.Update();
  1595. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1596. returnSuccessMsg("转售后成功!");
  1597. return;
  1598. }
  1599. returnErrorMsg("找不到记录");
  1600. }
  1601. }
  1602. public void set_erp_withdraw()
  1603. {
  1604. if (UrlPostParmsCheck("ctid"))
  1605. {
  1606. try
  1607. {
  1608. string eid = GetPostString("ctid");//商品id
  1609. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1610. CeWithdraw ceWithdrawSelect = null;
  1611. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1612. if (ceWithdrawSelect != null)
  1613. {
  1614. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1615. {
  1616. ceWithdrawSelect.status = -1;
  1617. ceWithdrawSelect.Update();
  1618. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1619. returnSuccessMsg("重新发起审核成功");
  1620. return;
  1621. }
  1622. else
  1623. {
  1624. returnSuccessMsg("请勿重复申请!");
  1625. return;
  1626. }
  1627. }
  1628. else
  1629. {
  1630. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1631. if (string.IsNullOrEmpty(CustomerUserId))
  1632. {
  1633. CustomerUserId = "-1";
  1634. }
  1635. int Userid = CurrentUser.UserID;//用户id
  1636. CeWithdraw ceWithdraw = new CeWithdraw();
  1637. ceWithdraw.tid = eid;
  1638. ceWithdraw.userid = Userid;
  1639. ceWithdraw.providerid = CustomerUserId;
  1640. ceWithdraw.status = 3;
  1641. ceWithdraw.creationtime = DateTime.Now;
  1642. ceWithdraw.Create();
  1643. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1644. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1645. return;
  1646. }
  1647. }
  1648. catch
  1649. {
  1650. returnErrorMsg("申请撤回订单失败");
  1651. return;
  1652. }
  1653. }
  1654. }
  1655. public void ins_erp_billinfo()
  1656. {
  1657. if (UrlPostParmsCheck("ctid"))
  1658. {
  1659. string eid = GetPostString("ctid");
  1660. CeErpTradeCell entity = null;
  1661. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1662. if (entity != null)
  1663. {
  1664. CeErpBill bill = CeErpBill.GetByTid(eid);
  1665. bool isHave = false;
  1666. if (bill != null)
  1667. {
  1668. isHave = true;
  1669. if (bill.state != 4)
  1670. {
  1671. returnErrorMsg("此单已经申请过发票了");
  1672. return;
  1673. }
  1674. }
  1675. if (entity.IsNeedBill == 0)
  1676. {
  1677. entity.IsNeedBill = 1;
  1678. }
  1679. entity.Update();
  1680. string errjson = "";
  1681. try
  1682. {
  1683. CeErpBill bill_entity = new CeErpBill();
  1684. bill_entity.tid = entity.tid;
  1685. bill_entity.title = GetPostString("title");
  1686. string taxstr = GetPostString("tax");
  1687. taxstr = taxstr.Replace(" ", "");
  1688. bill_entity.tax = taxstr;
  1689. bill_entity.bank = GetPostString("bank");
  1690. string bankacstr = GetPostString("bankac");
  1691. bankacstr = bankacstr.Replace(" ", "");
  1692. bill_entity.bankac = bankacstr;
  1693. bill_entity.address = GetPostString("address");
  1694. bill_entity.phone = GetPostString("phone");
  1695. bill_entity.price = GetPostString("price");
  1696. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1697. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1698. {
  1699. billCount += 1;
  1700. }
  1701. string prebill = "ltb";
  1702. for (int idx = 1; idx <= 1; idx++)
  1703. {
  1704. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1705. string billoid = prebill + idx + dtstr;
  1706. bill_entity.billOrderId += billoid;
  1707. if (idx < billCount)
  1708. {
  1709. bill_entity.billOrderId += ",";
  1710. }
  1711. }
  1712. bill_entity.productId = GetPostInt("ProductName");
  1713. bill_entity.num = GetPostInt("num");
  1714. bill_entity.unit = GetPostString("unit");
  1715. bill_entity.type = GetPostString("type");
  1716. bill_entity.sendType = GetPostString("SendType");
  1717. bill_entity.email = GetPostString("email");
  1718. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1719. bill_entity.shopName = GetPostString("ShopName");
  1720. bill_entity.applymemo = GetPostString("applyMemo");
  1721. bill_entity.createTime = DateTime.Now;
  1722. bill_entity.state = 0;
  1723. bill_entity.userId = CurrentUser.UserID;
  1724. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1725. bill_entity.Create();
  1726. }
  1727. catch (Exception ex)
  1728. {
  1729. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1730. returnErrorMsg("创建发票出错!");
  1731. return;
  1732. }
  1733. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1734. returnSuccessMsg("发票申请成功!");
  1735. return;
  1736. }
  1737. returnErrorMsg("找不到记录");
  1738. }
  1739. }
  1740. public void ins_erp_neworder()
  1741. {
  1742. if (UrlPostParmsCheck("receiver_name"))
  1743. {
  1744. CeErpTrade entity = new CeErpTrade();
  1745. string plat_form = GetPostString("platform");
  1746. string preStr = "N_";
  1747. if (plat_form == "拼多多")
  1748. {
  1749. preStr = "P_";
  1750. }
  1751. else if (plat_form == "阿里巴巴")
  1752. {
  1753. preStr = "A_";
  1754. }
  1755. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1756. entity.seller_nick = GetPostString("seller_nick");
  1757. entity.buyer_nick = GetPostString("buyer_nick");
  1758. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1759. entity.total_fee = entity.payment;
  1760. entity.pay_time = DateTime.Now;
  1761. entity.status = "NOT_SHIPPED";
  1762. entity.receiver_name = GetPostString("receiver_name");
  1763. entity.receiver_mobile = GetPostString("receiver_mobile");
  1764. entity.receiver_state = GetPostString("receiver_state");
  1765. entity.receiver_city = GetPostString("receiver_city");
  1766. entity.receiver_district = GetPostString("receiver_district");
  1767. entity.receiver_address = GetPostString("receiver_address");
  1768. if (entity.receiver_state == "" || entity.receiver_city == "")
  1769. {
  1770. returnErrorMsg("收件地址不能为空");
  1771. return;
  1772. }
  1773. int shopId = 0;
  1774. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1775. if (nShop != null)
  1776. {
  1777. shopId = nShop.ID;
  1778. }
  1779. if (shopId != 34 && entity.payment == 0)
  1780. {
  1781. returnErrorMsg("公司自用的单金额才能为0");
  1782. return;
  1783. }
  1784. entity.Create();
  1785. CeErpTradeCell entitycell = new CeErpTradeCell();
  1786. entitycell.ctid = entity.tid;
  1787. entitycell.tid = entity.tid;
  1788. entitycell.ShopId = shopId;
  1789. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1790. entitycell.OrderState = 0;
  1791. entitycell.pay_time = entity.pay_time;
  1792. entitycell.IsOffLineOrder = 1;
  1793. entitycell.Create();
  1794. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1795. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1796. return;
  1797. }
  1798. }
  1799. public void ins_erp_neworder2()
  1800. {
  1801. if (UrlPostParmsCheck("receiver_name"))
  1802. {
  1803. //string plat_form = GetPostString("platform");
  1804. string preStr = "X_";
  1805. string memo = GetPostString("memo");
  1806. string productId = GetPostString("productId");
  1807. string primg = GetPostString("proofimg");
  1808. string sellerNick = GetPostString("seller_nick");
  1809. string addFrom = GetPostString("addfrom");
  1810. if (addFrom == "1")
  1811. {
  1812. preStr = "N_";
  1813. }
  1814. int shopId = 0;
  1815. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1816. if (nShop != null)
  1817. {
  1818. shopId = nShop.ID;
  1819. }
  1820. else
  1821. {
  1822. returnErrorMsg("找不到对应店铺");
  1823. return;
  1824. }
  1825. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1826. {
  1827. returnErrorMsg("必须上传付款凭证");
  1828. return;
  1829. }
  1830. CeErpTrade entity = new CeErpTrade();
  1831. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1832. entity.seller_nick = sellerNick;
  1833. entity.buyer_nick = GetPostString("buyer_nick");
  1834. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1835. entity.total_fee = entity.payment;
  1836. entity.pay_time = DateTime.Now;
  1837. entity.status = "NOT_SHIPPED";
  1838. entity.receiver_name = GetPostString("receiver_name");
  1839. entity.receiver_mobile = GetPostString("receiver_mobile");
  1840. entity.receiver_state = GetPostString("receiver_state");
  1841. entity.receiver_city = GetPostString("receiver_city");
  1842. entity.receiver_district = GetPostString("receiver_district");
  1843. entity.receiver_address = GetPostString("receiver_address");
  1844. entity.seller_memo = memo;
  1845. entity.orderFrom = 20;
  1846. entity.orderType = 15;
  1847. if (entity.receiver_state == "" || entity.receiver_city == "")
  1848. {
  1849. returnErrorMsg("收件地址不能为空");
  1850. return;
  1851. }
  1852. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1853. {
  1854. returnErrorMsg("公司自用的单金额才能为0");
  1855. return;
  1856. }
  1857. entity.Create();
  1858. string toWhere = GetPostString("towhere");
  1859. string oldOrder = GetPostString("oldOrder");
  1860. CeErpTradeCell entitycell = new CeErpTradeCell();
  1861. entitycell.ctid = entity.tid;
  1862. //唯一标识
  1863. entitycell.OrderSn = entity.tid;
  1864. string orderSn = commonHelper.generateDateTimeRandomNos();
  1865. if (orderSn != "")
  1866. {
  1867. entitycell.OrderSn = orderSn;
  1868. }
  1869. entitycell.tid = entity.tid;
  1870. //if (preStr == "X_")
  1871. //{
  1872. entitycell.IsOffLineOrder = 1;
  1873. if ("1".Equals(oldOrder))
  1874. {
  1875. entitycell.IsOldCustomer = 1;
  1876. }
  1877. //}
  1878. entitycell.CustomerUserId = CurrentUser.UserID;
  1879. entitycell.PayProofImg = primg;
  1880. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1881. entitycell.ProductId = Convert.ToInt32(productId);
  1882. entitycell.ShopId = shopId;
  1883. entitycell.UpdateTime = DateTime.Now;
  1884. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1885. if (entitycell.ProductId > 0)
  1886. {
  1887. CeErpProduct ceErpProduct = CeErpProduct.GetById(entitycell.ProductId);
  1888. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1889. {
  1890. entitycell.NewProduct = 1;
  1891. }
  1892. }
  1893. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1894. {
  1895. entitycell.IsXianHuo = 1;
  1896. }
  1897. entitycell.pay_time = entity.pay_time;
  1898. if (toWhere == "1")
  1899. {
  1900. entitycell.OrderState = 2;
  1901. }
  1902. else
  1903. {
  1904. entitycell.OrderState = 6;
  1905. entitycell.FinishPlaceTime = entitycell.pay_time;
  1906. }
  1907. if (shopId == 94)
  1908. {
  1909. entitycell.OrderState = 4;
  1910. entitycell.WaitDesignTime = entitycell.pay_time;
  1911. entitycell.StartDesignTime = entitycell.pay_time;
  1912. entitycell.DesignUserId = 218;
  1913. }
  1914. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114 && shopId != 158))
  1915. {
  1916. entitycell.OrderState = -1;//修改12-5
  1917. CeWithdraw ceWithdraw = new CeWithdraw();
  1918. ceWithdraw.tid = entity.tid;
  1919. ceWithdraw.providerid = "-1";
  1920. ceWithdraw.status = -1;
  1921. ceWithdraw.creationtime = DateTime.Now;
  1922. ceWithdraw.userid = 4634;
  1923. ceWithdraw.Create();
  1924. }
  1925. entitycell.Create();
  1926. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1927. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1928. {
  1929. addPlaceRegist(entitycell, CurrentUser.UserID);
  1930. }
  1931. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1932. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1933. return;
  1934. }
  1935. }
  1936. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1937. {
  1938. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1939. entity.PlactTime = tradecell.pay_time;
  1940. entity.AddUserId = userid;
  1941. entity.FileName = tradecell.seller_memo;
  1942. entity.Supplier = 24;
  1943. entity.CreateTime = DateTime.Now;
  1944. entity.Did = tradecell.ctid;
  1945. entity.tid = tradecell.tid;
  1946. entity.splitTag = tradecell.SplitTag;
  1947. entity.CurState = "未完成";
  1948. entity.Create();
  1949. }
  1950. public void get_erp_offlinelist()
  1951. {
  1952. DataStruct dStruct = GetPostStruct();
  1953. List<string> lw = new List<string>();
  1954. string tid = GetPostString("ctid");
  1955. string date1 = GetPostString("date1");
  1956. string date2 = GetPostString("date2");
  1957. if (tid.Length > 0 || date1.Length > 0)
  1958. {
  1959. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1960. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1961. if (dw.Length > 0) lw.Add(dw);
  1962. }
  1963. else
  1964. {
  1965. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1966. }
  1967. string shopname = GetPostString("shopname");
  1968. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1969. string buyernick = GetPostString("buyer_nick");
  1970. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1971. string customer = GetPostString("customer");
  1972. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1973. string design = GetPostString("design");
  1974. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1975. string orderState = GetPostString("orderState");
  1976. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1977. string address = GetPostString("address");
  1978. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  1979. string sellermemo = GetPostString("seller_memo");
  1980. if (sellermemo.Length > 0)
  1981. {
  1982. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1983. }
  1984. string price1 = GetPostString("price1");
  1985. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1986. string price2 = GetPostString("price2");
  1987. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1988. //if (PKey != "admin")
  1989. //{
  1990. // string usershop = CurrentUser.User.pemShop;
  1991. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1992. //}
  1993. //if (ex_psize > 0)
  1994. //{
  1995. dStruct.Order = "pay_time desc";
  1996. //}
  1997. //else
  1998. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1999. lw.Add(string.Format("IsOffLineOrder=1"));
  2000. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2001. DataTable dt = null;
  2002. dt = WebCache.GetData("view_erptradecell", dStruct);
  2003. writeGridDataTableJson(dStruct.TotalCount, dt);
  2004. }
  2005. public void get_erp_returncashrecord()
  2006. {
  2007. DataStruct dStruct = GetPostStruct();
  2008. List<string> lw = new List<string>();
  2009. string tid = GetPostString("ctid");
  2010. if (tid.Length > 0)
  2011. {
  2012. lw.Add(string.Format("tid like '%{0}%'", tid));
  2013. dStruct.Order = "id desc";
  2014. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2015. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  2016. //writeGridDataTableJson(dStruct.TotalCount, dt);
  2017. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2018. return;
  2019. }
  2020. returnErrorMsg("id数据错误!");
  2021. }
  2022. public void ins_erp_returncashrecord()
  2023. {
  2024. if (UrlPostParmsCheck("tid"))
  2025. {
  2026. string tid = GetPostString("tid");
  2027. string retype = GetPostString("type");
  2028. StringBuilder sql = new StringBuilder();
  2029. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  2030. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2031. if (dt.Rows.Count > 0)
  2032. {
  2033. returnErrorMsg("相同返现类型记录已存在");
  2034. return;
  2035. }
  2036. CeErpReturnCash entity = new CeErpReturnCash();
  2037. entity.tid = tid;
  2038. entity.seller_nick = GetPostString("seller_nick");
  2039. string pment = GetPostString("payment");
  2040. if (pment.Length > 0)
  2041. {
  2042. entity.payment = Convert.ToDouble(pment);
  2043. }
  2044. entity.buyer_nick = GetPostString("buyer_nick");
  2045. entity.cashstate = 0;
  2046. entity.rtype = retype;
  2047. string rPrice = GetPostString("returnprice");
  2048. if (rPrice.Length > 0)
  2049. {
  2050. entity.returnprice = Convert.ToDouble(rPrice);
  2051. }
  2052. entity.created = DateTime.Now;
  2053. entity.con = GetPostString("con");
  2054. entity.img = GetPostString("img");
  2055. entity.applyuserid = CurrentUser.UserID;
  2056. entity.Create();
  2057. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  2058. returnSuccessMsg("操作成功!");
  2059. return;
  2060. }
  2061. }
  2062. public void set_erp_predelivery()
  2063. {
  2064. if (UrlPostParmsCheck("ctid"))
  2065. {
  2066. string eid = GetPostString("ctid");
  2067. CeErpTradeCell entity = null;
  2068. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2069. if (entity != null)
  2070. {
  2071. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  2072. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  2073. //{
  2074. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  2075. // return;
  2076. //}
  2077. entity.IsPreDelivery = 1;
  2078. entity.Update();
  2079. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2080. returnSuccessMsg("预发货成功!");
  2081. return;
  2082. //string shop = GetPostString("seller_nick");
  2083. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  2084. //string comName = GetPostString("comName");
  2085. //string comCode = GetPostString("comCode");
  2086. //string outSid = GetPostString("outSid");//运单号
  2087. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  2088. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  2089. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  2090. //string apires = "";
  2091. //if (deliveryType == "虚拟发货")
  2092. //{
  2093. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  2094. //}
  2095. //else
  2096. //{
  2097. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  2098. //}
  2099. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  2100. ////{
  2101. //if (apires.IndexOf("发货成功") != -1)
  2102. //{
  2103. // if (deliveryType != "虚拟发货")
  2104. // {
  2105. // //还要插入快递信息到 快递信息表
  2106. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  2107. // exinfo.tid = eid;
  2108. // exinfo.out_sid = outSid;
  2109. // exinfo.company_code = comCode;
  2110. // exinfo.company_name = comName;
  2111. // exinfo.delivery_memo = deliveryMemo;
  2112. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  2113. // exinfo.deliveryType = deliveryType;
  2114. // exinfo.Create();
  2115. // }
  2116. // returnSuccessMsg("发货成功!");
  2117. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2118. //}
  2119. //else
  2120. //{
  2121. // returnErrorMsg("淘宝发货失败!!");
  2122. //}
  2123. //return;
  2124. }
  2125. returnErrorMsg("找不到订单记录");
  2126. }
  2127. }
  2128. public void get_erp_unusuallist()
  2129. {
  2130. DataStruct dStruct = GetPostStruct();
  2131. List<string> lw = new List<string>();
  2132. string tid = GetPostString("ctid");
  2133. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2134. string shopname = GetPostString("shopname");
  2135. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2136. string buyernick = GetPostString("buyer_nick");
  2137. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2138. string ResponsibleMan = GetPostString("responsible");
  2139. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2140. string date1 = GetPostString("date1");
  2141. string date2 = GetPostString("date2");
  2142. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2143. if (dw.Length > 0) lw.Add(dw);
  2144. string price1 = GetPostString("price1");
  2145. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2146. string price2 = GetPostString("price2");
  2147. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2148. string orderState = GetPostString("orderState");
  2149. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2150. string sellermemo = GetPostString("seller_memo");
  2151. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2152. lw.Add(string.Format("UnusualTag > 0"));
  2153. lw.Add(string.Format("IsRefund<={0}", 1));
  2154. dStruct.Order = "pay_time desc";
  2155. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2156. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2157. writeGridDataTableJson(dStruct.TotalCount, dt);
  2158. }
  2159. public void set_erp_unusualtonomal()
  2160. {
  2161. if (UrlPostParmsCheck("ctid"))
  2162. {
  2163. string eid = GetPostString("ctid");
  2164. CeErpTradeCell entity = null;
  2165. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2166. if (entity != null)
  2167. {
  2168. entity.UnusualTag = -1;
  2169. entity.Update();
  2170. returnSuccessMsg("忽略成功!");
  2171. return;
  2172. }
  2173. returnErrorMsg("找不到记录");
  2174. }
  2175. }
  2176. public void ins_erp_unusualreason()
  2177. {
  2178. if (UrlPostParmsCheck("ctid"))
  2179. {
  2180. string eid = GetPostString("ctid");
  2181. CeErpTradeCell entity = null;
  2182. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2183. if (entity != null)
  2184. {
  2185. entity.MemoOpt = 4;
  2186. entity.UnusualCon = GetPostString("con");
  2187. entity.Update();
  2188. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2189. if (trade != null)
  2190. {
  2191. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2192. }
  2193. //查货是否超时
  2194. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2195. if (ceErpTradeCellExtend == null)
  2196. {
  2197. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2198. ceErpTradeCellExtend.ctid = entity.ctid;
  2199. }
  2200. if (ceErpTradeCellExtend.CheckTime != null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2201. {
  2202. ceErpTradeCellExtend.CheckOut += 1;
  2203. }
  2204. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2205. if (ceErpTradeCellExtend.ID > 0)
  2206. {
  2207. ceErpTradeCellExtend.Update();
  2208. }
  2209. else
  2210. {
  2211. ceErpTradeCellExtend.Create();
  2212. }
  2213. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2214. returnSuccessMsg("操作成功!");
  2215. return;
  2216. }
  2217. returnErrorMsg("找不到记录");
  2218. }
  2219. }
  2220. public void upd_erp_sampleorder()
  2221. {
  2222. if (UrlPostParmsCheck("ctid"))
  2223. {
  2224. string eid = GetPostString("ctid");
  2225. string[] eArr = eid.Split(',');
  2226. if (eArr.Length > 1)
  2227. {
  2228. List<string> eLst = new List<string>();
  2229. for (int i = 0; i < eArr.Length; i++)
  2230. {
  2231. eLst.Add("'" + eArr[i] + "'");
  2232. }
  2233. eid = string.Join(",", eLst.ToArray());
  2234. }
  2235. else
  2236. {
  2237. eid = "'" + eid + "'";
  2238. }
  2239. StringBuilder sql = new StringBuilder();
  2240. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2241. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2242. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2243. if (dt.Rows.Count > 0)
  2244. {
  2245. string errmsg = "";
  2246. foreach (DataRow dr in dt.Rows)
  2247. {
  2248. StringBuilder sqlsb = new StringBuilder();
  2249. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2250. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2251. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2252. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2253. //string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2254. /*if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2255. {
  2256. continue;
  2257. }
  2258. else
  2259. {
  2260. string emsg = commonHelper.KeepChinese(apires);
  2261. errmsg += emsg;
  2262. }*/
  2263. }
  2264. if (errmsg.Length > 0)
  2265. {
  2266. returnErrorMsg(errmsg);
  2267. return;
  2268. }
  2269. returnSuccessMsg("操作成功");
  2270. return;
  2271. }
  2272. returnErrorMsg("找不到记录");
  2273. }
  2274. }
  2275. public void upd_erp_transcustomer()
  2276. {
  2277. if (UrlPostParmsCheck("ctid"))
  2278. {
  2279. string eid = GetPostString("ctid");
  2280. int userid = GetPostInt("CustomerUserId");
  2281. CeErpTradeCell entity = null;
  2282. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2283. if (entity != null)
  2284. {
  2285. //string[] mlist = entity.seller_memo.Split('-');
  2286. //string sql = "select * from view_erpuser where id=" + userid;
  2287. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2288. //if (dt != null && dt.Rows.Count > 0)
  2289. //{
  2290. // string nmemo = "";
  2291. // for(int i = 0; i < mlist.Length - 1; i++)
  2292. // {
  2293. // nmemo += mlist[i];
  2294. // nmemo += "-";
  2295. // }
  2296. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2297. // entity.seller_memo = nmemo;
  2298. //}
  2299. entity.CustomerUserId = userid;
  2300. entity.Update();
  2301. returnSuccessMsg("操作成功!");
  2302. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2303. return;
  2304. }
  2305. returnErrorMsg("找不到记录");
  2306. }
  2307. }
  2308. public void upd_erp_transdesigner()
  2309. {
  2310. if (UrlPostParmsCheck("ctid"))
  2311. {
  2312. string eids = GetPostString("ctid");
  2313. string[] ctidList = eids.Split(',');
  2314. int userid = GetPostInt("DesignUserId");
  2315. foreach (string ctid in ctidList)
  2316. {
  2317. CeErpTradeCell entity = null;
  2318. CeErpDesignerBill entitys = null;
  2319. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2320. entitys = CeErpDesignerBill.GetByTid(ctid);
  2321. if (entity != null)
  2322. {
  2323. if (entity.OrderState > 4)
  2324. {
  2325. continue;
  2326. }
  2327. //存在退款不能流转
  2328. if (entity.IsRefund > 0)
  2329. {
  2330. continue;
  2331. }
  2332. entity.DesignUserId = userid;
  2333. entity.WaitDesignTime = DateTime.Now;
  2334. entity.Update();
  2335. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2336. }
  2337. }
  2338. returnSuccessMsg("操作成功!");
  2339. }
  2340. }
  2341. public void upd_erp_distributedesigner()
  2342. {
  2343. if (UrlPostParmsCheck("ctid"))
  2344. {
  2345. string eid = GetPostString("ctid");
  2346. int userid = GetPostInt("DesignUserId");
  2347. string reason = GetPostString("reason");
  2348. string[] idlist = eid.Split(',');
  2349. if (idlist.Length <= 0)
  2350. {
  2351. returnErrorMsg("订单不能为空");
  2352. return;
  2353. }
  2354. foreach (string ctid in idlist)
  2355. {
  2356. CeErpTradeCell entity = null;
  2357. CeErpDesignerBill entitys = null;
  2358. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2359. else continue;
  2360. if (entity != null)
  2361. {
  2362. if (userid == 2125 || userid == 3542)
  2363. { }
  2364. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2365. {
  2366. returnErrorMsg("金额错误的订单无法指派");
  2367. return;
  2368. }
  2369. if (entity.OrderState >= 5)
  2370. {
  2371. returnErrorMsg("已经设计完成无法指派");
  2372. return;
  2373. }
  2374. if (entity.OrderState == -1)
  2375. {
  2376. returnErrorMsg("审核中的订单无法指派");
  2377. return;
  2378. }
  2379. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2380. {
  2381. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2382. return;
  2383. }
  2384. List<int> userIds = new List<int>()
  2385. {
  2386. 157 ,159 ,1479 ,73
  2387. };
  2388. //157赖橙帆 159林晨 73 静之颖
  2389. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && !userIds.Contains(CurrentUser.UserID))
  2390. {
  2391. returnErrorMsg("指派设计共创无法再次指派!");
  2392. return;
  2393. }
  2394. entity.OrderState = 3;
  2395. if (entity.SupplierId == 0)
  2396. {
  2397. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2398. entity.SupplierId = suid;
  2399. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2400. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2401. }
  2402. if (userid == 2125 && entity.seller_memo != "")
  2403. {
  2404. //apiDesign.API_GetPrintData_CreateOrder(entity);
  2405. }
  2406. List<int> shopIds = new List<int>() { 17, 21, 52, 54, 64, 63, 66, 49, 67, 105, 35, 57, 53, 65, 87, 140, 26, 45, 2, 77, 122, 121, 153, 154, 158 };
  2407. if (userid == 3542 && entity.seller_memo != "")
  2408. {
  2409. string userPost = CurrentUser.UserPost.Post.Code;
  2410. if (CurrentUser.UserID == 4516 || CurrentUser.UserID == 159 || CurrentUser.UserID == 157 || shopIds.Contains(entity.ShopId))
  2411. {
  2412. userPost = "SysAdmin";
  2413. }
  2414. if (CurrentUser.UserID == 159 || CurrentUser.UserID == 157)
  2415. {
  2416. saveAssignLog(reason, entity);
  2417. }
  2418. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2419. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2420. if (response.msg != "设计共创:成功")
  2421. {
  2422. returnErrorMsg(response.msg);
  2423. return;
  2424. }
  2425. entity.DispatchSort = 2;
  2426. }
  2427. else
  2428. {
  2429. if (entity.DispatchSort == 2)
  2430. {
  2431. ApiVo apiVo = new ApiVo();
  2432. apiVo.actionName = "closeDesign";
  2433. apiVo.orderNumber = entity.ctid;
  2434. designHelper.API_WorkCore(apiVo);//closeDesign
  2435. }
  2436. entity.DispatchSort = 0;
  2437. }
  2438. entity.DesignUserId = userid;
  2439. entity.WaitDesignTime = DateTime.Now;
  2440. entity.UpdateTime = DateTime.Now;
  2441. entity.Update();
  2442. string name = commonHelper.getUserNameById(userid);
  2443. commonHelper.UpdateRelationOrder(entity.ctid);
  2444. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2445. }
  2446. }
  2447. returnSuccessMsg("操作成功!");
  2448. return;
  2449. }
  2450. }
  2451. public string getTidByCtid(string ctid)
  2452. {
  2453. string tid = "";
  2454. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2455. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2456. if (dataTable != null && dataTable.Rows.Count > 0)
  2457. {
  2458. tid = dataTable.Rows[0]["tid"].ToString();
  2459. }
  2460. return tid;
  2461. }
  2462. public List<string> getTidByCtidMore(string ctid)
  2463. {
  2464. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2465. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2466. List<string> list = new List<string>();
  2467. if (dataTable != null && dataTable.Rows.Count > 0)
  2468. {
  2469. foreach (DataRow item in dataTable.Rows)
  2470. {
  2471. list.Add("'" + item["tid"].ToString() + "'");
  2472. }
  2473. }
  2474. return list;
  2475. }
  2476. public List<string> getTidByCtidLike(string ctid)
  2477. {
  2478. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2479. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2480. List<string> list = new List<string>();
  2481. if (dataTable != null && dataTable.Rows.Count > 0)
  2482. {
  2483. foreach (DataRow item in dataTable.Rows)
  2484. {
  2485. list.Add("'" + item["tid"].ToString() + "'");
  2486. }
  2487. }
  2488. return list;
  2489. }
  2490. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2491. {
  2492. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2493. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2494. List<string> list = new List<string>();
  2495. if (dataTable != null && dataTable.Rows.Count > 0)
  2496. {
  2497. foreach (DataRow item in dataTable.Rows)
  2498. {
  2499. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2500. {
  2501. continue;
  2502. }
  2503. list.Add("'" + item["receiverId"].ToString() + "'");
  2504. }
  2505. }
  2506. return list;
  2507. }
  2508. public void get_erp_myorderlist()
  2509. {
  2510. DataStruct dStruct = GetPostStruct();
  2511. List<string> lw = new List<string>();
  2512. string tid = GetPostString("ctid");
  2513. if (tid.Length > 0)
  2514. {
  2515. string select_tid = getTidByCtid(tid);
  2516. lw.Add(string.Format("tid='{0}'", select_tid));
  2517. }
  2518. else
  2519. {
  2520. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2521. }
  2522. //12-1 修改
  2523. string urgent = GetPostString("urgent");
  2524. string back = GetPostString("back");
  2525. string offlineSearch = GetPostString("offlineSearch");
  2526. if (!string.IsNullOrWhiteSpace(urgent))
  2527. {
  2528. if (urgent.Equals("true"))
  2529. {
  2530. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2531. }
  2532. }
  2533. if (!string.IsNullOrWhiteSpace(back))
  2534. {
  2535. if (back.Equals("true"))
  2536. {
  2537. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2538. }
  2539. }
  2540. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2541. {
  2542. if (offlineSearch.Equals("true"))
  2543. {
  2544. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2545. }
  2546. }
  2547. //end
  2548. string shopname = GetPostString("shopname");
  2549. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2550. string buyernick = GetPostString("buyer_nick");
  2551. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2552. string design = GetPostString("design");
  2553. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2554. string orderState = GetPostString("orderState");
  2555. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2556. string sellermemo = GetPostString("seller_memo");
  2557. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2558. string date1 = GetPostString("date1");
  2559. string date2 = GetPostString("date2");
  2560. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2561. if (dw.Length > 0) lw.Add(dw);
  2562. string price1 = GetPostString("price1");
  2563. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2564. string price2 = GetPostString("price2");
  2565. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2566. string urgency = GetPostString("urgency");
  2567. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2568. string after = GetPostString("after");
  2569. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2570. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2571. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2572. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2573. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2574. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2575. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2576. if (dt != null && dt.Rows.Count > 0)
  2577. {
  2578. foreach (DataRow dr in dt.Rows)
  2579. {
  2580. try
  2581. {
  2582. // 对象操作
  2583. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2584. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2585. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2586. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2587. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2588. if (dStruct.PageSize != 100000)
  2589. {
  2590. if (dr["DispatchSort"].ToString() == "2")
  2591. {
  2592. dr["gongchuang"] = 200;
  2593. }
  2594. else if ("外协".Equals(dr["ToType"].ToString()))
  2595. {
  2596. dr["gongchuang"] = 200;
  2597. }
  2598. else if ("内部".Equals(dr["ToType"].ToString()))
  2599. {
  2600. dr["gongchuang"] = -1;
  2601. }
  2602. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2603. {
  2604. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2605. dr["gongchuang"] = response.code;
  2606. }
  2607. }
  2608. }
  2609. catch (NullReferenceException ex)
  2610. {
  2611. }
  2612. }
  2613. }
  2614. writeGridDataTableJson(dStruct.TotalCount, dt);
  2615. }
  2616. public void get_erp_myreturnorderlist()
  2617. {
  2618. DataStruct dStruct = GetPostStruct();
  2619. List<string> lw = new List<string>();
  2620. string tid = GetPostString("ctid");
  2621. if (tid.Length > 0)
  2622. {
  2623. string select_tid = getTidByCtid(tid);
  2624. lw.Add(string.Format("tid='{0}'", select_tid));
  2625. }
  2626. else
  2627. {
  2628. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2629. }
  2630. string shopname = GetPostString("shopname");
  2631. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2632. string buyernick = GetPostString("buyer_nick");
  2633. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2634. string design = GetPostString("design");
  2635. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2636. string orderState = GetPostString("orderState");
  2637. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2638. string sellermemo = GetPostString("seller_memo");
  2639. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2640. string date1 = GetPostString("date1");
  2641. string date2 = GetPostString("date2");
  2642. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2643. if (dw.Length > 0) lw.Add(dw);
  2644. string price1 = GetPostString("price1");
  2645. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2646. string price2 = GetPostString("price2");
  2647. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2648. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2649. {
  2650. lw.Add(string.Format("CusOrgID = 94"));
  2651. }
  2652. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2653. {
  2654. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2655. }
  2656. else
  2657. {
  2658. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2659. }
  2660. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2661. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2662. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2663. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2664. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2665. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2666. if (dt != null && dt.Rows.Count > 0)
  2667. {
  2668. foreach (DataRow dr in dt.Rows)
  2669. {
  2670. try
  2671. {
  2672. // 对象操作
  2673. if (dStruct.PageSize != 100000)
  2674. {
  2675. if (dr["DispatchSort"].ToString() == "2")
  2676. {
  2677. dr["gongchuang"] = 200;
  2678. }
  2679. else if ("外协".Equals(dr["ToType"].ToString()))
  2680. {
  2681. dr["gongchuang"] = 200;
  2682. }
  2683. else if ("内部".Equals(dr["ToType"].ToString()))
  2684. {
  2685. dr["gongchuang"] = -1;
  2686. }
  2687. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2688. {
  2689. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2690. dr["gongchuang"] = response.code;
  2691. }
  2692. }
  2693. }
  2694. catch (NullReferenceException ex)
  2695. {
  2696. // 处理空引用异常
  2697. }
  2698. }
  2699. }
  2700. writeGridDataTableJson(dStruct.TotalCount, dt);
  2701. }
  2702. public void get_erp_myorderlist_pregather()
  2703. {
  2704. string date1 = GetPostString("date1");
  2705. string date2 = GetPostString("date2");
  2706. int userId = CurrentUser.UserID; //客服id
  2707. string orderWhere = "";
  2708. List<string> lw = new List<string>();
  2709. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2710. if (dw.Length > 0) lw.Add(dw);
  2711. lw.Add(string.Format("CustomerUserId={0}", userId));
  2712. lw.Add(string.Format("OrderState<9"));
  2713. orderWhere = string.Join(" and ", lw.ToArray());
  2714. string orderWhere2 = "";
  2715. List<string> lw2 = new List<string>();
  2716. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2717. if (dw2.Length > 0) lw2.Add(dw2);
  2718. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2719. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2720. string sql = string.Format("select *" +
  2721. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2722. "left join(select CustomerUserId, count(ctid) as dCount from View_ErpTradeCell where OrderState = 6 and " + orderWhere2 + " group by CustomerUserId) b on a.CustomerUserId = b.CustomerUserId " +
  2723. "left join(select CustomerUserId, count(ctid) as jCount from View_ErpTradeCell where IsUrgency = 1 and " + orderWhere + " group by CustomerUserId) c on a.CustomerUserId = c.CustomerUserId " +
  2724. "left join(select CustomerUserId, count(ctid) as sCount from View_ErpTradeCell where AfterSaleState > 0 and CHARINDEX(','+CONVERT(varchar," + userId + ")+'_k,',','+ResponsibleUserId+',')>0 and " + orderWhere + " group by CustomerUserId) d on a.CustomerUserId = d.CustomerUserId");
  2725. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2726. //writeGridDataTableJson(dt.Rows.Count, dt);
  2727. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2728. }
  2729. public void upd_erp_publishorder()
  2730. {
  2731. if (UrlPostParmsCheck("ctid"))
  2732. {
  2733. string eid = GetPostString("ctid");
  2734. CeErpTradeCell entity = null;
  2735. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2736. if (entity != null)
  2737. {
  2738. entity.OrderState = 0; //发布后,变为待抢单
  2739. entity.Update();
  2740. commonHelper.UpdateRelationOrder(entity.ctid);
  2741. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2742. returnSuccessMsg("发布成功!");
  2743. return;
  2744. }
  2745. returnErrorMsg("找不到记录");
  2746. }
  2747. }
  2748. public void get_erp_my_tiporder()
  2749. {
  2750. StringBuilder sql = new StringBuilder();
  2751. int userId = 0;
  2752. if (CurrentUser != null) userId = CurrentUser.UserID;
  2753. string posCode = CurrentUser.UserPost.Post.Code;
  2754. string isTipedAfterSaleVerify = GetPostString("af");
  2755. DataTable dt = new DataTable();
  2756. if (posCode != "Supplier")
  2757. {
  2758. if (posCode == "CustomerService" || posCode == "Director")
  2759. {
  2760. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2761. }
  2762. else if (posCode == "Place" || posCode == "PlaceMr")
  2763. {
  2764. }
  2765. else
  2766. {
  2767. string teamIds = CurrentUser.User.TeamIds;
  2768. if (teamIds == "")
  2769. {
  2770. teamIds = "0";
  2771. }
  2772. sql.AppendFormat("select * from ce_erptradecell where (DesignUserId={0} or DesignUserId in (select ID from view_erpuser where OnDuty=0 and ID in ({1}))) and OrderState in (3,4) and IsReadTag>0 ", userId, teamIds);
  2773. }
  2774. if (sql.Length > 0)
  2775. {
  2776. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2777. }
  2778. }
  2779. if (dt.Rows.Count <= 0)
  2780. {
  2781. string key = "aftersale_order_" + userId;
  2782. if (RedisHelper.HasKey(key))
  2783. {
  2784. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2785. dt.Columns.Add("ctid", typeof(string));
  2786. dt.Columns.Add("IsReadTag", typeof(int));
  2787. foreach (var i in list)
  2788. {
  2789. DataRow data = dt.NewRow();
  2790. data["ctid"] = i;
  2791. data["IsReadTag"] = 4;
  2792. dt.Rows.Add(data);
  2793. }
  2794. RedisHelper.StringDelete(key);
  2795. }
  2796. }
  2797. if (dt.Rows.Count <= 0)
  2798. {
  2799. sql = new StringBuilder();
  2800. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2801. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2802. }
  2803. if (posCode == "Supplier")
  2804. {
  2805. string ids = CurrentUser.User.pemVend;
  2806. if (ids != null && ids.Length > 0)
  2807. {
  2808. string[] ids_list = ids.Split(',');
  2809. foreach (var item in ids_list)
  2810. {
  2811. string key = "return_order_" + item;
  2812. if (RedisHelper.HasKey(key))
  2813. {
  2814. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2815. dt.Columns.Add("ctid", typeof(string));
  2816. dt.Columns.Add("IsReadTag", typeof(int));
  2817. foreach (var i in list)
  2818. {
  2819. DataRow data = dt.NewRow();
  2820. data["ctid"] = i;
  2821. data["IsReadTag"] = 1;
  2822. dt.Rows.Add(data);
  2823. }
  2824. RedisHelper.StringDelete(key);
  2825. }
  2826. }
  2827. }
  2828. if (dt.Rows.Count <= 0)
  2829. {
  2830. sql = new StringBuilder();
  2831. sql.AppendFormat("select MemoOpt,SupplierId,ctid from ce_erptradecell where SupplierId in ({0}) and MemoOpt=3 and DATEDIFF(MINUTE,CheckOrderTime,GETDATE())<=3", CurrentUser.User.pemVend);
  2832. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2833. }
  2834. }
  2835. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2836. }
  2837. public void reset_erp_tiporder()
  2838. {
  2839. string ids = GetPostString("ids");
  2840. string[] ctidList = ids.Split(',');
  2841. foreach (string ctid in ctidList)
  2842. {
  2843. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2844. if (enty != null)
  2845. {
  2846. enty.IsReadTag = 0;
  2847. enty.Update();
  2848. }
  2849. }
  2850. returnSuccessMsg("成功!");
  2851. return;
  2852. }
  2853. public void get_erp_designlist()
  2854. {
  2855. DataStruct dStruct = GetPostStruct();
  2856. List<string> lw = new List<string>();
  2857. string tid = GetPostString("ctid");
  2858. if (tid.Length > 0)
  2859. {
  2860. string select_tid = getTidByCtid(tid);
  2861. lw.Add(string.Format("tid='{0}'", select_tid));
  2862. }
  2863. string shopname = GetPostString("shopname");
  2864. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2865. string buyernick = GetPostString("buyer_nick");
  2866. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2867. string customer = GetPostString("customer");
  2868. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2869. string design = GetPostString("design");
  2870. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2871. string orderState = GetPostString("orderState");
  2872. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2873. lw.Add(string.Format("OrderState<6"));
  2874. string address = GetPostString("address");
  2875. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2876. string sellermemo = GetPostString("seller_memo");
  2877. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2878. string date1 = GetPostString("date1");
  2879. string date2 = GetPostString("date2");
  2880. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2881. if (dw.Length > 0) lw.Add(dw);
  2882. string apdate1 = GetPostString("apdate1");
  2883. string apdate2 = GetPostString("apdate2");
  2884. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2885. if (dwap.Length > 0) lw.Add(dwap);
  2886. string price1 = GetPostString("price1");
  2887. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2888. string price2 = GetPostString("price2");
  2889. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2890. string designTime = GetPostString("designtime");
  2891. if (designTime.Length > 0)
  2892. {
  2893. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2894. }
  2895. string usershop = CurrentUser.User.pemShop;
  2896. if (usershop.Length > 0)
  2897. {
  2898. lw.Add(string.Format("shopId in ({0})", usershop));
  2899. }
  2900. int myOrgid = CurrentUser.UserPost.OrgID;
  2901. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2902. if (myOrgCode.IndexOf("Designer") != -1)
  2903. {
  2904. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2905. {
  2906. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2907. }
  2908. else
  2909. {
  2910. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2911. }
  2912. }
  2913. else
  2914. {
  2915. string orgId = GetPostString("designerhd");
  2916. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2917. }
  2918. if (tid.Length > 0 || buyernick.Length > 0)
  2919. {
  2920. lw.Add(string.Format("OrderState >= 3"));
  2921. }
  2922. else
  2923. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2924. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2925. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2926. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2927. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2928. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2929. if (dt != null && dt.Rows.Count > 0)
  2930. {
  2931. foreach (DataRow dr in dt.Rows)
  2932. {
  2933. try
  2934. {
  2935. // 对象操作
  2936. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2937. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2938. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2939. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2940. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2941. if (dStruct.PageSize != 100000)
  2942. {
  2943. if (dr["DispatchSort"].ToString() == "2")
  2944. {
  2945. dr["gongchuang"] = 200;
  2946. }
  2947. else if ("外协".Equals(dr["ToType"].ToString()))
  2948. {
  2949. dr["gongchuang"] = 200;
  2950. }
  2951. else if ("内部".Equals(dr["ToType"].ToString()))
  2952. {
  2953. dr["gongchuang"] = -1;
  2954. }
  2955. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2956. {
  2957. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2958. dr["gongchuang"] = response.code;
  2959. }
  2960. }
  2961. }
  2962. catch (NullReferenceException ex)
  2963. {
  2964. }
  2965. }
  2966. }
  2967. writeGridDataTableJson(dStruct.TotalCount, dt);
  2968. }
  2969. public void get_erp_mydesignlist()
  2970. {
  2971. DataStruct dStruct = GetPostStruct();
  2972. List<string> lw = new List<string>();
  2973. string tid = GetPostString("ctid");
  2974. if (tid.Length > 0)
  2975. {
  2976. string select_tid = getTidByCtid(tid);
  2977. lw.Add(string.Format("tid='{0}'", select_tid));
  2978. }
  2979. string shopname = GetPostString("shopname");
  2980. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2981. string buyernick = GetPostString("buyer_nick");
  2982. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2983. string customer = GetPostString("customer");
  2984. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2985. string orderState = GetPostString("orderState");
  2986. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2987. //lw.Add(string.Format("OrderState<6"));
  2988. string date1 = GetPostString("date1");
  2989. string date2 = GetPostString("date2");
  2990. string dw = GetDateWhere("pay_time", date1, date2);
  2991. if (dw.Length > 0) lw.Add(dw);
  2992. string apdate1 = GetPostString("apdate1");
  2993. string apdate2 = GetPostString("apdate2");
  2994. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2995. if (dwap.Length > 0) lw.Add(dwap);
  2996. string price1 = GetPostString("price1");
  2997. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2998. string price2 = GetPostString("price2");
  2999. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3000. string olddownload = GetPostString("olddown");
  3001. if (olddownload == "1")
  3002. {
  3003. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  3004. }
  3005. else if (olddownload == "2")
  3006. {
  3007. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  3008. }
  3009. string sellermemo = GetPostString("seller_memo");
  3010. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3011. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  3012. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  3013. {
  3014. if (CurrentUser.User.TeamIds.Length > 0)
  3015. {
  3016. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  3017. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3018. else
  3019. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3020. }
  3021. else
  3022. {
  3023. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  3024. }
  3025. }
  3026. if (tid.Length <= 0)
  3027. {
  3028. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  3029. }
  3030. lw.Add(string.Format("IsReturn!=3"));
  3031. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  3032. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3033. string teamids = CurrentUser.User.TeamIds.ToString();
  3034. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3035. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  3036. if (dt != null && dt.Rows.Count > 0)
  3037. {
  3038. foreach (DataRow dr in dt.Rows)
  3039. {
  3040. try
  3041. {
  3042. // 对象操作
  3043. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  3044. ceErpTradeCell.ctid = dr["ctid"].ToString();
  3045. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  3046. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  3047. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  3048. if (dStruct.PageSize != 100000)
  3049. {
  3050. if (dr["DispatchSort"].ToString() == "2")
  3051. {
  3052. dr["gongchuang"] = 200;
  3053. }
  3054. else if ("外协".Equals(dr["ToType"].ToString()))
  3055. {
  3056. dr["gongchuang"] = 200;
  3057. }
  3058. else if ("内部".Equals(dr["ToType"].ToString()))
  3059. {
  3060. dr["gongchuang"] = -1;
  3061. }
  3062. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3063. {
  3064. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3065. dr["gongchuang"] = response.code;
  3066. }
  3067. }
  3068. }
  3069. catch (NullReferenceException ex)
  3070. {
  3071. }
  3072. }
  3073. }
  3074. writeGridDataTableJson(dStruct.TotalCount, dt);
  3075. }
  3076. public void set_erp_startdesign()
  3077. {
  3078. if (UrlPostParmsCheck("ctid"))
  3079. {
  3080. string eid = GetPostString("ctid");
  3081. CeErpTradeCell entity = null;
  3082. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3083. if (entity != null)
  3084. {
  3085. if (entity.OrderState != 3)
  3086. {
  3087. returnErrorMsg("请刷新,订单已经设计了");
  3088. return;
  3089. }
  3090. entity.StartDesignTime = DateTime.Now;
  3091. entity.OrderState = 4;
  3092. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3093. {
  3094. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3095. entity.SupplierId = suid;
  3096. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3097. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3098. }
  3099. entity.UpdateTime = DateTime.Now;
  3100. //entity.MakeSupplier = suname;
  3101. entity.Update();
  3102. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3103. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3104. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3105. commonHelper.getCytPrice(entity);
  3106. returnSuccessMsg("操作成功!");
  3107. return;
  3108. }
  3109. returnErrorMsg("找不到记录");
  3110. }
  3111. }
  3112. public void ins_erp_designselfmemo()
  3113. {
  3114. if (UrlPostParmsCheck("ctid"))
  3115. {
  3116. string eid = GetPostString("ctid");
  3117. string con = GetPostString("con");
  3118. CeErpTradeCell entity = null;
  3119. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3120. if (entity != null)
  3121. {
  3122. entity.DesignSelfMemo = con;
  3123. entity.Update();
  3124. returnSuccessMsg("操作成功!");
  3125. return;
  3126. }
  3127. returnErrorMsg("找不到记录");
  3128. }
  3129. }
  3130. public void ins_erp_designprice()
  3131. {
  3132. if (UrlPostParmsCheck("ctid"))
  3133. {
  3134. string eid = GetPostString("ctid");
  3135. int uid = CurrentUser.UserID;
  3136. string userName = CurrentUser.UserName;
  3137. CeErpTradeCell entity = null;
  3138. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3139. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3140. if (entitys == null)
  3141. {
  3142. entitys = new CeErpDesignerBill();
  3143. }
  3144. if (entity != null)
  3145. {
  3146. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3147. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3148. entity.StartDesignTime = DateTime.Now;
  3149. entity.OrderState = 4;
  3150. string suname = "";
  3151. if (entity.SupplierId == 0)
  3152. {
  3153. int sid = commonHelper.autoDistributeToSupplier(entity);
  3154. entity.SupplierId = sid;
  3155. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3156. }
  3157. entity.Update();
  3158. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3159. if (ceErpUserPost != null)
  3160. {
  3161. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3162. if (ceErpPost != null)
  3163. {
  3164. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3165. {
  3166. entitys.tid = entity.ctid;
  3167. entitys.oid = entity.tid;
  3168. entitys.uid = uid;
  3169. entitys.userName = userName;
  3170. entitys.designerType = 1;
  3171. entitys.designerTypeText = "内部设计师";
  3172. entitys.price = Convert.ToDouble(GetPostString("price"));
  3173. entitys.designNum = GetPostInt("designNum");
  3174. entitys.modifyNum = GetPostInt("modifyNum");
  3175. entitys.designSize = GetPostString("designSize");
  3176. entitys.modifySize = GetPostString("modifySize");
  3177. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3178. {
  3179. entitys.create_time = DateTime.Now;
  3180. entitys.create_u_id = uid;
  3181. entitys.create_u_name = userName;
  3182. entitys.Save();
  3183. }
  3184. else
  3185. {
  3186. entitys.update_time = DateTime.Now;
  3187. entitys.update_u_id = uid;
  3188. entitys.update_u_name = userName;
  3189. entitys.Update();
  3190. }
  3191. }
  3192. }
  3193. }
  3194. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3195. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3196. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3197. if (suname != "")
  3198. {
  3199. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3200. }
  3201. commonHelper.getCytPrice(entity);
  3202. returnSuccessMsg("操作成功!");
  3203. return;
  3204. }
  3205. returnErrorMsg("找不到记录");
  3206. }
  3207. }
  3208. public void upload_erp_filecomplete()
  3209. {
  3210. if (UrlPostParmsCheck("ctid"))
  3211. {
  3212. string eid = GetPostString("ctid");
  3213. CeErpTradeCell entity = null;
  3214. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3215. if (entity != null)
  3216. {
  3217. entity.OrderState = 5; //设计完成
  3218. entity.Update();
  3219. returnSuccessMsg(eid + "上传成功,设计完成!");
  3220. return;
  3221. }
  3222. returnErrorMsg("找不到订单记录");
  3223. }
  3224. }
  3225. public void get_erp_designovertimelist()
  3226. {
  3227. DataStruct dStruct = GetPostStruct();
  3228. List<string> lw = new List<string>();
  3229. string tid = GetPostString("ctid");
  3230. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3231. string shopname = GetPostString("shopname");
  3232. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3233. string buyernick = GetPostString("buyer_nick");
  3234. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3235. string ResponsibleMan = GetPostString("responsible");
  3236. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3237. string date1 = GetPostString("date1");
  3238. string date2 = GetPostString("date2");
  3239. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3240. if (dw.Length > 0) lw.Add(dw);
  3241. string price1 = GetPostString("price1");
  3242. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3243. string price2 = GetPostString("price2");
  3244. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3245. string orderState = GetPostString("orderState");
  3246. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3247. string sellermemo = GetPostString("seller_memo");
  3248. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3249. lw.Add(string.Format("UnusualTag=3"));
  3250. lw.Add(string.Format("IsRefund<={0}", 1));
  3251. dStruct.Order = "WaitDesignTime desc";
  3252. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3253. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3254. writeGridDataTableJson(dStruct.TotalCount, dt);
  3255. }
  3256. //设计管理 获取抢单大厅列表
  3257. public void get_erp_grabinglist()
  3258. {
  3259. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3260. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3261. bool oldOrder = false;
  3262. if (org != null)
  3263. {
  3264. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3265. }
  3266. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3267. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3268. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3269. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3270. //先处理订单数据
  3271. if (dt.Rows.Count > 0)
  3272. {
  3273. Dictionary<string, int> design = null;
  3274. int count = 0;
  3275. foreach (DataRow row in dt.Rows)
  3276. {
  3277. if (map.ContainsKey(row["ShopId"].ToString()))
  3278. {
  3279. map.TryGetValue(row["ShopId"].ToString(), out design);
  3280. }
  3281. else
  3282. {
  3283. design = new Dictionary<string, int>();
  3284. }
  3285. if (design.ContainsKey(row["ProductId"].ToString()))
  3286. {
  3287. design.TryGetValue(row["ProductId"].ToString(), out count);
  3288. }
  3289. count++;
  3290. design[row["ProductId"].ToString()] = count;
  3291. map[row["ShopId"].ToString()] = design;
  3292. }
  3293. }
  3294. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3295. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3296. //把店铺排序和技能排序分类
  3297. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3298. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3299. if (design_dt.Rows.Count > 0)
  3300. {
  3301. Dictionary<string, string> design = null;
  3302. List<string> shopIds = null;
  3303. foreach (DataRow row in design_dt.Rows)
  3304. {
  3305. if ("0".Equals(row["designId"].ToString()))
  3306. {
  3307. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3308. {
  3309. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3310. }
  3311. else
  3312. {
  3313. shopIds = new List<string>();
  3314. }
  3315. shopIds.Add(row["shopId"].ToString());
  3316. shop_orders[row["orders"].ToString()] = shopIds;
  3317. }
  3318. else
  3319. {
  3320. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3321. {
  3322. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3323. }
  3324. else
  3325. {
  3326. design = new Dictionary<string, string>();
  3327. }
  3328. design[row["orders"].ToString()] = row["designId"].ToString();
  3329. design_orders[row["shopId"].ToString()] = design;
  3330. }
  3331. }
  3332. //处理成key value后根据key排序
  3333. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3334. foreach (List<string> val in shop_orders.Values)
  3335. {
  3336. if (val != null)
  3337. {
  3338. foreach (string key in val)
  3339. {
  3340. if (design_orders.ContainsKey(key.ToString()))
  3341. {
  3342. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3343. }
  3344. }
  3345. }
  3346. }
  3347. }
  3348. //校验哪个优先级有订单
  3349. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3350. foreach (string key in shop_orders.Keys)
  3351. {
  3352. List<string> ids = null;
  3353. shop_orders.TryGetValue(key, out ids);
  3354. //id为shopid
  3355. foreach (string id in ids)
  3356. {
  3357. Dictionary<string, int> list = null;
  3358. Dictionary<string, string> desing = null;
  3359. map.TryGetValue(id, out list);
  3360. design_orders.TryGetValue(id, out desing);
  3361. if (list != null && desing != null)
  3362. {
  3363. foreach (var item in desing)
  3364. {
  3365. int count = 0;
  3366. if (list.ContainsKey(item.Value))
  3367. {
  3368. list.TryGetValue(item.Value, out count);
  3369. if (count > 0)
  3370. {
  3371. designIds[id] = item.Value;
  3372. break;
  3373. }
  3374. }
  3375. }
  3376. }
  3377. }
  3378. if (designIds.Count > 0)
  3379. {
  3380. break;
  3381. }
  3382. }
  3383. DataTable table = new DataTable();
  3384. table.Columns.Add("tid", typeof(string));
  3385. table.Columns.Add("ctid", typeof(string));
  3386. table.Columns.Add("seller_nick", typeof(string));
  3387. table.Columns.Add("productName", typeof(string));
  3388. table.Columns.Add("pay_time", typeof(string));
  3389. table.Columns.Add("seller_memo", typeof(string));
  3390. if (designIds.Count > 0)
  3391. {
  3392. string shopId = "";
  3393. string productId = "";
  3394. foreach (var designInfo in designIds)
  3395. {
  3396. shopId = designInfo.Key;
  3397. productId = designInfo.Value;
  3398. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3399. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3400. if (dt.Rows.Count > 0)
  3401. {
  3402. foreach (DataRow row in dt.Rows)
  3403. {
  3404. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3405. {
  3406. DataRow data = table.NewRow();
  3407. data["ctid"] = row["ctid"].ToString();
  3408. data["tid"] = row["tid"].ToString();
  3409. data["seller_nick"] = ceErpShop.ShopName;
  3410. data["pay_time"] = row["pay_time"].ToString();
  3411. data["seller_memo"] = row["seller_memo"].ToString();
  3412. data["productName"] = ceErpProduct.PType;
  3413. table.Rows.Add(data);
  3414. }
  3415. }
  3416. }
  3417. }
  3418. }
  3419. writeGridDataTableJson(table.Rows.Count, table);
  3420. }
  3421. private object rushLockObject = new object();
  3422. public void set_erp_grabingorder()
  3423. {
  3424. if (UrlPostParmsCheck("ctid"))
  3425. {
  3426. int total = CurrentUser.User.Person.Total;
  3427. int userId = CurrentUser.User.ID;
  3428. int noFinish = CurrentUser.User.Person.NoFinish;
  3429. int finalization = CurrentUser.User.Person.Finalization;
  3430. string eids = GetPostString("ctid");
  3431. string key = "RushKey_" + userId;
  3432. int count = 0;
  3433. if (erpRedis.RedisHelper.KeyExists(key))
  3434. {
  3435. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3436. if (redisCount != null)
  3437. {
  3438. count = Convert.ToInt32(redisCount);
  3439. }
  3440. }
  3441. if (count >= total)
  3442. {
  3443. returnErrorMsg("半小时内已经抢" + total + "单");
  3444. return;
  3445. }
  3446. string[] ctidlist = eids.Split(',');
  3447. if (count + ctidlist.Length > total)
  3448. {
  3449. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3450. return;
  3451. }
  3452. int itag = 0;
  3453. lock (rushLockObject)
  3454. {
  3455. if (ctidlist.Length > 0)
  3456. {
  3457. string[] dtList = new string[ctidlist.Length];
  3458. for (int i = 0; i < ctidlist.Length; i++)
  3459. {
  3460. dtList[i] = "'" + ctidlist[i] + "'";
  3461. }
  3462. string sql_user = string.Format("select OrderState from CE_ErpTradeCell where DesignUserId = {0} and WaitDesignTime BETWEEN '{1}' and '{2}'", userId, DateTime.Now.ToString("yyyy-MM-dd 00:00:00"), DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  3463. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3464. if (dt_user.Rows.Count > 0)
  3465. {
  3466. int doing = 0;//未定稿
  3467. int finish = 0;//已完成
  3468. foreach (DataRow dr in dt_user.Rows)
  3469. {
  3470. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3471. {
  3472. doing++;
  3473. }
  3474. else
  3475. {
  3476. finish++;
  3477. }
  3478. }
  3479. if (doing >= noFinish)
  3480. {
  3481. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3482. return;
  3483. }
  3484. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3485. {
  3486. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3487. return;
  3488. }
  3489. }
  3490. //校验选择单子状态
  3491. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3492. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3493. if (dt.Rows.Count > 0)
  3494. {
  3495. List<string> list = new List<string>();
  3496. foreach (DataRow dr in dt.Rows)
  3497. {
  3498. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3499. {
  3500. list.Add(dr["ctid"].ToString());
  3501. }
  3502. }
  3503. if (list.Count > 0)
  3504. {
  3505. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3506. return;
  3507. }
  3508. }
  3509. foreach (string ctid in ctidlist)
  3510. {
  3511. CeErpTradeCell entity = null;
  3512. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3513. if (entity != null)
  3514. {
  3515. entity.OrderState = 3;
  3516. entity.DesignUserId = CurrentUser.UserID;
  3517. entity.WaitDesignTime = DateTime.Now;
  3518. entity.StartDesignTime = DateTime.Now;
  3519. entity.Update();
  3520. commonHelper.UpdateRelationOrder(entity.ctid);
  3521. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3522. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3523. itag++;
  3524. }
  3525. }
  3526. }
  3527. }
  3528. count += ctidlist.Length;
  3529. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3530. if (itag == 0)
  3531. returnErrorMsg("没有找到相关订单");
  3532. else
  3533. returnSuccessMsg("抢单成功!");
  3534. return;
  3535. }
  3536. }
  3537. public void get_erp_waitorderlist()
  3538. {
  3539. DataStruct dStruct = GetPostStruct();
  3540. List<string> lw = new List<string>();
  3541. string tid = GetPostString("ctid");
  3542. if (tid.Length > 0)
  3543. {
  3544. string select_tid = getTidByCtid(tid);
  3545. lw.Add(string.Format("tid='{0}'", select_tid));
  3546. }
  3547. string shopname = GetPostString("shopname");
  3548. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3549. string buyernick = GetPostString("buyer_nick");
  3550. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3551. string customer = GetPostString("customer");
  3552. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3553. string design = GetPostString("design");
  3554. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3555. string orderState = GetPostString("orderState");
  3556. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3557. string supplier = GetPostString("supplier");
  3558. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3559. string sellermemo = GetPostString("seller_memo");
  3560. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3561. string otherMemo = GetPostString("otherMemo");
  3562. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3563. string address = GetPostString("address");
  3564. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  3565. string date1 = GetPostString("date1");
  3566. string date2 = GetPostString("date2");
  3567. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3568. if (dw.Length > 0) lw.Add(dw);
  3569. string price1 = GetPostString("price1");
  3570. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3571. string price2 = GetPostString("price2");
  3572. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3573. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3574. lw.Add(string.Format("IsSample != 2 "));
  3575. lw.Add(string.Format("OrderState = 5 "));
  3576. lw.Add(string.Format("IsRefund<={0}", 1));
  3577. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3578. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3579. string pagesize = GetPostString("pagesize");
  3580. if (pagesize != null)
  3581. {
  3582. dStruct.PageSize = 200;
  3583. }
  3584. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3585. List<string> tids = new List<string>();
  3586. if (dt != null)
  3587. {
  3588. dt.Columns.Add("compenPrice", typeof(double));
  3589. foreach (DataRow dr in dt.Rows)
  3590. {
  3591. if (Convert.IsDBNull(dr["compenPrice"]))
  3592. {
  3593. dr["compenPrice"] = 0;
  3594. }
  3595. tids.Add("'" + dr["tid"].ToString() + "'");
  3596. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3597. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3598. {
  3599. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3600. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3601. entity.SupplierId = suid;
  3602. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3603. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3604. entity.Update();
  3605. }
  3606. }
  3607. }
  3608. if (tids.Count > 0)
  3609. {
  3610. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3611. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3612. if (dt_price != null && dt_price.Rows.Count > 0)
  3613. {
  3614. foreach (DataRow dr in dt_price.Rows)
  3615. {
  3616. foreach (DataRow row in dt.Rows)
  3617. {
  3618. if (row["tid"].Equals(dr["ptid"]))
  3619. {
  3620. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3621. break;
  3622. }
  3623. }
  3624. }
  3625. }
  3626. }
  3627. writeGridDataTableJson(dStruct.TotalCount, dt);
  3628. }
  3629. public void get_erp_supplierwaitorderlist()
  3630. {
  3631. DataStruct dStruct = GetPostStruct();
  3632. List<string> lw = new List<string>();
  3633. string tid = GetPostString("ctid");
  3634. if (tid.Length > 0)
  3635. {
  3636. string select_tid = getTidByCtid(tid);
  3637. lw.Add(string.Format("tid='{0}'", select_tid));
  3638. }
  3639. string shopname = GetPostString("shopname");
  3640. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3641. string sellermemo = GetPostString("seller_memo");
  3642. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3643. string date1 = GetPostString("date1");
  3644. string date2 = GetPostString("date2");
  3645. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3646. if (dw.Length > 0) lw.Add(dw);
  3647. lw.Add(string.Format("OrderState = 5 "));
  3648. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3649. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3650. {
  3651. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3652. }
  3653. string supplier = GetPostString("supplier");
  3654. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3655. {
  3656. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3657. }
  3658. lw.Add(string.Format("IsRefund<={0}", 1));
  3659. dStruct.Order = "FinishDesignTime desc";
  3660. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3661. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3662. if (dt != null)
  3663. {
  3664. foreach (DataRow dr in dt.Rows)
  3665. {
  3666. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3667. }
  3668. }
  3669. writeGridDataTableJson(dStruct.TotalCount, dt);
  3670. }
  3671. public void upd_erp_verifytosupplier()
  3672. {
  3673. if (UrlPostParmsCheck("ctid"))
  3674. {
  3675. string eids = GetPostString("ctid");
  3676. CeErpTradeCell entity = null;
  3677. string[] eidsList = eids.Split(',');
  3678. if (eidsList.Length <= 0)
  3679. {
  3680. returnErrorMsg("订单号不能空");
  3681. return;
  3682. }
  3683. List<string> tLst = new List<string>();
  3684. foreach (string ctidstr in eidsList)
  3685. {
  3686. tLst.Add("'" + ctidstr + "'");
  3687. CeErpDataSendOrderInfo.createObject(ctidstr);
  3688. }
  3689. string needtids = string.Join(",", tLst.ToArray());
  3690. StringBuilder sql = new StringBuilder();
  3691. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3692. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 AND OrderState = 5 and ctid in ({0});", needtids, CurrentUser.UserID);
  3693. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3694. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3695. returnSuccessMsg("操作成功!");
  3696. return;
  3697. /**foreach (string ctidstr in eidsList)
  3698. {
  3699. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3700. if (entity != null)
  3701. {
  3702. if (entity.SupplierId == 0)
  3703. {
  3704. continue;
  3705. }
  3706. entity.IsVerifyToSupplier = true;
  3707. if (entity.IsReturn == 1) //1是供应商打回
  3708. {
  3709. entity.IsReturn = 0;
  3710. }
  3711. entity.FinishPlaceTime = DateTime.Now;
  3712. entity.PlaceUserId = CurrentUser.UserID;
  3713. entity.Update();
  3714. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3715. }
  3716. }
  3717. returnSuccessMsg("操作成功!");
  3718. return;**/
  3719. }
  3720. }
  3721. public void upd_erp_supplierback()
  3722. {
  3723. if (UrlPostParmsCheck("ctid"))
  3724. {
  3725. string eid = GetPostString("ctid");
  3726. string reason = GetPostString("returnreason");
  3727. CeErpTradeCell entity = null;
  3728. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3729. if (entity != null)
  3730. {
  3731. string message = "操作成功!";
  3732. string isDown = "";
  3733. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3734. {
  3735. message = eid + "订单有被点击下载。请注意沟通是否已下载完!";
  3736. isDown = "被点击下载";
  3737. }
  3738. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3739. {
  3740. string key = "return_order_" + entity.SupplierId;
  3741. List<string> list = new List<string>();
  3742. if (RedisHelper.HasKey(key))
  3743. {
  3744. object data = RedisHelper.StringGet(key);
  3745. list = Convert.ToString(data).Split(',').ToList();
  3746. }
  3747. list.Add(eid);
  3748. RedisHelper.StringSet(key, string.Join(",", list));
  3749. }
  3750. entity.IsVerifyToSupplier = false;
  3751. entity.IsReturn = 1;
  3752. entity.IsHaveNewOrder = 0;
  3753. entity.ReturnTime = DateTime.Now;
  3754. entity.ReturnReason = reason;
  3755. if (entity.OrderState == 6)
  3756. {
  3757. entity.OrderState = 5;
  3758. }
  3759. entity.Update();
  3760. CeErpSukuraData.createInfo(entity.ctid, 5);
  3761. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3762. returnSuccessMsg(message);
  3763. return;
  3764. }
  3765. returnErrorMsg("找不到订单记录");
  3766. }
  3767. }
  3768. public void upd_erp_toaftersaleorder()
  3769. {
  3770. if (UrlPostParmsCheck("ctid"))
  3771. {
  3772. string eid = GetPostString("ctid");
  3773. string reason = GetPostString("returnreason");
  3774. CeErpTradeCell entity = null;
  3775. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3776. if (entity != null)
  3777. {
  3778. if (entity.isAfterSaleOrder != 1)
  3779. {
  3780. returnErrorMsg("带S的售后单才能打回给售后");
  3781. return;
  3782. }
  3783. if (entity.OrderState >= 5)
  3784. {
  3785. returnErrorMsg("已经设计完成了不能打回给售后");
  3786. return;
  3787. }
  3788. entity.OrderState = 0;
  3789. entity.IsReturn = 3;
  3790. entity.ReturnTime = DateTime.Now;
  3791. entity.UpdateTime = DateTime.Now;
  3792. entity.ReturnReason = reason;
  3793. entity.Update();
  3794. CeErpSukuraData.createInfo(entity.ctid, 5);
  3795. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3796. returnSuccessMsg("操作成功!");
  3797. return;
  3798. }
  3799. returnErrorMsg("找不到订单记录");
  3800. }
  3801. }
  3802. public void upd_erp_aftersaletodesign()
  3803. {
  3804. if (UrlPostParmsCheck("ctid"))
  3805. {
  3806. string eid = GetPostString("ctid");
  3807. CeErpTradeCell entity = null;
  3808. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3809. if (entity != null)
  3810. {
  3811. entity.OrderState = 3;
  3812. entity.IsReturn = 0;
  3813. entity.UpdateTime = DateTime.Now;
  3814. entity.Update();
  3815. CeErpSukuraData.createInfo(entity.ctid, 5);
  3816. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3817. returnSuccessMsg("操作成功!");
  3818. return;
  3819. }
  3820. returnErrorMsg("找不到订单记录");
  3821. }
  3822. }
  3823. public void assign_erp_supplier()
  3824. {
  3825. if (UrlPostParmsCheck("ctid"))
  3826. {
  3827. string eids = GetPostString("ctid");
  3828. int sid = GetPostInt("SupplierName");
  3829. string fromTag = GetPostString("tag");
  3830. string[] eidList = eids.Split(',');
  3831. if (eidList.Length <= 0)
  3832. {
  3833. returnErrorMsg("指派不能为空");
  3834. return;
  3835. }
  3836. string errMsg = "";
  3837. string suname = commonHelper.getSupplierNameById(sid);
  3838. foreach (string ctid in eidList)
  3839. {
  3840. CeErpTradeCell entity = null;
  3841. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3842. if (entity != null)
  3843. {
  3844. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3845. {
  3846. errMsg += (ctid + "指派失败!!!");
  3847. continue;
  3848. }
  3849. entity.SupplierId = sid;
  3850. entity.Update();
  3851. commonHelper.UpdateRelationOrder(entity.ctid);
  3852. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3853. if (entity.OrderState >= 6)
  3854. {
  3855. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3856. //{
  3857. // string msl = entity.MakeSupplier;
  3858. // string[] mslist = msl.Split(',');
  3859. // sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={2} where ID in (select top {1} ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, mslist.Length,sid);
  3860. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3861. //}
  3862. //else
  3863. //{
  3864. StringBuilder sql = new StringBuilder();
  3865. sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={1},MakeSupplier='{2}' where ID in (select top 1 ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, sid, entity.MakeSupplier);
  3866. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3867. //}
  3868. }
  3869. }
  3870. else
  3871. {
  3872. continue;
  3873. }
  3874. }
  3875. if (errMsg.Length > 0)
  3876. {
  3877. returnErrorMsg(errMsg);
  3878. return;
  3879. }
  3880. returnSuccessMsg("操作成功!");
  3881. return;
  3882. }
  3883. }
  3884. public void assign_erp_makesupplier()
  3885. {
  3886. if (UrlPostParmsCheck("ctid"))
  3887. {
  3888. string eids = GetPostString("ctid");
  3889. string sname = GetPostString("SupplierName");
  3890. string[] eidList = eids.Split(',');
  3891. if (eidList.Length <= 0)
  3892. {
  3893. returnErrorMsg("指派不能为空");
  3894. return;
  3895. }
  3896. List<string> tLst = new List<string>();
  3897. foreach (string ctid in eidList)
  3898. {
  3899. CeErpTradeCell entity = null;
  3900. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3901. if (entity != null)
  3902. {
  3903. entity.MakeSupplier = sname;
  3904. entity.Update();
  3905. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3906. tLst.Add("'" + ctid + "'");
  3907. }
  3908. else
  3909. {
  3910. continue;
  3911. }
  3912. }
  3913. string ctids = string.Join(",", tLst.ToArray());
  3914. StringBuilder sql2 = new StringBuilder();
  3915. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3916. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3917. returnSuccessMsg("操作成功!");
  3918. return;
  3919. }
  3920. }
  3921. public void ins_erp_returnreason()
  3922. {
  3923. if (UrlPostParmsCheck("ctid"))
  3924. {
  3925. string eid = GetPostString("ctid");
  3926. CeErpTradeCell entity = null;
  3927. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3928. string userpost = CurrentUser.UserPost.Post.Code;
  3929. if (entity != null)
  3930. {
  3931. bool isPlace = false;
  3932. if (entity.OrderState > 6)
  3933. {
  3934. returnErrorMsg("已发货无法打回!");
  3935. return;
  3936. }
  3937. if (entity.OrderState == 6)
  3938. {
  3939. isPlace = true;
  3940. }
  3941. bool isNeedUpdateCell2 = false;
  3942. if (entity.OrderState >= 6)
  3943. {
  3944. isNeedUpdateCell2 = true;
  3945. }
  3946. int returnTag = 2;
  3947. if (userpost == "Supplier")
  3948. {
  3949. returnTag = 1;
  3950. }
  3951. int toType = GetPostInt("totype");
  3952. string fromType = "3";
  3953. if (entity.OrderState < 5)
  3954. {
  3955. fromType = "3";
  3956. }
  3957. else
  3958. {
  3959. fromType = "4";
  3960. }
  3961. if (entity.IsXianHuo == 0)
  3962. {
  3963. if (returnTag == 2)
  3964. {
  3965. if (toType == 1)
  3966. {
  3967. entity.OrderState = 0;
  3968. entity.ReturnUserType = 1;
  3969. string clearman = GetPostString("clearman");
  3970. if (!string.IsNullOrEmpty(clearman))
  3971. {
  3972. entity.DesignUserId = 0;
  3973. }
  3974. }
  3975. else
  3976. {
  3977. entity.OrderState = 3;
  3978. entity.ReturnUserType = 2;
  3979. }
  3980. entity.IsReadTag = 1;
  3981. }
  3982. else if (returnTag == 1)
  3983. {
  3984. entity.OrderState = 5;
  3985. }
  3986. entity.IsVerifyToSupplier = false;
  3987. }
  3988. if (entity.IsXianHuo == 1)
  3989. {
  3990. entity.OrderState = 5;
  3991. }
  3992. entity.UnusualTag = 0;
  3993. entity.UnusualTime = null;
  3994. entity.UnusualCon = "";
  3995. entity.IsReturn = returnTag;
  3996. entity.ReturnTime = DateTime.Now;
  3997. entity.UpdateTime = DateTime.Now;
  3998. entity.IsHaveNewOrder = 0;
  3999. entity.ReturnReason = GetPostString("returnreason");
  4000. entity.Update();
  4001. if (entity.OrderState == 3)
  4002. {
  4003. ApiVo apiVo = new ApiVo();
  4004. apiVo.orderNumber = entity.ctid;
  4005. apiVo.actionName = "rebutDesign";
  4006. apiVo.orderRemarks = entity.ReturnReason;
  4007. designHelper.API_WorkCore(apiVo);//rebutDesign
  4008. }
  4009. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  4010. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  4011. {
  4012. //dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  4013. }
  4014. //CeErpSukuraData.createInfo(entity.ctid, 5);
  4015. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4016. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4017. if (isPlace)
  4018. {
  4019. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4020. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4021. if (dth != null && dth.Rows.Count > 0)
  4022. {
  4023. dataSendOrderBean dataSendOrderBean = null;
  4024. foreach (DataRow item in dth.Rows)
  4025. {
  4026. try
  4027. {
  4028. dataSendOrderBean = new dataSendOrderBean();
  4029. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4030. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4031. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4032. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4033. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4034. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4035. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4036. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4037. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4038. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4039. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4040. dataSendOrderBean.Radio1723534706288 = "打回";
  4041. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4042. if (result != null)
  4043. {
  4044. if ("0".Equals(result.errcode))
  4045. {
  4046. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4047. }
  4048. else
  4049. {
  4050. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4051. }
  4052. }
  4053. }
  4054. catch (Exception ex)
  4055. {
  4056. }
  4057. }
  4058. }
  4059. }
  4060. returnSuccessMsg("操作成功!");
  4061. return;
  4062. }
  4063. returnErrorMsg("找不到订单记录");
  4064. }
  4065. }
  4066. public void batch_ins_erp_returnreason()
  4067. {
  4068. if (UrlPostParmsCheck("ctids"))
  4069. {
  4070. string ctids = GetPostString("ctids");
  4071. if (!string.IsNullOrEmpty(ctids))
  4072. {
  4073. List<string> ctid_list = ctids.Split(',').ToList();
  4074. CeErpTradeCell entity = null;
  4075. List<string> message_list = new List<string>();
  4076. foreach (string eid in ctid_list)
  4077. {
  4078. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4079. string userpost = CurrentUser.UserPost.Post.Code;
  4080. if (entity != null)
  4081. {
  4082. bool isPlace = false;
  4083. if (entity.OrderState > 6)
  4084. {
  4085. message_list.Add(eid + ":已发货无法打回!");
  4086. continue;
  4087. }
  4088. if (entity.OrderState == 6)
  4089. {
  4090. isPlace = true;
  4091. }
  4092. bool isNeedUpdateCell2 = false;
  4093. if (entity.OrderState >= 6)
  4094. {
  4095. isNeedUpdateCell2 = true;
  4096. }
  4097. int returnTag = 2;
  4098. if (userpost == "Supplier")
  4099. {
  4100. returnTag = 1;
  4101. }
  4102. int toType = GetPostInt("totype");
  4103. string fromType = "3";
  4104. if (entity.OrderState < 5)
  4105. {
  4106. fromType = "3";
  4107. }
  4108. else
  4109. {
  4110. fromType = "4";
  4111. }
  4112. if (entity.IsXianHuo == 0)
  4113. {
  4114. if (returnTag == 2)
  4115. {
  4116. if (toType == 1)
  4117. {
  4118. entity.OrderState = 0;
  4119. entity.ReturnUserType = 1;
  4120. string clearman = GetPostString("clearman");
  4121. if (!string.IsNullOrEmpty(clearman))
  4122. {
  4123. entity.DesignUserId = 0;
  4124. }
  4125. }
  4126. else
  4127. {
  4128. entity.OrderState = 3;
  4129. entity.ReturnUserType = 2;
  4130. }
  4131. entity.IsReadTag = 1;
  4132. }
  4133. else if (returnTag == 1)
  4134. {
  4135. entity.OrderState = 5;
  4136. }
  4137. entity.IsVerifyToSupplier = false;
  4138. }
  4139. if (entity.IsXianHuo == 1)
  4140. {
  4141. entity.OrderState = 5;
  4142. }
  4143. entity.UnusualTag = 0;
  4144. entity.UnusualTime = null;
  4145. entity.UnusualCon = "";
  4146. entity.IsReturn = returnTag;
  4147. entity.ReturnTime = DateTime.Now;
  4148. entity.UpdateTime = DateTime.Now;
  4149. entity.IsHaveNewOrder = 0;
  4150. entity.ReturnReason = GetPostString("returnreason");
  4151. entity.Update();
  4152. if (entity.OrderState == 3)
  4153. {
  4154. ApiVo apiVo = new ApiVo();
  4155. apiVo.orderNumber = entity.ctid;
  4156. apiVo.actionName = "rebutDesign";
  4157. apiVo.orderRemarks = entity.ReturnReason;
  4158. designHelper.API_WorkCore(apiVo);//rebutDesign
  4159. }
  4160. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  4161. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  4162. {
  4163. //dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  4164. }
  4165. //CeErpSukuraData.createInfo(entity.ctid, 5);
  4166. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4167. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4168. if (isPlace)
  4169. {
  4170. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4171. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4172. if (dth != null && dth.Rows.Count > 0)
  4173. {
  4174. dataSendOrderBean dataSendOrderBean = null;
  4175. foreach (DataRow item in dth.Rows)
  4176. {
  4177. try
  4178. {
  4179. dataSendOrderBean = new dataSendOrderBean();
  4180. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4181. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4182. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4183. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4184. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4185. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4186. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4187. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4188. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4189. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4190. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4191. dataSendOrderBean.Radio1723534706288 = "打回";
  4192. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4193. if (result != null)
  4194. {
  4195. if ("0".Equals(result.errcode))
  4196. {
  4197. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4198. }
  4199. else
  4200. {
  4201. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4202. }
  4203. }
  4204. }
  4205. catch (Exception ex)
  4206. {
  4207. }
  4208. }
  4209. }
  4210. }
  4211. }
  4212. }
  4213. returnSuccessMsg(message_list.Count > 0 ? string.Join("、", message_list) : "操作成功");
  4214. return;
  4215. }
  4216. returnErrorMsg("找不到订单记录");
  4217. }
  4218. }
  4219. public void cyt_erp_returnreason()
  4220. {
  4221. if (UrlPostParmsCheck("ctid"))
  4222. {
  4223. string eid = GetPostString("ctid");
  4224. CeErpTradeCell entity = null;
  4225. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4226. string userpost = CurrentUser.UserPost.Post.Code;
  4227. if (entity != null)
  4228. {
  4229. if (entity.OrderState > 6)
  4230. {
  4231. returnErrorMsg("已发货无法打回!");
  4232. return;
  4233. }
  4234. JObject jsonObject = new JObject
  4235. {
  4236. { "Userid", "77886" },
  4237. { "Pwd", "lt666888" },
  4238. { "LTOrderId",eid }
  4239. };
  4240. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4241. JObject jsonObjects = JObject.Parse(response);
  4242. string msg = (string)jsonObjects["msg"];
  4243. if (msg != "取消成功")
  4244. {
  4245. returnErrorMsg(msg);
  4246. return;
  4247. }
  4248. bool isNeedUpdateCell2 = false;
  4249. if (entity.OrderState >= 6)
  4250. {
  4251. isNeedUpdateCell2 = true;
  4252. }
  4253. int returnTag = 2;
  4254. if (userpost == "Supplier")
  4255. {
  4256. returnTag = 1;
  4257. }
  4258. if (entity.IsXianHuo == 0)
  4259. {
  4260. if (returnTag == 2)
  4261. {
  4262. int toType = GetPostInt("totype");
  4263. if (toType == 1)
  4264. {
  4265. entity.OrderState = 0;
  4266. entity.ReturnUserType = 1;
  4267. }
  4268. else
  4269. {
  4270. entity.OrderState = 4;
  4271. entity.ReturnUserType = 2;
  4272. }
  4273. entity.IsReadTag = 1;
  4274. }
  4275. else if (returnTag == 1)
  4276. {
  4277. entity.OrderState = 5;
  4278. }
  4279. entity.IsVerifyToSupplier = false;
  4280. }
  4281. entity.UnusualTag = 0;
  4282. entity.UnusualTime = null;
  4283. entity.UnusualCon = "";
  4284. entity.IsReturn = returnTag;
  4285. entity.ReturnTime = DateTime.Now;
  4286. entity.IsHaveNewOrder = 0;
  4287. entity.ReturnReason = GetPostString("returnreason");
  4288. entity.Update();
  4289. if (entity.OrderState == 4)
  4290. {
  4291. ApiVo apiVo = new ApiVo();
  4292. apiVo.orderNumber = entity.ctid;
  4293. apiVo.actionName = "rebutDesign";
  4294. apiVo.orderRemarks = entity.ReturnReason;
  4295. designHelper.API_WorkCore(apiVo);//rebutDesign
  4296. }
  4297. CeErpSukuraData.createInfo(entity.ctid, 5);
  4298. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4299. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4300. if (isNeedUpdateCell2)
  4301. {
  4302. if (entity.MakeSupplier.IndexOf(",") != -1)
  4303. {
  4304. StringBuilder sql2 = new StringBuilder();
  4305. 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);
  4306. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4307. }
  4308. else
  4309. {
  4310. StringBuilder sql2 = new StringBuilder();
  4311. 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);
  4312. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4313. }
  4314. }
  4315. returnSuccessMsg("操作成功!");
  4316. return;
  4317. }
  4318. returnErrorMsg("找不到订单记录");
  4319. }
  4320. }
  4321. public void upd_erp_xianhuoreturntag()
  4322. {
  4323. if (UrlPostParmsCheck("ctid"))
  4324. {
  4325. string eids = GetPostString("ctid");
  4326. string[] ctids = eids.Split(',');
  4327. foreach (string ctid in ctids)
  4328. {
  4329. CeErpTradeCell entity = null;
  4330. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4331. if (entity != null)
  4332. {
  4333. entity.IsReturn = 0;
  4334. entity.Update();
  4335. CeErpSukuraData.createInfo(entity.ctid, 5);
  4336. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4337. }
  4338. }
  4339. returnSuccessMsg("操作成功!");
  4340. return;
  4341. }
  4342. }
  4343. public void get_erp_waitdeliverylist()
  4344. {
  4345. DataStruct dStruct = GetPostStruct();
  4346. List<string> lw = new List<string>();
  4347. string tid = GetPostString("ctid");
  4348. if (tid.Length > 0)
  4349. {
  4350. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4351. if (tid.Length > 5)
  4352. {
  4353. List<string> tids = getTidByCtidLike(tid);
  4354. if (tids.Count > 0 && tids.Count < 10)
  4355. {
  4356. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4357. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4358. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4359. {
  4360. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4361. }*/
  4362. }
  4363. }
  4364. lw.Add(tid_sql);
  4365. }
  4366. string shopname = GetPostString("shopname");
  4367. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4368. string buyernick = GetPostString("buyer_nick");
  4369. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4370. //if (tid.Length == 0 && buyernick.Length == 0)
  4371. //{
  4372. // lw.Add(string.Format("IsRefund<={0}", 1));
  4373. //}
  4374. string customer = GetPostString("customer");
  4375. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4376. string design = GetPostString("design");
  4377. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4378. string orderState = GetPostString("orderState");
  4379. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4380. string address = GetPostString("address");
  4381. 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));
  4382. string sellermemo = GetPostString("seller_memo");
  4383. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4384. string supplier = GetPostString("supplier");
  4385. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4386. string OrderArea = GetPostString("order_area");
  4387. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4388. string placedate1 = GetPostString("placedate1");
  4389. string placedate2 = GetPostString("placedate2");
  4390. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4391. if (fdw.Length > 0) lw.Add(fdw);
  4392. string price1 = GetPostString("price1");
  4393. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4394. string price2 = GetPostString("price2");
  4395. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4396. string unusualCon = GetPostString("unusualcon");
  4397. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4398. string otherMemo = GetPostString("otherMemo");
  4399. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4400. string posTag = CurrentUser.UserPost.Post.Code;
  4401. if (posTag == "Supplier")
  4402. {
  4403. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4404. }
  4405. else
  4406. {
  4407. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4408. {
  4409. string usershop = CurrentUser.User.pemShop;
  4410. lw.Add(string.Format("ShopId in ({0})", usershop));
  4411. }
  4412. }
  4413. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4414. lw.Add(string.Format("type != 'PDD' "));
  4415. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4416. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4417. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4418. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4419. writeGridDataTableJson(dStruct.TotalCount, dt);
  4420. }
  4421. public void get_erp_changedeliverylist()
  4422. {
  4423. DataStruct dStruct = GetPostStruct();
  4424. List<string> lw = new List<string>();
  4425. string tid = GetPostString("ctid");
  4426. if (tid.Length > 0)
  4427. {
  4428. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4429. if (tid.Length > 5)
  4430. {
  4431. List<string> tids = getTidByCtidLike(tid);
  4432. if (tids.Count > 0 && tids.Count < 10)
  4433. {
  4434. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4435. }
  4436. }
  4437. lw.Add(tid_sql);
  4438. }
  4439. string shopname = GetPostString("shopname");
  4440. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4441. string buyernick = GetPostString("buyer_nick");
  4442. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4443. //if (tid.Length == 0 && buyernick.Length == 0)
  4444. //{
  4445. // lw.Add(string.Format("IsRefund<={0}", 1));
  4446. //}
  4447. string customer = GetPostString("customer");
  4448. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4449. string design = GetPostString("design");
  4450. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4451. string orderState = GetPostString("orderState");
  4452. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4453. string address = GetPostString("address");
  4454. 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));
  4455. string sellermemo = GetPostString("seller_memo");
  4456. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4457. string supplier = GetPostString("supplier");
  4458. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4459. string OrderArea = GetPostString("order_area");
  4460. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4461. string placedate1 = GetPostString("placedate1");
  4462. string placedate2 = GetPostString("placedate2");
  4463. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4464. if (fdw.Length > 0) lw.Add(fdw);
  4465. string price1 = GetPostString("price1");
  4466. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4467. string price2 = GetPostString("price2");
  4468. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4469. string unusualCon = GetPostString("unusualcon");
  4470. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4471. string otherMemo = GetPostString("otherMemo");
  4472. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4473. string posTag = CurrentUser.UserPost.Post.Code;
  4474. if (posTag == "Supplier")
  4475. {
  4476. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4477. }
  4478. else
  4479. {
  4480. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4481. {
  4482. string usershop = CurrentUser.User.pemShop;
  4483. lw.Add(string.Format("ShopId in ({0})", usershop));
  4484. }
  4485. }
  4486. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4487. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4488. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4489. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4490. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4491. /*if (tid.Length > 0)
  4492. {
  4493. List<string> tids = new List<string>();
  4494. if (dt != null && dt.Rows.Count > 0)
  4495. {
  4496. foreach (DataRow item in dt.Rows)
  4497. {
  4498. tids.Add("'" + item["tid"] + "'");
  4499. }
  4500. }
  4501. if (tids.Count > 0)
  4502. {
  4503. lw.RemoveAt(0);
  4504. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4505. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4506. dt = WebCache.GetData("view_erptradecell", dStruct);
  4507. }
  4508. }*/
  4509. writeGridDataTableJson(dStruct.TotalCount, dt);
  4510. }
  4511. public void get_erp_pddderiving()
  4512. {
  4513. DataStruct dStruct = GetPostStruct();
  4514. List<string> lw = new List<string>();
  4515. string tid = GetPostString("ctid");
  4516. if (tid.Length > 0)
  4517. {
  4518. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4519. if (tid.Length > 5)
  4520. {
  4521. List<string> tids = getTidByCtidLike(tid);
  4522. if (tids.Count > 0 && tids.Count < 10)
  4523. {
  4524. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4525. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4526. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4527. {
  4528. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4529. }*/
  4530. }
  4531. }
  4532. lw.Add(tid_sql);
  4533. }
  4534. string shopname = GetPostString("shopname");
  4535. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4536. string buyernick = GetPostString("buyer_nick");
  4537. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4538. //if (tid.Length == 0 && buyernick.Length == 0)
  4539. //{
  4540. // lw.Add(string.Format("IsRefund<={0}", 1));
  4541. //}
  4542. string customer = GetPostString("customer");
  4543. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4544. string design = GetPostString("design");
  4545. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4546. string orderState = GetPostString("orderState");
  4547. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4548. string address = GetPostString("address");
  4549. 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));
  4550. string sellermemo = GetPostString("seller_memo");
  4551. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4552. string supplier = GetPostString("supplier");
  4553. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4554. string OrderArea = GetPostString("order_area");
  4555. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4556. string placedate1 = GetPostString("placedate1");
  4557. string placedate2 = GetPostString("placedate2");
  4558. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4559. if (fdw.Length > 0) lw.Add(fdw);
  4560. string price1 = GetPostString("price1");
  4561. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4562. string price2 = GetPostString("price2");
  4563. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4564. string unusualCon = GetPostString("unusualcon");
  4565. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4566. string posTag = CurrentUser.UserPost.Post.Code;
  4567. if (posTag == "Supplier")
  4568. {
  4569. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4570. }
  4571. else
  4572. {
  4573. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4574. {
  4575. string usershop = CurrentUser.User.pemShop;
  4576. lw.Add(string.Format("ShopId in ({0})", usershop));
  4577. }
  4578. }
  4579. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4580. lw.Add(string.Format("type = 'PDD' "));
  4581. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4582. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4583. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4584. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4585. /*if (tid.Length > 0)
  4586. {
  4587. List<string> tids = new List<string>();
  4588. if (dt != null && dt.Rows.Count > 0)
  4589. {
  4590. foreach (DataRow item in dt.Rows)
  4591. {
  4592. tids.Add("'" + item["tid"] + "'");
  4593. }
  4594. }
  4595. if (tids.Count > 0)
  4596. {
  4597. lw.RemoveAt(0);
  4598. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4599. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4600. dt = WebCache.GetData("view_erptradecell", dStruct);
  4601. }
  4602. }*/
  4603. writeGridDataTableJson(dStruct.TotalCount, dt);
  4604. }
  4605. public void get_erp_jdderiving()
  4606. {
  4607. DataStruct dStruct = GetPostStruct();
  4608. List<string> lw = new List<string>();
  4609. string tid = GetPostString("ctid");
  4610. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4611. string shopname = GetPostString("shopname");
  4612. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4613. string buyernick = GetPostString("buyer_nick");
  4614. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4615. //if (tid.Length == 0 && buyernick.Length == 0)
  4616. //{
  4617. // lw.Add(string.Format("IsRefund<={0}", 1));
  4618. //}
  4619. string customer = GetPostString("customer");
  4620. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4621. string design = GetPostString("design");
  4622. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4623. string orderState = GetPostString("orderState");
  4624. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4625. string address = GetPostString("address");
  4626. 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));
  4627. string sellermemo = GetPostString("seller_memo");
  4628. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4629. string supplier = GetPostString("supplier");
  4630. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4631. string OrderArea = GetPostString("order_area");
  4632. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4633. string placedate1 = GetPostString("placedate1");
  4634. string placedate2 = GetPostString("placedate2");
  4635. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4636. if (fdw.Length > 0) lw.Add(fdw);
  4637. string price1 = GetPostString("price1");
  4638. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4639. string price2 = GetPostString("price2");
  4640. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4641. string unusualCon = GetPostString("unusualcon");
  4642. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4643. string posTag = CurrentUser.UserPost.Post.Code;
  4644. if (posTag == "Supplier")
  4645. {
  4646. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4647. }
  4648. lw.Add(string.Format("OrderState = 6 "));
  4649. lw.Add(string.Format("type = 'JD' "));
  4650. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4651. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4652. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4653. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4654. writeGridDataTableJson(dStruct.TotalCount, dt);
  4655. }
  4656. public void get_erp_demoorderlist()
  4657. {
  4658. DataStruct dStruct = GetPostStruct();
  4659. List<string> lw = new List<string>();
  4660. string tid = GetPostString("ctid");
  4661. if (tid.Length > 0)
  4662. {
  4663. string select_tid = getTidByCtid(tid);
  4664. lw.Add(string.Format("tid='{0}'", select_tid));
  4665. }
  4666. string shopname = GetPostString("shopname");
  4667. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4668. string buyernick = GetPostString("buyer_nick");
  4669. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4670. string customer = GetPostString("customer");
  4671. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4672. string design = GetPostString("design");
  4673. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4674. string orderState = GetPostString("orderState");
  4675. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4676. string address = GetPostString("address");
  4677. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4678. string sellermemo = GetPostString("seller_memo");
  4679. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4680. string supplier = GetPostString("supplier");
  4681. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4682. string OrderArea = GetPostString("order_area");
  4683. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4684. string date1 = GetPostString("date1");
  4685. string date2 = GetPostString("date2");
  4686. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4687. if (dw.Length > 0) lw.Add(dw);
  4688. string price1 = GetPostString("price1");
  4689. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4690. string price2 = GetPostString("price2");
  4691. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4692. string posTag = CurrentUser.UserPost.Post.Code;
  4693. if (posTag == "Supplier")
  4694. {
  4695. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4696. }
  4697. //lw.Add(string.Format("OrderState = 6 "));
  4698. lw.Add(string.Format("IsSample={0}", 3));
  4699. lw.Add(string.Format("IsRefund<={0}", 1));
  4700. dStruct.Order = "pay_time desc";
  4701. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4702. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4703. writeGridDataTableJson(dStruct.TotalCount, dt);
  4704. }
  4705. public void save_erp_checkmemo()
  4706. {
  4707. if (UrlPostParmsCheck("ctid"))
  4708. {
  4709. string ctid = GetPostString("ctid");
  4710. CeErpTradeCell entity = null;
  4711. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4712. if (entity != null)
  4713. {
  4714. entity.CheckMemo = GetPostString("CheckMemo");
  4715. entity.Update();
  4716. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4717. if (trade != null)
  4718. {
  4719. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4720. }
  4721. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4722. returnSuccessMsg("保存成功!");
  4723. return;
  4724. }
  4725. returnErrorMsg("找不到记录");
  4726. }
  4727. }
  4728. public void get_erp_returnlist()
  4729. {
  4730. DataStruct dStruct = GetPostStruct();
  4731. List<string> lw = new List<string>();
  4732. string tid = GetPostString("ctid");
  4733. if (tid.Length > 0)
  4734. {
  4735. string select_tid = getTidByCtid(tid);
  4736. lw.Add(string.Format("tid='{0}'", select_tid));
  4737. }
  4738. string shopname = GetPostString("shopname");
  4739. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4740. string buyernick = GetPostString("buyer_nick");
  4741. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4742. string customer = GetPostString("customer");
  4743. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4744. string design = GetPostString("design");
  4745. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4746. string orderState = GetPostString("orderState");
  4747. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4748. string address = GetPostString("address");
  4749. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4750. string sellermemo = GetPostString("seller_memo");
  4751. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4752. string supplier = GetPostString("supplier");
  4753. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4754. string date1 = GetPostString("date1");
  4755. string date2 = GetPostString("date2");
  4756. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4757. if (dw.Length > 0) lw.Add(dw);
  4758. string bdate1 = GetPostString("backdate1");
  4759. string bdate2 = GetPostString("backdate2");
  4760. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4761. if (dw_back.Length > 0) lw.Add(dw_back);
  4762. string price1 = GetPostString("price1");
  4763. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4764. string price2 = GetPostString("price2");
  4765. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4766. lw.Add(string.Format("IsReturn>0"));
  4767. lw.Add(string.Format("IsXianHuo=0"));
  4768. lw.Add(string.Format("IsReturn!=3"));
  4769. string backtype = GetPostString("backtype");
  4770. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4771. dStruct.Order = "FinishDesignTime desc";
  4772. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4773. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4774. writeGridDataTableJson(dStruct.TotalCount, dt);
  4775. }
  4776. public void get_erp_today_sumreturn()
  4777. {
  4778. DataStruct dStruct = GetPostStruct();
  4779. List<string> lw = new List<string>();
  4780. string bdate1 = GetPostString("returnTimeS");
  4781. string bdate2 = GetPostString("returnTimeE");
  4782. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4783. if (dw_back.Length > 0) lw.Add(dw_back);
  4784. lw.Add(string.Format("IsReturn=0"));
  4785. lw.Add(string.Format("IsXianHuo=0"));
  4786. string mainWhere = string.Join(" and ", lw.ToArray());
  4787. string sql = "";
  4788. if (dw_back.Length > 0)
  4789. {
  4790. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4791. }
  4792. else
  4793. {
  4794. 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 + "'";
  4795. }
  4796. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4797. decimal total = 0, today_finish = 0;
  4798. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4799. {
  4800. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4801. }
  4802. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4803. {
  4804. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4805. }
  4806. var res = new
  4807. {
  4808. data = total,
  4809. data1 = today_finish,
  4810. };
  4811. string ro_jsond = JsonConvert.SerializeObject(res);
  4812. returnSuccess(ro_jsond);
  4813. return;
  4814. }
  4815. public void get_erp_allreturnlist()
  4816. {
  4817. DataStruct dStruct = GetPostStruct();
  4818. List<string> lw = new List<string>();
  4819. string tid = GetPostString("ctid");
  4820. if (tid.Length > 0)
  4821. {
  4822. string select_tid = getTidByCtid(tid);
  4823. lw.Add(string.Format("tid='{0}'", select_tid));
  4824. }
  4825. string shopname = GetPostString("shopname");
  4826. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4827. string buyernick = GetPostString("buyer_nick");
  4828. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4829. string customer = GetPostString("customer");
  4830. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4831. string design = GetPostString("design");
  4832. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4833. string orderState = GetPostString("orderState");
  4834. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4835. string address = GetPostString("address");
  4836. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4837. string sellermemo = GetPostString("seller_memo");
  4838. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4839. string supplier = GetPostString("supplier");
  4840. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4841. string date1 = GetPostString("date1");
  4842. string date2 = GetPostString("date2");
  4843. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4844. if (dw.Length > 0) lw.Add(dw);
  4845. string bdate1 = GetPostString("backdate1");
  4846. string bdate2 = GetPostString("backdate2");
  4847. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4848. if (dw_back.Length > 0) lw.Add(dw_back);
  4849. string price1 = GetPostString("price1");
  4850. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4851. string price2 = GetPostString("price2");
  4852. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4853. string backreason = GetPostString("backreason");
  4854. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4855. lw.Add(string.Format("IsXianHuo=0"));
  4856. lw.Add(string.Format("ReturnTime != ''"));
  4857. string backtype = GetPostString("backtype");
  4858. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4859. string posTag = CurrentUser.UserPost.Post.Code;
  4860. if (posTag == "Supplier")
  4861. {
  4862. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4863. }
  4864. else
  4865. {
  4866. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4867. {
  4868. string usershop = CurrentUser.User.pemShop;
  4869. lw.Add(string.Format("ShopId in ({0})", usershop));
  4870. }
  4871. }
  4872. dStruct.Order = "FinishDesignTime desc";
  4873. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4874. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4875. writeGridDataTableJson(dStruct.TotalCount, dt);
  4876. }
  4877. public void get_erp_aftersalereturnlist()
  4878. {
  4879. DataStruct dStruct = GetPostStruct();
  4880. List<string> lw = new List<string>();
  4881. string tid = GetPostString("ctid");
  4882. if (tid.Length > 0)
  4883. {
  4884. string select_tid = getTidByCtid(tid);
  4885. lw.Add(string.Format("tid='{0}'", select_tid));
  4886. }
  4887. string shopname = GetPostString("shopname");
  4888. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4889. string buyernick = GetPostString("buyer_nick");
  4890. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4891. string customer = GetPostString("customer");
  4892. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4893. string design = GetPostString("design");
  4894. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4895. string orderState = GetPostString("orderState");
  4896. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4897. string address = GetPostString("address");
  4898. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4899. string sellermemo = GetPostString("seller_memo");
  4900. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4901. string supplier = GetPostString("supplier");
  4902. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4903. string date1 = GetPostString("date1");
  4904. string date2 = GetPostString("date2");
  4905. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4906. if (dw.Length > 0) lw.Add(dw);
  4907. string bdate1 = GetPostString("backdate1");
  4908. string bdate2 = GetPostString("backdate2");
  4909. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4910. if (dw_back.Length > 0) lw.Add(dw_back);
  4911. string price1 = GetPostString("price1");
  4912. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4913. string price2 = GetPostString("price2");
  4914. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4915. lw.Add(string.Format("IsReturn=3"));
  4916. string backtype = GetPostString("backtype");
  4917. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4918. string backreason = GetPostString("backreason");
  4919. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4920. dStruct.Order = "ReturnTime desc";
  4921. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4922. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4923. writeGridDataTableJson(dStruct.TotalCount, dt);
  4924. }
  4925. public void get_erp_xianhuoreturnlist()
  4926. {
  4927. DataStruct dStruct = GetPostStruct();
  4928. List<string> lw = new List<string>();
  4929. string tid = GetPostString("ctid");
  4930. if (tid.Length > 0)
  4931. {
  4932. string select_tid = getTidByCtid(tid);
  4933. lw.Add(string.Format("tid='{0}'", select_tid));
  4934. }
  4935. string shopname = GetPostString("shopname");
  4936. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4937. string buyernick = GetPostString("buyer_nick");
  4938. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4939. string customer = GetPostString("customer");
  4940. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4941. string design = GetPostString("design");
  4942. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4943. string orderState = GetPostString("orderState");
  4944. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4945. string address = GetPostString("address");
  4946. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4947. string sellermemo = GetPostString("seller_memo");
  4948. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4949. string supplier = GetPostString("supplier");
  4950. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4951. string OrderArea = GetPostString("order_area");
  4952. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4953. string date1 = GetPostString("date1");
  4954. string date2 = GetPostString("date2");
  4955. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4956. if (dw.Length > 0) lw.Add(dw);
  4957. string price1 = GetPostString("price1");
  4958. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4959. string price2 = GetPostString("price2");
  4960. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4961. string posTag = CurrentUser.UserPost.Post.Code;
  4962. if (posTag == "Supplier")
  4963. {
  4964. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4965. }
  4966. lw.Add(string.Format("OrderState=6 "));
  4967. lw.Add(string.Format("IsXianHuo=1 "));
  4968. lw.Add(string.Format("IsReturn>0 "));
  4969. lw.Add(string.Format("IsReturn < 3"));
  4970. lw.Add(string.Format("IsRefund<={0}", 1));
  4971. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4972. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4973. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4974. writeGridDataTableJson(dStruct.TotalCount, dt);
  4975. }
  4976. public void set_erp_orderdelivery()
  4977. {
  4978. if (UrlPostParmsCheck("ctid"))
  4979. {
  4980. string eid = GetPostString("ctid");
  4981. CeErpTradeCell entity = null;
  4982. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4983. if (entity != null)
  4984. {
  4985. if (entity.OrderState >= 7)
  4986. {
  4987. returnErrorMsg("此单已发货,无需重复发货");
  4988. return;
  4989. }
  4990. if (entity.OrderState != 6)
  4991. {
  4992. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4993. return;
  4994. }
  4995. string shop = GetPostString("seller_nick");
  4996. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4997. string comName = GetPostString("comName");
  4998. string comCode = GetPostString("comCode");
  4999. string outSid = GetPostString("outSid");
  5000. string deliveryType = GetPostString("deliveryType");
  5001. string deliveryMemo = GetPostString("deliveryMemo");
  5002. outSid = outSid.Trim();
  5003. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5004. if (mainEn == null)
  5005. {
  5006. returnErrorMsg("找不到原始订单记录");
  5007. return;
  5008. }
  5009. bool isInitOrderDeliv = false;
  5010. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  5011. {
  5012. isInitOrderDeliv = true;
  5013. }
  5014. string apires = "";
  5015. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  5016. 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)
  5017. {
  5018. apires = "发货成功true";
  5019. }
  5020. else
  5021. {
  5022. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5023. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid, entity.ctid);
  5024. }
  5025. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  5026. {
  5027. entity.OrderState = 7;//发货后订单已发货
  5028. entity.OutSid = outSid;
  5029. entity.MemoOpt = 0;
  5030. entity.UpdateTime = DateTime.Now;
  5031. entity.FinishDeliveryTime = DateTime.Now;
  5032. entity.Update();
  5033. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  5034. commonHelper.UpdateRelationOrder(entity.ctid);
  5035. //还要插入快递信息到 快递信息表
  5036. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5037. exinfo.tid = eid;
  5038. exinfo.out_sid = outSid;
  5039. exinfo.company_code = comCode;
  5040. exinfo.company_name = comName;
  5041. exinfo.delivery_memo = deliveryMemo;
  5042. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5043. exinfo.deliveryType = deliveryType;
  5044. exinfo.printUser = CurrentUser.UserName;
  5045. exinfo.print_time = DateTime.Now;
  5046. exinfo.Create();
  5047. returnSuccessMsg("发货操作成功!");
  5048. commonHelper.UpdateRelationOrder(entity.ctid);
  5049. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  5050. CeErpSukuraData.createInfo(entity.ctid, 4);
  5051. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  5052. {
  5053. commonHelper.sendCytExpress(exinfo);
  5054. }
  5055. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5056. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  5057. }
  5058. else
  5059. {
  5060. string errmsg = commonHelper.KeepChinese(apires);
  5061. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  5062. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  5063. }
  5064. return;
  5065. }
  5066. returnErrorMsg("找不到订单记录");
  5067. }
  5068. }
  5069. public void set_erp_multidelivery()
  5070. {
  5071. string eids = GetPostString("tids");
  5072. string[] eidList = eids.Split(',');
  5073. if (eidList.Length <= 0)
  5074. {
  5075. returnErrorMsg("发货不能为空");
  5076. return;
  5077. }
  5078. foreach (string ctid in eidList)
  5079. {
  5080. if (ctid.Length <= 0) continue;
  5081. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  5082. if (expInfo != null)
  5083. {
  5084. StringBuilder sql = new StringBuilder();
  5085. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  5086. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5087. if (dt.Rows.Count > 0)
  5088. {
  5089. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  5090. {
  5091. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  5092. expInfo.state = "异常";
  5093. expInfo.isMultiDelivery = 1;
  5094. expInfo.Update();
  5095. continue;
  5096. }
  5097. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  5098. {
  5099. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  5100. expInfo.state = "异常";
  5101. expInfo.Update();
  5102. continue;
  5103. }
  5104. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  5105. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  5106. bool isInitOrderDeliv = false;
  5107. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  5108. {
  5109. isInitOrderDeliv = true;
  5110. expInfo.isMultiDelivery = 1;
  5111. }
  5112. if (ctid.IndexOf("N") != -1)
  5113. {
  5114. StringBuilder sqlbucha = new StringBuilder();
  5115. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  5116. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  5117. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  5118. commonHelper.UpdateRelationOrder(ctid);
  5119. expInfo.delivery_memo = "发货成功";
  5120. expInfo.state = "发货成功";
  5121. expInfo.isMultiDelivery = 1;
  5122. expInfo.Update();
  5123. }
  5124. else
  5125. {
  5126. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  5127. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid, ctid);
  5128. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  5129. {
  5130. expInfo.delivery_memo = "发货成功";
  5131. expInfo.state = "发货成功";
  5132. expInfo.isMultiDelivery = 1;
  5133. expInfo.Update();
  5134. commonHelper.UpdateRelationOrder(ctid);
  5135. CeErpSukuraData.createInfo(ctid, 4);
  5136. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  5137. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  5138. }
  5139. else
  5140. {
  5141. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  5142. expInfo.state = "异常";
  5143. expInfo.Update();
  5144. }
  5145. }
  5146. }
  5147. }
  5148. }
  5149. returnSuccessMsg("操作完成");
  5150. }
  5151. public void reset_erp_memoopt()
  5152. {
  5153. if (UrlPostParmsCheck("ctid"))
  5154. {
  5155. string eid = GetPostString("ctid");
  5156. CeErpTradeCell entity = null;
  5157. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5158. if (entity != null)
  5159. {
  5160. string stropt = "";
  5161. if (entity.MemoOpt == 1)
  5162. {
  5163. stropt = "“改稿”";
  5164. }
  5165. else if (entity.MemoOpt == 2)
  5166. {
  5167. stropt = "“定稿”";
  5168. }
  5169. else if (entity.MemoOpt == 3)
  5170. {
  5171. stropt = "“完成查货”";
  5172. CeErpSukuraData.createInfo(entity.ctid, 6);
  5173. }
  5174. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  5175. entity.UpdateTime = DateTime.Now;
  5176. entity.MemoOpt = 0;
  5177. entity.Update();
  5178. returnSuccessMsg("操作成功!");
  5179. return;
  5180. }
  5181. returnErrorMsg("找不到记录");
  5182. }
  5183. }
  5184. public void get_erp_deliveryunusual()
  5185. {
  5186. DataStruct dStruct = GetPostStruct();
  5187. List<string> lw = new List<string>();
  5188. string tid = GetPostString("ctid");
  5189. if (tid.Length > 0)
  5190. {
  5191. string select_tid = getTidByCtid(tid);
  5192. lw.Add(string.Format("tid='{0}'", select_tid));
  5193. }
  5194. string shopname = GetPostString("shopname");
  5195. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5196. string buyernick = GetPostString("buyer_nick");
  5197. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5198. string customer = GetPostString("customer");
  5199. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5200. string design = GetPostString("design");
  5201. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5202. string sellermemo = GetPostString("seller_memo");
  5203. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5204. string supplier = GetPostString("supplier");
  5205. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5206. string date1 = GetPostString("date1");
  5207. string date2 = GetPostString("date2");
  5208. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5209. if (dw.Length > 0) lw.Add(dw);
  5210. string placedate1 = GetPostString("placedate1");
  5211. string placedate2 = GetPostString("placedate2");
  5212. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5213. if (dw_place.Length > 0) lw.Add(dw_place);
  5214. string price1 = GetPostString("price1");
  5215. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5216. string price2 = GetPostString("price2");
  5217. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5218. string unusualCon = GetPostString("unusualcon");
  5219. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  5220. string posTag = CurrentUser.UserPost.Post.Code;
  5221. if (posTag == "Supplier")
  5222. {
  5223. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5224. }
  5225. lw.Add(string.Format("OrderState = 6"));
  5226. lw.Add(string.Format("UnusualTag = 5"));
  5227. lw.Add(string.Format("IsRefund<={0}", 1));
  5228. dStruct.Order = "FinishPlaceTime desc";
  5229. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5230. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5231. writeGridDataTableJson(dStruct.TotalCount, dt);
  5232. }
  5233. public void get_erp_deliveryedlist()
  5234. {
  5235. DataStruct dStruct = GetPostStruct();
  5236. List<string> lw = new List<string>();
  5237. string tid = GetPostString("ctid");
  5238. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5239. string shopname = GetPostString("shopname");
  5240. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5241. string buyernick = GetPostString("buyer_nick");
  5242. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5243. string customer = GetPostString("customer");
  5244. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5245. string design = GetPostString("design");
  5246. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5247. string sellermemo = GetPostString("seller_memo");
  5248. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5249. string logistics = GetPostString("logistics");
  5250. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5251. string date1 = GetPostString("date1");
  5252. string date2 = GetPostString("date2");
  5253. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5254. //if (dw.Length > 0) lw.Add(dw);
  5255. string placedate1 = GetPostString("placedate1");
  5256. string placedate2 = GetPostString("placedate2");
  5257. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5258. if (fdw.Length > 0) lw.Add(fdw);
  5259. string devdate1 = GetPostString("deliverydate1");
  5260. string devdate2 = GetPostString("deliverydate2");
  5261. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5262. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5263. string price1 = GetPostString("price1");
  5264. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5265. string price2 = GetPostString("price2");
  5266. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5267. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5268. {
  5269. if (tid.Length > 0)
  5270. {
  5271. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5272. if (tid.Length > 5)
  5273. {
  5274. List<string> tids = getTidByCtidLike(tid);
  5275. if (tids.Count > 0 && tids.Count < 10)
  5276. {
  5277. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5278. }
  5279. }
  5280. lw.Add(tid_sql);
  5281. }
  5282. if (buyernick.Length > 0)
  5283. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5284. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5285. if (dw.Length > 0) lw.Add(dw);
  5286. }
  5287. else
  5288. {
  5289. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5290. }
  5291. string posTag = CurrentUser.UserPost.Post.Code;
  5292. if (posTag == "Supplier")
  5293. {
  5294. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5295. }
  5296. else
  5297. {
  5298. string supplier = GetPostString("supplier");
  5299. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5300. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5301. {
  5302. string usershop = CurrentUser.User.pemShop;
  5303. lw.Add(string.Format("ShopId in ({0})", usershop));
  5304. }
  5305. }
  5306. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5307. lw.Add(string.Format("type != 'PDD' "));
  5308. lw.Add(string.Format("IsRefund!={0}", 2));
  5309. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5310. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5311. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5312. /*if (tid.Length > 0)
  5313. {
  5314. List<string> tids = new List<string>();
  5315. if (dt != null && dt.Rows.Count > 0)
  5316. {
  5317. foreach (DataRow item in dt.Rows)
  5318. {
  5319. tids.Add("'" + item["tid"] + "'");
  5320. }
  5321. }
  5322. if (tids.Count > 0)
  5323. {
  5324. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5325. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5326. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5327. dt = WebCache.GetData("view_erptradecell", dStruct);
  5328. }
  5329. }*/
  5330. if (dt != null)
  5331. {
  5332. foreach (DataRow dr in dt.Rows)
  5333. {
  5334. 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();
  5335. }
  5336. }
  5337. writeGridDataTableJson(dStruct.TotalCount, dt);
  5338. }
  5339. public void get_erp_pdddeliveryed()
  5340. {
  5341. DataStruct dStruct = GetPostStruct();
  5342. List<string> lw = new List<string>();
  5343. string tid = GetPostString("ctid");
  5344. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5345. string shopname = GetPostString("shopname");
  5346. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5347. string buyernick = GetPostString("buyer_nick");
  5348. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5349. string customer = GetPostString("customer");
  5350. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5351. string design = GetPostString("design");
  5352. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5353. string sellermemo = GetPostString("seller_memo");
  5354. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5355. string logistics = GetPostString("logistics");
  5356. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5357. string date1 = GetPostString("date1");
  5358. string date2 = GetPostString("date2");
  5359. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5360. //if (dw.Length > 0) lw.Add(dw);
  5361. string placedate1 = GetPostString("placedate1");
  5362. string placedate2 = GetPostString("placedate2");
  5363. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5364. if (fdw.Length > 0) lw.Add(fdw);
  5365. string devdate1 = GetPostString("deliverydate1");
  5366. string devdate2 = GetPostString("deliverydate2");
  5367. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5368. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5369. string price1 = GetPostString("price1");
  5370. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5371. string price2 = GetPostString("price2");
  5372. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5373. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5374. {
  5375. if (tid.Length > 0)
  5376. {
  5377. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5378. if (tid.Length > 5)
  5379. {
  5380. List<string> tids = getTidByCtidLike(tid);
  5381. if (tids.Count > 0 && tids.Count < 10)
  5382. {
  5383. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5384. }
  5385. }
  5386. lw.Add(tid_sql);
  5387. }
  5388. if (buyernick.Length > 0)
  5389. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5390. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5391. if (dw.Length > 0) lw.Add(dw);
  5392. }
  5393. else
  5394. {
  5395. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5396. }
  5397. string posTag = CurrentUser.UserPost.Post.Code;
  5398. if (posTag == "Supplier")
  5399. {
  5400. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5401. }
  5402. else
  5403. {
  5404. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5405. {
  5406. string usershop = CurrentUser.User.pemShop;
  5407. lw.Add(string.Format("ShopId in ({0})", usershop));
  5408. }
  5409. string supplier = GetPostString("supplier");
  5410. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5411. }
  5412. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5413. lw.Add(string.Format("type = 'PDD' "));
  5414. lw.Add(string.Format("IsRefund!={0}", 2));
  5415. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5416. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5417. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5418. /* if (tid.Length > 0)
  5419. {
  5420. List<string> tids = new List<string>();
  5421. if (dt != null && dt.Rows.Count > 0)
  5422. {
  5423. foreach (DataRow item in dt.Rows)
  5424. {
  5425. tids.Add("'" + item["tid"] + "'");
  5426. }
  5427. }
  5428. if (tids.Count > 0)
  5429. {
  5430. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5431. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5432. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5433. dt = WebCache.GetData("view_erptradecell", dStruct);
  5434. }
  5435. }*/
  5436. foreach (DataRow dr in dt.Rows)
  5437. {
  5438. 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();
  5439. }
  5440. writeGridDataTableJson(dStruct.TotalCount, dt);
  5441. }
  5442. public void get_erp_jddeliveryed()
  5443. {
  5444. DataStruct dStruct = GetPostStruct();
  5445. List<string> lw = new List<string>();
  5446. string tid = GetPostString("ctid");
  5447. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5448. string shopname = GetPostString("shopname");
  5449. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5450. string buyernick = GetPostString("buyer_nick");
  5451. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5452. string customer = GetPostString("customer");
  5453. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5454. string design = GetPostString("design");
  5455. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5456. string sellermemo = GetPostString("seller_memo");
  5457. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5458. string date1 = GetPostString("date1");
  5459. string date2 = GetPostString("date2");
  5460. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5461. //if (dw.Length > 0) lw.Add(dw);
  5462. string placedate1 = GetPostString("placedate1");
  5463. string placedate2 = GetPostString("placedate2");
  5464. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5465. if (fdw.Length > 0) lw.Add(fdw);
  5466. string devdate1 = GetPostString("deliverydate1");
  5467. string devdate2 = GetPostString("deliverydate2");
  5468. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5469. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5470. string price1 = GetPostString("price1");
  5471. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5472. string price2 = GetPostString("price2");
  5473. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5474. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5475. {
  5476. if (tid.Length > 0)
  5477. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5478. if (buyernick.Length > 0)
  5479. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5480. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5481. if (dw.Length > 0) lw.Add(dw);
  5482. }
  5483. else
  5484. {
  5485. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5486. }
  5487. string posTag = CurrentUser.UserPost.Post.Code;
  5488. if (posTag == "Supplier")
  5489. {
  5490. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5491. }
  5492. else
  5493. {
  5494. string supplier = GetPostString("supplier");
  5495. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5496. }
  5497. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5498. lw.Add(string.Format("type = 'JD' "));
  5499. lw.Add(string.Format("IsRefund!={0}", 2));
  5500. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5501. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5502. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5503. foreach (DataRow dr in dt.Rows)
  5504. {
  5505. 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();
  5506. }
  5507. writeGridDataTableJson(dStruct.TotalCount, dt);
  5508. }
  5509. public void get_erp_allplacelist()
  5510. {
  5511. DataStruct dStruct = GetPostStruct();
  5512. List<string> lw = new List<string>();
  5513. string tid = GetPostString("ctid");
  5514. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5515. string shopname = GetPostString("shopname");
  5516. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5517. string buyernick = GetPostString("buyer_nick");
  5518. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5519. string customer = GetPostString("customer");
  5520. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5521. string design = GetPostString("design");
  5522. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5523. string sellermemo = GetPostString("seller_memo");
  5524. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5525. string supplier = GetPostString("supplier");
  5526. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5527. string date1 = GetPostString("date1");
  5528. string date2 = GetPostString("date2");
  5529. string pldate1 = GetPostString("placedate1");
  5530. string pldate2 = GetPostString("placedate2");
  5531. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5532. //if (dw.Length > 0) lw.Add(dw);
  5533. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5534. {
  5535. if (tid.Length > 0)
  5536. {
  5537. string select_tid = getTidByCtid(tid);
  5538. lw.Add(string.Format("tid='{0}'", select_tid));
  5539. }
  5540. if (buyernick.Length > 0)
  5541. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5542. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5543. if (dw.Length > 0) lw.Add(dw);
  5544. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5545. if (dw_place.Length > 0) lw.Add(dw_place);
  5546. }
  5547. else
  5548. {
  5549. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5550. {
  5551. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5552. }
  5553. }
  5554. string price1 = GetPostString("price1");
  5555. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5556. string price2 = GetPostString("price2");
  5557. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5558. string posTag = CurrentUser.UserPost.Post.Code;
  5559. if (posTag == "Supplier")
  5560. {
  5561. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5562. }
  5563. lw.Add(string.Format("OrderState >= 6"));
  5564. lw.Add(string.Format("IsSample != 2 "));
  5565. //lw.Add(string.Format("isDianziOrder = 0 "));
  5566. lw.Add(string.Format("SupplierId > 0 "));
  5567. //lw.Add(string.Format("IsRefund<={0}", 1));
  5568. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5569. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5570. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5571. foreach (DataRow dr in dt.Rows)
  5572. {
  5573. 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();
  5574. }
  5575. writeGridDataTableJson(dStruct.TotalCount, dt);
  5576. }
  5577. public void get_erp_financeallplacelist()
  5578. {
  5579. DataStruct dStruct = GetPostStruct();
  5580. List<string> lw = new List<string>();
  5581. string tid = GetPostString("ctid");
  5582. string shopname = GetPostString("shopname");
  5583. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5584. string buyernick = GetPostString("buyer_nick");
  5585. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5586. string customer = GetPostString("customer");
  5587. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5588. string design = GetPostString("design");
  5589. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5590. string sellermemo = GetPostString("seller_memo");
  5591. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5592. string supplier = GetPostString("supplier");
  5593. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5594. string date1 = GetPostString("date1");
  5595. string date2 = GetPostString("date2");
  5596. string pldate1 = GetPostString("placedate1");
  5597. string pldate2 = GetPostString("placedate2");
  5598. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5599. {
  5600. if (tid.Length > 0)
  5601. {
  5602. string select_tid = getTidByCtid(tid);
  5603. lw.Add(string.Format("tid='{0}'", select_tid));
  5604. }
  5605. if (buyernick.Length > 0)
  5606. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5607. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5608. if (dw.Length > 0) lw.Add(dw);
  5609. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5610. if (dw_place.Length > 0) lw.Add(dw_place);
  5611. }
  5612. else
  5613. {
  5614. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5615. {
  5616. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5617. }
  5618. }
  5619. string price1 = GetPostString("price1");
  5620. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5621. string price2 = GetPostString("price2");
  5622. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5623. string posTag = CurrentUser.UserPost.Post.Code;
  5624. if (posTag == "Supplier")
  5625. {
  5626. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5627. }
  5628. //lw.Add(string.Format("OrderState >= 6"));
  5629. lw.Add(string.Format("IsSample != 2 "));
  5630. lw.Add(string.Format("isDianziOrder = 0 "));
  5631. //lw.Add(string.Format("IsRefund<={0}", 1));
  5632. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5633. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5634. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5635. foreach (DataRow dr in dt.Rows)
  5636. {
  5637. 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();
  5638. }
  5639. writeGridDataTableJson(dStruct.TotalCount, dt);
  5640. }
  5641. public void get_erp_expresslist()
  5642. {
  5643. int listtype = GetInt("ltype");
  5644. DataStruct dStruct = GetPostStruct();
  5645. List<string> lw = new List<string>();
  5646. string tid = GetPostString("tid");
  5647. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5648. string outsid = GetPostString("out_sid");
  5649. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5650. string importer = GetPostString("ImportUserName");
  5651. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5652. string file = GetPostString("import_file");
  5653. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5654. string printman = GetPostString("printman");
  5655. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5656. string date1 = GetPostString("date1");
  5657. string date2 = GetPostString("date2");
  5658. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5659. if (dw.Length > 0) lw.Add(dw);
  5660. string fdate1 = GetPostString("finishdate1");
  5661. string fdate2 = GetPostString("finishdate2");
  5662. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5663. if (fdw.Length > 0) lw.Add(fdw);
  5664. string supplierId = GetPostString("supplierId");
  5665. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5666. if (listtype == 1)
  5667. {
  5668. lw.Add(string.Format("importUserId !=0"));
  5669. }
  5670. string posTag = CurrentUser.UserPost.Post.Code;
  5671. if (posTag == "Supplier")
  5672. {
  5673. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5674. }
  5675. if (dStruct.PageSize != 100000)
  5676. {
  5677. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5678. }
  5679. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5680. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5681. writeGridDataTableJson(dStruct.TotalCount, dt);
  5682. }
  5683. public void set_erp_buchaorderdelivery()
  5684. {
  5685. if (UrlPostParmsCheck("ctid"))
  5686. {
  5687. string eid = GetPostString("ctid");
  5688. CeErpTradeCell entity = null;
  5689. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5690. if (entity != null)
  5691. {
  5692. if (entity.IsSample != 2)
  5693. {
  5694. returnErrorMsg("补差价单才能标记为已发货");
  5695. return;
  5696. }
  5697. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5698. entity.OrderState = 7;
  5699. entity.Update();
  5700. returnSuccessMsg("操作成功!");
  5701. return;
  5702. }
  5703. returnErrorMsg("找不到记录");
  5704. }
  5705. }
  5706. public void get_stdtemplates()
  5707. {
  5708. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5709. //string res = taobaoHelper.test();
  5710. string res = apiHelper.API_PrintTemplate();
  5711. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5712. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5713. {
  5714. int sidx = res.IndexOf("error_code");
  5715. int eidx = res.IndexOf("success");
  5716. string msg = res.Substring(sidx, eidx - sidx);
  5717. returnErrorMsg(msg);
  5718. return;
  5719. }
  5720. if (res.Length <= 0)
  5721. {
  5722. returnErrorMsg("模板数据为空!");
  5723. return;
  5724. }
  5725. ReturnSuccess(res);
  5726. }
  5727. public void cancel_print_order()
  5728. {
  5729. if (UrlPostParmsCheck("ctid"))
  5730. {
  5731. string ctid = GetPostString("ctid");
  5732. CeErpTradeCell entity = null;
  5733. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5734. if (entity != null)
  5735. {
  5736. string res = "";
  5737. string code = entity.LastBillWaybillCode;
  5738. if (code == "")
  5739. {
  5740. code = entity.OutSid;
  5741. }
  5742. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5743. XLog.SaveLog(0, "取消面单" + res);
  5744. }
  5745. }
  5746. }
  5747. public void set_erp_printwaybill()
  5748. {
  5749. if (UrlPostParmsCheck("ctid"))
  5750. {
  5751. string ctid = GetPostString("ctid");
  5752. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5753. string cpName = GetPostString("cpname");
  5754. string isTogether = GetPostString("together");
  5755. string printType = GetPostString("printType");
  5756. //var res_obj = new
  5757. //{
  5758. // restype = 1,
  5759. // 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\"}"
  5760. //};
  5761. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5762. //ReturnSuccess(ro_json);
  5763. //return;
  5764. bool isUseLastWayBillCode = false;
  5765. CeErpTradeCell entity = null;
  5766. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5767. if (entity != null)
  5768. {
  5769. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5770. {
  5771. isUseLastWayBillCode = true;
  5772. }
  5773. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5774. {
  5775. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5776. return;
  5777. }
  5778. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5779. {
  5780. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5781. return;
  5782. }
  5783. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5784. {
  5785. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5786. return;
  5787. }
  5788. }
  5789. string res = "";
  5790. Api_waybill_code_response_Obj fullObj = null;
  5791. string pData_str = "";
  5792. string curUseWayBillCode = "";
  5793. if (isUseLastWayBillCode == false)
  5794. {
  5795. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5796. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5797. if (res.IndexOf("failure") != -1)
  5798. {
  5799. //int idx = res.IndexOf("sub_message");
  5800. //int idx2 = res.IndexOf("flag");
  5801. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5802. string errMsgNeed = commonHelper.KeepChinese(res);
  5803. var res_objd = new
  5804. {
  5805. restype = 0,
  5806. data = "获取面单失败" + errMsgNeed
  5807. };
  5808. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5809. returnSuccess(ro_jsond);
  5810. if (res.IndexOf("停发") != -1)
  5811. {
  5812. entity.UnusualCon = "物流停发";
  5813. entity.Update();
  5814. }
  5815. //returnErrorMsg("获取面单失败,"+emsg);
  5816. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5817. return;
  5818. }
  5819. else if (res.IndexOf("errorMsg") != -1)
  5820. {
  5821. //int idx = res.IndexOf("errorMsg");
  5822. //int idx2 = res.IndexOf("}]}");
  5823. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5824. string errMsgNeed = commonHelper.KeepChinese(res);
  5825. var res_objf = new
  5826. {
  5827. restype = 0,
  5828. data = "获取面单失败2" + errMsgNeed
  5829. };
  5830. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5831. if (res.IndexOf("停发") != -1)
  5832. {
  5833. entity.UnusualCon = "物流停发";
  5834. entity.Update();
  5835. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5836. if (trade != null)
  5837. {
  5838. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5839. }
  5840. }
  5841. returnSuccess(ro_jsonf);
  5842. //returnErrorMsg("获取面单失败," + emsg);
  5843. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5844. return;
  5845. }
  5846. try
  5847. {
  5848. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5849. //res = res.Replace(" ", "");
  5850. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5851. }
  5852. catch (Exception ex)
  5853. {
  5854. XLog.SaveLog(0, "生成fullObj" + res);
  5855. var res_objf = new
  5856. {
  5857. restype = 0,
  5858. data = "生成fullObj发生错误" + ex.Message
  5859. };
  5860. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5861. returnSuccess(ro_jsonf);
  5862. return;
  5863. }
  5864. if (fullObj.response.data.content.Count > 0)
  5865. {
  5866. ContentItem codeObj = fullObj.response.data.content[0];
  5867. if (cpCode.IndexOf("SFFQ-") != -1)
  5868. {
  5869. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5870. }
  5871. else
  5872. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5873. curUseWayBillCode = codeObj.waybillCode;
  5874. }
  5875. else
  5876. {
  5877. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5878. var res_objf = new
  5879. {
  5880. restype = 0,
  5881. data = "生成fullObj找不到快递单号waybillCode"
  5882. };
  5883. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5884. returnSuccess(ro_jsonf);
  5885. return;
  5886. }
  5887. }
  5888. else
  5889. {
  5890. //使用上次打印的快递单号
  5891. if (cpCode == "SFFQ-LY")
  5892. {
  5893. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5894. }
  5895. else
  5896. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5897. curUseWayBillCode = entity.LastBillWaybillCode;
  5898. }
  5899. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5900. {
  5901. var res_obje = new
  5902. {
  5903. restype = 0,
  5904. data = "获取加密打印数据失败"
  5905. };
  5906. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5907. returnSuccess(ro_jsone);
  5908. entity.LastBillCpCode = cpCode;
  5909. entity.LastBillWaybillCode = curUseWayBillCode;
  5910. entity.Update();
  5911. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5912. //returnErrorMsg("获取加密打印数据失败");
  5913. return;
  5914. }
  5915. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5916. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5917. string btnType = "";
  5918. string errorMsg = "";
  5919. if (entity != null)
  5920. {
  5921. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5922. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5923. //cpcode是 YTO-CAINIAO
  5924. //string comCode = cpCode.Split('-')[0].ToString();
  5925. string apires = "";
  5926. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5927. //isTogether=2是新的合包弹窗
  5928. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5929. {
  5930. if (ctid.IndexOf("N") != -1)
  5931. {
  5932. apires = "发货成功";
  5933. }
  5934. else
  5935. {
  5936. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode, entity.ctid);
  5937. }
  5938. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5939. //打单后发货
  5940. StringBuilder sql = new StringBuilder();
  5941. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5942. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5943. {
  5944. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5945. }
  5946. else
  5947. {
  5948. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5949. }
  5950. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5951. foreach (DataRow row in dt.Rows)
  5952. {
  5953. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5954. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5955. {
  5956. try
  5957. {
  5958. btnType = "待发货";
  5959. entity.OutSid = curUseWayBillCode;
  5960. entity.OrderState = 7;
  5961. entity.IsUrgency = false;
  5962. entity.LastBillCpCode = "";
  5963. entity.LastBillWaybillCode = "";
  5964. entity.FinishDeliveryTime = DateTime.Now;
  5965. entity.IsReturn = 0;
  5966. entity.MemoOpt = 0;
  5967. entity.UpdateTime = DateTime.Now;
  5968. entity.Update();
  5969. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5970. //还要插入快递信息到 快递信息表
  5971. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5972. exinfo.tid = entity.ctid;
  5973. exinfo.out_sid = curUseWayBillCode;
  5974. exinfo.company_code = cpCode;
  5975. exinfo.company_name = cpName;
  5976. exinfo.supplierUserName = supplierName;
  5977. exinfo.deliveryType = "发货成功";
  5978. exinfo.print_time = DateTime.Now;
  5979. exinfo.printUser = CurrentUser.UserName;
  5980. exinfo.postData = pData_str;
  5981. exinfo.Create();
  5982. commonHelper.UpdateRelationOrder(entity.ctid);
  5983. CeErpSukuraData.createInfo(ctid, 4);
  5984. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5985. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  5986. {
  5987. commonHelper.sendCytExpress(exinfo);
  5988. }
  5989. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5990. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5991. }
  5992. catch (Exception ex)
  5993. {
  5994. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5995. }
  5996. }
  5997. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5998. {
  5999. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  6000. if (entity.OrderState == 6)
  6001. {
  6002. entity.OrderState = 7;
  6003. }
  6004. entity.UpdateTime = DateTime.Now;
  6005. entity.FinishDeliveryTime = DateTime.Now;
  6006. btnType = "已发货";
  6007. entity.Update();
  6008. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  6009. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6010. exinfo.tid = entity.ctid;
  6011. exinfo.out_sid = curUseWayBillCode;
  6012. exinfo.company_code = cpCode;
  6013. exinfo.company_name = cpName;
  6014. exinfo.supplierUserName = supplierName;
  6015. exinfo.deliveryType = "发货成功";
  6016. exinfo.print_time = DateTime.Now;
  6017. exinfo.printUser = CurrentUser.UserName;
  6018. exinfo.postData = pData_str;
  6019. exinfo.Create();
  6020. commonHelper.UpdateRelationOrder(entity.ctid);
  6021. CeErpSukuraData.createInfo(entity.ctid, 4);
  6022. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  6023. {
  6024. commonHelper.sendCytExpress(exinfo);
  6025. }
  6026. //不处理
  6027. }
  6028. else
  6029. {
  6030. entity.UpdateTime = DateTime.Now;
  6031. entity.LastBillCpCode = cpCode;
  6032. entity.LastBillWaybillCode = curUseWayBillCode;
  6033. entity.Update();
  6034. string errmsg = commonHelper.KeepChinese(apires);
  6035. var res_objz = new
  6036. {
  6037. restype = 0,
  6038. data = "打单后发货失败"
  6039. };
  6040. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6041. returnSuccess(ro_jsonz);
  6042. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  6043. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  6044. return;
  6045. }
  6046. }
  6047. }
  6048. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  6049. {
  6050. string ctids = GetPostString("ctids");
  6051. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  6052. List<string> list = new List<string>();
  6053. List<string> send_list = new List<string>();
  6054. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  6055. CeErpTrade ceErpTrade = new CeErpTrade();
  6056. //可合包的合并一起发货
  6057. if (dt == null && string.IsNullOrEmpty(ctids))
  6058. {
  6059. var res_objz = new
  6060. {
  6061. restype = 0,
  6062. data = "打单后发货失败"
  6063. };
  6064. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6065. returnSuccess(ro_jsonz);
  6066. return;
  6067. }
  6068. if (!string.IsNullOrEmpty(ctids))
  6069. {
  6070. StringBuilder sql = new StringBuilder();
  6071. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  6072. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  6073. }
  6074. foreach (DataRow row in dt.Rows)
  6075. {
  6076. list.Add("'" + row["ctid"] + "'");
  6077. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  6078. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  6079. if (ctid.IndexOf("N") != -1)
  6080. {
  6081. apires = "发货成功";
  6082. }
  6083. else
  6084. {
  6085. if (!send_list.Contains(ceErpTrade.tid))
  6086. {
  6087. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode, ctid);
  6088. }
  6089. else
  6090. {
  6091. apires = "发货成功";
  6092. }
  6093. }
  6094. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  6095. {
  6096. send_list.Add(ceErpTrade.tid);
  6097. try
  6098. {
  6099. btnType = "待发货";
  6100. ceErpTradeCell.OutSid = curUseWayBillCode;
  6101. ceErpTradeCell.OrderState = 7;
  6102. ceErpTradeCell.IsUrgency = false;
  6103. ceErpTradeCell.LastBillCpCode = "";
  6104. ceErpTradeCell.LastBillWaybillCode = "";
  6105. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  6106. ceErpTradeCell.IsReturn = 0;
  6107. ceErpTradeCell.MemoOpt = 0;
  6108. ceErpTradeCell.UpdateTime = DateTime.Now;
  6109. ceErpTradeCell.Update();
  6110. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  6111. //还要插入快递信息到 快递信息表
  6112. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6113. exinfo.tid = ceErpTradeCell.ctid;
  6114. exinfo.out_sid = curUseWayBillCode;
  6115. exinfo.company_code = cpCode;
  6116. exinfo.company_name = cpName;
  6117. exinfo.supplierUserName = supplierName;
  6118. exinfo.deliveryType = "发货成功";
  6119. exinfo.print_time = DateTime.Now;
  6120. exinfo.printUser = CurrentUser.UserName;
  6121. exinfo.postData = pData_str;
  6122. exinfo.Create();
  6123. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  6124. CeErpSukuraData.createInfo(ctid, 4);
  6125. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  6126. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  6127. {
  6128. commonHelper.sendCytExpress(exinfo);
  6129. }
  6130. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  6131. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6132. }
  6133. catch (Exception ex)
  6134. {
  6135. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  6136. }
  6137. }
  6138. else
  6139. {
  6140. ceErpTradeCell.UpdateTime = DateTime.Now;
  6141. ceErpTradeCell.LastBillCpCode = cpCode;
  6142. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  6143. ceErpTradeCell.Update();
  6144. string errmsg = commonHelper.KeepChinese(apires);
  6145. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  6146. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  6147. }
  6148. }
  6149. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  6150. }
  6151. }
  6152. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  6153. var res_obj = new
  6154. {
  6155. restype = 1,
  6156. data = pData_str,
  6157. errorMsg
  6158. };
  6159. string ro_json = JsonConvert.SerializeObject(res_obj);
  6160. ReturnSuccess(ro_json);
  6161. return;
  6162. }
  6163. }
  6164. private string GetUTF8String(byte[] vs)
  6165. {
  6166. throw new NotImplementedException();
  6167. }
  6168. public void set_erp_printwaybill_cn()
  6169. {
  6170. if (UrlPostParmsCheck("ctid"))
  6171. {
  6172. string ctid = GetPostString("ctid");
  6173. string cpCode = GetPostString("cpcode");
  6174. string cpName = GetPostString("cpname");
  6175. string tempUrl = GetPostString("tempurl");
  6176. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6177. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  6178. //string res = taobaoHelper.test();
  6179. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6180. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  6181. {
  6182. int sidx = res.IndexOf("errorMsg");
  6183. int eidx = res.IndexOf("}");
  6184. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  6185. var res_objzxx = new
  6186. {
  6187. restype = 0,
  6188. data = msg
  6189. };
  6190. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  6191. returnSuccess(ro_jsonzxx);
  6192. //returnErrorMsg(msg);
  6193. return;
  6194. }
  6195. int idx = res.IndexOf("waybillCode");
  6196. int idx2 = res.IndexOf("printData");
  6197. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  6198. string eid = GetPostString("ctid");
  6199. CeErpTradeCell entity = null;
  6200. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6201. if (entity != null)
  6202. {
  6203. string osid = entity.OutSid;
  6204. entity.OutSid = osid + "," + outsid;
  6205. entity.FinishDeliveryTime = DateTime.Now;
  6206. entity.OrderState = 7;
  6207. entity.UpdateTime = DateTime.Now;
  6208. entity.IsReturn = 0;
  6209. entity.Update();
  6210. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6211. exinfo.tid = entity.ctid;
  6212. exinfo.out_sid = outsid;
  6213. exinfo.company_code = cpCode;
  6214. exinfo.company_name = cpName;
  6215. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  6216. exinfo.deliveryType = "发货成功";
  6217. exinfo.print_time = DateTime.Now;
  6218. exinfo.printUser = CurrentUser.UserName;
  6219. exinfo.Create();
  6220. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  6221. {
  6222. commonHelper.sendCytExpress(exinfo);
  6223. }
  6224. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6225. }
  6226. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  6227. var res_objz = new
  6228. {
  6229. restype = 1,
  6230. data = res
  6231. };
  6232. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6233. returnSuccess(ro_jsonz);
  6234. //ReturnSuccess(res);
  6235. }
  6236. }
  6237. ////打单,打印面单 获取面单号
  6238. //public void set_erp_printwaybill()
  6239. //{
  6240. // if (UrlPostParmsCheck("ctid"))
  6241. // {
  6242. // string ctid = GetPostString("ctid");
  6243. // string cpCode = GetPostString("cpcode");
  6244. // string tempUrl = GetPostString("tempurl");
  6245. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6246. // //string res = taobaoHelper.test();
  6247. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6248. // if (res.IndexOf("error_response") != -1)
  6249. // {
  6250. // int sidx = res.IndexOf("sub_msg");
  6251. // int eidx = res.IndexOf("request_id");
  6252. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6253. // returnErrorMsg(msg);
  6254. // return;
  6255. // }
  6256. // int idx = res.IndexOf("waybill_code");
  6257. // int idx2 = res.IndexOf("}]}");
  6258. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6259. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6260. // ReturnSuccess(res);
  6261. // }
  6262. //}
  6263. public void cancel_erp_aftersale()
  6264. {
  6265. if (UrlPostParmsCheck("ctid"))
  6266. {
  6267. string eid = GetPostString("ctid");
  6268. CeErpTradeCell entity = null;
  6269. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6270. if (entity != null)
  6271. {
  6272. //有过处理的售后,取消也不能删除 售 字,保留
  6273. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6274. {
  6275. entity.AfterSaleState = 4;
  6276. }
  6277. else
  6278. entity.AfterSaleState = 0;
  6279. entity.UpdateTime = DateTime.Now;
  6280. entity.Update();
  6281. returnSuccessMsg("操作成功!");
  6282. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6283. return;
  6284. }
  6285. returnErrorMsg("找不到订单记录");
  6286. }
  6287. }
  6288. public void get_erp_aftersalelist()
  6289. {
  6290. DataStruct dStruct = GetPostStruct();
  6291. List<string> lw = new List<string>();
  6292. int st = GetInt("st");
  6293. string tid = GetPostString("ctid");
  6294. if (st == 3)
  6295. {
  6296. if (tid.Length > 0)
  6297. {
  6298. string select_tid = getTidByCtid(tid);
  6299. lw.Add(string.Format("tid='{0}'", select_tid));
  6300. }
  6301. }
  6302. else
  6303. {
  6304. if (tid.Length > 0)
  6305. {
  6306. string select_tid = getTidByCtid(tid);
  6307. lw.Add(string.Format("tid='{0}'", select_tid));
  6308. }
  6309. }
  6310. string shopname = GetPostString("shopname");
  6311. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6312. string buyernick = GetPostString("buyer_nick");
  6313. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6314. string sellermemo = GetPostString("seller_memo");
  6315. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6316. string orderState = GetPostString("orderState");
  6317. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6318. string afterState = GetPostString("afterstate");
  6319. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6320. string date1 = GetPostString("date1");
  6321. string date2 = GetPostString("date2");
  6322. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6323. if (dw.Length > 0) lw.Add(dw);
  6324. string price1 = GetPostString("price1");
  6325. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6326. string price2 = GetPostString("price2");
  6327. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6328. //lw.Add(string.Format("IsRefund!={0}", 1));
  6329. string reason = GetPostString("reason");
  6330. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6331. string method = GetPostString("method");
  6332. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6333. string handler = GetPostString("handler");
  6334. if (handler.Length > 0)
  6335. {
  6336. lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6337. }
  6338. string handledate1 = GetPostString("handledate1");
  6339. string handledate2 = GetPostString("handledate2");
  6340. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6341. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6342. string finish1 = GetPostString("finishdate1");
  6343. string finish2 = GetPostString("finishdate2");
  6344. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6345. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6346. string afterdate1 = GetPostString("afterdate1");
  6347. string afterdate2 = GetPostString("afterdate2");
  6348. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6349. if (afterDate.Length > 0) lw.Add(afterDate);
  6350. string supplier = GetPostString("supplier");
  6351. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6352. string responsible = GetPostString("responsibleman");
  6353. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6354. string customer = GetPostString("customer");
  6355. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6356. string design = GetPostString("design");
  6357. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6358. string afterMemoType = GetPostString("aftermemotype");
  6359. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6360. string posCode = CurrentUser.UserPost.Post.Code;
  6361. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6362. //{
  6363. // string vstate = GetPostString("vstate");
  6364. // if (vstate.Length > 0)
  6365. // {
  6366. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6367. // }
  6368. // if (posCode == "Supplier")
  6369. // {
  6370. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6371. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6372. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6373. // }
  6374. // else
  6375. // {
  6376. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6377. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6378. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6379. // {
  6380. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6381. // }
  6382. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6383. // {
  6384. // int orgid = CurrentUser.UserPost.OrgID;
  6385. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6386. // }
  6387. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6388. // {
  6389. // string shopid = CurrentUser.User.pemShop;
  6390. // lw.Add(string.Format("shopId in ({0})", shopid));
  6391. // }
  6392. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6393. // //{
  6394. // // int org_id = CurrentUser.UserPost.OrgID;
  6395. // // lw.Add(string.Format("OrgID={0}", org_id));
  6396. // //}
  6397. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6398. // }
  6399. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6400. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6401. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6402. //}
  6403. if (st == 5)
  6404. {
  6405. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6406. {
  6407. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6408. {
  6409. string shopid = CurrentUser.User.pemShop;
  6410. lw.Add(string.Format("shopId in ({0})", shopid));
  6411. }
  6412. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6413. {
  6414. int mrOrgid = CurrentUser.UserPost.OrgID;
  6415. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6416. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6417. }
  6418. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6419. //{
  6420. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6421. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6422. //}
  6423. else
  6424. {
  6425. string userIdStr = "";
  6426. if (posCode == "CustomerService")
  6427. {
  6428. userIdStr = CurrentUser.UserID + "_k";
  6429. }
  6430. else if (posCode == "Designer" || posCode == "wxDesigner")
  6431. {
  6432. userIdStr = CurrentUser.UserID + "_s";
  6433. }
  6434. else if (posCode == "Place")
  6435. {
  6436. userIdStr = CurrentUser.UserID + "_x";
  6437. }
  6438. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6439. }
  6440. }
  6441. string placedate1 = GetPostString("placedate1");
  6442. string placedate2 = GetPostString("placedate2");
  6443. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6444. if (dwplace.Length > 0) lw.Add(dwplace);
  6445. string supState = GetPostString("supState");
  6446. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6447. string searchType = GetPostString("searchType");
  6448. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6449. {
  6450. lw.Add(string.Format("BackNum>1"));
  6451. }
  6452. lw.Add(string.Format("AfterSaleState>0"));
  6453. if (ex_psize > 0)
  6454. {
  6455. if (CurrentUser.UserPost.Post.Code == "Finance")
  6456. dStruct.Order = "pay_time desc";
  6457. else
  6458. dStruct.Order = "HandleTime desc";
  6459. }
  6460. else
  6461. dStruct.Order = "HandleTime desc";
  6462. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6463. DataTable dt = WebCache.GetData("view_test", dStruct);
  6464. writeGridDataTableJson(dStruct.TotalCount, dt);
  6465. }
  6466. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6467. //{
  6468. // lw.Add(string.Format("AfterSaleState=4"));
  6469. // string code = CurrentUser.UserPost.Post.Code;
  6470. // if (code == "CustomerService")
  6471. // {
  6472. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6473. // }
  6474. // else if (code == "Designer" || code == "DesignerMr")
  6475. // {
  6476. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6477. // }
  6478. // else if (code == "Place" || code == "PlaceMr")
  6479. // {
  6480. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6481. // }
  6482. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6483. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6484. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6485. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6486. //}
  6487. //else //处理中的售后,待处理和处理中合并
  6488. //{
  6489. // if (afterState.Length <= 0)
  6490. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6491. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6492. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6493. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6494. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6495. //}
  6496. }
  6497. public void get_erp_disagreeftersalelist()
  6498. {
  6499. DataStruct dStruct = GetPostStruct();
  6500. List<string> lw = new List<string>();
  6501. int st = 2;
  6502. string tid = GetPostString("ctid");
  6503. if (tid.Length > 0)
  6504. {
  6505. string select_tid = getTidByCtid(tid);
  6506. lw.Add(string.Format("tid='{0}'", select_tid));
  6507. }
  6508. string shopname = GetPostString("shopname");
  6509. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6510. string buyernick = GetPostString("buyer_nick");
  6511. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6512. string sellermemo = GetPostString("seller_memo");
  6513. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6514. string orderState = GetPostString("orderState");
  6515. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6516. string afterState = GetPostString("afterstate");
  6517. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6518. string date1 = GetPostString("date1");
  6519. string date2 = GetPostString("date2");
  6520. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6521. if (dw.Length > 0) lw.Add(dw);
  6522. string price1 = GetPostString("price1");
  6523. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6524. string price2 = GetPostString("price2");
  6525. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6526. //lw.Add(string.Format("IsRefund!={0}", 1));
  6527. string reason = GetPostString("reason");
  6528. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6529. string method = GetPostString("method");
  6530. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6531. string handler = GetPostString("handler");
  6532. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6533. string handledate1 = GetPostString("handledate1");
  6534. string handledate2 = GetPostString("handledate2");
  6535. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6536. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6537. string afterdate1 = GetPostString("afterdate1");
  6538. string afterdate2 = GetPostString("afterdate2");
  6539. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6540. if (afterDate.Length > 0) lw.Add(afterDate);
  6541. string backdate1 = GetPostString("backdate1");
  6542. string backdate2 = GetPostString("backdate2");
  6543. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6544. if (backDate.Length > 0) lw.Add(backDate);
  6545. string supplier = GetPostString("supplier");
  6546. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6547. string responsible = GetPostString("responsibleman");
  6548. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6549. string customer = GetPostString("customer");
  6550. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6551. string design = GetPostString("design");
  6552. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6553. string afterSaleMemo = GetPostString("afterSaleMemo");
  6554. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6555. string afterMemoType = GetPostString("aftermemotype");
  6556. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6557. string aftersakereason = GetPostString("aftersakereason");
  6558. if (aftersakereason.Length > 0)
  6559. {
  6560. if (aftersakereason == "1")
  6561. {
  6562. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6563. }
  6564. if (aftersakereason == "2")
  6565. {
  6566. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6567. }
  6568. }
  6569. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6570. string poscode = CurrentUser.UserPost.Post.Code;
  6571. if (poscode != "SysAdmin")
  6572. {
  6573. string shopid = CurrentUser.User.pemShop;
  6574. lw.Add(string.Format("shopId in ({0})", shopid));
  6575. }
  6576. string searchType = GetPostString("searchType");
  6577. if (searchType == "wait")
  6578. {
  6579. lw.Add(string.Format("HandleTime is null"));
  6580. }
  6581. if (searchType == "handling")
  6582. {
  6583. lw.Add(string.Format("HandleTime is not null "));
  6584. }
  6585. if (searchType == "back" || searchType == "puBack")
  6586. {
  6587. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6588. }
  6589. if (searchType == "reBack")
  6590. {
  6591. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6592. }
  6593. if (searchType == "moreBack")
  6594. {
  6595. lw.Add(string.Format("backNum > 1"));
  6596. }
  6597. lw.Add(string.Format("(AfterSaleState=5)"));
  6598. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6599. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6600. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6601. writeGridDataTableJson(dStruct.TotalCount, dt);
  6602. }
  6603. public void get_erp_handlingaftersalelist()
  6604. {
  6605. DataStruct dStruct = GetPostStruct();
  6606. List<string> lw = new List<string>();
  6607. int st = 2;
  6608. string tid = GetPostString("ctid");
  6609. if (tid.Length > 0)
  6610. {
  6611. string select_tid = getTidByCtid(tid);
  6612. lw.Add(string.Format("tid='{0}'", select_tid));
  6613. }
  6614. string shopname = GetPostString("shopname");
  6615. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6616. string buyernick = GetPostString("buyer_nick");
  6617. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6618. string sellermemo = GetPostString("seller_memo");
  6619. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6620. string orderState = GetPostString("orderState");
  6621. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6622. string searchType = GetPostString("searchType");
  6623. string afterState = GetPostString("afterstate");
  6624. if (searchType != "documentary")
  6625. {
  6626. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6627. }
  6628. string date1 = GetPostString("date1");
  6629. string date2 = GetPostString("date2");
  6630. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6631. if (dw.Length > 0) lw.Add(dw);
  6632. string price1 = GetPostString("price1");
  6633. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6634. string price2 = GetPostString("price2");
  6635. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6636. //lw.Add(string.Format("IsRefund!={0}", 1));
  6637. string reason = GetPostString("reason");
  6638. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6639. string method = GetPostString("method");
  6640. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6641. string handler = GetPostString("handler");
  6642. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6643. string handledate1 = GetPostString("handledate1");
  6644. string handledate2 = GetPostString("handledate2");
  6645. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6646. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6647. string afterdate1 = GetPostString("afterdate1");
  6648. string afterdate2 = GetPostString("afterdate2");
  6649. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6650. if (afterDate.Length > 0) lw.Add(afterDate);
  6651. string supplier = GetPostString("supplier");
  6652. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6653. string responsible = GetPostString("responsibleman");
  6654. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6655. string customer = GetPostString("customer");
  6656. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6657. string design = GetPostString("design");
  6658. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6659. string afterSaleMemo = GetPostString("afterSaleMemo");
  6660. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6661. string afterMemoType = GetPostString("aftermemotype");
  6662. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6663. string afterresult = GetPostString("afterresult");
  6664. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6665. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6666. string poscode = CurrentUser.UserPost.Post.Code;
  6667. if (poscode != "SysAdmin")
  6668. {
  6669. string shopid = CurrentUser.User.pemShop;
  6670. lw.Add(string.Format("shopId in ({0})", shopid));
  6671. }
  6672. if (searchType == "wait")
  6673. {
  6674. lw.Add(string.Format("HandleTime is null"));
  6675. }
  6676. if (searchType == "documentary")
  6677. {
  6678. lw.Add(string.Format(" AfterSaleState > 2 AND HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' AND AfterSalSend = 0 "));
  6679. afterState = "2";
  6680. }
  6681. if (searchType == "handling")
  6682. {
  6683. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6684. }
  6685. if (searchType == "back" || searchType == "puBack")
  6686. {
  6687. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6688. }
  6689. if (searchType == "reBack")
  6690. {
  6691. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6692. }
  6693. if (afterState.Length <= 0)
  6694. {
  6695. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6696. }
  6697. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6698. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6699. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6700. writeGridDataTableJson(dStruct.TotalCount, dt);
  6701. }
  6702. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6703. //public void get_erp_back_handlingaftersalelist()
  6704. //{
  6705. // DataStruct dStruct = GetPostStruct();
  6706. // List<string> lw = new List<string>();
  6707. // string tid = GetPostString("ctid");
  6708. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6709. // string shopname = GetPostString("shopname");
  6710. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6711. // string buyernick = GetPostString("buyer_nick");
  6712. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6713. // string sellermemo = GetPostString("seller_memo");
  6714. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6715. // string orderState = GetPostString("orderState");
  6716. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6717. // string afterState = GetPostString("afterstate");
  6718. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6719. // string date1 = GetPostString("date1");
  6720. // string date2 = GetPostString("date2");
  6721. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6722. // if (dw.Length > 0) lw.Add(dw);
  6723. // string price1 = GetPostString("price1");
  6724. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6725. // string price2 = GetPostString("price2");
  6726. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6727. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6728. // string reason = GetPostString("reason");
  6729. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6730. // string method = GetPostString("method");
  6731. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6732. // string handler = GetPostString("handler");
  6733. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6734. // string handledate1 = GetPostString("handledate1");
  6735. // string handledate2 = GetPostString("handledate2");
  6736. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6737. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6738. // string afterdate1 = GetPostString("afterdate1");
  6739. // string afterdate2 = GetPostString("afterdate2");
  6740. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6741. // if (afterDate.Length > 0) lw.Add(afterDate);
  6742. // string supplier = GetPostString("supplier");
  6743. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6744. // string responsible = GetPostString("responsibleman");
  6745. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6746. // string customer = GetPostString("customer");
  6747. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6748. // string design = GetPostString("design");
  6749. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6750. // string afterMemoType = GetPostString("aftermemotype");
  6751. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6752. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6753. // if (afterState.Length <= 0)
  6754. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6755. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6756. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6757. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6758. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6759. //}
  6760. public void get_erp_aftersaleverifylist()
  6761. {
  6762. DataStruct dStruct = GetPostStruct();
  6763. List<string> lw = new List<string>();
  6764. string tid = GetPostString("ctid");
  6765. if (tid.Length > 0)
  6766. {
  6767. string select_tid = getTidByCtid(tid);
  6768. lw.Add(string.Format("otid='{0}'", select_tid));
  6769. }
  6770. string shopname = GetPostString("shopname");
  6771. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6772. string buyernick = GetPostString("buyer_nick");
  6773. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6774. string sellermemo = GetPostString("seller_memo");
  6775. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6776. string orderState = GetPostString("orderState");
  6777. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6778. //lw.Add(string.Format("IsRefund!={0}", 1));
  6779. string reason = GetPostString("reason");
  6780. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6781. string method = GetPostString("method");
  6782. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6783. string handler = GetPostString("handler");
  6784. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6785. string handledate1 = GetPostString("handledate1");
  6786. string handledate2 = GetPostString("handledate2");
  6787. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6788. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6789. string finish1 = GetPostString("finishdate1");
  6790. string finish2 = GetPostString("finishdate2");
  6791. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6792. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6793. string supplier = GetPostString("supplier");
  6794. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6795. string responsible = GetPostString("responsibleman");
  6796. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6797. string posCode = CurrentUser.UserPost.Post.Code;
  6798. string vstate = GetPostString("vstate");
  6799. if (vstate.Length > 0)
  6800. {
  6801. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6802. }
  6803. if (posCode == "Supplier")
  6804. {
  6805. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6806. lw.Add(string.Format("VerifyState = 0"));
  6807. lw.Add("type = 1");
  6808. lw.Add(string.Format("AfterSaleState={0}", 3));
  6809. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6810. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6811. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6812. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6813. writeGridDataTableJson(dStruct.TotalCount, dt);
  6814. }
  6815. else if (posCode == "logistics")
  6816. {
  6817. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6818. lw.Add(string.Format("VerifyState = 0"));
  6819. lw.Add("type = 2");
  6820. lw.Add(string.Format("AfterSaleState={0}", 3));
  6821. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6822. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6823. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6824. writeGridDataTableJson(dStruct.TotalCount, dt);
  6825. }
  6826. else
  6827. {
  6828. lw.Add(string.Format("(AfterSaleState = 3)"));
  6829. lw.Add("type = 0");
  6830. string reasonState = GetPostString("reasonState");
  6831. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6832. {
  6833. if (reasonState == "2")
  6834. {
  6835. lw.Add("VerifyState = 3");
  6836. }
  6837. else if (reasonState == "1")
  6838. {
  6839. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6840. }
  6841. else
  6842. {
  6843. lw.Add("VerifyState in (0,3)");
  6844. }
  6845. //不加条件,可以看全部
  6846. }
  6847. 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")
  6848. {
  6849. int orgid = CurrentUser.UserPost.OrgID;
  6850. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6851. if (string.IsNullOrEmpty(manageOrgId))
  6852. {
  6853. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6854. }
  6855. else
  6856. {
  6857. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6858. }
  6859. if (reasonState == "1")
  6860. {
  6861. lw.Add("VerifyState = 3");
  6862. }
  6863. else if (reasonState == "2")
  6864. {
  6865. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6866. }
  6867. else
  6868. {
  6869. }
  6870. }
  6871. else
  6872. {
  6873. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6874. }
  6875. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6876. //{
  6877. // int org_id = CurrentUser.UserPost.OrgID;
  6878. // lw.Add(string.Format("OrgID={0}", org_id));
  6879. //}
  6880. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6881. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6882. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6883. writeGridDataTableJson(dStruct.TotalCount, dt);
  6884. }
  6885. }
  6886. public void get_erp_finishaftersalelist()
  6887. {
  6888. DataStruct dStruct = GetPostStruct();
  6889. List<string> lw = new List<string>();
  6890. int st = 4;
  6891. string tid = GetPostString("ctid");
  6892. if (tid.Length > 0)
  6893. {
  6894. string select_tid = getTidByCtid(tid);
  6895. lw.Add(string.Format("otid='{0}'", select_tid));
  6896. }
  6897. string shopname = GetPostString("shopname");
  6898. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6899. //lw.Add(string.Format("IsRefund!={0}", 1));
  6900. string reason = GetPostString("reason");
  6901. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6902. string method = GetPostString("method");
  6903. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6904. string buyernick = GetPostString("buyer_nick");
  6905. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6906. string handler = GetPostString("handler");
  6907. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6908. string handledate1 = GetPostString("handledate1");
  6909. string handledate2 = GetPostString("handledate2");
  6910. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6911. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6912. string finish1 = GetPostString("finishdate1");
  6913. string finish2 = GetPostString("finishdate2");
  6914. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6915. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6916. string supplier = GetPostString("supplier");
  6917. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6918. string responsible = GetPostString("responsibleman");
  6919. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6920. string vstate = GetPostString("vstate");
  6921. if (vstate.Length > 0)
  6922. {
  6923. if ("3".Equals(vstate))
  6924. {
  6925. lw.Add(string.Format("IsTem=1"));
  6926. }
  6927. else
  6928. {
  6929. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6930. }
  6931. }
  6932. lw.Add(string.Format("AfterSaleState=4"));
  6933. string code = CurrentUser.UserPost.Post.Code;
  6934. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6935. {
  6936. //不加条件,可以看全部
  6937. }
  6938. else if (code == "Supplier")
  6939. {
  6940. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6941. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6942. lw.Add("type = 1");
  6943. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6944. }
  6945. else if (code == "logistics")
  6946. {
  6947. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6948. lw.Add("type = 2");
  6949. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6950. }
  6951. 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")
  6952. {
  6953. lw.Add("type = 0");
  6954. int orgid = CurrentUser.UserPost.OrgID;
  6955. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6956. if (string.IsNullOrEmpty(manageOrgIds))
  6957. {
  6958. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6959. }
  6960. else
  6961. {
  6962. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6963. }
  6964. }
  6965. else
  6966. {
  6967. lw.Add("type = 0");
  6968. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6969. }
  6970. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6971. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6972. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6973. writeGridDataTableJson(dStruct.TotalCount, dt);
  6974. }
  6975. public void handle_erp_aftersale()
  6976. {
  6977. if (UrlPostParmsCheck("ctid"))
  6978. {
  6979. string eid = GetPostString("ctid");
  6980. string responStr = GetPostString("AfterSaleResponsible");
  6981. if (responStr.Length <= 0)
  6982. {
  6983. returnErrorMsg("售后责任人不能为空");
  6984. return;
  6985. }
  6986. bool isDesign = false;
  6987. double designFree = 0.00;
  6988. int responsibleId = 0;
  6989. CeErpTradeCell entity = null;
  6990. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6991. if (entity != null)
  6992. {
  6993. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6994. string afterMethod = GetPostString("AfterSaleMethod");
  6995. if (isNeedNewOrder == 1)
  6996. {
  6997. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6998. bool ishav = true;
  6999. if (newentity == null)
  7000. {
  7001. newentity = entity.Clone() as CeErpTradeCell;
  7002. ishav = false;
  7003. newentity.ctid = "S_" + entity.ctid;
  7004. newentity.OrderState = 0;
  7005. //唯一标识
  7006. newentity.OrderSn = newentity.ctid;
  7007. string orderSn = commonHelper.generateDateTimeRandomNos();
  7008. if (orderSn != "")
  7009. {
  7010. newentity.OrderSn = orderSn;
  7011. }
  7012. }
  7013. newentity.UpdateTime = DateTime.Now;
  7014. newentity.AfterSaleState = 0;
  7015. newentity.AfterSaleMethod = afterMethod;
  7016. if (!ishav)
  7017. {
  7018. string memo_str = newentity.seller_memo;
  7019. memo_str = memo_str.Replace("(", "(");
  7020. memo_str = memo_str.Replace(")", ")");
  7021. int sIndex = memo_str.IndexOf("(");
  7022. int eIndex = memo_str.IndexOf(")");
  7023. if (sIndex == -1 || eIndex == -1)
  7024. {
  7025. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  7026. return;
  7027. }
  7028. string first = memo_str.Substring(0, sIndex + 1);
  7029. string memoCtid = newentity.OrderSn;
  7030. //if (memoCtid.IndexOf("C") != -1)
  7031. //{
  7032. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  7033. //if (CIdx.IndexOf("+") != -1)
  7034. //{
  7035. //CIdx = "C" + CIdx.Split('+')[1];
  7036. //}
  7037. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  7038. //}
  7039. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  7040. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  7041. string newMemo = first + memoCtid + last;
  7042. newentity.seller_memo = newMemo;
  7043. newentity.FinishPlaceTime = null;
  7044. newentity.UnusualTag = 0;
  7045. newentity.UnusualCon = "";
  7046. newentity.UnusualTime = null;
  7047. newentity.AfterSaleMemo = "";
  7048. newentity.AfterSaleMethod = afterMethod;
  7049. newentity.AfterSalePreTime = null;
  7050. newentity.AfterSaleReason = "";
  7051. newentity.AfterSaleResponsible = "";
  7052. newentity.AfterSaleState = 0;
  7053. newentity.AfterSaleTime = null;
  7054. newentity.AfterSaleUserId = 0;
  7055. newentity.AfterSaleSupplierState = 0;
  7056. newentity.LastBillWaybillCode = "";
  7057. newentity.LastBillCpCode = "";
  7058. newentity.FinishAfterSaleTime = null;
  7059. newentity.HandleTime = null;
  7060. newentity.IsSF = 0;
  7061. newentity.IsOldCustomer = 0;
  7062. newentity.UrgencyTime = null;
  7063. newentity.ResponsibleUserId = "";
  7064. newentity.IsVerifyToSupplier = false;
  7065. newentity.payment = 0;
  7066. newentity.CheckMemo = "";
  7067. newentity.OutSid = "";
  7068. newentity.CheckOrderTime = null;
  7069. newentity.MemoOpt = 0;
  7070. newentity.IsReturn = 0;
  7071. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  7072. }
  7073. newentity.isAfterSaleOrder = 1;
  7074. newentity.IsRefund = 0;
  7075. string receiveMobile = GetPostString("receiver_mobile");
  7076. if (receiveMobile.Length > 0)
  7077. {
  7078. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  7079. if (trade != null)
  7080. {
  7081. trade.receiver_name = GetPostString("receiver_name");
  7082. trade.receiver_mobile = receiveMobile;
  7083. trade.receiver_state = GetPostString("receiver_state");
  7084. trade.receiver_city = GetPostString("receiver_city");
  7085. trade.receiver_district = GetPostString("receiver_district");
  7086. trade.receiver_address = GetPostString("receiver_address");
  7087. newentity.IsOffLineOrder = 1;
  7088. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  7089. }
  7090. }
  7091. string st = GetPostString("ToState");
  7092. if (st.Length > 0)
  7093. {
  7094. if (newentity.OrderState <= 3)
  7095. {
  7096. newentity.WaitDesignTime = DateTime.Now;
  7097. newentity.StartDesignTime = null;
  7098. newentity.FinishDesignTime = null;
  7099. newentity.OrderState = 3;
  7100. if (st == "下单员")
  7101. {
  7102. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  7103. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  7104. {
  7105. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  7106. }
  7107. }
  7108. else
  7109. {
  7110. newentity.WaitDesignTime = DateTime.Now;
  7111. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  7112. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7113. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  7114. {
  7115. DataRow user = dt1.Rows[0];
  7116. //找主管
  7117. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  7118. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7119. if (dt != null && dt.Rows.Count > 0)
  7120. {
  7121. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  7122. newentity.DesignUserId = designMr;
  7123. string key = "aftersale_order_" + designMr;
  7124. if (RedisHelper.HasKey(key))
  7125. {
  7126. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  7127. list.Add(newentity.ctid);
  7128. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  7129. }
  7130. }
  7131. //账号正常
  7132. if (user["State"].ToString() == "0")
  7133. {
  7134. newentity.DesignUserId = entity.DesignUserId;
  7135. string key = "aftersale_order_" + entity.DesignUserId;
  7136. if (RedisHelper.HasKey(key))
  7137. {
  7138. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  7139. list.Add(newentity.ctid);
  7140. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  7141. }
  7142. }
  7143. }
  7144. }
  7145. }
  7146. if (entity.IsXianHuo == 1)
  7147. {
  7148. newentity.OrderState = 6;
  7149. entity.FinishPlaceTime = DateTime.Now;
  7150. }
  7151. }
  7152. if (ishav)
  7153. {
  7154. newentity.Update();
  7155. }
  7156. else
  7157. {
  7158. newentity.Create();
  7159. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  7160. newCellExtend.ctid = newentity.ctid;
  7161. newCellExtend.orderFrom = 20;
  7162. newCellExtend.orderType = 30;
  7163. if (st == "下单员")
  7164. {
  7165. }
  7166. else
  7167. {
  7168. newCellExtend.ReprintTime = DateTime.Now;
  7169. }
  7170. newCellExtend.Create();
  7171. }
  7172. if (st != "下单员")
  7173. {
  7174. if (entity.DispatchSort == 2)
  7175. {
  7176. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  7177. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  7178. }
  7179. }
  7180. }
  7181. //处理售后扩展
  7182. string resIdStr = GetPostString("ResponsibleUserId");
  7183. string refundFees = GetPostString("refundFrees");
  7184. int IsComplain = GetPostInt("isComplain");
  7185. int IsBad = GetPostInt("isBad");
  7186. string IsOriginal = GetPostString("isOriginal");
  7187. double diffResultPrice = GetPostDouble("diffResultPrice");
  7188. string textResult = GetPostString("textResult");
  7189. string supplierResponsible = GetPostString("supplierResponsible");
  7190. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  7191. if (ceErpTradeAfterSaleExtend == null)
  7192. {
  7193. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7194. ceErpTradeAfterSaleExtend.tid = eid;
  7195. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7196. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7197. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7198. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7199. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7200. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7201. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7202. ceErpTradeAfterSaleExtend.Create();
  7203. }
  7204. else
  7205. {
  7206. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  7207. {
  7208. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  7209. }
  7210. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7211. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7212. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7213. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7214. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7215. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7216. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7217. ceErpTradeAfterSaleExtend.Update();
  7218. }
  7219. int gysid = GetPostInt("ResponsibleSupId");
  7220. if (entity.AfterSaleUserId == 0)
  7221. {
  7222. entity.AfterSaleUserId = CurrentUser.UserID;
  7223. }
  7224. entity.ResponsibleUserId = resIdStr;
  7225. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  7226. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  7227. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  7228. {
  7229. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7230. int backNum = 0;
  7231. if (number != null)
  7232. {
  7233. backNum = number.BackNum;
  7234. }
  7235. char[] separator = { ',' };
  7236. string[] sArray = resIdStr.Split(separator);
  7237. string[] refundFreeList = { };
  7238. if (refundFees.Length > 0)
  7239. {
  7240. refundFreeList = refundFees.Split(separator);
  7241. }
  7242. int index = -1;
  7243. List<int> responsibleIds = new List<int>();
  7244. foreach (string i in sArray)
  7245. {
  7246. index++;
  7247. if (i.Length <= 0) continue;
  7248. char[] separator2 = { '_' };
  7249. string idstr = i.Split(separator2)[0];
  7250. string idtype = i.Split(separator2)[1];
  7251. double refudFree = 0;
  7252. if (refundFreeList.Length > 0)
  7253. {
  7254. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  7255. }
  7256. if (idtype == "s")
  7257. {
  7258. isDesign = true;
  7259. designFree = refudFree;
  7260. }
  7261. int userId = Convert.ToInt32(idstr);
  7262. int type = 0;
  7263. if (idtype == "g")
  7264. {
  7265. type = 1;
  7266. }
  7267. if (idtype == "w")
  7268. {
  7269. type = 2;
  7270. }
  7271. if (idtype == "t")
  7272. {
  7273. type = 3;
  7274. }
  7275. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7276. if (ceErpTradeResponsible == null)
  7277. {
  7278. ceErpTradeResponsible = new CeErpTradeResponsible();
  7279. ceErpTradeResponsible.tid = eid;
  7280. ceErpTradeResponsible.UserId = userId;
  7281. ceErpTradeResponsible.createdTime = DateTime.Now;
  7282. ceErpTradeResponsible.type = type;
  7283. if (type == 1)
  7284. {
  7285. ceErpTradeResponsible.IsSup = 1;
  7286. }
  7287. if (type == 2)
  7288. {
  7289. ceErpTradeResponsible.IsFlow = 1;
  7290. }
  7291. }
  7292. int state = 0;
  7293. //已认可的不需要再次认可
  7294. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7295. {
  7296. state = 1;
  7297. }
  7298. ceErpTradeResponsible.RefundFee = refudFree;
  7299. ceErpTradeResponsible.VerifyState = state;
  7300. if (userId == 2125 || idtype == "w")
  7301. {
  7302. ceErpTradeResponsible.VerifyState = 1;
  7303. }
  7304. if (idtype == "w" && userId == 101)
  7305. {
  7306. ceErpTradeResponsible.VerifyState = state;
  7307. }
  7308. if (ceErpTradeResponsible.ID > 0)
  7309. {
  7310. ceErpTradeResponsible.Update();
  7311. }
  7312. else
  7313. {
  7314. ceErpTradeResponsible.Create();
  7315. }
  7316. if (isDesign)
  7317. {
  7318. responsibleId = ceErpTradeResponsible.ID;
  7319. }
  7320. responsibleIds.Add(ceErpTradeResponsible.ID);
  7321. }
  7322. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7323. CeErpTradeResponsible.NumByTid(backNum, eid);
  7324. }
  7325. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7326. if (ceErpTradeCellExtend != null)
  7327. {
  7328. ceErpTradeCellExtend.returnVisit = 0;
  7329. ceErpTradeCellExtend.Update();
  7330. }
  7331. if (entity.HandleTime != null)
  7332. {
  7333. if (entity.AfterSaleState == 1)
  7334. {
  7335. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7336. }
  7337. else
  7338. {
  7339. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7340. }
  7341. }
  7342. else
  7343. {
  7344. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7345. entity.HandleTime = DateTime.Now;
  7346. }
  7347. bool isCompale = false;
  7348. if (entity.AfterSaleState == 5)
  7349. {
  7350. isCompale = true;
  7351. entity.AfterSaleState = 3;
  7352. }
  7353. entity.AfterSaleSupplierState = 0;
  7354. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7355. {
  7356. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7357. }
  7358. string sImgs = GetPostString("img");
  7359. entity.AfterSaleSupplierImg = sImgs;
  7360. entity.supRefundType = GetPostString("supRefundType");
  7361. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7362. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7363. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7364. entity.AfterSaleMemoType = GetPostString("MemoType");
  7365. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7366. {
  7367. //entity.AfterSaleSupplierState = 2;
  7368. }
  7369. string df = GetPostString("DeductFee");
  7370. if (df == "")
  7371. {
  7372. df = "0";
  7373. }
  7374. string rf = GetPostString("RefundFee");
  7375. if (rf == "")
  7376. {
  7377. rf = "0";
  7378. }
  7379. string pm = GetPostString("AfterSalePayment");
  7380. if (pm == "")
  7381. {
  7382. pm = "0";
  7383. }
  7384. entity.AfterSalePayment = Convert.ToDouble(pm);
  7385. entity.DeductFee = Convert.ToDouble(df);
  7386. entity.RefundFee = Convert.ToDouble(rf);
  7387. entity.UpdateTime = DateTime.Now;
  7388. entity.Update();
  7389. string toState = GetPostString("ToState");
  7390. string original = GetPostString("isOriginal");
  7391. ApiVo apiVo = new ApiVo();
  7392. apiVo.orderNumber = entity.ctid;
  7393. apiVo.actionName = "afterDesign";
  7394. apiVo.orderRemarks = entity.AfterSaleMethod;
  7395. apiVo.reasonRemarks = entity.AfterSaleReason;
  7396. apiVo.isDesign = isDesign;
  7397. apiVo.designFree = designFree;
  7398. apiVo.responsibleId = responsibleId;
  7399. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7400. if (toState == "设计师")
  7401. {
  7402. apiVo.isOriginal = Convert.ToBoolean(original);
  7403. }
  7404. designHelper.API_WorkCore(apiVo);//afterDesign
  7405. CeErpMethod methodSql = new CeErpMethod();
  7406. methodSql.con = entity.AfterSaleMethod;
  7407. methodSql.addTime = DateTime.Now;
  7408. methodSql.Create();
  7409. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7410. CeErpMethod.ExecuteNonQuery(delsql);
  7411. if (isCompale)
  7412. {
  7413. aftersale_data_change(entity.ctid);
  7414. }
  7415. returnSuccessMsg("操作成功!");
  7416. return;
  7417. }
  7418. returnErrorMsg("找不到订单记录");
  7419. }
  7420. }
  7421. public void ins_erp_toresponsible()
  7422. {
  7423. if (UrlPostParmsCheck("ctid"))
  7424. {
  7425. string eid = GetPostString("ctid");
  7426. CeErpTradeCell entity = null;
  7427. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7428. if (entity != null)
  7429. {
  7430. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7431. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7432. {
  7433. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7434. return;
  7435. }
  7436. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7437. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7438. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7439. if (entity.AfterSalePreTime == null)
  7440. {
  7441. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7442. {
  7443. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7444. }
  7445. }
  7446. entity.AfterSalePreTime = DateTime.Now;
  7447. //预完成给售后主管审核客户问题直接完成
  7448. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7449. {
  7450. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7451. {
  7452. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7453. }
  7454. }
  7455. ceErpTradeAfterSaleExtend.DisagreeTime = null;
  7456. ceErpTradeAfterSaleExtend.Update();
  7457. entity.AfterSaleUserId = CurrentUser.UserID;
  7458. entity.AfterSaleState = 2;
  7459. entity.UpdateTime = DateTime.Now;
  7460. entity.Update();
  7461. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7462. aftersale_data_change(entity.ctid);
  7463. returnSuccessMsg("操作成功!");
  7464. return;
  7465. }
  7466. returnErrorMsg("找不到订单记录");
  7467. }
  7468. }
  7469. public void cancel_erp_aftersaleanddelnew()
  7470. {
  7471. if (UrlPostParmsCheck("ctid"))
  7472. {
  7473. string eid = GetPostString("ctid");
  7474. CeErpTradeCell entity = null;
  7475. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7476. if (entity != null)
  7477. {
  7478. entity.AfterSaleState = 0;
  7479. entity.AfterSaleReason = "";
  7480. entity.AfterSaleMethod = "";
  7481. entity.AfterSaleMemo = "";
  7482. entity.AfterSaleResponsible = "";
  7483. entity.ResponsibleUserId = "";
  7484. entity.DeductFee = 0;
  7485. entity.RefundFee = 0;
  7486. entity.IsArbitrate = 0;
  7487. CeErpTradeResponsible.DelByTid(eid, -1);
  7488. entity.Update();
  7489. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7490. if (after != null)
  7491. {
  7492. if (after.OrderState < 5)
  7493. CeErpTradeCell.DelByCtid("S_" + eid);
  7494. }
  7495. returnSuccessMsg("操作成功!");
  7496. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7497. return;
  7498. }
  7499. returnErrorMsg("找不到订单记录");
  7500. }
  7501. }
  7502. public void get_erp_aftersale_pregather()
  7503. {
  7504. List<string> lw = new List<string>();
  7505. int st = GetInt("st");
  7506. string tid = GetPostString("ctid");
  7507. if (tid.Length > 0)
  7508. {
  7509. string select_tid = getTidByCtid(tid);
  7510. lw.Add(string.Format("tid='{0}'", select_tid));
  7511. }
  7512. string shopname = GetPostString("shopname");
  7513. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7514. string buyernick = GetPostString("buyer_nick");
  7515. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7516. string sellermemo = GetPostString("seller_memo");
  7517. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7518. string orderState = GetPostString("orderState");
  7519. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7520. string reason = GetPostString("reason");
  7521. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7522. string method = GetPostString("method");
  7523. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7524. string handler = GetPostString("handler");
  7525. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7526. string handledate1 = GetPostString("handledate1");
  7527. string handledate2 = GetPostString("handledate2");
  7528. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7529. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7530. string supplier = GetPostString("supplier");
  7531. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7532. string responsible = GetPostString("responsibleman");
  7533. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7534. string customer = GetPostString("customer");
  7535. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7536. string design = GetPostString("design");
  7537. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7538. string afterMemoType = GetPostString("aftermemotype");
  7539. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7540. string afterSaleMemo = GetPostString("afterSaleMemo");
  7541. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7542. string afterresult = GetPostString("afterresult");
  7543. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7544. string poscode = CurrentUser.UserPost.Post.Code;
  7545. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7546. {
  7547. string shopid = CurrentUser.User.pemShop;
  7548. lw.Add(string.Format("shopId in ({0})", shopid));
  7549. }
  7550. var mainwhere = string.Join(" and ", lw.ToArray());
  7551. string ro_json = "";
  7552. string type = GetPostString("gather_type");
  7553. int number = 0;
  7554. if (poscode == "AfterSale")
  7555. {
  7556. //处理中
  7557. if (type == "Handling")
  7558. {
  7559. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7560. DataTable dt = null;
  7561. try
  7562. {
  7563. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7564. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7565. }
  7566. catch (Exception e)
  7567. {
  7568. dt = new DataTable();
  7569. }
  7570. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7571. return;
  7572. }
  7573. if (type == "Wait")
  7574. {
  7575. //待处理
  7576. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7577. DataTable dt1 = null;
  7578. try
  7579. {
  7580. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7581. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7582. }
  7583. catch (Exception e)
  7584. {
  7585. dt1 = new DataTable();
  7586. }
  7587. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7588. return;
  7589. }
  7590. if (type == "back")
  7591. {
  7592. //打回
  7593. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7594. DataTable dt2 = null;
  7595. try
  7596. {
  7597. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7598. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7599. }
  7600. catch (Exception e)
  7601. {
  7602. dt2 = new DataTable();
  7603. }
  7604. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7605. return;
  7606. }
  7607. if (type == "preCompletion")
  7608. {
  7609. //预完成
  7610. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7611. DataTable dt3 = null;
  7612. try
  7613. {
  7614. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7615. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7616. }
  7617. catch (Exception e)
  7618. {
  7619. dt3 = new DataTable();
  7620. }
  7621. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7622. return;
  7623. }
  7624. if (type == "documentary")
  7625. {
  7626. //跟单中
  7627. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7628. DataTable dt4 = null;
  7629. try
  7630. {
  7631. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7632. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7633. }
  7634. catch (Exception e)
  7635. {
  7636. dt4 = new DataTable();
  7637. }
  7638. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7639. return;
  7640. }
  7641. if (type == "reBack")
  7642. {
  7643. //被打回
  7644. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7645. DataTable dt1 = null;
  7646. try
  7647. {
  7648. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7649. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7650. }
  7651. catch (Exception e)
  7652. {
  7653. dt1 = new DataTable();
  7654. }
  7655. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7656. return;
  7657. }
  7658. }
  7659. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7660. {
  7661. if (type == "puBack")
  7662. {
  7663. //退回
  7664. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7665. DataTable dt = null;
  7666. try
  7667. {
  7668. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7669. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7670. }
  7671. catch (Exception e)
  7672. {
  7673. dt = new DataTable();
  7674. }
  7675. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7676. return;
  7677. }
  7678. if (type == "reBack")
  7679. {
  7680. //打回
  7681. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7682. DataTable dt1 = null;
  7683. try
  7684. {
  7685. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7686. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7687. }
  7688. catch (Exception e)
  7689. {
  7690. dt1 = new DataTable();
  7691. }
  7692. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7693. return;
  7694. }
  7695. if (type == "examEd")
  7696. {
  7697. //已审核
  7698. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7699. DataTable dt2 = null;
  7700. try
  7701. {
  7702. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7703. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7704. }
  7705. catch (Exception e)
  7706. {
  7707. dt2 = new DataTable();
  7708. }
  7709. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7710. return;
  7711. }
  7712. if (type == "waitExam")
  7713. {
  7714. //待审核
  7715. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7716. DataTable dt3 = null;
  7717. try
  7718. {
  7719. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7720. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7721. }
  7722. catch (Exception e)
  7723. {
  7724. dt3 = new DataTable();
  7725. }
  7726. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7727. return;
  7728. }
  7729. if (type == "Handling")
  7730. {
  7731. //处理中
  7732. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7733. DataTable dt4 = null;
  7734. try
  7735. {
  7736. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7737. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7738. }
  7739. catch (Exception e)
  7740. {
  7741. dt4 = new DataTable();
  7742. }
  7743. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7744. return;
  7745. }
  7746. if (type == "Wait")
  7747. {
  7748. //待处理
  7749. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7750. DataTable dt5 = null;
  7751. try
  7752. {
  7753. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7754. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7755. }
  7756. catch (Exception e)
  7757. {
  7758. dt5 = new DataTable();
  7759. }
  7760. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7761. return;
  7762. }
  7763. if (type == "documentary")
  7764. {
  7765. //跟单中
  7766. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7767. DataTable dt6 = null;
  7768. try
  7769. {
  7770. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7771. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7772. }
  7773. catch (Exception e)
  7774. {
  7775. dt6 = new DataTable();
  7776. }
  7777. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7778. return;
  7779. }
  7780. }
  7781. returnSuccess(ro_json);
  7782. }
  7783. public void end_erp_aftersale()
  7784. {
  7785. if (UrlPostParmsCheck("ctid"))
  7786. {
  7787. string eid = GetPostString("ctid");
  7788. CeErpTradeCell entity = null;
  7789. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7790. if (entity != null)
  7791. {
  7792. string stype = GetPostString("stype");
  7793. string typeStr = stype;
  7794. entity.AfterSaleState = 4;
  7795. entity.FinishAfterSaleTime = DateTime.Now;
  7796. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7797. entity.Update();
  7798. ApiVo apiVo = new ApiVo();
  7799. apiVo.orderNumber = entity.ctid;
  7800. apiVo.actionName = "afterOver";
  7801. designHelper.API_WorkCore(apiVo); //afterOver
  7802. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7803. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7804. CeErpSukuraData.createInfo(entity.ctid, 8);
  7805. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7806. returnSuccessMsg("操作成功!");
  7807. return;
  7808. }
  7809. returnErrorMsg("找不到订单记录");
  7810. }
  7811. }
  7812. public void ins_erp_finishaftersale()
  7813. {
  7814. if (UrlPostParmsCheck("id"))
  7815. {
  7816. string eid = GetPostString("id");
  7817. CeErpTradeResponsible entity = null;
  7818. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7819. if (entity != null)
  7820. {
  7821. entity.VerifyState = 1;
  7822. entity.VerifyTime = DateTime.Now;
  7823. entity.Update();
  7824. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7825. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7826. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7827. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7828. if (dt.Rows.Count <= 0)
  7829. {
  7830. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7831. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7832. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7833. CeErpSukuraData.createInfo(entity.tid, 8);
  7834. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7835. {
  7836. CeErpDesignerBill.Del(entity.tid);
  7837. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7838. }
  7839. }
  7840. returnSuccessMsg("操作成功!");
  7841. return;
  7842. }
  7843. returnErrorMsg("找不到订单记录");
  7844. }
  7845. }
  7846. public void upd_erp_arbitrateaftersale()
  7847. {
  7848. if (UrlPostParmsCheck("id"))
  7849. {
  7850. string eid = GetPostString("id");
  7851. CeErpTradeResponsible entity = null;
  7852. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7853. if (entity != null)
  7854. {
  7855. entity.IsArbitrate = 1;
  7856. entity.ArbitradeMemo = GetPostString("reason");
  7857. entity.VerifyState = 2;
  7858. entity.Update();
  7859. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7860. if (tradecell != null)
  7861. {
  7862. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7863. tradecell.IsArbitrate = 1;
  7864. tradecell.Update();
  7865. }
  7866. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7867. returnSuccessMsg("操作成功!");
  7868. return;
  7869. }
  7870. returnErrorMsg("找不到订单记录");
  7871. }
  7872. }
  7873. public void upd_erp_backaftersale()
  7874. {
  7875. if (UrlPostParmsCheck("tid"))
  7876. {
  7877. string eid = GetPostString("tid");
  7878. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7879. int backNum = 0;
  7880. if (number != null)
  7881. {
  7882. backNum = number.BackNum;
  7883. }
  7884. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7885. CeErpTradeCell entity = null;
  7886. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7887. if (entity != null)
  7888. {
  7889. entity.AfterSaleBackReason = GetPostString("backreason");
  7890. entity.AfterSaleState = 1;
  7891. entity.AfterSaleSupplierState = 0;
  7892. entity.UpdateTime = DateTime.Now;
  7893. entity.Update();
  7894. returnSuccessMsg("操作成功!");
  7895. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7896. return;
  7897. }
  7898. returnErrorMsg("找不到订单记录");
  7899. }
  7900. }
  7901. public void get_erp_supplieraftersalelist()
  7902. {
  7903. DataStruct dStruct = GetPostStruct();
  7904. List<string> lw = new List<string>();
  7905. string tid = GetPostString("ctid");
  7906. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7907. string shopname = GetPostString("shopname");
  7908. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7909. string buyernick = GetPostString("buyer_nick");
  7910. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7911. string sellermemo = GetPostString("seller_memo");
  7912. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7913. string orderState = GetPostString("orderState");
  7914. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7915. string afterState = GetPostString("afterstate");
  7916. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7917. string date1 = GetPostString("date1");
  7918. string date2 = GetPostString("date2");
  7919. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7920. if (dw.Length > 0) lw.Add(dw);
  7921. string price1 = GetPostString("price1");
  7922. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7923. string price2 = GetPostString("price2");
  7924. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7925. string reason = GetPostString("reason");
  7926. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7927. string method = GetPostString("method");
  7928. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7929. string handledate1 = GetPostString("handledate1");
  7930. string handledate2 = GetPostString("handledate2");
  7931. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7932. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7933. string handler = GetPostString("handler");
  7934. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7935. string afterdate1 = GetPostString("afterdate1");
  7936. string afterdate2 = GetPostString("afterdate2");
  7937. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7938. if (afterDate.Length > 0) lw.Add(afterDate);
  7939. string customer = GetPostString("customer");
  7940. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7941. string design = GetPostString("design");
  7942. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7943. string afterMemoType = GetPostString("aftermemotype");
  7944. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7945. string vstate = GetPostString("vstate");
  7946. if (vstate.Length > 0)
  7947. {
  7948. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7949. }
  7950. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7951. string supplier = GetPostString("supplier");
  7952. int supid = commonHelper.getSupplierIDByName(supplier);
  7953. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7954. string posCode = CurrentUser.UserPost.Post.Code;
  7955. if (posCode == "Supplier")
  7956. {
  7957. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7958. }
  7959. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7960. {
  7961. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7962. }
  7963. else
  7964. {
  7965. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7966. }
  7967. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7968. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7969. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7970. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7971. writeGridDataTableJson(dStruct.TotalCount, dt);
  7972. }
  7973. public void upd_erp_supverifyaftersale()
  7974. {
  7975. if (UrlPostParmsCheck("id"))
  7976. {
  7977. string id = GetPostString("id");
  7978. int st = GetPostInt("afterstate");
  7979. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7980. CeErpTradeCell entity = null;
  7981. if (ceErpTradeResponsible != null)
  7982. {
  7983. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7984. }
  7985. string afmemo = GetPostString("supmemo");
  7986. string image = GetPostString("image");
  7987. if (entity != null)
  7988. {
  7989. entity.AfterSaleSupplierState = st;
  7990. entity.AfterSaleSupplierMemo = afmemo;
  7991. if (st == 1)
  7992. {
  7993. ceErpTradeResponsible.VerifyState = 1;
  7994. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7995. ceErpTradeResponsible.Update();
  7996. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7997. if (isAll)
  7998. {
  7999. entity.AfterSaleState = 4;
  8000. entity.FinishAfterSaleTime = DateTime.Now;
  8001. }
  8002. }
  8003. else
  8004. {
  8005. CeErpTradeResponsible.dateByTid(entity.ctid);
  8006. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  8007. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  8008. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  8009. if (num < 1)
  8010. {
  8011. entity.AfterSaleState = 1;
  8012. }
  8013. else
  8014. {
  8015. entity.AfterSaleState = 5;
  8016. }
  8017. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  8018. if (ceErpTradeAfterSaleExtend != null)
  8019. {
  8020. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8021. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  8022. ceErpTradeAfterSaleExtend.Update();
  8023. }
  8024. else
  8025. {
  8026. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  8027. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  8028. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8029. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  8030. ceErpTradeAfterSaleExtend.Create();
  8031. }
  8032. }
  8033. if (entity.AfterSaleState == 4)
  8034. {
  8035. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  8036. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  8037. {
  8038. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  8039. }
  8040. ApiVo apiVo = new ApiVo();
  8041. apiVo.orderNumber = entity.ctid;
  8042. apiVo.actionName = "afterOver";
  8043. designHelper.API_WorkCore(apiVo); //afterOver
  8044. }
  8045. entity.UpdateTime = DateTime.Now;
  8046. entity.Update();
  8047. returnSuccessMsg("操作成功!");
  8048. CeErpSukuraData.createInfo(entity.ctid, 8);
  8049. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  8050. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  8051. return;
  8052. }
  8053. returnErrorMsg("找不到订单记录");
  8054. }
  8055. }
  8056. public void upd_erp_masteraftersale()
  8057. {
  8058. if (UrlPostParmsCheck("id"))
  8059. {
  8060. string id = GetPostString("id");
  8061. int st = GetPostInt("afterstate");
  8062. string afmemo = GetPostString("supmemo");
  8063. string image = GetPostString("image");
  8064. string textResult = GetPostString("textResult");
  8065. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  8066. if (ceErpTradeResponsible != null)
  8067. {
  8068. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  8069. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  8070. ceErpTradeResponsible.Update();
  8071. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  8072. if (entity != null)
  8073. {
  8074. entity.AfterSaleSupplierState = st;
  8075. entity.AfterSaleSupplierMemo = afmemo;
  8076. if (st == 1)
  8077. {
  8078. }
  8079. else
  8080. {
  8081. CeErpTradeResponsible.dateByTid(entity.ctid);
  8082. //退回到售后
  8083. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  8084. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  8085. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  8086. if (num <= 1)
  8087. {
  8088. entity.AfterSaleState = 1;
  8089. }
  8090. else
  8091. {
  8092. entity.AfterSaleState = 5;
  8093. }
  8094. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  8095. if (ceErpTradeAfterSaleExtend != null)
  8096. {
  8097. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8098. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  8099. ceErpTradeAfterSaleExtend.Update();
  8100. }
  8101. else
  8102. {
  8103. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  8104. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  8105. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8106. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  8107. ceErpTradeAfterSaleExtend.Create();
  8108. }
  8109. }
  8110. entity.UpdateTime = DateTime.Now;
  8111. entity.Update();
  8112. returnSuccessMsg("操作成功!");
  8113. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  8114. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  8115. return;
  8116. }
  8117. }
  8118. returnErrorMsg("找不到订单记录");
  8119. }
  8120. }
  8121. public void upd_erp_personaftersale()
  8122. {
  8123. if (UrlPostParmsCheck("id"))
  8124. {
  8125. //林小连
  8126. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  8127. {
  8128. upd_erp_masteraftersale();
  8129. return;
  8130. }
  8131. string id = GetPostString("id");
  8132. int st = GetPostInt("afterstate");
  8133. string afmemo = GetPostString("supmemo");
  8134. string image = GetPostString("image");
  8135. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  8136. if (ceErpTradeResponsible != null)
  8137. {
  8138. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  8139. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  8140. ceErpTradeResponsible.Update();
  8141. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  8142. if (entity != null)
  8143. {
  8144. entity.AfterSaleSupplierMemo = afmemo;
  8145. entity.AfterSaleSupplierState = st;
  8146. if (st == 1)
  8147. {
  8148. bool isAll = commonHelper.tradeResponsibleAll(entity);
  8149. if (isAll)
  8150. {
  8151. entity.AfterSaleState = 4;
  8152. entity.FinishAfterSaleTime = DateTime.Now;
  8153. }
  8154. }
  8155. else
  8156. {
  8157. CeErpTradeResponsible.dateByTid(entity.ctid);
  8158. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  8159. if (ceErpTradeAfterSaleExtend != null)
  8160. {
  8161. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8162. ceErpTradeAfterSaleExtend.Update();
  8163. }
  8164. else
  8165. {
  8166. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  8167. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  8168. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8169. ceErpTradeAfterSaleExtend.Create();
  8170. }
  8171. //退回到主管
  8172. //entity.AfterSaleState = 2;
  8173. }
  8174. if (entity.AfterSaleState == 4)
  8175. {
  8176. ApiVo apiVo = new ApiVo();
  8177. apiVo.orderNumber = entity.ctid;
  8178. apiVo.actionName = "afterOver";
  8179. designHelper.API_WorkCore(apiVo); //afterOver
  8180. }
  8181. entity.UpdateTime = DateTime.Now;
  8182. entity.Update();
  8183. returnSuccessMsg("操作成功!");
  8184. CeErpSukuraData.createInfo(entity.ctid, 8);
  8185. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  8186. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  8187. return;
  8188. }
  8189. }
  8190. returnErrorMsg("找不到订单记录");
  8191. }
  8192. }
  8193. public void set_erp_supplierrefundtag()
  8194. {
  8195. if (UrlPostParmsCheck("ctid"))
  8196. {
  8197. string eid = GetPostString("ctid");
  8198. CeErpTradeCell entity = null;
  8199. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8200. if (entity != null)
  8201. {
  8202. entity.IsSupplierRefund = GetPostInt("tag");
  8203. entity.Update();
  8204. returnSuccessMsg("操作成功!");
  8205. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  8206. return;
  8207. }
  8208. returnErrorMsg("找不到订单记录");
  8209. }
  8210. }
  8211. public void get_erp_refundlist()
  8212. {
  8213. DataStruct dStruct = GetPostStruct();
  8214. List<string> lw = new List<string>();
  8215. string tid = GetPostString("tid");
  8216. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8217. //string rid = GetPostString("refund_id");
  8218. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  8219. string shopname = GetPostString("shopname");
  8220. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8221. string buyernick = GetPostString("buyer_nick");
  8222. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8223. string customer = GetPostString("customer");
  8224. if (customer.Length > 0) lw.Add(string.Format("CustomerUserName = '{0}'", customer));
  8225. string design = GetPostString("design");
  8226. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8227. string sellermemo = GetPostString("seller_memo");
  8228. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8229. //string date1 = GetPostString("date1");
  8230. //string date2 = GetPostString("date2");
  8231. //string dateType = GetPostString("dateType");
  8232. //if (dateType.Length > 0)
  8233. //{
  8234. // if (dateType == "1001") dateType = "0";
  8235. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  8236. // if (searchDT.Count == 2)
  8237. // {
  8238. // date1 = searchDT[0].ToString();
  8239. // date2 = searchDT[1].ToString();
  8240. // }
  8241. //}
  8242. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8243. //if (dw.Length > 0) lw.Add(dw);
  8244. string redate1 = GetPostString("refunddate1");
  8245. string redate2 = GetPostString("refunddate2");
  8246. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8247. if (dwdate.Length > 0) lw.Add(dwdate);
  8248. string price1 = GetPostString("price1");
  8249. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8250. string price2 = GetPostString("price2");
  8251. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8252. string ispartrefund = GetPostString("ispartrefund");
  8253. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8254. string refundState = GetPostString("refundvstate");
  8255. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  8256. int st = GetInt("st");
  8257. if (st == 2) //待确认列表中,把state=3已确认的也显示
  8258. {
  8259. string responsible = GetPostString("responsibleman");
  8260. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8261. lw.Add(string.Format("RefundState>={0}", st));
  8262. string code = CurrentUser.UserPost.Post.Code;
  8263. if (code == "CustomerService")
  8264. {
  8265. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8266. }
  8267. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8268. {
  8269. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8270. }
  8271. else if (code == "Place" || code == "PlaceMr")
  8272. {
  8273. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8274. }
  8275. dStruct.Order = "RefundState asc,created desc";
  8276. }
  8277. else if (st == 10)
  8278. {
  8279. string responsible = GetPostString("responsibleman");
  8280. if (responsible == "空白")
  8281. {
  8282. lw.Add(string.Format("ResponsibleUserName = ''"));
  8283. }
  8284. else if (responsible.Length > 0)
  8285. {
  8286. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8287. }
  8288. lw.Add(string.Format("RefundState>=0"));
  8289. dStruct.Order = "created desc";
  8290. }
  8291. else
  8292. {
  8293. string responsible = GetPostString("responsibleman");
  8294. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8295. lw.Add(string.Format("RefundState={0}", st));
  8296. dStruct.Order = "created desc";
  8297. }
  8298. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8299. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8300. if (dt != null)
  8301. {
  8302. dt.Columns.Add("refund_fees");
  8303. foreach (DataRow dr in dt.Rows)
  8304. {
  8305. String status = dr["status"].ToString();
  8306. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8307. {
  8308. dr["refund_fees"] = dr["refund_fee"];
  8309. }
  8310. else
  8311. {
  8312. dr["refund_fees"] = "0.0";
  8313. }
  8314. }
  8315. }
  8316. writeGridDataTableJson(dStruct.TotalCount, dt);
  8317. }
  8318. public void get_erp_refunddesignlist()
  8319. {
  8320. DataStruct dStruct = GetPostStruct();
  8321. List<string> lw = new List<string>();
  8322. string tid = GetPostString("tid");
  8323. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8324. string shopname = GetPostString("shopname");
  8325. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8326. string buyernick = GetPostString("buyer_nick");
  8327. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8328. string customer = GetPostString("customer");
  8329. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8330. string design = GetPostString("design");
  8331. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8332. string sellermemo = GetPostString("seller_memo");
  8333. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8334. string redate1 = GetPostString("refunddate1");
  8335. string redate2 = GetPostString("refunddate2");
  8336. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8337. if (dwdate.Length > 0) lw.Add(dwdate);
  8338. string price1 = GetPostString("price1");
  8339. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8340. string price2 = GetPostString("price2");
  8341. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8342. string ispartrefund = GetPostString("ispartrefund");
  8343. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8344. string designerorg = GetPostString("designerorg");
  8345. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8346. string refundState = GetPostString("refundState");
  8347. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8348. int myOrgid = CurrentUser.UserPost.OrgID;
  8349. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8350. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8351. {
  8352. if (CurrentUser.User.TeamIds.Length > 0)
  8353. {
  8354. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8355. }
  8356. else
  8357. {
  8358. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8359. }
  8360. }
  8361. else if ("SysAdmin".Equals(myOrgCode))
  8362. {
  8363. }
  8364. else
  8365. {
  8366. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8367. {
  8368. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8369. }
  8370. else
  8371. {
  8372. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8373. }
  8374. }
  8375. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8376. dStruct.Order = "created desc";
  8377. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8378. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8379. dt.Columns.Add("refund_fees");
  8380. foreach (DataRow dr in dt.Rows)
  8381. {
  8382. String status = dr["status"].ToString();
  8383. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8384. {
  8385. dr["refund_fees"] = dr["refund_fee"];
  8386. }
  8387. else
  8388. {
  8389. dr["refund_fees"] = "0.0";
  8390. }
  8391. }
  8392. writeGridDataTableJson(dStruct.TotalCount, dt);
  8393. }
  8394. public void handle_erp_refundtag()
  8395. {
  8396. if (UrlPostParmsCheck("refund_id"))
  8397. {
  8398. string eid = GetPostString("refund_id");
  8399. string respMan = GetPostString("ResponsibleName");
  8400. if (respMan.Length <= 0)
  8401. {
  8402. returnErrorMsg("责任人不能为空");
  8403. return;
  8404. }
  8405. CeErpTradeRefund entity = null;
  8406. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8407. if (entity != null)
  8408. {
  8409. entity.ResponsibleUserName = respMan;
  8410. string userid = GetPostString("ResponsibleUserId");
  8411. if (userid.Length > 0)
  8412. {
  8413. entity.ResponsibleUserId = userid;
  8414. }
  8415. entity.Memo = GetPostString("Memo");
  8416. if (respMan.IndexOf("客服") != -1 ||
  8417. respMan.IndexOf("设计师") != -1 ||
  8418. respMan.IndexOf("下单员") != -1)
  8419. {
  8420. entity.RefundState = 2;
  8421. }
  8422. else
  8423. {
  8424. entity.RefundState = 3;
  8425. }
  8426. entity.modified = DateTime.Now;
  8427. entity.Update();
  8428. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8429. returnSuccessMsg("操作成功!");
  8430. return;
  8431. }
  8432. returnErrorMsg("找不到订单记录");
  8433. }
  8434. }
  8435. public void handle_erp_designrefundtag()
  8436. {
  8437. if (UrlPostParmsCheck("refund_id"))
  8438. {
  8439. string eid = GetPostString("refund_id");
  8440. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8441. if (ceErpTradeCellExtend == null)
  8442. {
  8443. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8444. ceErpTradeCellExtend.ctid = eid;
  8445. }
  8446. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8447. if (ceErpTradeCellExtend.ID > 0)
  8448. {
  8449. ceErpTradeCellExtend.Update();
  8450. }
  8451. else
  8452. {
  8453. ceErpTradeCellExtend.Create();
  8454. }
  8455. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8456. returnSuccessMsg("操作成功!");
  8457. return;
  8458. }
  8459. returnErrorMsg("找不到订单记录");
  8460. }
  8461. public void upd_erp_refundverify()
  8462. {
  8463. if (UrlPostParmsCheck("refund_id"))
  8464. {
  8465. string eid = GetPostString("refund_id");
  8466. CeErpTradeRefund entity = null;
  8467. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8468. if (entity != null)
  8469. {
  8470. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8471. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8472. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8473. {
  8474. entity.RefundState = 2;
  8475. }
  8476. else
  8477. {
  8478. entity.RefundState = 3;
  8479. }
  8480. entity.Update();
  8481. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8482. returnSuccessMsg("操作成功!");
  8483. return;
  8484. }
  8485. returnErrorMsg("找不到订单记录");
  8486. }
  8487. }
  8488. public void upd_erp_refundapprove()
  8489. {
  8490. if (UrlPostParmsCheck("refund_id"))
  8491. {
  8492. string eid = GetPostString("refund_id");
  8493. CeErpTradeRefund entity = null;
  8494. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8495. if (entity != null)
  8496. {
  8497. int apr = GetPostInt("approve");
  8498. if (apr == 0)
  8499. {
  8500. entity.RefundState = 1;
  8501. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8502. }
  8503. else if (apr == 1)
  8504. {
  8505. entity.RefundState = 3;
  8506. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8507. }
  8508. entity.modified = DateTime.Now;
  8509. entity.Update();
  8510. returnSuccessMsg("操作成功!");
  8511. return;
  8512. }
  8513. returnErrorMsg("找不到订单记录");
  8514. }
  8515. }
  8516. public void get_erp_billlist()
  8517. {
  8518. DataStruct dStruct = GetPostStruct();
  8519. List<string> lw = new List<string>();
  8520. string title = GetPostString("title");
  8521. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8522. string tid = GetPostString("tid");
  8523. string tids = GetPostString("tids");
  8524. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8525. if (tids.Length > 0)
  8526. {
  8527. tids = "'" + tids + "'";
  8528. tids = tids.Replace(",", "','");
  8529. lw.Add(string.Format("tid in ({0})", tids));
  8530. }
  8531. string shopname = GetPostString("shopname");
  8532. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8533. string buyernick = GetPostString("buyer_nick");
  8534. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8535. string customer = GetPostString("customer");
  8536. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8537. string date1 = GetPostString("date1");
  8538. string date2 = GetPostString("date2");
  8539. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8540. if (dw.Length > 0) lw.Add(dw);
  8541. string price1 = GetPostString("price1");
  8542. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8543. string price2 = GetPostString("price2");
  8544. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8545. string returndate1 = GetPostString("returndate1");
  8546. string returndate2 = GetPostString("returndate2");
  8547. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8548. if (dw1.Length > 0) lw.Add(dw1);
  8549. string billtype = GetPostString("billtype");
  8550. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8551. string billstate = GetPostString("billstate");
  8552. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8553. string usershop = CurrentUser.User.pemShop;
  8554. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8555. dStruct.Order = "createTime desc";
  8556. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8557. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8558. //foreach (DataRow dr in dt.Rows)
  8559. //{
  8560. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8561. //}
  8562. writeGridDataTableJson(dStruct.TotalCount, dt);
  8563. }
  8564. public void modify_erp_billinfo()
  8565. {
  8566. if (UrlPostParmsCheck("ID"))
  8567. {
  8568. string eid = GetPostString("ID");
  8569. CeErpBill bill_entity = null;
  8570. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8571. if (bill_entity != null)
  8572. {
  8573. bill_entity.tid = GetPostString("tid");
  8574. bill_entity.title = GetPostString("title");
  8575. bill_entity.tax = GetPostString("tax");
  8576. bill_entity.bank = GetPostString("bank");
  8577. bill_entity.bankac = GetPostString("bankac");
  8578. bill_entity.address = GetPostString("address");
  8579. bill_entity.phone = GetPostString("phone");
  8580. bill_entity.price = GetPostString("price");
  8581. bill_entity.productId = GetPostInt("ProductName");
  8582. bill_entity.num = GetPostInt("num");
  8583. bill_entity.unit = GetPostString("unit");
  8584. bill_entity.type = GetPostString("type");
  8585. bill_entity.sendType = GetPostString("SendType");
  8586. bill_entity.email = GetPostString("email");
  8587. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8588. bill_entity.shopName = GetPostString("ShopName");
  8589. bill_entity.applymemo = GetPostString("applymemo");
  8590. bill_entity.modifyTime = DateTime.Now;
  8591. bill_entity.createTime = DateTime.Now;
  8592. bill_entity.state = 0;
  8593. bill_entity.Update();
  8594. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8595. returnSuccessMsg("发票修改成功!");
  8596. return;
  8597. }
  8598. returnErrorMsg("找不到对应记录");
  8599. }
  8600. }
  8601. public void set_erp_invoicing()
  8602. {
  8603. if (UrlPostParmsCheck("id"))
  8604. {
  8605. try
  8606. {
  8607. string eid = GetPostString("id");
  8608. CeErpBill bill_entity = null;
  8609. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8610. if (bill_entity != null)
  8611. {
  8612. int ComId = GetPostInt("ComId");
  8613. //string memo = GetPostString("Memo");
  8614. int allInfo = GetPostInt("allinfo");
  8615. string clert = CurrentUser.User.Name;
  8616. //string detailValue = GetPostString("detailvalue");
  8617. string billId = bill_entity.billOrderId;
  8618. string[] billIdList = billId.Split(',');
  8619. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8620. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8621. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8622. {
  8623. billCount += 1;
  8624. }
  8625. if (billId.Length <= 0 || billIdList.Length != billCount)
  8626. {
  8627. bill_entity.billOrderId = "";
  8628. string prebill = "ltb";
  8629. for (int idx = 1; idx <= billCount; idx++)
  8630. {
  8631. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8632. string billoid = prebill + idx + dtstr;
  8633. bill_entity.billOrderId += billoid;
  8634. if (idx < billCount)
  8635. {
  8636. bill_entity.billOrderId += ",";
  8637. }
  8638. }
  8639. }
  8640. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8641. if (bill_entity.state == 5)
  8642. {
  8643. string errMsg = bill_entity.failerror;
  8644. string[] errlist = errMsg.Split('|');
  8645. string[] errTags = new string[errlist.Length];
  8646. for (int itag = 0; itag < errlist.Length; itag++)
  8647. {
  8648. if (errlist[itag].Length <= 0) continue;
  8649. errTags[itag] = errlist[itag].Split('&')[0];
  8650. }
  8651. for (int iii = 0; iii < errTags.Length; iii++)
  8652. {
  8653. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8654. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8655. if (billOrderList.Length >= erroBillOrderTag)
  8656. {
  8657. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8658. if (needModifyBillId.Length <= 19)
  8659. {
  8660. needModifyBillId = needModifyBillId + "1";
  8661. }
  8662. else
  8663. {
  8664. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8665. last = last + 1;
  8666. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8667. }
  8668. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8669. }
  8670. }
  8671. }
  8672. bool isHaveBillSucces = false;
  8673. string totalRes = "";
  8674. bill_entity.failerror = "";
  8675. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8676. {
  8677. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8678. totalRes += res;
  8679. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8680. {
  8681. isHaveBillSucces = true;
  8682. bill_entity.comId = ComId;
  8683. bill_entity.state = 1;
  8684. bill_entity.executeTime = DateTime.Now;
  8685. bill_entity.executeUser = clert;
  8686. }
  8687. else
  8688. {
  8689. bill_entity.state = 5;
  8690. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8691. }
  8692. }
  8693. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8694. bill_entity.Update();
  8695. if (isHaveBillSucces)
  8696. {
  8697. StringBuilder sql = new StringBuilder();
  8698. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8699. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8700. }
  8701. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8702. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8703. {
  8704. returnErrorMsg("开票失败");
  8705. }
  8706. else
  8707. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8708. return;
  8709. }
  8710. returnErrorMsg("找不到对应记录");
  8711. }
  8712. catch (Exception ex)
  8713. {
  8714. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8715. returnErrorMsg("操作失败");
  8716. }
  8717. }
  8718. }
  8719. public void get_erp_invoicing_back()
  8720. {
  8721. if (UrlPostParmsCheck("id"))
  8722. {
  8723. try
  8724. {
  8725. string id = GetPostString("id");
  8726. CeErpBill entiy = CeErpBill.Get(id);
  8727. if (entiy != null)
  8728. {
  8729. if (entiy.state == 0)
  8730. {
  8731. returnErrorMsg("发票还未开具");
  8732. return;
  8733. }
  8734. string[] billOrderList = entiy.billOrderId.Split(',');
  8735. int iTag = 0;
  8736. entiy.fplsh = "";
  8737. entiy.fpdm = "";
  8738. entiy.fphm = "";
  8739. foreach (string billOrderId in billOrderList)
  8740. {
  8741. iTag++;
  8742. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8743. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8744. {
  8745. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8746. try
  8747. {
  8748. Invoicing_get_response_Obj iObj = null;
  8749. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8750. if (iObj != null)
  8751. {
  8752. entiy.state = 2;
  8753. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8754. entiy.fpdm += iObj.list[0].c_fpdm;
  8755. entiy.fphm += iObj.list[0].c_fphm;
  8756. if (iTag < billOrderList.Length)
  8757. {
  8758. entiy.fplsh += ",";
  8759. entiy.fpdm += ",";
  8760. entiy.fphm += ",";
  8761. }
  8762. entiy.Update();
  8763. }
  8764. StringBuilder sql = new StringBuilder();
  8765. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8766. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8767. returnSuccessMsg("开票成功");
  8768. }
  8769. catch (Exception ex)
  8770. {
  8771. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8772. }
  8773. return;
  8774. }
  8775. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8776. {
  8777. var res_obj = new
  8778. {
  8779. data = "开票中"
  8780. };
  8781. string ro_json = JsonConvert.SerializeObject(res_obj);
  8782. returnSuccess(ro_json);
  8783. return;
  8784. }
  8785. else
  8786. {
  8787. int eidx = res.IndexOf("c_resultmsg");
  8788. int lidx = res.IndexOf("c_status");
  8789. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8790. entiy.state = 5;
  8791. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8792. entiy.Update();
  8793. returnErrorMsg("开票失败");
  8794. return;
  8795. }
  8796. }
  8797. }
  8798. }
  8799. catch (Exception ex)
  8800. {
  8801. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8802. }
  8803. return;
  8804. }
  8805. }
  8806. public void get_erp_invoicing()
  8807. {
  8808. if (UrlPostParmsCheck("id"))
  8809. {
  8810. try
  8811. {
  8812. string id = GetPostString("id");
  8813. CeErpBill entiy = CeErpBill.Get(id);
  8814. if (entiy != null)
  8815. {
  8816. if (entiy.state == 0)
  8817. {
  8818. returnErrorMsg("发票还未开具");
  8819. return;
  8820. }
  8821. if (entiy.sendType == "纸质发票")
  8822. {
  8823. if (entiy.img.Length <= 0)
  8824. {
  8825. returnErrorMsg("查无纸质发票");
  8826. return;
  8827. }
  8828. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8829. returnSuccess(returnres);
  8830. return;
  8831. }
  8832. string[] billOrderList = entiy.billOrderId.Split(',');
  8833. int iTag = 0;
  8834. string fpUrl = "";
  8835. entiy.fplsh = "";
  8836. entiy.fpdm = "";
  8837. entiy.fphm = "";
  8838. foreach (string billOrderId in billOrderList)
  8839. {
  8840. iTag++;
  8841. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8842. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8843. {
  8844. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8845. Invoicing_get_response_Obj iObj = null;
  8846. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8847. if (iObj != null)
  8848. {
  8849. //entiy.state = 2;
  8850. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8851. entiy.fpdm += iObj.list[0].c_fpdm;
  8852. entiy.fphm += iObj.list[0].c_fphm;
  8853. if (iTag < billOrderList.Length)
  8854. {
  8855. entiy.fplsh += ",";
  8856. entiy.fpdm += ",";
  8857. entiy.fphm += ",";
  8858. }
  8859. entiy.Update();
  8860. fpUrl += iObj.list[0].c_url + ",";
  8861. }
  8862. //returnSuccess(res);
  8863. StringBuilder sql = new StringBuilder();
  8864. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8865. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8866. }
  8867. else
  8868. {
  8869. int eidx = res.IndexOf("c_resultmsg");
  8870. //int lidx = res.IndexOf("c_status");
  8871. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8872. //开票失败
  8873. entiy.state = 5;
  8874. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8875. entiy.Update();
  8876. returnErrorMsg("开票失败");
  8877. return;
  8878. }
  8879. }
  8880. var returnObj = new
  8881. {
  8882. data = fpUrl
  8883. };
  8884. string ro_json = JsonConvert.SerializeObject(returnObj);
  8885. returnSuccess(ro_json);
  8886. }
  8887. }
  8888. catch (Exception ex)
  8889. {
  8890. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8891. }
  8892. return;
  8893. }
  8894. }
  8895. public void save_erp_billimg()
  8896. {
  8897. if (UrlPostParmsCheck("id"))
  8898. {
  8899. string eid = GetPostString("id");
  8900. CeErpBill bill_entity = null;
  8901. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8902. if (bill_entity != null)
  8903. {
  8904. bill_entity.img = GetPostString("img");
  8905. bill_entity.executeTime = DateTime.Now;
  8906. bill_entity.state = 2;
  8907. bill_entity.Update();
  8908. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8909. returnSuccessMsg("保存成功");
  8910. }
  8911. return;
  8912. }
  8913. }
  8914. public void upd_erp_billreturnback()
  8915. {
  8916. if (UrlPostParmsCheck("id"))
  8917. {
  8918. int eid = GetPostInt("id");
  8919. CeErpBill bill_entity = null;
  8920. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8921. if (bill_entity != null)
  8922. {
  8923. bill_entity.state = 3;
  8924. bill_entity.returnReason = GetPostString("reason");
  8925. bill_entity.Update();
  8926. returnSuccessMsg("驳回成功!");
  8927. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8928. }
  8929. return;
  8930. }
  8931. }
  8932. public void cancel_erp_bill()
  8933. {
  8934. if (UrlPostParmsCheck("id"))
  8935. {
  8936. int eid = GetPostInt("id");
  8937. int detailValue = GetPostInt("detailvalue");
  8938. CeErpBill bill_entity = null;
  8939. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8940. string cres = "";
  8941. string gres = "";
  8942. if (bill_entity != null)
  8943. {
  8944. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8945. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8946. {
  8947. int iTag = 0;
  8948. bill_entity.fplsh = "";
  8949. bill_entity.fpdm = "";
  8950. bill_entity.fphm = "";
  8951. foreach (string billOrderId in billOrderList)
  8952. {
  8953. iTag++;
  8954. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8955. if (gres.IndexOf("success") != -1)
  8956. {
  8957. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8958. Invoicing_get_response_Obj iObj = null;
  8959. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8960. if (iObj != null)
  8961. {
  8962. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8963. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8964. bill_entity.fphm += iObj.list[0].c_fphm;
  8965. if (iTag < billOrderList.Length)
  8966. {
  8967. bill_entity.fplsh += ",";
  8968. bill_entity.fpdm += ",";
  8969. bill_entity.fphm += ",";
  8970. }
  8971. bill_entity.Update();
  8972. }
  8973. }
  8974. else
  8975. {
  8976. returnErrorMsg(gres);
  8977. return;
  8978. }
  8979. }
  8980. }
  8981. if (bill_entity.sendType == "纸质发票")
  8982. {
  8983. //作废
  8984. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8985. //if (DateTime.Now.Month == extime.Month)
  8986. //{
  8987. //cres = taobaoHelper.cancel_invoicing(eid);
  8988. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8989. //{
  8990. bill_entity.state = 4;//已作废
  8991. bill_entity.Update();
  8992. returnSuccessMsg("发票已作废");
  8993. return;
  8994. //}
  8995. //else
  8996. //{
  8997. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8998. // bill_entity.Update();
  8999. // returnErrorMsg(cres);
  9000. // return;
  9001. //}
  9002. //}
  9003. //else
  9004. //{
  9005. // returnErrorMsg("纸质发票只能作废本月的发票");
  9006. // return;
  9007. //}
  9008. }
  9009. //红冲
  9010. int redTag = 0;
  9011. string[] fpdmList = bill_entity.fpdm.Split(',');
  9012. string[] fphmList = bill_entity.fphm.Split(',');
  9013. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  9014. {
  9015. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  9016. return;
  9017. }
  9018. foreach (string billOrderId in billOrderList)
  9019. {
  9020. redTag++;
  9021. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  9022. cres += onecres;
  9023. cres += ",";
  9024. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  9025. {
  9026. bill_entity.state = 4;//已作废
  9027. //bill_entity.Update();
  9028. //returnSuccessMsg("发票已红冲");
  9029. }
  9030. else if (onecres.IndexOf("重复冲红") != -1)
  9031. {
  9032. bill_entity.state = 4;//已作废
  9033. //bill_entity.Update();
  9034. //returnSuccessMsg("发票已红冲");
  9035. }
  9036. else
  9037. {
  9038. string errmsg = commonHelper.KeepChinese(onecres);
  9039. bill_entity.failerror += redTag + "&" + errmsg + "|";
  9040. }
  9041. }
  9042. bill_entity.Update();
  9043. if (cres.IndexOf("失败") != -1)
  9044. returnErrorMsg("红冲失败");
  9045. else
  9046. returnSuccessMsg("发票已红冲");
  9047. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  9048. return;
  9049. }
  9050. return;
  9051. }
  9052. }
  9053. public void del_erp_billorder()
  9054. {
  9055. if (UrlPostParmsCheck("id"))
  9056. {
  9057. string eid = GetPostString("id");
  9058. CeErpBill.Del(eid);
  9059. CeErpBill bill = CeErpBill.Get(eid);
  9060. if (bill != null)
  9061. {
  9062. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  9063. }
  9064. returnSuccessMsg("删除成功");
  9065. }
  9066. }
  9067. public void finish_erp_bill()
  9068. {
  9069. if (UrlPostParmsCheck("ids"))
  9070. {
  9071. string eids = GetPostString("ids");
  9072. string[] list = eids.Split(',');
  9073. foreach (string eid in list)
  9074. {
  9075. CeErpBill bill = CeErpBill.Get(eid);
  9076. if (bill != null)
  9077. {
  9078. bill.state = 2;
  9079. bill.Update();
  9080. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  9081. }
  9082. }
  9083. returnSuccessMsg("操作成功");
  9084. }
  9085. }
  9086. public void get_erp_returncash()
  9087. {
  9088. DataStruct dStruct = GetPostStruct();
  9089. List<string> lw = new List<string>();
  9090. string tid = GetPostString("tid");
  9091. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9092. string shopname = GetPostString("shopname");
  9093. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9094. string buyernick = GetPostString("buyer_nick");
  9095. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9096. string customer = GetPostString("customer");
  9097. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9098. string returndate1 = GetPostString("returndate1");
  9099. string returndate2 = GetPostString("returndate2");
  9100. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9101. if (dw.Length > 0) lw.Add(dw);
  9102. string finishDate1 = GetPostString("finishdate1");
  9103. string finishDate2 = GetPostString("finishdate2");
  9104. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9105. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9106. string returntype = GetPostString("returntype");
  9107. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  9108. string returnvstate = GetPostString("returnvstate");
  9109. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  9110. dStruct.Order = "created desc";
  9111. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9112. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  9113. writeGridDataTableJson(dStruct.TotalCount, dt);
  9114. }
  9115. public void get_erp_staygoods()
  9116. {
  9117. DataStruct dStruct = GetPostStruct();
  9118. List<string> lw = new List<string>();
  9119. string tid = GetPostString("tid");
  9120. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9121. string shopname = GetPostString("shopname");
  9122. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  9123. string wangwang = GetPostString("wangwang");
  9124. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  9125. string customer = GetPostString("customer");
  9126. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  9127. string returndate1 = GetPostString("returndate1");
  9128. string returndate2 = GetPostString("returndate2");
  9129. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  9130. if (dw.Length > 0) lw.Add(dw);
  9131. string finishDate1 = GetPostString("finishdate1");
  9132. string finishDate2 = GetPostString("finishdate2");
  9133. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  9134. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9135. string returnvstate = GetPostString("returnvstate");
  9136. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  9137. string persuadetype = GetPostString("persuadetype");
  9138. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  9139. string customerOrg = GetPostString("customerOrg");
  9140. if (customerOrg.Length > 0)
  9141. {
  9142. lw.Add(string.Format("OrgID = {0}", customerOrg));
  9143. }
  9144. string designerorg = GetPostString("designerorg");
  9145. if (designerorg.Length > 0)
  9146. {
  9147. lw.Add(string.Format("OrgID = {0}", designerorg));
  9148. }
  9149. dStruct.Order = "creata_time desc";
  9150. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9151. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  9152. writeGridDataTableJson(dStruct.TotalCount, dt);
  9153. }
  9154. public void upd_erp_staygoods()
  9155. {
  9156. if (UrlPostParmsCheck("id"))
  9157. {
  9158. int eid = GetPostInt("id");
  9159. CeErpStayGoods entity = null;
  9160. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  9161. if (entity != null)
  9162. {
  9163. entity.audit_type = 1;
  9164. entity.audit_time = DateTime.Now;
  9165. entity.audit_u_id = CurrentUser.UserID;
  9166. entity.audit_u_name = CurrentUser.UserName;
  9167. entity.Update();
  9168. returnSuccessMsg("审核成功!");
  9169. return;
  9170. }
  9171. returnErrorMsg("找不到订单记录");
  9172. }
  9173. }
  9174. public void upd_erp_stayGoodsback()
  9175. {
  9176. if (UrlPostParmsCheck("id"))
  9177. {
  9178. int eid = GetPostInt("id");
  9179. CeErpStayGoods entity = null;
  9180. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  9181. if (entity != null)
  9182. {
  9183. entity.audit_text = GetPostString("reason");
  9184. entity.audit_type = 2;
  9185. entity.audit_time = DateTime.Now;
  9186. entity.audit_u_id = CurrentUser.UserID;
  9187. entity.audit_u_name = CurrentUser.UserName;
  9188. entity.Update();
  9189. returnSuccessMsg("退回成功!");
  9190. return;
  9191. }
  9192. returnErrorMsg("找不到订单记录");
  9193. }
  9194. }
  9195. public void upd_erp_returncashverify()
  9196. {
  9197. if (UrlPostParmsCheck("ID"))
  9198. {
  9199. int eid = GetPostInt("ID");
  9200. CeErpReturnCash entity = null;
  9201. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9202. if (entity != null)
  9203. {
  9204. entity.cashstate = 1;
  9205. entity.verifytime = DateTime.Now;
  9206. entity.verifyuserid = CurrentUser.UserID;
  9207. entity.Update();
  9208. returnSuccessMsg("审核成功!");
  9209. return;
  9210. }
  9211. returnErrorMsg("找不到订单记录");
  9212. }
  9213. }
  9214. public void upd_all_erp_returncashverify()
  9215. {
  9216. if (UrlPostParmsCheck("ID"))
  9217. {
  9218. String[] list = GetPostString("ID").Split(',');
  9219. CeErpReturnCash entity = null;
  9220. for (int i = 0; i < list.Length; i++)
  9221. {
  9222. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  9223. if (entity != null)
  9224. {
  9225. if (entity.cashstate == 1)
  9226. {
  9227. returnErrorMsg("已审核过的订单不需要在审核!");
  9228. return;
  9229. }
  9230. entity.cashstate = 1;
  9231. entity.verifytime = DateTime.Now;
  9232. entity.verifyuserid = CurrentUser.UserID;
  9233. entity.Update();
  9234. }
  9235. }
  9236. returnSuccessMsg("审核成功!");
  9237. return;
  9238. }
  9239. }
  9240. public void upd_erp_returncashback()
  9241. {
  9242. if (UrlPostParmsCheck("ID"))
  9243. {
  9244. int eid = GetPostInt("ID");
  9245. CeErpReturnCash entity = null;
  9246. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9247. if (entity != null)
  9248. {
  9249. entity.backreason = GetPostString("reason");
  9250. entity.cashstate = 2;
  9251. entity.verifytime = DateTime.Now;
  9252. entity.verifyuserid = CurrentUser.UserID;
  9253. entity.Update();
  9254. returnSuccessMsg("退回成功!");
  9255. return;
  9256. }
  9257. returnErrorMsg("找不到订单记录");
  9258. }
  9259. }
  9260. public void upd_erp_returnprice()
  9261. {
  9262. if (UrlPostParmsCheck("ID"))
  9263. {
  9264. int eid = GetPostInt("ID");
  9265. CeErpReturnCash entity = null;
  9266. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9267. if (entity != null)
  9268. {
  9269. if (entity.cashstate == 1)
  9270. {
  9271. returnErrorMsg("审核通过了不能改");
  9272. return;
  9273. }
  9274. entity.returnprice = GetPostDouble("returnprice");
  9275. entity.Update();
  9276. returnSuccessMsg("修改成功!");
  9277. return;
  9278. }
  9279. returnErrorMsg("找不到订单记录");
  9280. }
  9281. }
  9282. public void del_erp_returncash()
  9283. {
  9284. if (UrlPostParmsCheck("ID"))
  9285. {
  9286. int eid = GetPostInt("ID");
  9287. CeErpReturnCash.Del(eid);
  9288. returnSuccessMsg("操作成功");
  9289. return;
  9290. }
  9291. }
  9292. public void test_for_do_sql()
  9293. {
  9294. string sql = GetPostString("sqlstr");
  9295. if (sql.Length > 0)
  9296. {
  9297. try
  9298. {
  9299. DbHelper.DbConn.ExecuteNonQuery(sql);
  9300. var res_obj = new
  9301. {
  9302. data = "成功",
  9303. };
  9304. string ro_json = JsonConvert.SerializeObject(res_obj);
  9305. returnSuccess(ro_json);
  9306. }
  9307. catch (Exception ex)
  9308. {
  9309. var res_obj = new
  9310. {
  9311. data = ex.Message,
  9312. };
  9313. string ro_json = JsonConvert.SerializeObject(res_obj);
  9314. returnSuccess(ro_json);
  9315. }
  9316. }
  9317. }
  9318. public void get_user_info()
  9319. {
  9320. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9321. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9322. }
  9323. public void get_total_data()
  9324. {
  9325. int userId = CurrentUser.UserID;
  9326. string sql = "";
  9327. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9328. {
  9329. 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);
  9330. }
  9331. else
  9332. {
  9333. 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 " +
  9334. "(select ID from CE_ErpUser where ID = {0}) d " +
  9335. "left join " +
  9336. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9337. ") a on d.ID = a.id left join " +
  9338. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9339. ") b on a.id = b.id1 left join" +
  9340. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9341. ") c on a.id = c.id2;", userId);
  9342. }
  9343. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9344. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9345. }
  9346. public void get_date_area_total_data2()
  9347. {
  9348. int userId = CurrentUser.UserID;
  9349. string date_type = GetPostString("timetype");
  9350. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9351. string sql = "";
  9352. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9353. {
  9354. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9355. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9356. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9357. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9358. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9359. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9360. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9361. ") a on e.ID = a.id left join " +
  9362. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9363. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9364. ") b on a.id = b.id1 " +
  9365. "left join " +
  9366. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9367. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9368. ") c on a.id = c.id2 " +
  9369. "left join " +
  9370. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9371. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9372. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9373. }
  9374. else
  9375. {
  9376. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9377. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9378. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9379. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9380. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9381. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9382. ") a on e.ID = a.id left join " +
  9383. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9384. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9385. ") c on a.id = c.id2 " +
  9386. "left join " +
  9387. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9388. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9389. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9390. }
  9391. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9392. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9393. }
  9394. public void get_date_area_total_data()
  9395. {
  9396. int userId = CurrentUser.UserID;
  9397. string date_type = GetPostString("timetype");
  9398. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9399. string date1 = searchDT[0].ToString();
  9400. string date2 = searchDT[1].ToString();
  9401. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9402. {
  9403. SqlParameter[] sqlParameter ={
  9404. new SqlParameter("@userId", SqlDbType.Int,4),
  9405. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9406. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9407. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9408. };
  9409. sqlParameter[0].Value = userId;
  9410. sqlParameter[1].Value = date1;
  9411. sqlParameter[2].Value = date2;
  9412. sqlParameter[3].Direction = ParameterDirection.Output;
  9413. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9414. string res = sqlParameter[3].Value.ToString();
  9415. var res_obj = new
  9416. {
  9417. data = res
  9418. };
  9419. string ro_json = JsonConvert.SerializeObject(res_obj);
  9420. returnSuccess(ro_json);
  9421. }
  9422. else
  9423. {
  9424. SqlParameter[] sqlParameter ={
  9425. new SqlParameter("@userId", SqlDbType.Int,4),
  9426. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9427. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9428. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9429. };
  9430. sqlParameter[0].Value = userId;
  9431. sqlParameter[1].Value = date1;
  9432. sqlParameter[2].Value = date2;
  9433. sqlParameter[3].Direction = ParameterDirection.Output;
  9434. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9435. string res = sqlParameter[3].Value.ToString();
  9436. var res_obj = new
  9437. {
  9438. data = res
  9439. };
  9440. string ro_json = JsonConvert.SerializeObject(res_obj);
  9441. returnSuccess(ro_json);
  9442. }
  9443. //writeGridDataViewJson(dt.Rows.Count, dv);
  9444. }
  9445. public void get_order_list()
  9446. {
  9447. string strFields = GetPostString("paraFields");
  9448. string strOrder = GetPostString("paraOrder");
  9449. string strWhere = GetPostString("paraWhere");
  9450. string strPageSize = GetPostString("paraPageSize");
  9451. DataStruct dStruct = GetPostStruct();
  9452. dStruct.PageSize = int.Parse(strPageSize);
  9453. dStruct.Fileds = strFields;
  9454. dStruct.Order = strOrder;
  9455. dStruct.MainWhere = strWhere;
  9456. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9457. writeGridDataTableJson(dStruct.TotalCount, dt);
  9458. }
  9459. ////获取待开始订单列表
  9460. //public void get_wait_design_order_list()
  9461. //{
  9462. // string date_type = GetPostString("date_type");
  9463. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9464. // DataStruct dStruct = GetPostStruct();
  9465. // dStruct.PageSize = 1000;
  9466. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9467. // List<string> lw = new List<string>();
  9468. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9469. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9470. // dStruct.Order = "WaitDesignTime asc";
  9471. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9472. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9473. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9474. //}
  9475. //获取完成单量排名
  9476. public void get_finish_order_count_ranking()
  9477. {
  9478. /* string date_type = GetPostString("date_type");
  9479. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9480. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9481. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9482. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9483. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9484. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9485. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9486. writeGridDataTableJson(0, new DataTable());
  9487. }
  9488. public void get_finish_order_amount_ranking()
  9489. {
  9490. /*string date_type = GetPostString("date_type");
  9491. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9492. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9493. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9494. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9495. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9496. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9497. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9498. writeGridDataTableJson(0, new DataTable());
  9499. }
  9500. public void get_finish_refund_count_ranking()
  9501. {
  9502. string date_type = GetPostString("date_type");
  9503. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9504. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9505. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9506. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9507. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9508. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9509. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9510. writeGridDataTableJson(dt.Rows.Count, dt);
  9511. }
  9512. public void get_finish_refund_amount_ranking()
  9513. {
  9514. string date_type = GetPostString("date_type");
  9515. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9516. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9517. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9518. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9519. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9520. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9521. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9522. writeGridDataTableJson(dt.Rows.Count, dt);
  9523. }
  9524. public void set_erp_finishorder_director()
  9525. {
  9526. if (UrlPostParmsCheck("ctid"))
  9527. {
  9528. string eid = GetPostString("ctid");
  9529. CeErpTradeCell entity = null;
  9530. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9531. if (entity != null)
  9532. {
  9533. entity.OrderState = 8;
  9534. entity.Update();
  9535. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9536. returnSuccessMsg("操作成功!");
  9537. return;
  9538. }
  9539. returnErrorMsg("找不到记录");
  9540. }
  9541. }
  9542. public void get_erp_placeregistlist()
  9543. {
  9544. DataStruct dStruct = GetPostStruct();
  9545. List<string> lw = new List<string>();
  9546. string outsid = GetPostString("outsid");
  9547. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9548. string memo = GetPostString("memo");
  9549. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9550. string filename = GetPostString("filename");
  9551. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9552. string islate = GetPostString("islate");
  9553. if (islate.Length > 0)
  9554. {
  9555. if (islate == "1")
  9556. lw.Add(string.Format("OutLate>0"));
  9557. else
  9558. lw.Add(string.Format("OutLate=0"));
  9559. }
  9560. string placedate1 = GetPostString("placedate1");
  9561. string placedate2 = GetPostString("placedate2");
  9562. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9563. if (dw.Length > 0) lw.Add(dw);
  9564. string deliveryDate1 = GetPostString("deliverydate1");
  9565. string deliveryDate2 = GetPostString("deliverydate2");
  9566. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9567. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9568. dStruct.Order = "ID desc";
  9569. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9570. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9571. writeGridDataTableJson(dStruct.TotalCount, dt);
  9572. }
  9573. public void ins_erp_placeregist()
  9574. {
  9575. if (UrlPostParmsCheck("id"))
  9576. {
  9577. string eid = GetPostString("id");
  9578. CeErpPlaceRegister entity = null;
  9579. if (eid == "0")//新增
  9580. {
  9581. entity = new CeErpPlaceRegister();
  9582. string xdTime = GetPostString("placeTime");
  9583. if (xdTime.Length > 0)
  9584. {
  9585. entity.PlactTime = Convert.ToDateTime(xdTime);
  9586. }
  9587. string fhTime = GetPostString("deliveryTime");
  9588. if (fhTime.Length > 0)
  9589. {
  9590. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9591. }
  9592. string preTime = GetPostString("preOutTime");
  9593. if (preTime.Length > 0)
  9594. {
  9595. entity.PreOutTime = Convert.ToDateTime(preTime);
  9596. }
  9597. entity.DeliveryCount = GetPostInt("deliveryCount");
  9598. entity.ReceiveCount = GetPostInt("receiveCount");
  9599. entity.OutSid = GetPostString("outSid");
  9600. entity.FileName = GetPostString("fileName");
  9601. entity.Memo = GetPostString("memo");
  9602. entity.AddUserId = CurrentUser.UserID;
  9603. entity.CreateTime = DateTime.Now;
  9604. entity.Img = GetPostString("img");
  9605. entity.Supplier = GetPostInt("supplier");
  9606. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9607. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9608. {
  9609. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9610. DateTime dt2 = (DateTime)entity.PreOutTime;
  9611. TimeSpan span = dt1.Subtract(dt2);
  9612. if (span.Days > 0)
  9613. {
  9614. entity.OutLate = span.Days;
  9615. }
  9616. }
  9617. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9618. entity.Create();
  9619. returnSuccessMsg("添加成功!");
  9620. return;
  9621. }
  9622. else //修改
  9623. {
  9624. entity = CeErpPlaceRegister.Get(eid);
  9625. if (entity != null)
  9626. {
  9627. string xdTime = GetPostString("placeTime");
  9628. if (xdTime.Length > 0)
  9629. {
  9630. entity.PlactTime = Convert.ToDateTime(xdTime);
  9631. }
  9632. string fhTime = GetPostString("deliveryTime");
  9633. if (fhTime.Length > 0)
  9634. {
  9635. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9636. }
  9637. string preTime = GetPostString("preOutTime");
  9638. if (preTime.Length > 0)
  9639. {
  9640. entity.PreOutTime = Convert.ToDateTime(preTime);
  9641. }
  9642. entity.DeliveryCount = GetPostInt("deliveryCount");
  9643. entity.ReceiveCount = GetPostInt("receiveCount");
  9644. if (entity.DeliveryCount == entity.ReceiveCount)
  9645. {
  9646. entity.CurState = "已完成";
  9647. }
  9648. else
  9649. {
  9650. entity.CurState = "未完成";
  9651. }
  9652. entity.OutSid = GetPostString("outSid");
  9653. entity.FileName = GetPostString("fileName");
  9654. entity.Memo = GetPostString("memo");
  9655. entity.Img = GetPostString("img");
  9656. entity.Supplier = GetPostInt("supplier");
  9657. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9658. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9659. {
  9660. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9661. DateTime dt2 = (DateTime)entity.PreOutTime;
  9662. TimeSpan span = dt1.Subtract(dt2);
  9663. if (span.Days > 0)
  9664. {
  9665. entity.OutLate = span.Days;
  9666. }
  9667. }
  9668. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9669. entity.Update();
  9670. returnSuccessMsg("修改成功");
  9671. return;
  9672. }
  9673. returnErrorMsg("找不到对应的记录");
  9674. return;
  9675. }
  9676. }
  9677. returnErrorMsg("缺少必要参数");
  9678. }
  9679. public void del_erp_placeregist()
  9680. {
  9681. string eid = GetPostString("id");
  9682. CeErpPlaceRegister.Del(eid);
  9683. returnSuccessMsg("删除成功!");
  9684. return;
  9685. }
  9686. public void ins_erp_placeregistbyorder()
  9687. {
  9688. string ctid = GetPostString("ctid");
  9689. if (ctid.Length > 0)
  9690. {
  9691. StringBuilder sql = new StringBuilder();
  9692. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9693. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9694. if (dt.Rows.Count > 0)
  9695. {
  9696. foreach (DataRow dr in dt.Rows)
  9697. {
  9698. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9699. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9700. entity.AddUserId = CurrentUser.UserID;
  9701. entity.tid = dr["tid"].ToString();
  9702. entity.Did = Convert.ToString(dr["ctid"]);
  9703. entity.splitTag = dr["SplitTag"].ToString();
  9704. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9705. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9706. if (pre_ctid.Length > 0)
  9707. {
  9708. sellmemo = sellmemo.Replace(pre_ctid, "");
  9709. }
  9710. sellmemo = sellmemo.Replace("[", "");
  9711. sellmemo = sellmemo.Replace("]", "");
  9712. entity.FileName = sellmemo;
  9713. string count = dr["ProductCount"].ToString();
  9714. int usecount = commonHelper.getIntCountFromString(count);
  9715. entity.DeliveryCount = usecount;
  9716. entity.CurState = "未完成";
  9717. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9718. {
  9719. entity.Supplier = 24;//dl手提袋定制
  9720. }
  9721. else
  9722. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9723. entity.CreateTime = DateTime.Now;
  9724. entity.Create();
  9725. }
  9726. returnSuccessMsg("操作成功");
  9727. return;
  9728. }
  9729. returnErrorMsg("没有找到对应订单");
  9730. return;
  9731. }
  9732. returnErrorMsg("缺少订单编号");
  9733. return;
  9734. }
  9735. public void get_erp_persuadelist()
  9736. {
  9737. DataStruct dStruct = GetPostStruct();
  9738. List<string> lw = new List<string>();
  9739. string ctid = GetPostString("ctid");
  9740. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9741. string shopname = GetPostString("shopname");
  9742. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9743. string buyernick = GetPostString("buyer_nick");
  9744. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9745. string customer = GetPostString("customer");
  9746. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9747. string returndate1 = GetPostString("returndate1");
  9748. string returndate2 = GetPostString("returndate2");
  9749. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9750. if (dw.Length > 0) lw.Add(dw);
  9751. string finishDate1 = GetPostString("finishdate1");
  9752. string finishDate2 = GetPostString("finishdate2");
  9753. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9754. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9755. string persuadetype = GetPostString("persuadetype");
  9756. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9757. string returnvstate = GetPostString("returnvstate");
  9758. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9759. dStruct.Order = "created desc";
  9760. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9761. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9762. writeGridDataTableJson(dStruct.TotalCount, dt);
  9763. }
  9764. public void upd_erp_returnpersuadeback()
  9765. {
  9766. if (UrlPostParmsCheck("ID"))
  9767. {
  9768. int eid = GetPostInt("ID");
  9769. CeErpPersuade entity = null;
  9770. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9771. if (entity != null)
  9772. {
  9773. entity.backreason = GetPostString("reason");
  9774. entity.pstate = 2;
  9775. entity.verifytime = DateTime.Now;
  9776. entity.verifyuserid = CurrentUser.UserID;
  9777. entity.Update();
  9778. returnSuccessMsg("退回成功!");
  9779. return;
  9780. }
  9781. returnErrorMsg("找不到订单记录");
  9782. }
  9783. }
  9784. public void upd_erp_returnpersuadeverify()
  9785. {
  9786. if (UrlPostParmsCheck("ID"))
  9787. {
  9788. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9789. {
  9790. returnErrorMsg("暂无权限审核");
  9791. return;
  9792. }
  9793. int eid = GetPostInt("ID");
  9794. CeErpPersuade entity = null;
  9795. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9796. if (entity != null)
  9797. {
  9798. entity.pstate = 1;
  9799. entity.verifytime = DateTime.Now;
  9800. entity.verifyuserid = CurrentUser.UserID;
  9801. entity.Update();
  9802. returnSuccessMsg("审核成功!");
  9803. return;
  9804. }
  9805. returnErrorMsg("找不到订单记录");
  9806. }
  9807. }
  9808. public void del_erp_persuade()
  9809. {
  9810. if (UrlPostParmsCheck("ID"))
  9811. {
  9812. int eid = GetPostInt("ID");
  9813. CeErpPersuade.Del(eid);
  9814. returnSuccessMsg("操作成功");
  9815. return;
  9816. }
  9817. }
  9818. public void get_erp_oldcustoupload()
  9819. {
  9820. DataStruct dStruct = GetPostStruct();
  9821. List<string> lw = new List<string>();
  9822. string buyernick = GetPostString("buyer_nick");
  9823. if (buyernick.Length > 0)
  9824. {
  9825. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9826. }
  9827. else
  9828. return;
  9829. dStruct.Order = "pay_time desc";
  9830. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9831. DataTable dt = null;
  9832. dt = WebCache.GetData("view_erptradecell", dStruct);
  9833. writeGridDataTableJson(dStruct.TotalCount, dt);
  9834. }
  9835. public void get_erp_checkorderlist()
  9836. {
  9837. DataStruct dStruct = GetPostStruct();
  9838. List<string> lw = new List<string>();
  9839. string tid = GetPostString("ctid");
  9840. if (tid.Length > 0)
  9841. {
  9842. string select_tid = getTidByCtid(tid);
  9843. lw.Add(string.Format("tid='{0}'", select_tid));
  9844. }
  9845. string shopname = GetPostString("shopname");
  9846. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9847. string buyernick = GetPostString("buyer_nick");
  9848. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9849. string customer = GetPostString("customer");
  9850. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9851. string design = GetPostString("design");
  9852. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9853. string orderState = GetPostString("orderState");
  9854. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9855. string address = GetPostString("address");
  9856. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9857. string sellermemo = GetPostString("seller_memo");
  9858. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9859. string supplier = GetPostString("supplier");
  9860. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9861. {
  9862. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9863. }
  9864. else
  9865. {
  9866. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9867. }
  9868. string date1 = GetPostString("date1");
  9869. string date2 = GetPostString("date2");
  9870. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9871. if (dw.Length > 0) lw.Add(dw);
  9872. string placedate1 = GetPostString("placedate1");
  9873. string placedate2 = GetPostString("placedate2");
  9874. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9875. if (fdw.Length > 0) lw.Add(fdw);
  9876. string price1 = GetPostString("price1");
  9877. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9878. string price2 = GetPostString("price2");
  9879. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9880. string checkst = GetPostString("checkstate");
  9881. if (checkst.Length > 0 && "10".Equals(checkst))
  9882. {
  9883. lw.Add(string.Format("CheckOut>0"));
  9884. }
  9885. else
  9886. {
  9887. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9888. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9889. }
  9890. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9891. {
  9892. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9893. }
  9894. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9895. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9896. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9897. writeGridDataTableJson(dStruct.TotalCount, dt);
  9898. }
  9899. public void ins_erp_startCheck()
  9900. {
  9901. if (UrlPostParmsCheck("ctid"))
  9902. {
  9903. string eid = GetPostString("ctid");
  9904. CeErpTradeCell entity = null;
  9905. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9906. if (entity != null)
  9907. {
  9908. entity.MemoOpt = 4;
  9909. entity.UpdateTime = DateTime.Now;
  9910. entity.Update();
  9911. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9912. CeErpSukuraData.createInfo(entity.ctid, 6);
  9913. returnSuccessMsg("操作成功!");
  9914. return;
  9915. }
  9916. returnErrorMsg("找不到记录");
  9917. }
  9918. }
  9919. public void upd_erp_sendXlw()
  9920. {
  9921. if (UrlPostParmsCheck("ctid"))
  9922. {
  9923. string eid = GetPostString("ctid");
  9924. CeErpTradeCell entity = null;
  9925. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9926. if (entity != null)
  9927. {
  9928. if (entity.IsSendGift == 1)
  9929. {
  9930. returnErrorMsg("请勿重复标记");
  9931. return;
  9932. }
  9933. entity.IsSendGift = 1;
  9934. entity.Update();
  9935. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9936. returnSuccessMsg("操作成功!");
  9937. return;
  9938. }
  9939. returnErrorMsg("找不到记录");
  9940. }
  9941. }
  9942. public void cancel_sendXlw()
  9943. {
  9944. if (UrlPostParmsCheck("ctid"))
  9945. {
  9946. string eid = GetPostString("ctid");
  9947. CeErpTradeCell entity = null;
  9948. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9949. if (entity != null)
  9950. {
  9951. if (entity.IsSendGift == 0)
  9952. {
  9953. returnErrorMsg("未标记小礼物");
  9954. return;
  9955. }
  9956. entity.IsSendGift = 0;
  9957. entity.Update();
  9958. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9959. returnSuccessMsg("操作成功!");
  9960. return;
  9961. }
  9962. returnErrorMsg("找不到记录");
  9963. }
  9964. }
  9965. public void get_erp_designbill()
  9966. {
  9967. DataStruct dStruct = GetPostStruct();
  9968. List<string> lw = new List<string>();
  9969. int isMy = GetInt("my");
  9970. if (isMy == 1)
  9971. {
  9972. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9973. }
  9974. string tid = GetPostString("tid");
  9975. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9976. string userName = GetPostString("design");
  9977. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9978. string price1 = GetPostString("price1");
  9979. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9980. string price2 = GetPostString("price2");
  9981. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9982. string rePrice1 = GetPostString("rePrice1");
  9983. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9984. string rePrice2 = GetPostString("rePrice2");
  9985. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9986. string designerType = GetPostString("designerType");
  9987. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9988. string orderState = GetPostString("orderState");
  9989. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9990. string endTime1 = GetPostString("endTime1");
  9991. string endTime2 = GetPostString("endTime2");
  9992. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9993. if (dw.Length > 0) lw.Add(dw);
  9994. string isDk = GetPostString("isDk");
  9995. if (isDk == "1")
  9996. {
  9997. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9998. }
  9999. else if (isDk == "0")
  10000. {
  10001. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  10002. }
  10003. dStruct.Order = "oid, create_time desc";
  10004. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10005. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  10006. writeGridDataTableJson(dStruct.TotalCount, dt);
  10007. }
  10008. public void upd_erp_designerbill()
  10009. {
  10010. if (UrlPostParmsCheck("ID"))
  10011. {
  10012. string eid = GetPostString("ID");
  10013. CeErpDesignerBill entity = null;
  10014. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  10015. if (entity != null)
  10016. {
  10017. if (GetPostDouble("designerpirce") > 0)
  10018. {
  10019. entity.realPrice = GetPostDouble("designerpirce");
  10020. entity.update_time = DateTime.Now;
  10021. entity.update_u_id = CurrentUser.UserID;
  10022. entity.update_u_name = CurrentUser.UserName;
  10023. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  10024. entity.Update();
  10025. returnSuccessMsg("操作成功!");
  10026. return;
  10027. }
  10028. else
  10029. {
  10030. entity.price = GetPostDouble("price");
  10031. entity.update_time = DateTime.Now;
  10032. entity.update_u_id = CurrentUser.UserID;
  10033. entity.update_u_name = CurrentUser.UserName;
  10034. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  10035. entity.Update();
  10036. returnSuccessMsg("操作成功!");
  10037. return;
  10038. }
  10039. }
  10040. returnErrorMsg("找不到记录");
  10041. }
  10042. }
  10043. public void audit_erp_designerbill()
  10044. {
  10045. if (UrlPostParmsCheck("ID"))
  10046. {
  10047. string eid = GetPostString("ID");
  10048. CeErpDesignerBill entity = null;
  10049. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  10050. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  10051. if (entity != null)
  10052. {
  10053. entity.realPrice = GetPostDouble("designerpirce");
  10054. entity.update_time = DateTime.Now;
  10055. entity.update_u_id = CurrentUser.UserID;
  10056. entity.update_u_name = CurrentUser.UserName;
  10057. entity.isAudit = 1;
  10058. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  10059. entity.Update();
  10060. if (orderEntity != null)
  10061. {
  10062. orderEntity.IsReadTag = 3;
  10063. orderEntity.Update();
  10064. }
  10065. returnSuccessMsg("操作成功!");
  10066. return;
  10067. }
  10068. returnErrorMsg("找不到记录");
  10069. }
  10070. }
  10071. public void all_audit_erp_designerbill()
  10072. {
  10073. if (UrlPostParmsCheck("idList"))
  10074. {
  10075. string[] list = GetPostString("idList").Split(',');
  10076. CeErpDesignerBill entity = null;
  10077. for (int i = 0; i < list.Length; i++)
  10078. {
  10079. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  10080. if (entity == null) return;
  10081. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  10082. if (orderEntity == null) return;
  10083. if (entity.realPrice == 0) entity.realPrice = entity.price;
  10084. entity.update_time = DateTime.Now;
  10085. entity.update_u_id = CurrentUser.UserID;
  10086. entity.update_u_name = CurrentUser.UserName;
  10087. entity.isAudit = 1;
  10088. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  10089. entity.Update();
  10090. orderEntity.IsReadTag = 3;
  10091. orderEntity.Update();
  10092. }
  10093. returnSuccessMsg("操作成功!");
  10094. return;
  10095. }
  10096. }
  10097. public void get_erp_sameorders()
  10098. {
  10099. if (UrlPostParmsCheck("ctid"))
  10100. {
  10101. string eid = GetPostString("ctid");
  10102. CeErpTradeCell entity = null;
  10103. entity = CeErpTradeCell.GetByCtid(eid);
  10104. if (entity != null)
  10105. {
  10106. StringBuilder sql = new StringBuilder();
  10107. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  10108. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10109. var res = new
  10110. {
  10111. data = dt.Rows.Count
  10112. };
  10113. string ro_jsond = JsonConvert.SerializeObject(res);
  10114. returnSuccess(ro_jsond);
  10115. return;
  10116. }
  10117. returnErrorMsg("未找到订单");
  10118. return;
  10119. }
  10120. returnErrorMsg("缺少必要的参数");
  10121. }
  10122. public void get_erp_islasthavesameorder()
  10123. {
  10124. if (UrlPostParmsCheck("ctid"))
  10125. {
  10126. string eid = GetPostString("ctid");
  10127. string[] ctidList = eid.Split(',');
  10128. StringBuilder sql = new StringBuilder();
  10129. string tisCtid = "";
  10130. foreach (string ctid in ctidList)
  10131. {
  10132. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  10133. if (entity != null)
  10134. {
  10135. sql = new StringBuilder();
  10136. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  10137. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10138. if (dth.Rows.Count > 0)
  10139. {
  10140. tisCtid += entity.ctid;
  10141. tisCtid += ",";
  10142. }
  10143. }
  10144. }
  10145. if (tisCtid.Length > 0)
  10146. {
  10147. var res = new
  10148. {
  10149. data = tisCtid
  10150. };
  10151. string ro_jsond = JsonConvert.SerializeObject(res);
  10152. returnSuccess(ro_jsond);
  10153. }
  10154. else
  10155. {
  10156. var res = new
  10157. {
  10158. data = ""
  10159. };
  10160. string ro_jsond = JsonConvert.SerializeObject(res);
  10161. returnSuccess(ro_jsond);
  10162. }
  10163. return;
  10164. }
  10165. returnErrorMsg("缺少必要的参数");
  10166. }
  10167. public void file_client_down_url()
  10168. {
  10169. if (!UrlPostParmsCheck("userId"))
  10170. {
  10171. returnErrorMsg("缺少必要的参数");
  10172. }
  10173. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  10174. }
  10175. public void checkout_form_data()
  10176. {
  10177. if (!UrlPostParmsCheck("tid"))
  10178. {
  10179. returnErrorMsg("缺少必要的参数");
  10180. }
  10181. string tid = GetPostString("tid");
  10182. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  10183. if (ceErpOrderFormData != null)
  10184. {
  10185. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  10186. returnSuccess(ro_jsond);
  10187. return;
  10188. }
  10189. returnErrorMsg("尚未有文件!");
  10190. }
  10191. public void back_supplier_audit()
  10192. {
  10193. int userId = CurrentUser.UserID;
  10194. StringBuilder sql = new StringBuilder();
  10195. 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);
  10196. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10197. if (dt.Rows.Count > 0)
  10198. {
  10199. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10200. }
  10201. else
  10202. {
  10203. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10204. }
  10205. }
  10206. public void back_supplier_query()
  10207. {
  10208. string eid = GetPostString("ctid");
  10209. if (eid != "")
  10210. {
  10211. StringBuilder sql = new StringBuilder();
  10212. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  10213. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10214. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10215. }
  10216. else
  10217. {
  10218. returnErrorMsg("找不到订单记录");
  10219. return;
  10220. }
  10221. }
  10222. public void verified_to_order()
  10223. {
  10224. int userId = CurrentUser.UserID;
  10225. StringBuilder sql = new StringBuilder();
  10226. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  10227. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10228. if (dt.Rows.Count > 0)
  10229. {
  10230. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10231. }
  10232. else
  10233. {
  10234. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10235. }
  10236. }
  10237. public void upd_supplier_audit()
  10238. {
  10239. if (UrlPostParmsCheck("ctid"))
  10240. {
  10241. string eid = GetPostString("ctid");
  10242. string reason = GetPostString("returnreason");
  10243. CeErpTradeCell entity = null;
  10244. CeWithdraw withdraw = null;
  10245. withdraw = CeWithdraw.GetByTid(eid);
  10246. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  10247. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  10248. {
  10249. if (withdraw != null)
  10250. {
  10251. if (!withdraw.userid.Equals(CurrentUser.UserID))
  10252. {
  10253. returnSuccessMsg("您没有权限操作!");
  10254. return;
  10255. }
  10256. else
  10257. {
  10258. if (reason.Equals("1"))
  10259. {
  10260. if (entity.OrderState == -1)
  10261. {
  10262. if (entity.FinishPlaceTime == null)
  10263. {
  10264. entity.OrderState = 2;
  10265. }
  10266. else
  10267. {
  10268. entity.OrderState = 6;
  10269. }
  10270. //配件单直接到下单部
  10271. if (entity.IsSample == 4)
  10272. {
  10273. entity.OrderState = 5;
  10274. }
  10275. }
  10276. entity.Update();
  10277. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10278. if (withdraw != null)
  10279. {
  10280. withdraw.status = int.Parse(reason);
  10281. withdraw.Update();
  10282. }
  10283. returnSuccessMsg("操作成功!");
  10284. return;
  10285. }
  10286. else
  10287. {
  10288. withdraw.status = int.Parse(reason);
  10289. withdraw.acknowledgingtime = DateTime.Now;
  10290. withdraw.Update();
  10291. returnSuccessMsg("查看详细请点击线下订单查询");
  10292. return;
  10293. }
  10294. }
  10295. }
  10296. // 第一个字符是 'N'
  10297. }
  10298. if (eid[0] != 'N')
  10299. {
  10300. }
  10301. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10302. {
  10303. entity.IsVerifyToSupplier = false;
  10304. entity.IsReturn = 1;
  10305. entity.ReturnTime = DateTime.Now;
  10306. entity.ReturnReason = reason;
  10307. if (entity.OrderState == 6)
  10308. {
  10309. entity.OrderState = 5;
  10310. }
  10311. entity.Update();
  10312. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10313. if (withdraw != null)
  10314. {
  10315. withdraw.status = int.Parse(reason);
  10316. withdraw.Update();
  10317. }
  10318. returnSuccessMsg("操作成功!");
  10319. return;
  10320. }
  10321. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10322. {
  10323. ;
  10324. if (withdraw != null)
  10325. {
  10326. withdraw.status = int.Parse(reason);
  10327. withdraw.acknowledgingtime = DateTime.Now;
  10328. withdraw.Update();
  10329. returnSuccessMsg("供应商取消撤回!");
  10330. return;
  10331. }
  10332. }
  10333. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10334. {
  10335. if (entity.OrderState == -1)
  10336. {
  10337. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10338. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10339. /*if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10340. {
  10341. returnErrorMsg("台湾客户需填写身份证!");
  10342. return;
  10343. }*/
  10344. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10345. {
  10346. returnErrorMsg("偏远地区需要填写物流费!");
  10347. return;
  10348. }
  10349. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10350. {
  10351. returnErrorMsg("订单spu没有确认无法通过审核!");
  10352. return;
  10353. }
  10354. if (entity.FinishPlaceTime == null)
  10355. {
  10356. entity.OrderState = 2;
  10357. }
  10358. else
  10359. {
  10360. entity.OrderState = 3;
  10361. }
  10362. commonHelper.getCytPrice(entity);
  10363. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10364. {
  10365. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10366. }
  10367. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10368. {
  10369. entity.OrderState = 6;
  10370. }
  10371. if (entity.IsSample == 4)
  10372. {
  10373. entity.OrderState = 5;
  10374. }
  10375. }
  10376. entity.Update();
  10377. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10378. if (withdraw != null)
  10379. {
  10380. withdraw.status = int.Parse(reason);
  10381. withdraw.Update();
  10382. }
  10383. returnSuccessMsg("操作成功!");
  10384. return;
  10385. }
  10386. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10387. {
  10388. if (withdraw == null)
  10389. {
  10390. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10391. return;
  10392. }
  10393. }
  10394. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10395. {
  10396. if (withdraw != null)
  10397. {
  10398. withdraw.status = int.Parse(reason);
  10399. withdraw.acknowledgingtime = DateTime.Now;
  10400. withdraw.Update();
  10401. returnSuccessMsg("查看详细请点击线下订单查询");
  10402. return;
  10403. }
  10404. }
  10405. return;
  10406. }
  10407. }
  10408. //校验报价
  10409. public void refund_order_tip()
  10410. {
  10411. int userid = CurrentUser.UserID;
  10412. int sectionId = CurrentUser.UserPost.OrgID;
  10413. StringBuilder sql = new StringBuilder();
  10414. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10415. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10416. List<string> ids = new List<string>();
  10417. if (dth.Rows.Count > 0)
  10418. {
  10419. foreach (DataRow dr in dth.Rows)
  10420. {
  10421. ids.Add(dr["ID"].ToString());
  10422. }
  10423. try
  10424. {
  10425. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10426. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10427. }
  10428. catch (Exception ex)
  10429. {
  10430. }
  10431. }
  10432. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10433. }
  10434. public void refund_order_Design()
  10435. {
  10436. int userid = CurrentUser.UserID;
  10437. int sectionId = CurrentUser.UserPost.OrgID;
  10438. StringBuilder sql = new StringBuilder();
  10439. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10440. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10441. List<string> ids = new List<string>();
  10442. if (dth.Rows.Count > 0)
  10443. {
  10444. foreach (DataRow dr in dth.Rows)
  10445. {
  10446. ids.Add(dr["ID"].ToString());
  10447. }
  10448. try
  10449. {
  10450. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10451. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10452. }
  10453. catch (Exception ex)
  10454. {
  10455. }
  10456. }
  10457. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10458. }
  10459. public void change_order_info()
  10460. {
  10461. int userid = CurrentUser.UserID;
  10462. StringBuilder sql = new StringBuilder();
  10463. 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);
  10464. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10465. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10466. }
  10467. public void size_order_tip()
  10468. {
  10469. int userid = CurrentUser.UserID;
  10470. StringBuilder sql = new StringBuilder();
  10471. sql.AppendFormat("select top 1 * from CE_ErpMessageTip c where (c.userId = '{0}' ) and c.isVisit = 0 and c.type in (3,4);", userid);
  10472. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10473. List<string> ids = new List<string>();
  10474. if (dth.Rows.Count > 0)
  10475. {
  10476. foreach (DataRow dr in dth.Rows)
  10477. {
  10478. ids.Add(dr["ID"].ToString());
  10479. }
  10480. try
  10481. {
  10482. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10483. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10484. }
  10485. catch (Exception ex)
  10486. {
  10487. }
  10488. }
  10489. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10490. }
  10491. public void change_win_mome()
  10492. {
  10493. if (UrlPostParmsCheck("id,ctid"))
  10494. {
  10495. string id = GetPostString("id");
  10496. string ctid = GetPostString("ctid");
  10497. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10498. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10499. if (ce == null || ceErpMessageTip == null)
  10500. {
  10501. returnSuccessMsg("未找到对应的订单!");
  10502. return;
  10503. }
  10504. if (ce.OrderState >= 5)
  10505. {
  10506. ceErpMessageTip.isVisit = true;
  10507. ceErpMessageTip.Update();
  10508. returnSuccessMsg("已上传文件无法修改!");
  10509. return;
  10510. }
  10511. int type = GetPostInt("type");
  10512. string content = GetPostString("content");
  10513. if (type == 0)
  10514. {
  10515. content = content.Replace("(", "(");
  10516. content = content.Replace(")", ")");
  10517. string check = MidStrEx(content, "(", ")").Trim();
  10518. if (string.IsNullOrEmpty(check))
  10519. {
  10520. returnSuccessMsg("文件名格式不正确");
  10521. return;
  10522. }
  10523. }
  10524. ce.seller_memo = content;
  10525. ce.Update();
  10526. ceErpMessageTip.isVisit = true;
  10527. ceErpMessageTip.Update();
  10528. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10529. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10530. ApiVo apiVo = new ApiVo();
  10531. apiVo.orderNumber = ce.ctid;
  10532. apiVo.actionName = "demandDesign";
  10533. apiVo.orderRemarks = content;
  10534. apiVo.demandExamine = type + 1;
  10535. designHelper.API_WorkCore(apiVo);//demandDesign
  10536. returnSuccessMsg("修改成功!");
  10537. }
  10538. }
  10539. public static string MidStrEx(string sourse, string startstr, string endstr)
  10540. {
  10541. string result = string.Empty;
  10542. int startindex, endindex;
  10543. try
  10544. {
  10545. startindex = sourse.IndexOf(startstr);
  10546. if (startindex == -1)
  10547. return result;
  10548. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10549. endindex = tmpstr.IndexOf(endstr);
  10550. if (endindex == -1)
  10551. return result;
  10552. result = tmpstr.Remove(endindex);
  10553. }
  10554. catch (Exception ex)
  10555. {
  10556. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10557. }
  10558. return result;
  10559. }
  10560. public void refund_order_list()
  10561. {
  10562. int userid = CurrentUser.UserID;
  10563. int sectionId = CurrentUser.UserPost.OrgID;
  10564. StringBuilder sql = new StringBuilder();
  10565. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10566. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10567. DataStruct dStruct = GetPostStruct();
  10568. DataTable dt = null;
  10569. List<string> ids = new List<string>();
  10570. List<string> tids = new List<string>();
  10571. if (dth.Rows.Count > 0)
  10572. {
  10573. foreach (DataRow dr in dth.Rows)
  10574. {
  10575. tids.Add("'" + dr["tid"].ToString() + "'");
  10576. ids.Add(dr["id"].ToString());
  10577. }
  10578. try
  10579. {
  10580. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10581. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10582. List<string> lw = new List<string>();
  10583. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10584. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10585. dt = WebCache.GetData("view_orderlist", dStruct);
  10586. }
  10587. catch (Exception ex)
  10588. {
  10589. }
  10590. }
  10591. writeGridDataTableJson(dStruct.TotalCount, dt);
  10592. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10593. }
  10594. //新增
  10595. public void order_batch_downloads()
  10596. {
  10597. string ceid = GetPostString("tid");
  10598. String[] tid = ceid.Split(',');
  10599. order_batch_caiyingtong(tid);
  10600. /* (string success, string errors) = UploadFiles(tid);
  10601. returnSuccessMsg(success + errors);*/
  10602. return;
  10603. }
  10604. //报价接口
  10605. public void Get_To_Quote()
  10606. {
  10607. string ceid = GetPostString("ctid");
  10608. if (ceid != null)
  10609. {
  10610. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10611. if (entity != null)
  10612. {
  10613. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10614. {
  10615. return;
  10616. }
  10617. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10618. double price = 0;
  10619. if (cp == null)
  10620. {
  10621. JObject jsonObject12 = new JObject
  10622. {
  10623. { "UserId", "77886" },
  10624. { "Pwd", "lt666888" },
  10625. { "Filename", entity.seller_memo }
  10626. };
  10627. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10628. JObject jsonObjects1 = JObject.Parse(response1);
  10629. string ms1g = (string)jsonObjects1["msg"];
  10630. if (ms1g == "报价成功")
  10631. {
  10632. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10633. string data = (string)jsonObject1["price"];
  10634. 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 + "');";
  10635. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10636. returnSuccessMsg("获取报价成功:" + data);
  10637. price = Convert.ToDouble(data);
  10638. }
  10639. else
  10640. {
  10641. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10642. return;
  10643. }
  10644. }
  10645. String[] beizhu = entity.seller_memo.Split('-');
  10646. String chanp = "";
  10647. if (beizhu.Length > 0)
  10648. {
  10649. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10650. }
  10651. else
  10652. {
  10653. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10654. }
  10655. JObject jsonObject = new JObject
  10656. {
  10657. { "UserId", "77886" },
  10658. { "Pwd", "lt666888" },
  10659. { "Filename", chanp }
  10660. };
  10661. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10662. JObject jsonObjects = JObject.Parse(response);
  10663. string msg = (string)jsonObjects["msg"];
  10664. if (msg == "报价成功")
  10665. {
  10666. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10667. string data = (string)jsonObject1["price"];
  10668. 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 + "');";
  10669. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10670. returnSuccessMsg("获取报价成功:" + data);
  10671. price = Convert.ToDouble(data);
  10672. }
  10673. else
  10674. {
  10675. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10676. return;
  10677. }
  10678. if (price > 0)
  10679. {
  10680. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10681. if (ceErpTradeCellExtend == null)
  10682. {
  10683. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10684. ceErpTradeCellExtend.ctid = entity.ctid;
  10685. ceErpTradeCellExtend.payment_cyt = price;
  10686. ceErpTradeCellExtend.Create();
  10687. }
  10688. else
  10689. {
  10690. ceErpTradeCellExtend.payment_cyt = price;
  10691. ceErpTradeCellExtend.Update();
  10692. }
  10693. }
  10694. return;
  10695. }
  10696. }
  10697. else
  10698. {
  10699. returnErrorMsg("请至少选择一条数据");
  10700. return;
  10701. }
  10702. }
  10703. //新增
  10704. public void order_To_Supplier()
  10705. {
  10706. string ceid = GetPostString("tid");
  10707. String[] tid = ceid.Split(',');
  10708. if (tid.Length > 0)
  10709. {
  10710. try
  10711. {
  10712. for (int i = 0; i < tid.Length; i++)
  10713. {
  10714. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10715. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10716. entity.SupplierId = suid;
  10717. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10718. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10719. entity.Update();
  10720. }
  10721. }
  10722. catch (Exception ex)
  10723. {
  10724. returnErrorMsg("自动匹配供应商失败");
  10725. return;
  10726. }
  10727. }
  10728. else
  10729. {
  10730. returnErrorMsg("请至少选择一条数据");
  10731. return;
  10732. }
  10733. returnSuccessMsg("自动匹配供应商成功");
  10734. return;
  10735. }
  10736. public (string, string) UploadFiles(string[] urls)
  10737. {
  10738. string success = "";
  10739. string errors = "";
  10740. int userid = CurrentUser.UserID;
  10741. foreach (string url in urls)
  10742. {
  10743. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10744. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10745. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10746. {
  10747. JObject jsonObject = new JObject
  10748. {
  10749. { "Userid", "77886" },
  10750. { "pwd", "cyt86435015" },
  10751. { "content", base64FileContent },
  10752. { "ext", Path.GetExtension(fileName) }
  10753. };
  10754. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10755. JObject jsonObjects = JObject.Parse(response);
  10756. string msg = (string)jsonObjects["msg"];
  10757. if (msg.Equals("上传成功"))
  10758. {
  10759. success += url + " 上传成功";
  10760. }
  10761. else
  10762. {
  10763. errors += url + " 上传失败";
  10764. }
  10765. }
  10766. else
  10767. {
  10768. errors += url + " 格式出现问题";
  10769. }
  10770. }
  10771. if (urls.Length == 0)
  10772. {
  10773. return (success, errors);
  10774. }
  10775. return (success, errors);
  10776. }
  10777. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10778. {
  10779. return true; //总是接受
  10780. }
  10781. public static string HttpPost(string url, string param = null)
  10782. {
  10783. HttpWebRequest request;
  10784. //如果是发送HTTPS请求
  10785. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10786. {
  10787. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10788. request = WebRequest.Create(url) as HttpWebRequest;
  10789. request.ProtocolVersion = HttpVersion.Version10;
  10790. }
  10791. else
  10792. {
  10793. request = WebRequest.Create(url) as HttpWebRequest;
  10794. }
  10795. request.Method = "POST";
  10796. request.ContentType = "application/json";
  10797. request.Accept = "*/*";
  10798. request.Timeout = 120000;
  10799. request.AllowAutoRedirect = false;
  10800. StreamWriter requestStream = null;
  10801. WebResponse response = null;
  10802. string responseStr = null;
  10803. try
  10804. {
  10805. requestStream = new StreamWriter(request.GetRequestStream());
  10806. requestStream.Write(param);
  10807. requestStream.Close();
  10808. response = request.GetResponse();
  10809. if (response != null)
  10810. {
  10811. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10812. responseStr = reader.ReadToEnd();
  10813. reader.Close();
  10814. }
  10815. }
  10816. catch (Exception ex)
  10817. {
  10818. return ex.Message;
  10819. }
  10820. finally
  10821. {
  10822. request = null;
  10823. requestStream = null;
  10824. response = null;
  10825. }
  10826. return responseStr;
  10827. }
  10828. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10829. {
  10830. string base64FileContent;
  10831. string fileName;
  10832. using (WebClient webClient = new WebClient())
  10833. {
  10834. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10835. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10836. {
  10837. using (Stream stream = response.GetResponseStream())
  10838. {
  10839. using (MemoryStream memoryStream = new MemoryStream())
  10840. {
  10841. stream.CopyTo(memoryStream);
  10842. byte[] fileBytes = memoryStream.ToArray();
  10843. base64FileContent = Convert.ToBase64String(fileBytes);
  10844. fileName = response.Headers["Content-Disposition"];
  10845. if (!string.IsNullOrEmpty(fileName))
  10846. {
  10847. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10848. if (index >= 0)
  10849. {
  10850. fileName = fileName.Substring(index + 9).Trim('\"');
  10851. }
  10852. }
  10853. else
  10854. {
  10855. fileName = Path.GetFileName(downloadUrl);
  10856. }
  10857. }
  10858. }
  10859. }
  10860. }
  10861. return (fileName, base64FileContent);
  10862. }
  10863. //新增
  10864. public void order_batch_caiyingtong(string[] downloadUrls)
  10865. {
  10866. try
  10867. {
  10868. //遍历文件
  10869. DataStruct dStruct = GetPostStruct();
  10870. DataTable dt = null;
  10871. int userid = CurrentUser.UserID;
  10872. List<string> ids = new List<string>();//失败组
  10873. List<string> tids = new List<string>();
  10874. using (WebClient webClient = new WebClient())
  10875. {
  10876. foreach (var url in downloadUrls)
  10877. {
  10878. try
  10879. {
  10880. tids.Add("'" + url + "'");
  10881. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10882. if (entity != null)
  10883. {
  10884. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10885. if (cp == null)
  10886. {
  10887. JObject jsonObject = new JObject
  10888. {
  10889. { "Userid", "77886" },
  10890. { "pwd", "lt666888" },
  10891. { "Filename",entity.seller_memo }
  10892. };
  10893. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10894. JObject jsonObjects = JObject.Parse(response);
  10895. string msg = (string)jsonObjects["msg"];
  10896. if (msg == "报价成功")
  10897. {
  10898. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10899. DownloadAndConvertToBase64(url1);
  10900. }
  10901. else
  10902. {
  10903. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10904. }
  10905. }
  10906. else
  10907. {
  10908. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10909. JObject jsonObject = new JObject
  10910. {
  10911. { "Userid", "77886" },
  10912. { "pwd", "lt666888" },
  10913. { "Filename",chanp }
  10914. };
  10915. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10916. JObject jsonObjects = JObject.Parse(response);
  10917. string msg = (string)jsonObjects["msg"];
  10918. if (msg == "报价成功")
  10919. {
  10920. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10921. DownloadAndConvertToBase64(url1);
  10922. }
  10923. else
  10924. {
  10925. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10926. }
  10927. }
  10928. }
  10929. // 上传文件到FTP
  10930. }
  10931. catch (Exception ex)
  10932. {
  10933. Console.WriteLine($"An error occurred: {ex.Message}");
  10934. }
  10935. }
  10936. List<string> lw = new List<string>();
  10937. lw.Add(string.Format("( OrderState < 6 )"));
  10938. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10939. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10940. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10941. if (dt.Rows.Count > 0)
  10942. {
  10943. foreach (DataRow dr in dt.Rows)
  10944. {
  10945. ids.Add(dr["ctid"].ToString());
  10946. }
  10947. }
  10948. String ErrorMsgs = "";
  10949. foreach (String id in ids)
  10950. {
  10951. ErrorMsgs += id + ",";
  10952. }
  10953. if (ErrorMsgs.Length > 1)
  10954. {
  10955. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10956. }
  10957. if (ErrorMsgs.Length < 1)
  10958. {
  10959. ErrorMsgs = "上传成功";
  10960. returnSuccessMsg(ErrorMsgs);
  10961. }
  10962. else
  10963. {
  10964. returnErrorMsg("以下订单" + ErrorMsgs);
  10965. }
  10966. }
  10967. // 删除文件夹及其内容
  10968. /* Directory.Delete(localDirectory, true);*/
  10969. }
  10970. catch { }
  10971. }
  10972. public void get_center_data()
  10973. {
  10974. int userId = CurrentUser.UserID;
  10975. string postCode = CurrentUser.UserPost.Post.Code;
  10976. List<string> lw = new List<string>();
  10977. List<string> ww = new List<string>();
  10978. DateTime currentTime = DateTime.Now;
  10979. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10980. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10981. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10982. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10983. string sql = " SELECT ";
  10984. string startTime = "2023-10-01 11:22:31";
  10985. //设计
  10986. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10987. {
  10988. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10989. 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));
  10990. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10991. 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));
  10992. }
  10993. //客服
  10994. else if (postCode == "CustomerService" || postCode == "Director")
  10995. {
  10996. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10997. 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));
  10998. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10999. 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));
  11000. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  11001. 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));
  11002. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  11003. 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));
  11004. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  11005. 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));
  11006. }
  11007. //售后
  11008. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  11009. {
  11010. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  11011. 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));
  11012. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  11013. 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));
  11014. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  11015. 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));
  11016. }
  11017. //下单部
  11018. else if (postCode == "Place" || postCode == "PlaceMr")
  11019. {
  11020. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  11021. 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));
  11022. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  11023. 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));
  11024. }
  11025. //车间
  11026. else if (postCode == "Supplier")
  11027. {
  11028. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  11029. 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));
  11030. }
  11031. DataTable dt = new DataTable();
  11032. if (lw.Count > 0)
  11033. {
  11034. sql += string.Join(" , ", lw);
  11035. sql += " FROM ";
  11036. sql += string.Join(" , ", ww);
  11037. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11038. }
  11039. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  11040. }
  11041. public void get_center_data_list()
  11042. {
  11043. int userId = CurrentUser.UserID;
  11044. string postCode = CurrentUser.UserPost.Post.Code;
  11045. string shopIds = CurrentUser.User.pemShop;
  11046. DataStruct dStruct = GetPostStruct();
  11047. List<string> lw = new List<string>();
  11048. DateTime currentTime = DateTime.Now;
  11049. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  11050. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  11051. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  11052. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  11053. string startTime = "2023-10-01 11:22:31";
  11054. int order_type = GetPostInt("order_type");
  11055. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  11056. {
  11057. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  11058. if (order_type == 0)
  11059. {
  11060. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  11061. }
  11062. else if (order_type == 3)
  11063. {
  11064. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  11065. }
  11066. else
  11067. {
  11068. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  11069. }
  11070. }
  11071. //客服
  11072. if (postCode == "CustomerService" || postCode == "Director")
  11073. {
  11074. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  11075. if (order_type == 0)
  11076. {
  11077. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  11078. }
  11079. else if (order_type == 1)
  11080. {
  11081. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  11082. }
  11083. else if (order_type == 2)
  11084. {
  11085. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  11086. }
  11087. else if (order_type == 3)
  11088. {
  11089. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  11090. }
  11091. else if (order_type == 4)
  11092. {
  11093. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  11094. }
  11095. else
  11096. {
  11097. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  11098. }
  11099. }
  11100. //售后
  11101. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  11102. {
  11103. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  11104. if (shopIds != "")
  11105. {
  11106. lw.Add(string.Format("ShopId in ({0})", shopIds));
  11107. }
  11108. if (order_type == 2)
  11109. {
  11110. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  11111. }
  11112. else if (order_type == 4)
  11113. {
  11114. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  11115. }
  11116. else if (order_type == 5)
  11117. {
  11118. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  11119. }
  11120. else
  11121. {
  11122. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  11123. }
  11124. }
  11125. //下单部
  11126. if (postCode == "Place" || postCode == "PlaceMr")
  11127. {
  11128. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  11129. if (shopIds != "")
  11130. {
  11131. lw.Add(string.Format("ShopId in ({0})", shopIds));
  11132. }
  11133. else if (order_type == 1)
  11134. {
  11135. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  11136. }
  11137. else if (order_type == 2)
  11138. {
  11139. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  11140. }
  11141. else
  11142. {
  11143. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  11144. }
  11145. }
  11146. //车间
  11147. if (postCode == "Supplier")
  11148. {
  11149. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  11150. if (order_type == 5)
  11151. {
  11152. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  11153. }
  11154. else
  11155. {
  11156. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  11157. }
  11158. }
  11159. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11160. dStruct.Fileds = "tid,ctid";
  11161. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  11162. writeGridDataTableJson(dStruct.TotalCount, dt);
  11163. }
  11164. public void aftersale_audit_master()
  11165. {
  11166. if (UrlPostParmsCheck("ctid"))
  11167. {
  11168. string ctid = GetPostString("ctid");
  11169. if (ctid.Length > 0)
  11170. {
  11171. bool result = aftersale_data_change(ctid);
  11172. if (result)
  11173. {
  11174. returnSuccessMsg("修改成功!");
  11175. return;
  11176. }
  11177. }
  11178. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11179. }
  11180. }
  11181. public void aftersale_documentary_finish()
  11182. {
  11183. if (UrlPostParmsCheck("ctid"))
  11184. {
  11185. string ctid = GetPostString("ctid");
  11186. if (ctid.Length > 0)
  11187. {
  11188. List<string> list = new List<string>();
  11189. string[] ctid_list = ctid.Split(',');
  11190. foreach (var item in ctid_list)
  11191. {
  11192. try
  11193. {
  11194. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(item);
  11195. if (ceErpTradeAfterSaleExtend == null)
  11196. {
  11197. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11198. ceErpTradeAfterSaleExtend.tid = item;
  11199. }
  11200. ceErpTradeAfterSaleExtend.AfterSalSend = 1;
  11201. if (ceErpTradeAfterSaleExtend.ID > 0)
  11202. {
  11203. ceErpTradeAfterSaleExtend.Update();
  11204. }
  11205. else
  11206. {
  11207. ceErpTradeAfterSaleExtend.Create();
  11208. }
  11209. LogHelper.addLog(item, CurrentUser.UserID, "跟单完成", 6, 4);
  11210. }
  11211. catch (Exception ex)
  11212. {
  11213. list.Add(item);
  11214. }
  11215. }
  11216. if (list.Count > 0)
  11217. {
  11218. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11219. return;
  11220. }
  11221. returnSuccessMsg("修改成功!");
  11222. return;
  11223. }
  11224. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11225. }
  11226. }
  11227. public void aftersale_batch_audit_master()
  11228. {
  11229. if (UrlPostParmsCheck("ctids"))
  11230. {
  11231. string ctids = GetPostString("ctids");
  11232. if (ctids.Length > 0)
  11233. {
  11234. List<string> list = new List<string>();
  11235. string[] ctid_list = ctids.Split(',');
  11236. foreach (var item in ctid_list)
  11237. {
  11238. bool result = aftersale_data_change(item);
  11239. if (!result)
  11240. {
  11241. list.Add(item);
  11242. }
  11243. }
  11244. if (list.Count > 0)
  11245. {
  11246. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11247. return;
  11248. }
  11249. returnSuccessMsg("修改成功!");
  11250. return;
  11251. }
  11252. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11253. }
  11254. }
  11255. public bool aftersale_data_change(string ctid)
  11256. {
  11257. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11258. if (ceErpTradeCell != null)
  11259. {
  11260. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  11261. ceErpTradeCell.AfterSaleSupplierState = 0;
  11262. StringBuilder sql = new StringBuilder();
  11263. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  11264. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11265. CeErpTradeResponsible.DelByTid(ctid, 0);
  11266. 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 == "不理赔")
  11267. {
  11268. CeErpTradeResponsible.DelByTid(ctid, -1);
  11269. ceErpTradeCell.AfterSaleSupplierState = 1;
  11270. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11271. ceErpTradeCell.AfterSaleState = 4;
  11272. }
  11273. else
  11274. {
  11275. ceErpTradeCell.AfterSaleState = 3;
  11276. }
  11277. bool needCyt = false;
  11278. if (dt != null)
  11279. {
  11280. if (dt.Rows.Count == 1)
  11281. {
  11282. bool isEnd = false;
  11283. foreach (DataRow dr in dt.Rows)
  11284. {
  11285. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11286. {
  11287. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11288. isEnd = true;
  11289. }
  11290. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  11291. {
  11292. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11293. isEnd = true;
  11294. }
  11295. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11296. {
  11297. needCyt = true;
  11298. }
  11299. }
  11300. if (isEnd)
  11301. {
  11302. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11303. ceErpTradeCell.AfterSaleState = 4;
  11304. ceErpTradeCell.AfterSaleSupplierState = 1;
  11305. }
  11306. }
  11307. else
  11308. {
  11309. bool isAll = true;
  11310. foreach (DataRow dr in dt.Rows)
  11311. {
  11312. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11313. {
  11314. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11315. continue;
  11316. }
  11317. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  11318. {
  11319. string path = "";
  11320. int OrgID = 0;
  11321. if (!Convert.IsDBNull(dr["OrgPath"]))
  11322. {
  11323. path = dr["OrgPath"].ToString();
  11324. }
  11325. if (!Convert.IsDBNull(dr["OrgID"]))
  11326. {
  11327. OrgID = Convert.ToInt32(dr["OrgID"]);
  11328. }
  11329. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  11330. {
  11331. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11332. continue;
  11333. }
  11334. }
  11335. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11336. {
  11337. needCyt = true;
  11338. }
  11339. isAll = false;
  11340. }
  11341. if (isAll)
  11342. {
  11343. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11344. ceErpTradeCell.AfterSaleState = 4;
  11345. ceErpTradeCell.AfterSaleSupplierState = 1;
  11346. }
  11347. }
  11348. }
  11349. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11350. {
  11351. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11352. }
  11353. if (ceErpTradeCell.AfterSaleState == 4)
  11354. {
  11355. ApiVo apiVo = new ApiVo();
  11356. apiVo.orderNumber = ceErpTradeCell.ctid;
  11357. apiVo.actionName = "afterOver";
  11358. designHelper.API_WorkCore(apiVo); //afterOver
  11359. }
  11360. ceErpTradeCell.Update();
  11361. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11362. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11363. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11364. return true;
  11365. }
  11366. return false;
  11367. }
  11368. public void get_erp_wechatorder()
  11369. {
  11370. DataStruct dStruct = GetPostStruct();
  11371. List<string> lw = new List<string>();
  11372. string tid = GetPostString("tid");
  11373. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11374. string shopname = GetPostString("shopname");
  11375. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11376. string buyernick = GetPostString("buyer_nick");
  11377. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11378. string customer = GetPostString("customer");
  11379. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11380. string returndate1 = GetPostString("returndate1");
  11381. string returndate2 = GetPostString("returndate2");
  11382. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11383. if (dw.Length > 0) lw.Add(dw);
  11384. string finishDate1 = GetPostString("finishdate1");
  11385. string finishDate2 = GetPostString("finishdate2");
  11386. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11387. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11388. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11389. dStruct.Order = "created desc";
  11390. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11391. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11392. writeGridDataTableJson(dStruct.TotalCount, dt);
  11393. }
  11394. public void get_erp_wechatlist_sumprice()
  11395. {
  11396. DataStruct dStruct = GetPostStruct();
  11397. List<string> lw = new List<string>();
  11398. string tid = GetPostString("tid");
  11399. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11400. string shopname = GetPostString("shopname");
  11401. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11402. string buyernick = GetPostString("buyer_nick");
  11403. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11404. string customer = GetPostString("customer");
  11405. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11406. string returndate1 = GetPostString("returndate1");
  11407. string returndate2 = GetPostString("returndate2");
  11408. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11409. if (dw.Length > 0) lw.Add(dw);
  11410. string finishDate1 = GetPostString("finishdate1");
  11411. string finishDate2 = GetPostString("finishdate2");
  11412. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11413. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11414. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11415. string mainWhere = string.Join(" and ", lw.ToArray());
  11416. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11417. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11418. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11419. decimal total = 0;
  11420. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11421. {
  11422. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11423. }
  11424. var res = new
  11425. {
  11426. data = total
  11427. };
  11428. string ro_jsond = JsonConvert.SerializeObject(res);
  11429. returnSuccess(ro_jsond);
  11430. return;
  11431. }
  11432. public void get_erp_qr_waitdeliverylist()
  11433. {
  11434. DataStruct dStruct = GetPostStruct();
  11435. List<string> lw = new List<string>();
  11436. string tid = GetPostString("ctid");
  11437. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11438. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11439. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11440. var res_objz = new
  11441. {
  11442. restype = 1,
  11443. data = dt
  11444. };
  11445. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11446. returnSuccess(ro_jsonz);
  11447. }
  11448. public void get_erp_yield_list()
  11449. {
  11450. DataStruct dStruct = GetPostStruct();
  11451. List<string> lw = new List<string>();
  11452. string tid = GetPostString("ctid");
  11453. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11454. string shopname = GetPostString("shopname");
  11455. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11456. string buyernick = GetPostString("buyer_nick");
  11457. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11458. //if (tid.Length == 0 && buyernick.Length == 0)
  11459. //{
  11460. // lw.Add(string.Format("IsRefund<={0}", 1));
  11461. //}
  11462. string customer = GetPostString("customer");
  11463. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11464. string design = GetPostString("design");
  11465. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11466. string orderState = GetPostString("orderState");
  11467. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11468. string address = GetPostString("address");
  11469. 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));
  11470. string sellermemo = GetPostString("seller_memo");
  11471. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11472. string supplier = GetPostString("supplier");
  11473. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11474. string OrderArea = GetPostString("order_area");
  11475. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11476. string placedate1 = GetPostString("placedate1");
  11477. string placedate2 = GetPostString("placedate2");
  11478. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11479. if (fdw.Length > 0) lw.Add(fdw);
  11480. string price1 = GetPostString("price1");
  11481. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11482. string price2 = GetPostString("price2");
  11483. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11484. string unusualCon = GetPostString("unusualcon");
  11485. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11486. string posTag = CurrentUser.UserPost.Post.Code;
  11487. if (posTag == "Supplier")
  11488. {
  11489. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11490. }
  11491. lw.Add(string.Format("OrderState = 6 "));
  11492. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11493. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11494. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11495. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11496. writeGridDataTableJson(dStruct.TotalCount, dt);
  11497. }
  11498. public void change_erp_sup_state()
  11499. {
  11500. if (UrlPostParmsCheck("ctid"))
  11501. {
  11502. string ctid = GetPostString("ctid");
  11503. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11504. if (ceErpTradeCell != null)
  11505. {
  11506. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11507. if (ceErpTradeCellExtend == null)
  11508. {
  11509. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11510. ceErpTradeCellExtend.ctid = ctid;
  11511. ceErpTradeCellExtend.SupState = 1;
  11512. ceErpTradeCellExtend.Create();
  11513. }
  11514. else
  11515. {
  11516. ceErpTradeCellExtend.SupState = 1;
  11517. ceErpTradeCellExtend.Update();
  11518. }
  11519. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11520. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11521. return;
  11522. }
  11523. returnErrorMsg("找不到订单");
  11524. }
  11525. }
  11526. public void supplier_all_downs()
  11527. {
  11528. if (UrlPostParmsCheck("tids"))
  11529. {
  11530. string tids = GetPostString("tids");
  11531. if (tids != null && tids.Length > 0)
  11532. {
  11533. StringBuilder sql = new StringBuilder();
  11534. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11535. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11536. sql = new StringBuilder();
  11537. 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, "下载设计文件");
  11538. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11539. string[] list = tids.Split(',');
  11540. foreach (string ctid in list)
  11541. {
  11542. CeErpSukuraData.createInfo(ctid, 3);
  11543. }
  11544. designHelper.api_approveDesign(tids); //approveDesign
  11545. returnSuccessMsg("下载成功!");
  11546. return;
  11547. }
  11548. returnErrorMsg("下载订单更新失败");
  11549. }
  11550. }
  11551. public void uploaderFileSuccess()
  11552. {
  11553. if (UrlPostParmsCheck("fileName"))
  11554. {
  11555. string fileName = GetPostString("fileName");
  11556. ApiVo apiVo = new ApiVo();
  11557. apiVo.orderNumber = fileName;
  11558. apiVo.actionName = "finishDesign";
  11559. designHelper.API_WorkCore(apiVo);//finishDesign
  11560. returnSuccessMsg("");
  11561. }
  11562. }
  11563. public void get_sample2_order()
  11564. {
  11565. if (UrlPostParmsCheck("ctid"))
  11566. {
  11567. string ctid = GetPostString("ctid");
  11568. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11569. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11570. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11571. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11572. double total = 0.0;
  11573. double order_price = 0.0;
  11574. if (dt_bu.Rows.Count > 0)
  11575. {
  11576. foreach (DataRow dr in dt_bu.Rows)
  11577. {
  11578. total += Convert.ToDouble(dr["payment"]);
  11579. }
  11580. }
  11581. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11582. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11583. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11584. string tid = ctid.Replace("S_", "");
  11585. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11586. double paymant = 0.0;
  11587. if (entity != null)
  11588. {
  11589. paymant = entity.payment;
  11590. }
  11591. string return_reason = "";
  11592. if (dt_after != null && dt_after.Rows.Count > 0)
  11593. {
  11594. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11595. }
  11596. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11597. }
  11598. }
  11599. public void get_erp_design_status()
  11600. {
  11601. string designName = GetPostString("designName");
  11602. DataStruct dStruct = GetPostStruct();
  11603. if (designName.Length > 0)
  11604. {
  11605. 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";
  11606. sql_user += " and Name like '%" + designName + "%'";
  11607. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11608. List<string> ids_list = new List<string>();
  11609. if (user_table.Rows.Count > 0)
  11610. {
  11611. foreach (DataRow item in user_table.Rows)
  11612. {
  11613. ids_list.Add(item["id"].ToString());
  11614. string ids_s = item["TeamIds"].ToString();
  11615. if (ids_s.Length > 0)
  11616. {
  11617. ids_list.AddRange(ids_s.Split(','));
  11618. }
  11619. }
  11620. }
  11621. HashSet<string> set = new HashSet<string>(ids_list);
  11622. ids_list = set.ToList();
  11623. if (ids_list.Count > 0)
  11624. {
  11625. 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));
  11626. dStruct.MainWhere = sql;
  11627. DataTable dt = null;
  11628. dt = WebCache.GetData("view_ErpUser", dStruct);
  11629. writeGridDataTableJson(dStruct.TotalCount, dt);
  11630. }
  11631. }
  11632. }
  11633. public void change_erp_order_price()
  11634. {
  11635. string ctid = GetPostString("ctid");
  11636. double price = GetPostDouble("price");
  11637. if (ctid.Length > 0)
  11638. {
  11639. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11640. if (ceErpTradeCellExtend == null)
  11641. {
  11642. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11643. ceErpTradeCellExtend.ctid = ctid;
  11644. ceErpTradeCellExtend.payment_cyt = price;
  11645. ceErpTradeCellExtend.Create();
  11646. }
  11647. else
  11648. {
  11649. ceErpTradeCellExtend.payment_cyt = price;
  11650. ceErpTradeCellExtend.Update();
  11651. }
  11652. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11653. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11654. {
  11655. ceErpDataSendOrderInfo.isSync = false;
  11656. ceErpDataSendOrderInfo.Update();
  11657. }
  11658. if (ceErpDataSendOrderInfo == null)
  11659. {
  11660. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11661. ceErpDataSendOrderInfo.isSync = false;
  11662. ceErpDataSendOrderInfo.ctid = ctid;
  11663. ceErpDataSendOrderInfo.Create();
  11664. }
  11665. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11666. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11667. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11668. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11669. {
  11670. dataSendOrderBean dataSendOrderBean = null;
  11671. foreach (DataRow item in dth.Rows)
  11672. {
  11673. try
  11674. {
  11675. dataSendOrderBean = new dataSendOrderBean();
  11676. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11677. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11678. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11679. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11680. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11681. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11682. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11683. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11684. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11685. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11686. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11687. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11688. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11689. if (result != null)
  11690. {
  11691. if ("0".Equals(result.errcode))
  11692. {
  11693. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11694. }
  11695. else
  11696. {
  11697. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11698. }
  11699. }
  11700. }
  11701. catch (Exception ex)
  11702. {
  11703. }
  11704. }
  11705. }
  11706. returnSuccessMsg("修改成功!");
  11707. return;
  11708. }
  11709. returnErrorMsg("找不到订单");
  11710. }
  11711. public void find_he_together()
  11712. {
  11713. string ctid = GetPostString("ctid");
  11714. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11715. List<string> list = new List<string>();
  11716. if (ceErpTradeCell != null)
  11717. {
  11718. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11719. {
  11720. 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);
  11721. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11722. if (table != null && table.Rows.Count > 0)
  11723. {
  11724. foreach (TableRow row in table.Rows)
  11725. {
  11726. }
  11727. }
  11728. }
  11729. }
  11730. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11731. }
  11732. //不统计
  11733. List<int> no_suppliers = new List<int>()
  11734. {
  11735. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11736. };
  11737. List<int> no_shop = new List<int>()
  11738. {
  11739. 136,114,34,96
  11740. };
  11741. public void get_place_order_data()
  11742. {
  11743. string date1 = GetPostString("date1");
  11744. string date2 = GetPostString("date2");
  11745. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11746. DateTime start = DateTime.Parse(starttime);
  11747. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11748. DateTime end = DateTime.Parse(endtime);
  11749. if (date1 != null && date1.Length > 0)
  11750. {
  11751. DateTime dateTime = DateTime.Parse(date1);
  11752. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11753. start = DateTime.Parse(starttime);
  11754. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11755. end = DateTime.Parse(endtime);
  11756. }
  11757. if (date2 != null && date2.Length > 0)
  11758. {
  11759. DateTime dateTime = DateTime.Parse(date2);
  11760. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11761. end = DateTime.Parse(endtime);
  11762. }
  11763. string startMonthDate = commonHelper.FirstDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 00:00:00");
  11764. string endMonthDate = commonHelper.LastDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 23:59:59");
  11765. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime,AfterSaleState=0,AfterSaleReason = '',delivery=0,shopId,UnusualTag from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  11766. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11767. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState,AfterSaleReason,delivery=0,shopId,UnusualTag FROM view_ErpTradeCell WHERE ( HandleTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime IS NOT NULL", startMonthDate, endMonthDate);
  11768. DataTable afterSaleData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11769. data.Merge(afterSaleData);
  11770. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState=0,AfterSaleReason = '',delivery=1,shopId,UnusualTag FROM view_ErpTradeCell WHERE orderstate = 6 AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime > '2025-11-01 00:00:31.000' AND IsRefund <= 1 AND LEN( ProductName ) > 0 AND SupplierId not in (86,10,105,86)", startMonthDate, endMonthDate);
  11771. DataTable deliveryData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11772. data.Merge(deliveryData);
  11773. //不干胶-----1,卡片-----29
  11774. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11775. foreach (DataRow row in data.Rows)
  11776. {
  11777. int productId = Convert.ToInt32(row["ProductId"]);
  11778. int shopId = Convert.ToInt32(row["shopId"]);
  11779. string ProductName = row["ProductName"].ToString();
  11780. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11781. if (no_suppliers.Contains(supplierId))
  11782. {
  11783. continue;
  11784. }
  11785. string seller_memo = row["seller_memo"].ToString();
  11786. bool ispj = commonHelper.placeDataIsPeijian(seller_memo);//是否配件单
  11787. if (ispj)
  11788. {
  11789. continue;
  11790. }
  11791. seller_memo = seller_memo.Replace("UV", "uv");
  11792. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11793. //吊牌归到卡片
  11794. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11795. seller_memo = seller_memo.Replace("卡套", "卡片");
  11796. seller_memo = seller_memo.Replace("封套", "卡片");
  11797. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11798. seller_memo = seller_memo.Replace("腰封", "卡片");
  11799. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11800. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11801. seller_memo = seller_memo.Replace("横幅", "条幅");
  11802. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11803. string map_key = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  11804. string type = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  11805. if (map_key == "")
  11806. {
  11807. type = ProductName;
  11808. map_key = ProductName;
  11809. }
  11810. if ("其他".Equals(map_key) && commonHelper.suppliers.ContainsKey(supplierId))
  11811. {
  11812. map_key = commonHelper.suppliers[supplierId];
  11813. }
  11814. map_key += "_" + row["SupplierName"].ToString();
  11815. Dictionary<string, int> map = null;
  11816. if (other_map.ContainsKey(map_key))
  11817. {
  11818. other_map.TryGetValue(map_key, out map);
  11819. }
  11820. else
  11821. {
  11822. map = new Dictionary<string, int>();
  11823. map.Add("dayDev", 0);//当天出货
  11824. map.Add("dayTotal", 0);//下单总数
  11825. map.Add("payTotal", 0);//500以上
  11826. map.Add("today", 0);//当天出货数量
  11827. map.Add("unusua", 0);//异常数
  11828. map.Add("aftersale", 0);//异常数
  11829. map.Add("deliveryNum", 0);//待发货数
  11830. other_map.Add(map_key, map);
  11831. other_map.TryGetValue(map_key, out map);
  11832. }
  11833. int afterSaleState = Convert.ToInt32(row["AfterSaleState"]);
  11834. int delivery = Convert.ToInt32(row["delivery"]);
  11835. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11836. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11837. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11838. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11839. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11840. //GD-CYT-----64
  11841. bool istoday = commonHelper.placeDataIsToday(row, type);
  11842. if (afterSaleState == 0 && delivery == 0)
  11843. {
  11844. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11845. {
  11846. map["dayTotal"]++;
  11847. }
  11848. if (Convert.ToDecimal(row["payment"]) >= 500)
  11849. {
  11850. map["payTotal"]++;
  11851. }
  11852. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11853. {
  11854. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11855. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11856. {
  11857. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11858. {
  11859. map["today"]++;
  11860. }
  11861. }
  11862. else
  11863. {
  11864. if (supplierId == 80 || supplierId == 126)
  11865. {
  11866. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11867. {
  11868. map["today"]++;
  11869. }
  11870. }
  11871. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11872. {
  11873. map["today"]++;
  11874. }
  11875. }
  11876. }
  11877. if (istoday)
  11878. {
  11879. map["dayDev"]++;
  11880. }
  11881. }
  11882. else if (delivery == 0)
  11883. {
  11884. if (row["AfterSaleReason"].ToString().Contains("车间责任"))
  11885. {
  11886. map["aftersale"]++;
  11887. }
  11888. }
  11889. else
  11890. {
  11891. map["deliveryNum"]++;
  11892. if (no_shop.Contains(shopId))
  11893. {
  11894. continue;
  11895. }
  11896. if (!Convert.IsDBNull(row["UnusualTag"]) && Convert.ToInt32(row["UnusualTag"]) == 5)
  11897. {
  11898. map["unusua"]++;
  11899. }
  11900. continue;
  11901. }
  11902. }
  11903. DataTable dt = new DataTable();
  11904. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11905. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11906. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11907. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11908. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11909. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11910. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11911. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11912. dt.Columns.Add(new DataColumn("aftersale", typeof(string)));
  11913. dt.Columns.Add(new DataColumn("deliveryNum", typeof(string)));
  11914. other_map.Keys.ForEach(key =>
  11915. {
  11916. DataRow dr = dt.NewRow();
  11917. Dictionary<string, int> map = other_map[key];
  11918. string[] key_list = key.Split('_');
  11919. dr[0] = key_list[0];
  11920. dr[1] = key_list[1];
  11921. if (key_list.Length > 2)
  11922. {
  11923. dr[1] += "(" + key_list[2] + ")";
  11924. }
  11925. dr[2] = map["dayTotal"];
  11926. dr[3] = map["payTotal"];
  11927. dr[4] = map["today"];
  11928. dr[5] = map["unusua"];
  11929. dr[6] = map["dayDev"];
  11930. double rate = 0.00;
  11931. if (map["dayDev"] > 0)
  11932. {
  11933. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11934. }
  11935. dr[7] = rate.ToString();
  11936. dr[8] = map["aftersale"];
  11937. dr[9] = map["deliveryNum"];
  11938. dt.Rows.Add(dr);
  11939. });
  11940. DataView dv = new DataView(dt);
  11941. dv.Sort = "SupplierName";
  11942. //dv.Sort = "ProductName desc";
  11943. DataTable dtNew = dv.ToTable();
  11944. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11945. }
  11946. public void get_place_all_order_data()
  11947. {
  11948. string date1 = GetPostString("date1");
  11949. string date2 = GetPostString("date2");
  11950. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11951. DateTime start = DateTime.Parse(starttime);
  11952. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11953. DateTime end = DateTime.Parse(endtime);
  11954. if (date1 != null && date1.Length > 0)
  11955. {
  11956. DateTime dateTime = DateTime.Parse(date1);
  11957. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11958. start = DateTime.Parse(starttime);
  11959. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11960. end = DateTime.Parse(endtime);
  11961. }
  11962. if (date2 != null && date2.Length > 0)
  11963. {
  11964. DateTime dateTime = DateTime.Parse(date2);
  11965. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11966. end = DateTime.Parse(endtime);
  11967. }
  11968. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11969. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( FinishDeliveryTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  11970. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11971. string timer_sql = string.Format("select * from CE_ErpSupplierProductTime");
  11972. DataTable timer_data = DbHelper.DbConn.ExecuteDataset(timer_sql).Tables[0];
  11973. Dictionary<int, List<CeErpSupplierProductTime>> timer_map = new Dictionary<int, List<CeErpSupplierProductTime>>();
  11974. foreach (DataRow datarow in timer_data.Rows)
  11975. {
  11976. List<CeErpSupplierProductTime> list = null;
  11977. int supplierId = Convert.ToInt32(datarow["SupplierId"]);
  11978. if (timer_map.ContainsKey(supplierId))
  11979. {
  11980. timer_map.TryGetValue(supplierId, out list);
  11981. }
  11982. else
  11983. {
  11984. list = new List<CeErpSupplierProductTime>();
  11985. timer_map.Add(supplierId, list);
  11986. timer_map.TryGetValue(supplierId, out list);
  11987. }
  11988. CeErpSupplierProductTime ceErpSupplierProductTime = new CeErpSupplierProductTime();
  11989. ceErpSupplierProductTime.quantity = Convert.ToInt32(datarow["quantity"]);
  11990. ceErpSupplierProductTime.dayDeadLine = datarow["dayDeadLine"].ToString();
  11991. ceErpSupplierProductTime.deadLine = datarow["deadLine"].ToString();
  11992. ceErpSupplierProductTime.productId = datarow["productId"].ToString();
  11993. ceErpSupplierProductTime.craft = datarow["craft"].ToString();
  11994. ceErpSupplierProductTime.sendDay = Convert.ToInt32(datarow["sendDay"]);
  11995. list.Add(ceErpSupplierProductTime);
  11996. }
  11997. foreach (DataRow row in data.Rows)
  11998. {
  11999. //存储数据
  12000. int productId = Convert.ToInt32(row["ProductId"]);
  12001. string ProductName = row["ProductName"].ToString();
  12002. int supplierId = Convert.ToInt32(row["SupplierId"]);
  12003. if (no_suppliers.Contains(supplierId))
  12004. {
  12005. continue;
  12006. }
  12007. string seller_memo = row["seller_memo"].ToString();
  12008. bool ispj = commonHelper.placeDataIsPeijian(seller_memo);//是否配件单
  12009. if (ispj)
  12010. {
  12011. continue;
  12012. }
  12013. seller_memo = seller_memo.Replace("UV", "uv");
  12014. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  12015. //吊牌归到卡片
  12016. seller_memo = seller_memo.Replace("吊牌", "卡片");
  12017. seller_memo = seller_memo.Replace("卡套", "卡片");
  12018. seller_memo = seller_memo.Replace("封套", "卡片");
  12019. seller_memo = seller_memo.Replace("吸管套", "卡片");
  12020. seller_memo = seller_memo.Replace("腰封", "卡片");
  12021. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  12022. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  12023. seller_memo = seller_memo.Replace("横幅", "条幅");
  12024. seller_memo = seller_memo.Replace("锦旗", "条幅");
  12025. string map_key = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  12026. string type = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  12027. if (map_key == "")
  12028. {
  12029. type = ProductName;
  12030. map_key = ProductName;
  12031. }
  12032. if ("其他".Equals(map_key) && commonHelper.suppliers.ContainsKey(supplierId))
  12033. {
  12034. map_key = commonHelper.suppliers[supplierId];
  12035. }
  12036. map_key += "_" + row["SupplierName"].ToString();
  12037. Dictionary<string, int> map = null;
  12038. if (other_map.ContainsKey(map_key))
  12039. {
  12040. other_map.TryGetValue(map_key, out map);
  12041. }
  12042. else
  12043. {
  12044. map = new Dictionary<string, int>();
  12045. map.Add("all", 0);//全部
  12046. map.Add("unusua", 0);//异常数
  12047. map.Add("normal", 0);//正常数
  12048. map.Add("noMatch", 0);//未匹配
  12049. other_map.Add(map_key, map);
  12050. other_map.TryGetValue(map_key, out map);
  12051. }
  12052. //处理是否超时
  12053. string finishPlaceTime = row["FinishPlaceTime"].ToString();
  12054. string sellmer_mome = row["seller_memo"].ToString();
  12055. string txtCount = row["ProductCount"].ToString();
  12056. string FinishDeliveryTime = row["FinishDeliveryTime"].ToString();
  12057. map["all"]++;
  12058. if (string.IsNullOrEmpty(finishPlaceTime))
  12059. {
  12060. map["noMatch"]++;
  12061. continue;
  12062. }
  12063. if (string.IsNullOrEmpty(FinishDeliveryTime))
  12064. {
  12065. map["noMatch"]++;
  12066. continue;
  12067. }
  12068. if (!timer_map.ContainsKey(supplierId))
  12069. {
  12070. map["noMatch"]++;
  12071. continue;
  12072. }
  12073. List<CeErpSupplierProductTime> lists = timer_map[supplierId];
  12074. if (lists.Count > 0)
  12075. {
  12076. bool isComplate = false;
  12077. string[] productIds = null;
  12078. foreach (CeErpSupplierProductTime ceErpSupplierProductTime in lists)
  12079. {
  12080. string[] crafts = { };
  12081. if (string.IsNullOrEmpty(ceErpSupplierProductTime.productId))
  12082. {
  12083. continue;
  12084. }
  12085. if (ceErpSupplierProductTime.quantity > 0)
  12086. {
  12087. int quantity = commonHelper.handleProductCount(txtCount, true);
  12088. //订单数量大于写入的数量则跳过
  12089. if (quantity > ceErpSupplierProductTime.quantity)
  12090. {
  12091. continue;
  12092. }
  12093. }
  12094. productIds = ceErpSupplierProductTime.productId.Split(',');
  12095. if (productIds.Contains(productId.ToString()))
  12096. {
  12097. string textCraft = ceErpSupplierProductTime.craft;
  12098. textCraft = textCraft.Replace(",", ",");//统一格式
  12099. if (!string.IsNullOrEmpty(textCraft))
  12100. {
  12101. crafts = textCraft.Split(',');
  12102. }
  12103. if (crafts.Length > 0)
  12104. {
  12105. bool isinCraft = false;
  12106. for (int i = 0; i < crafts.Length; i++)
  12107. {
  12108. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12109. {
  12110. isinCraft = true;
  12111. break;
  12112. }
  12113. }
  12114. //有写工艺并且备注中没匹配中则跳过
  12115. if (!isinCraft)
  12116. {
  12117. continue;
  12118. }
  12119. }
  12120. DateTime deadLine = DateTime.Parse(ceErpSupplierProductTime.deadLine);
  12121. DateTime dayDeadLine = DateTime.Parse(ceErpSupplierProductTime.dayDeadLine);
  12122. int sendDay = ceErpSupplierProductTime.sendDay;
  12123. //订单发货时间
  12124. DateTime placeTime = DateTime.Parse(finishPlaceTime);
  12125. DateTime sendtime = DateTime.Now;//预计发货时间
  12126. DateTime dateTime = DateTime.Parse(FinishDeliveryTime);//实际发货时间
  12127. //下单时间小于当日发货时间则不用判断
  12128. //当日发货必须发货
  12129. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12130. {
  12131. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59"));
  12132. }
  12133. else if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12134. {
  12135. //在截稿时间之前下单的可以减去一天时间
  12136. sendDay = Math.Max(1, sendDay - 1);
  12137. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 00:00:00")).AddDays(sendDay);
  12138. }
  12139. else
  12140. {
  12141. sendDay = Math.Max(1, sendDay - 1);
  12142. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59")).AddDays(sendDay);
  12143. }
  12144. isComplate = true;
  12145. //判断有没有到发货日期大于0还没到发货时间
  12146. if (DateTime.Compare(sendtime.Date, dateTime.Date) < 0)
  12147. {
  12148. //匹配到就不要继续匹配了
  12149. map["unusua"]++;
  12150. break;
  12151. }
  12152. else
  12153. {
  12154. map["normal"]++;
  12155. break;
  12156. }
  12157. }
  12158. }
  12159. if (!isComplate)
  12160. {
  12161. map["noMatch"]++;
  12162. continue;
  12163. }
  12164. }
  12165. else
  12166. {
  12167. map["noMatch"]++;
  12168. }
  12169. }
  12170. DataTable dt = new DataTable();
  12171. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  12172. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  12173. dt.Columns.Add(new DataColumn("all", typeof(string)));
  12174. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  12175. dt.Columns.Add(new DataColumn("normal", typeof(string)));
  12176. dt.Columns.Add(new DataColumn("noMatch", typeof(string)));
  12177. dt.Columns.Add(new DataColumn("shipmentRate", typeof(string)));
  12178. other_map.Keys.ForEach(key =>
  12179. {
  12180. DataRow dr = dt.NewRow();
  12181. Dictionary<string, int> map = other_map[key];
  12182. string[] key_list = key.Split('_');
  12183. dr[0] = key_list[0];
  12184. dr[1] = key_list[1];
  12185. if (key_list.Length > 2)
  12186. {
  12187. dr[1] += "(" + key_list[2] + ")";
  12188. }
  12189. dr[2] = map["all"];
  12190. dr[3] = map["unusua"];
  12191. dr[4] = map["normal"];
  12192. dr[5] = map["noMatch"];
  12193. double rate = 0.00;
  12194. if (map["all"] > 0)
  12195. {
  12196. rate = Math.Round(((Convert.ToDouble(map["normal"]) + Convert.ToDouble(map["noMatch"])) / Convert.ToDouble(map["all"])), 2) * 100;
  12197. }
  12198. dr[6] = rate.ToString();
  12199. dt.Rows.Add(dr);
  12200. });
  12201. DataView dv = new DataView(dt);
  12202. dv.Sort = "SupplierName";
  12203. //dv.Sort = "ProductName desc";
  12204. DataTable dtNew = dv.ToTable();
  12205. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  12206. }
  12207. public void check_order_desing_info()
  12208. {
  12209. string ctid = GetPostString("ctid");
  12210. if (!string.IsNullOrEmpty(ctid))
  12211. {
  12212. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12213. if (ceErpTradeCell != null)
  12214. {
  12215. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  12216. returnSuccess(JsonConvert.SerializeObject(new { response }));
  12217. return;
  12218. }
  12219. returnErrorMsg("找不到订单");
  12220. return;
  12221. }
  12222. returnErrorMsg("找不到订单");
  12223. }
  12224. public void get_timeout_detail()
  12225. {
  12226. string poscode = CurrentUser.UserPost.Post.Code;
  12227. DataStruct dStruct = GetPostStruct();
  12228. List<string> lw = new List<string>();
  12229. string id = GetPostString("id");
  12230. string pay_date1 = GetPostString("pay_date1");
  12231. string pay_date2 = GetPostString("pay_date2");
  12232. int type = GetPostInt("type");
  12233. if (type == 0)
  12234. {
  12235. if (pay_date1.Length > 0)
  12236. {
  12237. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  12238. }
  12239. if (pay_date2.Length > 0)
  12240. {
  12241. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  12242. }
  12243. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  12244. }
  12245. if (type == 1)
  12246. {
  12247. if (pay_date1.Length > 0)
  12248. {
  12249. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  12250. }
  12251. if (pay_date2.Length > 0)
  12252. {
  12253. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  12254. }
  12255. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  12256. }
  12257. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12258. DataTable dt = null;
  12259. dt = WebCache.GetData("view_orderlist", dStruct);
  12260. writeGridDataTableJson(dStruct.TotalCount, dt);
  12261. }
  12262. public void saveUrgentChargePrice()
  12263. {
  12264. string ctid = GetPostString("ctid");
  12265. if (!string.IsNullOrEmpty(ctid))
  12266. {
  12267. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12268. if (ceErpTradeCell != null)
  12269. {
  12270. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  12271. if (prices <= 100)
  12272. {
  12273. returnErrorMsg("此订单金额不足100元,无法加急。");
  12274. return;
  12275. }
  12276. double price = GetPostDouble("price");
  12277. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  12278. if (ceErpTradeCellExtend == null)
  12279. {
  12280. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12281. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  12282. }
  12283. ceErpTradeCellExtend.urgentCharge = price;
  12284. if (ceErpTradeCellExtend.ID > 0)
  12285. {
  12286. ceErpTradeCellExtend.Update();
  12287. }
  12288. else
  12289. {
  12290. ceErpTradeCellExtend.Save();
  12291. }
  12292. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  12293. returnSuccessMsg("修改成功!");
  12294. return;
  12295. }
  12296. returnErrorMsg("找不到订单");
  12297. return;
  12298. }
  12299. returnErrorMsg("找不到订单");
  12300. }
  12301. public void finish_erp_order()
  12302. {
  12303. string ctid = GetPostString("ctid");
  12304. if (!string.IsNullOrEmpty(ctid))
  12305. {
  12306. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  12307. {
  12308. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12309. if (ceErpTradeCell != null)
  12310. {
  12311. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  12312. ceErpTradeCell.Update();
  12313. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  12314. returnSuccessMsg("修改成功!");
  12315. return;
  12316. }
  12317. }
  12318. }
  12319. returnErrorMsg("找不到订单");
  12320. }
  12321. public void get_trade_order_list()
  12322. {
  12323. string tid = GetPostString("tid");
  12324. if (!string.IsNullOrEmpty(tid))
  12325. {
  12326. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  12327. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12328. writeGridDataTableJson(data.Rows.Count, data);
  12329. return;
  12330. }
  12331. returnErrorMsg("找不到订单");
  12332. }
  12333. public void save_cell_spu()
  12334. {
  12335. string ctid = GetPostString("ctid");
  12336. string spu_id = GetPostString("spu_id");
  12337. if (!string.IsNullOrEmpty(ctid))
  12338. {
  12339. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12340. if (ceErpTradeCellExtend == null)
  12341. {
  12342. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12343. ceErpTradeCellExtend.ctid = ctid;
  12344. }
  12345. ceErpTradeCellExtend.spu_id = spu_id;
  12346. if (!string.IsNullOrEmpty(spu_id))
  12347. {
  12348. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12349. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  12350. }
  12351. if (ceErpTradeCellExtend.ID == 0)
  12352. {
  12353. ceErpTradeCellExtend.Create();
  12354. }
  12355. else
  12356. {
  12357. ceErpTradeCellExtend.Update();
  12358. }
  12359. returnSuccessMsg("修改成功!");
  12360. return;
  12361. }
  12362. returnErrorMsg("找不到订单");
  12363. }
  12364. public void change_express_info()
  12365. {
  12366. string ctid = GetPostString("ctid");
  12367. string transNo = GetPostString("transNo");
  12368. string transCom = GetPostString("transCom");
  12369. if (!string.IsNullOrEmpty(ctid))
  12370. {
  12371. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12372. if (ceErpTradeCellExtend == null)
  12373. {
  12374. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12375. ceErpTradeCellExtend.ctid = ctid;
  12376. }
  12377. ceErpTradeCellExtend.modExpressNo = transNo;
  12378. ceErpTradeCellExtend.modExpressCom = transCom;
  12379. ceErpTradeCellExtend.readMod = 2;
  12380. if (ceErpTradeCellExtend.ID == 0)
  12381. {
  12382. ceErpTradeCellExtend.Create();
  12383. }
  12384. else
  12385. {
  12386. ceErpTradeCellExtend.Update();
  12387. }
  12388. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  12389. returnSuccessMsg("修改成功!");
  12390. return;
  12391. }
  12392. returnErrorMsg("找不到订单");
  12393. }
  12394. public void get_change_express_list()
  12395. {
  12396. DataStruct dStruct = GetPostStruct();
  12397. List<string> lw = new List<string>();
  12398. int st = 2;
  12399. string tid = GetPostString("ctid");
  12400. if (tid.Length > 0)
  12401. {
  12402. string select_tid = getTidByCtid(tid);
  12403. lw.Add(string.Format("tid='{0}'", select_tid));
  12404. }
  12405. string shopname = GetPostString("shopname");
  12406. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12407. string buyernick = GetPostString("buyer_nick");
  12408. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12409. string sellermemo = GetPostString("seller_memo");
  12410. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12411. string supplier = GetPostString("supplier");
  12412. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12413. string customer = GetPostString("customer");
  12414. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12415. string design = GetPostString("design");
  12416. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12417. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12418. string poscode = CurrentUser.UserPost.Post.Code;
  12419. if (poscode != "SysAdmin")
  12420. {
  12421. string shopid = CurrentUser.User.pemShop;
  12422. lw.Add(string.Format("shopId in ({0})", shopid));
  12423. }
  12424. lw.Add("readMod = 2");
  12425. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12426. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  12427. writeGridDataTableJson(dStruct.TotalCount, dt);
  12428. }
  12429. public void deal_express_complete()
  12430. {
  12431. string ctid = GetPostString("ctid");
  12432. if (!string.IsNullOrEmpty(ctid))
  12433. {
  12434. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12435. if (ceErpTradeCellExtend == null)
  12436. {
  12437. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12438. ceErpTradeCellExtend.ctid = ctid;
  12439. }
  12440. ceErpTradeCellExtend.readMod = 1;
  12441. if (ceErpTradeCellExtend.ID == 0)
  12442. {
  12443. ceErpTradeCellExtend.Create();
  12444. }
  12445. else
  12446. {
  12447. ceErpTradeCellExtend.Update();
  12448. }
  12449. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  12450. returnSuccessMsg("修改成功!");
  12451. return;
  12452. }
  12453. returnErrorMsg("找不到订单");
  12454. }
  12455. public void aftersale_return_visit()
  12456. {
  12457. string ctid = GetPostString("ctid");
  12458. if (!string.IsNullOrEmpty(ctid))
  12459. {
  12460. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12461. if (ceErpTradeCellExtend == null)
  12462. {
  12463. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12464. ceErpTradeCellExtend.ctid = ctid;
  12465. }
  12466. ceErpTradeCellExtend.returnVisit = 1;
  12467. if (ceErpTradeCellExtend.ID == 0)
  12468. {
  12469. ceErpTradeCellExtend.Create();
  12470. }
  12471. else
  12472. {
  12473. ceErpTradeCellExtend.Update();
  12474. }
  12475. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12476. if (ceErpTradeAfterSaleExtend != null)
  12477. {
  12478. ceErpTradeAfterSaleExtend.TextResult = "";
  12479. ceErpTradeAfterSaleExtend.Update();
  12480. }
  12481. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12482. returnSuccessMsg("修改成功!");
  12483. return;
  12484. }
  12485. returnErrorMsg("找不到订单");
  12486. }
  12487. public void orderPlaceInfo()
  12488. {
  12489. string ctids = GetPostString("ctids");
  12490. string[] list = ctids.Split(',');
  12491. foreach (string ctid in list)
  12492. {
  12493. CeErpSukuraData.createInfo(ctid, 3);
  12494. }
  12495. StringBuilder sql = new StringBuilder();
  12496. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12497. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12498. designHelper.api_approveDesign(ctids); //approveDesign
  12499. returnSuccessMsg("");
  12500. }
  12501. public void get_issue_list()
  12502. {
  12503. DataStruct dStruct = GetPostStruct();
  12504. List<string> lw = new List<string>();
  12505. int st = 2;
  12506. string tid = GetPostString("ctid");
  12507. if (tid.Length > 0)
  12508. {
  12509. string select_tid = getTidByCtid(tid);
  12510. lw.Add(string.Format("tid='{0}'", select_tid));
  12511. }
  12512. string shopname = GetPostString("shopname");
  12513. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12514. string buyernick = GetPostString("buyer_nick");
  12515. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12516. string sellermemo = GetPostString("seller_memo");
  12517. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12518. string supplier = GetPostString("supplier");
  12519. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12520. string customer = GetPostString("customer");
  12521. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12522. string design = GetPostString("design");
  12523. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12524. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12525. string poscode = CurrentUser.UserPost.Post.Code;
  12526. if (poscode != "SysAdmin")
  12527. {
  12528. string shopid = CurrentUser.User.pemShop;
  12529. lw.Add(string.Format("shopId in ({0})", shopid));
  12530. }
  12531. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12532. {
  12533. lw.Add("IssueState = 1");
  12534. }
  12535. else
  12536. {
  12537. string iisstate = GetPostString("iisstate");
  12538. if ("1".Equals(iisstate))
  12539. {
  12540. lw.Add("IssueState =1");
  12541. }
  12542. else if ("2".Equals(iisstate))
  12543. {
  12544. lw.Add("IssueState = 2");
  12545. }
  12546. else
  12547. {
  12548. lw.Add("IssueState > 0");
  12549. }
  12550. }
  12551. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12552. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12553. writeGridDataTableJson(dStruct.TotalCount, dt);
  12554. }
  12555. public void saveIssueContent()
  12556. {
  12557. string ctid = GetPostString("ctid");
  12558. if (!string.IsNullOrEmpty(ctid))
  12559. {
  12560. string content = GetPostString("content");
  12561. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12562. if (ceErpTradeAfterSaleExtend == null)
  12563. {
  12564. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12565. ceErpTradeAfterSaleExtend.tid = ctid;
  12566. }
  12567. ceErpTradeAfterSaleExtend.IssueContent = content;
  12568. ceErpTradeAfterSaleExtend.IssueState = 1;
  12569. if (ceErpTradeAfterSaleExtend.ID > 0)
  12570. {
  12571. ceErpTradeAfterSaleExtend.Update();
  12572. }
  12573. else
  12574. {
  12575. ceErpTradeAfterSaleExtend.Create();
  12576. }
  12577. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12578. returnSuccessMsg("添加成功!");
  12579. return;
  12580. }
  12581. returnErrorMsg("找不到订单");
  12582. }
  12583. public void dealIssueContent()
  12584. {
  12585. string ctid = GetPostString("ctid");
  12586. if (!string.IsNullOrEmpty(ctid))
  12587. {
  12588. string content = GetPostString("content");
  12589. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12590. if (ceErpTradeAfterSaleExtend != null)
  12591. {
  12592. ceErpTradeAfterSaleExtend.IssueState = 2;
  12593. ceErpTradeAfterSaleExtend.Update();
  12594. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12595. returnSuccessMsg("修改完成!");
  12596. return;
  12597. }
  12598. }
  12599. returnErrorMsg("找不到订单");
  12600. }
  12601. public void set_tid_attachments()
  12602. {
  12603. string tid = GetPostString("tid");
  12604. string atta = GetPostString("atta");
  12605. if (!string.IsNullOrEmpty(tid))
  12606. {
  12607. if (string.IsNullOrEmpty(atta))
  12608. {
  12609. returnErrorMsg("文件地址为空");
  12610. return;
  12611. }
  12612. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12613. if (ceErpTradeCell != null)
  12614. {
  12615. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12616. if (ceErpTrade == null)
  12617. {
  12618. returnErrorMsg("找不到订单");
  12619. return;
  12620. }
  12621. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12622. bool isSend = false;
  12623. if (dt != null && dt.Rows.Count > 0)
  12624. {
  12625. foreach (DataRow row in dt.Rows)
  12626. {
  12627. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12628. {
  12629. isSend = true;
  12630. }
  12631. }
  12632. if (isSend)
  12633. {
  12634. returnErrorMsg("已发货无法修改");
  12635. return;
  12636. }
  12637. ceErpTrade.Attachments = atta;
  12638. ceErpTrade.Update();
  12639. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12640. returnSuccessMsg("上传成功!");
  12641. return;
  12642. }
  12643. }
  12644. }
  12645. returnErrorMsg("找不到订单");
  12646. }
  12647. public void get_tid_attachments()
  12648. {
  12649. string tid = GetPostString("tid");
  12650. if (!string.IsNullOrEmpty(tid))
  12651. {
  12652. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12653. if (ceErpTradeCell != null)
  12654. {
  12655. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12656. if (ceErpTrade == null)
  12657. {
  12658. returnErrorMsg("找不到订单");
  12659. return;
  12660. }
  12661. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12662. return;
  12663. }
  12664. }
  12665. returnErrorMsg("找不到订单");
  12666. }
  12667. public void check_erp_sameorders()
  12668. {
  12669. if (UrlPostParmsCheck("ctid"))
  12670. {
  12671. string eid = GetPostString("ctid");
  12672. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12673. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12674. if (entity != null && ceErpTrade != null)
  12675. {
  12676. if (entity.OrderState > 6)
  12677. {
  12678. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12679. return;
  12680. }
  12681. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12682. List<string> ids = new List<string>();
  12683. if (dt != null && dt.Rows.Count > 1)
  12684. {
  12685. bool needhe = true;
  12686. foreach (DataRow dr in dt.Rows)
  12687. {
  12688. ids.Add("'" + dr["ctid"] + "'");
  12689. /* //备注有合包
  12690. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12691. {
  12692. needhe = true;
  12693. }
  12694. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12695. {
  12696. needhe = true;
  12697. }
  12698. //顺丰快递
  12699. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12700. {
  12701. needhe = true;
  12702. }*/
  12703. }
  12704. if (!needhe)
  12705. {
  12706. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12707. return;
  12708. }
  12709. StringBuilder sql = new StringBuilder();
  12710. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12711. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12712. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12713. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12714. foreach (DataRow dr in dt.Rows)
  12715. {
  12716. dr["dstate"] = 0;
  12717. dr["dnumber"] = 0;
  12718. foreach (DataRow row in dt1.Rows)
  12719. {
  12720. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12721. {
  12722. dr["dstate"] = 2;
  12723. dr["default"] = 1;
  12724. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12725. }
  12726. }
  12727. if (eid.Equals(dr["ctid"].ToString()))
  12728. {
  12729. dr["dstate"] = 1;
  12730. dr["default"] = 1;
  12731. }
  12732. }
  12733. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12734. return;
  12735. }
  12736. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12737. return;
  12738. }
  12739. returnErrorMsg("未找到订单");
  12740. return;
  12741. }
  12742. returnErrorMsg("缺少必要的参数");
  12743. }
  12744. public void get_mark_number()
  12745. {
  12746. string eid = GetPostString("ctid");
  12747. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12748. if (entity != null)
  12749. {
  12750. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12751. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12752. int current = 1;
  12753. if (ceErpDeliverMark == null)
  12754. {
  12755. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12756. List<string> ids = new List<string>();
  12757. if (dt != null && dt.Rows.Count > 1)
  12758. {
  12759. foreach (DataRow dr in dt.Rows)
  12760. {
  12761. ids.Add("'" + dr["ctid"] + "'");
  12762. }
  12763. //查询已有的编号
  12764. StringBuilder sql = new StringBuilder();
  12765. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12766. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12767. if (dt1 == null || dt1.Rows.Count == 0)
  12768. {
  12769. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12770. List<int> list_number = new List<int>();
  12771. foreach (DataRow row in numbers.Rows)
  12772. {
  12773. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12774. }
  12775. //查询空余编号
  12776. for (int i = 0; i < list_number.Count + 2; i++)
  12777. {
  12778. if (!list_number.Contains(current))
  12779. {
  12780. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12781. //防止查询过程中有新数据生成
  12782. if (ceErpDeliverMark1 == null)
  12783. {
  12784. break;
  12785. }
  12786. }
  12787. current++;
  12788. }
  12789. }
  12790. else
  12791. {
  12792. foreach (DataRow row in dt1.Rows)
  12793. {
  12794. current = Convert.ToInt32(row["markNumber"]);
  12795. }
  12796. }
  12797. ceErpDeliverMark = new CeErpDeliverMark();
  12798. ceErpDeliverMark.ctid = eid;
  12799. ceErpDeliverMark.createtime = DateTime.Now;
  12800. if (ceErpTrade != null)
  12801. {
  12802. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12803. }
  12804. ceErpDeliverMark.markNumber = current;
  12805. ceErpDeliverMark.Create();
  12806. }
  12807. }
  12808. else
  12809. {
  12810. current = ceErpDeliverMark.markNumber;
  12811. }
  12812. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12813. return;
  12814. }
  12815. }
  12816. public void aftersaleCytSend()
  12817. {
  12818. string ctid = GetPostString("ctid");
  12819. if (!string.IsNullOrEmpty(ctid))
  12820. {
  12821. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12822. if (ceErpTradeCell != null)
  12823. {
  12824. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12825. }
  12826. returnSuccessMsg("推送成功");
  12827. return;
  12828. }
  12829. returnErrorMsg("缺少必要的参数");
  12830. }
  12831. public void packOrderInfo()
  12832. {
  12833. string ctids = GetPostString("ctids");
  12834. if (!string.IsNullOrEmpty(ctids))
  12835. {
  12836. string[] ctid_list = ctids.Split(',');
  12837. if (ctid_list.Length > 100)
  12838. {
  12839. returnErrorMsg("单次下载次数不能超过100个");
  12840. return;
  12841. }
  12842. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12843. StringBuilder sql = new StringBuilder();
  12844. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12845. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12846. int supplierId = 0;
  12847. StringBuilder insterSql = new StringBuilder();
  12848. for (int i = 0; i < dt.Rows.Count; i++)
  12849. {
  12850. DataRow row = dt.Rows[i];
  12851. if (i == 0)
  12852. {
  12853. supplierId = Convert.ToInt32(row["SupplierId"]);
  12854. }
  12855. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12856. {
  12857. returnErrorMsg("同车间的订单才能一起打包");
  12858. return;
  12859. }
  12860. int orderState = Convert.ToInt32(row["OrderState"]);
  12861. if (orderState != 5)
  12862. {
  12863. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12864. return;
  12865. }
  12866. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12867. }
  12868. CeErpPackData ceErpPackData = new CeErpPackData();
  12869. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12870. ceErpPackData.supplierId = supplierId;
  12871. ceErpPackData.createtime = DateTime.Now;
  12872. ceErpPackData.createBy = CurrentUser.UserID;
  12873. ceErpPackData.createName = CurrentUser.UserName;
  12874. ceErpPackData.Create();
  12875. if (ceErpPackData.ID > 0)
  12876. {
  12877. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12878. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12879. }
  12880. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12881. returnSuccessMsg("打包成功");
  12882. return;
  12883. }
  12884. returnErrorMsg("缺少必要的参数");
  12885. }
  12886. public void rePackOrderInfo()
  12887. {
  12888. string id = GetPostString("id");
  12889. if (!string.IsNullOrEmpty(id))
  12890. {
  12891. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12892. if (ceErpPackData == null)
  12893. {
  12894. returnSuccessMsg("查无数据");
  12895. return;
  12896. }
  12897. ceErpPackData.upStatus = 0;
  12898. ceErpPackData.message = "";
  12899. ceErpPackData.Update();
  12900. returnSuccessMsg("打包成功");
  12901. return;
  12902. }
  12903. returnErrorMsg("缺少必要的参数");
  12904. }
  12905. public void backPackOrderInfo()
  12906. {
  12907. string id = GetPostString("id");
  12908. if (!string.IsNullOrEmpty(id))
  12909. {
  12910. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12911. if (ceErpPackData == null)
  12912. {
  12913. returnSuccessMsg("查无数据");
  12914. return;
  12915. }
  12916. ceErpPackData.upStatus = 4;
  12917. ceErpPackData.Update();
  12918. List<string> list = new List<string>();
  12919. StringBuilder sql = new StringBuilder();
  12920. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12921. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12922. for (int i = 0; i < dt.Rows.Count; i++)
  12923. {
  12924. DataRow row = dt.Rows[i];
  12925. list.Add("'" + row["ctid"].ToString() + "'");
  12926. }
  12927. string textCtids = string.Join(",", list);
  12928. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=5,IsVerifyToSupplier=0,IsReturn=1,ReturnTime=GETDATE(),ReturnReason='无法打包' where ctid in ({0}) and OrderState=6", textCtids));
  12929. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", textCtids, (int)OrderState.下单完成, 0, "无法打包退回"));
  12930. returnSuccessMsg("退回成功");
  12931. return;
  12932. }
  12933. returnErrorMsg("缺少必要的参数");
  12934. }
  12935. public void addPackDownNum()
  12936. {
  12937. string id = GetPostString("id");
  12938. if (!string.IsNullOrEmpty(id))
  12939. {
  12940. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12941. returnSuccessMsg("下载成功");
  12942. return;
  12943. }
  12944. returnErrorMsg("缺少必要的参数");
  12945. }
  12946. public void get_pack_list()
  12947. {
  12948. DataStruct dStruct = GetPostStruct();
  12949. List<string> lw = new List<string>();
  12950. string supplier = GetPostString("supplier");
  12951. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12952. string posTag = CurrentUser.UserPost.Post.Code;
  12953. if (posTag == "Supplier")
  12954. {
  12955. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12956. }
  12957. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12958. dStruct.Order = "createtime desc";
  12959. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12960. writeGridDataTableJson(dStruct.TotalCount, dt);
  12961. }
  12962. public void get_pack_order_list()
  12963. {
  12964. string packId = GetPostString("packId");
  12965. if (string.IsNullOrEmpty(packId))
  12966. {
  12967. returnErrorMsg("缺少必要的参数");
  12968. return;
  12969. }
  12970. StringBuilder sql = new StringBuilder();
  12971. sql.AppendFormat("select c.ctid,c.seller_memo,i.message from CE_ErpPackDataItem i left join CE_ErpTradeCell c on i.ctid=c.ctid where i.packId = {0}", packId);
  12972. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12973. if (dt == null || dt.Rows.Count == 0)
  12974. {
  12975. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12976. return;
  12977. }
  12978. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12979. return;
  12980. }
  12981. public void get_supplier_product_time_list()
  12982. {
  12983. DataStruct dStruct = GetPostStruct();
  12984. List<string> lw = new List<string>();
  12985. string txtKey = GetPostString("txtKey");
  12986. if (txtKey.Length > 0)
  12987. {
  12988. lw.Add(string.Format("(supplierName = '{0}' or productName like '%{0}%')", txtKey));
  12989. }
  12990. string posTag = CurrentUser.UserPost.Post.Code;
  12991. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12992. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12993. writeGridDataTableJson(dStruct.TotalCount, dt);
  12994. }
  12995. public void saveSupplierProductTime()
  12996. {
  12997. string productId = GetPostString("productId");
  12998. if (string.IsNullOrEmpty(productId))
  12999. {
  13000. returnErrorMsg("缺少必要的参数");
  13001. return;
  13002. }
  13003. string productName = GetPostString("productName");
  13004. int supplierId = GetPostInt("supplierId");
  13005. if (supplierId == 0)
  13006. {
  13007. returnErrorMsg("缺少必要的参数");
  13008. return;
  13009. }
  13010. int quantity = GetPostInt("quantity");
  13011. int sendDay = GetPostInt("sendTime");
  13012. string supplierName = GetPostString("supplierName");
  13013. string craft = GetPostString("craft");
  13014. string deadLine = GetPostString("deadLine");
  13015. string dayDeadLine = GetPostString("dayDeadLine");
  13016. try
  13017. {
  13018. int eid = GetPostInt("eid");
  13019. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  13020. if (ceErpSupplierProductTime == null)
  13021. {
  13022. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  13023. }
  13024. ceErpSupplierProductTime.productId = productId;
  13025. ceErpSupplierProductTime.productName = productName;
  13026. ceErpSupplierProductTime.supplierId = supplierId;
  13027. ceErpSupplierProductTime.supplierName = supplierName;
  13028. ceErpSupplierProductTime.craft = craft;
  13029. ceErpSupplierProductTime.sendDay = sendDay;
  13030. ceErpSupplierProductTime.quantity = quantity;
  13031. if (!string.IsNullOrEmpty(deadLine))
  13032. {
  13033. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  13034. }
  13035. if (!string.IsNullOrEmpty(dayDeadLine))
  13036. {
  13037. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  13038. }
  13039. if (ceErpSupplierProductTime.ID == 0)
  13040. {
  13041. ceErpSupplierProductTime.Save();
  13042. }
  13043. else
  13044. {
  13045. ceErpSupplierProductTime.Update();
  13046. }
  13047. }
  13048. catch (Exception e)
  13049. {
  13050. }
  13051. returnSuccessMsg("保存成功");
  13052. return;
  13053. }
  13054. public void delSupplierProductTime()
  13055. {
  13056. int eid = GetPostInt("eid");
  13057. if (eid > 0)
  13058. {
  13059. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  13060. if (ceErpSupplierProductTime == null)
  13061. {
  13062. returnErrorMsg("查无数据");
  13063. return;
  13064. }
  13065. ceErpSupplierProductTime.Delete();
  13066. returnSuccessMsg("保存成功");
  13067. return;
  13068. }
  13069. returnErrorMsg("缺少必要的参数");
  13070. }
  13071. public void getExpressInfo()
  13072. {
  13073. string ctid = GetPostString("ctid");
  13074. if (!string.IsNullOrEmpty(ctid))
  13075. {
  13076. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13077. if (ceErpTradeCell != null)
  13078. {
  13079. string outSid = ceErpTradeCell.OutSid;
  13080. if (outSid.Length > 0)
  13081. {
  13082. string sql = string.Format("SELECT out_sid FROM [dbo].[CE_ErpExpressInfo] WHERE (out_sid in ({0}) or tid = '{1}') and ISNULL(DATALENGTH(postData), 0)>0;", "'" + outSid.Replace(",", "','") + "'", ceErpTradeCell.tid);
  13083. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13084. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  13085. return;
  13086. }
  13087. }
  13088. returnErrorMsg("查无记录");
  13089. return;
  13090. }
  13091. returnErrorMsg("缺少必要的参数");
  13092. }
  13093. public void getExpressPostData()
  13094. {
  13095. string express = GetPostString("express");
  13096. if (!string.IsNullOrEmpty(express))
  13097. {
  13098. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  13099. if (ceErpExpressInfo != null)
  13100. {
  13101. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  13102. return;
  13103. }
  13104. }
  13105. returnErrorMsg("缺少必要的参数");
  13106. }
  13107. public void checkSupplierOrder()
  13108. {
  13109. string ctids = GetPostString("ctids");
  13110. if (ctids != null)
  13111. {
  13112. List<string> list = new List<string>();
  13113. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  13114. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13115. for (int i = 0; i < dt.Rows.Count; i++)
  13116. {
  13117. DataRow row = dt.Rows[i];
  13118. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  13119. {
  13120. continue;
  13121. }
  13122. list.Add(row["seller_memo"].ToString());
  13123. }
  13124. if (list.Count > 0)
  13125. {
  13126. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", "'" + ctids.Replace(",", "','") + "'", (int)OrderState.下单完成, CurrentUser.UserID, "点击下载按钮"));
  13127. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  13128. return;
  13129. }
  13130. }
  13131. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  13132. return;
  13133. }
  13134. public void addPersonId()
  13135. {
  13136. string tid = GetPostString("tid");
  13137. string personId = GetPostString("personId");
  13138. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13139. if (ceErpTrade != null)
  13140. {
  13141. ceErpTrade.receiver_zip = personId;
  13142. ceErpTrade.Update();
  13143. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  13144. returnSuccessMsg("保存成功");
  13145. return;
  13146. }
  13147. returnErrorMsg("缺少必要的参数");
  13148. }
  13149. public void addDeliveryPaymant()
  13150. {
  13151. string tid = GetPostString("tid");
  13152. string paymant = GetPostString("paymant");
  13153. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13154. if (ceErpTrade != null)
  13155. {
  13156. if (!string.IsNullOrEmpty(paymant))
  13157. {
  13158. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  13159. }
  13160. ceErpTrade.Update();
  13161. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  13162. returnSuccessMsg("保存成功");
  13163. return;
  13164. }
  13165. returnErrorMsg("缺少必要的参数");
  13166. }
  13167. public void saveCellFile()
  13168. {
  13169. string tid = GetPostString("tid");
  13170. string ctid = GetPostString("ctid");
  13171. string urls = GetPostString("urls");
  13172. string type = GetPostString("type");
  13173. string del = GetPostString("del");
  13174. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13175. {
  13176. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13177. {
  13178. ctid = tid;
  13179. }
  13180. if ("1".Equals(del))
  13181. {
  13182. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  13183. }
  13184. string[] list = urls.Split(',');
  13185. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  13186. {
  13187. foreach (string item in list)
  13188. {
  13189. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  13190. ceErpTradeCellFile.Create();
  13191. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  13192. }
  13193. }
  13194. returnSuccessMsg("保存成功");
  13195. return;
  13196. }
  13197. returnErrorMsg("缺少必要的参数");
  13198. }
  13199. public void getCellFile()
  13200. {
  13201. string tid = GetPostString("tid");
  13202. string ctid = GetPostString("ctid");
  13203. string type = GetPostString("type");
  13204. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13205. {
  13206. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13207. {
  13208. ctid = tid;
  13209. }
  13210. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  13211. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13212. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  13213. return;
  13214. }
  13215. returnErrorMsg("缺少必要的参数");
  13216. }
  13217. public void delCellFile()
  13218. {
  13219. string id = GetPostString("id");
  13220. if (string.IsNullOrEmpty(id))
  13221. {
  13222. returnErrorMsg("缺少必要的参数");
  13223. return;
  13224. }
  13225. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  13226. CeErpTradeCellFile.delByID(id);
  13227. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  13228. returnSuccessMsg("保存成功");
  13229. }
  13230. public void getInvoiceOrder()
  13231. {
  13232. string tid = GetPostString("tid");
  13233. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13234. List<string> tids = new List<string>();
  13235. if (!string.IsNullOrEmpty(ceErpTrade.buyer_nick) && !string.IsNullOrEmpty(ceErpTrade.buyer_id))
  13236. {
  13237. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WHERE buyer_id = '{0}' AND seller_nick = '{1}' order by pay_time desc;", ceErpTrade.buyer_id, ceErpTrade.seller_nick);
  13238. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13239. foreach (DataRow dr in dt.Rows)
  13240. {
  13241. tids.Add("'" + dr["tid"].ToString() + "'");
  13242. }
  13243. }
  13244. else
  13245. {
  13246. tids.Add("'" + ceErpTrade.tid + "'");
  13247. }
  13248. DataTable cell_dt = new DataTable();
  13249. if (tids.Count > 0)
  13250. {
  13251. cell_dt = DbHelper.DbConn.ExecuteDataset(string.Format("SELECT * FROM [dbo].[CE_ErpTradeCell] WHERE tid in ({0});", string.Join(",", tids))).Tables[0];
  13252. }
  13253. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(cell_dt));
  13254. return;
  13255. }
  13256. public void getOrderLogInfo()
  13257. {
  13258. string ctid = GetPostString("ctid");
  13259. if (!string.IsNullOrEmpty(ctid))
  13260. {
  13261. StringBuilder sql = new StringBuilder();
  13262. sql.AppendFormat("select * from view_erptradelog where tid='{0}' order by id;", ctid);
  13263. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  13264. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(ds.Tables[0])) + "}");
  13265. return;
  13266. }
  13267. returnErrorMsg("缺少必要的参数");
  13268. }
  13269. public void setCellTeampId()
  13270. {
  13271. string ctid = GetPostString("ctid");
  13272. string tempId = GetPostString("tempId");
  13273. if (!string.IsNullOrEmpty(ctid))
  13274. {
  13275. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13276. if (ceErpTradeCellExtend == null)
  13277. {
  13278. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13279. ceErpTradeCellExtend.ctid = ctid;
  13280. }
  13281. ceErpTradeCellExtend.tempId = tempId;
  13282. if (ceErpTradeCellExtend.ID > 0)
  13283. {
  13284. ceErpTradeCellExtend.Update();
  13285. }
  13286. else
  13287. {
  13288. ceErpTradeCellExtend.Create();
  13289. }
  13290. designHelper.API_sendTempInfo(ctid, tempId);
  13291. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "修改模板id" + tempId, 6);
  13292. returnSuccessMsg("保存成功");
  13293. return;
  13294. }
  13295. returnErrorMsg("缺少必要的参数");
  13296. }
  13297. public void saveJointorder()
  13298. {
  13299. string ctid = GetPostString("ctid");
  13300. if (!string.IsNullOrEmpty(ctid))
  13301. {
  13302. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13303. if (ceErpTradeCellExtend == null)
  13304. {
  13305. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13306. ceErpTradeCellExtend.ctid = ctid;
  13307. }
  13308. if (ceErpTradeCellExtend.IsJoint == 1)
  13309. {
  13310. ceErpTradeCellExtend.IsJoint = 0;
  13311. }
  13312. else
  13313. {
  13314. ceErpTradeCellExtend.IsJoint = 1;
  13315. }
  13316. if (ceErpTradeCellExtend.ID > 0)
  13317. {
  13318. ceErpTradeCellExtend.Update();
  13319. }
  13320. else
  13321. {
  13322. ceErpTradeCellExtend.Create();
  13323. }
  13324. returnSuccessMsg("保存成功");
  13325. return;
  13326. }
  13327. returnErrorMsg("缺少必要的参数");
  13328. }
  13329. public void applyOrderBack()
  13330. {
  13331. string ctid = GetPostString("ctid");
  13332. string reason = GetPostString("reason");
  13333. if (!string.IsNullOrEmpty(ctid))
  13334. {
  13335. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13336. if (ceErpTradeCell == null)
  13337. {
  13338. returnErrorMsg("找不到订单");
  13339. return;
  13340. }
  13341. if (ceErpTradeCell.OrderState != 5 && ceErpTradeCell.OrderState != 6)
  13342. {
  13343. returnErrorMsg("待下单已下单才能申请");
  13344. return;
  13345. }
  13346. //下单后24小时后无法申请
  13347. if (ceErpTradeCell.OrderState == 6 && ceErpTradeCell.FinishPlaceTime != null)
  13348. {
  13349. DateTime now = DateTime.Now;
  13350. if (!string.IsNullOrEmpty(ceErpTradeCell.FinishPlaceTime.ToString()) && DateTime.Compare(DateTime.Parse(ceErpTradeCell.FinishPlaceTime.ToString()), now.AddHours(-24)) < 0)
  13351. {
  13352. returnErrorMsg("下单后24小时后无法申请");
  13353. return;
  13354. }
  13355. }
  13356. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}'", ceErpTradeCell.ctid);
  13357. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13358. if (dataTable != null && dataTable.Rows.Count > 0)
  13359. {
  13360. foreach (DataRow row in dataTable.Rows)
  13361. {
  13362. if (row["Con"].ToString().Contains("拒绝打回"))
  13363. {
  13364. returnErrorMsg("被拒绝过无法继续申请");
  13365. return;
  13366. }
  13367. }
  13368. }
  13369. ceErpTradeCell.IsReturn = 4;
  13370. ceErpTradeCell.Update();
  13371. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请打回:" + reason, ceErpTradeCell.OrderState);
  13372. returnSuccessMsg("保存成功");
  13373. return;
  13374. }
  13375. returnErrorMsg("缺少必要的参数");
  13376. }
  13377. public void cancelApplyOrderBack()
  13378. {
  13379. string ctid = GetPostString("ctid");
  13380. if (!string.IsNullOrEmpty(ctid))
  13381. {
  13382. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13383. if (ceErpTradeCell == null)
  13384. {
  13385. returnErrorMsg("找不到订单");
  13386. return;
  13387. }
  13388. if (ceErpTradeCell.IsReturn != 4)
  13389. {
  13390. returnErrorMsg("订单未在申请阶段");
  13391. return;
  13392. }
  13393. ceErpTradeCell.IsReturn = 0;
  13394. ceErpTradeCell.Update();
  13395. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "取消申请打回", ceErpTradeCell.OrderState);
  13396. returnSuccessMsg("保存成功");
  13397. return;
  13398. }
  13399. returnErrorMsg("缺少必要的参数");
  13400. }
  13401. public void get_erp_applybackorderlist()
  13402. {
  13403. DataStruct dStruct = GetPostStruct();
  13404. List<string> lw = new List<string>();
  13405. string tid = GetPostString("ctid");
  13406. if (tid.Length > 0)
  13407. {
  13408. string select_tid = getTidByCtid(tid);
  13409. lw.Add(string.Format("tid='{0}'", select_tid));
  13410. }
  13411. string shopname = GetPostString("shopname");
  13412. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  13413. string buyernick = GetPostString("buyer_nick");
  13414. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  13415. string customer = GetPostString("customer");
  13416. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  13417. string design = GetPostString("design");
  13418. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  13419. string orderState = GetPostString("orderState");
  13420. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  13421. string supplier = GetPostString("supplier");
  13422. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  13423. string sellermemo = GetPostString("seller_memo");
  13424. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  13425. string otherMemo = GetPostString("otherMemo");
  13426. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  13427. string address = GetPostString("address");
  13428. 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));
  13429. string date1 = GetPostString("date1");
  13430. string date2 = GetPostString("date2");
  13431. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  13432. if (dw.Length > 0) lw.Add(dw);
  13433. string price1 = GetPostString("price1");
  13434. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  13435. string price2 = GetPostString("price2");
  13436. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  13437. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13438. {
  13439. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13440. lw.Add(string.Format("OrderState = 6"));
  13441. }
  13442. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13443. {
  13444. lw.Add("OrderState in (5,6) ");
  13445. }
  13446. lw.Add(string.Format("IsReturn = 4"));
  13447. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  13448. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13449. string pagesize = GetPostString("pagesize");
  13450. if (pagesize != null)
  13451. {
  13452. dStruct.PageSize = 200;
  13453. }
  13454. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  13455. writeGridDataTableJson(dStruct.TotalCount, dt);
  13456. }
  13457. public void refuseBackOrder()
  13458. {
  13459. string ctid = GetPostString("ctid");
  13460. if (!string.IsNullOrEmpty(ctid))
  13461. {
  13462. string reason = GetPostString("returnreason");
  13463. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13464. if (ceErpTradeCell == null)
  13465. {
  13466. returnErrorMsg("找不到订单");
  13467. return;
  13468. }
  13469. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}' order by ID desc", ceErpTradeCell.ctid);
  13470. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13471. int userId = 0;
  13472. if (dataTable != null && dataTable.Rows.Count > 0)
  13473. {
  13474. foreach (DataRow row in dataTable.Rows)
  13475. {
  13476. if (row["Con"].ToString().Contains("申请打回:"))
  13477. {
  13478. userId = Convert.ToInt32(row["UserId"]);
  13479. }
  13480. }
  13481. }
  13482. if (userId > 0)
  13483. {
  13484. CeErpMessageTip ct = new CeErpMessageTip();
  13485. ct.tid = ceErpTradeCell.ctid;
  13486. ct.sectionId = 0;
  13487. ct.userId = userId;
  13488. ct.type = 4;
  13489. ct.isVisit = false;
  13490. ct.content = ceErpTradeCell.ctid + ",申请打回被拒绝:" + reason;
  13491. ct.Create();
  13492. }
  13493. ceErpTradeCell.IsReturn = 0;
  13494. ceErpTradeCell.Update();
  13495. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "拒绝打回:" + reason, ceErpTradeCell.OrderState);
  13496. returnSuccessMsg("保存成功");
  13497. return;
  13498. }
  13499. returnErrorMsg("缺少必要的参数");
  13500. }
  13501. public void passApplyBack()
  13502. {
  13503. if (UrlPostParmsCheck("ctid"))
  13504. {
  13505. string eid = GetPostString("ctid");
  13506. CeErpTradeCell entity = null;
  13507. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  13508. string userpost = CurrentUser.UserPost.Post.Code;
  13509. if (entity != null)
  13510. {
  13511. string message = "操作成功!";
  13512. string isDown = "";
  13513. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  13514. {
  13515. message = eid + "订单有被点击下载。请注意沟通是否已下载完!";
  13516. isDown = "被点击下载";
  13517. }
  13518. bool isPlace = false;
  13519. if (entity.OrderState > 6)
  13520. {
  13521. returnErrorMsg("已发货无法打回!");
  13522. return;
  13523. }
  13524. if (entity.OrderState == 6)
  13525. {
  13526. isPlace = true;
  13527. }
  13528. bool isNeedUpdateCell2 = false;
  13529. if (entity.OrderState >= 6)
  13530. {
  13531. isNeedUpdateCell2 = true;
  13532. }
  13533. int returnTag = 2;
  13534. if (userpost == "Supplier")
  13535. {
  13536. returnTag = 1;
  13537. }
  13538. int toType = GetPostInt("totype");
  13539. string fromType = "3";
  13540. if (entity.OrderState < 5)
  13541. {
  13542. fromType = "3";
  13543. }
  13544. else
  13545. {
  13546. fromType = "4";
  13547. }
  13548. if (entity.IsXianHuo == 0)
  13549. {
  13550. if (returnTag == 2)
  13551. {
  13552. if (toType == 1)
  13553. {
  13554. entity.OrderState = 0;
  13555. entity.ReturnUserType = 1;
  13556. string clearman = GetPostString("clearman");
  13557. if (!string.IsNullOrEmpty(clearman))
  13558. {
  13559. entity.DesignUserId = 0;
  13560. }
  13561. }
  13562. else
  13563. {
  13564. entity.OrderState = 3;
  13565. entity.ReturnUserType = 2;
  13566. }
  13567. entity.IsReadTag = 1;
  13568. }
  13569. else if (returnTag == 1)
  13570. {
  13571. entity.OrderState = 5;
  13572. }
  13573. entity.IsVerifyToSupplier = false;
  13574. }
  13575. if (entity.IsXianHuo == 1)
  13576. {
  13577. entity.OrderState = 5;
  13578. }
  13579. entity.IsVerifyToSupplier = false;
  13580. entity.IsHaveNewOrder = 0;
  13581. entity.UnusualTag = 0;
  13582. entity.UnusualTime = null;
  13583. entity.UnusualCon = "";
  13584. entity.IsReturn = returnTag;
  13585. entity.ReturnTime = DateTime.Now;
  13586. entity.UpdateTime = DateTime.Now;
  13587. entity.ReturnReason = GetPostString("returnreason");
  13588. entity.Update();
  13589. if (entity.OrderState == 3)
  13590. {
  13591. ApiVo apiVo = new ApiVo();
  13592. apiVo.orderNumber = entity.ctid;
  13593. apiVo.actionName = "rebutDesign";
  13594. apiVo.orderRemarks = entity.ReturnReason;
  13595. designHelper.API_WorkCore(apiVo);//rebutDesign
  13596. }
  13597. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason + isDown, entity.OrderState);
  13598. if (isPlace)
  13599. {
  13600. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  13601. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13602. if (dth != null && dth.Rows.Count > 0)
  13603. {
  13604. dataSendOrderBean dataSendOrderBean = null;
  13605. foreach (DataRow item in dth.Rows)
  13606. {
  13607. try
  13608. {
  13609. dataSendOrderBean = new dataSendOrderBean();
  13610. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  13611. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  13612. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  13613. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  13614. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  13615. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  13616. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  13617. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  13618. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  13619. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  13620. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  13621. dataSendOrderBean.Radio1723534706288 = "打回";
  13622. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  13623. if (result != null)
  13624. {
  13625. if ("0".Equals(result.errcode))
  13626. {
  13627. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  13628. }
  13629. else
  13630. {
  13631. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  13632. }
  13633. }
  13634. }
  13635. catch (Exception ex)
  13636. {
  13637. }
  13638. }
  13639. }
  13640. }
  13641. returnSuccessMsg(message);
  13642. return;
  13643. }
  13644. returnErrorMsg("找不到订单记录");
  13645. }
  13646. }
  13647. public void getApplyBackCount()
  13648. {
  13649. string sql = string.Format("SELECT top 1 ctid FROM [dbo].[CE_ErpTradeCell]");
  13650. List<string> lw = new List<string>();
  13651. lw.Add("IsReturn = 4");
  13652. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13653. {
  13654. lw.Add("OrderState = 6");
  13655. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13656. }
  13657. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13658. {
  13659. lw.Add("OrderState = 5");
  13660. }
  13661. else
  13662. {
  13663. ReturnSuccess("{" + string.Format("\"data\":{0}", "0") + "}");
  13664. return;
  13665. }
  13666. sql += " where " + string.Join(" and ", lw.ToArray());
  13667. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13668. List<string> list = new List<string>();
  13669. if (dataTable != null && dataTable.Rows.Count > 0)
  13670. {
  13671. foreach (DataRow row in dataTable.Rows)
  13672. {
  13673. list.Add(row["ctid"].ToString());
  13674. }
  13675. }
  13676. ReturnSuccess("{" + string.Format("\"data\":{0}", "\"" + string.Join(",", list) + "\"") + "}");
  13677. return;
  13678. }
  13679. public void getSysPrice()
  13680. {
  13681. string ctid = GetPostString("ctid");
  13682. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13683. if (ceErpTradeCell.ProductId == 0)
  13684. {
  13685. returnSuccessMsg("没有产品id");
  13686. }
  13687. dataHelper.get_sys_price(ceErpTradeCell);
  13688. returnSuccessMsg("保存成功");
  13689. }
  13690. public void saveAssignLog(string reason, CeErpTradeCell ce)
  13691. {
  13692. if (ce != null)
  13693. {
  13694. CeErpAssignLog ceErpAssignLog = new CeErpAssignLog();
  13695. ceErpAssignLog.ctid = ce.ctid;
  13696. ceErpAssignLog.userid = CurrentUser.UserID;
  13697. ceErpAssignLog.seller_memo = ce.seller_memo;
  13698. ceErpAssignLog.reason = reason;
  13699. ceErpAssignLog.Save();
  13700. }
  13701. }
  13702. public void get_erp_assignLog()
  13703. {
  13704. DataStruct dStruct = GetPostStruct();
  13705. List<string> lw = new List<string>();
  13706. string tid = GetPostString("ctid");
  13707. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  13708. string apdate2 = GetPostString("apdate2");
  13709. string apdate1 = GetPostString("apdate1");
  13710. string dwap = GetDateMinuteWhere("createtime", apdate1, apdate2);
  13711. if (dwap.Length > 0) lw.Add(dwap);
  13712. dStruct.Order = " createtime desc";
  13713. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13714. DataTable dt = WebCache.GetData("view_ErpAssignLog", dStruct);
  13715. writeGridDataTableJson(dStruct.TotalCount, dt);
  13716. }
  13717. public void change_upfile_status()
  13718. {
  13719. int id = GetPostInt("id");
  13720. CeErpUpFileSupplier ceErpUpFileSupplier = CeErpUpFileSupplier.Get(id);
  13721. if (ceErpUpFileSupplier != null)
  13722. {
  13723. ceErpUpFileSupplier.isOpen = !ceErpUpFileSupplier.isOpen;
  13724. ceErpUpFileSupplier.Update();
  13725. }
  13726. returnSuccessMsg("保存成功");
  13727. }
  13728. public void test_seller_memo_upfile()
  13729. {
  13730. string ctid = GetPostString("ctid");
  13731. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  13732. if (ce == null)
  13733. {
  13734. returnErrorMsg("查无订单");
  13735. return;
  13736. }
  13737. int supplierId = getsupplierId(ce);
  13738. if (supplierId > 0)
  13739. {
  13740. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(supplierId);
  13741. if (ceErpSupplier != null)
  13742. {
  13743. returnSuccessMsg(ceErpSupplier.ComName);
  13744. return;
  13745. }
  13746. }
  13747. returnErrorMsg("未匹配到车间");
  13748. return;
  13749. }
  13750. private int getsupplierId(CeErpTradeCell entity)
  13751. {
  13752. int supplierId = 0;
  13753. StringBuilder sql = new StringBuilder();
  13754. sql.AppendFormat("select * from CE_ErpUpFileSupplier where isOpen = 1");
  13755. DataTable cellEx = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13756. int num = getProductCount(entity.seller_memo);
  13757. foreach (DataRow row in cellEx.Rows)
  13758. {
  13759. bool isIn = true;
  13760. //判断材质工艺都要符合
  13761. if (!Convert.IsDBNull(row["seller_memo"]) && !string.IsNullOrEmpty(row["seller_memo"].ToString()))
  13762. {
  13763. string memo = row["seller_memo"].ToString();
  13764. string[] memolist = memo.Split('+');
  13765. for (int i = 0; i < memolist.Length; i++)
  13766. {
  13767. if (!Regex.IsMatch(entity.seller_memo, memolist[i].Replace("/", "|")))
  13768. {
  13769. isIn = false;
  13770. }
  13771. }
  13772. }
  13773. if (!isIn)
  13774. {
  13775. continue;
  13776. }
  13777. //判断金额符不符合
  13778. if (!Convert.IsDBNull(row["payment"]) && !string.IsNullOrEmpty(row["payment"].ToString()))
  13779. {
  13780. string payment = row["payment"].ToString();
  13781. string[] paymentList = payment.Split('-');
  13782. if (!string.IsNullOrEmpty(paymentList[0]))
  13783. {
  13784. if (entity.payment < Convert.ToDouble(paymentList[0]))
  13785. {
  13786. continue;
  13787. }
  13788. }
  13789. if (!string.IsNullOrEmpty(paymentList[1]))
  13790. {
  13791. if (entity.payment > Convert.ToDouble(paymentList[1]))
  13792. {
  13793. continue;
  13794. }
  13795. }
  13796. }
  13797. if (!Convert.IsDBNull(row["size"]) && !string.IsNullOrEmpty(row["size"].ToString()))
  13798. {
  13799. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  13800. string memo = entity.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
  13801. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  13802. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  13803. double width = 0;
  13804. double height = 0;
  13805. try
  13806. {
  13807. if (matches[0].Success)
  13808. {
  13809. string sizematches = matches[0].Groups[0].Value;
  13810. sizematches = sizematches.Replace("mm", "");
  13811. sizematches = sizematches.Replace("cm", "");
  13812. string[] size_list = sizematches.Split('x');
  13813. if (size_list.Length > 1)
  13814. {
  13815. width = Convert.ToDouble(size_list[0]);
  13816. height = Convert.ToDouble(size_list[1]);
  13817. }
  13818. }
  13819. }
  13820. catch (Exception ex)
  13821. {
  13822. }
  13823. string size = row["size"].ToString();
  13824. string[] sizeList = size.Split('-');
  13825. if (!string.IsNullOrEmpty(sizeList[0]))
  13826. {
  13827. string[] sizeItemList = sizeList[0].Split('x');
  13828. //第一个尺寸格式不正确
  13829. if (sizeItemList.Length < 2)
  13830. {
  13831. continue;
  13832. }
  13833. double sizeWidth = Convert.ToDouble(sizeItemList[0]);
  13834. double sizeheight = Convert.ToDouble(sizeItemList[1]);
  13835. //备注尺寸要大于第一个尺寸
  13836. if (!((width > sizeWidth && height > sizeheight) || (width > sizeheight && height > sizeWidth)))
  13837. {
  13838. continue;
  13839. }
  13840. }
  13841. if (!string.IsNullOrEmpty(sizeList[1]))
  13842. {
  13843. string[] sizeItemList = sizeList[1].Split('x');
  13844. //第二个尺寸格式不正确
  13845. if (sizeItemList.Length < 2)
  13846. {
  13847. continue;
  13848. }
  13849. double sizeWidth = Convert.ToDouble(sizeItemList[0]);
  13850. double sizeheight = Convert.ToDouble(sizeItemList[1]);
  13851. //备注尺寸要大于第二个尺寸
  13852. if (!((width < sizeWidth && height < sizeheight) || (width < sizeheight && height < sizeWidth)))
  13853. {
  13854. continue;
  13855. }
  13856. }
  13857. }
  13858. //判断数量是否符合
  13859. if (!Convert.IsDBNull(row["number"]) && !string.IsNullOrEmpty(row["number"].ToString()))
  13860. {
  13861. string numberText = row["number"].ToString();
  13862. string[] numberTextList = numberText.Split('-');
  13863. int number = 0;
  13864. if (!string.IsNullOrEmpty(numberTextList[0]))
  13865. {
  13866. number = Convert.ToInt32(numberTextList[0]);
  13867. if (number > num)
  13868. {
  13869. continue;
  13870. }
  13871. }
  13872. if (!string.IsNullOrEmpty(numberTextList[1]))
  13873. {
  13874. number = Convert.ToInt32(numberTextList[1]);
  13875. if (number < num)
  13876. {
  13877. continue;
  13878. }
  13879. }
  13880. }
  13881. //判断店铺符不符合
  13882. if (!Convert.IsDBNull(row["shopIds"]) && !string.IsNullOrEmpty(row["shopIds"].ToString()))
  13883. {
  13884. List<string> shopids = row["shopIds"].ToString().Split(',').ToList();
  13885. if (!shopids.Contains(entity.ShopId.ToString()))
  13886. {
  13887. continue;
  13888. }
  13889. }
  13890. //地区不符合
  13891. if (!Convert.IsDBNull(row["address"]) && !string.IsNullOrEmpty(row["address"].ToString()))
  13892. {
  13893. if (!Regex.IsMatch(entity.seller_memo, row["address"].ToString().Replace("、", "|")))
  13894. {
  13895. continue;
  13896. }
  13897. }
  13898. //限制条件
  13899. if (!Convert.IsDBNull(row["filterText"]) && !string.IsNullOrEmpty(row["filterText"].ToString()))
  13900. {
  13901. if (Regex.IsMatch(entity.seller_memo, row["filterText"].ToString().Replace("/", "|")))
  13902. {
  13903. continue;
  13904. }
  13905. }
  13906. supplierId = Convert.ToInt32(row["supplierId"]);
  13907. break;
  13908. }
  13909. return supplierId;
  13910. }
  13911. public static int getProductCount(string txt)
  13912. {
  13913. // 提取"个"或"张"前面的数字
  13914. int unit = 0;
  13915. try
  13916. {
  13917. string unitPattern = @"(\d+)(?=个|张|本|套|件|卷|劵|条|箱 )";
  13918. System.Text.RegularExpressions.Match unitMatch = Regex.Match(txt, unitPattern);
  13919. string unitNum = unitMatch.Success ? unitMatch.Groups[1].Value : "1";
  13920. if (!int.TryParse(unitNum, out unit))
  13921. {
  13922. return 0;
  13923. }
  13924. }
  13925. catch (Exception ex)
  13926. {
  13927. }
  13928. return unit;
  13929. }
  13930. public void setNegotiateInfo()
  13931. {
  13932. string ctid = GetPostString("ctid");
  13933. string negotiate = GetPostString("negotiate");
  13934. if (!string.IsNullOrEmpty(ctid))
  13935. {
  13936. CeErpTradeCellExtend ce = CeErpTradeCellExtend.getByTid(ctid);
  13937. if (ce == null)
  13938. {
  13939. ce = new CeErpTradeCellExtend();
  13940. ce.ctid = ctid;
  13941. }
  13942. ce.negotiate = negotiate + "-" + CurrentUser.UserName;
  13943. if (ce.ID > 0)
  13944. {
  13945. ce.Update();
  13946. }
  13947. else
  13948. {
  13949. ce.Create();
  13950. }
  13951. LogHelper.addLog(ce.ctid, CurrentUser.UserID, "协商内容:" + negotiate, 0, 1);
  13952. returnSuccessMsg("保存成功");
  13953. }
  13954. }
  13955. }
  13956. }