sync.order.cs 615 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. namespace SiteCore.Handler
  48. {
  49. public partial class sync
  50. {
  51. public void get_erp_orderlist()
  52. {
  53. string poscode = CurrentUser.UserPost.Post.Code;
  54. DataStruct dStruct = GetPostStruct();
  55. //apiHelper.Api_SyncOrderByTime("598825");
  56. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  57. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  58. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  59. //banniuApiHelper.sendLogisticsInfo(null);
  60. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  61. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  62. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  63. //int sid = commonHelper.autoDistributeToSupplier(entity);
  64. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  65. //tmcHelper.Api_TmcTradeMsg("{\r\n \"content\": {\r\n \"businessType\": \"GUARANTEE\",\r\n \"buyerMemo\": \"\",\r\n \"consolidateType\": \"\",\r\n \"createTime\": 1744882656361,\r\n \"deliveryType\": \"OFFLINE\",\r\n \"discountFee\": 0.0,\r\n \"flag\": \"NONE\",\r\n \"latestDeliveryTime\": 1744882656361,\r\n \"lines\": [\r\n {\r\n \"mark2\": [],\r\n \"num\": 4,\r\n \"outerId\": \"\",\r\n \"payment\": 60.0,\r\n \"picUrl\": \"https://img.alicdn.com/bao/uploaded/i4/2209226402185/O1CN011Zh53V1S0mQKgHJyF_!!4611686018427382153-0-item_pic.jpg\",\r\n \"platServiceFee\": 0.0,\r\n \"price\": 10.0,\r\n \"refOlId\": \"1111122222333338942\",\r\n \"refSkuId\": \"0\",\r\n \"refSpuId\": \"908453435193\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellPrice\": 10.0,\r\n \"singleFee\": 10.0,\r\n \"standards\": \"测试内部\",\r\n \"status\": \"NOT_SHIPPED\",\r\n \"title\": \"【老客户订单2】测试老客户订单内部\",\r\n \"totalFee\": 60.0,\r\n \"totalPrice\": 60.0,\r\n \"totalSellPrice\": 60.0\r\n }\r\n ],\r\n \"logisticsOrderNo\": \"\",\r\n \"mark2\": [],\r\n \"modifyTime\": 1744882656361,\r\n \"openBuyerId\": \"AAG1RHraABkUZRPgSx3g7Eam\",\r\n \"openBuyerNick\": \"0**\",\r\n \"openSellerNick\": \"海角七旗舰店\",\r\n \"orderSource\": \"SYNC\",\r\n \"orderTime\": 1744882656361,\r\n \"payTime\": 1744882656361,\r\n \"payment\": 100.0,\r\n \"platServiceFee\": 0.0,\r\n \"posCode\": \"HJQ\",\r\n \"posId\": 663281,\r\n \"postFee\": 0.0,\r\n \"props\": {\r\n \"payType\": \"ALI_PAY\",\r\n \"govSubsidyAmount\": 0\r\n },\r\n \"receivedPayment\": 0.0,\r\n \"receiverCity\": \"龙岩市\",\r\n \"receiverCountry\": \"中国\",\r\n \"receiverDistrict\": \"新罗区\",\r\n \"receiverId\": \"d1b65912ef886228ac4ada4b65055e52$\",\r\n \"receiverState\": \"福建省\",\r\n \"receiverTown\": \"西陂街道\",\r\n \"refOid\": \"1111122222333338942\",\r\n \"refType\": \"TB\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellerMemo\": \"\",\r\n \"serviceFee\": 0.0,\r\n \"status\": \"NOT_SHIPPED\",\r\n \"totalFee\": 100.0,\r\n \"totalPrice\": 100.0,\r\n \"totalSellPrice\": 100.0,\r\n \"type\": \"SALE\"\r\n }\r\n}");
  66. //refundTmcHelper.Api_TmcRefundMsg("{\"content\":{\"afterStatus\":\"SUCCESS\",\"createTime\":1735287446000,\"desc\":\"\",\"interceptInvestor\":\"NONE\",\"interceptStatus\":\"NONE\",\"interceptType\":\"NONE\",\"lines\":[{\"num\":2,\"outerId\":\"\",\"price\":50.0,\"refAid\":\"313001208133750610\",\"refAlId\":\"313001208133750610\",\"refBoughtSkuId\":\"\",\"refOid\":\"4181722704291751006\",\"refOlId\":\"4181722704291751006\",\"refSkuId\":\"0\",\"refSpuId\":\"865893808768\",\"refundFee\":98.86,\"refundStatus\":\"SUCCESS\",\"title\":\"新年会抽奖券定制2025蛇年公司活动正副可撕代金券打印纪念票根奖品兑换尾牙晚宴邀请卡号码牌创意入场券设计\",\"totalFee\":98.86,\"type\":1}],\"logisticsCompany\":\"\",\"logisticsOrderNo\":\"\",\"mark2\":[],\"openBuyerNick\":\"0**\",\"openSellerNick\":\"万慕办公旗舰店\",\"posCode\":\"wanmu\",\"posId\":598798,\"reason\":\"订单信息拍错(规格/尺码/颜色等)\",\"receiverCity\":\"\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"\",\"receiverId\":\"\",\"receiverState\":\"\",\"receiverTown\":\"\",\"receiverZip\":\"\",\"refAid\":\"313001208133750610\",\"refOid\":\"4181722704291751006\",\"refPlatform\":\"TB\",\"refType\":\"TMALL\",\"refundCreateTime\":1735287358000,\"refundFee\":\"98.86\",\"refundPhase\":\"ON_SALE\",\"refundTime\":1735289443000,\"refundUpdateTime\":1735289443000,\"refundVersion\":1735287358100,\"senderAddress\":\"\",\"senderCity\":\"\",\"senderCountry\":\"中国\",\"senderDistrict\":\"\",\"senderMobile\":\"\",\"senderName\":\"\",\"senderPhone\":\"\",\"senderState\":\"\",\"senderTown\":\"\",\"senderZip\":\"\",\"status\":\"SUCCESS\",\"statusCode\":\"SUCCESS\",\"statusName\":\"退款成功\",\"totalFee\":\"98.86\",\"type\":\"REFUND\",\"updateTime\":1735289479000}}");
  67. /*string sql = "SELECT spuId,tid FROM [dbo].[CE_ErpTradeSpu] where isSync is null ";
  68. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  69. DataTable dataTable = dataSet == null ? new DataTable() : dataSet.Tables[0];
  70. foreach (DataRow dr in dataTable.Rows)
  71. {
  72. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByTid(dr["tid"].ToString());
  73. CeErpTradeOrder ceErpTradeOrder = CeErpTradeOrder.GetBySpuId(dr["spuId"].ToString());
  74. CeErpTradeSpu ceErpTradeSpu = CeErpTradeSpu.GetBySpuId(dr["spuId"].ToString());
  75. dataSendSpuBean bean = new dataSendSpuBean();
  76. bean.ShortText1728890680485 = ceErpTradeOrder.title;
  77. bean.ShortText1728890649488 = dr["spuId"].ToString();
  78. bean.shopId = ceErpTradeCell.ShopId.ToString();
  79. ceErpTradeSpu.shopId = ceErpTradeCell.ShopId;
  80. ceErpTradeSpu.isSync = false;
  81. bean.Date1728891156995 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  82. dataResponseVo response = dataHelper.sendSpuInfo(bean);
  83. if (response != null)
  84. {
  85. if ("0".Equals(response.errcode))
  86. {
  87. ceErpTradeSpu.isSync = true;
  88. }
  89. else
  90. {
  91. ceErpTradeSpu.message = response.errmsg;
  92. }
  93. }
  94. ceErpTradeSpu.Update();
  95. }*/
  96. List<string> lw = new List<string>();
  97. string tid = GetPostString("ctid");
  98. string date1 = GetPostString("date1");
  99. //12-1 修改
  100. string urgent = GetPostString("urgent");
  101. string back = GetPostString("back");
  102. string offlineSearch = GetPostString("offlineSearch");
  103. int paramsCount = 0;
  104. if (!string.IsNullOrWhiteSpace(urgent))
  105. {
  106. if (urgent.Equals("true"))
  107. {
  108. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  109. }
  110. }
  111. if (!string.IsNullOrWhiteSpace(back))
  112. {
  113. if (back.Equals("true"))
  114. {
  115. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  116. }
  117. }
  118. if (!string.IsNullOrWhiteSpace(offlineSearch))
  119. {
  120. if (offlineSearch.Equals("true"))
  121. {
  122. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  123. }
  124. }
  125. //end
  126. string date2 = GetPostString("date2");
  127. string buyernick = GetPostString("buyer_nick");
  128. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  129. {
  130. if (tid.Length <= 0 && buyernick.Length <= 0)
  131. {
  132. return;
  133. }
  134. }
  135. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  136. {
  137. if (tid.Length > 0)
  138. {
  139. string select_tid = getTidByCtid(tid);
  140. lw.Add(string.Format("tid='{0}'", select_tid));
  141. }
  142. if (buyernick.Length > 0)
  143. {
  144. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  145. }
  146. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  147. if (dw.Length > 0)
  148. {
  149. lw.Add(dw);
  150. }
  151. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  152. {
  153. string usershop = CurrentUser.User.pemShop;
  154. lw.Add(string.Format("ShopId in ({0})", usershop));
  155. }
  156. }
  157. else
  158. {
  159. if (ex_psize == 0)
  160. {
  161. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  162. }
  163. if (PKey != "admin")
  164. {
  165. string usershop = CurrentUser.User.pemShop;
  166. lw.Add(string.Format("ShopId in ({0})", usershop));
  167. paramsCount++;
  168. }
  169. }
  170. string uploaddate1 = GetPostString("uploaddate1");
  171. string uploaddate2 = GetPostString("uploaddate2");
  172. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  173. if (update.Length > 0) lw.Add(update);
  174. string deliverydate1 = GetPostString("deliverydate1");
  175. string deliverydate2 = GetPostString("deliverydate2");
  176. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  177. if (deliverydate.Length > 0)
  178. {
  179. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  180. };
  181. string shopname = GetPostString("shopname");
  182. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  183. string addwechat = GetPostString("addwechat");
  184. if (addwechat.Length > 0)
  185. {
  186. int addWt = Convert.ToInt32(addwechat);
  187. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  188. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  189. }
  190. string customer = GetPostString("customer");
  191. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  192. string design = GetPostString("design");
  193. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  194. string orderState = GetPostString("orderState");
  195. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  196. string address = GetPostString("address");
  197. 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));
  198. string sellermemo = GetPostString("seller_memo");
  199. if (sellermemo.Length > 0)
  200. {
  201. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  202. }
  203. string backReason = GetPostString("backReason");
  204. if (backReason.Length > 0)
  205. {
  206. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  207. }
  208. string apdate1 = GetPostString("apdate1");
  209. string apdate2 = GetPostString("apdate2");
  210. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  211. if (dwap.Length > 0) lw.Add(dwap);
  212. string price1 = GetPostString("price1");
  213. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  214. string price2 = GetPostString("price2");
  215. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  216. string isoldcustomer = GetPostString("isoldcus");
  217. string spudata = GetPostString("spudata");
  218. if ("0".Equals(spudata))
  219. {
  220. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  221. }
  222. if ("1".Equals(spudata))
  223. {
  224. lw.Add(string.Format("spu_id <> ''"));
  225. }
  226. string finishdate1 = GetPostString("finishdate1");
  227. string finishdate2 = GetPostString("finishdate2");
  228. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  229. bool isFinish = false;
  230. if (finishdate.Length > 0)
  231. {
  232. lw.Add(finishdate);
  233. isFinish = true;
  234. paramsCount++;
  235. }
  236. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  237. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  238. if (ex_psize > 0)
  239. {
  240. int UserID = CurrentUser.UserID;
  241. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  242. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  243. {
  244. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  245. }
  246. dStruct.Order = "pay_time desc";
  247. }
  248. string isNew = GetPostString("isNew");
  249. if (isNew == "true")
  250. {
  251. lw.Add(string.Format("IsNew = {0}", 1));
  252. }
  253. string overtime = GetPostString("overtime");
  254. if (overtime == "1")
  255. {
  256. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  257. }
  258. String usePost = CurrentUser.UserPost.Post.Code;
  259. if (usePost.Equals("Operation") == true)
  260. {
  261. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  262. }
  263. else
  264. {
  265. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  266. }
  267. //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";
  268. if (dStruct.PageSize == 100000)
  269. {
  270. dStruct.Order = "";
  271. }
  272. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  273. DataTable dt = null;
  274. string tablename = "view_orderlist";
  275. if (isFinish)
  276. {
  277. tablename = "view_orderlist_end";
  278. }
  279. dt = WebCache.GetData(tablename, dStruct);
  280. if (dt != null && dt.Rows.Count > 0)
  281. {
  282. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  283. foreach (DataRow dr in dt.Rows)
  284. {
  285. try
  286. {
  287. if (dr["refund_fees"] != null)
  288. {
  289. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  290. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  291. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  292. if (payment == refund_fees)
  293. {
  294. dr["refund_fees"] = Math.Round(refund_fees, 2);
  295. }
  296. else if (refund_fees == total_fee)
  297. {
  298. dr["refund_fees"] = payment;
  299. }
  300. else
  301. {
  302. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  303. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  304. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  305. }
  306. }
  307. // 对象操作
  308. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  309. ceErpTradeCell.ctid = dr["ctid"].ToString();
  310. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  311. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  312. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  313. if (dStruct.PageSize != 100000)
  314. {
  315. if (dr["DispatchSort"].ToString() == "2")
  316. {
  317. dr["gongchuang"] = 200;
  318. }
  319. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  320. {
  321. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  322. dr["gongchuang"] = response.code;
  323. }
  324. }
  325. }
  326. catch (NullReferenceException ex)
  327. {
  328. // 处理空引用异常
  329. dr["refund_fees"] = "0.00";
  330. }
  331. }
  332. }
  333. writeGridDataTableJson(dStruct.TotalCount, dt);
  334. }
  335. public void get_erp_orderlist_sumprice()
  336. {
  337. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  338. return;
  339. List<string> lw = new List<string>();
  340. string tid = GetPostString("ctid");
  341. string date1 = GetPostString("date1");
  342. string date2 = GetPostString("date2");
  343. if (tid.Length > 0 || date1.Length > 0)
  344. {
  345. lw.Add(string.Format("ctid like '%{0}%'", tid));
  346. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  347. if (dw.Length > 0) lw.Add(dw);
  348. }
  349. else
  350. {
  351. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  352. }
  353. string shopname = GetPostString("shopname");
  354. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  355. string buyernick = GetPostString("buyer_nick");
  356. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  357. string customer = GetPostString("customer");
  358. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  359. string design = GetPostString("design");
  360. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  361. string orderState = GetPostString("orderState");
  362. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  363. string address = GetPostString("address");
  364. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  365. string sellermemo = GetPostString("seller_memo");
  366. if (sellermemo.Length > 0)
  367. {
  368. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  369. }
  370. string apdate1 = GetPostString("apdate1");
  371. string apdate2 = GetPostString("apdate2");
  372. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  373. if (dwap.Length > 0) lw.Add(dwap);
  374. string price1 = GetPostString("price1");
  375. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  376. string price2 = GetPostString("price2");
  377. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  378. string isoldcustomer = GetPostString("isoldcus");
  379. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  380. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  381. if (PKey != "admin")
  382. {
  383. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  384. lw.Add(string.Format("shopId in ({0})", usershop));
  385. }
  386. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  387. string mainWhere = string.Join(" and ", lw.ToArray());
  388. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  389. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  390. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  391. decimal total = 0;
  392. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  393. {
  394. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  395. }
  396. var res = new
  397. {
  398. data = total
  399. };
  400. string ro_jsond = JsonConvert.SerializeObject(res);
  401. returnSuccess(ro_jsond);
  402. return;
  403. }
  404. public void get_erp_CustomerServiceGather()
  405. {
  406. string userWhere = "", orderWhere = "";
  407. List<string> lw = new List<string>();
  408. string customer = GetPostString("customer");
  409. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  410. string shopname = GetPostString("shopname");
  411. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  412. string date1 = GetPostString("date1");
  413. string date2 = GetPostString("date2");
  414. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  415. if (dw.Length > 0) lw.Add(dw);
  416. orderWhere = string.Join(" and ", lw.ToArray());
  417. string sql = string.Format("select a.Name CusName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitRelease,0) WaitRelease, isnull(e.WaitRob,0) WaitRob, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  418. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  419. "left join " +
  420. "( " +
  421. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  422. ") as b on a.ID = b.CustomerUserId " +
  423. "left join " +
  424. "( " +
  425. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  426. ") as d on a.ID = d.CustomerUserId " +
  427. "left join " +
  428. "( " +
  429. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  430. ") as e on a.ID = e.CustomerUserId " +
  431. "left join " +
  432. "( " +
  433. " select CustomerUserId, RefundCount, RefundSum from " +
  434. " ( " +
  435. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  436. " from CE_ErpTradeRefund a " +
  437. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  438. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  439. " group by CustomerUserId " +
  440. " ) as a " +
  441. ") as f on a.ID = f.CustomerUserId " +
  442. "where a.PostCode = 'CustomerService'",
  443. userWhere, orderWhere);
  444. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  445. writeGridDataTableJson(dt.Rows.Count, dt);
  446. //writeGridDataTableJson(dt.Rows.Count, dt);
  447. }
  448. //设计汇总
  449. public void get_erp_DesignerGather()
  450. {
  451. string userWhere = "", orderWhere = "";
  452. List<string> lw = new List<string>();
  453. string Designer = GetPostString("designer");
  454. int org = GetPostInt("org");
  455. if (Designer.Length > 0)
  456. {
  457. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  458. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  459. }
  460. else if (org > 0)
  461. {
  462. userWhere = string.Format(" where OrgID ={0}", org);
  463. }
  464. string shopname = GetPostString("shopname");
  465. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  466. string state = GetPostString("state");
  467. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  468. string OrderArea = GetPostString("order_area");
  469. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  470. string date1 = GetPostString("date1");
  471. string date2 = GetPostString("date2");
  472. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  473. if (dw.Length > 0) lw.Add(dw);
  474. string UpDate1 = GetPostString("UpDate1");
  475. string UpDate2 = GetPostString("UpDate2");
  476. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  477. if (dw.Length > 0) lw.Add(dw);
  478. orderWhere = string.Join(" and ", lw.ToArray());
  479. string sql = string.Format("select *,cast(cast(z.DesignFinish as float) / (case z.AllOrder when 0 then 1 else z.AllOrder end) * 100 as numeric(18,2)) as FinalizationRate from (" +
  480. "select a.Name DesignerName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitDesign,0) WaitDesign, isnull(e.Designing,0) Designing, isnull(g.DesignFinish,0) DesignFinish, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  481. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  482. "left join " +
  483. "( " +
  484. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  485. ") as b on a.ID = b.DesignUserId " +
  486. "left join " +
  487. "( " +
  488. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  489. ") as d on a.ID = d.DesignUserId " +
  490. "left join " +
  491. "( " +
  492. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  493. ") as e on a.ID = e.DesignUserId " +
  494. "left join " +
  495. "( " +
  496. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  497. ") as g on a.ID = g.DesignUserId " +
  498. "left join " +
  499. "( " +
  500. " select CustomerUserId, RefundCount, RefundSum from " +
  501. " ( " +
  502. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  503. " from CE_ErpTradeRefund a " +
  504. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  505. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  506. " group by CustomerUserId " +
  507. " ) as a " +
  508. ") as f on a.ID = f.CustomerUserId " +
  509. "where a.PostCode = 'Designer') as z",
  510. userWhere, orderWhere);
  511. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  512. writeGridDataTableJson(dt.Rows.Count, dt);
  513. }
  514. //删除tradecell的订单
  515. public void del_erp_cellorder()
  516. {
  517. if (UrlPostParmsCheck("ctid"))
  518. {
  519. string eid = GetPostString("ctid");
  520. CeErpTradeCell.DelByCtid(eid);
  521. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  522. returnSuccessMsg("删除成功");
  523. }
  524. }
  525. public void clear_erp_refundstate()
  526. {
  527. if (UrlPostParmsCheck("ids"))
  528. {
  529. string eids = GetPostString("ids");
  530. string[] ctidList = eids.Split(',');
  531. foreach (string ctid in ctidList)
  532. {
  533. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  534. if (entity != null)
  535. {
  536. entity.IsRefund = 0;
  537. entity.Update();
  538. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  539. }
  540. else
  541. continue;
  542. }
  543. returnSuccessMsg("操作成功");
  544. return;
  545. }
  546. returnErrorMsg("缺少必要参数");
  547. }
  548. public void set_erp_urgency()
  549. {
  550. if (UrlPostParmsCheck("ctid"))
  551. {
  552. string eid = GetPostString("ctid");
  553. CeErpTradeCell entity = null;
  554. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  555. if (entity != null)
  556. {
  557. string utime = GetPostString("urgencytime");
  558. if (utime.Length > 0)
  559. {
  560. entity.UrgencyTime = Convert.ToDateTime(utime);
  561. }
  562. else
  563. {
  564. returnErrorMsg("请选择加急时间");
  565. return;
  566. }
  567. if (entity.OrderState <= 4)
  568. {
  569. //entity.seller_memo = entity.seller_memo + "-加急";
  570. string smemo = entity.seller_memo;
  571. int kindex = smemo.IndexOf(")");
  572. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  573. if (lastoneStr != "-")
  574. {
  575. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  576. }
  577. string prememo = smemo.Substring(0, kindex + 2);
  578. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  579. int lastkindex = lastmemo.IndexOf("(");
  580. DateTime urgtime = Convert.ToDateTime(utime);
  581. string newlastmemo = "";
  582. if (lastkindex == 0)
  583. {
  584. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  585. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  586. }
  587. else
  588. {
  589. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  590. }
  591. entity.seller_memo = prememo + newlastmemo;
  592. }
  593. entity.IsUrgency = true;
  594. entity.UpdateTime = DateTime.Now;
  595. entity.Update();
  596. ApiVo apiVo = new ApiVo();
  597. apiVo.orderNumber = entity.ctid;
  598. apiVo.actionName = "changeDesign";
  599. apiVo.orderRemarks = entity.seller_memo;
  600. apiVo.remarkSign = 3;
  601. designHelper.API_WorkCore(apiVo); //changeDesign
  602. CeErpSukuraData.createInfo(entity.ctid, 7);
  603. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  604. returnSuccessMsg("设置成功!");
  605. return;
  606. }
  607. returnErrorMsg("找不到记录");
  608. }
  609. }
  610. public void set_erp_reset()
  611. {
  612. if (UrlPostParmsCheck("ctid"))
  613. {
  614. string eid = GetPostString("ctid");
  615. CeErpTradeCell entity = null;
  616. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  617. if (entity != null)
  618. {
  619. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  620. {
  621. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  622. {
  623. returnErrorMsg("财务要求已下单已发货无法重置");
  624. return;
  625. }
  626. }
  627. entity.IsUrgency = false;
  628. entity.seller_memo = "";
  629. entity.OtherMemo = "";
  630. entity.OrderState = 0;
  631. entity.IsReturn = 0;
  632. //entity.IsRefund = 0;
  633. entity.MemoOpt = 0;
  634. entity.AfterSaleState = 0;
  635. entity.AfterSaleResponsible = "";
  636. entity.AfterSaleUserId = 0;
  637. entity.IsNeedBill = 0;
  638. entity.CustomerUserId = 0;
  639. entity.DesignUserId = 0;
  640. entity.SupplierId = 0;
  641. entity.PlaceUserId = 0;
  642. entity.ptid = "";
  643. entity.IsSample = 0;
  644. entity.IsXianHuo = 0;
  645. entity.isDianziOrder = 0;
  646. entity.DispatchSort = 0;
  647. entity.FinishPlaceTime = null;
  648. entity.Update();
  649. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  650. if (trade != null)
  651. {
  652. trade.seller_memo = "";
  653. trade.Update();
  654. }
  655. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  656. returnSuccessMsg("重置成功!");
  657. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  658. if (desginBill != null)
  659. {
  660. desginBill.isDel = 1;
  661. desginBill.Update();
  662. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  663. }
  664. ApiVo apiVo = new ApiVo();
  665. apiVo.orderNumber = entity.ctid;
  666. apiVo.actionName = "resetDesign";
  667. designHelper.API_WorkCore(apiVo);//resetDesign
  668. return;
  669. }
  670. returnErrorMsg("找不到记录");
  671. }
  672. }
  673. public void save_erp_sellermemo()
  674. {
  675. if (UrlPostParmsCheck("ctid"))
  676. {
  677. string ctid = GetPostString("ctid");
  678. CeErpTradeCell entity = null;
  679. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  680. if (entity != null)
  681. {
  682. string memo = GetPostString("seller_memo");
  683. memo = memo.Replace(" ", "");
  684. if (memo.Contains("补差"))
  685. {
  686. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  687. return;
  688. }
  689. if (entity.seller_memo != memo)
  690. {
  691. if (entity.IsSample == 2)
  692. {
  693. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  694. return;
  695. }
  696. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  697. {
  698. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  699. {
  700. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  701. return;
  702. }
  703. }
  704. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  705. }
  706. commonHelper.getCytPrice(entity);
  707. int memoopt = GetPostInt("MemoOpt");
  708. Boolean ismemoopt = false;
  709. if (memoopt > 0)
  710. {
  711. string stropt = "";
  712. if (memoopt == 1)
  713. {
  714. stropt = "“改稿”";
  715. ismemoopt = true;
  716. }
  717. else if (memoopt == 2)
  718. {
  719. stropt = "“定稿”";
  720. }
  721. else if (memoopt == 3)
  722. {
  723. stropt = "“查货”";
  724. CeErpSukuraData.createInfo(entity.ctid, 6);
  725. }
  726. entity.MemoOpt = Convert.ToInt32(memoopt);
  727. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  728. }
  729. if (entity.OrderState < 5)
  730. {
  731. memo = memo.Replace("(", "(");
  732. memo = memo.Replace(")", ")");
  733. }
  734. entity.DispatchSort = 0;
  735. entity.seller_memo = memo;
  736. entity.UpdateTime = DateTime.Now;
  737. entity.Update();
  738. ApiVo apiVo = new ApiVo();
  739. apiVo.orderNumber = entity.ctid;
  740. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  741. apiVo.orderRemarks = memo;
  742. apiVo.remarkSign = memoopt;
  743. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  744. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  745. returnSuccessMsg("保存成功!");
  746. return;
  747. }
  748. returnErrorMsg("找不到记录");
  749. }
  750. }
  751. public void ins_erp_checkorder()
  752. {
  753. if (UrlPostParmsCheck("ctid"))
  754. {
  755. string ctid = GetPostString("ctid");
  756. CeErpTradeCell entity = null;
  757. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  758. if (entity != null)
  759. {
  760. if (entity.OrderState < 6)
  761. {
  762. returnErrorMsg("下单完成后才可查货");
  763. return;
  764. }
  765. /*if (entity.OrderState > 6)
  766. {
  767. returnErrorMsg("订单已发货");
  768. return;
  769. }*/
  770. if (entity.FinishPlaceTime != null)
  771. {
  772. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  773. {
  774. returnErrorMsg("下单时间不足,无法查货");
  775. return;
  776. }
  777. }
  778. entity.MemoOpt = 3;
  779. entity.CheckOrderTime = DateTime.Now;
  780. entity.UpdateTime = DateTime.Now;
  781. entity.Update();
  782. CeErpSukuraData.createInfo(entity.ctid, 6);
  783. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  784. returnSuccessMsg("操作成功!");
  785. return;
  786. }
  787. returnErrorMsg("找不到记录");
  788. }
  789. }
  790. public void save_erp_othermemo()
  791. {
  792. if (UrlPostParmsCheck("ctid"))
  793. {
  794. string ctid = GetPostString("ctid");
  795. CeErpTradeCell entity = null;
  796. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  797. if (entity != null)
  798. {
  799. entity.OtherMemo = GetPostString("otherMemo");
  800. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  801. {
  802. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  803. StringBuilder sql = new StringBuilder();
  804. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  805. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  806. if (dt != null && dt.Rows.Count > 0)
  807. {
  808. foreach (DataRow dr in dt.Rows)
  809. {
  810. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  811. {
  812. //品类一直
  813. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  814. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  815. if (ceErpSampleCustomer == null)
  816. {
  817. ceErpSampleCustomer = new CeErpSampleCustomer();
  818. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  819. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  820. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  821. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  822. ceErpSampleCustomer.shopId = entity.ShopId;
  823. }
  824. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  825. ceErpSampleCustomer.lastTid = entity.tid;
  826. if (ceErpSampleCustomer.ID > 0)
  827. {
  828. ceErpSampleCustomer.Update();
  829. }
  830. else
  831. {
  832. ceErpSampleCustomer.Create();
  833. }
  834. }
  835. }
  836. }
  837. }
  838. //if (entity.IsOldCustomer == 1)
  839. //{
  840. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  841. //{
  842. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  843. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  844. //}
  845. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  846. //{
  847. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  848. // {
  849. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  850. // {
  851. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  852. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  853. // }
  854. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  855. // {
  856. // entity.OrderState = 2;
  857. // entity.DesignUserId = 0;
  858. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  859. // }
  860. // else
  861. // {
  862. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  863. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  864. // }
  865. // }
  866. //}
  867. //}
  868. entity.Update();
  869. returnSuccessMsg("保存成功!");
  870. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  871. return;
  872. }
  873. returnErrorMsg("找不到记录");
  874. }
  875. }
  876. public void save_erp_customermemo()
  877. {
  878. if (UrlPostParmsCheck("ctid"))
  879. {
  880. string ctid = GetPostString("ctid");
  881. CeErpTradeCell entity = null;
  882. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  883. if (entity != null)
  884. {
  885. entity.CustomerMemo = GetPostString("CustomerMemo");
  886. entity.Update();
  887. ApiVo apiVo = new ApiVo();
  888. apiVo.orderNumber = entity.ctid;
  889. apiVo.actionName = "followRemarks";
  890. apiVo.orderRemarks = entity.CustomerMemo;
  891. designHelper.API_WorkCore(apiVo);//followRemarks
  892. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  893. returnSuccessMsg("保存成功!");
  894. return;
  895. }
  896. returnErrorMsg("找不到记录");
  897. }
  898. }
  899. public void upd_erp_addmemotag()
  900. {
  901. if (UrlPostParmsCheck("ctid"))
  902. {
  903. ;
  904. string eid = GetPostString("ctid");
  905. string sfTagstr = GetPostString("memotag");
  906. CeErpTradeCell entity = null;
  907. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  908. if (entity != null)
  909. {
  910. ApiVo apiVo = new ApiVo();
  911. if (entity.OrderState == 0)
  912. {
  913. returnErrorMsg("请先领单");
  914. return;
  915. }
  916. //撤销顺丰
  917. if (sfTagstr == "撤销顺丰")
  918. {
  919. entity.IsSF = 0;
  920. string reMsg = "";
  921. string oldmemo = entity.seller_memo;
  922. if (entity.OrderState < 5)
  923. {
  924. oldmemo = oldmemo.Replace("顺丰到付", "");
  925. oldmemo = oldmemo.Replace("顺丰寄付", "");
  926. entity.seller_memo = oldmemo;
  927. }
  928. else
  929. {
  930. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  931. {
  932. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  933. }
  934. }
  935. entity.Update();
  936. apiVo.orderNumber = entity.ctid;
  937. apiVo.actionName = "orderRemarks";
  938. apiVo.orderRemarks = entity.seller_memo;
  939. apiVo.isSf = entity.IsSF.ToString();
  940. designHelper.API_WorkCore(apiVo);//orderRemarks
  941. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  942. returnSuccessMsg("撤销成功!" + reMsg);
  943. return;
  944. }
  945. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  946. {
  947. //string oldmemo = entity.seller_memo;
  948. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  949. string sfStr = GetPostString("memotag");
  950. string smemo = entity.seller_memo;
  951. int kindex = smemo.IndexOf(")");
  952. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  953. if (lastoneStr != "-")
  954. {
  955. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  956. }
  957. string prememo = smemo.Substring(0, kindex + 2);
  958. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  959. int lastkindex = lastmemo.IndexOf("(");
  960. string newlastmemo = "";
  961. if (lastkindex == 0)
  962. {
  963. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  964. newlastmemo = "(" + sfStr + "." + useLastmemo;
  965. }
  966. else
  967. {
  968. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  969. }
  970. entity.seller_memo = prememo + newlastmemo;
  971. }
  972. string sfTagMSg = "";
  973. if (sfTagstr == "顺丰寄付")
  974. {
  975. entity.IsSF = 1;
  976. sfTagMSg = "顺丰寄付";
  977. }
  978. else if (sfTagstr == "顺丰到付")
  979. {
  980. entity.IsSF = 2;
  981. sfTagMSg = "顺丰到付";
  982. }
  983. entity.Update();
  984. apiVo = new ApiVo();
  985. apiVo.orderNumber = entity.ctid;
  986. apiVo.actionName = "orderRemarks";
  987. apiVo.orderRemarks = entity.seller_memo;
  988. apiVo.isSf = entity.IsSF.ToString();
  989. designHelper.API_WorkCore(apiVo);//orderRemarks
  990. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  991. returnSuccessMsg("标记成功!");
  992. return;
  993. }
  994. returnErrorMsg("找不到记录");
  995. }
  996. }
  997. public void upd_erp_ordertag()
  998. {
  999. if (UrlPostParmsCheck("ctid"))
  1000. {
  1001. string eid = GetPostString("ctid");
  1002. CeErpTradeCell entity = null;
  1003. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1004. if (entity != null)
  1005. {
  1006. int tag = GetPostInt("wechattag");
  1007. //if(tag==4 && entity.IsSample == 2)
  1008. //{
  1009. // returnErrorMsg("补差价单不能标记微信单");
  1010. // return;
  1011. //}
  1012. entity.wechatTag = tag;
  1013. entity.Update();
  1014. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1015. if (tag == 1)
  1016. {
  1017. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1018. if (cash == null)
  1019. {
  1020. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1021. cash = new CeErpReturnCash();
  1022. cash.tid = entity.tid;
  1023. cash.seller_nick = main.seller_nick;
  1024. cash.payment = trade.payment;
  1025. cash.buyer_nick = main.buyer_nick;
  1026. cash.cashstate = 0;
  1027. cash.rtype = "微信返现";
  1028. cash.returnprice = 0;
  1029. cash.created = DateTime.Now;
  1030. cash.con = "订单标记微信单";
  1031. cash.img = "";
  1032. cash.applyuserid = CurrentUser.UserID;
  1033. cash.Create();
  1034. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1035. }
  1036. else
  1037. {
  1038. cash.cashstate = 0;
  1039. cash.Update();
  1040. }
  1041. CeErpSukuraData.createInfo(entity.ctid, 9);
  1042. }
  1043. else if (tag == 2)
  1044. {
  1045. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1046. if (cash == null)
  1047. {
  1048. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1049. cash = new CeErpReturnCash();
  1050. cash.tid = entity.tid;
  1051. cash.seller_nick = main.seller_nick;
  1052. cash.payment = trade.payment;
  1053. cash.buyer_nick = main.buyer_nick;
  1054. cash.cashstate = 0;
  1055. cash.rtype = "推购返现";
  1056. cash.returnprice = 5;
  1057. cash.created = DateTime.Now;
  1058. cash.con = "订单标记推购单";
  1059. cash.img = "";
  1060. cash.applyuserid = CurrentUser.UserID;
  1061. cash.Create();
  1062. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1063. }
  1064. else
  1065. {
  1066. cash.cashstate = 0;
  1067. cash.Update();
  1068. }
  1069. CeErpSukuraData.createInfo(entity.ctid, 9);
  1070. }
  1071. else if (tag == 3)
  1072. {
  1073. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1074. if (pers == null)
  1075. {
  1076. pers = new CeErpPersuade();
  1077. pers.ctid = entity.ctid;
  1078. pers.pstate = 0;
  1079. pers.created = DateTime.Now;
  1080. pers.applyuserid = CurrentUser.UserID;
  1081. pers.Create();
  1082. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1083. }
  1084. else
  1085. {
  1086. pers.pstate = 0;
  1087. pers.Update();
  1088. }
  1089. }
  1090. else if (tag == 4 || tag == 5)
  1091. {
  1092. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1093. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1094. if (pers == null)
  1095. {
  1096. pers = new CeErpStayGoods();
  1097. pers.t_id = entity.tid;
  1098. pers.status = "待审核";
  1099. pers.audit_type = 0;
  1100. if (tag == 4)
  1101. {
  1102. pers.stay_type = "微信推购";
  1103. }
  1104. else
  1105. {
  1106. pers.stay_type = "旺旺推购";
  1107. }
  1108. if (entity.IsXianHuo == 0)
  1109. {
  1110. pers.product_id = entity.ProductId;
  1111. }
  1112. pers.wangwang = main.buyer_nick;
  1113. pers.shop_name = main.seller_nick;
  1114. pers.creata_time = DateTime.Now;
  1115. pers.create_u_id = CurrentUser.UserID;
  1116. pers.create_u_name = CurrentUser.UserName;
  1117. pers.Create();
  1118. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1119. }
  1120. else
  1121. {
  1122. pers.audit_type = 0;
  1123. pers.Update();
  1124. }
  1125. CeErpSukuraData.createInfo(entity.ctid, 10);
  1126. }
  1127. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1128. returnSuccessMsg("标记成功!");
  1129. return;
  1130. }
  1131. returnErrorMsg("找不到记录");
  1132. }
  1133. }
  1134. public void upd_erp_ordertag_cancel()
  1135. {
  1136. if (UrlPostParmsCheck("ctid"))
  1137. {
  1138. string eid = GetPostString("ctid");
  1139. CeErpTradeCell entity = null;
  1140. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1141. if (entity != null)
  1142. {
  1143. entity.wechatTag = 0;
  1144. entity.Update();
  1145. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1146. if (pers != null)
  1147. {
  1148. pers.status = "取消推购";
  1149. pers.audit_type = 3;
  1150. pers.Update();
  1151. }
  1152. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1153. returnSuccessMsg("标记成功!");
  1154. return;
  1155. }
  1156. returnErrorMsg("找不到记录");
  1157. }
  1158. }
  1159. public void upd_erp_addweichattag()
  1160. {
  1161. if (UrlPostParmsCheck("ctid"))
  1162. {
  1163. ;
  1164. string eid = GetPostString("ctid");
  1165. CeErpTradeCell entity = null;
  1166. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1167. if (entity != null)
  1168. {
  1169. if (entity.IsAddWechat > 0)
  1170. {
  1171. returnErrorMsg("此单已经标记过了");
  1172. return;
  1173. }
  1174. 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);
  1175. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1176. if (dt.Rows.Count > 0)
  1177. {
  1178. entity.IsAddWechat = 2;
  1179. }
  1180. else
  1181. {
  1182. entity.IsAddWechat = 1;
  1183. }
  1184. entity.Update();
  1185. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1186. returnSuccessMsg("标记成功!");
  1187. return;
  1188. }
  1189. returnErrorMsg("找不到记录");
  1190. }
  1191. }
  1192. public void upd_erp_getmyorder()
  1193. {
  1194. if (UrlPostParmsCheck("ctid"))
  1195. {
  1196. ;
  1197. string eid = GetPostString("ctid");
  1198. CeErpTradeCell entity = null;
  1199. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1200. if (entity != null)
  1201. {
  1202. if (entity.ctid.IndexOf("C") != -1)
  1203. {
  1204. StringBuilder sql = new StringBuilder();
  1205. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1206. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1207. if (dt.Rows.Count > 0)
  1208. {
  1209. decimal total = 0;
  1210. foreach (DataRow dr in dt.Rows)
  1211. {
  1212. total += Convert.ToDecimal(dr["payment"]);
  1213. }
  1214. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1215. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1216. {
  1217. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1218. return;
  1219. }
  1220. }
  1221. }
  1222. if (entity.OrderState == -1)
  1223. {
  1224. returnErrorMsg("待审核订单无法领取!");
  1225. return;
  1226. }
  1227. entity.CustomerUserId = CurrentUser.UserID;
  1228. if (entity.OrderState < 2)
  1229. {
  1230. entity.OrderState = 2;
  1231. if (entity.ShopId != 0)
  1232. {
  1233. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1234. }
  1235. }
  1236. entity.UpdateTime = DateTime.Now;
  1237. entity.Update();
  1238. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1239. returnSuccessMsg("领单成功!");
  1240. return;
  1241. }
  1242. returnErrorMsg("找不到记录");
  1243. }
  1244. }
  1245. public void getmyorder_from_init()
  1246. {
  1247. if (UrlPostParmsCheck("ctid"))
  1248. {
  1249. string eid = GetPostString("ctid");
  1250. CeErpTradeCell entity = null;
  1251. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1252. if (entity != null)
  1253. {
  1254. string sellerMemo = GetPostString("sellerMemo");
  1255. if (sellerMemo.Length > 0)
  1256. {
  1257. entity.seller_memo = sellerMemo;
  1258. }
  1259. string oterhMemo = GetPostString("otherMemo");
  1260. if (oterhMemo.Length > 0)
  1261. {
  1262. entity.OtherMemo = oterhMemo;
  1263. }
  1264. int urg = GetPostInt("urgency");
  1265. entity.IsUrgency = (urg == 1 ? true : false);
  1266. int wechat = GetPostInt("wechat");
  1267. int command = GetPostInt("command");
  1268. if (wechat == 1)
  1269. {
  1270. entity.wechatTag = 1;
  1271. }
  1272. if (command == 1)
  1273. {
  1274. entity.wechatTag = 2;
  1275. }
  1276. string pPro = GetPostString("pprofession");
  1277. if (pPro.Length > 0)
  1278. {
  1279. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1280. string spro = GetPostString("profession");
  1281. if (spro.Length > 0)
  1282. {
  1283. entity.ProfessionId = Convert.ToInt32(spro);
  1284. }
  1285. }
  1286. string proId = GetPostString("productId");
  1287. if (proId.Length > 0)
  1288. {
  1289. entity.ProductId = Convert.ToInt32(proId);
  1290. }
  1291. entity.Material = GetPostString("material");
  1292. entity.Craft = GetPostString("craft");
  1293. entity.CustomerUserId = CurrentUser.UserID;
  1294. if (entity.OrderState < 2)
  1295. {
  1296. entity.OrderState = 2;
  1297. if (entity.ShopId != 0)
  1298. {
  1299. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1300. }
  1301. }
  1302. entity.Update();
  1303. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1304. returnSuccessMsg("领单成功!");
  1305. return;
  1306. }
  1307. returnErrorMsg("找不到记录");
  1308. }
  1309. }
  1310. public void upd_erp_setrelationorder()
  1311. {
  1312. if (UrlPostParmsCheck("ctid"))
  1313. {
  1314. ;
  1315. string eid = GetPostString("ctid");
  1316. string ftid = GetPostString("ftid");
  1317. CeErpTradeCell entity = null;
  1318. CeErpTradeCell fentity = null;
  1319. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1320. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1321. if (fentity == null)
  1322. {
  1323. returnErrorMsg("找不到关联的主订单");
  1324. return;
  1325. }
  1326. if (entity != null)
  1327. {
  1328. if (entity.OrderState >= 5)
  1329. {
  1330. returnErrorMsg("本单已经设计完成无法关联");
  1331. return;
  1332. }
  1333. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1334. {
  1335. returnErrorMsg("线下单续审核后才能关联!");
  1336. return;
  1337. }
  1338. entity.ptid = ftid;
  1339. entity.OrderState = fentity.OrderState;
  1340. //entity.status = fentity.status;
  1341. entity.CustomerUserId = fentity.CustomerUserId;
  1342. entity.DesignUserId = fentity.DesignUserId;
  1343. entity.seller_memo = "补差价单:" + ftid;
  1344. entity.IsSample = 2;
  1345. entity.Update();
  1346. ApiVo apiVo = new ApiVo();
  1347. apiVo.orderNumber = ftid;
  1348. apiVo.payment = entity.payment;
  1349. apiVo.actionName = "repairDesign";
  1350. designHelper.API_WorkCore(apiVo);//repairDesign
  1351. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1352. returnSuccessMsg("关联成功!");
  1353. return;
  1354. }
  1355. else
  1356. returnErrorMsg("找不到记录");
  1357. }
  1358. }
  1359. public void download_erp_neworder()
  1360. {
  1361. string seller = GetPostString("seller_nick");
  1362. string tid = GetPostString("tid");
  1363. if (seller.Length <= 0 || tid.Length <= 0)
  1364. {
  1365. returnErrorMsg("数据错误");
  1366. }
  1367. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1368. //{
  1369. // returnErrorMsg("找不到店铺Sessionkey");
  1370. //}
  1371. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1372. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1373. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1374. if (res.IndexOf("refOid") == -1)
  1375. {
  1376. returnErrorMsg("下载订单数据失败");
  1377. return;
  1378. }
  1379. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1380. returnSuccessMsg("下载完成");
  1381. //tmcHelper.createNewOrder(res);
  1382. //CeErpTrade entr = null;
  1383. //entr = CeErpTrade.Get(tid);
  1384. //if (entr != null)
  1385. //{
  1386. // returnSuccess("下载成功");
  1387. // //下载成功之后,Cell表生成对应的订单;
  1388. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1389. //}
  1390. //else
  1391. //{
  1392. // returnErrorMsg("下载失败或者创建订单失败");
  1393. //}
  1394. }
  1395. public void set_erp_atersale()
  1396. {
  1397. if (UrlPostParmsCheck("ctid"))
  1398. {
  1399. string eid = GetPostString("ctid");
  1400. string reason = GetPostString("AfterSaleReason");
  1401. CeErpTradeCell entity = null;
  1402. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1403. if (entity != null)
  1404. {
  1405. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1406. {
  1407. returnErrorMsg("此订单已经在售后");
  1408. return;
  1409. }
  1410. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1411. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1412. entity.AfterSaleTime = DateTime.Now;
  1413. entity.Update();
  1414. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1415. returnSuccessMsg("转售后成功!");
  1416. return;
  1417. }
  1418. returnErrorMsg("找不到记录");
  1419. }
  1420. }
  1421. public void set_erp_withdraw()
  1422. {
  1423. if (UrlPostParmsCheck("ctid"))
  1424. {
  1425. try
  1426. {
  1427. string eid = GetPostString("ctid");//商品id
  1428. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1429. CeWithdraw ceWithdrawSelect = null;
  1430. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1431. if (ceWithdrawSelect != null)
  1432. {
  1433. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1434. {
  1435. ceWithdrawSelect.status = -1;
  1436. ceWithdrawSelect.Update();
  1437. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1438. returnSuccessMsg("重新发起审核成功");
  1439. return;
  1440. }
  1441. else
  1442. {
  1443. returnSuccessMsg("请勿重复申请!");
  1444. return;
  1445. }
  1446. }
  1447. else
  1448. {
  1449. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1450. if (string.IsNullOrEmpty(CustomerUserId))
  1451. {
  1452. CustomerUserId = "-1";
  1453. }
  1454. int Userid = CurrentUser.UserID;//用户id
  1455. CeWithdraw ceWithdraw = new CeWithdraw();
  1456. ceWithdraw.tid = eid;
  1457. ceWithdraw.userid = Userid;
  1458. ceWithdraw.providerid = CustomerUserId;
  1459. ceWithdraw.status = 3;
  1460. ceWithdraw.creationtime = DateTime.Now;
  1461. ceWithdraw.Create();
  1462. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1463. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1464. return;
  1465. }
  1466. }
  1467. catch
  1468. {
  1469. returnErrorMsg("申请撤回订单失败");
  1470. return;
  1471. }
  1472. }
  1473. }
  1474. public void ins_erp_billinfo()
  1475. {
  1476. if (UrlPostParmsCheck("ctid"))
  1477. {
  1478. string eid = GetPostString("ctid");
  1479. CeErpTradeCell entity = null;
  1480. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1481. if (entity != null)
  1482. {
  1483. CeErpBill bill = CeErpBill.GetByTid(eid);
  1484. bool isHave = false;
  1485. if (bill != null)
  1486. {
  1487. isHave = true;
  1488. if (bill.state != 4)
  1489. {
  1490. returnErrorMsg("此单已经申请过发票了");
  1491. return;
  1492. }
  1493. }
  1494. if (entity.IsNeedBill == 0)
  1495. {
  1496. entity.IsNeedBill = 1;
  1497. }
  1498. entity.Update();
  1499. string errjson = "";
  1500. try
  1501. {
  1502. CeErpBill bill_entity = new CeErpBill();
  1503. bill_entity.tid = entity.tid;
  1504. bill_entity.title = GetPostString("title");
  1505. string taxstr = GetPostString("tax");
  1506. taxstr = taxstr.Replace(" ", "");
  1507. bill_entity.tax = taxstr;
  1508. bill_entity.bank = GetPostString("bank");
  1509. string bankacstr = GetPostString("bankac");
  1510. bankacstr = bankacstr.Replace(" ", "");
  1511. bill_entity.bankac = bankacstr;
  1512. bill_entity.address = GetPostString("address");
  1513. bill_entity.phone = GetPostString("phone");
  1514. bill_entity.price = GetPostString("price");
  1515. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1516. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1517. {
  1518. billCount += 1;
  1519. }
  1520. string prebill = "ltb";
  1521. for (int idx = 1; idx <= billCount; idx++)
  1522. {
  1523. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1524. string billoid = prebill + idx + dtstr;
  1525. bill_entity.billOrderId += billoid;
  1526. if (idx < billCount)
  1527. {
  1528. bill_entity.billOrderId += ",";
  1529. }
  1530. }
  1531. bill_entity.productId = GetPostInt("ProductName");
  1532. bill_entity.num = GetPostInt("num");
  1533. bill_entity.unit = GetPostString("unit");
  1534. bill_entity.type = GetPostString("type");
  1535. bill_entity.sendType = GetPostString("SendType");
  1536. bill_entity.email = GetPostString("email");
  1537. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1538. bill_entity.shopName = GetPostString("ShopName");
  1539. bill_entity.applymemo = GetPostString("applyMemo");
  1540. bill_entity.createTime = DateTime.Now;
  1541. bill_entity.state = 0;
  1542. bill_entity.userId = CurrentUser.UserID;
  1543. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1544. bill_entity.Create();
  1545. }
  1546. catch (Exception ex)
  1547. {
  1548. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1549. returnErrorMsg("创建发票出错!");
  1550. return;
  1551. }
  1552. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1553. returnSuccessMsg("发票申请成功!");
  1554. return;
  1555. }
  1556. returnErrorMsg("找不到记录");
  1557. }
  1558. }
  1559. public void ins_erp_neworder()
  1560. {
  1561. if (UrlPostParmsCheck("receiver_name"))
  1562. {
  1563. CeErpTrade entity = new CeErpTrade();
  1564. string plat_form = GetPostString("platform");
  1565. string preStr = "N_";
  1566. if (plat_form == "拼多多")
  1567. {
  1568. preStr = "P_";
  1569. }
  1570. else if (plat_form == "阿里巴巴")
  1571. {
  1572. preStr = "A_";
  1573. }
  1574. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1575. entity.seller_nick = GetPostString("seller_nick");
  1576. entity.buyer_nick = GetPostString("buyer_nick");
  1577. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1578. entity.total_fee = entity.payment;
  1579. entity.pay_time = DateTime.Now;
  1580. entity.status = "NOT_SHIPPED";
  1581. entity.receiver_name = GetPostString("receiver_name");
  1582. entity.receiver_mobile = GetPostString("receiver_mobile");
  1583. entity.receiver_state = GetPostString("receiver_state");
  1584. entity.receiver_city = GetPostString("receiver_city");
  1585. entity.receiver_district = GetPostString("receiver_district");
  1586. entity.receiver_address = GetPostString("receiver_address");
  1587. if (entity.receiver_state == "" || entity.receiver_city == "")
  1588. {
  1589. returnErrorMsg("收件地址不能为空");
  1590. return;
  1591. }
  1592. int shopId = 0;
  1593. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1594. if (nShop != null)
  1595. {
  1596. shopId = nShop.ID;
  1597. }
  1598. if (shopId != 34 && entity.payment == 0)
  1599. {
  1600. returnErrorMsg("公司自用的单金额才能为0");
  1601. return;
  1602. }
  1603. entity.Create();
  1604. CeErpTradeCell entitycell = new CeErpTradeCell();
  1605. entitycell.ctid = entity.tid;
  1606. entitycell.tid = entity.tid;
  1607. entitycell.ShopId = shopId;
  1608. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1609. entitycell.OrderState = 0;
  1610. entitycell.pay_time = entity.pay_time;
  1611. entitycell.IsOffLineOrder = 1;
  1612. entitycell.Create();
  1613. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1614. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1615. return;
  1616. }
  1617. }
  1618. public void ins_erp_neworder2()
  1619. {
  1620. if (UrlPostParmsCheck("receiver_name"))
  1621. {
  1622. //string plat_form = GetPostString("platform");
  1623. string preStr = "X_";
  1624. string memo = GetPostString("memo");
  1625. string productId = GetPostString("productId");
  1626. string primg = GetPostString("proofimg");
  1627. string sellerNick = GetPostString("seller_nick");
  1628. string addFrom = GetPostString("addfrom");
  1629. if (addFrom == "1")
  1630. {
  1631. preStr = "N_";
  1632. }
  1633. int shopId = 0;
  1634. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1635. if (nShop != null)
  1636. {
  1637. shopId = nShop.ID;
  1638. }
  1639. else
  1640. {
  1641. returnErrorMsg("找不到对应店铺");
  1642. return;
  1643. }
  1644. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1645. {
  1646. returnErrorMsg("必须上传付款凭证");
  1647. return;
  1648. }
  1649. CeErpTrade entity = new CeErpTrade();
  1650. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1651. entity.seller_nick = sellerNick;
  1652. entity.buyer_nick = GetPostString("buyer_nick");
  1653. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1654. entity.total_fee = entity.payment;
  1655. entity.pay_time = DateTime.Now;
  1656. entity.status = "NOT_SHIPPED";
  1657. entity.receiver_name = GetPostString("receiver_name");
  1658. entity.receiver_mobile = GetPostString("receiver_mobile");
  1659. entity.receiver_state = GetPostString("receiver_state");
  1660. entity.receiver_city = GetPostString("receiver_city");
  1661. entity.receiver_district = GetPostString("receiver_district");
  1662. entity.receiver_address = GetPostString("receiver_address");
  1663. entity.seller_memo = memo;
  1664. entity.orderFrom = 20;
  1665. entity.orderType = 15;
  1666. if (entity.receiver_state == "" || entity.receiver_city == "")
  1667. {
  1668. returnErrorMsg("收件地址不能为空");
  1669. return;
  1670. }
  1671. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1672. {
  1673. returnErrorMsg("公司自用的单金额才能为0");
  1674. return;
  1675. }
  1676. entity.Create();
  1677. string toWhere = GetPostString("towhere");
  1678. CeErpTradeCell entitycell = new CeErpTradeCell();
  1679. entitycell.ctid = entity.tid;
  1680. //唯一标识
  1681. entitycell.OrderSn = entity.tid;
  1682. string orderSn = dataHelper.getSaleOrderSn();
  1683. if (orderSn != "")
  1684. {
  1685. entitycell.OrderSn = orderSn;
  1686. }
  1687. entitycell.tid = entity.tid;
  1688. //if (preStr == "X_")
  1689. //{
  1690. entitycell.IsOffLineOrder = 1;
  1691. //}
  1692. entitycell.CustomerUserId = CurrentUser.UserID;
  1693. entitycell.PayProofImg = primg;
  1694. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1695. entitycell.ProductId = Convert.ToInt32(productId);
  1696. entitycell.ShopId = shopId;
  1697. entitycell.UpdateTime = DateTime.Now;
  1698. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1699. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1700. {
  1701. entitycell.IsXianHuo = 1;
  1702. }
  1703. entitycell.pay_time = entity.pay_time;
  1704. if (toWhere == "1")
  1705. {
  1706. entitycell.OrderState = 2;
  1707. }
  1708. else
  1709. {
  1710. entitycell.OrderState = 6;
  1711. entitycell.FinishPlaceTime = entitycell.pay_time;
  1712. }
  1713. if (shopId == 94)
  1714. {
  1715. entitycell.OrderState = 4;
  1716. entitycell.WaitDesignTime = entitycell.pay_time;
  1717. entitycell.StartDesignTime = entitycell.pay_time;
  1718. entitycell.DesignUserId = 218;
  1719. }
  1720. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1721. {
  1722. entitycell.OrderState = -1;//修改12-5
  1723. CeWithdraw ceWithdraw = new CeWithdraw();
  1724. ceWithdraw.tid = entity.tid;
  1725. ceWithdraw.providerid = "-1";
  1726. ceWithdraw.status = -1;
  1727. ceWithdraw.creationtime = DateTime.Now;
  1728. ceWithdraw.userid = 1337;
  1729. ceWithdraw.Create();
  1730. }
  1731. entitycell.Create();
  1732. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1733. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1734. {
  1735. addPlaceRegist(entitycell, CurrentUser.UserID);
  1736. }
  1737. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1738. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1739. return;
  1740. }
  1741. }
  1742. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1743. {
  1744. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1745. entity.PlactTime = tradecell.pay_time;
  1746. entity.AddUserId = userid;
  1747. entity.FileName = tradecell.seller_memo;
  1748. entity.Supplier = 24;
  1749. entity.CreateTime = DateTime.Now;
  1750. entity.Did = tradecell.ctid;
  1751. entity.tid = tradecell.tid;
  1752. entity.splitTag = tradecell.SplitTag;
  1753. entity.CurState = "未完成";
  1754. entity.Create();
  1755. }
  1756. public void get_erp_offlinelist()
  1757. {
  1758. DataStruct dStruct = GetPostStruct();
  1759. List<string> lw = new List<string>();
  1760. string tid = GetPostString("ctid");
  1761. string date1 = GetPostString("date1");
  1762. string date2 = GetPostString("date2");
  1763. if (tid.Length > 0 || date1.Length > 0)
  1764. {
  1765. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1766. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1767. if (dw.Length > 0) lw.Add(dw);
  1768. }
  1769. else
  1770. {
  1771. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1772. }
  1773. string shopname = GetPostString("shopname");
  1774. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1775. string buyernick = GetPostString("buyer_nick");
  1776. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1777. string customer = GetPostString("customer");
  1778. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1779. string design = GetPostString("design");
  1780. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1781. string orderState = GetPostString("orderState");
  1782. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1783. string address = GetPostString("address");
  1784. 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));
  1785. string sellermemo = GetPostString("seller_memo");
  1786. if (sellermemo.Length > 0)
  1787. {
  1788. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1789. }
  1790. string price1 = GetPostString("price1");
  1791. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1792. string price2 = GetPostString("price2");
  1793. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1794. //if (PKey != "admin")
  1795. //{
  1796. // string usershop = CurrentUser.User.pemShop;
  1797. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1798. //}
  1799. //if (ex_psize > 0)
  1800. //{
  1801. dStruct.Order = "pay_time desc";
  1802. //}
  1803. //else
  1804. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1805. lw.Add(string.Format("IsOffLineOrder=1"));
  1806. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1807. DataTable dt = null;
  1808. dt = WebCache.GetData("view_erptradecell", dStruct);
  1809. writeGridDataTableJson(dStruct.TotalCount, dt);
  1810. }
  1811. public void get_erp_returncashrecord()
  1812. {
  1813. DataStruct dStruct = GetPostStruct();
  1814. List<string> lw = new List<string>();
  1815. string tid = GetPostString("ctid");
  1816. if (tid.Length > 0)
  1817. {
  1818. lw.Add(string.Format("tid like '%{0}%'", tid));
  1819. dStruct.Order = "id desc";
  1820. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1821. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1822. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1823. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1824. return;
  1825. }
  1826. returnErrorMsg("id数据错误!");
  1827. }
  1828. public void ins_erp_returncashrecord()
  1829. {
  1830. if (UrlPostParmsCheck("tid"))
  1831. {
  1832. string tid = GetPostString("tid");
  1833. string retype = GetPostString("type");
  1834. StringBuilder sql = new StringBuilder();
  1835. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1836. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1837. if (dt.Rows.Count > 0)
  1838. {
  1839. returnErrorMsg("相同返现类型记录已存在");
  1840. return;
  1841. }
  1842. CeErpReturnCash entity = new CeErpReturnCash();
  1843. entity.tid = tid;
  1844. entity.seller_nick = GetPostString("seller_nick");
  1845. string pment = GetPostString("payment");
  1846. if (pment.Length > 0)
  1847. {
  1848. entity.payment = Convert.ToDouble(pment);
  1849. }
  1850. entity.buyer_nick = GetPostString("buyer_nick");
  1851. entity.cashstate = 0;
  1852. entity.rtype = retype;
  1853. string rPrice = GetPostString("returnprice");
  1854. if (rPrice.Length > 0)
  1855. {
  1856. entity.returnprice = Convert.ToDouble(rPrice);
  1857. }
  1858. entity.created = DateTime.Now;
  1859. entity.con = GetPostString("con");
  1860. entity.img = GetPostString("img");
  1861. entity.applyuserid = CurrentUser.UserID;
  1862. entity.Create();
  1863. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1864. returnSuccessMsg("操作成功!");
  1865. return;
  1866. }
  1867. }
  1868. public void set_erp_predelivery()
  1869. {
  1870. if (UrlPostParmsCheck("ctid"))
  1871. {
  1872. string eid = GetPostString("ctid");
  1873. CeErpTradeCell entity = null;
  1874. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1875. if (entity != null)
  1876. {
  1877. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1878. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1879. //{
  1880. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1881. // return;
  1882. //}
  1883. entity.IsPreDelivery = 1;
  1884. entity.Update();
  1885. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1886. returnSuccessMsg("预发货成功!");
  1887. return;
  1888. //string shop = GetPostString("seller_nick");
  1889. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1890. //string comName = GetPostString("comName");
  1891. //string comCode = GetPostString("comCode");
  1892. //string outSid = GetPostString("outSid");//运单号
  1893. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1894. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1895. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1896. //string apires = "";
  1897. //if (deliveryType == "虚拟发货")
  1898. //{
  1899. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1900. //}
  1901. //else
  1902. //{
  1903. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1904. //}
  1905. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1906. ////{
  1907. //if (apires.IndexOf("发货成功") != -1)
  1908. //{
  1909. // if (deliveryType != "虚拟发货")
  1910. // {
  1911. // //还要插入快递信息到 快递信息表
  1912. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1913. // exinfo.tid = eid;
  1914. // exinfo.out_sid = outSid;
  1915. // exinfo.company_code = comCode;
  1916. // exinfo.company_name = comName;
  1917. // exinfo.delivery_memo = deliveryMemo;
  1918. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1919. // exinfo.deliveryType = deliveryType;
  1920. // exinfo.Create();
  1921. // }
  1922. // returnSuccessMsg("发货成功!");
  1923. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1924. //}
  1925. //else
  1926. //{
  1927. // returnErrorMsg("淘宝发货失败!!");
  1928. //}
  1929. //return;
  1930. }
  1931. returnErrorMsg("找不到订单记录");
  1932. }
  1933. }
  1934. public void get_erp_unusuallist()
  1935. {
  1936. DataStruct dStruct = GetPostStruct();
  1937. List<string> lw = new List<string>();
  1938. string tid = GetPostString("ctid");
  1939. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1940. string shopname = GetPostString("shopname");
  1941. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1942. string buyernick = GetPostString("buyer_nick");
  1943. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1944. string ResponsibleMan = GetPostString("responsible");
  1945. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1946. string date1 = GetPostString("date1");
  1947. string date2 = GetPostString("date2");
  1948. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1949. if (dw.Length > 0) lw.Add(dw);
  1950. string price1 = GetPostString("price1");
  1951. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1952. string price2 = GetPostString("price2");
  1953. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1954. string orderState = GetPostString("orderState");
  1955. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1956. string sellermemo = GetPostString("seller_memo");
  1957. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1958. lw.Add(string.Format("UnusualTag > 0"));
  1959. lw.Add(string.Format("IsRefund<={0}", 1));
  1960. dStruct.Order = "pay_time desc";
  1961. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1962. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1963. writeGridDataTableJson(dStruct.TotalCount, dt);
  1964. }
  1965. public void set_erp_unusualtonomal()
  1966. {
  1967. if (UrlPostParmsCheck("ctid"))
  1968. {
  1969. string eid = GetPostString("ctid");
  1970. CeErpTradeCell entity = null;
  1971. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1972. if (entity != null)
  1973. {
  1974. entity.UnusualTag = -1;
  1975. entity.Update();
  1976. returnSuccessMsg("忽略成功!");
  1977. return;
  1978. }
  1979. returnErrorMsg("找不到记录");
  1980. }
  1981. }
  1982. public void ins_erp_unusualreason()
  1983. {
  1984. if (UrlPostParmsCheck("ctid"))
  1985. {
  1986. string eid = GetPostString("ctid");
  1987. CeErpTradeCell entity = null;
  1988. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1989. if (entity != null)
  1990. {
  1991. entity.MemoOpt = 4;
  1992. entity.UnusualCon = GetPostString("con");
  1993. entity.Update();
  1994. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1995. if (trade != null)
  1996. {
  1997. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  1998. }
  1999. //查货是否超时
  2000. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2001. if (ceErpTradeCellExtend == null)
  2002. {
  2003. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2004. ceErpTradeCellExtend.ctid = entity.ctid;
  2005. }
  2006. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2007. {
  2008. ceErpTradeCellExtend.CheckOut += 1;
  2009. }
  2010. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2011. if (ceErpTradeCellExtend.ID > 0)
  2012. {
  2013. ceErpTradeCellExtend.Update();
  2014. }
  2015. else
  2016. {
  2017. ceErpTradeCellExtend.Create();
  2018. }
  2019. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2020. returnSuccessMsg("操作成功!");
  2021. return;
  2022. }
  2023. returnErrorMsg("找不到记录");
  2024. }
  2025. }
  2026. public void upd_erp_sampleorder()
  2027. {
  2028. if (UrlPostParmsCheck("ctid"))
  2029. {
  2030. string eid = GetPostString("ctid");
  2031. string[] eArr = eid.Split(',');
  2032. if (eArr.Length > 1)
  2033. {
  2034. List<string> eLst = new List<string>();
  2035. for (int i = 0; i < eArr.Length; i++)
  2036. {
  2037. eLst.Add("'" + eArr[i] + "'");
  2038. }
  2039. eid = string.Join(",", eLst.ToArray());
  2040. }
  2041. else
  2042. {
  2043. eid = "'" + eid + "'";
  2044. }
  2045. StringBuilder sql = new StringBuilder();
  2046. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2047. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2048. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2049. if (dt.Rows.Count > 0)
  2050. {
  2051. string errmsg = "";
  2052. foreach (DataRow dr in dt.Rows)
  2053. {
  2054. StringBuilder sqlsb = new StringBuilder();
  2055. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2056. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2057. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2058. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2059. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2060. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2061. {
  2062. continue;
  2063. }
  2064. else
  2065. {
  2066. string emsg = commonHelper.KeepChinese(apires);
  2067. errmsg += emsg;
  2068. }
  2069. }
  2070. if (errmsg.Length > 0)
  2071. {
  2072. returnErrorMsg(errmsg);
  2073. return;
  2074. }
  2075. returnSuccessMsg("操作成功");
  2076. return;
  2077. }
  2078. returnErrorMsg("找不到记录");
  2079. }
  2080. }
  2081. public void upd_erp_transcustomer()
  2082. {
  2083. if (UrlPostParmsCheck("ctid"))
  2084. {
  2085. string eid = GetPostString("ctid");
  2086. int userid = GetPostInt("CustomerUserId");
  2087. CeErpTradeCell entity = null;
  2088. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2089. if (entity != null)
  2090. {
  2091. //string[] mlist = entity.seller_memo.Split('-');
  2092. //string sql = "select * from view_erpuser where id=" + userid;
  2093. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2094. //if (dt != null && dt.Rows.Count > 0)
  2095. //{
  2096. // string nmemo = "";
  2097. // for(int i = 0; i < mlist.Length - 1; i++)
  2098. // {
  2099. // nmemo += mlist[i];
  2100. // nmemo += "-";
  2101. // }
  2102. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2103. // entity.seller_memo = nmemo;
  2104. //}
  2105. entity.CustomerUserId = userid;
  2106. entity.Update();
  2107. returnSuccessMsg("操作成功!");
  2108. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2109. return;
  2110. }
  2111. returnErrorMsg("找不到记录");
  2112. }
  2113. }
  2114. public void upd_erp_transdesigner()
  2115. {
  2116. if (UrlPostParmsCheck("ctid"))
  2117. {
  2118. string eids = GetPostString("ctid");
  2119. string[] ctidList = eids.Split(',');
  2120. int userid = GetPostInt("DesignUserId");
  2121. foreach (string ctid in ctidList)
  2122. {
  2123. CeErpTradeCell entity = null;
  2124. CeErpDesignerBill entitys = null;
  2125. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2126. entitys = CeErpDesignerBill.GetByTid(ctid);
  2127. if (entity != null)
  2128. {
  2129. if (entity.OrderState > 4)
  2130. {
  2131. continue;
  2132. }
  2133. //存在退款不能流转
  2134. if (entity.IsRefund > 0)
  2135. {
  2136. continue;
  2137. }
  2138. entity.DesignUserId = userid;
  2139. entity.WaitDesignTime = DateTime.Now;
  2140. entity.Update();
  2141. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2142. }
  2143. }
  2144. returnSuccessMsg("操作成功!");
  2145. }
  2146. }
  2147. public void upd_erp_distributedesigner()
  2148. {
  2149. if (UrlPostParmsCheck("ctid"))
  2150. {
  2151. string eid = GetPostString("ctid");
  2152. int userid = GetPostInt("DesignUserId");
  2153. string[] idlist = eid.Split(',');
  2154. if (idlist.Length <= 0)
  2155. {
  2156. returnErrorMsg("订单不能为空");
  2157. return;
  2158. }
  2159. foreach (string ctid in idlist)
  2160. {
  2161. CeErpTradeCell entity = null;
  2162. CeErpDesignerBill entitys = null;
  2163. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2164. else continue;
  2165. if (entity != null)
  2166. {
  2167. if (userid == 2125 || userid == 3542)
  2168. { }
  2169. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2170. {
  2171. returnErrorMsg("金额错误的订单无法指派");
  2172. return;
  2173. }
  2174. if (entity.OrderState >= 5)
  2175. {
  2176. returnErrorMsg("已经设计完成无法指派");
  2177. return;
  2178. }
  2179. if (entity.OrderState == -1)
  2180. {
  2181. returnErrorMsg("审核中的订单无法指派");
  2182. return;
  2183. }
  2184. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2185. {
  2186. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2187. return;
  2188. }
  2189. //157赖橙帆 159林晨 73 静之颖
  2190. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && CurrentUser.UserID != 157 && CurrentUser.UserID != 159 && CurrentUser.UserID != 1479 && CurrentUser.UserID != 73)
  2191. {
  2192. returnErrorMsg("指派设计共创无法再次指派!");
  2193. return;
  2194. }
  2195. entity.OrderState = 3;
  2196. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  2197. if (entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  2198. {
  2199. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2200. entity.SupplierId = suid;
  2201. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2202. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2203. }
  2204. if (userid == 2125 && entity.seller_memo != "")
  2205. {
  2206. apiDesign.API_GetPrintData_CreateOrder(entity);
  2207. }
  2208. if (userid == 3542 && entity.seller_memo != "")
  2209. {
  2210. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, CurrentUser.UserPost.Post.Code);
  2211. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2212. if (response.msg != "设计共创:成功")
  2213. {
  2214. returnErrorMsg(response.msg);
  2215. return;
  2216. }
  2217. entity.DispatchSort = 2;
  2218. }
  2219. else
  2220. {
  2221. if (entity.DispatchSort == 2)
  2222. {
  2223. ApiVo apiVo = new ApiVo();
  2224. apiVo.actionName = "closeDesign";
  2225. apiVo.orderNumber = entity.ctid;
  2226. designHelper.API_WorkCore(apiVo);//closeDesign
  2227. }
  2228. entity.DispatchSort = 0;
  2229. }
  2230. entity.DesignUserId = userid;
  2231. entity.WaitDesignTime = DateTime.Now;
  2232. entity.UpdateTime = DateTime.Now;
  2233. entity.Update();
  2234. string name = commonHelper.getUserNameById(userid);
  2235. commonHelper.UpdateRelationOrder(entity.ctid);
  2236. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2237. }
  2238. }
  2239. returnSuccessMsg("操作成功!");
  2240. return;
  2241. }
  2242. }
  2243. public string getTidByCtid(string ctid)
  2244. {
  2245. string tid = "";
  2246. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2247. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2248. if (dataTable != null && dataTable.Rows.Count > 0)
  2249. {
  2250. tid = dataTable.Rows[0]["tid"].ToString();
  2251. }
  2252. return tid;
  2253. }
  2254. public List<string> getTidByCtidLike(string ctid)
  2255. {
  2256. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2257. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2258. List<string> list = new List<string>();
  2259. if (dataTable != null && dataTable.Rows.Count > 0)
  2260. {
  2261. foreach (DataRow item in dataTable.Rows)
  2262. {
  2263. list.Add("'" + item["tid"].ToString() + "'");
  2264. }
  2265. }
  2266. return list;
  2267. }
  2268. public void get_erp_myorderlist()
  2269. {
  2270. DataStruct dStruct = GetPostStruct();
  2271. List<string> lw = new List<string>();
  2272. string tid = GetPostString("ctid");
  2273. if (tid.Length > 0)
  2274. {
  2275. string select_tid = getTidByCtid(tid);
  2276. lw.Add(string.Format("tid='{0}'", select_tid));
  2277. }
  2278. else
  2279. {
  2280. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2281. }
  2282. //12-1 修改
  2283. string urgent = GetPostString("urgent");
  2284. string back = GetPostString("back");
  2285. string offlineSearch = GetPostString("offlineSearch");
  2286. if (!string.IsNullOrWhiteSpace(urgent))
  2287. {
  2288. if (urgent.Equals("true"))
  2289. {
  2290. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2291. }
  2292. }
  2293. if (!string.IsNullOrWhiteSpace(back))
  2294. {
  2295. if (back.Equals("true"))
  2296. {
  2297. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2298. }
  2299. }
  2300. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2301. {
  2302. if (offlineSearch.Equals("true"))
  2303. {
  2304. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2305. }
  2306. }
  2307. //end
  2308. string shopname = GetPostString("shopname");
  2309. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2310. string buyernick = GetPostString("buyer_nick");
  2311. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2312. string design = GetPostString("design");
  2313. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2314. string orderState = GetPostString("orderState");
  2315. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2316. string sellermemo = GetPostString("seller_memo");
  2317. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2318. string date1 = GetPostString("date1");
  2319. string date2 = GetPostString("date2");
  2320. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2321. if (dw.Length > 0) lw.Add(dw);
  2322. string price1 = GetPostString("price1");
  2323. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2324. string price2 = GetPostString("price2");
  2325. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2326. string urgency = GetPostString("urgency");
  2327. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2328. string after = GetPostString("after");
  2329. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2330. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2331. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2332. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2333. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2334. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2335. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2336. if (dt != null && dt.Rows.Count > 0)
  2337. {
  2338. foreach (DataRow dr in dt.Rows)
  2339. {
  2340. try
  2341. {
  2342. // 对象操作
  2343. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2344. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2345. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2346. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2347. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2348. if (dStruct.PageSize != 100000)
  2349. {
  2350. if (dr["DispatchSort"].ToString() == "2")
  2351. {
  2352. dr["gongchuang"] = 200;
  2353. }
  2354. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2355. {
  2356. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2357. dr["gongchuang"] = response.code;
  2358. }
  2359. }
  2360. }
  2361. catch (NullReferenceException ex)
  2362. {
  2363. }
  2364. }
  2365. }
  2366. writeGridDataTableJson(dStruct.TotalCount, dt);
  2367. }
  2368. public void get_erp_myreturnorderlist()
  2369. {
  2370. DataStruct dStruct = GetPostStruct();
  2371. List<string> lw = new List<string>();
  2372. string tid = GetPostString("ctid");
  2373. if (tid.Length > 0)
  2374. {
  2375. string select_tid = getTidByCtid(tid);
  2376. lw.Add(string.Format("tid='{0}'", select_tid));
  2377. }
  2378. else
  2379. {
  2380. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2381. }
  2382. string shopname = GetPostString("shopname");
  2383. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2384. string buyernick = GetPostString("buyer_nick");
  2385. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2386. string design = GetPostString("design");
  2387. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2388. string orderState = GetPostString("orderState");
  2389. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2390. string sellermemo = GetPostString("seller_memo");
  2391. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2392. string date1 = GetPostString("date1");
  2393. string date2 = GetPostString("date2");
  2394. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2395. if (dw.Length > 0) lw.Add(dw);
  2396. string price1 = GetPostString("price1");
  2397. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2398. string price2 = GetPostString("price2");
  2399. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2400. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2401. {
  2402. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2403. }
  2404. else
  2405. {
  2406. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2407. }
  2408. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2409. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2410. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2411. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2412. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2413. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2414. if (dt != null && dt.Rows.Count > 0)
  2415. {
  2416. foreach (DataRow dr in dt.Rows)
  2417. {
  2418. try
  2419. {
  2420. // 对象操作
  2421. if (dStruct.PageSize != 100000)
  2422. {
  2423. if (dr["DispatchSort"].ToString() == "2")
  2424. {
  2425. dr["gongchuang"] = 200;
  2426. }
  2427. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2428. {
  2429. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2430. dr["gongchuang"] = response.code;
  2431. }
  2432. }
  2433. }
  2434. catch (NullReferenceException ex)
  2435. {
  2436. // 处理空引用异常
  2437. }
  2438. }
  2439. }
  2440. writeGridDataTableJson(dStruct.TotalCount, dt);
  2441. }
  2442. public void get_erp_myorderlist_pregather()
  2443. {
  2444. string date1 = GetPostString("date1");
  2445. string date2 = GetPostString("date2");
  2446. int userId = CurrentUser.UserID; //客服id
  2447. string orderWhere = "";
  2448. List<string> lw = new List<string>();
  2449. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2450. if (dw.Length > 0) lw.Add(dw);
  2451. lw.Add(string.Format("CustomerUserId={0}", userId));
  2452. lw.Add(string.Format("OrderState<9"));
  2453. orderWhere = string.Join(" and ", lw.ToArray());
  2454. string orderWhere2 = "";
  2455. List<string> lw2 = new List<string>();
  2456. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2457. if (dw2.Length > 0) lw2.Add(dw2);
  2458. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2459. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2460. string sql = string.Format("select *" +
  2461. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2462. "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 " +
  2463. "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 " +
  2464. "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");
  2465. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2466. //writeGridDataTableJson(dt.Rows.Count, dt);
  2467. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2468. }
  2469. public void upd_erp_publishorder()
  2470. {
  2471. if (UrlPostParmsCheck("ctid"))
  2472. {
  2473. string eid = GetPostString("ctid");
  2474. CeErpTradeCell entity = null;
  2475. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2476. if (entity != null)
  2477. {
  2478. entity.OrderState = 0; //发布后,变为待抢单
  2479. entity.Update();
  2480. commonHelper.UpdateRelationOrder(entity.ctid);
  2481. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2482. returnSuccessMsg("发布成功!");
  2483. return;
  2484. }
  2485. returnErrorMsg("找不到记录");
  2486. }
  2487. }
  2488. public void get_erp_my_tiporder()
  2489. {
  2490. StringBuilder sql = new StringBuilder();
  2491. int userId = 0;
  2492. if (CurrentUser != null) userId = CurrentUser.UserID;
  2493. string posCode = CurrentUser.UserPost.Post.Code;
  2494. string isTipedAfterSaleVerify = GetPostString("af");
  2495. DataTable dt = new DataTable();
  2496. if (posCode != "Supplier")
  2497. {
  2498. if (posCode == "CustomerService" || posCode == "Director")
  2499. {
  2500. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2501. }
  2502. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2503. {
  2504. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2505. }
  2506. else
  2507. {
  2508. string teamIds = CurrentUser.User.TeamIds;
  2509. if (teamIds == "")
  2510. {
  2511. teamIds = "0";
  2512. }
  2513. 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);
  2514. }
  2515. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2516. }
  2517. if (dt.Rows.Count <= 0)
  2518. {
  2519. string key = "aftersale_order_" + userId;
  2520. if (RedisHelper.HasKey(key))
  2521. {
  2522. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2523. dt.Columns.Add("ctid", typeof(string));
  2524. dt.Columns.Add("IsReadTag", typeof(int));
  2525. foreach (var i in list)
  2526. {
  2527. DataRow data = dt.NewRow();
  2528. data["ctid"] = i;
  2529. data["IsReadTag"] = 4;
  2530. dt.Rows.Add(data);
  2531. }
  2532. RedisHelper.StringDelete(key);
  2533. }
  2534. }
  2535. if (dt.Rows.Count <= 0)
  2536. {
  2537. sql = new StringBuilder();
  2538. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2539. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2540. }
  2541. if (posCode == "Supplier")
  2542. {
  2543. string ids = CurrentUser.User.pemVend;
  2544. if (ids != null && ids.Length > 0)
  2545. {
  2546. string[] ids_list = ids.Split(',');
  2547. foreach (var item in ids_list)
  2548. {
  2549. string key = "return_order_" + item;
  2550. if (RedisHelper.HasKey(key))
  2551. {
  2552. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2553. dt.Columns.Add("ctid", typeof(string));
  2554. dt.Columns.Add("IsReadTag", typeof(int));
  2555. foreach (var i in list)
  2556. {
  2557. DataRow data = dt.NewRow();
  2558. data["ctid"] = i;
  2559. data["IsReadTag"] = 1;
  2560. dt.Rows.Add(data);
  2561. }
  2562. RedisHelper.StringDelete(key);
  2563. }
  2564. }
  2565. }
  2566. if (dt.Rows.Count <= 0)
  2567. {
  2568. sql = new StringBuilder();
  2569. 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);
  2570. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2571. }
  2572. }
  2573. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2574. }
  2575. public void reset_erp_tiporder()
  2576. {
  2577. string ids = GetPostString("ids");
  2578. string[] ctidList = ids.Split(',');
  2579. foreach (string ctid in ctidList)
  2580. {
  2581. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2582. if (enty != null)
  2583. {
  2584. enty.IsReadTag = 0;
  2585. enty.Update();
  2586. }
  2587. }
  2588. returnSuccessMsg("成功!");
  2589. return;
  2590. }
  2591. public void get_erp_designlist()
  2592. {
  2593. DataStruct dStruct = GetPostStruct();
  2594. List<string> lw = new List<string>();
  2595. string tid = GetPostString("ctid");
  2596. if (tid.Length > 0)
  2597. {
  2598. string select_tid = getTidByCtid(tid);
  2599. lw.Add(string.Format("tid='{0}'", select_tid));
  2600. }
  2601. string shopname = GetPostString("shopname");
  2602. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2603. string buyernick = GetPostString("buyer_nick");
  2604. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2605. string customer = GetPostString("customer");
  2606. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2607. string design = GetPostString("design");
  2608. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2609. string orderState = GetPostString("orderState");
  2610. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2611. lw.Add(string.Format("OrderState<6"));
  2612. string address = GetPostString("address");
  2613. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2614. string sellermemo = GetPostString("seller_memo");
  2615. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2616. string date1 = GetPostString("date1");
  2617. string date2 = GetPostString("date2");
  2618. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2619. if (dw.Length > 0) lw.Add(dw);
  2620. string apdate1 = GetPostString("apdate1");
  2621. string apdate2 = GetPostString("apdate2");
  2622. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2623. if (dwap.Length > 0) lw.Add(dwap);
  2624. string price1 = GetPostString("price1");
  2625. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2626. string price2 = GetPostString("price2");
  2627. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2628. string designTime = GetPostString("designtime");
  2629. if (designTime.Length > 0)
  2630. {
  2631. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2632. }
  2633. string usershop = CurrentUser.User.pemShop;
  2634. if (usershop.Length > 0)
  2635. {
  2636. lw.Add(string.Format("shopId in ({0})", usershop));
  2637. }
  2638. int myOrgid = CurrentUser.UserPost.OrgID;
  2639. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2640. if (myOrgCode.IndexOf("Designer") != -1)
  2641. {
  2642. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2643. {
  2644. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2645. }
  2646. else
  2647. {
  2648. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2649. }
  2650. }
  2651. else
  2652. {
  2653. string orgId = GetPostString("designerhd");
  2654. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2655. }
  2656. if (tid.Length > 0 || buyernick.Length > 0)
  2657. {
  2658. lw.Add(string.Format("OrderState >= 3"));
  2659. }
  2660. else
  2661. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2662. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2663. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2664. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2665. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2666. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2667. if (dt != null && dt.Rows.Count > 0)
  2668. {
  2669. foreach (DataRow dr in dt.Rows)
  2670. {
  2671. try
  2672. {
  2673. // 对象操作
  2674. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2675. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2676. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2677. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2678. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2679. if (dStruct.PageSize != 100000)
  2680. {
  2681. if (dr["DispatchSort"].ToString() == "2")
  2682. {
  2683. dr["gongchuang"] = 200;
  2684. }
  2685. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2686. {
  2687. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2688. dr["gongchuang"] = response.code;
  2689. }
  2690. }
  2691. }
  2692. catch (NullReferenceException ex)
  2693. {
  2694. }
  2695. }
  2696. }
  2697. writeGridDataTableJson(dStruct.TotalCount, dt);
  2698. }
  2699. public void get_erp_mydesignlist()
  2700. {
  2701. DataStruct dStruct = GetPostStruct();
  2702. List<string> lw = new List<string>();
  2703. string tid = GetPostString("ctid");
  2704. if (tid.Length > 0)
  2705. {
  2706. string select_tid = getTidByCtid(tid);
  2707. lw.Add(string.Format("tid='{0}'", select_tid));
  2708. }
  2709. string shopname = GetPostString("shopname");
  2710. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2711. string buyernick = GetPostString("buyer_nick");
  2712. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2713. string customer = GetPostString("customer");
  2714. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2715. string orderState = GetPostString("orderState");
  2716. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2717. //lw.Add(string.Format("OrderState<6"));
  2718. string date1 = GetPostString("date1");
  2719. string date2 = GetPostString("date2");
  2720. string dw = GetDateWhere("pay_time", date1, date2);
  2721. if (dw.Length > 0) lw.Add(dw);
  2722. string apdate1 = GetPostString("apdate1");
  2723. string apdate2 = GetPostString("apdate2");
  2724. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2725. if (dwap.Length > 0) lw.Add(dwap);
  2726. string price1 = GetPostString("price1");
  2727. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2728. string price2 = GetPostString("price2");
  2729. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2730. string olddownload = GetPostString("olddown");
  2731. if (olddownload == "1")
  2732. {
  2733. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2734. }
  2735. else if (olddownload == "2")
  2736. {
  2737. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2738. }
  2739. string sellermemo = GetPostString("seller_memo");
  2740. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2741. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2742. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2743. {
  2744. if (CurrentUser.User.TeamIds.Length > 0)
  2745. {
  2746. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2747. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2748. else
  2749. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2750. }
  2751. else
  2752. {
  2753. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2754. }
  2755. }
  2756. if (tid.Length <= 0)
  2757. {
  2758. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2759. }
  2760. lw.Add(string.Format("IsReturn!=3"));
  2761. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2762. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2763. string teamids = CurrentUser.User.TeamIds.ToString();
  2764. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2765. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2766. if (dt != null && dt.Rows.Count > 0)
  2767. {
  2768. foreach (DataRow dr in dt.Rows)
  2769. {
  2770. try
  2771. {
  2772. // 对象操作
  2773. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2774. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2775. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2776. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2777. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2778. if (dStruct.PageSize != 100000)
  2779. {
  2780. if (dr["DispatchSort"].ToString() == "2")
  2781. {
  2782. dr["gongchuang"] = 200;
  2783. }
  2784. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2785. {
  2786. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2787. dr["gongchuang"] = response.code;
  2788. }
  2789. }
  2790. }
  2791. catch (NullReferenceException ex)
  2792. {
  2793. }
  2794. }
  2795. }
  2796. writeGridDataTableJson(dStruct.TotalCount, dt);
  2797. }
  2798. public void set_erp_startdesign()
  2799. {
  2800. if (UrlPostParmsCheck("ctid"))
  2801. {
  2802. string eid = GetPostString("ctid");
  2803. CeErpTradeCell entity = null;
  2804. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2805. if (entity != null)
  2806. {
  2807. if (entity.OrderState != 3)
  2808. {
  2809. returnErrorMsg("请刷新,订单已经设计了");
  2810. return;
  2811. }
  2812. entity.StartDesignTime = DateTime.Now;
  2813. entity.OrderState = 4;
  2814. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2815. {
  2816. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2817. entity.SupplierId = suid;
  2818. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2819. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2820. }
  2821. entity.UpdateTime = DateTime.Now;
  2822. //entity.MakeSupplier = suname;
  2823. entity.Update();
  2824. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2825. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2826. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2827. commonHelper.getCytPrice(entity);
  2828. returnSuccessMsg("操作成功!");
  2829. return;
  2830. }
  2831. returnErrorMsg("找不到记录");
  2832. }
  2833. }
  2834. public void ins_erp_designselfmemo()
  2835. {
  2836. if (UrlPostParmsCheck("ctid"))
  2837. {
  2838. string eid = GetPostString("ctid");
  2839. string con = GetPostString("con");
  2840. CeErpTradeCell entity = null;
  2841. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2842. if (entity != null)
  2843. {
  2844. entity.DesignSelfMemo = con;
  2845. entity.Update();
  2846. returnSuccessMsg("操作成功!");
  2847. return;
  2848. }
  2849. returnErrorMsg("找不到记录");
  2850. }
  2851. }
  2852. public void ins_erp_designprice()
  2853. {
  2854. if (UrlPostParmsCheck("ctid"))
  2855. {
  2856. string eid = GetPostString("ctid");
  2857. int uid = CurrentUser.UserID;
  2858. string userName = CurrentUser.UserName;
  2859. CeErpTradeCell entity = null;
  2860. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2861. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2862. if (entitys == null)
  2863. {
  2864. entitys = new CeErpDesignerBill();
  2865. }
  2866. if (entity != null)
  2867. {
  2868. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2869. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2870. entity.StartDesignTime = DateTime.Now;
  2871. entity.OrderState = 4;
  2872. string suname = "";
  2873. if (entity.SupplierId == 0)
  2874. {
  2875. int sid = commonHelper.autoDistributeToSupplier(entity);
  2876. entity.SupplierId = sid;
  2877. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2878. }
  2879. entity.Update();
  2880. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2881. if (ceErpUserPost != null)
  2882. {
  2883. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2884. if (ceErpPost != null)
  2885. {
  2886. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2887. {
  2888. entitys.tid = entity.ctid;
  2889. entitys.oid = entity.tid;
  2890. entitys.uid = uid;
  2891. entitys.userName = userName;
  2892. entitys.designerType = 1;
  2893. entitys.designerTypeText = "内部设计师";
  2894. entitys.price = Convert.ToDouble(GetPostString("price"));
  2895. entitys.designNum = GetPostInt("designNum");
  2896. entitys.modifyNum = GetPostInt("modifyNum");
  2897. entitys.designSize = GetPostString("designSize");
  2898. entitys.modifySize = GetPostString("modifySize");
  2899. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2900. {
  2901. entitys.create_time = DateTime.Now;
  2902. entitys.create_u_id = uid;
  2903. entitys.create_u_name = userName;
  2904. entitys.Save();
  2905. }
  2906. else
  2907. {
  2908. entitys.update_time = DateTime.Now;
  2909. entitys.update_u_id = uid;
  2910. entitys.update_u_name = userName;
  2911. entitys.Update();
  2912. }
  2913. }
  2914. }
  2915. }
  2916. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2917. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2918. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2919. if (suname != "")
  2920. {
  2921. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2922. }
  2923. commonHelper.getCytPrice(entity);
  2924. returnSuccessMsg("操作成功!");
  2925. return;
  2926. }
  2927. returnErrorMsg("找不到记录");
  2928. }
  2929. }
  2930. public void upload_erp_filecomplete()
  2931. {
  2932. if (UrlPostParmsCheck("ctid"))
  2933. {
  2934. string eid = GetPostString("ctid");
  2935. CeErpTradeCell entity = null;
  2936. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2937. if (entity != null)
  2938. {
  2939. entity.OrderState = 5; //设计完成
  2940. entity.Update();
  2941. returnSuccessMsg(eid + "上传成功,设计完成!");
  2942. return;
  2943. }
  2944. returnErrorMsg("找不到订单记录");
  2945. }
  2946. }
  2947. public void get_erp_designovertimelist()
  2948. {
  2949. DataStruct dStruct = GetPostStruct();
  2950. List<string> lw = new List<string>();
  2951. string tid = GetPostString("ctid");
  2952. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  2953. string shopname = GetPostString("shopname");
  2954. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2955. string buyernick = GetPostString("buyer_nick");
  2956. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2957. string ResponsibleMan = GetPostString("responsible");
  2958. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2959. string date1 = GetPostString("date1");
  2960. string date2 = GetPostString("date2");
  2961. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2962. if (dw.Length > 0) lw.Add(dw);
  2963. string price1 = GetPostString("price1");
  2964. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2965. string price2 = GetPostString("price2");
  2966. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2967. string orderState = GetPostString("orderState");
  2968. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2969. string sellermemo = GetPostString("seller_memo");
  2970. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2971. lw.Add(string.Format("UnusualTag=3"));
  2972. lw.Add(string.Format("IsRefund<={0}", 1));
  2973. dStruct.Order = "WaitDesignTime desc";
  2974. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2975. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2976. writeGridDataTableJson(dStruct.TotalCount, dt);
  2977. }
  2978. //设计管理 获取抢单大厅列表
  2979. public void get_erp_grabinglist()
  2980. {
  2981. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  2982. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  2983. bool oldOrder = false;
  2984. if (org != null)
  2985. {
  2986. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  2987. }
  2988. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  2989. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  2990. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2991. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  2992. //先处理订单数据
  2993. if (dt.Rows.Count > 0)
  2994. {
  2995. Dictionary<string, int> design = null;
  2996. int count = 0;
  2997. foreach (DataRow row in dt.Rows)
  2998. {
  2999. if (map.ContainsKey(row["ShopId"].ToString()))
  3000. {
  3001. map.TryGetValue(row["ShopId"].ToString(), out design);
  3002. }
  3003. else
  3004. {
  3005. design = new Dictionary<string, int>();
  3006. }
  3007. if (design.ContainsKey(row["ProductId"].ToString()))
  3008. {
  3009. design.TryGetValue(row["ProductId"].ToString(), out count);
  3010. }
  3011. count++;
  3012. design[row["ProductId"].ToString()] = count;
  3013. map[row["ShopId"].ToString()] = design;
  3014. }
  3015. }
  3016. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3017. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3018. //把店铺排序和技能排序分类
  3019. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3020. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3021. if (design_dt.Rows.Count > 0)
  3022. {
  3023. Dictionary<string, string> design = null;
  3024. List<string> shopIds = null;
  3025. foreach (DataRow row in design_dt.Rows)
  3026. {
  3027. if ("0".Equals(row["designId"].ToString()))
  3028. {
  3029. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3030. {
  3031. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3032. }
  3033. else
  3034. {
  3035. shopIds = new List<string>();
  3036. }
  3037. shopIds.Add(row["shopId"].ToString());
  3038. shop_orders[row["orders"].ToString()] = shopIds;
  3039. }
  3040. else
  3041. {
  3042. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3043. {
  3044. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3045. }
  3046. else
  3047. {
  3048. design = new Dictionary<string, string>();
  3049. }
  3050. design[row["orders"].ToString()] = row["designId"].ToString();
  3051. design_orders[row["shopId"].ToString()] = design;
  3052. }
  3053. }
  3054. //处理成key value后根据key排序
  3055. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3056. foreach (List<string> val in shop_orders.Values)
  3057. {
  3058. if (val != null)
  3059. {
  3060. foreach (string key in val)
  3061. {
  3062. if (design_orders.ContainsKey(key.ToString()))
  3063. {
  3064. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. //校验哪个优先级有订单
  3071. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3072. foreach (string key in shop_orders.Keys)
  3073. {
  3074. List<string> ids = null;
  3075. shop_orders.TryGetValue(key, out ids);
  3076. //id为shopid
  3077. foreach (string id in ids)
  3078. {
  3079. Dictionary<string, int> list = null;
  3080. Dictionary<string, string> desing = null;
  3081. map.TryGetValue(id, out list);
  3082. design_orders.TryGetValue(id, out desing);
  3083. if (list != null && desing != null)
  3084. {
  3085. foreach (var item in desing)
  3086. {
  3087. int count = 0;
  3088. if (list.ContainsKey(item.Value))
  3089. {
  3090. list.TryGetValue(item.Value, out count);
  3091. if (count > 0)
  3092. {
  3093. designIds[id] = item.Value;
  3094. break;
  3095. }
  3096. }
  3097. }
  3098. }
  3099. }
  3100. if (designIds.Count > 0)
  3101. {
  3102. break;
  3103. }
  3104. }
  3105. DataTable table = new DataTable();
  3106. table.Columns.Add("tid", typeof(string));
  3107. table.Columns.Add("ctid", typeof(string));
  3108. table.Columns.Add("seller_nick", typeof(string));
  3109. table.Columns.Add("productName", typeof(string));
  3110. table.Columns.Add("pay_time", typeof(string));
  3111. table.Columns.Add("seller_memo", typeof(string));
  3112. if (designIds.Count > 0)
  3113. {
  3114. string shopId = "";
  3115. string productId = "";
  3116. foreach (var designInfo in designIds)
  3117. {
  3118. shopId = designInfo.Key;
  3119. productId = designInfo.Value;
  3120. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3121. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3122. if (dt.Rows.Count > 0)
  3123. {
  3124. foreach (DataRow row in dt.Rows)
  3125. {
  3126. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3127. {
  3128. DataRow data = table.NewRow();
  3129. data["ctid"] = row["ctid"].ToString();
  3130. data["tid"] = row["tid"].ToString();
  3131. data["seller_nick"] = ceErpShop.ShopName;
  3132. data["pay_time"] = row["pay_time"].ToString();
  3133. data["seller_memo"] = row["seller_memo"].ToString();
  3134. data["productName"] = ceErpProduct.PType;
  3135. table.Rows.Add(data);
  3136. }
  3137. }
  3138. }
  3139. }
  3140. }
  3141. writeGridDataTableJson(table.Rows.Count, table);
  3142. }
  3143. private object rushLockObject = new object();
  3144. public void set_erp_grabingorder()
  3145. {
  3146. if (UrlPostParmsCheck("ctid"))
  3147. {
  3148. int total = CurrentUser.User.Person.Total;
  3149. int userId = CurrentUser.User.ID;
  3150. int noFinish = CurrentUser.User.Person.NoFinish;
  3151. int finalization = CurrentUser.User.Person.Finalization;
  3152. string eids = GetPostString("ctid");
  3153. string key = "RushKey_" + userId;
  3154. int count = 0;
  3155. if (erpRedis.RedisHelper.KeyExists(key))
  3156. {
  3157. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3158. if (redisCount != null)
  3159. {
  3160. count = Convert.ToInt32(redisCount);
  3161. }
  3162. }
  3163. if (count >= total)
  3164. {
  3165. returnErrorMsg("半小时内已经抢" + total + "单");
  3166. return;
  3167. }
  3168. string[] ctidlist = eids.Split(',');
  3169. if (count + ctidlist.Length > total)
  3170. {
  3171. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3172. return;
  3173. }
  3174. int itag = 0;
  3175. lock (rushLockObject)
  3176. {
  3177. if (ctidlist.Length > 0)
  3178. {
  3179. string[] dtList = new string[ctidlist.Length];
  3180. for (int i = 0; i < ctidlist.Length; i++)
  3181. {
  3182. dtList[i] = "'" + ctidlist[i] + "'";
  3183. }
  3184. 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"));
  3185. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3186. if (dt_user.Rows.Count > 0)
  3187. {
  3188. int doing = 0;//未定稿
  3189. int finish = 0;//已完成
  3190. foreach (DataRow dr in dt_user.Rows)
  3191. {
  3192. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3193. {
  3194. doing++;
  3195. }
  3196. else
  3197. {
  3198. finish++;
  3199. }
  3200. }
  3201. if (doing >= noFinish)
  3202. {
  3203. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3204. return;
  3205. }
  3206. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3207. {
  3208. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3209. return;
  3210. }
  3211. }
  3212. //校验选择单子状态
  3213. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3214. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3215. if (dt.Rows.Count > 0)
  3216. {
  3217. List<string> list = new List<string>();
  3218. foreach (DataRow dr in dt.Rows)
  3219. {
  3220. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3221. {
  3222. list.Add(dr["ctid"].ToString());
  3223. }
  3224. }
  3225. if (list.Count > 0)
  3226. {
  3227. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3228. return;
  3229. }
  3230. }
  3231. foreach (string ctid in ctidlist)
  3232. {
  3233. CeErpTradeCell entity = null;
  3234. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3235. if (entity != null)
  3236. {
  3237. entity.OrderState = 3;
  3238. entity.DesignUserId = CurrentUser.UserID;
  3239. entity.WaitDesignTime = DateTime.Now;
  3240. entity.StartDesignTime = DateTime.Now;
  3241. entity.Update();
  3242. commonHelper.UpdateRelationOrder(entity.ctid);
  3243. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3244. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3245. itag++;
  3246. }
  3247. }
  3248. }
  3249. }
  3250. count += ctidlist.Length;
  3251. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3252. if (itag == 0)
  3253. returnErrorMsg("没有找到相关订单");
  3254. else
  3255. returnSuccessMsg("抢单成功!");
  3256. return;
  3257. }
  3258. }
  3259. public void get_erp_waitorderlist()
  3260. {
  3261. DataStruct dStruct = GetPostStruct();
  3262. List<string> lw = new List<string>();
  3263. string tid = GetPostString("ctid");
  3264. if (tid.Length > 0)
  3265. {
  3266. string select_tid = getTidByCtid(tid);
  3267. lw.Add(string.Format("tid='{0}'", select_tid));
  3268. }
  3269. string shopname = GetPostString("shopname");
  3270. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3271. string buyernick = GetPostString("buyer_nick");
  3272. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3273. string customer = GetPostString("customer");
  3274. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3275. string design = GetPostString("design");
  3276. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3277. string orderState = GetPostString("orderState");
  3278. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3279. string supplier = GetPostString("supplier");
  3280. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3281. string sellermemo = GetPostString("seller_memo");
  3282. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3283. string otherMemo = GetPostString("otherMemo");
  3284. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3285. string address = GetPostString("address");
  3286. 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));
  3287. string date1 = GetPostString("date1");
  3288. string date2 = GetPostString("date2");
  3289. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3290. if (dw.Length > 0) lw.Add(dw);
  3291. string price1 = GetPostString("price1");
  3292. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3293. string price2 = GetPostString("price2");
  3294. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3295. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3296. lw.Add(string.Format("IsSample != 2 "));
  3297. lw.Add(string.Format("OrderState = 5 "));
  3298. lw.Add(string.Format("IsRefund<={0}", 1));
  3299. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3300. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3301. string pagesize = GetPostString("pagesize");
  3302. if (pagesize != null)
  3303. {
  3304. dStruct.PageSize = 200;
  3305. }
  3306. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3307. if (dt != null)
  3308. {
  3309. foreach (DataRow dr in dt.Rows)
  3310. {
  3311. 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();
  3312. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3313. {
  3314. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3315. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3316. entity.SupplierId = suid;
  3317. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3318. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3319. entity.Update();
  3320. }
  3321. }
  3322. }
  3323. writeGridDataTableJson(dStruct.TotalCount, dt);
  3324. }
  3325. public void get_erp_supplierwaitorderlist()
  3326. {
  3327. DataStruct dStruct = GetPostStruct();
  3328. List<string> lw = new List<string>();
  3329. string tid = GetPostString("ctid");
  3330. if (tid.Length > 0)
  3331. {
  3332. string select_tid = getTidByCtid(tid);
  3333. lw.Add(string.Format("tid='{0}'", select_tid));
  3334. }
  3335. string shopname = GetPostString("shopname");
  3336. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3337. string sellermemo = GetPostString("seller_memo");
  3338. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3339. string date1 = GetPostString("date1");
  3340. string date2 = GetPostString("date2");
  3341. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3342. if (dw.Length > 0) lw.Add(dw);
  3343. lw.Add(string.Format("OrderState = 5 "));
  3344. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3345. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3346. {
  3347. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3348. }
  3349. string supplier = GetPostString("supplier");
  3350. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3351. {
  3352. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3353. }
  3354. lw.Add(string.Format("IsRefund<={0}", 1));
  3355. dStruct.Order = "FinishDesignTime desc";
  3356. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3357. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3358. if (dt != null)
  3359. {
  3360. foreach (DataRow dr in dt.Rows)
  3361. {
  3362. 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();
  3363. }
  3364. }
  3365. writeGridDataTableJson(dStruct.TotalCount, dt);
  3366. }
  3367. public void upd_erp_verifytosupplier()
  3368. {
  3369. if (UrlPostParmsCheck("ctid"))
  3370. {
  3371. string eids = GetPostString("ctid");
  3372. CeErpTradeCell entity = null;
  3373. string[] eidsList = eids.Split(',');
  3374. if (eidsList.Length <= 0)
  3375. {
  3376. returnErrorMsg("订单号不能空");
  3377. return;
  3378. }
  3379. List<string> tLst = new List<string>();
  3380. foreach (string ctidstr in eidsList)
  3381. {
  3382. tLst.Add("'" + ctidstr + "'");
  3383. CeErpDataSendOrderInfo.createObject(ctidstr);
  3384. }
  3385. string needtids = string.Join(",", tLst.ToArray());
  3386. StringBuilder sql = new StringBuilder();
  3387. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3388. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3389. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3390. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3391. returnSuccessMsg("操作成功!");
  3392. return;
  3393. /**foreach (string ctidstr in eidsList)
  3394. {
  3395. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3396. if (entity != null)
  3397. {
  3398. if (entity.SupplierId == 0)
  3399. {
  3400. continue;
  3401. }
  3402. entity.IsVerifyToSupplier = true;
  3403. if (entity.IsReturn == 1) //1是供应商打回
  3404. {
  3405. entity.IsReturn = 0;
  3406. }
  3407. entity.FinishPlaceTime = DateTime.Now;
  3408. entity.PlaceUserId = CurrentUser.UserID;
  3409. entity.Update();
  3410. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3411. }
  3412. }
  3413. returnSuccessMsg("操作成功!");
  3414. return;**/
  3415. }
  3416. }
  3417. public void upd_erp_supplierback()
  3418. {
  3419. if (UrlPostParmsCheck("ctid"))
  3420. {
  3421. string eid = GetPostString("ctid");
  3422. string reason = GetPostString("returnreason");
  3423. CeErpTradeCell entity = null;
  3424. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3425. if (entity != null)
  3426. {
  3427. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3428. {
  3429. string key = "return_order_" + entity.SupplierId;
  3430. List<string> list = new List<string>();
  3431. if (RedisHelper.HasKey(key))
  3432. {
  3433. object data = RedisHelper.StringGet(key);
  3434. list = Convert.ToString(data).Split(',').ToList();
  3435. }
  3436. list.Add(eid);
  3437. RedisHelper.StringSet(key, string.Join(",", list));
  3438. }
  3439. entity.IsVerifyToSupplier = false;
  3440. entity.IsReturn = 1;
  3441. entity.ReturnTime = DateTime.Now;
  3442. entity.ReturnReason = reason;
  3443. if (entity.OrderState == 6)
  3444. {
  3445. entity.OrderState = 5;
  3446. }
  3447. entity.Update();
  3448. CeErpSukuraData.createInfo(entity.ctid, 5);
  3449. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3450. returnSuccessMsg("操作成功!");
  3451. return;
  3452. }
  3453. returnErrorMsg("找不到订单记录");
  3454. }
  3455. }
  3456. public void upd_erp_toaftersaleorder()
  3457. {
  3458. if (UrlPostParmsCheck("ctid"))
  3459. {
  3460. string eid = GetPostString("ctid");
  3461. string reason = GetPostString("returnreason");
  3462. CeErpTradeCell entity = null;
  3463. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3464. if (entity != null)
  3465. {
  3466. if (entity.isAfterSaleOrder != 1)
  3467. {
  3468. returnErrorMsg("带S的售后单才能打回给售后");
  3469. return;
  3470. }
  3471. if (entity.OrderState >= 5)
  3472. {
  3473. returnErrorMsg("已经设计完成了不能打回给售后");
  3474. return;
  3475. }
  3476. entity.OrderState = 0;
  3477. entity.IsReturn = 3;
  3478. entity.ReturnTime = DateTime.Now;
  3479. entity.UpdateTime = DateTime.Now;
  3480. entity.ReturnReason = reason;
  3481. entity.Update();
  3482. CeErpSukuraData.createInfo(entity.ctid, 5);
  3483. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3484. returnSuccessMsg("操作成功!");
  3485. return;
  3486. }
  3487. returnErrorMsg("找不到订单记录");
  3488. }
  3489. }
  3490. public void upd_erp_aftersaletodesign()
  3491. {
  3492. if (UrlPostParmsCheck("ctid"))
  3493. {
  3494. string eid = GetPostString("ctid");
  3495. CeErpTradeCell entity = null;
  3496. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3497. if (entity != null)
  3498. {
  3499. entity.OrderState = 3;
  3500. entity.IsReturn = 0;
  3501. entity.UpdateTime = DateTime.Now;
  3502. entity.Update();
  3503. CeErpSukuraData.createInfo(entity.ctid, 5);
  3504. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3505. returnSuccessMsg("操作成功!");
  3506. return;
  3507. }
  3508. returnErrorMsg("找不到订单记录");
  3509. }
  3510. }
  3511. public void assign_erp_supplier()
  3512. {
  3513. if (UrlPostParmsCheck("ctid"))
  3514. {
  3515. string eids = GetPostString("ctid");
  3516. int sid = GetPostInt("SupplierName");
  3517. string fromTag = GetPostString("tag");
  3518. string[] eidList = eids.Split(',');
  3519. if (eidList.Length <= 0)
  3520. {
  3521. returnErrorMsg("指派不能为空");
  3522. return;
  3523. }
  3524. string errMsg = "";
  3525. string suname = commonHelper.getSupplierNameById(sid);
  3526. foreach (string ctid in eidList)
  3527. {
  3528. CeErpTradeCell entity = null;
  3529. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3530. if (entity != null)
  3531. {
  3532. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3533. {
  3534. errMsg += (ctid + "指派失败!!!");
  3535. continue;
  3536. }
  3537. entity.SupplierId = sid;
  3538. entity.Update();
  3539. commonHelper.UpdateRelationOrder(entity.ctid);
  3540. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3541. if (entity.OrderState >= 6)
  3542. {
  3543. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3544. //{
  3545. // string msl = entity.MakeSupplier;
  3546. // string[] mslist = msl.Split(',');
  3547. // 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);
  3548. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3549. //}
  3550. //else
  3551. //{
  3552. StringBuilder sql = new StringBuilder();
  3553. 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);
  3554. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3555. //}
  3556. }
  3557. }
  3558. else
  3559. {
  3560. continue;
  3561. }
  3562. }
  3563. if (errMsg.Length > 0)
  3564. {
  3565. returnErrorMsg(errMsg);
  3566. return;
  3567. }
  3568. returnSuccessMsg("操作成功!");
  3569. return;
  3570. }
  3571. }
  3572. public void assign_erp_makesupplier()
  3573. {
  3574. if (UrlPostParmsCheck("ctid"))
  3575. {
  3576. string eids = GetPostString("ctid");
  3577. string sname = GetPostString("SupplierName");
  3578. string[] eidList = eids.Split(',');
  3579. if (eidList.Length <= 0)
  3580. {
  3581. returnErrorMsg("指派不能为空");
  3582. return;
  3583. }
  3584. List<string> tLst = new List<string>();
  3585. foreach (string ctid in eidList)
  3586. {
  3587. CeErpTradeCell entity = null;
  3588. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3589. if (entity != null)
  3590. {
  3591. entity.MakeSupplier = sname;
  3592. entity.Update();
  3593. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3594. tLst.Add("'" + ctid + "'");
  3595. }
  3596. else
  3597. {
  3598. continue;
  3599. }
  3600. }
  3601. string ctids = string.Join(",", tLst.ToArray());
  3602. StringBuilder sql2 = new StringBuilder();
  3603. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3604. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3605. returnSuccessMsg("操作成功!");
  3606. return;
  3607. }
  3608. }
  3609. public void ins_erp_returnreason()
  3610. {
  3611. if (UrlPostParmsCheck("ctid"))
  3612. {
  3613. string eid = GetPostString("ctid");
  3614. CeErpTradeCell entity = null;
  3615. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3616. string userpost = CurrentUser.UserPost.Post.Code;
  3617. if (entity != null)
  3618. {
  3619. bool isPlace = false;
  3620. if (entity.OrderState > 6)
  3621. {
  3622. returnErrorMsg("已发货无法打回!");
  3623. return;
  3624. }
  3625. if (entity.OrderState == 6)
  3626. {
  3627. isPlace = true;
  3628. }
  3629. bool isNeedUpdateCell2 = false;
  3630. if (entity.OrderState >= 6)
  3631. {
  3632. isNeedUpdateCell2 = true;
  3633. }
  3634. int returnTag = 2;
  3635. if (userpost == "Supplier")
  3636. {
  3637. returnTag = 1;
  3638. }
  3639. int toType = GetPostInt("totype");
  3640. string fromType = "3";
  3641. if (entity.OrderState < 5)
  3642. {
  3643. fromType = "3";
  3644. }
  3645. else
  3646. {
  3647. fromType = "4";
  3648. }
  3649. if (entity.IsXianHuo == 0)
  3650. {
  3651. if (returnTag == 2)
  3652. {
  3653. if (toType == 1)
  3654. {
  3655. entity.OrderState = 0;
  3656. entity.ReturnUserType = 1;
  3657. string clearman = GetPostString("clearman");
  3658. if (!string.IsNullOrEmpty(clearman))
  3659. {
  3660. entity.DesignUserId = 0;
  3661. }
  3662. }
  3663. else
  3664. {
  3665. entity.OrderState = 3;
  3666. entity.ReturnUserType = 2;
  3667. }
  3668. entity.IsReadTag = 1;
  3669. }
  3670. else if (returnTag == 1)
  3671. {
  3672. entity.OrderState = 5;
  3673. }
  3674. entity.IsVerifyToSupplier = false;
  3675. }
  3676. if (entity.IsXianHuo == 1)
  3677. {
  3678. entity.OrderState = 5;
  3679. }
  3680. entity.UnusualTag = 0;
  3681. entity.UnusualTime = null;
  3682. entity.UnusualCon = "";
  3683. entity.IsReturn = returnTag;
  3684. entity.ReturnTime = DateTime.Now;
  3685. entity.UpdateTime = DateTime.Now;
  3686. entity.ReturnReason = GetPostString("returnreason");
  3687. entity.Update();
  3688. if (entity.OrderState == 3)
  3689. {
  3690. ApiVo apiVo = new ApiVo();
  3691. apiVo.orderNumber = entity.ctid;
  3692. apiVo.actionName = "rebutDesign";
  3693. apiVo.orderRemarks = entity.ReturnReason;
  3694. designHelper.API_WorkCore(apiVo);//rebutDesign
  3695. }
  3696. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3697. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3698. {
  3699. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3700. }
  3701. CeErpSukuraData.createInfo(entity.ctid, 5);
  3702. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3703. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3704. if (isPlace)
  3705. {
  3706. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3707. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3708. if (dth != null && dth.Rows.Count > 0)
  3709. {
  3710. dataSendOrderBean dataSendOrderBean = null;
  3711. foreach (DataRow item in dth.Rows)
  3712. {
  3713. try
  3714. {
  3715. dataSendOrderBean = new dataSendOrderBean();
  3716. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3717. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3718. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3719. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3720. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3721. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3722. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3723. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3724. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3725. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3726. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3727. dataSendOrderBean.Radio1723534706288 = "打回";
  3728. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3729. if (result != null)
  3730. {
  3731. if ("0".Equals(result.errcode))
  3732. {
  3733. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3734. }
  3735. else
  3736. {
  3737. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3738. }
  3739. }
  3740. }
  3741. catch (Exception ex)
  3742. {
  3743. }
  3744. }
  3745. }
  3746. }
  3747. if (isNeedUpdateCell2)
  3748. {
  3749. if (entity.MakeSupplier.IndexOf(",") != -1)
  3750. {
  3751. StringBuilder sql2 = new StringBuilder();
  3752. 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);
  3753. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3754. }
  3755. else
  3756. {
  3757. StringBuilder sql2 = new StringBuilder();
  3758. 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);
  3759. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3760. }
  3761. }
  3762. returnSuccessMsg("操作成功!");
  3763. return;
  3764. }
  3765. returnErrorMsg("找不到订单记录");
  3766. }
  3767. }
  3768. public void cyt_erp_returnreason()
  3769. {
  3770. if (UrlPostParmsCheck("ctid"))
  3771. {
  3772. string eid = GetPostString("ctid");
  3773. CeErpTradeCell entity = null;
  3774. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3775. string userpost = CurrentUser.UserPost.Post.Code;
  3776. if (entity != null)
  3777. {
  3778. if (entity.OrderState > 6)
  3779. {
  3780. returnErrorMsg("已发货无法打回!");
  3781. return;
  3782. }
  3783. JObject jsonObject = new JObject
  3784. {
  3785. { "Userid", "77886" },
  3786. { "Pwd", "lt666888" },
  3787. { "LTOrderId",eid }
  3788. };
  3789. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3790. JObject jsonObjects = JObject.Parse(response);
  3791. string msg = (string)jsonObjects["msg"];
  3792. if (msg != "取消成功")
  3793. {
  3794. returnErrorMsg(msg);
  3795. return;
  3796. }
  3797. bool isNeedUpdateCell2 = false;
  3798. if (entity.OrderState >= 6)
  3799. {
  3800. isNeedUpdateCell2 = true;
  3801. }
  3802. int returnTag = 2;
  3803. if (userpost == "Supplier")
  3804. {
  3805. returnTag = 1;
  3806. }
  3807. if (entity.IsXianHuo == 0)
  3808. {
  3809. if (returnTag == 2)
  3810. {
  3811. int toType = GetPostInt("totype");
  3812. if (toType == 1)
  3813. {
  3814. entity.OrderState = 0;
  3815. entity.ReturnUserType = 1;
  3816. }
  3817. else
  3818. {
  3819. entity.OrderState = 4;
  3820. entity.ReturnUserType = 2;
  3821. }
  3822. entity.IsReadTag = 1;
  3823. }
  3824. else if (returnTag == 1)
  3825. {
  3826. entity.OrderState = 5;
  3827. }
  3828. entity.IsVerifyToSupplier = false;
  3829. }
  3830. entity.UnusualTag = 0;
  3831. entity.UnusualTime = null;
  3832. entity.UnusualCon = "";
  3833. entity.IsReturn = returnTag;
  3834. entity.ReturnTime = DateTime.Now;
  3835. entity.ReturnReason = GetPostString("returnreason");
  3836. entity.Update();
  3837. if (entity.OrderState == 4)
  3838. {
  3839. ApiVo apiVo = new ApiVo();
  3840. apiVo.orderNumber = entity.ctid;
  3841. apiVo.actionName = "rebutDesign";
  3842. apiVo.orderRemarks = entity.ReturnReason;
  3843. designHelper.API_WorkCore(apiVo);//rebutDesign
  3844. }
  3845. CeErpSukuraData.createInfo(entity.ctid, 5);
  3846. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3847. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3848. if (isNeedUpdateCell2)
  3849. {
  3850. if (entity.MakeSupplier.IndexOf(",") != -1)
  3851. {
  3852. StringBuilder sql2 = new StringBuilder();
  3853. 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);
  3854. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3855. }
  3856. else
  3857. {
  3858. StringBuilder sql2 = new StringBuilder();
  3859. 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);
  3860. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3861. }
  3862. }
  3863. returnSuccessMsg("操作成功!");
  3864. return;
  3865. }
  3866. returnErrorMsg("找不到订单记录");
  3867. }
  3868. }
  3869. public void upd_erp_xianhuoreturntag()
  3870. {
  3871. if (UrlPostParmsCheck("ctid"))
  3872. {
  3873. string eids = GetPostString("ctid");
  3874. string[] ctids = eids.Split(',');
  3875. foreach (string ctid in ctids)
  3876. {
  3877. CeErpTradeCell entity = null;
  3878. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3879. if (entity != null)
  3880. {
  3881. entity.IsReturn = 0;
  3882. entity.Update();
  3883. CeErpSukuraData.createInfo(entity.ctid, 5);
  3884. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3885. }
  3886. }
  3887. returnSuccessMsg("操作成功!");
  3888. return;
  3889. }
  3890. }
  3891. public void get_erp_waitdeliverylist()
  3892. {
  3893. DataStruct dStruct = GetPostStruct();
  3894. List<string> lw = new List<string>();
  3895. string tid = GetPostString("ctid");
  3896. if (tid.Length > 0)
  3897. {
  3898. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3899. if (tid.Length > 5)
  3900. {
  3901. List<string> tids = getTidByCtidLike(tid);
  3902. if (tids.Count > 0 && tids.Count < 10)
  3903. {
  3904. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3905. }
  3906. }
  3907. lw.Add(tid_sql);
  3908. }
  3909. string shopname = GetPostString("shopname");
  3910. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3911. string buyernick = GetPostString("buyer_nick");
  3912. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3913. //if (tid.Length == 0 && buyernick.Length == 0)
  3914. //{
  3915. // lw.Add(string.Format("IsRefund<={0}", 1));
  3916. //}
  3917. string customer = GetPostString("customer");
  3918. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3919. string design = GetPostString("design");
  3920. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3921. string orderState = GetPostString("orderState");
  3922. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3923. string address = GetPostString("address");
  3924. 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));
  3925. string sellermemo = GetPostString("seller_memo");
  3926. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3927. string supplier = GetPostString("supplier");
  3928. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3929. string OrderArea = GetPostString("order_area");
  3930. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3931. string placedate1 = GetPostString("placedate1");
  3932. string placedate2 = GetPostString("placedate2");
  3933. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3934. if (fdw.Length > 0) lw.Add(fdw);
  3935. string price1 = GetPostString("price1");
  3936. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3937. string price2 = GetPostString("price2");
  3938. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3939. string unusualCon = GetPostString("unusualcon");
  3940. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3941. string otherMemo = GetPostString("otherMemo");
  3942. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3943. string posTag = CurrentUser.UserPost.Post.Code;
  3944. if (posTag == "Supplier")
  3945. {
  3946. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3947. }
  3948. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  3949. lw.Add(string.Format("type != 'PDD' "));
  3950. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3951. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3952. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3953. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3954. writeGridDataTableJson(dStruct.TotalCount, dt);
  3955. }
  3956. public void get_erp_changedeliverylist()
  3957. {
  3958. DataStruct dStruct = GetPostStruct();
  3959. List<string> lw = new List<string>();
  3960. string tid = GetPostString("ctid");
  3961. if (tid.Length > 0)
  3962. {
  3963. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3964. if (tid.Length > 5)
  3965. {
  3966. List<string> tids = getTidByCtidLike(tid);
  3967. if (tids.Count > 0 && tids.Count < 10)
  3968. {
  3969. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3970. }
  3971. }
  3972. lw.Add(tid_sql);
  3973. }
  3974. string shopname = GetPostString("shopname");
  3975. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3976. string buyernick = GetPostString("buyer_nick");
  3977. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3978. //if (tid.Length == 0 && buyernick.Length == 0)
  3979. //{
  3980. // lw.Add(string.Format("IsRefund<={0}", 1));
  3981. //}
  3982. string customer = GetPostString("customer");
  3983. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3984. string design = GetPostString("design");
  3985. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3986. string orderState = GetPostString("orderState");
  3987. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3988. string address = GetPostString("address");
  3989. 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));
  3990. string sellermemo = GetPostString("seller_memo");
  3991. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3992. string supplier = GetPostString("supplier");
  3993. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3994. string OrderArea = GetPostString("order_area");
  3995. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3996. string placedate1 = GetPostString("placedate1");
  3997. string placedate2 = GetPostString("placedate2");
  3998. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3999. if (fdw.Length > 0) lw.Add(fdw);
  4000. string price1 = GetPostString("price1");
  4001. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4002. string price2 = GetPostString("price2");
  4003. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4004. string unusualCon = GetPostString("unusualcon");
  4005. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4006. string otherMemo = GetPostString("otherMemo");
  4007. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4008. string posTag = CurrentUser.UserPost.Post.Code;
  4009. if (posTag == "Supplier")
  4010. {
  4011. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4012. }
  4013. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4014. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4015. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4016. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4017. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4018. /*if (tid.Length > 0)
  4019. {
  4020. List<string> tids = new List<string>();
  4021. if (dt != null && dt.Rows.Count > 0)
  4022. {
  4023. foreach (DataRow item in dt.Rows)
  4024. {
  4025. tids.Add("'" + item["tid"] + "'");
  4026. }
  4027. }
  4028. if (tids.Count > 0)
  4029. {
  4030. lw.RemoveAt(0);
  4031. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4032. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4033. dt = WebCache.GetData("view_erptradecell", dStruct);
  4034. }
  4035. }*/
  4036. writeGridDataTableJson(dStruct.TotalCount, dt);
  4037. }
  4038. public void get_erp_pddderiving()
  4039. {
  4040. DataStruct dStruct = GetPostStruct();
  4041. List<string> lw = new List<string>();
  4042. string tid = GetPostString("ctid");
  4043. if (tid.Length > 0)
  4044. {
  4045. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4046. if (tid.Length > 5)
  4047. {
  4048. List<string> tids = getTidByCtidLike(tid);
  4049. if (tids.Count > 0 && tids.Count < 10)
  4050. {
  4051. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4052. }
  4053. }
  4054. lw.Add(tid_sql);
  4055. }
  4056. string shopname = GetPostString("shopname");
  4057. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4058. string buyernick = GetPostString("buyer_nick");
  4059. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4060. //if (tid.Length == 0 && buyernick.Length == 0)
  4061. //{
  4062. // lw.Add(string.Format("IsRefund<={0}", 1));
  4063. //}
  4064. string customer = GetPostString("customer");
  4065. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4066. string design = GetPostString("design");
  4067. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4068. string orderState = GetPostString("orderState");
  4069. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4070. string address = GetPostString("address");
  4071. 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));
  4072. string sellermemo = GetPostString("seller_memo");
  4073. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4074. string supplier = GetPostString("supplier");
  4075. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4076. string OrderArea = GetPostString("order_area");
  4077. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4078. string placedate1 = GetPostString("placedate1");
  4079. string placedate2 = GetPostString("placedate2");
  4080. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4081. if (fdw.Length > 0) lw.Add(fdw);
  4082. string price1 = GetPostString("price1");
  4083. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4084. string price2 = GetPostString("price2");
  4085. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4086. string unusualCon = GetPostString("unusualcon");
  4087. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4088. string posTag = CurrentUser.UserPost.Post.Code;
  4089. if (posTag == "Supplier")
  4090. {
  4091. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4092. }
  4093. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4094. lw.Add(string.Format("type = 'PDD' "));
  4095. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4096. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4097. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4098. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4099. /*if (tid.Length > 0)
  4100. {
  4101. List<string> tids = new List<string>();
  4102. if (dt != null && dt.Rows.Count > 0)
  4103. {
  4104. foreach (DataRow item in dt.Rows)
  4105. {
  4106. tids.Add("'" + item["tid"] + "'");
  4107. }
  4108. }
  4109. if (tids.Count > 0)
  4110. {
  4111. lw.RemoveAt(0);
  4112. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4113. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4114. dt = WebCache.GetData("view_erptradecell", dStruct);
  4115. }
  4116. }*/
  4117. writeGridDataTableJson(dStruct.TotalCount, dt);
  4118. }
  4119. public void get_erp_jdderiving()
  4120. {
  4121. DataStruct dStruct = GetPostStruct();
  4122. List<string> lw = new List<string>();
  4123. string tid = GetPostString("ctid");
  4124. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4125. string shopname = GetPostString("shopname");
  4126. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4127. string buyernick = GetPostString("buyer_nick");
  4128. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4129. //if (tid.Length == 0 && buyernick.Length == 0)
  4130. //{
  4131. // lw.Add(string.Format("IsRefund<={0}", 1));
  4132. //}
  4133. string customer = GetPostString("customer");
  4134. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4135. string design = GetPostString("design");
  4136. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4137. string orderState = GetPostString("orderState");
  4138. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4139. string address = GetPostString("address");
  4140. 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));
  4141. string sellermemo = GetPostString("seller_memo");
  4142. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4143. string supplier = GetPostString("supplier");
  4144. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4145. string OrderArea = GetPostString("order_area");
  4146. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4147. string placedate1 = GetPostString("placedate1");
  4148. string placedate2 = GetPostString("placedate2");
  4149. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4150. if (fdw.Length > 0) lw.Add(fdw);
  4151. string price1 = GetPostString("price1");
  4152. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4153. string price2 = GetPostString("price2");
  4154. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4155. string unusualCon = GetPostString("unusualcon");
  4156. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4157. string posTag = CurrentUser.UserPost.Post.Code;
  4158. if (posTag == "Supplier")
  4159. {
  4160. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4161. }
  4162. lw.Add(string.Format("OrderState = 6 "));
  4163. lw.Add(string.Format("type = 'JD' "));
  4164. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4165. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4166. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4167. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4168. writeGridDataTableJson(dStruct.TotalCount, dt);
  4169. }
  4170. public void get_erp_demoorderlist()
  4171. {
  4172. DataStruct dStruct = GetPostStruct();
  4173. List<string> lw = new List<string>();
  4174. string tid = GetPostString("ctid");
  4175. if (tid.Length > 0)
  4176. {
  4177. string select_tid = getTidByCtid(tid);
  4178. lw.Add(string.Format("tid='{0}'", select_tid));
  4179. }
  4180. string shopname = GetPostString("shopname");
  4181. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4182. string buyernick = GetPostString("buyer_nick");
  4183. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4184. string customer = GetPostString("customer");
  4185. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4186. string design = GetPostString("design");
  4187. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4188. string orderState = GetPostString("orderState");
  4189. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4190. string address = GetPostString("address");
  4191. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4192. string sellermemo = GetPostString("seller_memo");
  4193. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4194. string supplier = GetPostString("supplier");
  4195. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4196. string OrderArea = GetPostString("order_area");
  4197. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4198. string date1 = GetPostString("date1");
  4199. string date2 = GetPostString("date2");
  4200. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4201. if (dw.Length > 0) lw.Add(dw);
  4202. string price1 = GetPostString("price1");
  4203. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4204. string price2 = GetPostString("price2");
  4205. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4206. string posTag = CurrentUser.UserPost.Post.Code;
  4207. if (posTag == "Supplier")
  4208. {
  4209. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4210. }
  4211. //lw.Add(string.Format("OrderState = 6 "));
  4212. lw.Add(string.Format("IsSample={0}", 3));
  4213. lw.Add(string.Format("IsRefund<={0}", 1));
  4214. dStruct.Order = "pay_time desc";
  4215. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4216. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4217. writeGridDataTableJson(dStruct.TotalCount, dt);
  4218. }
  4219. public void save_erp_checkmemo()
  4220. {
  4221. if (UrlPostParmsCheck("ctid"))
  4222. {
  4223. string ctid = GetPostString("ctid");
  4224. CeErpTradeCell entity = null;
  4225. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4226. if (entity != null)
  4227. {
  4228. entity.CheckMemo = GetPostString("CheckMemo");
  4229. entity.Update();
  4230. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4231. if (trade != null)
  4232. {
  4233. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4234. }
  4235. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4236. returnSuccessMsg("保存成功!");
  4237. return;
  4238. }
  4239. returnErrorMsg("找不到记录");
  4240. }
  4241. }
  4242. public void get_erp_returnlist()
  4243. {
  4244. DataStruct dStruct = GetPostStruct();
  4245. List<string> lw = new List<string>();
  4246. string tid = GetPostString("ctid");
  4247. if (tid.Length > 0)
  4248. {
  4249. string select_tid = getTidByCtid(tid);
  4250. lw.Add(string.Format("tid='{0}'", select_tid));
  4251. }
  4252. string shopname = GetPostString("shopname");
  4253. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4254. string buyernick = GetPostString("buyer_nick");
  4255. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4256. string customer = GetPostString("customer");
  4257. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4258. string design = GetPostString("design");
  4259. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4260. string orderState = GetPostString("orderState");
  4261. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4262. string address = GetPostString("address");
  4263. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4264. string sellermemo = GetPostString("seller_memo");
  4265. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4266. string supplier = GetPostString("supplier");
  4267. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4268. string date1 = GetPostString("date1");
  4269. string date2 = GetPostString("date2");
  4270. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4271. if (dw.Length > 0) lw.Add(dw);
  4272. string bdate1 = GetPostString("backdate1");
  4273. string bdate2 = GetPostString("backdate2");
  4274. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4275. if (dw_back.Length > 0) lw.Add(dw_back);
  4276. string price1 = GetPostString("price1");
  4277. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4278. string price2 = GetPostString("price2");
  4279. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4280. lw.Add(string.Format("IsReturn>0"));
  4281. lw.Add(string.Format("IsXianHuo=0"));
  4282. lw.Add(string.Format("IsReturn!=3"));
  4283. string backtype = GetPostString("backtype");
  4284. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4285. dStruct.Order = "FinishDesignTime desc";
  4286. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4287. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4288. writeGridDataTableJson(dStruct.TotalCount, dt);
  4289. }
  4290. public void get_erp_today_sumreturn()
  4291. {
  4292. DataStruct dStruct = GetPostStruct();
  4293. List<string> lw = new List<string>();
  4294. string bdate1 = GetPostString("returnTimeS");
  4295. string bdate2 = GetPostString("returnTimeE");
  4296. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4297. if (dw_back.Length > 0) lw.Add(dw_back);
  4298. lw.Add(string.Format("IsReturn=0"));
  4299. lw.Add(string.Format("IsXianHuo=0"));
  4300. string mainWhere = string.Join(" and ", lw.ToArray());
  4301. string sql = "";
  4302. if (dw_back.Length > 0)
  4303. {
  4304. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4305. }
  4306. else
  4307. {
  4308. 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 + "'";
  4309. }
  4310. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4311. decimal total = 0, today_finish = 0;
  4312. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4313. {
  4314. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4315. }
  4316. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4317. {
  4318. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4319. }
  4320. var res = new
  4321. {
  4322. data = total,
  4323. data1 = today_finish,
  4324. };
  4325. string ro_jsond = JsonConvert.SerializeObject(res);
  4326. returnSuccess(ro_jsond);
  4327. return;
  4328. }
  4329. public void get_erp_allreturnlist()
  4330. {
  4331. DataStruct dStruct = GetPostStruct();
  4332. List<string> lw = new List<string>();
  4333. string tid = GetPostString("ctid");
  4334. if (tid.Length > 0)
  4335. {
  4336. string select_tid = getTidByCtid(tid);
  4337. lw.Add(string.Format("tid='{0}'", select_tid));
  4338. }
  4339. string shopname = GetPostString("shopname");
  4340. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4341. string buyernick = GetPostString("buyer_nick");
  4342. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4343. string customer = GetPostString("customer");
  4344. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4345. string design = GetPostString("design");
  4346. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4347. string orderState = GetPostString("orderState");
  4348. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4349. string address = GetPostString("address");
  4350. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4351. string sellermemo = GetPostString("seller_memo");
  4352. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4353. string supplier = GetPostString("supplier");
  4354. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4355. string date1 = GetPostString("date1");
  4356. string date2 = GetPostString("date2");
  4357. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4358. if (dw.Length > 0) lw.Add(dw);
  4359. string bdate1 = GetPostString("backdate1");
  4360. string bdate2 = GetPostString("backdate2");
  4361. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4362. if (dw_back.Length > 0) lw.Add(dw_back);
  4363. string price1 = GetPostString("price1");
  4364. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4365. string price2 = GetPostString("price2");
  4366. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4367. string backreason = GetPostString("backreason");
  4368. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4369. lw.Add(string.Format("IsXianHuo=0"));
  4370. lw.Add(string.Format("ReturnTime != ''"));
  4371. string backtype = GetPostString("backtype");
  4372. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4373. dStruct.Order = "FinishDesignTime desc";
  4374. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4375. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4376. writeGridDataTableJson(dStruct.TotalCount, dt);
  4377. }
  4378. public void get_erp_aftersalereturnlist()
  4379. {
  4380. DataStruct dStruct = GetPostStruct();
  4381. List<string> lw = new List<string>();
  4382. string tid = GetPostString("ctid");
  4383. if (tid.Length > 0)
  4384. {
  4385. string select_tid = getTidByCtid(tid);
  4386. lw.Add(string.Format("tid='{0}'", select_tid));
  4387. }
  4388. string shopname = GetPostString("shopname");
  4389. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4390. string buyernick = GetPostString("buyer_nick");
  4391. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4392. string customer = GetPostString("customer");
  4393. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4394. string design = GetPostString("design");
  4395. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4396. string orderState = GetPostString("orderState");
  4397. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4398. string address = GetPostString("address");
  4399. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4400. string sellermemo = GetPostString("seller_memo");
  4401. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4402. string supplier = GetPostString("supplier");
  4403. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4404. string date1 = GetPostString("date1");
  4405. string date2 = GetPostString("date2");
  4406. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4407. if (dw.Length > 0) lw.Add(dw);
  4408. string bdate1 = GetPostString("backdate1");
  4409. string bdate2 = GetPostString("backdate2");
  4410. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4411. if (dw_back.Length > 0) lw.Add(dw_back);
  4412. string price1 = GetPostString("price1");
  4413. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4414. string price2 = GetPostString("price2");
  4415. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4416. lw.Add(string.Format("IsReturn=3"));
  4417. string backtype = GetPostString("backtype");
  4418. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4419. string backreason = GetPostString("backreason");
  4420. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4421. dStruct.Order = "ReturnTime desc";
  4422. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4423. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4424. writeGridDataTableJson(dStruct.TotalCount, dt);
  4425. }
  4426. public void get_erp_xianhuoreturnlist()
  4427. {
  4428. DataStruct dStruct = GetPostStruct();
  4429. List<string> lw = new List<string>();
  4430. string tid = GetPostString("ctid");
  4431. if (tid.Length > 0)
  4432. {
  4433. string select_tid = getTidByCtid(tid);
  4434. lw.Add(string.Format("tid='{0}'", select_tid));
  4435. }
  4436. string shopname = GetPostString("shopname");
  4437. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4438. string buyernick = GetPostString("buyer_nick");
  4439. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4440. string customer = GetPostString("customer");
  4441. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4442. string design = GetPostString("design");
  4443. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4444. string orderState = GetPostString("orderState");
  4445. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4446. string address = GetPostString("address");
  4447. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4448. string sellermemo = GetPostString("seller_memo");
  4449. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4450. string supplier = GetPostString("supplier");
  4451. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4452. string OrderArea = GetPostString("order_area");
  4453. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4454. string date1 = GetPostString("date1");
  4455. string date2 = GetPostString("date2");
  4456. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4457. if (dw.Length > 0) lw.Add(dw);
  4458. string price1 = GetPostString("price1");
  4459. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4460. string price2 = GetPostString("price2");
  4461. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4462. string posTag = CurrentUser.UserPost.Post.Code;
  4463. if (posTag == "Supplier")
  4464. {
  4465. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4466. }
  4467. lw.Add(string.Format("OrderState=6 "));
  4468. lw.Add(string.Format("IsXianHuo=1 "));
  4469. lw.Add(string.Format("IsReturn>0 "));
  4470. lw.Add(string.Format("IsReturn!=3"));
  4471. lw.Add(string.Format("IsRefund<={0}", 1));
  4472. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4473. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4474. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4475. writeGridDataTableJson(dStruct.TotalCount, dt);
  4476. }
  4477. public void set_erp_orderdelivery()
  4478. {
  4479. if (UrlPostParmsCheck("ctid"))
  4480. {
  4481. string eid = GetPostString("ctid");
  4482. CeErpTradeCell entity = null;
  4483. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4484. if (entity != null)
  4485. {
  4486. if (entity.OrderState >= 7)
  4487. {
  4488. returnErrorMsg("此单已发货,无需重复发货");
  4489. return;
  4490. }
  4491. if (entity.OrderState != 6)
  4492. {
  4493. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4494. return;
  4495. }
  4496. string shop = GetPostString("seller_nick");
  4497. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4498. string comName = GetPostString("comName");
  4499. string comCode = GetPostString("comCode");
  4500. string outSid = GetPostString("outSid");
  4501. string deliveryType = GetPostString("deliveryType");
  4502. string deliveryMemo = GetPostString("deliveryMemo");
  4503. outSid = outSid.Trim();
  4504. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4505. if (mainEn == null)
  4506. {
  4507. returnErrorMsg("找不到原始订单记录");
  4508. return;
  4509. }
  4510. bool isInitOrderDeliv = false;
  4511. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4512. {
  4513. isInitOrderDeliv = true;
  4514. }
  4515. string apires = "";
  4516. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4517. 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)
  4518. {
  4519. apires = "发货成功true";
  4520. }
  4521. else
  4522. {
  4523. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4524. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4525. }
  4526. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4527. {
  4528. entity.OrderState = 7;//发货后订单已发货
  4529. entity.OutSid = outSid;
  4530. entity.MemoOpt = 0;
  4531. entity.UpdateTime = DateTime.Now;
  4532. entity.FinishDeliveryTime = DateTime.Now;
  4533. entity.Update();
  4534. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4535. commonHelper.UpdateRelationOrder(entity.ctid);
  4536. //还要插入快递信息到 快递信息表
  4537. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4538. exinfo.tid = eid;
  4539. exinfo.out_sid = outSid;
  4540. exinfo.company_code = comCode;
  4541. exinfo.company_name = comName;
  4542. exinfo.delivery_memo = deliveryMemo;
  4543. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4544. exinfo.deliveryType = deliveryType;
  4545. exinfo.Create();
  4546. returnSuccessMsg("发货操作成功!");
  4547. commonHelper.UpdateRelationOrder(entity.ctid);
  4548. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4549. CeErpSukuraData.createInfo(entity.ctid, 4);
  4550. if (entity.SupplierId == 64)
  4551. {
  4552. commonHelper.sendCytExpress(exinfo);
  4553. }
  4554. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4555. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4556. }
  4557. else
  4558. {
  4559. string errmsg = commonHelper.KeepChinese(apires);
  4560. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4561. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4562. }
  4563. return;
  4564. }
  4565. returnErrorMsg("找不到订单记录");
  4566. }
  4567. }
  4568. public void set_erp_multidelivery()
  4569. {
  4570. string eids = GetPostString("tids");
  4571. string[] eidList = eids.Split(',');
  4572. if (eidList.Length <= 0)
  4573. {
  4574. returnErrorMsg("发货不能为空");
  4575. return;
  4576. }
  4577. foreach (string ctid in eidList)
  4578. {
  4579. if (ctid.Length <= 0) continue;
  4580. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4581. if (expInfo != null)
  4582. {
  4583. StringBuilder sql = new StringBuilder();
  4584. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4585. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4586. if (dt.Rows.Count > 0)
  4587. {
  4588. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4589. {
  4590. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4591. expInfo.state = "异常";
  4592. expInfo.isMultiDelivery = 1;
  4593. expInfo.Update();
  4594. continue;
  4595. }
  4596. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4597. {
  4598. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4599. expInfo.state = "异常";
  4600. expInfo.Update();
  4601. continue;
  4602. }
  4603. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4604. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4605. bool isInitOrderDeliv = false;
  4606. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4607. {
  4608. isInitOrderDeliv = true;
  4609. expInfo.isMultiDelivery = 1;
  4610. }
  4611. if (ctid.IndexOf("N") != -1)
  4612. {
  4613. StringBuilder sqlbucha = new StringBuilder();
  4614. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4615. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4616. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4617. commonHelper.UpdateRelationOrder(ctid);
  4618. expInfo.delivery_memo = "发货成功";
  4619. expInfo.state = "发货成功";
  4620. expInfo.isMultiDelivery = 1;
  4621. expInfo.Update();
  4622. }
  4623. else
  4624. {
  4625. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4626. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4627. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4628. {
  4629. expInfo.delivery_memo = "发货成功";
  4630. expInfo.state = "发货成功";
  4631. expInfo.isMultiDelivery = 1;
  4632. expInfo.Update();
  4633. commonHelper.UpdateRelationOrder(ctid);
  4634. CeErpSukuraData.createInfo(ctid, 4);
  4635. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4636. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4637. }
  4638. else
  4639. {
  4640. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4641. expInfo.state = "异常";
  4642. expInfo.Update();
  4643. }
  4644. }
  4645. }
  4646. }
  4647. }
  4648. returnSuccessMsg("操作完成");
  4649. }
  4650. public void reset_erp_memoopt()
  4651. {
  4652. if (UrlPostParmsCheck("ctid"))
  4653. {
  4654. string eid = GetPostString("ctid");
  4655. CeErpTradeCell entity = null;
  4656. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4657. if (entity != null)
  4658. {
  4659. string stropt = "";
  4660. if (entity.MemoOpt == 1)
  4661. {
  4662. stropt = "“改稿”";
  4663. }
  4664. else if (entity.MemoOpt == 2)
  4665. {
  4666. stropt = "“定稿”";
  4667. }
  4668. else if (entity.MemoOpt == 3)
  4669. {
  4670. stropt = "“完成查货”";
  4671. CeErpSukuraData.createInfo(entity.ctid, 6);
  4672. }
  4673. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4674. entity.UpdateTime = DateTime.Now;
  4675. entity.MemoOpt = 0;
  4676. entity.Update();
  4677. returnSuccessMsg("操作成功!");
  4678. return;
  4679. }
  4680. returnErrorMsg("找不到记录");
  4681. }
  4682. }
  4683. public void get_erp_deliveryunusual()
  4684. {
  4685. DataStruct dStruct = GetPostStruct();
  4686. List<string> lw = new List<string>();
  4687. string tid = GetPostString("ctid");
  4688. if (tid.Length > 0)
  4689. {
  4690. string select_tid = getTidByCtid(tid);
  4691. lw.Add(string.Format("tid='{0}'", select_tid));
  4692. }
  4693. string shopname = GetPostString("shopname");
  4694. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4695. string buyernick = GetPostString("buyer_nick");
  4696. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4697. string customer = GetPostString("customer");
  4698. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4699. string design = GetPostString("design");
  4700. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4701. string sellermemo = GetPostString("seller_memo");
  4702. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4703. string supplier = GetPostString("supplier");
  4704. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4705. string date1 = GetPostString("date1");
  4706. string date2 = GetPostString("date2");
  4707. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4708. if (dw.Length > 0) lw.Add(dw);
  4709. string placedate1 = GetPostString("placedate1");
  4710. string placedate2 = GetPostString("placedate2");
  4711. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4712. if (dw_place.Length > 0) lw.Add(dw_place);
  4713. string price1 = GetPostString("price1");
  4714. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4715. string price2 = GetPostString("price2");
  4716. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4717. string unusualCon = GetPostString("unusualcon");
  4718. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4719. string posTag = CurrentUser.UserPost.Post.Code;
  4720. if (posTag == "Supplier")
  4721. {
  4722. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4723. }
  4724. lw.Add(string.Format("OrderState = 6"));
  4725. lw.Add(string.Format("UnusualTag = 5"));
  4726. lw.Add(string.Format("IsRefund<={0}", 1));
  4727. dStruct.Order = "FinishPlaceTime desc";
  4728. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4729. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4730. writeGridDataTableJson(dStruct.TotalCount, dt);
  4731. }
  4732. public void get_erp_deliveryedlist()
  4733. {
  4734. DataStruct dStruct = GetPostStruct();
  4735. List<string> lw = new List<string>();
  4736. string tid = GetPostString("ctid");
  4737. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  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='{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 sellermemo = GetPostString("seller_memo");
  4747. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4748. string logistics = GetPostString("logistics");
  4749. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4750. string date1 = GetPostString("date1");
  4751. string date2 = GetPostString("date2");
  4752. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4753. //if (dw.Length > 0) lw.Add(dw);
  4754. string placedate1 = GetPostString("placedate1");
  4755. string placedate2 = GetPostString("placedate2");
  4756. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4757. if (fdw.Length > 0) lw.Add(fdw);
  4758. string devdate1 = GetPostString("deliverydate1");
  4759. string devdate2 = GetPostString("deliverydate2");
  4760. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4761. if (dw_dev.Length > 0) lw.Add(dw_dev);
  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. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4767. {
  4768. if (tid.Length > 0)
  4769. {
  4770. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4771. if (tid.Length > 5)
  4772. {
  4773. List<string> tids = getTidByCtidLike(tid);
  4774. if (tids.Count > 0 && tids.Count < 10)
  4775. {
  4776. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4777. }
  4778. }
  4779. lw.Add(tid_sql);
  4780. }
  4781. if (buyernick.Length > 0)
  4782. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4783. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4784. if (dw.Length > 0) lw.Add(dw);
  4785. }
  4786. else
  4787. {
  4788. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4789. }
  4790. string posTag = CurrentUser.UserPost.Post.Code;
  4791. if (posTag == "Supplier")
  4792. {
  4793. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4794. }
  4795. else
  4796. {
  4797. string supplier = GetPostString("supplier");
  4798. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4799. }
  4800. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4801. lw.Add(string.Format("type != 'PDD' "));
  4802. lw.Add(string.Format("IsRefund!={0}", 2));
  4803. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4804. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4805. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4806. /*if (tid.Length > 0)
  4807. {
  4808. List<string> tids = new List<string>();
  4809. if (dt != null && dt.Rows.Count > 0)
  4810. {
  4811. foreach (DataRow item in dt.Rows)
  4812. {
  4813. tids.Add("'" + item["tid"] + "'");
  4814. }
  4815. }
  4816. if (tids.Count > 0)
  4817. {
  4818. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4819. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4820. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4821. dt = WebCache.GetData("view_erptradecell", dStruct);
  4822. }
  4823. }*/
  4824. if (dt != null)
  4825. {
  4826. foreach (DataRow dr in dt.Rows)
  4827. {
  4828. 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();
  4829. }
  4830. }
  4831. writeGridDataTableJson(dStruct.TotalCount, dt);
  4832. }
  4833. public void get_erp_pdddeliveryed()
  4834. {
  4835. DataStruct dStruct = GetPostStruct();
  4836. List<string> lw = new List<string>();
  4837. string tid = GetPostString("ctid");
  4838. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4839. string shopname = GetPostString("shopname");
  4840. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4841. string buyernick = GetPostString("buyer_nick");
  4842. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4843. string customer = GetPostString("customer");
  4844. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4845. string design = GetPostString("design");
  4846. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4847. string sellermemo = GetPostString("seller_memo");
  4848. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4849. string logistics = GetPostString("logistics");
  4850. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4851. string date1 = GetPostString("date1");
  4852. string date2 = GetPostString("date2");
  4853. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4854. //if (dw.Length > 0) lw.Add(dw);
  4855. string placedate1 = GetPostString("placedate1");
  4856. string placedate2 = GetPostString("placedate2");
  4857. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4858. if (fdw.Length > 0) lw.Add(fdw);
  4859. string devdate1 = GetPostString("deliverydate1");
  4860. string devdate2 = GetPostString("deliverydate2");
  4861. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4862. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4863. string price1 = GetPostString("price1");
  4864. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4865. string price2 = GetPostString("price2");
  4866. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4867. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4868. {
  4869. if (tid.Length > 0)
  4870. {
  4871. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4872. if (tid.Length > 5)
  4873. {
  4874. List<string> tids = getTidByCtidLike(tid);
  4875. if (tids.Count > 0 && tids.Count < 10)
  4876. {
  4877. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4878. }
  4879. }
  4880. lw.Add(tid_sql);
  4881. }
  4882. if (buyernick.Length > 0)
  4883. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4884. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4885. if (dw.Length > 0) lw.Add(dw);
  4886. }
  4887. else
  4888. {
  4889. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4890. }
  4891. string posTag = CurrentUser.UserPost.Post.Code;
  4892. if (posTag == "Supplier")
  4893. {
  4894. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4895. }
  4896. else
  4897. {
  4898. string supplier = GetPostString("supplier");
  4899. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4900. }
  4901. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4902. lw.Add(string.Format("type = 'PDD' "));
  4903. lw.Add(string.Format("IsRefund!={0}", 2));
  4904. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4905. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4906. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4907. /* if (tid.Length > 0)
  4908. {
  4909. List<string> tids = new List<string>();
  4910. if (dt != null && dt.Rows.Count > 0)
  4911. {
  4912. foreach (DataRow item in dt.Rows)
  4913. {
  4914. tids.Add("'" + item["tid"] + "'");
  4915. }
  4916. }
  4917. if (tids.Count > 0)
  4918. {
  4919. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4920. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4921. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4922. dt = WebCache.GetData("view_erptradecell", dStruct);
  4923. }
  4924. }*/
  4925. foreach (DataRow dr in dt.Rows)
  4926. {
  4927. 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();
  4928. }
  4929. writeGridDataTableJson(dStruct.TotalCount, dt);
  4930. }
  4931. public void get_erp_jddeliveryed()
  4932. {
  4933. DataStruct dStruct = GetPostStruct();
  4934. List<string> lw = new List<string>();
  4935. string tid = GetPostString("ctid");
  4936. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4937. string shopname = GetPostString("shopname");
  4938. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4939. string buyernick = GetPostString("buyer_nick");
  4940. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4941. string customer = GetPostString("customer");
  4942. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4943. string design = GetPostString("design");
  4944. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4945. string sellermemo = GetPostString("seller_memo");
  4946. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4947. string date1 = GetPostString("date1");
  4948. string date2 = GetPostString("date2");
  4949. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4950. //if (dw.Length > 0) lw.Add(dw);
  4951. string placedate1 = GetPostString("placedate1");
  4952. string placedate2 = GetPostString("placedate2");
  4953. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4954. if (fdw.Length > 0) lw.Add(fdw);
  4955. string devdate1 = GetPostString("deliverydate1");
  4956. string devdate2 = GetPostString("deliverydate2");
  4957. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4958. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4959. string price1 = GetPostString("price1");
  4960. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4961. string price2 = GetPostString("price2");
  4962. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4963. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4964. {
  4965. if (tid.Length > 0)
  4966. lw.Add(string.Format("ctid like '%{0}%'", tid));
  4967. if (buyernick.Length > 0)
  4968. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4969. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4970. if (dw.Length > 0) lw.Add(dw);
  4971. }
  4972. else
  4973. {
  4974. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4975. }
  4976. string posTag = CurrentUser.UserPost.Post.Code;
  4977. if (posTag == "Supplier")
  4978. {
  4979. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4980. }
  4981. else
  4982. {
  4983. string supplier = GetPostString("supplier");
  4984. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4985. }
  4986. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4987. lw.Add(string.Format("type = 'JD' "));
  4988. lw.Add(string.Format("IsRefund!={0}", 2));
  4989. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4990. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4991. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4992. foreach (DataRow dr in dt.Rows)
  4993. {
  4994. 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();
  4995. }
  4996. writeGridDataTableJson(dStruct.TotalCount, dt);
  4997. }
  4998. public void get_erp_allplacelist()
  4999. {
  5000. DataStruct dStruct = GetPostStruct();
  5001. List<string> lw = new List<string>();
  5002. string tid = GetPostString("ctid");
  5003. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5004. string shopname = GetPostString("shopname");
  5005. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5006. string buyernick = GetPostString("buyer_nick");
  5007. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5008. string customer = GetPostString("customer");
  5009. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5010. string design = GetPostString("design");
  5011. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5012. string sellermemo = GetPostString("seller_memo");
  5013. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5014. string supplier = GetPostString("supplier");
  5015. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5016. string date1 = GetPostString("date1");
  5017. string date2 = GetPostString("date2");
  5018. string pldate1 = GetPostString("placedate1");
  5019. string pldate2 = GetPostString("placedate2");
  5020. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5021. //if (dw.Length > 0) lw.Add(dw);
  5022. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5023. {
  5024. if (tid.Length > 0)
  5025. {
  5026. string select_tid = getTidByCtid(tid);
  5027. lw.Add(string.Format("tid='{0}'", select_tid));
  5028. }
  5029. if (buyernick.Length > 0)
  5030. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5031. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5032. if (dw.Length > 0) lw.Add(dw);
  5033. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5034. if (dw_place.Length > 0) lw.Add(dw_place);
  5035. }
  5036. else
  5037. {
  5038. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5039. {
  5040. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5041. }
  5042. }
  5043. string price1 = GetPostString("price1");
  5044. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5045. string price2 = GetPostString("price2");
  5046. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5047. string posTag = CurrentUser.UserPost.Post.Code;
  5048. if (posTag == "Supplier")
  5049. {
  5050. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5051. }
  5052. lw.Add(string.Format("OrderState >= 6"));
  5053. lw.Add(string.Format("IsSample != 2 "));
  5054. //lw.Add(string.Format("isDianziOrder = 0 "));
  5055. lw.Add(string.Format("SupplierId > 0 "));
  5056. //lw.Add(string.Format("IsRefund<={0}", 1));
  5057. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5058. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5059. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5060. foreach (DataRow dr in dt.Rows)
  5061. {
  5062. 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();
  5063. }
  5064. writeGridDataTableJson(dStruct.TotalCount, dt);
  5065. }
  5066. public void get_erp_financeallplacelist()
  5067. {
  5068. DataStruct dStruct = GetPostStruct();
  5069. List<string> lw = new List<string>();
  5070. string tid = GetPostString("ctid");
  5071. string shopname = GetPostString("shopname");
  5072. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5073. string buyernick = GetPostString("buyer_nick");
  5074. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5075. string customer = GetPostString("customer");
  5076. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5077. string design = GetPostString("design");
  5078. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5079. string sellermemo = GetPostString("seller_memo");
  5080. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5081. string supplier = GetPostString("supplier");
  5082. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5083. string date1 = GetPostString("date1");
  5084. string date2 = GetPostString("date2");
  5085. string pldate1 = GetPostString("placedate1");
  5086. string pldate2 = GetPostString("placedate2");
  5087. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5088. {
  5089. if (tid.Length > 0)
  5090. {
  5091. string select_tid = getTidByCtid(tid);
  5092. lw.Add(string.Format("tid='{0}'", select_tid));
  5093. }
  5094. if (buyernick.Length > 0)
  5095. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5096. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5097. if (dw.Length > 0) lw.Add(dw);
  5098. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5099. if (dw_place.Length > 0) lw.Add(dw_place);
  5100. }
  5101. else
  5102. {
  5103. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5104. {
  5105. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5106. }
  5107. }
  5108. string price1 = GetPostString("price1");
  5109. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5110. string price2 = GetPostString("price2");
  5111. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5112. string posTag = CurrentUser.UserPost.Post.Code;
  5113. if (posTag == "Supplier")
  5114. {
  5115. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5116. }
  5117. //lw.Add(string.Format("OrderState >= 6"));
  5118. lw.Add(string.Format("IsSample != 2 "));
  5119. lw.Add(string.Format("isDianziOrder = 0 "));
  5120. //lw.Add(string.Format("IsRefund<={0}", 1));
  5121. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5122. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5123. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5124. foreach (DataRow dr in dt.Rows)
  5125. {
  5126. 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();
  5127. }
  5128. writeGridDataTableJson(dStruct.TotalCount, dt);
  5129. }
  5130. public void get_erp_expresslist()
  5131. {
  5132. int listtype = GetInt("ltype");
  5133. DataStruct dStruct = GetPostStruct();
  5134. List<string> lw = new List<string>();
  5135. string tid = GetPostString("tid");
  5136. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5137. string outsid = GetPostString("out_sid");
  5138. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5139. string importer = GetPostString("ImportUserName");
  5140. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5141. string file = GetPostString("import_file");
  5142. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5143. string printman = GetPostString("printman");
  5144. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5145. string date1 = GetPostString("date1");
  5146. string date2 = GetPostString("date2");
  5147. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5148. if (dw.Length > 0) lw.Add(dw);
  5149. string fdate1 = GetPostString("finishdate1");
  5150. string fdate2 = GetPostString("finishdate2");
  5151. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5152. if (fdw.Length > 0) lw.Add(fdw);
  5153. string supplierId = GetPostString("supplierId");
  5154. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5155. if (listtype == 1)
  5156. {
  5157. lw.Add(string.Format("importUserId !=0"));
  5158. }
  5159. string posTag = CurrentUser.UserPost.Post.Code;
  5160. if (posTag == "Supplier")
  5161. {
  5162. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5163. }
  5164. if (dStruct.PageSize != 100000)
  5165. {
  5166. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5167. }
  5168. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5169. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5170. writeGridDataTableJson(dStruct.TotalCount, dt);
  5171. }
  5172. public void set_erp_buchaorderdelivery()
  5173. {
  5174. if (UrlPostParmsCheck("ctid"))
  5175. {
  5176. string eid = GetPostString("ctid");
  5177. CeErpTradeCell entity = null;
  5178. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5179. if (entity != null)
  5180. {
  5181. if (entity.IsSample != 2)
  5182. {
  5183. returnErrorMsg("补差价单才能标记为已发货");
  5184. return;
  5185. }
  5186. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5187. entity.OrderState = 7;
  5188. entity.Update();
  5189. returnSuccessMsg("操作成功!");
  5190. return;
  5191. }
  5192. returnErrorMsg("找不到记录");
  5193. }
  5194. }
  5195. public void get_stdtemplates()
  5196. {
  5197. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5198. //string res = taobaoHelper.test();
  5199. string res = apiHelper.API_PrintTemplate();
  5200. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5201. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5202. {
  5203. int sidx = res.IndexOf("error_code");
  5204. int eidx = res.IndexOf("success");
  5205. string msg = res.Substring(sidx, eidx - sidx);
  5206. returnErrorMsg(msg);
  5207. return;
  5208. }
  5209. if (res.Length <= 0)
  5210. {
  5211. returnErrorMsg("模板数据为空!");
  5212. return;
  5213. }
  5214. ReturnSuccess(res);
  5215. }
  5216. public void cancel_print_order()
  5217. {
  5218. if (UrlPostParmsCheck("ctid"))
  5219. {
  5220. string ctid = GetPostString("ctid");
  5221. CeErpTradeCell entity = null;
  5222. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5223. if (entity != null)
  5224. {
  5225. string res = "";
  5226. string code = entity.LastBillWaybillCode;
  5227. if (code == "")
  5228. {
  5229. code = entity.OutSid;
  5230. }
  5231. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5232. XLog.SaveLog(0, "取消面单" + res);
  5233. }
  5234. }
  5235. }
  5236. public void set_erp_printwaybill()
  5237. {
  5238. if (UrlPostParmsCheck("ctid"))
  5239. {
  5240. string ctid = GetPostString("ctid");
  5241. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5242. string cpName = GetPostString("cpname");
  5243. string isTogether = GetPostString("together");
  5244. //var res_obj = new
  5245. //{
  5246. // restype = 1,
  5247. // 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\"}"
  5248. //};
  5249. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5250. //ReturnSuccess(ro_json);
  5251. //return;
  5252. bool isUseLastWayBillCode = false;
  5253. CeErpTradeCell entity = null;
  5254. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5255. if (entity != null)
  5256. {
  5257. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5258. {
  5259. isUseLastWayBillCode = true;
  5260. }
  5261. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5262. {
  5263. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5264. return;
  5265. }
  5266. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5267. {
  5268. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5269. return;
  5270. }
  5271. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5272. {
  5273. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5274. return;
  5275. }
  5276. }
  5277. string res = "";
  5278. Api_waybill_code_response_Obj fullObj = null;
  5279. string pData_str = "";
  5280. string curUseWayBillCode = "";
  5281. if (isUseLastWayBillCode == false)
  5282. {
  5283. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5284. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5285. if (res.IndexOf("failure") != -1)
  5286. {
  5287. //int idx = res.IndexOf("sub_message");
  5288. //int idx2 = res.IndexOf("flag");
  5289. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5290. string errMsgNeed = commonHelper.KeepChinese(res);
  5291. var res_objd = new
  5292. {
  5293. restype = 0,
  5294. data = "获取面单失败" + errMsgNeed
  5295. };
  5296. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5297. returnSuccess(ro_jsond);
  5298. if (res.IndexOf("停发") != -1)
  5299. {
  5300. entity.UnusualCon = "物流停发";
  5301. entity.Update();
  5302. }
  5303. //returnErrorMsg("获取面单失败,"+emsg);
  5304. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5305. return;
  5306. }
  5307. else if (res.IndexOf("errorMsg") != -1)
  5308. {
  5309. //int idx = res.IndexOf("errorMsg");
  5310. //int idx2 = res.IndexOf("}]}");
  5311. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5312. string errMsgNeed = commonHelper.KeepChinese(res);
  5313. var res_objf = new
  5314. {
  5315. restype = 0,
  5316. data = "获取面单失败2" + errMsgNeed
  5317. };
  5318. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5319. if (res.IndexOf("停发") != -1)
  5320. {
  5321. entity.UnusualCon = "物流停发";
  5322. entity.Update();
  5323. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5324. if (trade != null)
  5325. {
  5326. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5327. }
  5328. }
  5329. returnSuccess(ro_jsonf);
  5330. //returnErrorMsg("获取面单失败," + emsg);
  5331. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5332. return;
  5333. }
  5334. try
  5335. {
  5336. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5337. //res = res.Replace(" ", "");
  5338. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5339. }
  5340. catch (Exception ex)
  5341. {
  5342. XLog.SaveLog(0, "生成fullObj" + res);
  5343. var res_objf = new
  5344. {
  5345. restype = 0,
  5346. data = "生成fullObj发生错误" + ex.Message
  5347. };
  5348. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5349. returnSuccess(ro_jsonf);
  5350. return;
  5351. }
  5352. if (fullObj.response.data.content.Count > 0)
  5353. {
  5354. ContentItem codeObj = fullObj.response.data.content[0];
  5355. if (cpCode.IndexOf("SFFQ-") != -1)
  5356. {
  5357. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5358. }
  5359. else
  5360. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5361. curUseWayBillCode = codeObj.waybillCode;
  5362. }
  5363. else
  5364. {
  5365. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5366. var res_objf = new
  5367. {
  5368. restype = 0,
  5369. data = "生成fullObj找不到快递单号waybillCode"
  5370. };
  5371. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5372. returnSuccess(ro_jsonf);
  5373. return;
  5374. }
  5375. }
  5376. else
  5377. {
  5378. //使用上次打印的快递单号
  5379. if (cpCode == "SFFQ-LY")
  5380. {
  5381. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5382. }
  5383. else
  5384. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5385. curUseWayBillCode = entity.LastBillWaybillCode;
  5386. }
  5387. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5388. {
  5389. var res_obje = new
  5390. {
  5391. restype = 0,
  5392. data = "获取加密打印数据失败"
  5393. };
  5394. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5395. returnSuccess(ro_jsone);
  5396. entity.LastBillCpCode = cpCode;
  5397. entity.LastBillWaybillCode = curUseWayBillCode;
  5398. entity.Update();
  5399. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5400. //returnErrorMsg("获取加密打印数据失败");
  5401. return;
  5402. }
  5403. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5404. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5405. string btnType = "";
  5406. string errorMsg = "";
  5407. if (entity != null)
  5408. {
  5409. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5410. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5411. //cpcode是 YTO-CAINIAO
  5412. //string comCode = cpCode.Split('-')[0].ToString();
  5413. string apires = "";
  5414. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5415. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5416. {
  5417. if (ctid.IndexOf("N") != -1)
  5418. {
  5419. apires = "发货成功";
  5420. }
  5421. else
  5422. {
  5423. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5424. }
  5425. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5426. //打单后发货
  5427. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5428. {
  5429. try
  5430. {
  5431. btnType = "待发货";
  5432. entity.OutSid = curUseWayBillCode;
  5433. entity.OrderState = 7;
  5434. entity.IsUrgency = false;
  5435. entity.LastBillCpCode = "";
  5436. entity.LastBillWaybillCode = "";
  5437. entity.FinishDeliveryTime = DateTime.Now;
  5438. entity.IsReturn = 0;
  5439. entity.MemoOpt = 0;
  5440. entity.UpdateTime = DateTime.Now;
  5441. entity.Update();
  5442. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5443. //还要插入快递信息到 快递信息表
  5444. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5445. exinfo.tid = entity.ctid;
  5446. exinfo.out_sid = curUseWayBillCode;
  5447. exinfo.company_code = cpCode;
  5448. exinfo.company_name = cpName;
  5449. exinfo.supplierUserName = supplierName;
  5450. exinfo.deliveryType = "发货成功";
  5451. exinfo.print_time = DateTime.Now;
  5452. exinfo.printUser = CurrentUser.UserName;
  5453. exinfo.postData = pData_str;
  5454. exinfo.Create();
  5455. commonHelper.UpdateRelationOrder(entity.ctid);
  5456. CeErpSukuraData.createInfo(ctid, 4);
  5457. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5458. if (entity.SupplierId == 64)
  5459. {
  5460. commonHelper.sendCytExpress(exinfo);
  5461. }
  5462. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5463. if (!string.IsNullOrEmpty(isTogether))
  5464. {
  5465. if (Convert.ToInt32(isTogether) > 0)
  5466. {
  5467. StringBuilder sqlsb = new StringBuilder();
  5468. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}' where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5469. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5470. }
  5471. }
  5472. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5473. }
  5474. catch (Exception ex)
  5475. {
  5476. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5477. }
  5478. }
  5479. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5480. {
  5481. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5482. if (entity.OrderState == 6)
  5483. {
  5484. entity.OrderState = 7;
  5485. }
  5486. entity.UpdateTime = DateTime.Now;
  5487. entity.FinishDeliveryTime = DateTime.Now;
  5488. btnType = "已发货";
  5489. entity.Update();
  5490. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5491. exinfo.tid = entity.ctid;
  5492. exinfo.out_sid = curUseWayBillCode;
  5493. exinfo.company_code = cpCode;
  5494. exinfo.company_name = cpName;
  5495. exinfo.supplierUserName = supplierName;
  5496. exinfo.deliveryType = "发货成功";
  5497. exinfo.print_time = DateTime.Now;
  5498. exinfo.printUser = CurrentUser.UserName;
  5499. exinfo.postData = pData_str;
  5500. exinfo.Create();
  5501. commonHelper.UpdateRelationOrder(entity.ctid);
  5502. CeErpSukuraData.createInfo(entity.ctid, 4);
  5503. if (entity.SupplierId == 64)
  5504. {
  5505. commonHelper.sendCytExpress(exinfo);
  5506. }
  5507. if (!string.IsNullOrEmpty(isTogether))
  5508. {
  5509. if (Convert.ToInt32(isTogether) > 0)
  5510. {
  5511. StringBuilder sqlsb = new StringBuilder();
  5512. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}',FinishDeliveryTime=GETDATE(),UpdateTime=GETDATE() where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5513. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5514. }
  5515. }
  5516. //不处理
  5517. }
  5518. else
  5519. {
  5520. entity.UpdateTime = DateTime.Now;
  5521. entity.LastBillCpCode = cpCode;
  5522. entity.LastBillWaybillCode = curUseWayBillCode;
  5523. entity.Update();
  5524. string errmsg = commonHelper.KeepChinese(apires);
  5525. var res_objz = new
  5526. {
  5527. restype = 0,
  5528. data = "打单后发货失败"
  5529. };
  5530. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5531. returnSuccess(ro_jsonz);
  5532. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5533. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5534. return;
  5535. }
  5536. }
  5537. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5538. {
  5539. StringBuilder allSql = new StringBuilder();
  5540. allSql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,tid from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  5541. if (string.IsNullOrEmpty(mainEn.receiverId))
  5542. {
  5543. allSql.AppendFormat(" and (tid='{0}');", entity.tid);
  5544. }
  5545. else
  5546. {
  5547. //查询同车间同状态下的收货地址相同的单子
  5548. allSql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}') );", entity.tid, mainEn.receiverId, entity.IsSF);
  5549. }
  5550. DataTable dt = DbHelper.DbConn.ExecuteDataset(allSql.ToString()).Tables[0];
  5551. List<string> list = new List<string>();
  5552. List<string> send_list = new List<string>();
  5553. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5554. CeErpTrade ceErpTrade = new CeErpTrade();
  5555. foreach (DataRow row in dt.Rows)
  5556. {
  5557. list.Add("'" + row["ctid"] + "'");
  5558. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5559. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5560. if (ctid.IndexOf("N") != -1)
  5561. {
  5562. apires = "发货成功";
  5563. }
  5564. else
  5565. {
  5566. if (!send_list.Contains(ceErpTrade.tid))
  5567. {
  5568. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5569. }
  5570. else
  5571. {
  5572. apires = "发货成功";
  5573. }
  5574. }
  5575. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5576. {
  5577. send_list.Add(ceErpTrade.tid);
  5578. try
  5579. {
  5580. btnType = "待发货";
  5581. ceErpTradeCell.OutSid = curUseWayBillCode;
  5582. ceErpTradeCell.OrderState = 7;
  5583. ceErpTradeCell.IsUrgency = false;
  5584. ceErpTradeCell.LastBillCpCode = "";
  5585. ceErpTradeCell.LastBillWaybillCode = "";
  5586. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5587. ceErpTradeCell.IsReturn = 0;
  5588. ceErpTradeCell.MemoOpt = 0;
  5589. ceErpTradeCell.UpdateTime = DateTime.Now;
  5590. ceErpTradeCell.Update();
  5591. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5592. //还要插入快递信息到 快递信息表
  5593. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5594. exinfo.tid = ceErpTradeCell.ctid;
  5595. exinfo.out_sid = curUseWayBillCode;
  5596. exinfo.company_code = cpCode;
  5597. exinfo.company_name = cpName;
  5598. exinfo.supplierUserName = supplierName;
  5599. exinfo.deliveryType = "发货成功";
  5600. exinfo.print_time = DateTime.Now;
  5601. exinfo.printUser = CurrentUser.UserName;
  5602. exinfo.postData = pData_str;
  5603. exinfo.Create();
  5604. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5605. CeErpSukuraData.createInfo(ctid, 4);
  5606. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5607. if (ceErpTradeCell.SupplierId == 64)
  5608. {
  5609. commonHelper.sendCytExpress(exinfo);
  5610. }
  5611. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5612. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5613. }
  5614. catch (Exception ex)
  5615. {
  5616. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5617. }
  5618. }
  5619. else
  5620. {
  5621. ceErpTradeCell.UpdateTime = DateTime.Now;
  5622. ceErpTradeCell.LastBillCpCode = cpCode;
  5623. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5624. ceErpTradeCell.Update();
  5625. string errmsg = commonHelper.KeepChinese(apires);
  5626. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5627. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5628. }
  5629. }
  5630. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5631. }
  5632. }
  5633. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5634. var res_obj = new
  5635. {
  5636. restype = 1,
  5637. data = pData_str,
  5638. errorMsg
  5639. };
  5640. string ro_json = JsonConvert.SerializeObject(res_obj);
  5641. ReturnSuccess(ro_json);
  5642. return;
  5643. }
  5644. }
  5645. private string GetUTF8String(byte[] vs)
  5646. {
  5647. throw new NotImplementedException();
  5648. }
  5649. public void set_erp_printwaybill_cn()
  5650. {
  5651. if (UrlPostParmsCheck("ctid"))
  5652. {
  5653. string ctid = GetPostString("ctid");
  5654. string cpCode = GetPostString("cpcode");
  5655. string cpName = GetPostString("cpname");
  5656. string tempUrl = GetPostString("tempurl");
  5657. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5658. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5659. //string res = taobaoHelper.test();
  5660. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5661. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5662. {
  5663. int sidx = res.IndexOf("errorMsg");
  5664. int eidx = res.IndexOf("}");
  5665. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5666. var res_objzxx = new
  5667. {
  5668. restype = 0,
  5669. data = msg
  5670. };
  5671. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5672. returnSuccess(ro_jsonzxx);
  5673. //returnErrorMsg(msg);
  5674. return;
  5675. }
  5676. int idx = res.IndexOf("waybillCode");
  5677. int idx2 = res.IndexOf("printData");
  5678. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5679. string eid = GetPostString("ctid");
  5680. CeErpTradeCell entity = null;
  5681. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5682. if (entity != null)
  5683. {
  5684. string osid = entity.OutSid;
  5685. entity.OutSid = osid + "," + outsid;
  5686. entity.FinishDeliveryTime = DateTime.Now;
  5687. entity.OrderState = 7;
  5688. entity.UpdateTime = DateTime.Now;
  5689. entity.IsReturn = 0;
  5690. entity.Update();
  5691. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5692. exinfo.tid = entity.ctid;
  5693. exinfo.out_sid = outsid;
  5694. exinfo.company_code = cpCode;
  5695. exinfo.company_name = cpName;
  5696. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5697. exinfo.deliveryType = "发货成功";
  5698. exinfo.print_time = DateTime.Now;
  5699. exinfo.printUser = CurrentUser.UserName;
  5700. exinfo.Create();
  5701. if (entity.SupplierId == 64)
  5702. {
  5703. commonHelper.sendCytExpress(exinfo);
  5704. }
  5705. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5706. }
  5707. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5708. var res_objz = new
  5709. {
  5710. restype = 1,
  5711. data = res
  5712. };
  5713. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5714. returnSuccess(ro_jsonz);
  5715. //ReturnSuccess(res);
  5716. }
  5717. }
  5718. ////打单,打印面单 获取面单号
  5719. //public void set_erp_printwaybill()
  5720. //{
  5721. // if (UrlPostParmsCheck("ctid"))
  5722. // {
  5723. // string ctid = GetPostString("ctid");
  5724. // string cpCode = GetPostString("cpcode");
  5725. // string tempUrl = GetPostString("tempurl");
  5726. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5727. // //string res = taobaoHelper.test();
  5728. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5729. // if (res.IndexOf("error_response") != -1)
  5730. // {
  5731. // int sidx = res.IndexOf("sub_msg");
  5732. // int eidx = res.IndexOf("request_id");
  5733. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5734. // returnErrorMsg(msg);
  5735. // return;
  5736. // }
  5737. // int idx = res.IndexOf("waybill_code");
  5738. // int idx2 = res.IndexOf("}]}");
  5739. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5740. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5741. // ReturnSuccess(res);
  5742. // }
  5743. //}
  5744. public void cancel_erp_aftersale()
  5745. {
  5746. if (UrlPostParmsCheck("ctid"))
  5747. {
  5748. string eid = GetPostString("ctid");
  5749. CeErpTradeCell entity = null;
  5750. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5751. if (entity != null)
  5752. {
  5753. //有过处理的售后,取消也不能删除 售 字,保留
  5754. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5755. {
  5756. entity.AfterSaleState = 4;
  5757. }
  5758. else
  5759. entity.AfterSaleState = 0;
  5760. entity.UpdateTime = DateTime.Now;
  5761. entity.Update();
  5762. returnSuccessMsg("操作成功!");
  5763. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5764. return;
  5765. }
  5766. returnErrorMsg("找不到订单记录");
  5767. }
  5768. }
  5769. public void get_erp_aftersalelist()
  5770. {
  5771. DataStruct dStruct = GetPostStruct();
  5772. List<string> lw = new List<string>();
  5773. int st = GetInt("st");
  5774. string tid = GetPostString("ctid");
  5775. if (st == 3)
  5776. {
  5777. if (tid.Length > 0)
  5778. {
  5779. string select_tid = getTidByCtid(tid);
  5780. lw.Add(string.Format("tid='{0}'", select_tid));
  5781. }
  5782. }
  5783. else
  5784. {
  5785. if (tid.Length > 0)
  5786. {
  5787. string select_tid = getTidByCtid(tid);
  5788. lw.Add(string.Format("tid='{0}'", select_tid));
  5789. }
  5790. }
  5791. string shopname = GetPostString("shopname");
  5792. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5793. string buyernick = GetPostString("buyer_nick");
  5794. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5795. string sellermemo = GetPostString("seller_memo");
  5796. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5797. string orderState = GetPostString("orderState");
  5798. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5799. string afterState = GetPostString("afterstate");
  5800. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5801. string date1 = GetPostString("date1");
  5802. string date2 = GetPostString("date2");
  5803. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5804. if (dw.Length > 0) lw.Add(dw);
  5805. string price1 = GetPostString("price1");
  5806. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5807. string price2 = GetPostString("price2");
  5808. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5809. //lw.Add(string.Format("IsRefund!={0}", 1));
  5810. string reason = GetPostString("reason");
  5811. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5812. string method = GetPostString("method");
  5813. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5814. string handler = GetPostString("handler");
  5815. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5816. string handledate1 = GetPostString("handledate1");
  5817. string handledate2 = GetPostString("handledate2");
  5818. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5819. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5820. string finish1 = GetPostString("finishdate1");
  5821. string finish2 = GetPostString("finishdate2");
  5822. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5823. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5824. string afterdate1 = GetPostString("afterdate1");
  5825. string afterdate2 = GetPostString("afterdate2");
  5826. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5827. if (afterDate.Length > 0) lw.Add(afterDate);
  5828. string supplier = GetPostString("supplier");
  5829. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5830. string responsible = GetPostString("responsibleman");
  5831. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5832. string customer = GetPostString("customer");
  5833. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5834. string design = GetPostString("design");
  5835. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5836. string afterMemoType = GetPostString("aftermemotype");
  5837. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5838. string posCode = CurrentUser.UserPost.Post.Code;
  5839. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5840. //{
  5841. // string vstate = GetPostString("vstate");
  5842. // if (vstate.Length > 0)
  5843. // {
  5844. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5845. // }
  5846. // if (posCode == "Supplier")
  5847. // {
  5848. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5849. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5850. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5851. // }
  5852. // else
  5853. // {
  5854. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5855. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5856. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5857. // {
  5858. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5859. // }
  5860. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5861. // {
  5862. // int orgid = CurrentUser.UserPost.OrgID;
  5863. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5864. // }
  5865. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5866. // {
  5867. // string shopid = CurrentUser.User.pemShop;
  5868. // lw.Add(string.Format("shopId in ({0})", shopid));
  5869. // }
  5870. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5871. // //{
  5872. // // int org_id = CurrentUser.UserPost.OrgID;
  5873. // // lw.Add(string.Format("OrgID={0}", org_id));
  5874. // //}
  5875. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5876. // }
  5877. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5878. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5879. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5880. //}
  5881. if (st == 5)
  5882. {
  5883. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5884. {
  5885. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5886. {
  5887. string shopid = CurrentUser.User.pemShop;
  5888. lw.Add(string.Format("shopId in ({0})", shopid));
  5889. }
  5890. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5891. {
  5892. int mrOrgid = CurrentUser.UserPost.OrgID;
  5893. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5894. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5895. }
  5896. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5897. //{
  5898. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5899. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5900. //}
  5901. else
  5902. {
  5903. string userIdStr = "";
  5904. if (posCode == "CustomerService")
  5905. {
  5906. userIdStr = CurrentUser.UserID + "_k";
  5907. }
  5908. else if (posCode == "Designer" || posCode == "wxDesigner")
  5909. {
  5910. userIdStr = CurrentUser.UserID + "_s";
  5911. }
  5912. else if (posCode == "Place")
  5913. {
  5914. userIdStr = CurrentUser.UserID + "_x";
  5915. }
  5916. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5917. }
  5918. }
  5919. string placedate1 = GetPostString("placedate1");
  5920. string placedate2 = GetPostString("placedate2");
  5921. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5922. if (dwplace.Length > 0) lw.Add(dwplace);
  5923. string supState = GetPostString("supState");
  5924. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  5925. string searchType = GetPostString("searchType");
  5926. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  5927. {
  5928. lw.Add(string.Format("BackNum>1"));
  5929. }
  5930. lw.Add(string.Format("AfterSaleState>0"));
  5931. if (ex_psize > 0)
  5932. {
  5933. if (CurrentUser.UserPost.Post.Code == "Finance")
  5934. dStruct.Order = "pay_time desc";
  5935. else
  5936. dStruct.Order = "HandleTime desc";
  5937. }
  5938. else
  5939. dStruct.Order = "HandleTime desc";
  5940. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5941. DataTable dt = WebCache.GetData("view_test", dStruct);
  5942. writeGridDataTableJson(dStruct.TotalCount, dt);
  5943. }
  5944. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  5945. //{
  5946. // lw.Add(string.Format("AfterSaleState=4"));
  5947. // string code = CurrentUser.UserPost.Post.Code;
  5948. // if (code == "CustomerService")
  5949. // {
  5950. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  5951. // }
  5952. // else if (code == "Designer" || code == "DesignerMr")
  5953. // {
  5954. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  5955. // }
  5956. // else if (code == "Place" || code == "PlaceMr")
  5957. // {
  5958. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  5959. // }
  5960. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5961. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5962. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5963. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5964. //}
  5965. //else //处理中的售后,待处理和处理中合并
  5966. //{
  5967. // if (afterState.Length <= 0)
  5968. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  5969. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5970. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5971. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5972. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5973. //}
  5974. }
  5975. public void get_erp_disagreeftersalelist()
  5976. {
  5977. DataStruct dStruct = GetPostStruct();
  5978. List<string> lw = new List<string>();
  5979. int st = 2;
  5980. string tid = GetPostString("ctid");
  5981. if (tid.Length > 0)
  5982. {
  5983. string select_tid = getTidByCtid(tid);
  5984. lw.Add(string.Format("tid='{0}'", select_tid));
  5985. }
  5986. string shopname = GetPostString("shopname");
  5987. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5988. string buyernick = GetPostString("buyer_nick");
  5989. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5990. string sellermemo = GetPostString("seller_memo");
  5991. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5992. string orderState = GetPostString("orderState");
  5993. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  5994. string afterState = GetPostString("afterstate");
  5995. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5996. string date1 = GetPostString("date1");
  5997. string date2 = GetPostString("date2");
  5998. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5999. if (dw.Length > 0) lw.Add(dw);
  6000. string price1 = GetPostString("price1");
  6001. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6002. string price2 = GetPostString("price2");
  6003. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6004. //lw.Add(string.Format("IsRefund!={0}", 1));
  6005. string reason = GetPostString("reason");
  6006. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6007. string method = GetPostString("method");
  6008. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6009. string handler = GetPostString("handler");
  6010. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6011. string handledate1 = GetPostString("handledate1");
  6012. string handledate2 = GetPostString("handledate2");
  6013. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6014. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6015. string afterdate1 = GetPostString("afterdate1");
  6016. string afterdate2 = GetPostString("afterdate2");
  6017. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6018. if (afterDate.Length > 0) lw.Add(afterDate);
  6019. string backdate1 = GetPostString("backdate1");
  6020. string backdate2 = GetPostString("backdate2");
  6021. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6022. if (backDate.Length > 0) lw.Add(backDate);
  6023. string supplier = GetPostString("supplier");
  6024. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6025. string responsible = GetPostString("responsibleman");
  6026. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6027. string customer = GetPostString("customer");
  6028. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6029. string design = GetPostString("design");
  6030. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6031. string afterSaleMemo = GetPostString("afterSaleMemo");
  6032. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6033. string afterMemoType = GetPostString("aftermemotype");
  6034. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6035. string aftersakereason = GetPostString("aftersakereason");
  6036. if (aftersakereason.Length > 0)
  6037. {
  6038. if (aftersakereason == "1")
  6039. {
  6040. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6041. }
  6042. if (aftersakereason == "2")
  6043. {
  6044. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6045. }
  6046. }
  6047. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6048. string poscode = CurrentUser.UserPost.Post.Code;
  6049. if (poscode != "SysAdmin")
  6050. {
  6051. string shopid = CurrentUser.User.pemShop;
  6052. lw.Add(string.Format("shopId in ({0})", shopid));
  6053. }
  6054. string searchType = GetPostString("searchType");
  6055. if (searchType == "wait")
  6056. {
  6057. lw.Add(string.Format("HandleTime is null"));
  6058. }
  6059. if (searchType == "handling")
  6060. {
  6061. lw.Add(string.Format("HandleTime is not null "));
  6062. }
  6063. if (searchType == "back" || searchType == "puBack")
  6064. {
  6065. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6066. }
  6067. if (searchType == "reBack")
  6068. {
  6069. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6070. }
  6071. if (searchType == "moreBack")
  6072. {
  6073. lw.Add(string.Format("backNum > 1"));
  6074. }
  6075. lw.Add(string.Format("(AfterSaleState=5)"));
  6076. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6077. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6078. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6079. writeGridDataTableJson(dStruct.TotalCount, dt);
  6080. }
  6081. public void get_erp_handlingaftersalelist()
  6082. {
  6083. DataStruct dStruct = GetPostStruct();
  6084. List<string> lw = new List<string>();
  6085. int st = 2;
  6086. string tid = GetPostString("ctid");
  6087. if (tid.Length > 0)
  6088. {
  6089. string select_tid = getTidByCtid(tid);
  6090. lw.Add(string.Format("tid='{0}'", select_tid));
  6091. }
  6092. string shopname = GetPostString("shopname");
  6093. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6094. string buyernick = GetPostString("buyer_nick");
  6095. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6096. string sellermemo = GetPostString("seller_memo");
  6097. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6098. string orderState = GetPostString("orderState");
  6099. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6100. string afterState = GetPostString("afterstate");
  6101. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6102. string date1 = GetPostString("date1");
  6103. string date2 = GetPostString("date2");
  6104. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6105. if (dw.Length > 0) lw.Add(dw);
  6106. string price1 = GetPostString("price1");
  6107. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6108. string price2 = GetPostString("price2");
  6109. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6110. //lw.Add(string.Format("IsRefund!={0}", 1));
  6111. string reason = GetPostString("reason");
  6112. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6113. string method = GetPostString("method");
  6114. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6115. string handler = GetPostString("handler");
  6116. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6117. string handledate1 = GetPostString("handledate1");
  6118. string handledate2 = GetPostString("handledate2");
  6119. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6120. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6121. string afterdate1 = GetPostString("afterdate1");
  6122. string afterdate2 = GetPostString("afterdate2");
  6123. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6124. if (afterDate.Length > 0) lw.Add(afterDate);
  6125. string supplier = GetPostString("supplier");
  6126. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6127. string responsible = GetPostString("responsibleman");
  6128. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6129. string customer = GetPostString("customer");
  6130. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6131. string design = GetPostString("design");
  6132. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6133. string afterSaleMemo = GetPostString("afterSaleMemo");
  6134. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6135. string afterMemoType = GetPostString("aftermemotype");
  6136. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6137. string afterresult = GetPostString("afterresult");
  6138. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6139. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6140. string poscode = CurrentUser.UserPost.Post.Code;
  6141. if (poscode != "SysAdmin")
  6142. {
  6143. string shopid = CurrentUser.User.pemShop;
  6144. lw.Add(string.Format("shopId in ({0})", shopid));
  6145. }
  6146. string searchType = GetPostString("searchType");
  6147. if (searchType == "wait")
  6148. {
  6149. lw.Add(string.Format("HandleTime is null"));
  6150. }
  6151. if (searchType == "documentary")
  6152. {
  6153. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6154. }
  6155. if (searchType == "handling")
  6156. {
  6157. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6158. }
  6159. if (searchType == "back" || searchType == "puBack")
  6160. {
  6161. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6162. }
  6163. if (searchType == "reBack")
  6164. {
  6165. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6166. }
  6167. if (afterState.Length <= 0)
  6168. {
  6169. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6170. }
  6171. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6172. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6173. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6174. writeGridDataTableJson(dStruct.TotalCount, dt);
  6175. }
  6176. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6177. //public void get_erp_back_handlingaftersalelist()
  6178. //{
  6179. // DataStruct dStruct = GetPostStruct();
  6180. // List<string> lw = new List<string>();
  6181. // string tid = GetPostString("ctid");
  6182. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6183. // string shopname = GetPostString("shopname");
  6184. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6185. // string buyernick = GetPostString("buyer_nick");
  6186. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6187. // string sellermemo = GetPostString("seller_memo");
  6188. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6189. // string orderState = GetPostString("orderState");
  6190. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6191. // string afterState = GetPostString("afterstate");
  6192. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6193. // string date1 = GetPostString("date1");
  6194. // string date2 = GetPostString("date2");
  6195. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6196. // if (dw.Length > 0) lw.Add(dw);
  6197. // string price1 = GetPostString("price1");
  6198. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6199. // string price2 = GetPostString("price2");
  6200. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6201. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6202. // string reason = GetPostString("reason");
  6203. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6204. // string method = GetPostString("method");
  6205. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6206. // string handler = GetPostString("handler");
  6207. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6208. // string handledate1 = GetPostString("handledate1");
  6209. // string handledate2 = GetPostString("handledate2");
  6210. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6211. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6212. // string afterdate1 = GetPostString("afterdate1");
  6213. // string afterdate2 = GetPostString("afterdate2");
  6214. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6215. // if (afterDate.Length > 0) lw.Add(afterDate);
  6216. // string supplier = GetPostString("supplier");
  6217. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6218. // string responsible = GetPostString("responsibleman");
  6219. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6220. // string customer = GetPostString("customer");
  6221. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6222. // string design = GetPostString("design");
  6223. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6224. // string afterMemoType = GetPostString("aftermemotype");
  6225. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6226. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6227. // if (afterState.Length <= 0)
  6228. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6229. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6230. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6231. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6232. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6233. //}
  6234. public void get_erp_aftersaleverifylist()
  6235. {
  6236. DataStruct dStruct = GetPostStruct();
  6237. List<string> lw = new List<string>();
  6238. string tid = GetPostString("ctid");
  6239. if (tid.Length > 0)
  6240. {
  6241. string select_tid = getTidByCtid(tid);
  6242. lw.Add(string.Format("tid='{0}'", select_tid));
  6243. }
  6244. string shopname = GetPostString("shopname");
  6245. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6246. string buyernick = GetPostString("buyer_nick");
  6247. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6248. string sellermemo = GetPostString("seller_memo");
  6249. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6250. string orderState = GetPostString("orderState");
  6251. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6252. //lw.Add(string.Format("IsRefund!={0}", 1));
  6253. string reason = GetPostString("reason");
  6254. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6255. string method = GetPostString("method");
  6256. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6257. string handler = GetPostString("handler");
  6258. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6259. string handledate1 = GetPostString("handledate1");
  6260. string handledate2 = GetPostString("handledate2");
  6261. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6262. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6263. string finish1 = GetPostString("finishdate1");
  6264. string finish2 = GetPostString("finishdate2");
  6265. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6266. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6267. string supplier = GetPostString("supplier");
  6268. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6269. string responsible = GetPostString("responsibleman");
  6270. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6271. string posCode = CurrentUser.UserPost.Post.Code;
  6272. string vstate = GetPostString("vstate");
  6273. if (vstate.Length > 0)
  6274. {
  6275. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6276. }
  6277. if (posCode == "Supplier")
  6278. {
  6279. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6280. lw.Add(string.Format("VerifyState = 0"));
  6281. lw.Add("type = 1");
  6282. lw.Add(string.Format("AfterSaleState={0}", 3));
  6283. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6284. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6285. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6286. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6287. writeGridDataTableJson(dStruct.TotalCount, dt);
  6288. }
  6289. else if (posCode == "logistics")
  6290. {
  6291. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6292. lw.Add(string.Format("VerifyState = 0"));
  6293. lw.Add("type = 2");
  6294. lw.Add(string.Format("AfterSaleState={0}", 3));
  6295. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6296. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6297. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6298. writeGridDataTableJson(dStruct.TotalCount, dt);
  6299. }
  6300. else
  6301. {
  6302. lw.Add(string.Format("(AfterSaleState = 3)"));
  6303. string reasonState = GetPostString("reasonState");
  6304. lw.Add("type = 0");
  6305. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6306. || posCode == "Summarize" || posCode == "Finance")
  6307. {
  6308. if (reasonState == "2")
  6309. {
  6310. lw.Add("VerifyState = 3");
  6311. }
  6312. else if (reasonState == "1")
  6313. {
  6314. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6315. }
  6316. else
  6317. {
  6318. lw.Add("VerifyState in (0,3)");
  6319. }
  6320. //不加条件,可以看全部
  6321. }
  6322. 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")
  6323. {
  6324. int orgid = CurrentUser.UserPost.OrgID;
  6325. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6326. if (string.IsNullOrEmpty(manageOrgId))
  6327. {
  6328. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6329. }
  6330. else
  6331. {
  6332. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6333. }
  6334. if (reasonState == "1")
  6335. {
  6336. lw.Add("VerifyState = 3");
  6337. }
  6338. else if (reasonState == "2")
  6339. {
  6340. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6341. }
  6342. else
  6343. {
  6344. }
  6345. }
  6346. else
  6347. {
  6348. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6349. }
  6350. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6351. //{
  6352. // int org_id = CurrentUser.UserPost.OrgID;
  6353. // lw.Add(string.Format("OrgID={0}", org_id));
  6354. //}
  6355. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6356. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6357. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6358. writeGridDataTableJson(dStruct.TotalCount, dt);
  6359. }
  6360. }
  6361. public void get_erp_finishaftersalelist()
  6362. {
  6363. DataStruct dStruct = GetPostStruct();
  6364. List<string> lw = new List<string>();
  6365. int st = 4;
  6366. string tid = GetPostString("ctid");
  6367. if (tid.Length > 0)
  6368. {
  6369. string select_tid = getTidByCtid(tid);
  6370. lw.Add(string.Format("tid='{0}'", select_tid));
  6371. }
  6372. string shopname = GetPostString("shopname");
  6373. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6374. //lw.Add(string.Format("IsRefund!={0}", 1));
  6375. string reason = GetPostString("reason");
  6376. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6377. string method = GetPostString("method");
  6378. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6379. string buyernick = GetPostString("buyer_nick");
  6380. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6381. string handler = GetPostString("handler");
  6382. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6383. string handledate1 = GetPostString("handledate1");
  6384. string handledate2 = GetPostString("handledate2");
  6385. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6386. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6387. string finish1 = GetPostString("finishdate1");
  6388. string finish2 = GetPostString("finishdate2");
  6389. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6390. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6391. string supplier = GetPostString("supplier");
  6392. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6393. string responsible = GetPostString("responsibleman");
  6394. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6395. string vstate = GetPostString("vstate");
  6396. if (vstate.Length > 0)
  6397. {
  6398. if ("3".Equals(vstate))
  6399. {
  6400. lw.Add(string.Format("IsTem=1"));
  6401. }
  6402. else
  6403. {
  6404. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6405. }
  6406. }
  6407. lw.Add(string.Format("AfterSaleState=4"));
  6408. string code = CurrentUser.UserPost.Post.Code;
  6409. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6410. {
  6411. //不加条件,可以看全部
  6412. }
  6413. else if (code == "Supplier")
  6414. {
  6415. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6416. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6417. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6418. }
  6419. else if (code == "logistics")
  6420. {
  6421. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6422. lw.Add("type = 2");
  6423. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6424. }
  6425. 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")
  6426. {
  6427. int orgid = CurrentUser.UserPost.OrgID;
  6428. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6429. if (string.IsNullOrEmpty(manageOrgIds))
  6430. {
  6431. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6432. }
  6433. else
  6434. {
  6435. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6436. }
  6437. }
  6438. else
  6439. {
  6440. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6441. }
  6442. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6443. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6444. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6445. writeGridDataTableJson(dStruct.TotalCount, dt);
  6446. }
  6447. public void handle_erp_aftersale()
  6448. {
  6449. if (UrlPostParmsCheck("ctid"))
  6450. {
  6451. string eid = GetPostString("ctid");
  6452. string responStr = GetPostString("AfterSaleResponsible");
  6453. if (responStr.Length <= 0)
  6454. {
  6455. returnErrorMsg("售后责任人不能为空");
  6456. return;
  6457. }
  6458. bool isDesign = false;
  6459. double designFree = 0.00;
  6460. int responsibleId = 0;
  6461. CeErpTradeCell entity = null;
  6462. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6463. if (entity != null)
  6464. {
  6465. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6466. string afterMethod = GetPostString("AfterSaleMethod");
  6467. if (isNeedNewOrder == 1)
  6468. {
  6469. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6470. bool ishav = true;
  6471. if (newentity == null)
  6472. {
  6473. newentity = entity.Clone() as CeErpTradeCell;
  6474. ishav = false;
  6475. newentity.ctid = "S_" + entity.ctid;
  6476. newentity.OrderState = 0;
  6477. //唯一标识
  6478. newentity.OrderSn = newentity.ctid;
  6479. string orderSn = dataHelper.getSaleOrderSn();
  6480. if (orderSn != "")
  6481. {
  6482. newentity.OrderSn = orderSn;
  6483. }
  6484. }
  6485. newentity.UpdateTime = DateTime.Now;
  6486. newentity.AfterSaleState = 0;
  6487. newentity.AfterSaleMethod = afterMethod;
  6488. if (!ishav)
  6489. {
  6490. string memo_str = newentity.seller_memo;
  6491. memo_str = memo_str.Replace("(", "(");
  6492. memo_str = memo_str.Replace(")", ")");
  6493. int sIndex = memo_str.IndexOf("(");
  6494. int eIndex = memo_str.IndexOf(")");
  6495. if (sIndex == -1 || eIndex == -1)
  6496. {
  6497. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6498. return;
  6499. }
  6500. string first = memo_str.Substring(0, sIndex + 1);
  6501. string memoCtid = newentity.OrderSn;
  6502. //if (memoCtid.IndexOf("C") != -1)
  6503. //{
  6504. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6505. //if (CIdx.IndexOf("+") != -1)
  6506. //{
  6507. //CIdx = "C" + CIdx.Split('+')[1];
  6508. //}
  6509. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6510. //}
  6511. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6512. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6513. string newMemo = first + memoCtid + last;
  6514. newentity.seller_memo = newMemo;
  6515. newentity.FinishPlaceTime = null;
  6516. newentity.UnusualTag = 0;
  6517. newentity.UnusualCon = "";
  6518. newentity.UnusualTime = null;
  6519. newentity.AfterSaleMemo = "";
  6520. newentity.AfterSaleMethod = afterMethod;
  6521. newentity.AfterSalePreTime = null;
  6522. newentity.AfterSaleReason = "";
  6523. newentity.AfterSaleResponsible = "";
  6524. newentity.AfterSaleState = 0;
  6525. newentity.AfterSaleTime = null;
  6526. newentity.AfterSaleUserId = 0;
  6527. newentity.AfterSaleSupplierState = 0;
  6528. newentity.LastBillWaybillCode = "";
  6529. newentity.LastBillCpCode = "";
  6530. newentity.FinishAfterSaleTime = null;
  6531. newentity.HandleTime = null;
  6532. newentity.IsSF = 0;
  6533. newentity.IsOldCustomer = 0;
  6534. newentity.UrgencyTime = null;
  6535. newentity.ResponsibleUserId = "";
  6536. newentity.IsVerifyToSupplier = false;
  6537. newentity.payment = 0;
  6538. newentity.CheckMemo = "";
  6539. newentity.OutSid = "";
  6540. newentity.CheckOrderTime = null;
  6541. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6542. }
  6543. newentity.isAfterSaleOrder = 1;
  6544. newentity.IsRefund = 0;
  6545. string receiveMobile = GetPostString("receiver_mobile");
  6546. if (receiveMobile.Length > 0)
  6547. {
  6548. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6549. if (trade != null)
  6550. {
  6551. trade.receiver_name = GetPostString("receiver_name");
  6552. trade.receiver_mobile = receiveMobile;
  6553. trade.receiver_state = GetPostString("receiver_state");
  6554. trade.receiver_city = GetPostString("receiver_city");
  6555. trade.receiver_district = GetPostString("receiver_district");
  6556. trade.receiver_address = GetPostString("receiver_address");
  6557. newentity.IsOffLineOrder = 1;
  6558. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6559. }
  6560. }
  6561. string st = GetPostString("ToState");
  6562. if (st.Length > 0)
  6563. {
  6564. if (newentity.OrderState <= 3)
  6565. {
  6566. newentity.WaitDesignTime = DateTime.Now;
  6567. newentity.StartDesignTime = null;
  6568. newentity.FinishDesignTime = null;
  6569. newentity.OrderState = 3;
  6570. if (st == "下单员")
  6571. {
  6572. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6573. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6574. {
  6575. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6576. }
  6577. }
  6578. else
  6579. {
  6580. newentity.WaitDesignTime = DateTime.Now;
  6581. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6582. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6583. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6584. {
  6585. DataRow user = dt1.Rows[0];
  6586. //找主管
  6587. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6588. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6589. if (dt != null && dt.Rows.Count > 0)
  6590. {
  6591. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6592. newentity.DesignUserId = designMr;
  6593. string key = "aftersale_order_" + designMr;
  6594. if (RedisHelper.HasKey(key))
  6595. {
  6596. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6597. list.Add(newentity.ctid);
  6598. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6599. }
  6600. }
  6601. //账号正常
  6602. if (user["State"].ToString() == "0")
  6603. {
  6604. newentity.DesignUserId = entity.DesignUserId;
  6605. string key = "aftersale_order_" + entity.DesignUserId;
  6606. if (RedisHelper.HasKey(key))
  6607. {
  6608. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6609. list.Add(newentity.ctid);
  6610. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6611. }
  6612. }
  6613. }
  6614. }
  6615. }
  6616. if (entity.IsXianHuo == 1)
  6617. {
  6618. newentity.OrderState = 6;
  6619. entity.FinishPlaceTime = DateTime.Now;
  6620. }
  6621. }
  6622. if (ishav)
  6623. {
  6624. newentity.Update();
  6625. }
  6626. else
  6627. {
  6628. newentity.Create();
  6629. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6630. newCellExtend.ctid = newentity.ctid;
  6631. newCellExtend.orderFrom = 20;
  6632. newCellExtend.orderType = 30;
  6633. if (st == "下单员")
  6634. {
  6635. }
  6636. else
  6637. {
  6638. newCellExtend.ReprintTime = DateTime.Now;
  6639. }
  6640. newCellExtend.Create();
  6641. }
  6642. if (st != "下单员")
  6643. {
  6644. designHelper.API_GetPrintData_CreateOrder(newentity);
  6645. }
  6646. }
  6647. //处理售后扩展
  6648. string resIdStr = GetPostString("ResponsibleUserId");
  6649. string refundFees = GetPostString("refundFrees");
  6650. int IsComplain = GetPostInt("isComplain");
  6651. int IsBad = GetPostInt("isBad");
  6652. string IsOriginal = GetPostString("isOriginal");
  6653. double diffResultPrice = GetPostDouble("diffResultPrice");
  6654. string textResult = GetPostString("textResult");
  6655. string supplierResponsible = GetPostString("supplierResponsible");
  6656. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6657. if (ceErpTradeAfterSaleExtend == null)
  6658. {
  6659. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6660. ceErpTradeAfterSaleExtend.tid = eid;
  6661. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6662. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6663. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6664. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6665. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6666. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6667. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6668. ceErpTradeAfterSaleExtend.Create();
  6669. }
  6670. else
  6671. {
  6672. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6673. {
  6674. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6675. }
  6676. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6677. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6678. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6679. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6680. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6681. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6682. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6683. ceErpTradeAfterSaleExtend.Update();
  6684. }
  6685. int gysid = GetPostInt("ResponsibleSupId");
  6686. if (entity.AfterSaleUserId == 0)
  6687. {
  6688. entity.AfterSaleUserId = CurrentUser.UserID;
  6689. }
  6690. entity.ResponsibleUserId = resIdStr;
  6691. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6692. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6693. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6694. {
  6695. CeErpTradeResponsible.DelByTid(eid, -1);
  6696. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6697. int backNum = 0;
  6698. if (number != null)
  6699. {
  6700. backNum = number.BackNum;
  6701. }
  6702. char[] separator = { ',' };
  6703. string[] sArray = resIdStr.Split(separator);
  6704. string[] refundFreeList = { };
  6705. if (refundFees.Length > 0)
  6706. {
  6707. refundFreeList = refundFees.Split(separator);
  6708. }
  6709. int index = -1;
  6710. foreach (string i in sArray)
  6711. {
  6712. index++;
  6713. if (i.Length <= 0) continue;
  6714. char[] separator2 = { '_' };
  6715. string idstr = i.Split(separator2)[0];
  6716. string idtype = i.Split(separator2)[1];
  6717. double refudFree = 0;
  6718. if (refundFreeList.Length > 0)
  6719. {
  6720. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6721. }
  6722. if (idtype == "s")
  6723. {
  6724. isDesign = true;
  6725. designFree = refudFree;
  6726. }
  6727. int userId = Convert.ToInt32(idstr);
  6728. int type = 0;
  6729. if (idtype == "g")
  6730. {
  6731. type = 1;
  6732. }
  6733. if (idtype == "w")
  6734. {
  6735. type = 2;
  6736. }
  6737. if (idtype == "t")
  6738. {
  6739. type = 3;
  6740. }
  6741. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6742. if (ceErpTradeResponsible == null)
  6743. {
  6744. ceErpTradeResponsible = new CeErpTradeResponsible();
  6745. ceErpTradeResponsible.tid = eid;
  6746. ceErpTradeResponsible.UserId = userId;
  6747. ceErpTradeResponsible.createdTime = DateTime.Now;
  6748. ceErpTradeResponsible.type = type;
  6749. if (type == 1)
  6750. {
  6751. ceErpTradeResponsible.IsSup = 1;
  6752. }
  6753. if (type == 2)
  6754. {
  6755. ceErpTradeResponsible.IsFlow = 1;
  6756. }
  6757. }
  6758. ceErpTradeResponsible.RefundFee = refudFree;
  6759. ceErpTradeResponsible.VerifyState = 0;
  6760. if (userId == 2125 || idtype == "w")
  6761. {
  6762. ceErpTradeResponsible.VerifyState = 1;
  6763. }
  6764. if (idtype == "w" && userId == 101)
  6765. {
  6766. ceErpTradeResponsible.VerifyState = 0;
  6767. }
  6768. if (ceErpTradeResponsible.ID > 0)
  6769. {
  6770. ceErpTradeResponsible.Update();
  6771. }
  6772. else
  6773. {
  6774. ceErpTradeResponsible.Create();
  6775. }
  6776. if (isDesign)
  6777. {
  6778. responsibleId = ceErpTradeResponsible.ID;
  6779. }
  6780. }
  6781. CeErpTradeResponsible.NumByTid(backNum, eid);
  6782. }
  6783. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6784. if (ceErpTradeCellExtend != null)
  6785. {
  6786. ceErpTradeCellExtend.returnVisit = 0;
  6787. ceErpTradeCellExtend.Update();
  6788. }
  6789. if (entity.HandleTime != null)
  6790. {
  6791. if (entity.AfterSaleState == 1)
  6792. {
  6793. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6794. }
  6795. else
  6796. {
  6797. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6798. }
  6799. }
  6800. else
  6801. {
  6802. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6803. entity.HandleTime = DateTime.Now;
  6804. }
  6805. bool isCompale = false;
  6806. if (entity.AfterSaleState == 5)
  6807. {
  6808. isCompale = true;
  6809. entity.AfterSaleState = 3;
  6810. }
  6811. entity.AfterSaleSupplierState = 0;
  6812. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6813. {
  6814. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6815. }
  6816. string sImgs = GetPostString("img");
  6817. entity.AfterSaleSupplierImg = sImgs;
  6818. entity.supRefundType = GetPostString("supRefundType");
  6819. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6820. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6821. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6822. entity.AfterSaleMemoType = GetPostString("MemoType");
  6823. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6824. {
  6825. //entity.AfterSaleSupplierState = 2;
  6826. }
  6827. string df = GetPostString("DeductFee");
  6828. if (df == "")
  6829. {
  6830. df = "0";
  6831. }
  6832. string rf = GetPostString("RefundFee");
  6833. if (rf == "")
  6834. {
  6835. rf = "0";
  6836. }
  6837. string pm = GetPostString("AfterSalePayment");
  6838. if (pm == "")
  6839. {
  6840. pm = "0";
  6841. }
  6842. entity.AfterSalePayment = Convert.ToDouble(pm);
  6843. entity.DeductFee = Convert.ToDouble(df);
  6844. entity.RefundFee = Convert.ToDouble(rf);
  6845. entity.UpdateTime = DateTime.Now;
  6846. entity.Update();
  6847. string toState = GetPostString("ToState");
  6848. string original = GetPostString("isOriginal");
  6849. ApiVo apiVo = new ApiVo();
  6850. apiVo.orderNumber = entity.ctid;
  6851. apiVo.actionName = "afterDesign";
  6852. apiVo.orderRemarks = entity.AfterSaleMethod;
  6853. apiVo.reasonRemarks = entity.AfterSaleReason;
  6854. apiVo.isDesign = isDesign;
  6855. apiVo.designFree = designFree;
  6856. apiVo.responsibleId = responsibleId;
  6857. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6858. if (toState == "设计师")
  6859. {
  6860. apiVo.isOriginal = Convert.ToBoolean(original);
  6861. }
  6862. designHelper.API_WorkCore(apiVo);//afterDesign
  6863. CeErpMethod methodSql = new CeErpMethod();
  6864. methodSql.con = entity.AfterSaleMethod;
  6865. methodSql.addTime = DateTime.Now;
  6866. methodSql.Create();
  6867. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6868. CeErpMethod.ExecuteNonQuery(delsql);
  6869. if (isCompale)
  6870. {
  6871. aftersale_data_change(entity.ctid);
  6872. }
  6873. returnSuccessMsg("操作成功!");
  6874. return;
  6875. }
  6876. returnErrorMsg("找不到订单记录");
  6877. }
  6878. }
  6879. public void ins_erp_toresponsible()
  6880. {
  6881. if (UrlPostParmsCheck("ctid"))
  6882. {
  6883. string eid = GetPostString("ctid");
  6884. CeErpTradeCell entity = null;
  6885. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6886. if (entity != null)
  6887. {
  6888. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6889. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6890. {
  6891. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6892. return;
  6893. }
  6894. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6895. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6896. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6897. if (entity.AfterSalePreTime == null)
  6898. {
  6899. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6900. {
  6901. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6902. }
  6903. }
  6904. entity.AfterSalePreTime = DateTime.Now;
  6905. //预完成给售后主管审核客户问题直接完成
  6906. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6907. {
  6908. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6909. {
  6910. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6911. }
  6912. }
  6913. ceErpTradeAfterSaleExtend.Update();
  6914. entity.AfterSaleState = 2;
  6915. entity.UpdateTime = DateTime.Now;
  6916. entity.Update();
  6917. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  6918. aftersale_data_change(entity.ctid);
  6919. returnSuccessMsg("操作成功!");
  6920. return;
  6921. }
  6922. returnErrorMsg("找不到订单记录");
  6923. }
  6924. }
  6925. public void cancel_erp_aftersaleanddelnew()
  6926. {
  6927. if (UrlPostParmsCheck("ctid"))
  6928. {
  6929. string eid = GetPostString("ctid");
  6930. CeErpTradeCell entity = null;
  6931. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6932. if (entity != null)
  6933. {
  6934. entity.AfterSaleState = 0;
  6935. entity.AfterSaleReason = "";
  6936. entity.AfterSaleMethod = "";
  6937. entity.AfterSaleMemo = "";
  6938. entity.AfterSaleResponsible = "";
  6939. entity.ResponsibleUserId = "";
  6940. entity.DeductFee = 0;
  6941. entity.RefundFee = 0;
  6942. entity.IsArbitrate = 0;
  6943. CeErpTradeResponsible.DelByTid(eid, -1);
  6944. entity.Update();
  6945. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  6946. if (after != null)
  6947. {
  6948. if (after.OrderState < 5)
  6949. CeErpTradeCell.DelByCtid("S_" + eid);
  6950. }
  6951. returnSuccessMsg("操作成功!");
  6952. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  6953. return;
  6954. }
  6955. returnErrorMsg("找不到订单记录");
  6956. }
  6957. }
  6958. public void get_erp_aftersale_pregather()
  6959. {
  6960. List<string> lw = new List<string>();
  6961. int st = GetInt("st");
  6962. string tid = GetPostString("ctid");
  6963. if (tid.Length > 0)
  6964. {
  6965. string select_tid = getTidByCtid(tid);
  6966. lw.Add(string.Format("tid='{0}'", select_tid));
  6967. }
  6968. string shopname = GetPostString("shopname");
  6969. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6970. string buyernick = GetPostString("buyer_nick");
  6971. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6972. string sellermemo = GetPostString("seller_memo");
  6973. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6974. string orderState = GetPostString("orderState");
  6975. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6976. string reason = GetPostString("reason");
  6977. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6978. string method = GetPostString("method");
  6979. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6980. string handler = GetPostString("handler");
  6981. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6982. string handledate1 = GetPostString("handledate1");
  6983. string handledate2 = GetPostString("handledate2");
  6984. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6985. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6986. string supplier = GetPostString("supplier");
  6987. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6988. string responsible = GetPostString("responsibleman");
  6989. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6990. string customer = GetPostString("customer");
  6991. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6992. string design = GetPostString("design");
  6993. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6994. string afterMemoType = GetPostString("aftermemotype");
  6995. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6996. string afterSaleMemo = GetPostString("afterSaleMemo");
  6997. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6998. string afterresult = GetPostString("afterresult");
  6999. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7000. string poscode = CurrentUser.UserPost.Post.Code;
  7001. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7002. {
  7003. string shopid = CurrentUser.User.pemShop;
  7004. lw.Add(string.Format("shopId in ({0})", shopid));
  7005. }
  7006. var mainwhere = string.Join(" and ", lw.ToArray());
  7007. string ro_json = "";
  7008. string type = GetPostString("gather_type");
  7009. int number = 0;
  7010. if (poscode == "AfterSale")
  7011. {
  7012. //处理中
  7013. if (type == "Handling")
  7014. {
  7015. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7016. DataTable dt = null;
  7017. try
  7018. {
  7019. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7020. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7021. }
  7022. catch (Exception e)
  7023. {
  7024. dt = new DataTable();
  7025. }
  7026. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7027. return;
  7028. }
  7029. if (type == "Wait")
  7030. {
  7031. //待处理
  7032. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7033. DataTable dt1 = null;
  7034. try
  7035. {
  7036. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7037. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7038. }
  7039. catch (Exception e)
  7040. {
  7041. dt1 = new DataTable();
  7042. }
  7043. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7044. return;
  7045. }
  7046. if (type == "back")
  7047. {
  7048. //打回
  7049. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7050. DataTable dt2 = null;
  7051. try
  7052. {
  7053. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7054. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7055. }
  7056. catch (Exception e)
  7057. {
  7058. dt2 = new DataTable();
  7059. }
  7060. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7061. return;
  7062. }
  7063. if (type == "preCompletion")
  7064. {
  7065. //预完成
  7066. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7067. DataTable dt3 = null;
  7068. try
  7069. {
  7070. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7071. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7072. }
  7073. catch (Exception e)
  7074. {
  7075. dt3 = new DataTable();
  7076. }
  7077. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7078. return;
  7079. }
  7080. if (type == "documentary")
  7081. {
  7082. //跟单中
  7083. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7084. DataTable dt4 = null;
  7085. try
  7086. {
  7087. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7088. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7089. }
  7090. catch (Exception e)
  7091. {
  7092. dt4 = new DataTable();
  7093. }
  7094. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7095. return;
  7096. }
  7097. if (type == "reBack")
  7098. {
  7099. //被打回
  7100. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7101. DataTable dt1 = null;
  7102. try
  7103. {
  7104. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7105. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7106. }
  7107. catch (Exception e)
  7108. {
  7109. dt1 = new DataTable();
  7110. }
  7111. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7112. return;
  7113. }
  7114. }
  7115. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7116. {
  7117. if (type == "puBack")
  7118. {
  7119. //退回
  7120. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7121. DataTable dt = null;
  7122. try
  7123. {
  7124. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7125. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7126. }
  7127. catch (Exception e)
  7128. {
  7129. dt = new DataTable();
  7130. }
  7131. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7132. return;
  7133. }
  7134. if (type == "reBack")
  7135. {
  7136. //打回
  7137. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7138. DataTable dt1 = null;
  7139. try
  7140. {
  7141. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7142. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7143. }
  7144. catch (Exception e)
  7145. {
  7146. dt1 = new DataTable();
  7147. }
  7148. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7149. return;
  7150. }
  7151. if (type == "examEd")
  7152. {
  7153. //已审核
  7154. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7155. DataTable dt2 = null;
  7156. try
  7157. {
  7158. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7159. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7160. }
  7161. catch (Exception e)
  7162. {
  7163. dt2 = new DataTable();
  7164. }
  7165. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7166. return;
  7167. }
  7168. if (type == "waitExam")
  7169. {
  7170. //待审核
  7171. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7172. DataTable dt3 = null;
  7173. try
  7174. {
  7175. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7176. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7177. }
  7178. catch (Exception e)
  7179. {
  7180. dt3 = new DataTable();
  7181. }
  7182. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7183. return;
  7184. }
  7185. if (type == "Handling")
  7186. {
  7187. //处理中
  7188. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7189. DataTable dt4 = null;
  7190. try
  7191. {
  7192. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7193. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7194. }
  7195. catch (Exception e)
  7196. {
  7197. dt4 = new DataTable();
  7198. }
  7199. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7200. return;
  7201. }
  7202. if (type == "Wait")
  7203. {
  7204. //待处理
  7205. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7206. DataTable dt5 = null;
  7207. try
  7208. {
  7209. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7210. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7211. }
  7212. catch (Exception e)
  7213. {
  7214. dt5 = new DataTable();
  7215. }
  7216. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7217. return;
  7218. }
  7219. if (type == "documentary")
  7220. {
  7221. //跟单中
  7222. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7223. DataTable dt6 = null;
  7224. try
  7225. {
  7226. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7227. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7228. }
  7229. catch (Exception e)
  7230. {
  7231. dt6 = new DataTable();
  7232. }
  7233. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7234. return;
  7235. }
  7236. }
  7237. returnSuccess(ro_json);
  7238. }
  7239. public void end_erp_aftersale()
  7240. {
  7241. if (UrlPostParmsCheck("ctid"))
  7242. {
  7243. string eid = GetPostString("ctid");
  7244. CeErpTradeCell entity = null;
  7245. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7246. if (entity != null)
  7247. {
  7248. string stype = GetPostString("stype");
  7249. string typeStr = stype;
  7250. entity.AfterSaleState = 4;
  7251. entity.FinishAfterSaleTime = DateTime.Now;
  7252. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7253. entity.Update();
  7254. ApiVo apiVo = new ApiVo();
  7255. apiVo.orderNumber = entity.ctid;
  7256. apiVo.actionName = "afterOver";
  7257. designHelper.API_WorkCore(apiVo); //afterOver
  7258. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7259. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7260. CeErpSukuraData.createInfo(entity.ctid, 8);
  7261. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7262. returnSuccessMsg("操作成功!");
  7263. return;
  7264. }
  7265. returnErrorMsg("找不到订单记录");
  7266. }
  7267. }
  7268. public void ins_erp_finishaftersale()
  7269. {
  7270. if (UrlPostParmsCheck("id"))
  7271. {
  7272. string eid = GetPostString("id");
  7273. CeErpTradeResponsible entity = null;
  7274. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7275. if (entity != null)
  7276. {
  7277. entity.VerifyState = 1;
  7278. entity.VerifyTime = DateTime.Now;
  7279. entity.Update();
  7280. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7281. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7282. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7283. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7284. if (dt.Rows.Count <= 0)
  7285. {
  7286. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7287. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7288. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7289. CeErpSukuraData.createInfo(entity.tid, 8);
  7290. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7291. {
  7292. CeErpDesignerBill.Del(entity.tid);
  7293. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7294. }
  7295. }
  7296. returnSuccessMsg("操作成功!");
  7297. return;
  7298. }
  7299. returnErrorMsg("找不到订单记录");
  7300. }
  7301. }
  7302. public void upd_erp_arbitrateaftersale()
  7303. {
  7304. if (UrlPostParmsCheck("id"))
  7305. {
  7306. string eid = GetPostString("id");
  7307. CeErpTradeResponsible entity = null;
  7308. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7309. if (entity != null)
  7310. {
  7311. entity.IsArbitrate = 1;
  7312. entity.ArbitradeMemo = GetPostString("reason");
  7313. entity.VerifyState = 2;
  7314. entity.Update();
  7315. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7316. if (tradecell != null)
  7317. {
  7318. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7319. tradecell.IsArbitrate = 1;
  7320. tradecell.Update();
  7321. }
  7322. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7323. returnSuccessMsg("操作成功!");
  7324. return;
  7325. }
  7326. returnErrorMsg("找不到订单记录");
  7327. }
  7328. }
  7329. public void upd_erp_backaftersale()
  7330. {
  7331. if (UrlPostParmsCheck("tid"))
  7332. {
  7333. string eid = GetPostString("tid");
  7334. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7335. int backNum = 0;
  7336. if (number != null)
  7337. {
  7338. backNum = number.BackNum;
  7339. }
  7340. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7341. CeErpTradeCell entity = null;
  7342. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7343. if (entity != null)
  7344. {
  7345. entity.AfterSaleBackReason = GetPostString("backreason");
  7346. entity.AfterSaleState = 1;
  7347. entity.AfterSaleSupplierState = 0;
  7348. entity.UpdateTime = DateTime.Now;
  7349. entity.Update();
  7350. returnSuccessMsg("操作成功!");
  7351. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7352. return;
  7353. }
  7354. returnErrorMsg("找不到订单记录");
  7355. }
  7356. }
  7357. public void get_erp_supplieraftersalelist()
  7358. {
  7359. DataStruct dStruct = GetPostStruct();
  7360. List<string> lw = new List<string>();
  7361. string tid = GetPostString("ctid");
  7362. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7363. string shopname = GetPostString("shopname");
  7364. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7365. string buyernick = GetPostString("buyer_nick");
  7366. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7367. string sellermemo = GetPostString("seller_memo");
  7368. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7369. string orderState = GetPostString("orderState");
  7370. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7371. string afterState = GetPostString("afterstate");
  7372. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7373. string date1 = GetPostString("date1");
  7374. string date2 = GetPostString("date2");
  7375. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7376. if (dw.Length > 0) lw.Add(dw);
  7377. string price1 = GetPostString("price1");
  7378. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7379. string price2 = GetPostString("price2");
  7380. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7381. string reason = GetPostString("reason");
  7382. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7383. string method = GetPostString("method");
  7384. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7385. string handledate1 = GetPostString("handledate1");
  7386. string handledate2 = GetPostString("handledate2");
  7387. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7388. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7389. string handler = GetPostString("handler");
  7390. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7391. string afterdate1 = GetPostString("afterdate1");
  7392. string afterdate2 = GetPostString("afterdate2");
  7393. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7394. if (afterDate.Length > 0) lw.Add(afterDate);
  7395. string customer = GetPostString("customer");
  7396. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7397. string design = GetPostString("design");
  7398. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7399. string afterMemoType = GetPostString("aftermemotype");
  7400. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7401. string vstate = GetPostString("vstate");
  7402. if (vstate.Length > 0)
  7403. {
  7404. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7405. }
  7406. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7407. string supplier = GetPostString("supplier");
  7408. int supid = commonHelper.getSupplierIDByName(supplier);
  7409. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7410. string posCode = CurrentUser.UserPost.Post.Code;
  7411. if (posCode == "Supplier")
  7412. {
  7413. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7414. }
  7415. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7416. {
  7417. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7418. }
  7419. else
  7420. {
  7421. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7422. }
  7423. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7424. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7425. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7426. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7427. writeGridDataTableJson(dStruct.TotalCount, dt);
  7428. }
  7429. public void upd_erp_supverifyaftersale()
  7430. {
  7431. if (UrlPostParmsCheck("id"))
  7432. {
  7433. string id = GetPostString("id");
  7434. int st = GetPostInt("afterstate");
  7435. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7436. CeErpTradeCell entity = null;
  7437. if (ceErpTradeResponsible != null)
  7438. {
  7439. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7440. }
  7441. string afmemo = GetPostString("supmemo");
  7442. string image = GetPostString("image");
  7443. if (entity != null)
  7444. {
  7445. entity.AfterSaleSupplierState = st;
  7446. entity.AfterSaleSupplierMemo = afmemo;
  7447. if (st == 1)
  7448. {
  7449. ceErpTradeResponsible.VerifyState = 1;
  7450. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7451. ceErpTradeResponsible.Update();
  7452. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7453. if (isAll)
  7454. {
  7455. entity.AfterSaleState = 4;
  7456. entity.FinishAfterSaleTime = DateTime.Now;
  7457. }
  7458. }
  7459. else
  7460. {
  7461. CeErpTradeResponsible.dateByTid(entity.ctid);
  7462. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7463. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7464. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7465. if (num <= 1)
  7466. {
  7467. entity.AfterSaleState = 1;
  7468. }
  7469. else
  7470. {
  7471. entity.AfterSaleState = 5;
  7472. }
  7473. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7474. if (ceErpTradeAfterSaleExtend != null)
  7475. {
  7476. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7477. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7478. ceErpTradeAfterSaleExtend.Update();
  7479. }
  7480. else
  7481. {
  7482. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7483. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7484. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7485. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7486. ceErpTradeAfterSaleExtend.Create();
  7487. }
  7488. }
  7489. if (entity.AfterSaleState == 4)
  7490. {
  7491. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7492. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7493. {
  7494. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7495. }
  7496. ApiVo apiVo = new ApiVo();
  7497. apiVo.orderNumber = entity.ctid;
  7498. apiVo.actionName = "afterOver";
  7499. designHelper.API_WorkCore(apiVo); //afterOver
  7500. }
  7501. entity.UpdateTime = DateTime.Now;
  7502. entity.Update();
  7503. returnSuccessMsg("操作成功!");
  7504. CeErpSukuraData.createInfo(entity.ctid, 8);
  7505. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7506. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7507. return;
  7508. }
  7509. returnErrorMsg("找不到订单记录");
  7510. }
  7511. }
  7512. public void upd_erp_masteraftersale()
  7513. {
  7514. if (UrlPostParmsCheck("id"))
  7515. {
  7516. string id = GetPostString("id");
  7517. int st = GetPostInt("afterstate");
  7518. string afmemo = GetPostString("supmemo");
  7519. string image = GetPostString("image");
  7520. string textResult = GetPostString("textResult");
  7521. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7522. if (ceErpTradeResponsible != null)
  7523. {
  7524. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7525. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7526. ceErpTradeResponsible.Update();
  7527. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7528. if (entity != null)
  7529. {
  7530. entity.AfterSaleSupplierState = st;
  7531. entity.AfterSaleSupplierMemo = afmemo;
  7532. if (st == 1)
  7533. {
  7534. }
  7535. else
  7536. {
  7537. CeErpTradeResponsible.dateByTid(entity.ctid);
  7538. //退回到售后
  7539. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7540. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7541. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7542. if (num <= 1)
  7543. {
  7544. entity.AfterSaleState = 1;
  7545. }
  7546. else
  7547. {
  7548. entity.AfterSaleState = 5;
  7549. }
  7550. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7551. if (ceErpTradeAfterSaleExtend != null)
  7552. {
  7553. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7554. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7555. ceErpTradeAfterSaleExtend.Update();
  7556. }
  7557. else
  7558. {
  7559. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7560. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7561. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7562. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7563. ceErpTradeAfterSaleExtend.Create();
  7564. }
  7565. }
  7566. entity.UpdateTime = DateTime.Now;
  7567. entity.Update();
  7568. returnSuccessMsg("操作成功!");
  7569. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7570. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7571. return;
  7572. }
  7573. }
  7574. returnErrorMsg("找不到订单记录");
  7575. }
  7576. }
  7577. public void upd_erp_personaftersale()
  7578. {
  7579. if (UrlPostParmsCheck("id"))
  7580. {
  7581. string id = GetPostString("id");
  7582. int st = GetPostInt("afterstate");
  7583. string afmemo = GetPostString("supmemo");
  7584. string image = GetPostString("image");
  7585. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7586. if (ceErpTradeResponsible != null)
  7587. {
  7588. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7589. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7590. ceErpTradeResponsible.Update();
  7591. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7592. if (entity != null)
  7593. {
  7594. entity.AfterSaleSupplierMemo = afmemo;
  7595. entity.AfterSaleSupplierState = st;
  7596. if (st == 1)
  7597. {
  7598. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7599. if (isAll)
  7600. {
  7601. entity.AfterSaleState = 4;
  7602. entity.FinishAfterSaleTime = DateTime.Now;
  7603. }
  7604. }
  7605. else
  7606. {
  7607. CeErpTradeResponsible.dateByTid(entity.ctid);
  7608. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7609. if (ceErpTradeAfterSaleExtend != null)
  7610. {
  7611. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7612. ceErpTradeAfterSaleExtend.Update();
  7613. }
  7614. else
  7615. {
  7616. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7617. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7618. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7619. ceErpTradeAfterSaleExtend.Create();
  7620. }
  7621. //退回到主管
  7622. //entity.AfterSaleState = 2;
  7623. }
  7624. if (entity.AfterSaleState == 4)
  7625. {
  7626. ApiVo apiVo = new ApiVo();
  7627. apiVo.orderNumber = entity.ctid;
  7628. apiVo.actionName = "afterOver";
  7629. designHelper.API_WorkCore(apiVo); //afterOver
  7630. }
  7631. entity.UpdateTime = DateTime.Now;
  7632. entity.Update();
  7633. returnSuccessMsg("操作成功!");
  7634. CeErpSukuraData.createInfo(entity.ctid, 8);
  7635. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7636. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7637. return;
  7638. }
  7639. }
  7640. returnErrorMsg("找不到订单记录");
  7641. }
  7642. }
  7643. public void set_erp_supplierrefundtag()
  7644. {
  7645. if (UrlPostParmsCheck("ctid"))
  7646. {
  7647. string eid = GetPostString("ctid");
  7648. CeErpTradeCell entity = null;
  7649. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7650. if (entity != null)
  7651. {
  7652. entity.IsSupplierRefund = GetPostInt("tag");
  7653. entity.Update();
  7654. returnSuccessMsg("操作成功!");
  7655. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7656. return;
  7657. }
  7658. returnErrorMsg("找不到订单记录");
  7659. }
  7660. }
  7661. public void get_erp_refundlist()
  7662. {
  7663. DataStruct dStruct = GetPostStruct();
  7664. List<string> lw = new List<string>();
  7665. string tid = GetPostString("tid");
  7666. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7667. //string rid = GetPostString("refund_id");
  7668. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7669. string shopname = GetPostString("shopname");
  7670. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7671. string buyernick = GetPostString("buyer_nick");
  7672. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7673. string customer = GetPostString("customer");
  7674. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7675. string design = GetPostString("design");
  7676. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7677. string sellermemo = GetPostString("seller_memo");
  7678. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7679. //string date1 = GetPostString("date1");
  7680. //string date2 = GetPostString("date2");
  7681. //string dateType = GetPostString("dateType");
  7682. //if (dateType.Length > 0)
  7683. //{
  7684. // if (dateType == "1001") dateType = "0";
  7685. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7686. // if (searchDT.Count == 2)
  7687. // {
  7688. // date1 = searchDT[0].ToString();
  7689. // date2 = searchDT[1].ToString();
  7690. // }
  7691. //}
  7692. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7693. //if (dw.Length > 0) lw.Add(dw);
  7694. string redate1 = GetPostString("refunddate1");
  7695. string redate2 = GetPostString("refunddate2");
  7696. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7697. if (dwdate.Length > 0) lw.Add(dwdate);
  7698. string price1 = GetPostString("price1");
  7699. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7700. string price2 = GetPostString("price2");
  7701. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7702. string ispartrefund = GetPostString("ispartrefund");
  7703. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7704. string refundState = GetPostString("refundvstate");
  7705. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7706. int st = GetInt("st");
  7707. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7708. {
  7709. string responsible = GetPostString("responsibleman");
  7710. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7711. lw.Add(string.Format("RefundState>={0}", st));
  7712. string code = CurrentUser.UserPost.Post.Code;
  7713. if (code == "CustomerService")
  7714. {
  7715. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7716. }
  7717. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7718. {
  7719. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7720. }
  7721. else if (code == "Place" || code == "PlaceMr")
  7722. {
  7723. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7724. }
  7725. dStruct.Order = "RefundState asc,created desc";
  7726. }
  7727. else if (st == 10)
  7728. {
  7729. string responsible = GetPostString("responsibleman");
  7730. if (responsible == "空白")
  7731. {
  7732. lw.Add(string.Format("ResponsibleUserName = ''"));
  7733. }
  7734. else if (responsible.Length > 0)
  7735. {
  7736. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7737. }
  7738. lw.Add(string.Format("RefundState>=0"));
  7739. dStruct.Order = "created desc";
  7740. }
  7741. else
  7742. {
  7743. string responsible = GetPostString("responsibleman");
  7744. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7745. lw.Add(string.Format("RefundState={0}", st));
  7746. dStruct.Order = "created desc";
  7747. }
  7748. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7749. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7750. dt.Columns.Add("refund_fees");
  7751. foreach (DataRow dr in dt.Rows)
  7752. {
  7753. String status = dr["status"].ToString();
  7754. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7755. {
  7756. dr["refund_fees"] = dr["refund_fee"];
  7757. }
  7758. else
  7759. {
  7760. dr["refund_fees"] = "0.0";
  7761. }
  7762. }
  7763. writeGridDataTableJson(dStruct.TotalCount, dt);
  7764. }
  7765. public void get_erp_refunddesignlist()
  7766. {
  7767. DataStruct dStruct = GetPostStruct();
  7768. List<string> lw = new List<string>();
  7769. string tid = GetPostString("tid");
  7770. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7771. string shopname = GetPostString("shopname");
  7772. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7773. string buyernick = GetPostString("buyer_nick");
  7774. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7775. string customer = GetPostString("customer");
  7776. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7777. string design = GetPostString("design");
  7778. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7779. string sellermemo = GetPostString("seller_memo");
  7780. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7781. string redate1 = GetPostString("refunddate1");
  7782. string redate2 = GetPostString("refunddate2");
  7783. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7784. if (dwdate.Length > 0) lw.Add(dwdate);
  7785. string price1 = GetPostString("price1");
  7786. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7787. string price2 = GetPostString("price2");
  7788. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7789. string ispartrefund = GetPostString("ispartrefund");
  7790. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7791. string designerorg = GetPostString("designerorg");
  7792. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7793. string refundState = GetPostString("refundState");
  7794. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7795. int myOrgid = CurrentUser.UserPost.OrgID;
  7796. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7797. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7798. {
  7799. if (CurrentUser.User.TeamIds.Length > 0)
  7800. {
  7801. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7802. }
  7803. else
  7804. {
  7805. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7806. }
  7807. }
  7808. else if ("SysAdmin".Equals(myOrgCode))
  7809. {
  7810. }
  7811. else
  7812. {
  7813. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7814. {
  7815. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7816. }
  7817. else
  7818. {
  7819. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7820. }
  7821. }
  7822. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7823. dStruct.Order = "created desc";
  7824. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7825. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7826. dt.Columns.Add("refund_fees");
  7827. foreach (DataRow dr in dt.Rows)
  7828. {
  7829. String status = dr["status"].ToString();
  7830. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7831. {
  7832. dr["refund_fees"] = dr["refund_fee"];
  7833. }
  7834. else
  7835. {
  7836. dr["refund_fees"] = "0.0";
  7837. }
  7838. }
  7839. writeGridDataTableJson(dStruct.TotalCount, dt);
  7840. }
  7841. public void handle_erp_refundtag()
  7842. {
  7843. if (UrlPostParmsCheck("refund_id"))
  7844. {
  7845. string eid = GetPostString("refund_id");
  7846. string respMan = GetPostString("ResponsibleName");
  7847. if (respMan.Length <= 0)
  7848. {
  7849. returnErrorMsg("责任人不能为空");
  7850. return;
  7851. }
  7852. CeErpTradeRefund entity = null;
  7853. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7854. if (entity != null)
  7855. {
  7856. entity.ResponsibleUserName = respMan;
  7857. string userid = GetPostString("ResponsibleUserId");
  7858. if (userid.Length > 0)
  7859. {
  7860. entity.ResponsibleUserId = userid;
  7861. }
  7862. entity.Memo = GetPostString("Memo");
  7863. if (respMan.IndexOf("客服") != -1 ||
  7864. respMan.IndexOf("设计师") != -1 ||
  7865. respMan.IndexOf("下单员") != -1)
  7866. {
  7867. entity.RefundState = 2;
  7868. }
  7869. else
  7870. {
  7871. entity.RefundState = 3;
  7872. }
  7873. entity.modified = DateTime.Now;
  7874. entity.Update();
  7875. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7876. returnSuccessMsg("操作成功!");
  7877. return;
  7878. }
  7879. returnErrorMsg("找不到订单记录");
  7880. }
  7881. }
  7882. public void handle_erp_designrefundtag()
  7883. {
  7884. if (UrlPostParmsCheck("refund_id"))
  7885. {
  7886. string eid = GetPostString("refund_id");
  7887. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7888. if (ceErpTradeCellExtend == null)
  7889. {
  7890. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7891. ceErpTradeCellExtend.ctid = eid;
  7892. }
  7893. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7894. if (ceErpTradeCellExtend.ID > 0)
  7895. {
  7896. ceErpTradeCellExtend.Update();
  7897. }
  7898. else
  7899. {
  7900. ceErpTradeCellExtend.Create();
  7901. }
  7902. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7903. returnSuccessMsg("操作成功!");
  7904. return;
  7905. }
  7906. returnErrorMsg("找不到订单记录");
  7907. }
  7908. public void upd_erp_refundverify()
  7909. {
  7910. if (UrlPostParmsCheck("refund_id"))
  7911. {
  7912. string eid = GetPostString("refund_id");
  7913. CeErpTradeRefund entity = null;
  7914. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7915. if (entity != null)
  7916. {
  7917. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  7918. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  7919. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  7920. {
  7921. entity.RefundState = 2;
  7922. }
  7923. else
  7924. {
  7925. entity.RefundState = 3;
  7926. }
  7927. entity.Update();
  7928. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  7929. returnSuccessMsg("操作成功!");
  7930. return;
  7931. }
  7932. returnErrorMsg("找不到订单记录");
  7933. }
  7934. }
  7935. public void upd_erp_refundapprove()
  7936. {
  7937. if (UrlPostParmsCheck("refund_id"))
  7938. {
  7939. string eid = GetPostString("refund_id");
  7940. CeErpTradeRefund entity = null;
  7941. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7942. if (entity != null)
  7943. {
  7944. int apr = GetPostInt("approve");
  7945. if (apr == 0)
  7946. {
  7947. entity.RefundState = 1;
  7948. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  7949. }
  7950. else if (apr == 1)
  7951. {
  7952. entity.RefundState = 3;
  7953. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  7954. }
  7955. entity.modified = DateTime.Now;
  7956. entity.Update();
  7957. returnSuccessMsg("操作成功!");
  7958. return;
  7959. }
  7960. returnErrorMsg("找不到订单记录");
  7961. }
  7962. }
  7963. public void get_erp_billlist()
  7964. {
  7965. DataStruct dStruct = GetPostStruct();
  7966. List<string> lw = new List<string>();
  7967. string title = GetPostString("title");
  7968. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  7969. string tid = GetPostString("tid");
  7970. string tids = GetPostString("tids");
  7971. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7972. if (tids.Length > 0)
  7973. {
  7974. tids = "'" + tids + "'";
  7975. tids = tids.Replace(",", "','");
  7976. lw.Add(string.Format("tid in ({0})", tids));
  7977. }
  7978. string shopname = GetPostString("shopname");
  7979. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7980. string buyernick = GetPostString("buyer_nick");
  7981. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7982. string customer = GetPostString("customer");
  7983. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7984. string date1 = GetPostString("date1");
  7985. string date2 = GetPostString("date2");
  7986. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7987. if (dw.Length > 0) lw.Add(dw);
  7988. string price1 = GetPostString("price1");
  7989. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7990. string price2 = GetPostString("price2");
  7991. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7992. string returndate1 = GetPostString("returndate1");
  7993. string returndate2 = GetPostString("returndate2");
  7994. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  7995. if (dw1.Length > 0) lw.Add(dw1);
  7996. string billtype = GetPostString("billtype");
  7997. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  7998. string billstate = GetPostString("billstate");
  7999. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8000. string usershop = CurrentUser.User.pemShop;
  8001. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8002. dStruct.Order = "createTime desc";
  8003. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8004. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8005. //foreach (DataRow dr in dt.Rows)
  8006. //{
  8007. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8008. //}
  8009. writeGridDataTableJson(dStruct.TotalCount, dt);
  8010. }
  8011. public void modify_erp_billinfo()
  8012. {
  8013. if (UrlPostParmsCheck("ID"))
  8014. {
  8015. string eid = GetPostString("ID");
  8016. CeErpBill bill_entity = null;
  8017. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8018. if (bill_entity != null)
  8019. {
  8020. bill_entity.tid = GetPostString("tid");
  8021. bill_entity.title = GetPostString("title");
  8022. bill_entity.tax = GetPostString("tax");
  8023. bill_entity.bank = GetPostString("bank");
  8024. bill_entity.bankac = GetPostString("bankac");
  8025. bill_entity.address = GetPostString("address");
  8026. bill_entity.phone = GetPostString("phone");
  8027. bill_entity.price = GetPostString("price");
  8028. bill_entity.productId = GetPostInt("ProductName");
  8029. bill_entity.num = GetPostInt("num");
  8030. bill_entity.unit = GetPostString("unit");
  8031. bill_entity.type = GetPostString("type");
  8032. bill_entity.sendType = GetPostString("SendType");
  8033. bill_entity.email = GetPostString("email");
  8034. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8035. bill_entity.shopName = GetPostString("ShopName");
  8036. bill_entity.applymemo = GetPostString("applymemo");
  8037. bill_entity.modifyTime = DateTime.Now;
  8038. bill_entity.createTime = DateTime.Now;
  8039. bill_entity.state = 0;
  8040. bill_entity.Update();
  8041. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8042. returnSuccessMsg("发票修改成功!");
  8043. return;
  8044. }
  8045. returnErrorMsg("找不到对应记录");
  8046. }
  8047. }
  8048. public void set_erp_invoicing()
  8049. {
  8050. if (UrlPostParmsCheck("id"))
  8051. {
  8052. try
  8053. {
  8054. string eid = GetPostString("id");
  8055. CeErpBill bill_entity = null;
  8056. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8057. if (bill_entity != null)
  8058. {
  8059. int ComId = GetPostInt("ComId");
  8060. //string memo = GetPostString("Memo");
  8061. int allInfo = GetPostInt("allinfo");
  8062. string clert = CurrentUser.User.Name;
  8063. //string detailValue = GetPostString("detailvalue");
  8064. string billId = bill_entity.billOrderId;
  8065. string[] billIdList = billId.Split(',');
  8066. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8067. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8068. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8069. {
  8070. billCount += 1;
  8071. }
  8072. if (billId.Length <= 0 || billIdList.Length != billCount)
  8073. {
  8074. bill_entity.billOrderId = "";
  8075. string prebill = "ltb";
  8076. for (int idx = 1; idx <= billCount; idx++)
  8077. {
  8078. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8079. string billoid = prebill + idx + dtstr;
  8080. bill_entity.billOrderId += billoid;
  8081. if (idx < billCount)
  8082. {
  8083. bill_entity.billOrderId += ",";
  8084. }
  8085. }
  8086. }
  8087. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8088. if (bill_entity.state == 5)
  8089. {
  8090. string errMsg = bill_entity.failerror;
  8091. string[] errlist = errMsg.Split('|');
  8092. string[] errTags = new string[errlist.Length];
  8093. for (int itag = 0; itag < errlist.Length; itag++)
  8094. {
  8095. if (errlist[itag].Length <= 0) continue;
  8096. errTags[itag] = errlist[itag].Split('&')[0];
  8097. }
  8098. for (int iii = 0; iii < errTags.Length; iii++)
  8099. {
  8100. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8101. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8102. if (billOrderList.Length >= erroBillOrderTag)
  8103. {
  8104. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8105. if (needModifyBillId.Length <= 19)
  8106. {
  8107. needModifyBillId = needModifyBillId + "1";
  8108. }
  8109. else
  8110. {
  8111. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8112. last = last + 1;
  8113. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8114. }
  8115. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8116. }
  8117. }
  8118. }
  8119. bool isHaveBillSucces = false;
  8120. string totalRes = "";
  8121. bill_entity.failerror = "";
  8122. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8123. {
  8124. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8125. totalRes += res;
  8126. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8127. {
  8128. isHaveBillSucces = true;
  8129. bill_entity.comId = ComId;
  8130. bill_entity.state = 1;
  8131. bill_entity.executeTime = DateTime.Now;
  8132. bill_entity.executeUser = clert;
  8133. }
  8134. else
  8135. {
  8136. bill_entity.state = 5;
  8137. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8138. }
  8139. }
  8140. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8141. bill_entity.Update();
  8142. if (isHaveBillSucces)
  8143. {
  8144. StringBuilder sql = new StringBuilder();
  8145. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8146. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8147. }
  8148. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8149. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8150. {
  8151. returnErrorMsg("开票失败");
  8152. }
  8153. else
  8154. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8155. return;
  8156. }
  8157. returnErrorMsg("找不到对应记录");
  8158. }
  8159. catch (Exception ex)
  8160. {
  8161. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8162. returnErrorMsg("操作失败");
  8163. }
  8164. }
  8165. }
  8166. public void get_erp_invoicing_back()
  8167. {
  8168. if (UrlPostParmsCheck("id"))
  8169. {
  8170. try
  8171. {
  8172. string id = GetPostString("id");
  8173. CeErpBill entiy = CeErpBill.Get(id);
  8174. if (entiy != null)
  8175. {
  8176. if (entiy.state == 0)
  8177. {
  8178. returnErrorMsg("发票还未开具");
  8179. return;
  8180. }
  8181. string[] billOrderList = entiy.billOrderId.Split(',');
  8182. int iTag = 0;
  8183. entiy.fplsh = "";
  8184. entiy.fpdm = "";
  8185. entiy.fphm = "";
  8186. foreach (string billOrderId in billOrderList)
  8187. {
  8188. iTag++;
  8189. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8190. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8191. {
  8192. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8193. try
  8194. {
  8195. Invoicing_get_response_Obj iObj = null;
  8196. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8197. if (iObj != null)
  8198. {
  8199. entiy.state = 2;
  8200. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8201. entiy.fpdm += iObj.list[0].c_fpdm;
  8202. entiy.fphm += iObj.list[0].c_fphm;
  8203. if (iTag < billOrderList.Length)
  8204. {
  8205. entiy.fplsh += ",";
  8206. entiy.fpdm += ",";
  8207. entiy.fphm += ",";
  8208. }
  8209. entiy.Update();
  8210. }
  8211. StringBuilder sql = new StringBuilder();
  8212. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8213. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8214. returnSuccessMsg("开票成功");
  8215. }
  8216. catch (Exception ex)
  8217. {
  8218. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8219. }
  8220. return;
  8221. }
  8222. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8223. {
  8224. var res_obj = new
  8225. {
  8226. data = "开票中"
  8227. };
  8228. string ro_json = JsonConvert.SerializeObject(res_obj);
  8229. returnSuccess(ro_json);
  8230. return;
  8231. }
  8232. else
  8233. {
  8234. int eidx = res.IndexOf("c_resultmsg");
  8235. int lidx = res.IndexOf("c_status");
  8236. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8237. entiy.state = 5;
  8238. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8239. entiy.Update();
  8240. returnErrorMsg("开票失败");
  8241. return;
  8242. }
  8243. }
  8244. }
  8245. }
  8246. catch (Exception ex)
  8247. {
  8248. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8249. }
  8250. return;
  8251. }
  8252. }
  8253. public void get_erp_invoicing()
  8254. {
  8255. if (UrlPostParmsCheck("id"))
  8256. {
  8257. try
  8258. {
  8259. string id = GetPostString("id");
  8260. CeErpBill entiy = CeErpBill.Get(id);
  8261. if (entiy != null)
  8262. {
  8263. if (entiy.state == 0)
  8264. {
  8265. returnErrorMsg("发票还未开具");
  8266. return;
  8267. }
  8268. if (entiy.sendType == "纸质发票")
  8269. {
  8270. if (entiy.img.Length <= 0)
  8271. {
  8272. returnErrorMsg("查无纸质发票");
  8273. return;
  8274. }
  8275. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8276. returnSuccess(returnres);
  8277. return;
  8278. }
  8279. string[] billOrderList = entiy.billOrderId.Split(',');
  8280. int iTag = 0;
  8281. string fpUrl = "";
  8282. entiy.fplsh = "";
  8283. entiy.fpdm = "";
  8284. entiy.fphm = "";
  8285. foreach (string billOrderId in billOrderList)
  8286. {
  8287. iTag++;
  8288. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8289. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8290. {
  8291. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8292. Invoicing_get_response_Obj iObj = null;
  8293. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8294. if (iObj != null)
  8295. {
  8296. //entiy.state = 2;
  8297. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8298. entiy.fpdm += iObj.list[0].c_fpdm;
  8299. entiy.fphm += iObj.list[0].c_fphm;
  8300. if (iTag < billOrderList.Length)
  8301. {
  8302. entiy.fplsh += ",";
  8303. entiy.fpdm += ",";
  8304. entiy.fphm += ",";
  8305. }
  8306. entiy.Update();
  8307. fpUrl += iObj.list[0].c_url + ",";
  8308. }
  8309. //returnSuccess(res);
  8310. StringBuilder sql = new StringBuilder();
  8311. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8312. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8313. }
  8314. else
  8315. {
  8316. int eidx = res.IndexOf("c_resultmsg");
  8317. //int lidx = res.IndexOf("c_status");
  8318. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8319. //开票失败
  8320. entiy.state = 5;
  8321. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8322. entiy.Update();
  8323. returnErrorMsg("开票失败");
  8324. return;
  8325. }
  8326. }
  8327. var returnObj = new
  8328. {
  8329. data = fpUrl
  8330. };
  8331. string ro_json = JsonConvert.SerializeObject(returnObj);
  8332. returnSuccess(ro_json);
  8333. }
  8334. }
  8335. catch (Exception ex)
  8336. {
  8337. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8338. }
  8339. return;
  8340. }
  8341. }
  8342. public void save_erp_billimg()
  8343. {
  8344. if (UrlPostParmsCheck("id"))
  8345. {
  8346. string eid = GetPostString("id");
  8347. CeErpBill bill_entity = null;
  8348. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8349. if (bill_entity != null)
  8350. {
  8351. bill_entity.img = GetPostString("img");
  8352. bill_entity.executeTime = DateTime.Now;
  8353. bill_entity.state = 2;
  8354. bill_entity.Update();
  8355. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8356. returnSuccessMsg("保存成功");
  8357. }
  8358. return;
  8359. }
  8360. }
  8361. public void upd_erp_billreturnback()
  8362. {
  8363. if (UrlPostParmsCheck("id"))
  8364. {
  8365. int eid = GetPostInt("id");
  8366. CeErpBill bill_entity = null;
  8367. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8368. if (bill_entity != null)
  8369. {
  8370. bill_entity.state = 3;
  8371. bill_entity.returnReason = GetPostString("reason");
  8372. bill_entity.Update();
  8373. returnSuccessMsg("驳回成功!");
  8374. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8375. }
  8376. return;
  8377. }
  8378. }
  8379. public void cancel_erp_bill()
  8380. {
  8381. if (UrlPostParmsCheck("id"))
  8382. {
  8383. int eid = GetPostInt("id");
  8384. int detailValue = GetPostInt("detailvalue");
  8385. CeErpBill bill_entity = null;
  8386. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8387. string cres = "";
  8388. string gres = "";
  8389. if (bill_entity != null)
  8390. {
  8391. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8392. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8393. {
  8394. int iTag = 0;
  8395. bill_entity.fplsh = "";
  8396. bill_entity.fpdm = "";
  8397. bill_entity.fphm = "";
  8398. foreach (string billOrderId in billOrderList)
  8399. {
  8400. iTag++;
  8401. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8402. if (gres.IndexOf("success") != -1)
  8403. {
  8404. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8405. Invoicing_get_response_Obj iObj = null;
  8406. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8407. if (iObj != null)
  8408. {
  8409. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8410. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8411. bill_entity.fphm += iObj.list[0].c_fphm;
  8412. if (iTag < billOrderList.Length)
  8413. {
  8414. bill_entity.fplsh += ",";
  8415. bill_entity.fpdm += ",";
  8416. bill_entity.fphm += ",";
  8417. }
  8418. bill_entity.Update();
  8419. }
  8420. }
  8421. else
  8422. {
  8423. returnErrorMsg(gres);
  8424. return;
  8425. }
  8426. }
  8427. }
  8428. if (bill_entity.sendType == "纸质发票")
  8429. {
  8430. //作废
  8431. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8432. //if (DateTime.Now.Month == extime.Month)
  8433. //{
  8434. //cres = taobaoHelper.cancel_invoicing(eid);
  8435. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8436. //{
  8437. bill_entity.state = 4;//已作废
  8438. bill_entity.Update();
  8439. returnSuccessMsg("发票已作废");
  8440. return;
  8441. //}
  8442. //else
  8443. //{
  8444. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8445. // bill_entity.Update();
  8446. // returnErrorMsg(cres);
  8447. // return;
  8448. //}
  8449. //}
  8450. //else
  8451. //{
  8452. // returnErrorMsg("纸质发票只能作废本月的发票");
  8453. // return;
  8454. //}
  8455. }
  8456. //红冲
  8457. int redTag = 0;
  8458. string[] fpdmList = bill_entity.fpdm.Split(',');
  8459. string[] fphmList = bill_entity.fphm.Split(',');
  8460. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8461. {
  8462. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8463. return;
  8464. }
  8465. foreach (string billOrderId in billOrderList)
  8466. {
  8467. redTag++;
  8468. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8469. cres += onecres;
  8470. cres += ",";
  8471. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8472. {
  8473. bill_entity.state = 4;//已作废
  8474. //bill_entity.Update();
  8475. //returnSuccessMsg("发票已红冲");
  8476. }
  8477. else if (onecres.IndexOf("重复冲红") != -1)
  8478. {
  8479. bill_entity.state = 4;//已作废
  8480. //bill_entity.Update();
  8481. //returnSuccessMsg("发票已红冲");
  8482. }
  8483. else
  8484. {
  8485. string errmsg = commonHelper.KeepChinese(onecres);
  8486. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8487. }
  8488. }
  8489. bill_entity.Update();
  8490. if (cres.IndexOf("失败") != -1)
  8491. returnErrorMsg("红冲失败");
  8492. else
  8493. returnSuccessMsg("发票已红冲");
  8494. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8495. return;
  8496. }
  8497. return;
  8498. }
  8499. }
  8500. public void del_erp_billorder()
  8501. {
  8502. if (UrlPostParmsCheck("id"))
  8503. {
  8504. string eid = GetPostString("id");
  8505. CeErpBill.Del(eid);
  8506. CeErpBill bill = CeErpBill.Get(eid);
  8507. if (bill != null)
  8508. {
  8509. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8510. }
  8511. returnSuccessMsg("删除成功");
  8512. }
  8513. }
  8514. public void finish_erp_bill()
  8515. {
  8516. if (UrlPostParmsCheck("ids"))
  8517. {
  8518. string eids = GetPostString("ids");
  8519. string[] list = eids.Split(',');
  8520. foreach (string eid in list)
  8521. {
  8522. CeErpBill bill = CeErpBill.Get(eid);
  8523. if (bill != null)
  8524. {
  8525. bill.state = 2;
  8526. bill.Update();
  8527. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8528. }
  8529. }
  8530. returnSuccessMsg("操作成功");
  8531. }
  8532. }
  8533. public void get_erp_returncash()
  8534. {
  8535. DataStruct dStruct = GetPostStruct();
  8536. List<string> lw = new List<string>();
  8537. string tid = GetPostString("tid");
  8538. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8539. string shopname = GetPostString("shopname");
  8540. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8541. string buyernick = GetPostString("buyer_nick");
  8542. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8543. string customer = GetPostString("customer");
  8544. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8545. string returndate1 = GetPostString("returndate1");
  8546. string returndate2 = GetPostString("returndate2");
  8547. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8548. if (dw.Length > 0) lw.Add(dw);
  8549. string finishDate1 = GetPostString("finishdate1");
  8550. string finishDate2 = GetPostString("finishdate2");
  8551. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8552. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8553. string returntype = GetPostString("returntype");
  8554. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8555. string returnvstate = GetPostString("returnvstate");
  8556. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8557. dStruct.Order = "created desc";
  8558. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8559. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8560. writeGridDataTableJson(dStruct.TotalCount, dt);
  8561. }
  8562. public void get_erp_staygoods()
  8563. {
  8564. DataStruct dStruct = GetPostStruct();
  8565. List<string> lw = new List<string>();
  8566. string tid = GetPostString("tid");
  8567. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8568. string shopname = GetPostString("shopname");
  8569. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8570. string wangwang = GetPostString("wangwang");
  8571. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8572. string customer = GetPostString("customer");
  8573. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8574. string returndate1 = GetPostString("returndate1");
  8575. string returndate2 = GetPostString("returndate2");
  8576. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8577. if (dw.Length > 0) lw.Add(dw);
  8578. string finishDate1 = GetPostString("finishdate1");
  8579. string finishDate2 = GetPostString("finishdate2");
  8580. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8581. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8582. string returnvstate = GetPostString("returnvstate");
  8583. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8584. string persuadetype = GetPostString("persuadetype");
  8585. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8586. string customerOrg = GetPostString("customerOrg");
  8587. if (customerOrg.Length > 0)
  8588. {
  8589. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8590. }
  8591. dStruct.Order = "creata_time desc";
  8592. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8593. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8594. writeGridDataTableJson(dStruct.TotalCount, dt);
  8595. }
  8596. public void upd_erp_staygoods()
  8597. {
  8598. if (UrlPostParmsCheck("id"))
  8599. {
  8600. int eid = GetPostInt("id");
  8601. CeErpStayGoods entity = null;
  8602. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8603. if (entity != null)
  8604. {
  8605. entity.audit_type = 1;
  8606. entity.audit_time = DateTime.Now;
  8607. entity.audit_u_id = CurrentUser.UserID;
  8608. entity.audit_u_name = CurrentUser.UserName;
  8609. entity.Update();
  8610. returnSuccessMsg("审核成功!");
  8611. return;
  8612. }
  8613. returnErrorMsg("找不到订单记录");
  8614. }
  8615. }
  8616. public void upd_erp_stayGoodsback()
  8617. {
  8618. if (UrlPostParmsCheck("id"))
  8619. {
  8620. int eid = GetPostInt("id");
  8621. CeErpStayGoods entity = null;
  8622. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8623. if (entity != null)
  8624. {
  8625. entity.audit_text = GetPostString("reason");
  8626. entity.audit_type = 2;
  8627. entity.audit_time = DateTime.Now;
  8628. entity.audit_u_id = CurrentUser.UserID;
  8629. entity.audit_u_name = CurrentUser.UserName;
  8630. entity.Update();
  8631. returnSuccessMsg("退回成功!");
  8632. return;
  8633. }
  8634. returnErrorMsg("找不到订单记录");
  8635. }
  8636. }
  8637. public void upd_erp_returncashverify()
  8638. {
  8639. if (UrlPostParmsCheck("ID"))
  8640. {
  8641. int eid = GetPostInt("ID");
  8642. CeErpReturnCash entity = null;
  8643. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8644. if (entity != null)
  8645. {
  8646. entity.cashstate = 1;
  8647. entity.verifytime = DateTime.Now;
  8648. entity.verifyuserid = CurrentUser.UserID;
  8649. entity.Update();
  8650. returnSuccessMsg("审核成功!");
  8651. return;
  8652. }
  8653. returnErrorMsg("找不到订单记录");
  8654. }
  8655. }
  8656. public void upd_all_erp_returncashverify()
  8657. {
  8658. if (UrlPostParmsCheck("ID"))
  8659. {
  8660. String[] list = GetPostString("ID").Split(',');
  8661. CeErpReturnCash entity = null;
  8662. for (int i = 0; i < list.Length; i++)
  8663. {
  8664. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8665. if (entity != null)
  8666. {
  8667. if (entity.cashstate == 1)
  8668. {
  8669. returnErrorMsg("已审核过的订单不需要在审核!");
  8670. return;
  8671. }
  8672. entity.cashstate = 1;
  8673. entity.verifytime = DateTime.Now;
  8674. entity.verifyuserid = CurrentUser.UserID;
  8675. entity.Update();
  8676. }
  8677. }
  8678. returnSuccessMsg("审核成功!");
  8679. return;
  8680. }
  8681. }
  8682. public void upd_erp_returncashback()
  8683. {
  8684. if (UrlPostParmsCheck("ID"))
  8685. {
  8686. int eid = GetPostInt("ID");
  8687. CeErpReturnCash entity = null;
  8688. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8689. if (entity != null)
  8690. {
  8691. entity.backreason = GetPostString("reason");
  8692. entity.cashstate = 2;
  8693. entity.verifytime = DateTime.Now;
  8694. entity.verifyuserid = CurrentUser.UserID;
  8695. entity.Update();
  8696. returnSuccessMsg("退回成功!");
  8697. return;
  8698. }
  8699. returnErrorMsg("找不到订单记录");
  8700. }
  8701. }
  8702. public void upd_erp_returnprice()
  8703. {
  8704. if (UrlPostParmsCheck("ID"))
  8705. {
  8706. int eid = GetPostInt("ID");
  8707. CeErpReturnCash entity = null;
  8708. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8709. if (entity != null)
  8710. {
  8711. if (entity.cashstate == 1)
  8712. {
  8713. returnErrorMsg("审核通过了不能改");
  8714. return;
  8715. }
  8716. entity.returnprice = GetPostDouble("returnprice");
  8717. entity.Update();
  8718. returnSuccessMsg("修改成功!");
  8719. return;
  8720. }
  8721. returnErrorMsg("找不到订单记录");
  8722. }
  8723. }
  8724. public void del_erp_returncash()
  8725. {
  8726. if (UrlPostParmsCheck("ID"))
  8727. {
  8728. int eid = GetPostInt("ID");
  8729. CeErpReturnCash.Del(eid);
  8730. returnSuccessMsg("操作成功");
  8731. return;
  8732. }
  8733. }
  8734. public void test_for_do_sql()
  8735. {
  8736. string sql = GetPostString("sqlstr");
  8737. if (sql.Length > 0)
  8738. {
  8739. try
  8740. {
  8741. DbHelper.DbConn.ExecuteNonQuery(sql);
  8742. var res_obj = new
  8743. {
  8744. data = "成功",
  8745. };
  8746. string ro_json = JsonConvert.SerializeObject(res_obj);
  8747. returnSuccess(ro_json);
  8748. }
  8749. catch (Exception ex)
  8750. {
  8751. var res_obj = new
  8752. {
  8753. data = ex.Message,
  8754. };
  8755. string ro_json = JsonConvert.SerializeObject(res_obj);
  8756. returnSuccess(ro_json);
  8757. }
  8758. }
  8759. }
  8760. public void get_user_info()
  8761. {
  8762. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8763. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8764. }
  8765. public void get_total_data()
  8766. {
  8767. int userId = CurrentUser.UserID;
  8768. string sql = "";
  8769. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8770. {
  8771. 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);
  8772. }
  8773. else
  8774. {
  8775. 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 " +
  8776. "(select ID from CE_ErpUser where ID = {0}) d " +
  8777. "left join " +
  8778. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8779. ") a on d.ID = a.id left join " +
  8780. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8781. ") b on a.id = b.id1 left join" +
  8782. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8783. ") c on a.id = c.id2;", userId);
  8784. }
  8785. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8786. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8787. }
  8788. public void get_date_area_total_data2()
  8789. {
  8790. int userId = CurrentUser.UserID;
  8791. string date_type = GetPostString("timetype");
  8792. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8793. string sql = "";
  8794. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8795. {
  8796. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8797. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8798. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8799. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8800. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8801. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8802. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8803. ") a on e.ID = a.id left join " +
  8804. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8805. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8806. ") b on a.id = b.id1 " +
  8807. "left join " +
  8808. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8809. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8810. ") c on a.id = c.id2 " +
  8811. "left join " +
  8812. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8813. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8814. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8815. }
  8816. else
  8817. {
  8818. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8819. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8820. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8821. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8822. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8823. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8824. ") a on e.ID = a.id left join " +
  8825. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8826. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8827. ") c on a.id = c.id2 " +
  8828. "left join " +
  8829. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8830. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8831. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8832. }
  8833. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8834. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8835. }
  8836. public void get_date_area_total_data()
  8837. {
  8838. int userId = CurrentUser.UserID;
  8839. string date_type = GetPostString("timetype");
  8840. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8841. string date1 = searchDT[0].ToString();
  8842. string date2 = searchDT[1].ToString();
  8843. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8844. {
  8845. SqlParameter[] sqlParameter ={
  8846. new SqlParameter("@userId", SqlDbType.Int,4),
  8847. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8848. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8849. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8850. };
  8851. sqlParameter[0].Value = userId;
  8852. sqlParameter[1].Value = date1;
  8853. sqlParameter[2].Value = date2;
  8854. sqlParameter[3].Direction = ParameterDirection.Output;
  8855. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8856. string res = sqlParameter[3].Value.ToString();
  8857. var res_obj = new
  8858. {
  8859. data = res
  8860. };
  8861. string ro_json = JsonConvert.SerializeObject(res_obj);
  8862. returnSuccess(ro_json);
  8863. }
  8864. else
  8865. {
  8866. SqlParameter[] sqlParameter ={
  8867. new SqlParameter("@userId", SqlDbType.Int,4),
  8868. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8869. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8870. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8871. };
  8872. sqlParameter[0].Value = userId;
  8873. sqlParameter[1].Value = date1;
  8874. sqlParameter[2].Value = date2;
  8875. sqlParameter[3].Direction = ParameterDirection.Output;
  8876. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8877. string res = sqlParameter[3].Value.ToString();
  8878. var res_obj = new
  8879. {
  8880. data = res
  8881. };
  8882. string ro_json = JsonConvert.SerializeObject(res_obj);
  8883. returnSuccess(ro_json);
  8884. }
  8885. //writeGridDataViewJson(dt.Rows.Count, dv);
  8886. }
  8887. public void get_order_list()
  8888. {
  8889. string strFields = GetPostString("paraFields");
  8890. string strOrder = GetPostString("paraOrder");
  8891. string strWhere = GetPostString("paraWhere");
  8892. string strPageSize = GetPostString("paraPageSize");
  8893. DataStruct dStruct = GetPostStruct();
  8894. dStruct.PageSize = int.Parse(strPageSize);
  8895. dStruct.Fileds = strFields;
  8896. dStruct.Order = strOrder;
  8897. dStruct.MainWhere = strWhere;
  8898. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8899. writeGridDataTableJson(dStruct.TotalCount, dt);
  8900. }
  8901. ////获取待开始订单列表
  8902. //public void get_wait_design_order_list()
  8903. //{
  8904. // string date_type = GetPostString("date_type");
  8905. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8906. // DataStruct dStruct = GetPostStruct();
  8907. // dStruct.PageSize = 1000;
  8908. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8909. // List<string> lw = new List<string>();
  8910. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8911. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  8912. // dStruct.Order = "WaitDesignTime asc";
  8913. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8914. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8915. // writeGridDataTableJson(dStruct.TotalCount, dt);
  8916. //}
  8917. //获取完成单量排名
  8918. public void get_finish_order_count_ranking()
  8919. {
  8920. /* string date_type = GetPostString("date_type");
  8921. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8922. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8923. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8924. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  8925. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8926. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8927. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8928. writeGridDataTableJson(0, new DataTable());
  8929. }
  8930. public void get_finish_order_amount_ranking()
  8931. {
  8932. /*string date_type = GetPostString("date_type");
  8933. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8934. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8935. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8936. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  8937. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8938. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8939. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8940. writeGridDataTableJson(0, new DataTable());
  8941. }
  8942. public void get_finish_refund_count_ranking()
  8943. {
  8944. string date_type = GetPostString("date_type");
  8945. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8946. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8947. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8948. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  8949. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8950. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8951. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8952. writeGridDataTableJson(dt.Rows.Count, dt);
  8953. }
  8954. public void get_finish_refund_amount_ranking()
  8955. {
  8956. string date_type = GetPostString("date_type");
  8957. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8958. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8959. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8960. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  8961. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8962. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8963. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8964. writeGridDataTableJson(dt.Rows.Count, dt);
  8965. }
  8966. public void set_erp_finishorder_director()
  8967. {
  8968. if (UrlPostParmsCheck("ctid"))
  8969. {
  8970. string eid = GetPostString("ctid");
  8971. CeErpTradeCell entity = null;
  8972. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8973. if (entity != null)
  8974. {
  8975. entity.OrderState = 8;
  8976. entity.Update();
  8977. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  8978. returnSuccessMsg("操作成功!");
  8979. return;
  8980. }
  8981. returnErrorMsg("找不到记录");
  8982. }
  8983. }
  8984. public void get_erp_placeregistlist()
  8985. {
  8986. DataStruct dStruct = GetPostStruct();
  8987. List<string> lw = new List<string>();
  8988. string outsid = GetPostString("outsid");
  8989. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  8990. string memo = GetPostString("memo");
  8991. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  8992. string filename = GetPostString("filename");
  8993. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  8994. string islate = GetPostString("islate");
  8995. if (islate.Length > 0)
  8996. {
  8997. if (islate == "1")
  8998. lw.Add(string.Format("OutLate>0"));
  8999. else
  9000. lw.Add(string.Format("OutLate=0"));
  9001. }
  9002. string placedate1 = GetPostString("placedate1");
  9003. string placedate2 = GetPostString("placedate2");
  9004. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9005. if (dw.Length > 0) lw.Add(dw);
  9006. string deliveryDate1 = GetPostString("deliverydate1");
  9007. string deliveryDate2 = GetPostString("deliverydate2");
  9008. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9009. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9010. dStruct.Order = "ID desc";
  9011. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9012. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9013. writeGridDataTableJson(dStruct.TotalCount, dt);
  9014. }
  9015. public void ins_erp_placeregist()
  9016. {
  9017. if (UrlPostParmsCheck("id"))
  9018. {
  9019. string eid = GetPostString("id");
  9020. CeErpPlaceRegister entity = null;
  9021. if (eid == "0")//新增
  9022. {
  9023. entity = new CeErpPlaceRegister();
  9024. string xdTime = GetPostString("placeTime");
  9025. if (xdTime.Length > 0)
  9026. {
  9027. entity.PlactTime = Convert.ToDateTime(xdTime);
  9028. }
  9029. string fhTime = GetPostString("deliveryTime");
  9030. if (fhTime.Length > 0)
  9031. {
  9032. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9033. }
  9034. string preTime = GetPostString("preOutTime");
  9035. if (preTime.Length > 0)
  9036. {
  9037. entity.PreOutTime = Convert.ToDateTime(preTime);
  9038. }
  9039. entity.DeliveryCount = GetPostInt("deliveryCount");
  9040. entity.ReceiveCount = GetPostInt("receiveCount");
  9041. entity.OutSid = GetPostString("outSid");
  9042. entity.FileName = GetPostString("fileName");
  9043. entity.Memo = GetPostString("memo");
  9044. entity.AddUserId = CurrentUser.UserID;
  9045. entity.CreateTime = DateTime.Now;
  9046. entity.Img = GetPostString("img");
  9047. entity.Supplier = GetPostInt("supplier");
  9048. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9049. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9050. {
  9051. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9052. DateTime dt2 = (DateTime)entity.PreOutTime;
  9053. TimeSpan span = dt1.Subtract(dt2);
  9054. if (span.Days > 0)
  9055. {
  9056. entity.OutLate = span.Days;
  9057. }
  9058. }
  9059. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9060. entity.Create();
  9061. returnSuccessMsg("添加成功!");
  9062. return;
  9063. }
  9064. else //修改
  9065. {
  9066. entity = CeErpPlaceRegister.Get(eid);
  9067. if (entity != null)
  9068. {
  9069. string xdTime = GetPostString("placeTime");
  9070. if (xdTime.Length > 0)
  9071. {
  9072. entity.PlactTime = Convert.ToDateTime(xdTime);
  9073. }
  9074. string fhTime = GetPostString("deliveryTime");
  9075. if (fhTime.Length > 0)
  9076. {
  9077. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9078. }
  9079. string preTime = GetPostString("preOutTime");
  9080. if (preTime.Length > 0)
  9081. {
  9082. entity.PreOutTime = Convert.ToDateTime(preTime);
  9083. }
  9084. entity.DeliveryCount = GetPostInt("deliveryCount");
  9085. entity.ReceiveCount = GetPostInt("receiveCount");
  9086. if (entity.DeliveryCount == entity.ReceiveCount)
  9087. {
  9088. entity.CurState = "已完成";
  9089. }
  9090. else
  9091. {
  9092. entity.CurState = "未完成";
  9093. }
  9094. entity.OutSid = GetPostString("outSid");
  9095. entity.FileName = GetPostString("fileName");
  9096. entity.Memo = GetPostString("memo");
  9097. entity.Img = GetPostString("img");
  9098. entity.Supplier = GetPostInt("supplier");
  9099. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9100. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9101. {
  9102. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9103. DateTime dt2 = (DateTime)entity.PreOutTime;
  9104. TimeSpan span = dt1.Subtract(dt2);
  9105. if (span.Days > 0)
  9106. {
  9107. entity.OutLate = span.Days;
  9108. }
  9109. }
  9110. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9111. entity.Update();
  9112. returnSuccessMsg("修改成功");
  9113. return;
  9114. }
  9115. returnErrorMsg("找不到对应的记录");
  9116. return;
  9117. }
  9118. }
  9119. returnErrorMsg("缺少必要参数");
  9120. }
  9121. public void del_erp_placeregist()
  9122. {
  9123. string eid = GetPostString("id");
  9124. CeErpPlaceRegister.Del(eid);
  9125. returnSuccessMsg("删除成功!");
  9126. return;
  9127. }
  9128. public void ins_erp_placeregistbyorder()
  9129. {
  9130. string ctid = GetPostString("ctid");
  9131. if (ctid.Length > 0)
  9132. {
  9133. StringBuilder sql = new StringBuilder();
  9134. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9135. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9136. if (dt.Rows.Count > 0)
  9137. {
  9138. foreach (DataRow dr in dt.Rows)
  9139. {
  9140. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9141. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9142. entity.AddUserId = CurrentUser.UserID;
  9143. entity.tid = dr["tid"].ToString();
  9144. entity.Did = Convert.ToString(dr["ctid"]);
  9145. entity.splitTag = dr["SplitTag"].ToString();
  9146. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9147. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9148. if (pre_ctid.Length > 0)
  9149. {
  9150. sellmemo = sellmemo.Replace(pre_ctid, "");
  9151. }
  9152. sellmemo = sellmemo.Replace("[", "");
  9153. sellmemo = sellmemo.Replace("]", "");
  9154. entity.FileName = sellmemo;
  9155. string count = dr["ProductCount"].ToString();
  9156. int usecount = commonHelper.getIntCountFromString(count);
  9157. entity.DeliveryCount = usecount;
  9158. entity.CurState = "未完成";
  9159. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9160. {
  9161. entity.Supplier = 24;//dl手提袋定制
  9162. }
  9163. else
  9164. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9165. entity.CreateTime = DateTime.Now;
  9166. entity.Create();
  9167. }
  9168. returnSuccessMsg("操作成功");
  9169. return;
  9170. }
  9171. returnErrorMsg("没有找到对应订单");
  9172. return;
  9173. }
  9174. returnErrorMsg("缺少订单编号");
  9175. return;
  9176. }
  9177. public void get_erp_persuadelist()
  9178. {
  9179. DataStruct dStruct = GetPostStruct();
  9180. List<string> lw = new List<string>();
  9181. string ctid = GetPostString("ctid");
  9182. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9183. string shopname = GetPostString("shopname");
  9184. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9185. string buyernick = GetPostString("buyer_nick");
  9186. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9187. string customer = GetPostString("customer");
  9188. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9189. string returndate1 = GetPostString("returndate1");
  9190. string returndate2 = GetPostString("returndate2");
  9191. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9192. if (dw.Length > 0) lw.Add(dw);
  9193. string finishDate1 = GetPostString("finishdate1");
  9194. string finishDate2 = GetPostString("finishdate2");
  9195. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9196. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9197. string persuadetype = GetPostString("persuadetype");
  9198. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9199. string returnvstate = GetPostString("returnvstate");
  9200. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9201. dStruct.Order = "created desc";
  9202. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9203. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9204. writeGridDataTableJson(dStruct.TotalCount, dt);
  9205. }
  9206. public void upd_erp_returnpersuadeback()
  9207. {
  9208. if (UrlPostParmsCheck("ID"))
  9209. {
  9210. int eid = GetPostInt("ID");
  9211. CeErpPersuade entity = null;
  9212. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9213. if (entity != null)
  9214. {
  9215. entity.backreason = GetPostString("reason");
  9216. entity.pstate = 2;
  9217. entity.verifytime = DateTime.Now;
  9218. entity.verifyuserid = CurrentUser.UserID;
  9219. entity.Update();
  9220. returnSuccessMsg("退回成功!");
  9221. return;
  9222. }
  9223. returnErrorMsg("找不到订单记录");
  9224. }
  9225. }
  9226. public void upd_erp_returnpersuadeverify()
  9227. {
  9228. if (UrlPostParmsCheck("ID"))
  9229. {
  9230. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9231. {
  9232. returnErrorMsg("暂无权限审核");
  9233. return;
  9234. }
  9235. int eid = GetPostInt("ID");
  9236. CeErpPersuade entity = null;
  9237. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9238. if (entity != null)
  9239. {
  9240. entity.pstate = 1;
  9241. entity.verifytime = DateTime.Now;
  9242. entity.verifyuserid = CurrentUser.UserID;
  9243. entity.Update();
  9244. returnSuccessMsg("审核成功!");
  9245. return;
  9246. }
  9247. returnErrorMsg("找不到订单记录");
  9248. }
  9249. }
  9250. public void del_erp_persuade()
  9251. {
  9252. if (UrlPostParmsCheck("ID"))
  9253. {
  9254. int eid = GetPostInt("ID");
  9255. CeErpPersuade.Del(eid);
  9256. returnSuccessMsg("操作成功");
  9257. return;
  9258. }
  9259. }
  9260. public void get_erp_oldcustoupload()
  9261. {
  9262. DataStruct dStruct = GetPostStruct();
  9263. List<string> lw = new List<string>();
  9264. string buyernick = GetPostString("buyer_nick");
  9265. if (buyernick.Length > 0)
  9266. {
  9267. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9268. }
  9269. else
  9270. return;
  9271. dStruct.Order = "pay_time desc";
  9272. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9273. DataTable dt = null;
  9274. dt = WebCache.GetData("view_erptradecell", dStruct);
  9275. writeGridDataTableJson(dStruct.TotalCount, dt);
  9276. }
  9277. public void get_erp_checkorderlist()
  9278. {
  9279. DataStruct dStruct = GetPostStruct();
  9280. List<string> lw = new List<string>();
  9281. string tid = GetPostString("ctid");
  9282. if (tid.Length > 0)
  9283. {
  9284. string select_tid = getTidByCtid(tid);
  9285. lw.Add(string.Format("tid='{0}'", select_tid));
  9286. }
  9287. string shopname = GetPostString("shopname");
  9288. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9289. string buyernick = GetPostString("buyer_nick");
  9290. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9291. string customer = GetPostString("customer");
  9292. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9293. string design = GetPostString("design");
  9294. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9295. string orderState = GetPostString("orderState");
  9296. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9297. string address = GetPostString("address");
  9298. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9299. string sellermemo = GetPostString("seller_memo");
  9300. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9301. string supplier = GetPostString("supplier");
  9302. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9303. {
  9304. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9305. }
  9306. else
  9307. {
  9308. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9309. }
  9310. string date1 = GetPostString("date1");
  9311. string date2 = GetPostString("date2");
  9312. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9313. if (dw.Length > 0) lw.Add(dw);
  9314. string placedate1 = GetPostString("placedate1");
  9315. string placedate2 = GetPostString("placedate2");
  9316. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9317. if (fdw.Length > 0) lw.Add(fdw);
  9318. string price1 = GetPostString("price1");
  9319. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9320. string price2 = GetPostString("price2");
  9321. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9322. string checkst = GetPostString("checkstate");
  9323. if (checkst.Length > 0 && "10".Equals(checkst))
  9324. {
  9325. lw.Add(string.Format("CheckOut>0"));
  9326. }
  9327. else
  9328. {
  9329. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9330. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9331. }
  9332. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9333. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9334. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9335. writeGridDataTableJson(dStruct.TotalCount, dt);
  9336. }
  9337. public void ins_erp_startCheck()
  9338. {
  9339. if (UrlPostParmsCheck("ctid"))
  9340. {
  9341. string eid = GetPostString("ctid");
  9342. CeErpTradeCell entity = null;
  9343. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9344. if (entity != null)
  9345. {
  9346. entity.MemoOpt = 4;
  9347. entity.UpdateTime = DateTime.Now;
  9348. entity.Update();
  9349. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9350. CeErpSukuraData.createInfo(entity.ctid, 6);
  9351. returnSuccessMsg("操作成功!");
  9352. return;
  9353. }
  9354. returnErrorMsg("找不到记录");
  9355. }
  9356. }
  9357. public void upd_erp_sendXlw()
  9358. {
  9359. if (UrlPostParmsCheck("ctid"))
  9360. {
  9361. string eid = GetPostString("ctid");
  9362. CeErpTradeCell entity = null;
  9363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9364. if (entity != null)
  9365. {
  9366. if (entity.IsSendGift == 1)
  9367. {
  9368. returnErrorMsg("请勿重复标记");
  9369. return;
  9370. }
  9371. entity.IsSendGift = 1;
  9372. entity.Update();
  9373. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9374. returnSuccessMsg("操作成功!");
  9375. return;
  9376. }
  9377. returnErrorMsg("找不到记录");
  9378. }
  9379. }
  9380. public void cancel_sendXlw()
  9381. {
  9382. if (UrlPostParmsCheck("ctid"))
  9383. {
  9384. string eid = GetPostString("ctid");
  9385. CeErpTradeCell entity = null;
  9386. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9387. if (entity != null)
  9388. {
  9389. if (entity.IsSendGift == 0)
  9390. {
  9391. returnErrorMsg("未标记小礼物");
  9392. return;
  9393. }
  9394. entity.IsSendGift = 0;
  9395. entity.Update();
  9396. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9397. returnSuccessMsg("操作成功!");
  9398. return;
  9399. }
  9400. returnErrorMsg("找不到记录");
  9401. }
  9402. }
  9403. public void get_erp_designbill()
  9404. {
  9405. DataStruct dStruct = GetPostStruct();
  9406. List<string> lw = new List<string>();
  9407. int isMy = GetInt("my");
  9408. if (isMy == 1)
  9409. {
  9410. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9411. }
  9412. string tid = GetPostString("tid");
  9413. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9414. string userName = GetPostString("design");
  9415. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9416. string price1 = GetPostString("price1");
  9417. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9418. string price2 = GetPostString("price2");
  9419. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9420. string rePrice1 = GetPostString("rePrice1");
  9421. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9422. string rePrice2 = GetPostString("rePrice2");
  9423. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9424. string designerType = GetPostString("designerType");
  9425. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9426. string orderState = GetPostString("orderState");
  9427. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9428. string endTime1 = GetPostString("endTime1");
  9429. string endTime2 = GetPostString("endTime2");
  9430. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9431. if (dw.Length > 0) lw.Add(dw);
  9432. string isDk = GetPostString("isDk");
  9433. if (isDk == "1")
  9434. {
  9435. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9436. }
  9437. else if (isDk == "0")
  9438. {
  9439. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9440. }
  9441. dStruct.Order = "oid, create_time desc";
  9442. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9443. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9444. writeGridDataTableJson(dStruct.TotalCount, dt);
  9445. }
  9446. public void upd_erp_designerbill()
  9447. {
  9448. if (UrlPostParmsCheck("ID"))
  9449. {
  9450. string eid = GetPostString("ID");
  9451. CeErpDesignerBill entity = null;
  9452. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9453. if (entity != null)
  9454. {
  9455. if (GetPostDouble("designerpirce") > 0)
  9456. {
  9457. entity.realPrice = GetPostDouble("designerpirce");
  9458. entity.update_time = DateTime.Now;
  9459. entity.update_u_id = CurrentUser.UserID;
  9460. entity.update_u_name = CurrentUser.UserName;
  9461. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9462. entity.Update();
  9463. returnSuccessMsg("操作成功!");
  9464. return;
  9465. }
  9466. else
  9467. {
  9468. entity.price = GetPostDouble("price");
  9469. entity.update_time = DateTime.Now;
  9470. entity.update_u_id = CurrentUser.UserID;
  9471. entity.update_u_name = CurrentUser.UserName;
  9472. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9473. entity.Update();
  9474. returnSuccessMsg("操作成功!");
  9475. return;
  9476. }
  9477. }
  9478. returnErrorMsg("找不到记录");
  9479. }
  9480. }
  9481. public void audit_erp_designerbill()
  9482. {
  9483. if (UrlPostParmsCheck("ID"))
  9484. {
  9485. string eid = GetPostString("ID");
  9486. CeErpDesignerBill entity = null;
  9487. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9488. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9489. if (entity != null)
  9490. {
  9491. entity.realPrice = GetPostDouble("designerpirce");
  9492. entity.update_time = DateTime.Now;
  9493. entity.update_u_id = CurrentUser.UserID;
  9494. entity.update_u_name = CurrentUser.UserName;
  9495. entity.isAudit = 1;
  9496. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9497. entity.Update();
  9498. if (orderEntity != null)
  9499. {
  9500. orderEntity.IsReadTag = 3;
  9501. orderEntity.Update();
  9502. }
  9503. returnSuccessMsg("操作成功!");
  9504. return;
  9505. }
  9506. returnErrorMsg("找不到记录");
  9507. }
  9508. }
  9509. public void all_audit_erp_designerbill()
  9510. {
  9511. if (UrlPostParmsCheck("idList"))
  9512. {
  9513. string[] list = GetPostString("idList").Split(',');
  9514. CeErpDesignerBill entity = null;
  9515. for (int i = 0; i < list.Length; i++)
  9516. {
  9517. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9518. if (entity == null) return;
  9519. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9520. if (orderEntity == null) return;
  9521. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9522. entity.update_time = DateTime.Now;
  9523. entity.update_u_id = CurrentUser.UserID;
  9524. entity.update_u_name = CurrentUser.UserName;
  9525. entity.isAudit = 1;
  9526. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9527. entity.Update();
  9528. orderEntity.IsReadTag = 3;
  9529. orderEntity.Update();
  9530. }
  9531. returnSuccessMsg("操作成功!");
  9532. return;
  9533. }
  9534. }
  9535. public void get_erp_sameorders()
  9536. {
  9537. if (UrlPostParmsCheck("ctid"))
  9538. {
  9539. string eid = GetPostString("ctid");
  9540. CeErpTradeCell entity = null;
  9541. entity = CeErpTradeCell.GetByCtid(eid);
  9542. if (entity != null)
  9543. {
  9544. StringBuilder sql = new StringBuilder();
  9545. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9546. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9547. var res = new
  9548. {
  9549. data = dt.Rows.Count
  9550. };
  9551. string ro_jsond = JsonConvert.SerializeObject(res);
  9552. returnSuccess(ro_jsond);
  9553. return;
  9554. }
  9555. returnErrorMsg("未找到订单");
  9556. return;
  9557. }
  9558. returnErrorMsg("缺少必要的参数");
  9559. }
  9560. public void get_erp_islasthavesameorder()
  9561. {
  9562. if (UrlPostParmsCheck("ctid"))
  9563. {
  9564. string eid = GetPostString("ctid");
  9565. string[] ctidList = eid.Split(',');
  9566. StringBuilder sql = new StringBuilder();
  9567. string tisCtid = "";
  9568. foreach (string ctid in ctidList)
  9569. {
  9570. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9571. if (entity != null)
  9572. {
  9573. sql = new StringBuilder();
  9574. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9575. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9576. if (dth.Rows.Count > 0)
  9577. {
  9578. tisCtid += entity.ctid;
  9579. tisCtid += ",";
  9580. }
  9581. }
  9582. }
  9583. if (tisCtid.Length > 0)
  9584. {
  9585. var res = new
  9586. {
  9587. data = tisCtid
  9588. };
  9589. string ro_jsond = JsonConvert.SerializeObject(res);
  9590. returnSuccess(ro_jsond);
  9591. }
  9592. else
  9593. {
  9594. var res = new
  9595. {
  9596. data = ""
  9597. };
  9598. string ro_jsond = JsonConvert.SerializeObject(res);
  9599. returnSuccess(ro_jsond);
  9600. }
  9601. return;
  9602. }
  9603. returnErrorMsg("缺少必要的参数");
  9604. }
  9605. public void file_client_down_url()
  9606. {
  9607. if (!UrlPostParmsCheck("userId"))
  9608. {
  9609. returnErrorMsg("缺少必要的参数");
  9610. }
  9611. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9612. }
  9613. public void checkout_form_data()
  9614. {
  9615. if (!UrlPostParmsCheck("tid"))
  9616. {
  9617. returnErrorMsg("缺少必要的参数");
  9618. }
  9619. string tid = GetPostString("tid");
  9620. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9621. if (ceErpOrderFormData != null)
  9622. {
  9623. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9624. returnSuccess(ro_jsond);
  9625. return;
  9626. }
  9627. returnErrorMsg("尚未有文件!");
  9628. }
  9629. public void back_supplier_audit()
  9630. {
  9631. int userId = CurrentUser.UserID;
  9632. StringBuilder sql = new StringBuilder();
  9633. 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);
  9634. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9635. if (dt.Rows.Count > 0)
  9636. {
  9637. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9638. }
  9639. else
  9640. {
  9641. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9642. }
  9643. }
  9644. public void back_supplier_query()
  9645. {
  9646. string eid = GetPostString("ctid");
  9647. if (eid != "")
  9648. {
  9649. StringBuilder sql = new StringBuilder();
  9650. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9651. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9652. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9653. }
  9654. else
  9655. {
  9656. returnErrorMsg("找不到订单记录");
  9657. return;
  9658. }
  9659. }
  9660. public void verified_to_order()
  9661. {
  9662. int userId = CurrentUser.UserID;
  9663. StringBuilder sql = new StringBuilder();
  9664. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9665. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9666. if (dt.Rows.Count > 0)
  9667. {
  9668. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9669. }
  9670. else
  9671. {
  9672. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9673. }
  9674. }
  9675. public void upd_supplier_audit()
  9676. {
  9677. if (UrlPostParmsCheck("ctid"))
  9678. {
  9679. string eid = GetPostString("ctid");
  9680. string reason = GetPostString("returnreason");
  9681. CeErpTradeCell entity = null;
  9682. CeWithdraw withdraw = null;
  9683. withdraw = CeWithdraw.GetByTid(eid);
  9684. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9685. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9686. {
  9687. if (withdraw != null)
  9688. {
  9689. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9690. {
  9691. returnSuccessMsg("您没有权限操作!");
  9692. return;
  9693. }
  9694. else
  9695. {
  9696. if (reason.Equals("1"))
  9697. {
  9698. if (entity.OrderState == -1)
  9699. {
  9700. if (entity.FinishPlaceTime == null)
  9701. {
  9702. entity.OrderState = 2;
  9703. }
  9704. else
  9705. {
  9706. entity.OrderState = 6;
  9707. }
  9708. }
  9709. entity.Update();
  9710. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9711. if (withdraw != null)
  9712. {
  9713. withdraw.status = int.Parse(reason);
  9714. withdraw.Update();
  9715. }
  9716. returnSuccessMsg("操作成功!");
  9717. return;
  9718. }
  9719. else
  9720. {
  9721. withdraw.status = int.Parse(reason);
  9722. withdraw.acknowledgingtime = DateTime.Now;
  9723. withdraw.Update();
  9724. returnSuccessMsg("查看详细请点击线下订单查询");
  9725. return;
  9726. }
  9727. }
  9728. }
  9729. // 第一个字符是 'N'
  9730. }
  9731. if (eid[0] != 'N')
  9732. {
  9733. }
  9734. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9735. {
  9736. entity.IsVerifyToSupplier = false;
  9737. entity.IsReturn = 1;
  9738. entity.ReturnTime = DateTime.Now;
  9739. entity.ReturnReason = reason;
  9740. if (entity.OrderState == 6)
  9741. {
  9742. entity.OrderState = 5;
  9743. }
  9744. entity.Update();
  9745. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9746. if (withdraw != null)
  9747. {
  9748. withdraw.status = int.Parse(reason);
  9749. withdraw.Update();
  9750. }
  9751. returnSuccessMsg("操作成功!");
  9752. return;
  9753. }
  9754. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9755. {
  9756. ;
  9757. if (withdraw != null)
  9758. {
  9759. withdraw.status = int.Parse(reason);
  9760. withdraw.acknowledgingtime = DateTime.Now;
  9761. withdraw.Update();
  9762. returnSuccessMsg("供应商取消撤回!");
  9763. return;
  9764. }
  9765. }
  9766. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9767. {
  9768. if (entity.OrderState == -1)
  9769. {
  9770. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9771. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id))
  9772. {
  9773. returnErrorMsg("订单spu没有确认无法通过审核!");
  9774. return;
  9775. }
  9776. if (entity.FinishPlaceTime == null)
  9777. {
  9778. entity.OrderState = 2;
  9779. }
  9780. else
  9781. {
  9782. entity.OrderState = 3;
  9783. }
  9784. commonHelper.getCytPrice(entity);
  9785. }
  9786. entity.Update();
  9787. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9788. if (withdraw != null)
  9789. {
  9790. withdraw.status = int.Parse(reason);
  9791. withdraw.Update();
  9792. }
  9793. returnSuccessMsg("操作成功!");
  9794. return;
  9795. }
  9796. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9797. {
  9798. if (withdraw == null)
  9799. {
  9800. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9801. return;
  9802. }
  9803. }
  9804. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9805. {
  9806. if (withdraw != null)
  9807. {
  9808. withdraw.status = int.Parse(reason);
  9809. withdraw.acknowledgingtime = DateTime.Now;
  9810. withdraw.Update();
  9811. returnSuccessMsg("查看详细请点击线下订单查询");
  9812. return;
  9813. }
  9814. }
  9815. return;
  9816. }
  9817. }
  9818. //校验报价
  9819. public void refund_order_tip()
  9820. {
  9821. int userid = CurrentUser.UserID;
  9822. int sectionId = CurrentUser.UserPost.OrgID;
  9823. StringBuilder sql = new StringBuilder();
  9824. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9825. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9826. List<string> ids = new List<string>();
  9827. if (dth.Rows.Count > 0)
  9828. {
  9829. foreach (DataRow dr in dth.Rows)
  9830. {
  9831. ids.Add(dr["ID"].ToString());
  9832. }
  9833. try
  9834. {
  9835. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9836. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9837. }
  9838. catch (Exception ex)
  9839. {
  9840. }
  9841. }
  9842. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9843. }
  9844. public void refund_order_Design()
  9845. {
  9846. int userid = CurrentUser.UserID;
  9847. int sectionId = CurrentUser.UserPost.OrgID;
  9848. StringBuilder sql = new StringBuilder();
  9849. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9850. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9851. List<string> ids = new List<string>();
  9852. if (dth.Rows.Count > 0)
  9853. {
  9854. foreach (DataRow dr in dth.Rows)
  9855. {
  9856. ids.Add(dr["ID"].ToString());
  9857. }
  9858. try
  9859. {
  9860. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9861. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9862. }
  9863. catch (Exception ex)
  9864. {
  9865. }
  9866. }
  9867. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9868. }
  9869. public void change_order_info()
  9870. {
  9871. int userid = CurrentUser.UserID;
  9872. StringBuilder sql = new StringBuilder();
  9873. 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);
  9874. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9875. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9876. }
  9877. public void change_win_mome()
  9878. {
  9879. if (UrlPostParmsCheck("id,ctid"))
  9880. {
  9881. string id = GetPostString("id");
  9882. string ctid = GetPostString("ctid");
  9883. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9884. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9885. if (ce == null || ceErpMessageTip == null)
  9886. {
  9887. returnSuccessMsg("未找到对应的订单!");
  9888. return;
  9889. }
  9890. if (ce.OrderState >= 5)
  9891. {
  9892. returnSuccessMsg("已上传文件无法修改!");
  9893. return;
  9894. }
  9895. int type = GetPostInt("type");
  9896. string content = GetPostString("content");
  9897. if (type == 0)
  9898. {
  9899. content = content.Replace("(", "(");
  9900. content = content.Replace(")", ")");
  9901. string check = MidStrEx(content, "(", ")").Trim();
  9902. if (string.IsNullOrEmpty(check))
  9903. {
  9904. returnSuccessMsg("文件名格式不正确");
  9905. return;
  9906. }
  9907. }
  9908. ce.DispatchSort = 0;
  9909. ce.seller_memo = content;
  9910. ce.Update();
  9911. ceErpMessageTip.isVisit = true;
  9912. ceErpMessageTip.Update();
  9913. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  9914. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  9915. ApiVo apiVo = new ApiVo();
  9916. apiVo.orderNumber = ce.ctid;
  9917. apiVo.actionName = "demandDesign";
  9918. apiVo.orderRemarks = content;
  9919. apiVo.demandExamine = type + 1;
  9920. designHelper.API_WorkCore(apiVo);//demandDesign
  9921. returnSuccessMsg("修改成功!");
  9922. }
  9923. }
  9924. public static string MidStrEx(string sourse, string startstr, string endstr)
  9925. {
  9926. string result = string.Empty;
  9927. int startindex, endindex;
  9928. try
  9929. {
  9930. startindex = sourse.IndexOf(startstr);
  9931. if (startindex == -1)
  9932. return result;
  9933. string tmpstr = sourse.Substring(startindex + startstr.Length);
  9934. endindex = tmpstr.IndexOf(endstr);
  9935. if (endindex == -1)
  9936. return result;
  9937. result = tmpstr.Remove(endindex);
  9938. }
  9939. catch (Exception ex)
  9940. {
  9941. Console.WriteLine("MidStrEx Err:" + ex.Message);
  9942. }
  9943. return result;
  9944. }
  9945. public void refund_order_list()
  9946. {
  9947. int userid = CurrentUser.UserID;
  9948. int sectionId = CurrentUser.UserPost.OrgID;
  9949. StringBuilder sql = new StringBuilder();
  9950. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  9951. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9952. DataStruct dStruct = GetPostStruct();
  9953. DataTable dt = null;
  9954. List<string> ids = new List<string>();
  9955. List<string> tids = new List<string>();
  9956. if (dth.Rows.Count > 0)
  9957. {
  9958. foreach (DataRow dr in dth.Rows)
  9959. {
  9960. tids.Add("'" + dr["tid"].ToString() + "'");
  9961. ids.Add(dr["id"].ToString());
  9962. }
  9963. try
  9964. {
  9965. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  9966. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9967. List<string> lw = new List<string>();
  9968. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  9969. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9970. dt = WebCache.GetData("view_orderlist", dStruct);
  9971. }
  9972. catch (Exception ex)
  9973. {
  9974. }
  9975. }
  9976. writeGridDataTableJson(dStruct.TotalCount, dt);
  9977. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  9978. }
  9979. //新增
  9980. public void order_batch_downloads()
  9981. {
  9982. string ceid = GetPostString("tid");
  9983. String[] tid = ceid.Split(',');
  9984. order_batch_caiyingtong(tid);
  9985. /* (string success, string errors) = UploadFiles(tid);
  9986. returnSuccessMsg(success + errors);*/
  9987. return;
  9988. }
  9989. //报价接口
  9990. public void Get_To_Quote()
  9991. {
  9992. string ceid = GetPostString("ctid");
  9993. if (ceid != null)
  9994. {
  9995. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  9996. if (entity != null)
  9997. {
  9998. if (entity.seller_memo.IndexOf("种子纸") > -1)
  9999. {
  10000. return;
  10001. }
  10002. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10003. double price = 0;
  10004. if (cp == null)
  10005. {
  10006. JObject jsonObject12 = new JObject
  10007. {
  10008. { "UserId", "77886" },
  10009. { "Pwd", "lt666888" },
  10010. { "Filename", entity.seller_memo }
  10011. };
  10012. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10013. JObject jsonObjects1 = JObject.Parse(response1);
  10014. string ms1g = (string)jsonObjects1["msg"];
  10015. if (ms1g == "报价成功")
  10016. {
  10017. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10018. string data = (string)jsonObject1["price"];
  10019. 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 + "');";
  10020. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10021. returnSuccessMsg("获取报价成功:" + data);
  10022. price = Convert.ToDouble(data);
  10023. }
  10024. else
  10025. {
  10026. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10027. return;
  10028. }
  10029. }
  10030. String[] beizhu = entity.seller_memo.Split('-');
  10031. String chanp = "";
  10032. if (beizhu.Length > 0)
  10033. {
  10034. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10035. }
  10036. else
  10037. {
  10038. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10039. }
  10040. JObject jsonObject = new JObject
  10041. {
  10042. { "UserId", "77886" },
  10043. { "Pwd", "lt666888" },
  10044. { "Filename", chanp }
  10045. };
  10046. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10047. JObject jsonObjects = JObject.Parse(response);
  10048. string msg = (string)jsonObjects["msg"];
  10049. if (msg == "报价成功")
  10050. {
  10051. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10052. string data = (string)jsonObject1["price"];
  10053. 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 + "');";
  10054. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10055. returnSuccessMsg("获取报价成功:" + data);
  10056. price = Convert.ToDouble(data);
  10057. }
  10058. else
  10059. {
  10060. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10061. return;
  10062. }
  10063. if (price > 0)
  10064. {
  10065. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10066. if (ceErpTradeCellExtend == null)
  10067. {
  10068. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10069. ceErpTradeCellExtend.ctid = entity.ctid;
  10070. ceErpTradeCellExtend.payment_cyt = price;
  10071. ceErpTradeCellExtend.Create();
  10072. }
  10073. else
  10074. {
  10075. ceErpTradeCellExtend.payment_cyt = price;
  10076. ceErpTradeCellExtend.Update();
  10077. }
  10078. }
  10079. return;
  10080. }
  10081. }
  10082. else
  10083. {
  10084. returnErrorMsg("请至少选择一条数据");
  10085. return;
  10086. }
  10087. }
  10088. //新增
  10089. public void order_To_Supplier()
  10090. {
  10091. string ceid = GetPostString("tid");
  10092. String[] tid = ceid.Split(',');
  10093. if (tid.Length > 0)
  10094. {
  10095. try
  10096. {
  10097. for (int i = 0; i < tid.Length; i++)
  10098. {
  10099. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10100. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10101. entity.SupplierId = suid;
  10102. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10103. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10104. entity.Update();
  10105. }
  10106. }
  10107. catch (Exception ex)
  10108. {
  10109. returnErrorMsg("自动匹配供应商失败");
  10110. return;
  10111. }
  10112. }
  10113. else
  10114. {
  10115. returnErrorMsg("请至少选择一条数据");
  10116. return;
  10117. }
  10118. returnSuccessMsg("自动匹配供应商成功");
  10119. return;
  10120. }
  10121. public (string, string) UploadFiles(string[] urls)
  10122. {
  10123. string success = "";
  10124. string errors = "";
  10125. int userid = CurrentUser.UserID;
  10126. foreach (string url in urls)
  10127. {
  10128. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10129. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10130. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10131. {
  10132. JObject jsonObject = new JObject
  10133. {
  10134. { "Userid", "77886" },
  10135. { "pwd", "cyt86435015" },
  10136. { "content", base64FileContent },
  10137. { "ext", Path.GetExtension(fileName) }
  10138. };
  10139. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10140. JObject jsonObjects = JObject.Parse(response);
  10141. string msg = (string)jsonObjects["msg"];
  10142. if (msg.Equals("上传成功"))
  10143. {
  10144. success += url + " 上传成功";
  10145. }
  10146. else
  10147. {
  10148. errors += url + " 上传失败";
  10149. }
  10150. }
  10151. else
  10152. {
  10153. errors += url + " 格式出现问题";
  10154. }
  10155. }
  10156. if (urls.Length == 0)
  10157. {
  10158. return (success, errors);
  10159. }
  10160. return (success, errors);
  10161. }
  10162. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10163. {
  10164. return true; //总是接受
  10165. }
  10166. public static string HttpPost(string url, string param = null)
  10167. {
  10168. HttpWebRequest request;
  10169. //如果是发送HTTPS请求
  10170. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10171. {
  10172. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10173. request = WebRequest.Create(url) as HttpWebRequest;
  10174. request.ProtocolVersion = HttpVersion.Version10;
  10175. }
  10176. else
  10177. {
  10178. request = WebRequest.Create(url) as HttpWebRequest;
  10179. }
  10180. request.Method = "POST";
  10181. request.ContentType = "application/json";
  10182. request.Accept = "*/*";
  10183. request.Timeout = 120000;
  10184. request.AllowAutoRedirect = false;
  10185. StreamWriter requestStream = null;
  10186. WebResponse response = null;
  10187. string responseStr = null;
  10188. try
  10189. {
  10190. requestStream = new StreamWriter(request.GetRequestStream());
  10191. requestStream.Write(param);
  10192. requestStream.Close();
  10193. response = request.GetResponse();
  10194. if (response != null)
  10195. {
  10196. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10197. responseStr = reader.ReadToEnd();
  10198. reader.Close();
  10199. }
  10200. }
  10201. catch (Exception ex)
  10202. {
  10203. return ex.Message;
  10204. }
  10205. finally
  10206. {
  10207. request = null;
  10208. requestStream = null;
  10209. response = null;
  10210. }
  10211. return responseStr;
  10212. }
  10213. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10214. {
  10215. string base64FileContent;
  10216. string fileName;
  10217. using (WebClient webClient = new WebClient())
  10218. {
  10219. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10220. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10221. {
  10222. using (Stream stream = response.GetResponseStream())
  10223. {
  10224. using (MemoryStream memoryStream = new MemoryStream())
  10225. {
  10226. stream.CopyTo(memoryStream);
  10227. byte[] fileBytes = memoryStream.ToArray();
  10228. base64FileContent = Convert.ToBase64String(fileBytes);
  10229. fileName = response.Headers["Content-Disposition"];
  10230. if (!string.IsNullOrEmpty(fileName))
  10231. {
  10232. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10233. if (index >= 0)
  10234. {
  10235. fileName = fileName.Substring(index + 9).Trim('\"');
  10236. }
  10237. }
  10238. else
  10239. {
  10240. fileName = Path.GetFileName(downloadUrl);
  10241. }
  10242. }
  10243. }
  10244. }
  10245. }
  10246. return (fileName, base64FileContent);
  10247. }
  10248. //新增
  10249. public void order_batch_caiyingtong(string[] downloadUrls)
  10250. {
  10251. try
  10252. {
  10253. //遍历文件
  10254. DataStruct dStruct = GetPostStruct();
  10255. DataTable dt = null;
  10256. int userid = CurrentUser.UserID;
  10257. List<string> ids = new List<string>();//失败组
  10258. List<string> tids = new List<string>();
  10259. using (WebClient webClient = new WebClient())
  10260. {
  10261. foreach (var url in downloadUrls)
  10262. {
  10263. try
  10264. {
  10265. tids.Add("'" + url + "'");
  10266. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10267. if (entity != null)
  10268. {
  10269. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10270. if (cp == null)
  10271. {
  10272. JObject jsonObject = new JObject
  10273. {
  10274. { "Userid", "77886" },
  10275. { "pwd", "lt666888" },
  10276. { "Filename",entity.seller_memo }
  10277. };
  10278. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10279. JObject jsonObjects = JObject.Parse(response);
  10280. string msg = (string)jsonObjects["msg"];
  10281. if (msg == "报价成功")
  10282. {
  10283. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10284. DownloadAndConvertToBase64(url1);
  10285. }
  10286. else
  10287. {
  10288. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10289. }
  10290. }
  10291. else
  10292. {
  10293. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10294. JObject jsonObject = new JObject
  10295. {
  10296. { "Userid", "77886" },
  10297. { "pwd", "lt666888" },
  10298. { "Filename",chanp }
  10299. };
  10300. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10301. JObject jsonObjects = JObject.Parse(response);
  10302. string msg = (string)jsonObjects["msg"];
  10303. if (msg == "报价成功")
  10304. {
  10305. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10306. DownloadAndConvertToBase64(url1);
  10307. }
  10308. else
  10309. {
  10310. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10311. }
  10312. }
  10313. }
  10314. // 上传文件到FTP
  10315. }
  10316. catch (Exception ex)
  10317. {
  10318. Console.WriteLine($"An error occurred: {ex.Message}");
  10319. }
  10320. }
  10321. List<string> lw = new List<string>();
  10322. lw.Add(string.Format("( OrderState < 6 )"));
  10323. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10324. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10325. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10326. if (dt.Rows.Count > 0)
  10327. {
  10328. foreach (DataRow dr in dt.Rows)
  10329. {
  10330. ids.Add(dr["ctid"].ToString());
  10331. }
  10332. }
  10333. String ErrorMsgs = "";
  10334. foreach (String id in ids)
  10335. {
  10336. ErrorMsgs += id + ",";
  10337. }
  10338. if (ErrorMsgs.Length > 1)
  10339. {
  10340. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10341. }
  10342. if (ErrorMsgs.Length < 1)
  10343. {
  10344. ErrorMsgs = "上传成功";
  10345. returnSuccessMsg(ErrorMsgs);
  10346. }
  10347. else
  10348. {
  10349. returnErrorMsg("以下订单" + ErrorMsgs);
  10350. }
  10351. }
  10352. // 删除文件夹及其内容
  10353. /* Directory.Delete(localDirectory, true);*/
  10354. }
  10355. catch { }
  10356. }
  10357. public void get_center_data()
  10358. {
  10359. int userId = CurrentUser.UserID;
  10360. string postCode = CurrentUser.UserPost.Post.Code;
  10361. List<string> lw = new List<string>();
  10362. List<string> ww = new List<string>();
  10363. DateTime currentTime = DateTime.Now;
  10364. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10365. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10366. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10367. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10368. string sql = " SELECT ";
  10369. string startTime = "2023-10-01 11:22:31";
  10370. //设计
  10371. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10372. {
  10373. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10374. 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));
  10375. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10376. 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));
  10377. }
  10378. //客服
  10379. else if (postCode == "CustomerService" || postCode == "Director")
  10380. {
  10381. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10382. 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));
  10383. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10384. 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));
  10385. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10386. 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));
  10387. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10388. 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));
  10389. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10390. 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));
  10391. }
  10392. //售后
  10393. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10394. {
  10395. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10396. 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));
  10397. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10398. 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));
  10399. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10400. 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));
  10401. }
  10402. //下单部
  10403. else if (postCode == "Place" || postCode == "PlaceMr")
  10404. {
  10405. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10406. 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));
  10407. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10408. 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));
  10409. }
  10410. //车间
  10411. else if (postCode == "Supplier")
  10412. {
  10413. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10414. 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));
  10415. }
  10416. DataTable dt = new DataTable();
  10417. if (lw.Count > 0)
  10418. {
  10419. sql += string.Join(" , ", lw);
  10420. sql += " FROM ";
  10421. sql += string.Join(" , ", ww);
  10422. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10423. }
  10424. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10425. }
  10426. public void get_center_data_list()
  10427. {
  10428. int userId = CurrentUser.UserID;
  10429. string postCode = CurrentUser.UserPost.Post.Code;
  10430. string shopIds = CurrentUser.User.pemShop;
  10431. DataStruct dStruct = GetPostStruct();
  10432. List<string> lw = new List<string>();
  10433. DateTime currentTime = DateTime.Now;
  10434. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10435. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10436. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10437. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10438. string startTime = "2023-10-01 11:22:31";
  10439. int order_type = GetPostInt("order_type");
  10440. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10441. {
  10442. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10443. if (order_type == 0)
  10444. {
  10445. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10446. }
  10447. else if (order_type == 3)
  10448. {
  10449. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10450. }
  10451. else
  10452. {
  10453. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10454. }
  10455. }
  10456. //客服
  10457. if (postCode == "CustomerService" || postCode == "Director")
  10458. {
  10459. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10460. if (order_type == 0)
  10461. {
  10462. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10463. }
  10464. else if (order_type == 1)
  10465. {
  10466. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10467. }
  10468. else if (order_type == 2)
  10469. {
  10470. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10471. }
  10472. else if (order_type == 3)
  10473. {
  10474. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10475. }
  10476. else if (order_type == 4)
  10477. {
  10478. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10479. }
  10480. else
  10481. {
  10482. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10483. }
  10484. }
  10485. //售后
  10486. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10487. {
  10488. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10489. if (shopIds != "")
  10490. {
  10491. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10492. }
  10493. if (order_type == 2)
  10494. {
  10495. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10496. }
  10497. else if (order_type == 4)
  10498. {
  10499. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10500. }
  10501. else if (order_type == 5)
  10502. {
  10503. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10504. }
  10505. else
  10506. {
  10507. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10508. }
  10509. }
  10510. //下单部
  10511. if (postCode == "Place" || postCode == "PlaceMr")
  10512. {
  10513. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10514. if (shopIds != "")
  10515. {
  10516. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10517. }
  10518. else if (order_type == 1)
  10519. {
  10520. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10521. }
  10522. else if (order_type == 2)
  10523. {
  10524. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10525. }
  10526. else
  10527. {
  10528. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10529. }
  10530. }
  10531. //车间
  10532. if (postCode == "Supplier")
  10533. {
  10534. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10535. if (order_type == 5)
  10536. {
  10537. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10538. }
  10539. else
  10540. {
  10541. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10542. }
  10543. }
  10544. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10545. dStruct.Fileds = "tid,ctid";
  10546. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10547. writeGridDataTableJson(dStruct.TotalCount, dt);
  10548. }
  10549. public void aftersale_audit_master()
  10550. {
  10551. if (UrlPostParmsCheck("ctid"))
  10552. {
  10553. string ctid = GetPostString("ctid");
  10554. if (ctid.Length > 0)
  10555. {
  10556. bool result = aftersale_data_change(ctid);
  10557. if (result)
  10558. {
  10559. returnSuccessMsg("修改成功!");
  10560. return;
  10561. }
  10562. }
  10563. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10564. }
  10565. }
  10566. public void aftersale_batch_audit_master()
  10567. {
  10568. if (UrlPostParmsCheck("ctids"))
  10569. {
  10570. string ctids = GetPostString("ctids");
  10571. if (ctids.Length > 0)
  10572. {
  10573. List<string> list = new List<string>();
  10574. string[] ctid_list = ctids.Split(',');
  10575. foreach (var item in ctid_list)
  10576. {
  10577. bool result = aftersale_data_change(item);
  10578. if (!result)
  10579. {
  10580. list.Add(item);
  10581. }
  10582. }
  10583. if (list.Count > 0)
  10584. {
  10585. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10586. return;
  10587. }
  10588. returnSuccessMsg("修改成功!");
  10589. return;
  10590. }
  10591. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10592. }
  10593. }
  10594. public bool aftersale_data_change(string ctid)
  10595. {
  10596. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10597. if (ceErpTradeCell != null)
  10598. {
  10599. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10600. ceErpTradeCell.AfterSaleSupplierState = 0;
  10601. StringBuilder sql = new StringBuilder();
  10602. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10603. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10604. CeErpTradeResponsible.DelByTid(ctid, 0);
  10605. 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 == "不理赔")
  10606. {
  10607. CeErpTradeResponsible.DelByTid(ctid, 1);
  10608. ceErpTradeCell.AfterSaleSupplierState = 1;
  10609. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10610. ceErpTradeCell.AfterSaleState = 4;
  10611. }
  10612. else
  10613. {
  10614. ceErpTradeCell.AfterSaleState = 3;
  10615. }
  10616. bool needCyt = false;
  10617. if (dt != null)
  10618. {
  10619. if (dt.Rows.Count == 1)
  10620. {
  10621. bool isEnd = false;
  10622. foreach (DataRow dr in dt.Rows)
  10623. {
  10624. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10625. {
  10626. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10627. isEnd = true;
  10628. }
  10629. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10630. {
  10631. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10632. isEnd = true;
  10633. }
  10634. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10635. {
  10636. needCyt = true;
  10637. }
  10638. }
  10639. if (isEnd)
  10640. {
  10641. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10642. ceErpTradeCell.AfterSaleState = 4;
  10643. ceErpTradeCell.AfterSaleSupplierState = 1;
  10644. }
  10645. }
  10646. else
  10647. {
  10648. bool isAll = true;
  10649. foreach (DataRow dr in dt.Rows)
  10650. {
  10651. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10652. {
  10653. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10654. continue;
  10655. }
  10656. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10657. {
  10658. string path = "";
  10659. int OrgID = 0;
  10660. if (!Convert.IsDBNull(dr["OrgPath"]))
  10661. {
  10662. path = dr["OrgPath"].ToString();
  10663. }
  10664. if (!Convert.IsDBNull(dr["OrgID"]))
  10665. {
  10666. OrgID = Convert.ToInt32(dr["OrgID"]);
  10667. }
  10668. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10669. {
  10670. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10671. continue;
  10672. }
  10673. }
  10674. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10675. {
  10676. needCyt = true;
  10677. }
  10678. isAll = false;
  10679. }
  10680. if (isAll)
  10681. {
  10682. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10683. ceErpTradeCell.AfterSaleState = 4;
  10684. ceErpTradeCell.AfterSaleSupplierState = 1;
  10685. }
  10686. }
  10687. }
  10688. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10689. {
  10690. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10691. }
  10692. if (ceErpTradeCell.AfterSaleState == 4)
  10693. {
  10694. ApiVo apiVo = new ApiVo();
  10695. apiVo.orderNumber = ceErpTradeCell.ctid;
  10696. apiVo.actionName = "afterOver";
  10697. designHelper.API_WorkCore(apiVo); //afterOver
  10698. }
  10699. ceErpTradeCell.Update();
  10700. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10701. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10702. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10703. return true;
  10704. }
  10705. return false;
  10706. }
  10707. public void get_erp_wechatorder()
  10708. {
  10709. DataStruct dStruct = GetPostStruct();
  10710. List<string> lw = new List<string>();
  10711. string tid = GetPostString("tid");
  10712. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10713. string shopname = GetPostString("shopname");
  10714. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10715. string buyernick = GetPostString("buyer_nick");
  10716. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10717. string customer = GetPostString("customer");
  10718. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10719. string returndate1 = GetPostString("returndate1");
  10720. string returndate2 = GetPostString("returndate2");
  10721. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10722. if (dw.Length > 0) lw.Add(dw);
  10723. string finishDate1 = GetPostString("finishdate1");
  10724. string finishDate2 = GetPostString("finishdate2");
  10725. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10726. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10727. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10728. dStruct.Order = "created desc";
  10729. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10730. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10731. writeGridDataTableJson(dStruct.TotalCount, dt);
  10732. }
  10733. public void get_erp_wechatlist_sumprice()
  10734. {
  10735. DataStruct dStruct = GetPostStruct();
  10736. List<string> lw = new List<string>();
  10737. string tid = GetPostString("tid");
  10738. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10739. string shopname = GetPostString("shopname");
  10740. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10741. string buyernick = GetPostString("buyer_nick");
  10742. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10743. string customer = GetPostString("customer");
  10744. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10745. string returndate1 = GetPostString("returndate1");
  10746. string returndate2 = GetPostString("returndate2");
  10747. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10748. if (dw.Length > 0) lw.Add(dw);
  10749. string finishDate1 = GetPostString("finishdate1");
  10750. string finishDate2 = GetPostString("finishdate2");
  10751. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10752. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10753. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10754. string mainWhere = string.Join(" and ", lw.ToArray());
  10755. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10756. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10757. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10758. decimal total = 0;
  10759. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10760. {
  10761. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10762. }
  10763. var res = new
  10764. {
  10765. data = total
  10766. };
  10767. string ro_jsond = JsonConvert.SerializeObject(res);
  10768. returnSuccess(ro_jsond);
  10769. return;
  10770. }
  10771. public void get_erp_qr_waitdeliverylist()
  10772. {
  10773. DataStruct dStruct = GetPostStruct();
  10774. List<string> lw = new List<string>();
  10775. string tid = GetPostString("ctid");
  10776. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10777. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10778. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10779. var res_objz = new
  10780. {
  10781. restype = 1,
  10782. data = dt
  10783. };
  10784. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10785. returnSuccess(ro_jsonz);
  10786. }
  10787. public void get_erp_yield_list()
  10788. {
  10789. DataStruct dStruct = GetPostStruct();
  10790. List<string> lw = new List<string>();
  10791. string tid = GetPostString("ctid");
  10792. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10793. string shopname = GetPostString("shopname");
  10794. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10795. string buyernick = GetPostString("buyer_nick");
  10796. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10797. //if (tid.Length == 0 && buyernick.Length == 0)
  10798. //{
  10799. // lw.Add(string.Format("IsRefund<={0}", 1));
  10800. //}
  10801. string customer = GetPostString("customer");
  10802. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10803. string design = GetPostString("design");
  10804. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10805. string orderState = GetPostString("orderState");
  10806. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10807. string address = GetPostString("address");
  10808. 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));
  10809. string sellermemo = GetPostString("seller_memo");
  10810. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10811. string supplier = GetPostString("supplier");
  10812. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10813. string OrderArea = GetPostString("order_area");
  10814. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10815. string placedate1 = GetPostString("placedate1");
  10816. string placedate2 = GetPostString("placedate2");
  10817. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10818. if (fdw.Length > 0) lw.Add(fdw);
  10819. string price1 = GetPostString("price1");
  10820. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10821. string price2 = GetPostString("price2");
  10822. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10823. string unusualCon = GetPostString("unusualcon");
  10824. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10825. string posTag = CurrentUser.UserPost.Post.Code;
  10826. if (posTag == "Supplier")
  10827. {
  10828. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10829. }
  10830. lw.Add(string.Format("OrderState = 6 "));
  10831. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10832. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10833. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10834. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10835. writeGridDataTableJson(dStruct.TotalCount, dt);
  10836. }
  10837. public void change_erp_sup_state()
  10838. {
  10839. if (UrlPostParmsCheck("ctid"))
  10840. {
  10841. string ctid = GetPostString("ctid");
  10842. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10843. if (ceErpTradeCell != null)
  10844. {
  10845. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10846. if (ceErpTradeCellExtend == null)
  10847. {
  10848. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10849. ceErpTradeCellExtend.ctid = ctid;
  10850. ceErpTradeCellExtend.SupState = 1;
  10851. ceErpTradeCellExtend.Create();
  10852. }
  10853. else
  10854. {
  10855. ceErpTradeCellExtend.SupState = 1;
  10856. ceErpTradeCellExtend.Update();
  10857. }
  10858. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10859. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10860. return;
  10861. }
  10862. returnErrorMsg("找不到订单");
  10863. }
  10864. }
  10865. public void supplier_all_downs()
  10866. {
  10867. if (UrlPostParmsCheck("tids"))
  10868. {
  10869. string tids = GetPostString("tids");
  10870. if (tids != null && tids.Length > 0)
  10871. {
  10872. StringBuilder sql = new StringBuilder();
  10873. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10874. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10875. sql = new StringBuilder();
  10876. 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, "下载设计文件");
  10877. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10878. string[] list = tids.Split(',');
  10879. foreach (string ctid in list)
  10880. {
  10881. CeErpSukuraData.createInfo(ctid, 3);
  10882. }
  10883. designHelper.api_approveDesign(tids); //approveDesign
  10884. returnSuccessMsg("下载成功!");
  10885. return;
  10886. }
  10887. returnErrorMsg("下载订单更新失败");
  10888. }
  10889. }
  10890. public void uploaderFileSuccess()
  10891. {
  10892. if (UrlPostParmsCheck("fileName"))
  10893. {
  10894. string fileName = GetPostString("fileName");
  10895. ApiVo apiVo = new ApiVo();
  10896. apiVo.orderNumber = fileName;
  10897. apiVo.actionName = "finishDesign";
  10898. designHelper.API_WorkCore(apiVo);//finishDesign
  10899. returnSuccessMsg("");
  10900. }
  10901. }
  10902. public void get_sample2_order()
  10903. {
  10904. if (UrlPostParmsCheck("ctid"))
  10905. {
  10906. string ctid = GetPostString("ctid");
  10907. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10908. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10909. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10910. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10911. double total = 0.0;
  10912. double order_price = 0.0;
  10913. if (dt_bu.Rows.Count > 0)
  10914. {
  10915. foreach (DataRow dr in dt_bu.Rows)
  10916. {
  10917. total += Convert.ToDouble(dr["payment"]);
  10918. }
  10919. }
  10920. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  10921. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  10922. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  10923. string tid = ctid.Replace("S_", "");
  10924. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  10925. double paymant = 0.0;
  10926. if (entity != null)
  10927. {
  10928. paymant = entity.payment;
  10929. }
  10930. string return_reason = "";
  10931. if (dt_after != null && dt_after.Rows.Count > 0)
  10932. {
  10933. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  10934. }
  10935. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  10936. }
  10937. }
  10938. public void get_erp_design_status()
  10939. {
  10940. string designName = GetPostString("designName");
  10941. DataStruct dStruct = GetPostStruct();
  10942. if (designName.Length > 0)
  10943. {
  10944. 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";
  10945. sql_user += " and Name like '%" + designName + "%'";
  10946. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  10947. List<string> ids_list = new List<string>();
  10948. if (user_table.Rows.Count > 0)
  10949. {
  10950. foreach (DataRow item in user_table.Rows)
  10951. {
  10952. ids_list.Add(item["id"].ToString());
  10953. string ids_s = item["TeamIds"].ToString();
  10954. if (ids_s.Length > 0)
  10955. {
  10956. ids_list.AddRange(ids_s.Split(','));
  10957. }
  10958. }
  10959. }
  10960. HashSet<string> set = new HashSet<string>(ids_list);
  10961. ids_list = set.ToList();
  10962. if (ids_list.Count > 0)
  10963. {
  10964. 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));
  10965. dStruct.MainWhere = sql;
  10966. DataTable dt = null;
  10967. dt = WebCache.GetData("view_ErpUser", dStruct);
  10968. writeGridDataTableJson(dStruct.TotalCount, dt);
  10969. }
  10970. }
  10971. }
  10972. public void change_erp_order_price()
  10973. {
  10974. string ctid = GetPostString("ctid");
  10975. double price = GetPostDouble("price");
  10976. if (ctid.Length > 0)
  10977. {
  10978. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10979. if (ceErpTradeCellExtend == null)
  10980. {
  10981. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10982. ceErpTradeCellExtend.ctid = ctid;
  10983. ceErpTradeCellExtend.payment_cyt = price;
  10984. ceErpTradeCellExtend.Create();
  10985. }
  10986. else
  10987. {
  10988. ceErpTradeCellExtend.payment_cyt = price;
  10989. ceErpTradeCellExtend.Update();
  10990. }
  10991. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  10992. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  10993. {
  10994. ceErpDataSendOrderInfo.isSync = false;
  10995. ceErpDataSendOrderInfo.Update();
  10996. }
  10997. if (ceErpDataSendOrderInfo == null)
  10998. {
  10999. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11000. ceErpDataSendOrderInfo.isSync = false;
  11001. ceErpDataSendOrderInfo.ctid = ctid;
  11002. ceErpDataSendOrderInfo.Create();
  11003. }
  11004. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11005. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11006. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11007. if (dth != null && dth.Rows.Count > 0)
  11008. {
  11009. dataSendOrderBean dataSendOrderBean = null;
  11010. foreach (DataRow item in dth.Rows)
  11011. {
  11012. try
  11013. {
  11014. dataSendOrderBean = new dataSendOrderBean();
  11015. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11016. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11017. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11018. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11019. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11020. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11021. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11022. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11023. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11024. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11025. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11026. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11027. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11028. if (result != null)
  11029. {
  11030. if ("0".Equals(result.errcode))
  11031. {
  11032. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11033. }
  11034. else
  11035. {
  11036. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11037. }
  11038. }
  11039. }
  11040. catch (Exception ex)
  11041. {
  11042. }
  11043. }
  11044. }
  11045. returnSuccessMsg("修改成功!");
  11046. return;
  11047. }
  11048. returnErrorMsg("找不到订单");
  11049. }
  11050. public void find_he_together()
  11051. {
  11052. string ctid = GetPostString("ctid");
  11053. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11054. List<string> list = new List<string>();
  11055. if (ceErpTradeCell != null)
  11056. {
  11057. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11058. {
  11059. 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);
  11060. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11061. if (table != null && table.Rows.Count > 0)
  11062. {
  11063. foreach (TableRow row in table.Rows)
  11064. {
  11065. }
  11066. }
  11067. }
  11068. }
  11069. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11070. }
  11071. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11072. {
  11073. //chy----19
  11074. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11075. //GD-CYT-----64
  11076. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11077. //ZHX----3
  11078. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11079. //JK----97
  11080. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11081. //ZT----70
  11082. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11083. //LHCY-----98
  11084. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11085. //XD-----90
  11086. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11087. //CYCY-----14
  11088. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11089. };
  11090. //其他改名
  11091. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11092. {
  11093. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11094. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11095. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11096. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11097. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11098. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11099. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11100. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11101. };
  11102. //不统计
  11103. List<int> no_suppliers = new List<int>()
  11104. {
  11105. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11106. };
  11107. //配件单
  11108. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11109. {
  11110. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11111. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11112. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11113. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11114. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11115. {"旗杆",new List<string>(){ "班旗" } },
  11116. {"牙签",new List<string>(){ "不干胶" } }
  11117. };
  11118. public void get_place_order_data()
  11119. {
  11120. string date1 = GetPostString("date1");
  11121. string date2 = GetPostString("date2");
  11122. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11123. DateTime start = DateTime.Parse(starttime);
  11124. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11125. DateTime end = DateTime.Parse(endtime);
  11126. if (date1 != null && date1.Length > 0)
  11127. {
  11128. DateTime dateTime = DateTime.Parse(date1);
  11129. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11130. start = DateTime.Parse(starttime);
  11131. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11132. end = DateTime.Parse(endtime);
  11133. }
  11134. if (date2 != null && date2.Length > 0)
  11135. {
  11136. DateTime dateTime = DateTime.Parse(date2);
  11137. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11138. end = DateTime.Parse(endtime);
  11139. }
  11140. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierName is not null ", starttime, endtime);
  11141. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11142. //不干胶-----1,卡片-----29
  11143. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11144. foreach (DataRow row in data.Rows)
  11145. {
  11146. int productId = Convert.ToInt32(row["ProductId"]);
  11147. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11148. if (no_suppliers.Contains(supplierId))
  11149. {
  11150. continue;
  11151. }
  11152. string seller_memo = row["seller_memo"].ToString();
  11153. bool ispj = false;//是否配件单
  11154. bool isfirst = true;//第一个配
  11155. maps.Keys.ForEach(key =>
  11156. {
  11157. //备注包含配件
  11158. if (seller_memo.Contains(key) && isfirst)
  11159. {
  11160. List<string> list = maps[key];
  11161. ispj = true;
  11162. isfirst = false;
  11163. for (int i = 0; i < list.Count; i++)
  11164. {
  11165. if (seller_memo.Contains(list[i]))
  11166. {
  11167. ispj = false;
  11168. break;
  11169. }
  11170. }
  11171. }
  11172. });
  11173. if (ispj)
  11174. {
  11175. continue;
  11176. }
  11177. seller_memo = seller_memo.Replace("UV", "uv");
  11178. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11179. //吊牌归到卡片
  11180. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11181. seller_memo = seller_memo.Replace("卡套", "卡片");
  11182. seller_memo = seller_memo.Replace("封套", "卡片");
  11183. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11184. seller_memo = seller_memo.Replace("腰封", "卡片");
  11185. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11186. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11187. seller_memo = seller_memo.Replace("横幅", "条幅");
  11188. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11189. string map_key = "";
  11190. string type = "";
  11191. if (supplierMap.ContainsKey(supplierId))
  11192. {
  11193. foreach (var kvp in supplierMap[supplierId])
  11194. {
  11195. if (seller_memo.Contains(kvp.Key))
  11196. {
  11197. map_key = kvp.Value;
  11198. type = kvp.Value;
  11199. break;
  11200. }
  11201. }
  11202. }
  11203. if (map_key == "")
  11204. {
  11205. type = "其他";
  11206. map_key = "其他";
  11207. }
  11208. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11209. {
  11210. map_key = suppliers[supplierId];
  11211. }
  11212. if (supplierId == 70)
  11213. {
  11214. supplierId = 70;
  11215. }
  11216. map_key += "_" + row["SupplierName"].ToString();
  11217. Dictionary<string, int> map = null;
  11218. if (other_map.ContainsKey(map_key))
  11219. {
  11220. other_map.TryGetValue(map_key, out map);
  11221. }
  11222. else
  11223. {
  11224. map = new Dictionary<string, int>();
  11225. map.Add("dayDev", 0);//当天出货
  11226. map.Add("dayTotal", 0);//下单总数
  11227. map.Add("payTotal", 0);//500以上
  11228. map.Add("today", 0);//当天出货数量
  11229. map.Add("unusua", 0);//异常数
  11230. other_map.Add(map_key, map);
  11231. other_map.TryGetValue(map_key, out map);
  11232. }
  11233. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11234. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11235. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11236. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11237. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11238. {
  11239. map["dayTotal"]++;
  11240. if (supplierId == 97)
  11241. {
  11242. supplierId = 97;
  11243. }
  11244. }
  11245. if (Convert.ToDecimal(row["payment"]) >= 500)
  11246. {
  11247. map["payTotal"]++;
  11248. }
  11249. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11250. {
  11251. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11252. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11253. {
  11254. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11255. {
  11256. map["today"]++;
  11257. }
  11258. }
  11259. else
  11260. {
  11261. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11262. {
  11263. map["today"]++;
  11264. }
  11265. else
  11266. {
  11267. if (supplierId == 119)
  11268. {
  11269. Debug.WriteLine(row["seller_memo"].ToString());
  11270. }
  11271. }
  11272. }
  11273. }
  11274. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11275. {
  11276. map["unusua"]++;
  11277. }
  11278. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11279. //GD-CYT-----64
  11280. DateTime two = palceTimeStart.AddHours(14);
  11281. DateTime three = palceTimeStart.AddHours(15);
  11282. DateTime four = palceTimeStart.AddHours(16);
  11283. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11284. {
  11285. //下午四点前 500-1000
  11286. string count = row["ProductCount"].ToString();
  11287. if (count != null && count.Length > 0)
  11288. {
  11289. int productCount = commonHelper.getPlaceProductCount(count);
  11290. if (productCount >= 500 && productCount <= 1000)
  11291. {
  11292. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11293. {
  11294. map["dayDev"]++;
  11295. }
  11296. }
  11297. }
  11298. }
  11299. //UV
  11300. else if ("uv".Equals(type))
  11301. {
  11302. //ZT----70
  11303. //ZHX----3
  11304. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11305. {
  11306. map["dayDev"]++;
  11307. }
  11308. //JK----97
  11309. //HZX----105
  11310. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11311. {
  11312. map["dayDev"]++;
  11313. if (supplierId == 97)
  11314. {
  11315. supplierId = 97;
  11316. }
  11317. }
  11318. }
  11319. //帆布---52|条幅---27
  11320. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11321. {
  11322. //LHCY-----98
  11323. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11324. {
  11325. map["dayDev"]++;
  11326. }
  11327. }
  11328. //条幅
  11329. else if ("条幅".Equals(type))
  11330. {
  11331. //XD-----90
  11332. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11333. {
  11334. map["dayDev"]++;
  11335. }
  11336. }
  11337. //桌布
  11338. else if ("桌布".Equals(type))
  11339. {
  11340. //XD-----90
  11341. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11342. {
  11343. map["dayDev"]++;
  11344. }
  11345. }
  11346. //DL---10
  11347. //AYTW---119
  11348. //FS-CYT-DY ----80
  11349. //JK----97
  11350. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11351. {
  11352. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11353. {
  11354. map["dayDev"]++;
  11355. }
  11356. }
  11357. }
  11358. DataTable dt = new DataTable();
  11359. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11360. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11361. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11362. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11363. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11364. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11365. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11366. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11367. other_map.Keys.ForEach(key =>
  11368. {
  11369. DataRow dr = dt.NewRow();
  11370. Dictionary<string, int> map = other_map[key];
  11371. string[] key_list = key.Split('_');
  11372. dr[0] = key_list[0];
  11373. dr[1] = key_list[1];
  11374. if (key_list.Length > 2)
  11375. {
  11376. dr[1] += "(" + key_list[2] + ")";
  11377. }
  11378. dr[2] = map["dayTotal"];
  11379. dr[3] = map["payTotal"];
  11380. dr[4] = map["today"];
  11381. dr[5] = map["unusua"];
  11382. dr[6] = map["dayDev"];
  11383. double rate = 0.00;
  11384. if (map["dayDev"] > 0)
  11385. {
  11386. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11387. }
  11388. dr[7] = rate.ToString();
  11389. dt.Rows.Add(dr);
  11390. });
  11391. DataView dv = new DataView(dt);
  11392. dv.Sort = "SupplierName";
  11393. //dv.Sort = "AllOrder desc";
  11394. DataTable dtNew = dv.ToTable();
  11395. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11396. }
  11397. public void check_order_desing_info()
  11398. {
  11399. string ctid = GetPostString("ctid");
  11400. if (!string.IsNullOrEmpty(ctid))
  11401. {
  11402. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11403. if (ceErpTradeCell != null)
  11404. {
  11405. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11406. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11407. return;
  11408. }
  11409. returnErrorMsg("找不到订单");
  11410. return;
  11411. }
  11412. returnErrorMsg("找不到订单");
  11413. }
  11414. public void get_timeout_detail()
  11415. {
  11416. string poscode = CurrentUser.UserPost.Post.Code;
  11417. DataStruct dStruct = GetPostStruct();
  11418. List<string> lw = new List<string>();
  11419. string id = GetPostString("id");
  11420. string pay_date1 = GetPostString("pay_date1");
  11421. string pay_date2 = GetPostString("pay_date2");
  11422. int type = GetPostInt("type");
  11423. if (type == 0)
  11424. {
  11425. if (pay_date1.Length > 0)
  11426. {
  11427. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11428. }
  11429. if (pay_date2.Length > 0)
  11430. {
  11431. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11432. }
  11433. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11434. }
  11435. if (type == 1)
  11436. {
  11437. if (pay_date1.Length > 0)
  11438. {
  11439. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11440. }
  11441. if (pay_date2.Length > 0)
  11442. {
  11443. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11444. }
  11445. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11446. }
  11447. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11448. DataTable dt = null;
  11449. dt = WebCache.GetData("view_orderlist", dStruct);
  11450. writeGridDataTableJson(dStruct.TotalCount, dt);
  11451. }
  11452. public void saveUrgentChargePrice()
  11453. {
  11454. string ctid = GetPostString("ctid");
  11455. if (!string.IsNullOrEmpty(ctid))
  11456. {
  11457. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11458. if (ceErpTradeCell != null)
  11459. {
  11460. double price = GetPostDouble("price");
  11461. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11462. if (ceErpTradeCellExtend == null)
  11463. {
  11464. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11465. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11466. }
  11467. ceErpTradeCellExtend.urgentCharge = price;
  11468. if (ceErpTradeCellExtend.ID > 0)
  11469. {
  11470. ceErpTradeCellExtend.Update();
  11471. }
  11472. else
  11473. {
  11474. ceErpTradeCellExtend.Save();
  11475. }
  11476. returnSuccessMsg("修改成功!");
  11477. return;
  11478. }
  11479. returnErrorMsg("找不到订单");
  11480. return;
  11481. }
  11482. returnErrorMsg("找不到订单");
  11483. }
  11484. public void finish_erp_order()
  11485. {
  11486. string ctid = GetPostString("ctid");
  11487. if (!string.IsNullOrEmpty(ctid))
  11488. {
  11489. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11490. {
  11491. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11492. if (ceErpTradeCell != null)
  11493. {
  11494. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11495. ceErpTradeCell.Update();
  11496. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11497. returnSuccessMsg("修改成功!");
  11498. return;
  11499. }
  11500. }
  11501. }
  11502. returnErrorMsg("找不到订单");
  11503. }
  11504. public void get_trade_order_list()
  11505. {
  11506. string tid = GetPostString("tid");
  11507. if (!string.IsNullOrEmpty(tid))
  11508. {
  11509. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11510. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11511. writeGridDataTableJson(data.Rows.Count, data);
  11512. return;
  11513. }
  11514. returnErrorMsg("找不到订单");
  11515. }
  11516. public void save_cell_spu()
  11517. {
  11518. string ctid = GetPostString("ctid");
  11519. string spu_id = GetPostString("spu_id");
  11520. if (!string.IsNullOrEmpty(ctid))
  11521. {
  11522. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11523. if (ceErpTradeCellExtend == null)
  11524. {
  11525. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11526. ceErpTradeCellExtend.ctid = ctid;
  11527. }
  11528. ceErpTradeCellExtend.spu_id = spu_id;
  11529. if (!string.IsNullOrEmpty(spu_id))
  11530. {
  11531. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id);
  11532. ceErpTradeCellExtend.ToType = result;
  11533. }
  11534. if (ceErpTradeCellExtend.ID == 0)
  11535. {
  11536. ceErpTradeCellExtend.Create();
  11537. }
  11538. else
  11539. {
  11540. ceErpTradeCellExtend.Update();
  11541. }
  11542. returnSuccessMsg("修改成功!");
  11543. return;
  11544. }
  11545. returnErrorMsg("找不到订单");
  11546. }
  11547. public void change_express_info()
  11548. {
  11549. string ctid = GetPostString("ctid");
  11550. string transNo = GetPostString("transNo");
  11551. string transCom = GetPostString("transCom");
  11552. if (!string.IsNullOrEmpty(ctid))
  11553. {
  11554. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11555. if (ceErpTradeCellExtend == null)
  11556. {
  11557. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11558. ceErpTradeCellExtend.ctid = ctid;
  11559. }
  11560. ceErpTradeCellExtend.modExpressNo = transNo;
  11561. ceErpTradeCellExtend.modExpressCom = transCom;
  11562. ceErpTradeCellExtend.readMod = 2;
  11563. if (ceErpTradeCellExtend.ID == 0)
  11564. {
  11565. ceErpTradeCellExtend.Create();
  11566. }
  11567. else
  11568. {
  11569. ceErpTradeCellExtend.Update();
  11570. }
  11571. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11572. returnSuccessMsg("修改成功!");
  11573. return;
  11574. }
  11575. returnErrorMsg("找不到订单");
  11576. }
  11577. public void get_change_express_list()
  11578. {
  11579. DataStruct dStruct = GetPostStruct();
  11580. List<string> lw = new List<string>();
  11581. int st = 2;
  11582. string tid = GetPostString("ctid");
  11583. if (tid.Length > 0)
  11584. {
  11585. string select_tid = getTidByCtid(tid);
  11586. lw.Add(string.Format("tid='{0}'", select_tid));
  11587. }
  11588. string shopname = GetPostString("shopname");
  11589. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11590. string buyernick = GetPostString("buyer_nick");
  11591. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11592. string sellermemo = GetPostString("seller_memo");
  11593. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11594. string supplier = GetPostString("supplier");
  11595. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11596. string customer = GetPostString("customer");
  11597. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11598. string design = GetPostString("design");
  11599. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11600. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11601. string poscode = CurrentUser.UserPost.Post.Code;
  11602. if (poscode != "SysAdmin")
  11603. {
  11604. string shopid = CurrentUser.User.pemShop;
  11605. lw.Add(string.Format("shopId in ({0})", shopid));
  11606. }
  11607. lw.Add("readMod = 2");
  11608. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11609. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11610. writeGridDataTableJson(dStruct.TotalCount, dt);
  11611. }
  11612. public void deal_express_complete()
  11613. {
  11614. string ctid = GetPostString("ctid");
  11615. if (!string.IsNullOrEmpty(ctid))
  11616. {
  11617. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11618. if (ceErpTradeCellExtend == null)
  11619. {
  11620. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11621. ceErpTradeCellExtend.ctid = ctid;
  11622. }
  11623. ceErpTradeCellExtend.readMod = 1;
  11624. if (ceErpTradeCellExtend.ID == 0)
  11625. {
  11626. ceErpTradeCellExtend.Create();
  11627. }
  11628. else
  11629. {
  11630. ceErpTradeCellExtend.Update();
  11631. }
  11632. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11633. returnSuccessMsg("修改成功!");
  11634. return;
  11635. }
  11636. returnErrorMsg("找不到订单");
  11637. }
  11638. public void aftersale_return_visit()
  11639. {
  11640. string ctid = GetPostString("ctid");
  11641. if (!string.IsNullOrEmpty(ctid))
  11642. {
  11643. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11644. if (ceErpTradeCellExtend == null)
  11645. {
  11646. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11647. ceErpTradeCellExtend.ctid = ctid;
  11648. }
  11649. ceErpTradeCellExtend.returnVisit = 1;
  11650. if (ceErpTradeCellExtend.ID == 0)
  11651. {
  11652. ceErpTradeCellExtend.Create();
  11653. }
  11654. else
  11655. {
  11656. ceErpTradeCellExtend.Update();
  11657. }
  11658. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11659. if (ceErpTradeAfterSaleExtend != null)
  11660. {
  11661. ceErpTradeAfterSaleExtend.TextResult = "";
  11662. ceErpTradeAfterSaleExtend.Update();
  11663. }
  11664. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11665. returnSuccessMsg("修改成功!");
  11666. return;
  11667. }
  11668. returnErrorMsg("找不到订单");
  11669. }
  11670. public void orderPlaceInfo()
  11671. {
  11672. string ctids = GetPostString("ctids");
  11673. string[] list = ctids.Split(',');
  11674. foreach (string ctid in list)
  11675. {
  11676. CeErpSukuraData.createInfo(ctid, 3);
  11677. }
  11678. StringBuilder sql = new StringBuilder();
  11679. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11680. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11681. designHelper.api_approveDesign(ctids); //approveDesign
  11682. returnSuccessMsg("");
  11683. }
  11684. public void get_issue_list()
  11685. {
  11686. DataStruct dStruct = GetPostStruct();
  11687. List<string> lw = new List<string>();
  11688. int st = 2;
  11689. string tid = GetPostString("ctid");
  11690. if (tid.Length > 0)
  11691. {
  11692. string select_tid = getTidByCtid(tid);
  11693. lw.Add(string.Format("tid='{0}'", select_tid));
  11694. }
  11695. string shopname = GetPostString("shopname");
  11696. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11697. string buyernick = GetPostString("buyer_nick");
  11698. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11699. string sellermemo = GetPostString("seller_memo");
  11700. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11701. string supplier = GetPostString("supplier");
  11702. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11703. string customer = GetPostString("customer");
  11704. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11705. string design = GetPostString("design");
  11706. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11707. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11708. string poscode = CurrentUser.UserPost.Post.Code;
  11709. if (poscode != "SysAdmin")
  11710. {
  11711. string shopid = CurrentUser.User.pemShop;
  11712. lw.Add(string.Format("shopId in ({0})", shopid));
  11713. }
  11714. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11715. {
  11716. lw.Add("IssueState = 1");
  11717. }
  11718. lw.Add("IssueState > 0");
  11719. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11720. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11721. writeGridDataTableJson(dStruct.TotalCount, dt);
  11722. }
  11723. public void saveIssueContent()
  11724. {
  11725. string ctid = GetPostString("ctid");
  11726. if (!string.IsNullOrEmpty(ctid))
  11727. {
  11728. string content = GetPostString("content");
  11729. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11730. if (ceErpTradeAfterSaleExtend == null)
  11731. {
  11732. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11733. ceErpTradeAfterSaleExtend.tid = ctid;
  11734. }
  11735. ceErpTradeAfterSaleExtend.IssueContent = content;
  11736. ceErpTradeAfterSaleExtend.IssueState = 1;
  11737. if (ceErpTradeAfterSaleExtend.ID > 0)
  11738. {
  11739. ceErpTradeAfterSaleExtend.Update();
  11740. }
  11741. else
  11742. {
  11743. ceErpTradeAfterSaleExtend.Create();
  11744. }
  11745. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11746. returnSuccessMsg("添加成功!");
  11747. return;
  11748. }
  11749. returnErrorMsg("找不到订单");
  11750. }
  11751. public void dealIssueContent()
  11752. {
  11753. string ctid = GetPostString("ctid");
  11754. if (!string.IsNullOrEmpty(ctid))
  11755. {
  11756. string content = GetPostString("content");
  11757. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11758. if (ceErpTradeAfterSaleExtend != null)
  11759. {
  11760. ceErpTradeAfterSaleExtend.IssueState = 2;
  11761. ceErpTradeAfterSaleExtend.Update();
  11762. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11763. returnSuccessMsg("修改完成!");
  11764. return;
  11765. }
  11766. }
  11767. returnErrorMsg("找不到订单");
  11768. }
  11769. public void set_tid_attachments()
  11770. {
  11771. string tid = GetPostString("tid");
  11772. string atta = GetPostString("atta");
  11773. if (!string.IsNullOrEmpty(tid))
  11774. {
  11775. if (string.IsNullOrEmpty(atta))
  11776. {
  11777. returnErrorMsg("文件地址为空");
  11778. return;
  11779. }
  11780. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11781. if (ceErpTradeCell != null)
  11782. {
  11783. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11784. if (ceErpTrade == null)
  11785. {
  11786. returnErrorMsg("找不到订单");
  11787. return;
  11788. }
  11789. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11790. bool isSend = false;
  11791. if (dt != null && dt.Rows.Count > 0)
  11792. {
  11793. foreach (DataRow row in dt.Rows)
  11794. {
  11795. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11796. {
  11797. isSend = true;
  11798. }
  11799. }
  11800. if (isSend)
  11801. {
  11802. returnErrorMsg("已发货无法修改");
  11803. return;
  11804. }
  11805. ceErpTrade.Attachments = atta;
  11806. ceErpTrade.Update();
  11807. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11808. returnSuccessMsg("上传成功!");
  11809. return;
  11810. }
  11811. }
  11812. }
  11813. returnErrorMsg("找不到订单");
  11814. }
  11815. public void get_tid_attachments()
  11816. {
  11817. string tid = GetPostString("tid");
  11818. if (!string.IsNullOrEmpty(tid))
  11819. {
  11820. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11821. if (ceErpTradeCell != null)
  11822. {
  11823. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11824. if (ceErpTrade == null)
  11825. {
  11826. returnErrorMsg("找不到订单");
  11827. return;
  11828. }
  11829. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11830. return;
  11831. }
  11832. }
  11833. returnErrorMsg("找不到订单");
  11834. }
  11835. public void check_erp_sameorders()
  11836. {
  11837. if (UrlPostParmsCheck("ctid"))
  11838. {
  11839. string eid = GetPostString("ctid");
  11840. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11841. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11842. if (entity != null && ceErpTrade != null)
  11843. {
  11844. if (entity.OrderState > 6)
  11845. {
  11846. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11847. return;
  11848. }
  11849. StringBuilder sql = new StringBuilder();
  11850. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  11851. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11852. {
  11853. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11854. }
  11855. else
  11856. {
  11857. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11858. }
  11859. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11860. List<string> ids = new List<string>();
  11861. if (dt != null && dt.Rows.Count > 1)
  11862. {
  11863. bool needhe = true;
  11864. foreach (DataRow dr in dt.Rows)
  11865. {
  11866. ids.Add("'" + dr["ctid"] + "'");
  11867. /* //备注有合包
  11868. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11869. {
  11870. needhe = true;
  11871. }
  11872. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11873. {
  11874. needhe = true;
  11875. }
  11876. //顺丰快递
  11877. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11878. {
  11879. needhe = true;
  11880. }*/
  11881. }
  11882. if (!needhe)
  11883. {
  11884. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11885. return;
  11886. }
  11887. sql = new StringBuilder();
  11888. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11889. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11890. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11891. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11892. foreach (DataRow dr in dt.Rows)
  11893. {
  11894. dr["dstate"] = 0;
  11895. dr["dnumber"] = 0;
  11896. foreach (DataRow row in dt1.Rows)
  11897. {
  11898. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  11899. {
  11900. dr["dstate"] = 2;
  11901. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  11902. }
  11903. }
  11904. if (eid.Equals(dr["ctid"].ToString()))
  11905. {
  11906. dr["dstate"] = 1;
  11907. }
  11908. }
  11909. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  11910. return;
  11911. }
  11912. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11913. return;
  11914. }
  11915. returnErrorMsg("未找到订单");
  11916. return;
  11917. }
  11918. returnErrorMsg("缺少必要的参数");
  11919. }
  11920. public void get_mark_number()
  11921. {
  11922. string eid = GetPostString("ctid");
  11923. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11924. if (entity != null)
  11925. {
  11926. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11927. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  11928. int current = 1;
  11929. if (ceErpDeliverMark == null)
  11930. {
  11931. StringBuilder sql = new StringBuilder();
  11932. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  11933. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11934. {
  11935. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11936. }
  11937. else
  11938. {
  11939. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11940. }
  11941. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11942. List<string> ids = new List<string>();
  11943. if (dt != null && dt.Rows.Count > 1)
  11944. {
  11945. foreach (DataRow dr in dt.Rows)
  11946. {
  11947. ids.Add("'" + dr["ctid"] + "'");
  11948. }
  11949. //查询已有的编号
  11950. sql = new StringBuilder();
  11951. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11952. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11953. if (dt1 == null || dt1.Rows.Count == 0)
  11954. {
  11955. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  11956. List<int> list_number = new List<int>();
  11957. foreach (DataRow row in numbers.Rows)
  11958. {
  11959. list_number.Add(Convert.ToInt32(row["markNumber"]));
  11960. }
  11961. //查询空余编号
  11962. for (int i = 0; i < list_number.Count + 2; i++)
  11963. {
  11964. if (!list_number.Contains(current))
  11965. {
  11966. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  11967. //防止查询过程中有新数据生成
  11968. if (ceErpDeliverMark1 == null)
  11969. {
  11970. break;
  11971. }
  11972. }
  11973. current++;
  11974. }
  11975. }
  11976. else
  11977. {
  11978. foreach (DataRow row in dt1.Rows)
  11979. {
  11980. current = Convert.ToInt32(row["markNumber"]);
  11981. }
  11982. }
  11983. ceErpDeliverMark = new CeErpDeliverMark();
  11984. ceErpDeliverMark.ctid = eid;
  11985. ceErpDeliverMark.createtime = DateTime.Now;
  11986. if (ceErpTrade != null)
  11987. {
  11988. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  11989. }
  11990. ceErpDeliverMark.markNumber = current;
  11991. ceErpDeliverMark.Create();
  11992. }
  11993. }
  11994. else
  11995. {
  11996. current = ceErpDeliverMark.markNumber;
  11997. }
  11998. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  11999. return;
  12000. }
  12001. }
  12002. }
  12003. }