sync.order.cs 622 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416
  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 result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  68. List<string> lw = new List<string>();
  69. string tid = GetPostString("ctid");
  70. string date1 = GetPostString("date1");
  71. //12-1 修改
  72. string urgent = GetPostString("urgent");
  73. string back = GetPostString("back");
  74. string offlineSearch = GetPostString("offlineSearch");
  75. int paramsCount = 0;
  76. if (!string.IsNullOrWhiteSpace(urgent))
  77. {
  78. if (urgent.Equals("true"))
  79. {
  80. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  81. }
  82. }
  83. if (!string.IsNullOrWhiteSpace(back))
  84. {
  85. if (back.Equals("true"))
  86. {
  87. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  88. }
  89. }
  90. if (!string.IsNullOrWhiteSpace(offlineSearch))
  91. {
  92. if (offlineSearch.Equals("true"))
  93. {
  94. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  95. }
  96. }
  97. //end
  98. string date2 = GetPostString("date2");
  99. string buyernick = GetPostString("buyer_nick");
  100. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  101. {
  102. if (tid.Length <= 0 && buyernick.Length <= 0)
  103. {
  104. return;
  105. }
  106. }
  107. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  108. {
  109. if (tid.Length > 0)
  110. {
  111. string select_tid = getTidByCtid(tid);
  112. lw.Add(string.Format("tid='{0}'", select_tid));
  113. }
  114. if (buyernick.Length > 0)
  115. {
  116. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  117. }
  118. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  119. if (dw.Length > 0)
  120. {
  121. lw.Add(dw);
  122. }
  123. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  124. {
  125. string usershop = CurrentUser.User.pemShop;
  126. lw.Add(string.Format("ShopId in ({0})", usershop));
  127. }
  128. }
  129. else
  130. {
  131. if (ex_psize == 0)
  132. {
  133. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  134. }
  135. if (PKey != "admin")
  136. {
  137. string usershop = CurrentUser.User.pemShop;
  138. lw.Add(string.Format("ShopId in ({0})", usershop));
  139. paramsCount++;
  140. }
  141. }
  142. string uploaddate1 = GetPostString("uploaddate1");
  143. string uploaddate2 = GetPostString("uploaddate2");
  144. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  145. if (update.Length > 0) lw.Add(update);
  146. string deliverydate1 = GetPostString("deliverydate1");
  147. string deliverydate2 = GetPostString("deliverydate2");
  148. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  149. if (deliverydate.Length > 0)
  150. {
  151. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  152. };
  153. string shopname = GetPostString("shopname");
  154. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  155. string addwechat = GetPostString("addwechat");
  156. if (addwechat.Length > 0)
  157. {
  158. int addWt = Convert.ToInt32(addwechat);
  159. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  160. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  161. }
  162. string customer = GetPostString("customer");
  163. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  164. string design = GetPostString("design");
  165. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  166. string orderState = GetPostString("orderState");
  167. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  168. string address = GetPostString("address");
  169. 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));
  170. string sellermemo = GetPostString("seller_memo");
  171. if (sellermemo.Length > 0)
  172. {
  173. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  174. }
  175. string backReason = GetPostString("backReason");
  176. if (backReason.Length > 0)
  177. {
  178. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  179. }
  180. string apdate1 = GetPostString("apdate1");
  181. string apdate2 = GetPostString("apdate2");
  182. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  183. if (dwap.Length > 0) lw.Add(dwap);
  184. string price1 = GetPostString("price1");
  185. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  186. string price2 = GetPostString("price2");
  187. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  188. string isoldcustomer = GetPostString("isoldcus");
  189. string spudata = GetPostString("spudata");
  190. if ("0".Equals(spudata))
  191. {
  192. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  193. }
  194. if ("1".Equals(spudata))
  195. {
  196. lw.Add(string.Format("spu_id <> ''"));
  197. }
  198. string finishdate1 = GetPostString("finishdate1");
  199. string finishdate2 = GetPostString("finishdate2");
  200. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  201. bool isFinish = false;
  202. if (finishdate.Length > 0)
  203. {
  204. lw.Add(finishdate);
  205. isFinish = true;
  206. paramsCount++;
  207. }
  208. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  209. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  210. if (ex_psize > 0)
  211. {
  212. int UserID = CurrentUser.UserID;
  213. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  214. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  215. {
  216. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  217. }
  218. dStruct.Order = "pay_time desc";
  219. }
  220. string isNew = GetPostString("isNew");
  221. if (isNew == "true")
  222. {
  223. lw.Add(string.Format("IsNew = {0}", 1));
  224. }
  225. string overtime = GetPostString("overtime");
  226. if (overtime == "1")
  227. {
  228. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  229. }
  230. String usePost = CurrentUser.UserPost.Post.Code;
  231. if (usePost.Equals("Operation") == true)
  232. {
  233. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  234. }
  235. else
  236. {
  237. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  238. }
  239. //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";
  240. if (dStruct.PageSize == 100000)
  241. {
  242. dStruct.Order = "";
  243. }
  244. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  245. DataTable dt = null;
  246. string tablename = "view_orderlist";
  247. if (isFinish)
  248. {
  249. tablename = "view_orderlist_end";
  250. }
  251. dt = WebCache.GetData(tablename, dStruct);
  252. if (dt != null && dt.Rows.Count > 0)
  253. {
  254. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  255. foreach (DataRow dr in dt.Rows)
  256. {
  257. try
  258. {
  259. if (dr["refund_fees"] != null)
  260. {
  261. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  262. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  263. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  264. if (payment == refund_fees)
  265. {
  266. dr["refund_fees"] = Math.Round(refund_fees, 2);
  267. }
  268. else if (refund_fees == total_fee)
  269. {
  270. dr["refund_fees"] = payment;
  271. }
  272. else
  273. {
  274. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  275. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  276. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  277. }
  278. }
  279. // 对象操作
  280. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  281. ceErpTradeCell.ctid = dr["ctid"].ToString();
  282. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  283. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  284. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  285. if (dStruct.PageSize != 100000)
  286. {
  287. if (dr["DispatchSort"].ToString() == "2")
  288. {
  289. dr["gongchuang"] = 200;
  290. }
  291. else if ("外协".Equals(dr["ToType"].ToString()))
  292. {
  293. dr["gongchuang"] = 200;
  294. }
  295. else if ("内部".Equals(dr["ToType"].ToString()))
  296. {
  297. dr["gongchuang"] = -1;
  298. }
  299. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  300. {
  301. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  302. dr["gongchuang"] = response.code;
  303. }
  304. }
  305. }
  306. catch (NullReferenceException ex)
  307. {
  308. // 处理空引用异常
  309. dr["refund_fees"] = "0.00";
  310. }
  311. }
  312. }
  313. writeGridDataTableJson(dStruct.TotalCount, dt);
  314. }
  315. public void get_erp_orderlist_sumprice()
  316. {
  317. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  318. return;
  319. List<string> lw = new List<string>();
  320. string tid = GetPostString("ctid");
  321. string date1 = GetPostString("date1");
  322. string date2 = GetPostString("date2");
  323. if (tid.Length > 0 || date1.Length > 0)
  324. {
  325. lw.Add(string.Format("ctid like '%{0}%'", tid));
  326. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  327. if (dw.Length > 0) lw.Add(dw);
  328. }
  329. else
  330. {
  331. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  332. }
  333. string shopname = GetPostString("shopname");
  334. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  335. string buyernick = GetPostString("buyer_nick");
  336. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  337. string customer = GetPostString("customer");
  338. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  339. string design = GetPostString("design");
  340. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  341. string orderState = GetPostString("orderState");
  342. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  343. string address = GetPostString("address");
  344. 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));
  345. string sellermemo = GetPostString("seller_memo");
  346. if (sellermemo.Length > 0)
  347. {
  348. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  349. }
  350. string apdate1 = GetPostString("apdate1");
  351. string apdate2 = GetPostString("apdate2");
  352. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  353. if (dwap.Length > 0) lw.Add(dwap);
  354. string price1 = GetPostString("price1");
  355. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  356. string price2 = GetPostString("price2");
  357. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  358. string isoldcustomer = GetPostString("isoldcus");
  359. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  360. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  361. if (PKey != "admin")
  362. {
  363. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  364. lw.Add(string.Format("shopId in ({0})", usershop));
  365. }
  366. //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";
  367. string mainWhere = string.Join(" and ", lw.ToArray());
  368. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  369. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  370. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  371. decimal total = 0;
  372. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  373. {
  374. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  375. }
  376. var res = new
  377. {
  378. data = total
  379. };
  380. string ro_jsond = JsonConvert.SerializeObject(res);
  381. returnSuccess(ro_jsond);
  382. return;
  383. }
  384. public void get_erp_CustomerServiceGather()
  385. {
  386. string userWhere = "", orderWhere = "";
  387. List<string> lw = new List<string>();
  388. string customer = GetPostString("customer");
  389. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  390. string shopname = GetPostString("shopname");
  391. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  392. string date1 = GetPostString("date1");
  393. string date2 = GetPostString("date2");
  394. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  395. if (dw.Length > 0) lw.Add(dw);
  396. orderWhere = string.Join(" and ", lw.ToArray());
  397. 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 " +
  398. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  399. "left join " +
  400. "( " +
  401. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  402. ") as b on a.ID = b.CustomerUserId " +
  403. "left join " +
  404. "( " +
  405. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  406. ") as d on a.ID = d.CustomerUserId " +
  407. "left join " +
  408. "( " +
  409. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  410. ") as e on a.ID = e.CustomerUserId " +
  411. "left join " +
  412. "( " +
  413. " select CustomerUserId, RefundCount, RefundSum from " +
  414. " ( " +
  415. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  416. " from CE_ErpTradeRefund a " +
  417. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  418. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  419. " group by CustomerUserId " +
  420. " ) as a " +
  421. ") as f on a.ID = f.CustomerUserId " +
  422. "where a.PostCode = 'CustomerService'",
  423. userWhere, orderWhere);
  424. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  425. writeGridDataTableJson(dt.Rows.Count, dt);
  426. //writeGridDataTableJson(dt.Rows.Count, dt);
  427. }
  428. //设计汇总
  429. public void get_erp_DesignerGather()
  430. {
  431. string userWhere = "", orderWhere = "";
  432. List<string> lw = new List<string>();
  433. string Designer = GetPostString("designer");
  434. int org = GetPostInt("org");
  435. if (Designer.Length > 0)
  436. {
  437. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  438. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  439. }
  440. else if (org > 0)
  441. {
  442. userWhere = string.Format(" where OrgID ={0}", org);
  443. }
  444. string shopname = GetPostString("shopname");
  445. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  446. string state = GetPostString("state");
  447. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  448. string OrderArea = GetPostString("order_area");
  449. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  450. string date1 = GetPostString("date1");
  451. string date2 = GetPostString("date2");
  452. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  453. if (dw.Length > 0) lw.Add(dw);
  454. string UpDate1 = GetPostString("UpDate1");
  455. string UpDate2 = GetPostString("UpDate2");
  456. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  457. if (dw.Length > 0) lw.Add(dw);
  458. orderWhere = string.Join(" and ", lw.ToArray());
  459. 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 (" +
  460. "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 " +
  461. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  462. "left join " +
  463. "( " +
  464. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  465. ") as b on a.ID = b.DesignUserId " +
  466. "left join " +
  467. "( " +
  468. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  469. ") as d on a.ID = d.DesignUserId " +
  470. "left join " +
  471. "( " +
  472. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  473. ") as e on a.ID = e.DesignUserId " +
  474. "left join " +
  475. "( " +
  476. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  477. ") as g on a.ID = g.DesignUserId " +
  478. "left join " +
  479. "( " +
  480. " select CustomerUserId, RefundCount, RefundSum from " +
  481. " ( " +
  482. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  483. " from CE_ErpTradeRefund a " +
  484. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  485. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  486. " group by CustomerUserId " +
  487. " ) as a " +
  488. ") as f on a.ID = f.CustomerUserId " +
  489. "where a.PostCode = 'Designer') as z",
  490. userWhere, orderWhere);
  491. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  492. writeGridDataTableJson(dt.Rows.Count, dt);
  493. }
  494. //删除tradecell的订单
  495. public void del_erp_cellorder()
  496. {
  497. if (UrlPostParmsCheck("ctid"))
  498. {
  499. string eid = GetPostString("ctid");
  500. CeErpTradeCell.DelByCtid(eid);
  501. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  502. returnSuccessMsg("删除成功");
  503. }
  504. }
  505. public void clear_erp_refundstate()
  506. {
  507. if (UrlPostParmsCheck("ids"))
  508. {
  509. string eids = GetPostString("ids");
  510. string[] ctidList = eids.Split(',');
  511. foreach (string ctid in ctidList)
  512. {
  513. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  514. if (entity != null)
  515. {
  516. entity.IsRefund = 0;
  517. entity.Update();
  518. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  519. }
  520. else
  521. continue;
  522. }
  523. returnSuccessMsg("操作成功");
  524. return;
  525. }
  526. returnErrorMsg("缺少必要参数");
  527. }
  528. public void set_erp_urgency()
  529. {
  530. if (UrlPostParmsCheck("ctid"))
  531. {
  532. string eid = GetPostString("ctid");
  533. CeErpTradeCell entity = null;
  534. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  535. if (entity != null)
  536. {
  537. string utime = GetPostString("urgencytime");
  538. if (utime.Length > 0)
  539. {
  540. entity.UrgencyTime = Convert.ToDateTime(utime);
  541. }
  542. else
  543. {
  544. returnErrorMsg("请选择加急时间");
  545. return;
  546. }
  547. if (entity.OrderState <= 4)
  548. {
  549. //entity.seller_memo = entity.seller_memo + "-加急";
  550. string smemo = entity.seller_memo;
  551. int kindex = smemo.IndexOf(")");
  552. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  553. if (lastoneStr != "-")
  554. {
  555. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  556. }
  557. string prememo = smemo.Substring(0, kindex + 2);
  558. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  559. int lastkindex = lastmemo.IndexOf("(");
  560. DateTime urgtime = Convert.ToDateTime(utime);
  561. string newlastmemo = "";
  562. if (lastkindex == 0)
  563. {
  564. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  565. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  566. }
  567. else
  568. {
  569. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  570. }
  571. entity.seller_memo = prememo + newlastmemo;
  572. }
  573. entity.IsUrgency = true;
  574. entity.UpdateTime = DateTime.Now;
  575. entity.Update();
  576. ApiVo apiVo = new ApiVo();
  577. apiVo.orderNumber = entity.ctid;
  578. apiVo.actionName = "changeDesign";
  579. apiVo.orderRemarks = entity.seller_memo;
  580. apiVo.remarkSign = 3;
  581. designHelper.API_WorkCore(apiVo); //changeDesign
  582. CeErpSukuraData.createInfo(entity.ctid, 7);
  583. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  584. returnSuccessMsg("设置成功!");
  585. return;
  586. }
  587. returnErrorMsg("找不到记录");
  588. }
  589. }
  590. public void set_erp_reset()
  591. {
  592. if (UrlPostParmsCheck("ctid"))
  593. {
  594. string eid = GetPostString("ctid");
  595. CeErpTradeCell entity = null;
  596. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  597. if (entity != null)
  598. {
  599. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  600. {
  601. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  602. {
  603. returnErrorMsg("财务要求已下单已发货无法重置");
  604. return;
  605. }
  606. }
  607. entity.IsUrgency = false;
  608. entity.seller_memo = "";
  609. entity.OtherMemo = "";
  610. entity.OrderState = 0;
  611. entity.IsReturn = 0;
  612. //entity.IsRefund = 0;
  613. entity.MemoOpt = 0;
  614. entity.AfterSaleState = 0;
  615. entity.AfterSaleResponsible = "";
  616. entity.AfterSaleUserId = 0;
  617. entity.IsNeedBill = 0;
  618. entity.CustomerUserId = 0;
  619. entity.DesignUserId = 0;
  620. entity.SupplierId = 0;
  621. entity.PlaceUserId = 0;
  622. entity.ptid = "";
  623. entity.IsSample = 0;
  624. entity.IsXianHuo = 0;
  625. entity.isDianziOrder = 0;
  626. entity.DispatchSort = 0;
  627. entity.FinishPlaceTime = null;
  628. entity.Update();
  629. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  630. if (trade != null)
  631. {
  632. trade.seller_memo = "";
  633. trade.Update();
  634. }
  635. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  636. returnSuccessMsg("重置成功!");
  637. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  638. if (desginBill != null)
  639. {
  640. desginBill.isDel = 1;
  641. desginBill.Update();
  642. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  643. }
  644. ApiVo apiVo = new ApiVo();
  645. apiVo.orderNumber = entity.ctid;
  646. apiVo.actionName = "resetDesign";
  647. designHelper.API_WorkCore(apiVo);//resetDesign
  648. return;
  649. }
  650. returnErrorMsg("找不到记录");
  651. }
  652. }
  653. public void save_erp_sellermemo()
  654. {
  655. if (UrlPostParmsCheck("ctid"))
  656. {
  657. string ctid = GetPostString("ctid");
  658. CeErpTradeCell entity = null;
  659. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  660. if (entity != null)
  661. {
  662. string memo = GetPostString("seller_memo");
  663. memo = memo.Replace(" ", "");
  664. if (memo.Contains("补差"))
  665. {
  666. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  667. return;
  668. }
  669. List<string> bitList = new List<string>
  670. {
  671. "\\","/",":","*","?", "\"","<" ,">","|"
  672. };
  673. bool isIn = false;
  674. foreach (string bit in bitList)
  675. {
  676. if (memo.Contains(bit))
  677. {
  678. isIn = true;
  679. }
  680. }
  681. if (isIn)
  682. {
  683. returnErrorMsg("不能使用 一些符合作为文件名");
  684. return;
  685. }
  686. if (entity.seller_memo != memo)
  687. {
  688. if (entity.IsSample == 2)
  689. {
  690. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  691. return;
  692. }
  693. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  694. {
  695. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  696. {
  697. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  698. return;
  699. }
  700. }
  701. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  702. }
  703. commonHelper.getCytPrice(entity);
  704. int memoopt = GetPostInt("MemoOpt");
  705. Boolean ismemoopt = false;
  706. if (memoopt > 0)
  707. {
  708. string stropt = "";
  709. if (memoopt == 1)
  710. {
  711. stropt = "“改稿”";
  712. ismemoopt = true;
  713. }
  714. else if (memoopt == 2)
  715. {
  716. stropt = "“定稿”";
  717. }
  718. else if (memoopt == 3)
  719. {
  720. stropt = "“查货”";
  721. CeErpSukuraData.createInfo(entity.ctid, 6);
  722. }
  723. entity.MemoOpt = Convert.ToInt32(memoopt);
  724. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  725. }
  726. if (entity.OrderState < 5)
  727. {
  728. memo = memo.Replace("(", "(");
  729. memo = memo.Replace(")", ")");
  730. }
  731. if (entity.OrderState < 3)
  732. {
  733. entity.DispatchSort = 0;
  734. }
  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.UpdateTime = DateTime.Now;
  869. entity.Update();
  870. returnSuccessMsg("保存成功!");
  871. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  872. return;
  873. }
  874. returnErrorMsg("找不到记录");
  875. }
  876. }
  877. public void save_erp_customermemo()
  878. {
  879. if (UrlPostParmsCheck("ctid"))
  880. {
  881. string ctid = GetPostString("ctid");
  882. CeErpTradeCell entity = null;
  883. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  884. if (entity != null)
  885. {
  886. entity.UpdateTime = DateTime.Now;
  887. entity.CustomerMemo = GetPostString("CustomerMemo");
  888. entity.Update();
  889. ApiVo apiVo = new ApiVo();
  890. apiVo.orderNumber = entity.ctid;
  891. apiVo.actionName = "followRemarks";
  892. apiVo.orderRemarks = entity.CustomerMemo;
  893. designHelper.API_WorkCore(apiVo);//followRemarks
  894. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  895. returnSuccessMsg("保存成功!");
  896. return;
  897. }
  898. returnErrorMsg("找不到记录");
  899. }
  900. }
  901. public void upd_erp_addmemotag()
  902. {
  903. if (UrlPostParmsCheck("ctid"))
  904. {
  905. ;
  906. string eid = GetPostString("ctid");
  907. string sfTagstr = GetPostString("memotag");
  908. CeErpTradeCell entity = null;
  909. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  910. if (entity != null)
  911. {
  912. ApiVo apiVo = new ApiVo();
  913. if (entity.OrderState == 0)
  914. {
  915. returnErrorMsg("请先领单");
  916. return;
  917. }
  918. //撤销顺丰
  919. if (sfTagstr == "撤销顺丰")
  920. {
  921. entity.IsSF = 0;
  922. string reMsg = "";
  923. string oldmemo = entity.seller_memo;
  924. if (entity.OrderState < 5)
  925. {
  926. oldmemo = oldmemo.Replace("顺丰到付", "");
  927. oldmemo = oldmemo.Replace("顺丰寄付", "");
  928. entity.seller_memo = oldmemo;
  929. }
  930. else
  931. {
  932. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  933. {
  934. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  935. }
  936. }
  937. entity.Update();
  938. apiVo.orderNumber = entity.ctid;
  939. apiVo.actionName = "orderRemarks";
  940. apiVo.orderRemarks = entity.seller_memo;
  941. apiVo.isSf = entity.IsSF.ToString();
  942. designHelper.API_WorkCore(apiVo);//orderRemarks
  943. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  944. returnSuccessMsg("撤销成功!" + reMsg);
  945. return;
  946. }
  947. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  948. {
  949. //string oldmemo = entity.seller_memo;
  950. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  951. string sfStr = GetPostString("memotag");
  952. string smemo = entity.seller_memo;
  953. int kindex = smemo.IndexOf(")");
  954. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  955. if (lastoneStr != "-")
  956. {
  957. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  958. }
  959. string prememo = smemo.Substring(0, kindex + 2);
  960. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  961. int lastkindex = lastmemo.IndexOf("(");
  962. string newlastmemo = "";
  963. if (lastkindex == 0)
  964. {
  965. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  966. newlastmemo = "(" + sfStr + "." + useLastmemo;
  967. }
  968. else
  969. {
  970. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  971. }
  972. entity.seller_memo = prememo + newlastmemo;
  973. }
  974. string sfTagMSg = "";
  975. if (sfTagstr == "顺丰寄付")
  976. {
  977. entity.IsSF = 1;
  978. sfTagMSg = "顺丰寄付";
  979. }
  980. else if (sfTagstr == "顺丰到付")
  981. {
  982. entity.IsSF = 2;
  983. sfTagMSg = "顺丰到付";
  984. }
  985. entity.Update();
  986. apiVo = new ApiVo();
  987. apiVo.orderNumber = entity.ctid;
  988. apiVo.actionName = "orderRemarks";
  989. apiVo.orderRemarks = entity.seller_memo;
  990. apiVo.isSf = entity.IsSF.ToString();
  991. designHelper.API_WorkCore(apiVo);//orderRemarks
  992. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  993. returnSuccessMsg("标记成功!");
  994. return;
  995. }
  996. returnErrorMsg("找不到记录");
  997. }
  998. }
  999. public void upd_erp_ordertag()
  1000. {
  1001. if (UrlPostParmsCheck("ctid"))
  1002. {
  1003. string eid = GetPostString("ctid");
  1004. CeErpTradeCell entity = null;
  1005. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1006. if (entity != null)
  1007. {
  1008. int tag = GetPostInt("wechattag");
  1009. //if(tag==4 && entity.IsSample == 2)
  1010. //{
  1011. // returnErrorMsg("补差价单不能标记微信单");
  1012. // return;
  1013. //}
  1014. entity.wechatTag = tag;
  1015. entity.Update();
  1016. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1017. if (tag == 1)
  1018. {
  1019. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1020. if (cash == null)
  1021. {
  1022. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1023. cash = new CeErpReturnCash();
  1024. cash.tid = entity.tid;
  1025. cash.seller_nick = main.seller_nick;
  1026. cash.payment = trade.payment;
  1027. cash.buyer_nick = main.buyer_nick;
  1028. cash.cashstate = 0;
  1029. cash.rtype = "微信返现";
  1030. cash.returnprice = 0;
  1031. cash.created = DateTime.Now;
  1032. cash.con = "订单标记微信单";
  1033. cash.img = "";
  1034. cash.applyuserid = CurrentUser.UserID;
  1035. cash.Create();
  1036. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1037. }
  1038. else
  1039. {
  1040. cash.cashstate = 0;
  1041. cash.Update();
  1042. }
  1043. CeErpSukuraData.createInfo(entity.ctid, 9);
  1044. }
  1045. else if (tag == 2)
  1046. {
  1047. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1048. if (cash == null)
  1049. {
  1050. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1051. cash = new CeErpReturnCash();
  1052. cash.tid = entity.tid;
  1053. cash.seller_nick = main.seller_nick;
  1054. cash.payment = trade.payment;
  1055. cash.buyer_nick = main.buyer_nick;
  1056. cash.cashstate = 0;
  1057. cash.rtype = "推购返现";
  1058. cash.returnprice = 5;
  1059. cash.created = DateTime.Now;
  1060. cash.con = "订单标记推购单";
  1061. cash.img = "";
  1062. cash.applyuserid = CurrentUser.UserID;
  1063. cash.Create();
  1064. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1065. }
  1066. else
  1067. {
  1068. cash.cashstate = 0;
  1069. cash.Update();
  1070. }
  1071. CeErpSukuraData.createInfo(entity.ctid, 9);
  1072. }
  1073. else if (tag == 3)
  1074. {
  1075. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1076. if (pers == null)
  1077. {
  1078. pers = new CeErpPersuade();
  1079. pers.ctid = entity.ctid;
  1080. pers.pstate = 0;
  1081. pers.created = DateTime.Now;
  1082. pers.applyuserid = CurrentUser.UserID;
  1083. pers.Create();
  1084. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1085. }
  1086. else
  1087. {
  1088. pers.pstate = 0;
  1089. pers.Update();
  1090. }
  1091. }
  1092. else if (tag == 4 || tag == 5)
  1093. {
  1094. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1095. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1096. if (pers == null)
  1097. {
  1098. pers = new CeErpStayGoods();
  1099. pers.t_id = entity.tid;
  1100. pers.status = "待审核";
  1101. pers.audit_type = 0;
  1102. if (tag == 4)
  1103. {
  1104. pers.stay_type = "微信推购";
  1105. }
  1106. else
  1107. {
  1108. pers.stay_type = "旺旺推购";
  1109. }
  1110. if (entity.IsXianHuo == 0)
  1111. {
  1112. pers.product_id = entity.ProductId;
  1113. }
  1114. pers.wangwang = main.buyer_nick;
  1115. pers.shop_name = main.seller_nick;
  1116. pers.creata_time = DateTime.Now;
  1117. pers.create_u_id = CurrentUser.UserID;
  1118. pers.create_u_name = CurrentUser.UserName;
  1119. pers.Create();
  1120. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1121. }
  1122. else
  1123. {
  1124. pers.audit_type = 0;
  1125. pers.Update();
  1126. }
  1127. CeErpSukuraData.createInfo(entity.ctid, 10);
  1128. }
  1129. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1130. returnSuccessMsg("标记成功!");
  1131. return;
  1132. }
  1133. returnErrorMsg("找不到记录");
  1134. }
  1135. }
  1136. public void upd_erp_ordertag_cancel()
  1137. {
  1138. if (UrlPostParmsCheck("ctid"))
  1139. {
  1140. string eid = GetPostString("ctid");
  1141. CeErpTradeCell entity = null;
  1142. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1143. if (entity != null)
  1144. {
  1145. entity.wechatTag = 0;
  1146. entity.Update();
  1147. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1148. if (pers != null)
  1149. {
  1150. pers.status = "取消推购";
  1151. pers.audit_type = 3;
  1152. pers.Update();
  1153. }
  1154. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1155. returnSuccessMsg("标记成功!");
  1156. return;
  1157. }
  1158. returnErrorMsg("找不到记录");
  1159. }
  1160. }
  1161. public void upd_erp_addweichattag()
  1162. {
  1163. if (UrlPostParmsCheck("ctid"))
  1164. {
  1165. ;
  1166. string eid = GetPostString("ctid");
  1167. CeErpTradeCell entity = null;
  1168. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1169. if (entity != null)
  1170. {
  1171. if (entity.IsAddWechat > 0)
  1172. {
  1173. returnErrorMsg("此单已经标记过了");
  1174. return;
  1175. }
  1176. 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);
  1177. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1178. if (dt.Rows.Count > 0)
  1179. {
  1180. entity.IsAddWechat = 2;
  1181. }
  1182. else
  1183. {
  1184. entity.IsAddWechat = 1;
  1185. }
  1186. entity.Update();
  1187. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1188. returnSuccessMsg("标记成功!");
  1189. return;
  1190. }
  1191. returnErrorMsg("找不到记录");
  1192. }
  1193. }
  1194. public void upd_erp_getmyorder()
  1195. {
  1196. if (UrlPostParmsCheck("ctid"))
  1197. {
  1198. ;
  1199. string eid = GetPostString("ctid");
  1200. CeErpTradeCell entity = null;
  1201. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1202. if (entity != null)
  1203. {
  1204. if (entity.ctid.IndexOf("C") != -1)
  1205. {
  1206. StringBuilder sql = new StringBuilder();
  1207. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1208. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1209. if (dt.Rows.Count > 0)
  1210. {
  1211. decimal total = 0;
  1212. foreach (DataRow dr in dt.Rows)
  1213. {
  1214. total += Convert.ToDecimal(dr["payment"]);
  1215. }
  1216. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1217. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1218. {
  1219. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1220. return;
  1221. }
  1222. }
  1223. }
  1224. if (entity.OrderState == -1)
  1225. {
  1226. returnErrorMsg("待审核订单无法领取!");
  1227. return;
  1228. }
  1229. entity.CustomerUserId = CurrentUser.UserID;
  1230. if (entity.OrderState < 2)
  1231. {
  1232. entity.OrderState = 2;
  1233. if (entity.ShopId != 0)
  1234. {
  1235. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1236. }
  1237. }
  1238. entity.UpdateTime = DateTime.Now;
  1239. entity.Update();
  1240. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1241. returnSuccessMsg("领单成功!");
  1242. return;
  1243. }
  1244. returnErrorMsg("找不到记录");
  1245. }
  1246. }
  1247. public void getmyorder_from_init()
  1248. {
  1249. if (UrlPostParmsCheck("ctid"))
  1250. {
  1251. string eid = GetPostString("ctid");
  1252. CeErpTradeCell entity = null;
  1253. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1254. if (entity != null)
  1255. {
  1256. string sellerMemo = GetPostString("sellerMemo");
  1257. if (sellerMemo.Length > 0)
  1258. {
  1259. entity.seller_memo = sellerMemo;
  1260. }
  1261. string oterhMemo = GetPostString("otherMemo");
  1262. if (oterhMemo.Length > 0)
  1263. {
  1264. entity.OtherMemo = oterhMemo;
  1265. }
  1266. int urg = GetPostInt("urgency");
  1267. entity.IsUrgency = (urg == 1 ? true : false);
  1268. int wechat = GetPostInt("wechat");
  1269. int command = GetPostInt("command");
  1270. if (wechat == 1)
  1271. {
  1272. entity.wechatTag = 1;
  1273. }
  1274. if (command == 1)
  1275. {
  1276. entity.wechatTag = 2;
  1277. }
  1278. string pPro = GetPostString("pprofession");
  1279. if (pPro.Length > 0)
  1280. {
  1281. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1282. string spro = GetPostString("profession");
  1283. if (spro.Length > 0)
  1284. {
  1285. entity.ProfessionId = Convert.ToInt32(spro);
  1286. }
  1287. }
  1288. string proId = GetPostString("productId");
  1289. if (proId.Length > 0)
  1290. {
  1291. entity.ProductId = Convert.ToInt32(proId);
  1292. }
  1293. entity.Material = GetPostString("material");
  1294. entity.Craft = GetPostString("craft");
  1295. entity.CustomerUserId = CurrentUser.UserID;
  1296. if (entity.OrderState < 2)
  1297. {
  1298. entity.OrderState = 2;
  1299. if (entity.ShopId != 0)
  1300. {
  1301. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1302. }
  1303. }
  1304. entity.Update();
  1305. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1306. returnSuccessMsg("领单成功!");
  1307. return;
  1308. }
  1309. returnErrorMsg("找不到记录");
  1310. }
  1311. }
  1312. public void upd_erp_setrelationorder()
  1313. {
  1314. if (UrlPostParmsCheck("ctid"))
  1315. {
  1316. ;
  1317. string eid = GetPostString("ctid");
  1318. string ftid = GetPostString("ftid");
  1319. CeErpTradeCell entity = null;
  1320. CeErpTradeCell fentity = null;
  1321. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1322. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1323. if (fentity == null)
  1324. {
  1325. returnErrorMsg("找不到关联的主订单");
  1326. return;
  1327. }
  1328. if (entity != null)
  1329. {
  1330. if (entity.OrderState >= 5)
  1331. {
  1332. returnErrorMsg("本单已经设计完成无法关联");
  1333. return;
  1334. }
  1335. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1336. {
  1337. returnErrorMsg("线下单续审核后才能关联!");
  1338. return;
  1339. }
  1340. entity.ptid = ftid;
  1341. entity.OrderState = fentity.OrderState;
  1342. //entity.status = fentity.status;
  1343. entity.CustomerUserId = fentity.CustomerUserId;
  1344. entity.DesignUserId = fentity.DesignUserId;
  1345. entity.seller_memo = "补差价单:" + ftid;
  1346. entity.IsSample = 2;
  1347. entity.Update();
  1348. ApiVo apiVo = new ApiVo();
  1349. apiVo.orderNumber = ftid;
  1350. apiVo.payment = entity.payment;
  1351. apiVo.actionName = "repairDesign";
  1352. designHelper.API_WorkCore(apiVo);//repairDesign
  1353. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1354. returnSuccessMsg("关联成功!");
  1355. return;
  1356. }
  1357. else
  1358. returnErrorMsg("找不到记录");
  1359. }
  1360. }
  1361. public void download_erp_neworder()
  1362. {
  1363. string seller = GetPostString("seller_nick");
  1364. string tid = GetPostString("tid");
  1365. if (seller.Length <= 0 || tid.Length <= 0)
  1366. {
  1367. returnErrorMsg("数据错误");
  1368. }
  1369. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1370. //{
  1371. // returnErrorMsg("找不到店铺Sessionkey");
  1372. //}
  1373. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1374. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1375. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1376. if (res.IndexOf("refOid") == -1)
  1377. {
  1378. returnErrorMsg("下载订单数据失败");
  1379. return;
  1380. }
  1381. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1382. returnSuccessMsg("下载完成");
  1383. //tmcHelper.createNewOrder(res);
  1384. //CeErpTrade entr = null;
  1385. //entr = CeErpTrade.Get(tid);
  1386. //if (entr != null)
  1387. //{
  1388. // returnSuccess("下载成功");
  1389. // //下载成功之后,Cell表生成对应的订单;
  1390. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1391. //}
  1392. //else
  1393. //{
  1394. // returnErrorMsg("下载失败或者创建订单失败");
  1395. //}
  1396. }
  1397. public void set_erp_atersale()
  1398. {
  1399. if (UrlPostParmsCheck("ctid"))
  1400. {
  1401. string eid = GetPostString("ctid");
  1402. string reason = GetPostString("AfterSaleReason");
  1403. CeErpTradeCell entity = null;
  1404. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1405. if (entity != null)
  1406. {
  1407. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1408. {
  1409. returnErrorMsg("此订单已经在售后");
  1410. return;
  1411. }
  1412. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1413. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1414. entity.AfterSaleTime = DateTime.Now;
  1415. entity.Update();
  1416. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1417. returnSuccessMsg("转售后成功!");
  1418. return;
  1419. }
  1420. returnErrorMsg("找不到记录");
  1421. }
  1422. }
  1423. public void set_erp_withdraw()
  1424. {
  1425. if (UrlPostParmsCheck("ctid"))
  1426. {
  1427. try
  1428. {
  1429. string eid = GetPostString("ctid");//商品id
  1430. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1431. CeWithdraw ceWithdrawSelect = null;
  1432. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1433. if (ceWithdrawSelect != null)
  1434. {
  1435. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1436. {
  1437. ceWithdrawSelect.status = -1;
  1438. ceWithdrawSelect.Update();
  1439. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1440. returnSuccessMsg("重新发起审核成功");
  1441. return;
  1442. }
  1443. else
  1444. {
  1445. returnSuccessMsg("请勿重复申请!");
  1446. return;
  1447. }
  1448. }
  1449. else
  1450. {
  1451. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1452. if (string.IsNullOrEmpty(CustomerUserId))
  1453. {
  1454. CustomerUserId = "-1";
  1455. }
  1456. int Userid = CurrentUser.UserID;//用户id
  1457. CeWithdraw ceWithdraw = new CeWithdraw();
  1458. ceWithdraw.tid = eid;
  1459. ceWithdraw.userid = Userid;
  1460. ceWithdraw.providerid = CustomerUserId;
  1461. ceWithdraw.status = 3;
  1462. ceWithdraw.creationtime = DateTime.Now;
  1463. ceWithdraw.Create();
  1464. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1465. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1466. return;
  1467. }
  1468. }
  1469. catch
  1470. {
  1471. returnErrorMsg("申请撤回订单失败");
  1472. return;
  1473. }
  1474. }
  1475. }
  1476. public void ins_erp_billinfo()
  1477. {
  1478. if (UrlPostParmsCheck("ctid"))
  1479. {
  1480. string eid = GetPostString("ctid");
  1481. CeErpTradeCell entity = null;
  1482. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1483. if (entity != null)
  1484. {
  1485. CeErpBill bill = CeErpBill.GetByTid(eid);
  1486. bool isHave = false;
  1487. if (bill != null)
  1488. {
  1489. isHave = true;
  1490. if (bill.state != 4)
  1491. {
  1492. returnErrorMsg("此单已经申请过发票了");
  1493. return;
  1494. }
  1495. }
  1496. if (entity.IsNeedBill == 0)
  1497. {
  1498. entity.IsNeedBill = 1;
  1499. }
  1500. entity.Update();
  1501. string errjson = "";
  1502. try
  1503. {
  1504. CeErpBill bill_entity = new CeErpBill();
  1505. bill_entity.tid = entity.tid;
  1506. bill_entity.title = GetPostString("title");
  1507. string taxstr = GetPostString("tax");
  1508. taxstr = taxstr.Replace(" ", "");
  1509. bill_entity.tax = taxstr;
  1510. bill_entity.bank = GetPostString("bank");
  1511. string bankacstr = GetPostString("bankac");
  1512. bankacstr = bankacstr.Replace(" ", "");
  1513. bill_entity.bankac = bankacstr;
  1514. bill_entity.address = GetPostString("address");
  1515. bill_entity.phone = GetPostString("phone");
  1516. bill_entity.price = GetPostString("price");
  1517. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1518. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1519. {
  1520. billCount += 1;
  1521. }
  1522. string prebill = "ltb";
  1523. for (int idx = 1; idx <= billCount; idx++)
  1524. {
  1525. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1526. string billoid = prebill + idx + dtstr;
  1527. bill_entity.billOrderId += billoid;
  1528. if (idx < billCount)
  1529. {
  1530. bill_entity.billOrderId += ",";
  1531. }
  1532. }
  1533. bill_entity.productId = GetPostInt("ProductName");
  1534. bill_entity.num = GetPostInt("num");
  1535. bill_entity.unit = GetPostString("unit");
  1536. bill_entity.type = GetPostString("type");
  1537. bill_entity.sendType = GetPostString("SendType");
  1538. bill_entity.email = GetPostString("email");
  1539. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1540. bill_entity.shopName = GetPostString("ShopName");
  1541. bill_entity.applymemo = GetPostString("applyMemo");
  1542. bill_entity.createTime = DateTime.Now;
  1543. bill_entity.state = 0;
  1544. bill_entity.userId = CurrentUser.UserID;
  1545. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1546. bill_entity.Create();
  1547. }
  1548. catch (Exception ex)
  1549. {
  1550. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1551. returnErrorMsg("创建发票出错!");
  1552. return;
  1553. }
  1554. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1555. returnSuccessMsg("发票申请成功!");
  1556. return;
  1557. }
  1558. returnErrorMsg("找不到记录");
  1559. }
  1560. }
  1561. public void ins_erp_neworder()
  1562. {
  1563. if (UrlPostParmsCheck("receiver_name"))
  1564. {
  1565. CeErpTrade entity = new CeErpTrade();
  1566. string plat_form = GetPostString("platform");
  1567. string preStr = "N_";
  1568. if (plat_form == "拼多多")
  1569. {
  1570. preStr = "P_";
  1571. }
  1572. else if (plat_form == "阿里巴巴")
  1573. {
  1574. preStr = "A_";
  1575. }
  1576. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1577. entity.seller_nick = GetPostString("seller_nick");
  1578. entity.buyer_nick = GetPostString("buyer_nick");
  1579. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1580. entity.total_fee = entity.payment;
  1581. entity.pay_time = DateTime.Now;
  1582. entity.status = "NOT_SHIPPED";
  1583. entity.receiver_name = GetPostString("receiver_name");
  1584. entity.receiver_mobile = GetPostString("receiver_mobile");
  1585. entity.receiver_state = GetPostString("receiver_state");
  1586. entity.receiver_city = GetPostString("receiver_city");
  1587. entity.receiver_district = GetPostString("receiver_district");
  1588. entity.receiver_address = GetPostString("receiver_address");
  1589. if (entity.receiver_state == "" || entity.receiver_city == "")
  1590. {
  1591. returnErrorMsg("收件地址不能为空");
  1592. return;
  1593. }
  1594. int shopId = 0;
  1595. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1596. if (nShop != null)
  1597. {
  1598. shopId = nShop.ID;
  1599. }
  1600. if (shopId != 34 && entity.payment == 0)
  1601. {
  1602. returnErrorMsg("公司自用的单金额才能为0");
  1603. return;
  1604. }
  1605. entity.Create();
  1606. CeErpTradeCell entitycell = new CeErpTradeCell();
  1607. entitycell.ctid = entity.tid;
  1608. entitycell.tid = entity.tid;
  1609. entitycell.ShopId = shopId;
  1610. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1611. entitycell.OrderState = 0;
  1612. entitycell.pay_time = entity.pay_time;
  1613. entitycell.IsOffLineOrder = 1;
  1614. entitycell.Create();
  1615. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1616. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1617. return;
  1618. }
  1619. }
  1620. public void ins_erp_neworder2()
  1621. {
  1622. if (UrlPostParmsCheck("receiver_name"))
  1623. {
  1624. //string plat_form = GetPostString("platform");
  1625. string preStr = "X_";
  1626. string memo = GetPostString("memo");
  1627. string productId = GetPostString("productId");
  1628. string primg = GetPostString("proofimg");
  1629. string sellerNick = GetPostString("seller_nick");
  1630. string addFrom = GetPostString("addfrom");
  1631. if (addFrom == "1")
  1632. {
  1633. preStr = "N_";
  1634. }
  1635. int shopId = 0;
  1636. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1637. if (nShop != null)
  1638. {
  1639. shopId = nShop.ID;
  1640. }
  1641. else
  1642. {
  1643. returnErrorMsg("找不到对应店铺");
  1644. return;
  1645. }
  1646. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1647. {
  1648. returnErrorMsg("必须上传付款凭证");
  1649. return;
  1650. }
  1651. CeErpTrade entity = new CeErpTrade();
  1652. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1653. entity.seller_nick = sellerNick;
  1654. entity.buyer_nick = GetPostString("buyer_nick");
  1655. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1656. entity.total_fee = entity.payment;
  1657. entity.pay_time = DateTime.Now;
  1658. entity.status = "NOT_SHIPPED";
  1659. entity.receiver_name = GetPostString("receiver_name");
  1660. entity.receiver_mobile = GetPostString("receiver_mobile");
  1661. entity.receiver_state = GetPostString("receiver_state");
  1662. entity.receiver_city = GetPostString("receiver_city");
  1663. entity.receiver_district = GetPostString("receiver_district");
  1664. entity.receiver_address = GetPostString("receiver_address");
  1665. entity.seller_memo = memo;
  1666. entity.orderFrom = 20;
  1667. entity.orderType = 15;
  1668. if (entity.receiver_state == "" || entity.receiver_city == "")
  1669. {
  1670. returnErrorMsg("收件地址不能为空");
  1671. return;
  1672. }
  1673. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1674. {
  1675. returnErrorMsg("公司自用的单金额才能为0");
  1676. return;
  1677. }
  1678. entity.Create();
  1679. string toWhere = GetPostString("towhere");
  1680. CeErpTradeCell entitycell = new CeErpTradeCell();
  1681. entitycell.ctid = entity.tid;
  1682. //唯一标识
  1683. entitycell.OrderSn = entity.tid;
  1684. string orderSn = dataHelper.getSaleOrderSn();
  1685. if (orderSn != "")
  1686. {
  1687. entitycell.OrderSn = orderSn;
  1688. }
  1689. entitycell.tid = entity.tid;
  1690. //if (preStr == "X_")
  1691. //{
  1692. entitycell.IsOffLineOrder = 1;
  1693. //}
  1694. entitycell.CustomerUserId = CurrentUser.UserID;
  1695. entitycell.PayProofImg = primg;
  1696. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1697. entitycell.ProductId = Convert.ToInt32(productId);
  1698. entitycell.ShopId = shopId;
  1699. entitycell.UpdateTime = DateTime.Now;
  1700. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1701. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1702. {
  1703. entitycell.IsXianHuo = 1;
  1704. }
  1705. entitycell.pay_time = entity.pay_time;
  1706. if (toWhere == "1")
  1707. {
  1708. entitycell.OrderState = 2;
  1709. }
  1710. else
  1711. {
  1712. entitycell.OrderState = 6;
  1713. entitycell.FinishPlaceTime = entitycell.pay_time;
  1714. }
  1715. if (shopId == 94)
  1716. {
  1717. entitycell.OrderState = 4;
  1718. entitycell.WaitDesignTime = entitycell.pay_time;
  1719. entitycell.StartDesignTime = entitycell.pay_time;
  1720. entitycell.DesignUserId = 218;
  1721. }
  1722. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1723. {
  1724. entitycell.OrderState = -1;//修改12-5
  1725. CeWithdraw ceWithdraw = new CeWithdraw();
  1726. ceWithdraw.tid = entity.tid;
  1727. ceWithdraw.providerid = "-1";
  1728. ceWithdraw.status = -1;
  1729. ceWithdraw.creationtime = DateTime.Now;
  1730. ceWithdraw.userid = 1337;
  1731. ceWithdraw.Create();
  1732. }
  1733. entitycell.Create();
  1734. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1735. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1736. {
  1737. addPlaceRegist(entitycell, CurrentUser.UserID);
  1738. }
  1739. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1740. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1741. return;
  1742. }
  1743. }
  1744. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1745. {
  1746. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1747. entity.PlactTime = tradecell.pay_time;
  1748. entity.AddUserId = userid;
  1749. entity.FileName = tradecell.seller_memo;
  1750. entity.Supplier = 24;
  1751. entity.CreateTime = DateTime.Now;
  1752. entity.Did = tradecell.ctid;
  1753. entity.tid = tradecell.tid;
  1754. entity.splitTag = tradecell.SplitTag;
  1755. entity.CurState = "未完成";
  1756. entity.Create();
  1757. }
  1758. public void get_erp_offlinelist()
  1759. {
  1760. DataStruct dStruct = GetPostStruct();
  1761. List<string> lw = new List<string>();
  1762. string tid = GetPostString("ctid");
  1763. string date1 = GetPostString("date1");
  1764. string date2 = GetPostString("date2");
  1765. if (tid.Length > 0 || date1.Length > 0)
  1766. {
  1767. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1768. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1769. if (dw.Length > 0) lw.Add(dw);
  1770. }
  1771. else
  1772. {
  1773. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1774. }
  1775. string shopname = GetPostString("shopname");
  1776. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1777. string buyernick = GetPostString("buyer_nick");
  1778. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1779. string customer = GetPostString("customer");
  1780. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1781. string design = GetPostString("design");
  1782. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1783. string orderState = GetPostString("orderState");
  1784. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1785. string address = GetPostString("address");
  1786. 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));
  1787. string sellermemo = GetPostString("seller_memo");
  1788. if (sellermemo.Length > 0)
  1789. {
  1790. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1791. }
  1792. string price1 = GetPostString("price1");
  1793. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1794. string price2 = GetPostString("price2");
  1795. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1796. //if (PKey != "admin")
  1797. //{
  1798. // string usershop = CurrentUser.User.pemShop;
  1799. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1800. //}
  1801. //if (ex_psize > 0)
  1802. //{
  1803. dStruct.Order = "pay_time desc";
  1804. //}
  1805. //else
  1806. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1807. lw.Add(string.Format("IsOffLineOrder=1"));
  1808. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1809. DataTable dt = null;
  1810. dt = WebCache.GetData("view_erptradecell", dStruct);
  1811. writeGridDataTableJson(dStruct.TotalCount, dt);
  1812. }
  1813. public void get_erp_returncashrecord()
  1814. {
  1815. DataStruct dStruct = GetPostStruct();
  1816. List<string> lw = new List<string>();
  1817. string tid = GetPostString("ctid");
  1818. if (tid.Length > 0)
  1819. {
  1820. lw.Add(string.Format("tid like '%{0}%'", tid));
  1821. dStruct.Order = "id desc";
  1822. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1823. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1824. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1825. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1826. return;
  1827. }
  1828. returnErrorMsg("id数据错误!");
  1829. }
  1830. public void ins_erp_returncashrecord()
  1831. {
  1832. if (UrlPostParmsCheck("tid"))
  1833. {
  1834. string tid = GetPostString("tid");
  1835. string retype = GetPostString("type");
  1836. StringBuilder sql = new StringBuilder();
  1837. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1838. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1839. if (dt.Rows.Count > 0)
  1840. {
  1841. returnErrorMsg("相同返现类型记录已存在");
  1842. return;
  1843. }
  1844. CeErpReturnCash entity = new CeErpReturnCash();
  1845. entity.tid = tid;
  1846. entity.seller_nick = GetPostString("seller_nick");
  1847. string pment = GetPostString("payment");
  1848. if (pment.Length > 0)
  1849. {
  1850. entity.payment = Convert.ToDouble(pment);
  1851. }
  1852. entity.buyer_nick = GetPostString("buyer_nick");
  1853. entity.cashstate = 0;
  1854. entity.rtype = retype;
  1855. string rPrice = GetPostString("returnprice");
  1856. if (rPrice.Length > 0)
  1857. {
  1858. entity.returnprice = Convert.ToDouble(rPrice);
  1859. }
  1860. entity.created = DateTime.Now;
  1861. entity.con = GetPostString("con");
  1862. entity.img = GetPostString("img");
  1863. entity.applyuserid = CurrentUser.UserID;
  1864. entity.Create();
  1865. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1866. returnSuccessMsg("操作成功!");
  1867. return;
  1868. }
  1869. }
  1870. public void set_erp_predelivery()
  1871. {
  1872. if (UrlPostParmsCheck("ctid"))
  1873. {
  1874. string eid = GetPostString("ctid");
  1875. CeErpTradeCell entity = null;
  1876. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1877. if (entity != null)
  1878. {
  1879. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1880. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1881. //{
  1882. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1883. // return;
  1884. //}
  1885. entity.IsPreDelivery = 1;
  1886. entity.Update();
  1887. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1888. returnSuccessMsg("预发货成功!");
  1889. return;
  1890. //string shop = GetPostString("seller_nick");
  1891. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1892. //string comName = GetPostString("comName");
  1893. //string comCode = GetPostString("comCode");
  1894. //string outSid = GetPostString("outSid");//运单号
  1895. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1896. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1897. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1898. //string apires = "";
  1899. //if (deliveryType == "虚拟发货")
  1900. //{
  1901. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1902. //}
  1903. //else
  1904. //{
  1905. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1906. //}
  1907. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1908. ////{
  1909. //if (apires.IndexOf("发货成功") != -1)
  1910. //{
  1911. // if (deliveryType != "虚拟发货")
  1912. // {
  1913. // //还要插入快递信息到 快递信息表
  1914. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1915. // exinfo.tid = eid;
  1916. // exinfo.out_sid = outSid;
  1917. // exinfo.company_code = comCode;
  1918. // exinfo.company_name = comName;
  1919. // exinfo.delivery_memo = deliveryMemo;
  1920. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1921. // exinfo.deliveryType = deliveryType;
  1922. // exinfo.Create();
  1923. // }
  1924. // returnSuccessMsg("发货成功!");
  1925. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1926. //}
  1927. //else
  1928. //{
  1929. // returnErrorMsg("淘宝发货失败!!");
  1930. //}
  1931. //return;
  1932. }
  1933. returnErrorMsg("找不到订单记录");
  1934. }
  1935. }
  1936. public void get_erp_unusuallist()
  1937. {
  1938. DataStruct dStruct = GetPostStruct();
  1939. List<string> lw = new List<string>();
  1940. string tid = GetPostString("ctid");
  1941. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1942. string shopname = GetPostString("shopname");
  1943. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1944. string buyernick = GetPostString("buyer_nick");
  1945. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1946. string ResponsibleMan = GetPostString("responsible");
  1947. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1948. string date1 = GetPostString("date1");
  1949. string date2 = GetPostString("date2");
  1950. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1951. if (dw.Length > 0) lw.Add(dw);
  1952. string price1 = GetPostString("price1");
  1953. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1954. string price2 = GetPostString("price2");
  1955. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1956. string orderState = GetPostString("orderState");
  1957. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1958. string sellermemo = GetPostString("seller_memo");
  1959. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1960. lw.Add(string.Format("UnusualTag > 0"));
  1961. lw.Add(string.Format("IsRefund<={0}", 1));
  1962. dStruct.Order = "pay_time desc";
  1963. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1964. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1965. writeGridDataTableJson(dStruct.TotalCount, dt);
  1966. }
  1967. public void set_erp_unusualtonomal()
  1968. {
  1969. if (UrlPostParmsCheck("ctid"))
  1970. {
  1971. string eid = GetPostString("ctid");
  1972. CeErpTradeCell entity = null;
  1973. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1974. if (entity != null)
  1975. {
  1976. entity.UnusualTag = -1;
  1977. entity.Update();
  1978. returnSuccessMsg("忽略成功!");
  1979. return;
  1980. }
  1981. returnErrorMsg("找不到记录");
  1982. }
  1983. }
  1984. public void ins_erp_unusualreason()
  1985. {
  1986. if (UrlPostParmsCheck("ctid"))
  1987. {
  1988. string eid = GetPostString("ctid");
  1989. CeErpTradeCell entity = null;
  1990. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1991. if (entity != null)
  1992. {
  1993. entity.MemoOpt = 4;
  1994. entity.UnusualCon = GetPostString("con");
  1995. entity.Update();
  1996. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1997. if (trade != null)
  1998. {
  1999. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2000. }
  2001. //查货是否超时
  2002. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2003. if (ceErpTradeCellExtend == null)
  2004. {
  2005. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2006. ceErpTradeCellExtend.ctid = entity.ctid;
  2007. }
  2008. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2009. {
  2010. ceErpTradeCellExtend.CheckOut += 1;
  2011. }
  2012. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2013. if (ceErpTradeCellExtend.ID > 0)
  2014. {
  2015. ceErpTradeCellExtend.Update();
  2016. }
  2017. else
  2018. {
  2019. ceErpTradeCellExtend.Create();
  2020. }
  2021. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2022. returnSuccessMsg("操作成功!");
  2023. return;
  2024. }
  2025. returnErrorMsg("找不到记录");
  2026. }
  2027. }
  2028. public void upd_erp_sampleorder()
  2029. {
  2030. if (UrlPostParmsCheck("ctid"))
  2031. {
  2032. string eid = GetPostString("ctid");
  2033. string[] eArr = eid.Split(',');
  2034. if (eArr.Length > 1)
  2035. {
  2036. List<string> eLst = new List<string>();
  2037. for (int i = 0; i < eArr.Length; i++)
  2038. {
  2039. eLst.Add("'" + eArr[i] + "'");
  2040. }
  2041. eid = string.Join(",", eLst.ToArray());
  2042. }
  2043. else
  2044. {
  2045. eid = "'" + eid + "'";
  2046. }
  2047. StringBuilder sql = new StringBuilder();
  2048. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2049. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2050. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2051. if (dt.Rows.Count > 0)
  2052. {
  2053. string errmsg = "";
  2054. foreach (DataRow dr in dt.Rows)
  2055. {
  2056. StringBuilder sqlsb = new StringBuilder();
  2057. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2058. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2059. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2060. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2061. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2062. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2063. {
  2064. continue;
  2065. }
  2066. else
  2067. {
  2068. string emsg = commonHelper.KeepChinese(apires);
  2069. errmsg += emsg;
  2070. }
  2071. }
  2072. if (errmsg.Length > 0)
  2073. {
  2074. returnErrorMsg(errmsg);
  2075. return;
  2076. }
  2077. returnSuccessMsg("操作成功");
  2078. return;
  2079. }
  2080. returnErrorMsg("找不到记录");
  2081. }
  2082. }
  2083. public void upd_erp_transcustomer()
  2084. {
  2085. if (UrlPostParmsCheck("ctid"))
  2086. {
  2087. string eid = GetPostString("ctid");
  2088. int userid = GetPostInt("CustomerUserId");
  2089. CeErpTradeCell entity = null;
  2090. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2091. if (entity != null)
  2092. {
  2093. //string[] mlist = entity.seller_memo.Split('-');
  2094. //string sql = "select * from view_erpuser where id=" + userid;
  2095. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2096. //if (dt != null && dt.Rows.Count > 0)
  2097. //{
  2098. // string nmemo = "";
  2099. // for(int i = 0; i < mlist.Length - 1; i++)
  2100. // {
  2101. // nmemo += mlist[i];
  2102. // nmemo += "-";
  2103. // }
  2104. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2105. // entity.seller_memo = nmemo;
  2106. //}
  2107. entity.CustomerUserId = userid;
  2108. entity.Update();
  2109. returnSuccessMsg("操作成功!");
  2110. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2111. return;
  2112. }
  2113. returnErrorMsg("找不到记录");
  2114. }
  2115. }
  2116. public void upd_erp_transdesigner()
  2117. {
  2118. if (UrlPostParmsCheck("ctid"))
  2119. {
  2120. string eids = GetPostString("ctid");
  2121. string[] ctidList = eids.Split(',');
  2122. int userid = GetPostInt("DesignUserId");
  2123. foreach (string ctid in ctidList)
  2124. {
  2125. CeErpTradeCell entity = null;
  2126. CeErpDesignerBill entitys = null;
  2127. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2128. entitys = CeErpDesignerBill.GetByTid(ctid);
  2129. if (entity != null)
  2130. {
  2131. if (entity.OrderState > 4)
  2132. {
  2133. continue;
  2134. }
  2135. //存在退款不能流转
  2136. if (entity.IsRefund > 0)
  2137. {
  2138. continue;
  2139. }
  2140. entity.DesignUserId = userid;
  2141. entity.WaitDesignTime = DateTime.Now;
  2142. entity.Update();
  2143. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2144. }
  2145. }
  2146. returnSuccessMsg("操作成功!");
  2147. }
  2148. }
  2149. public void upd_erp_distributedesigner()
  2150. {
  2151. if (UrlPostParmsCheck("ctid"))
  2152. {
  2153. string eid = GetPostString("ctid");
  2154. int userid = GetPostInt("DesignUserId");
  2155. string[] idlist = eid.Split(',');
  2156. if (idlist.Length <= 0)
  2157. {
  2158. returnErrorMsg("订单不能为空");
  2159. return;
  2160. }
  2161. foreach (string ctid in idlist)
  2162. {
  2163. CeErpTradeCell entity = null;
  2164. CeErpDesignerBill entitys = null;
  2165. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2166. else continue;
  2167. if (entity != null)
  2168. {
  2169. if (userid == 2125 || userid == 3542)
  2170. { }
  2171. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2172. {
  2173. returnErrorMsg("金额错误的订单无法指派");
  2174. return;
  2175. }
  2176. if (entity.OrderState >= 5)
  2177. {
  2178. returnErrorMsg("已经设计完成无法指派");
  2179. return;
  2180. }
  2181. if (entity.OrderState == -1)
  2182. {
  2183. returnErrorMsg("审核中的订单无法指派");
  2184. return;
  2185. }
  2186. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2187. {
  2188. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2189. return;
  2190. }
  2191. //157赖橙帆 159林晨 73 静之颖
  2192. 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)
  2193. {
  2194. returnErrorMsg("指派设计共创无法再次指派!");
  2195. return;
  2196. }
  2197. entity.OrderState = 3;
  2198. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  2199. if (entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  2200. {
  2201. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2202. entity.SupplierId = suid;
  2203. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2204. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2205. }
  2206. if (userid == 2125 && entity.seller_memo != "")
  2207. {
  2208. apiDesign.API_GetPrintData_CreateOrder(entity);
  2209. }
  2210. if (userid == 3542 && entity.seller_memo != "")
  2211. {
  2212. string userPost = CurrentUser.UserPost.Post.Code;
  2213. if (CurrentUser.UserID == 73)
  2214. {
  2215. userPost = "SysAdmin";
  2216. }
  2217. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2218. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2219. if (response.msg != "设计共创:成功")
  2220. {
  2221. returnErrorMsg(response.msg);
  2222. return;
  2223. }
  2224. entity.DispatchSort = 2;
  2225. }
  2226. else
  2227. {
  2228. if (entity.DispatchSort == 2)
  2229. {
  2230. ApiVo apiVo = new ApiVo();
  2231. apiVo.actionName = "closeDesign";
  2232. apiVo.orderNumber = entity.ctid;
  2233. designHelper.API_WorkCore(apiVo);//closeDesign
  2234. }
  2235. entity.DispatchSort = 0;
  2236. }
  2237. entity.DesignUserId = userid;
  2238. entity.WaitDesignTime = DateTime.Now;
  2239. entity.UpdateTime = DateTime.Now;
  2240. entity.Update();
  2241. string name = commonHelper.getUserNameById(userid);
  2242. commonHelper.UpdateRelationOrder(entity.ctid);
  2243. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2244. }
  2245. }
  2246. returnSuccessMsg("操作成功!");
  2247. return;
  2248. }
  2249. }
  2250. public string getTidByCtid(string ctid)
  2251. {
  2252. string tid = "";
  2253. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2254. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2255. if (dataTable != null && dataTable.Rows.Count > 0)
  2256. {
  2257. tid = dataTable.Rows[0]["tid"].ToString();
  2258. }
  2259. return tid;
  2260. }
  2261. public List<string> getTidByCtidLike(string ctid)
  2262. {
  2263. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2264. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2265. List<string> list = new List<string>();
  2266. if (dataTable != null && dataTable.Rows.Count > 0)
  2267. {
  2268. foreach (DataRow item in dataTable.Rows)
  2269. {
  2270. list.Add("'" + item["tid"].ToString() + "'");
  2271. }
  2272. }
  2273. return list;
  2274. }
  2275. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2276. {
  2277. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2278. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2279. List<string> list = new List<string>();
  2280. if (dataTable != null && dataTable.Rows.Count > 0)
  2281. {
  2282. foreach (DataRow item in dataTable.Rows)
  2283. {
  2284. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2285. {
  2286. continue;
  2287. }
  2288. list.Add("'" + item["receiverId"].ToString() + "'");
  2289. }
  2290. }
  2291. return list;
  2292. }
  2293. public void get_erp_myorderlist()
  2294. {
  2295. DataStruct dStruct = GetPostStruct();
  2296. List<string> lw = new List<string>();
  2297. string tid = GetPostString("ctid");
  2298. if (tid.Length > 0)
  2299. {
  2300. string select_tid = getTidByCtid(tid);
  2301. lw.Add(string.Format("tid='{0}'", select_tid));
  2302. }
  2303. else
  2304. {
  2305. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2306. }
  2307. //12-1 修改
  2308. string urgent = GetPostString("urgent");
  2309. string back = GetPostString("back");
  2310. string offlineSearch = GetPostString("offlineSearch");
  2311. if (!string.IsNullOrWhiteSpace(urgent))
  2312. {
  2313. if (urgent.Equals("true"))
  2314. {
  2315. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2316. }
  2317. }
  2318. if (!string.IsNullOrWhiteSpace(back))
  2319. {
  2320. if (back.Equals("true"))
  2321. {
  2322. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2323. }
  2324. }
  2325. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2326. {
  2327. if (offlineSearch.Equals("true"))
  2328. {
  2329. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2330. }
  2331. }
  2332. //end
  2333. string shopname = GetPostString("shopname");
  2334. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2335. string buyernick = GetPostString("buyer_nick");
  2336. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2337. string design = GetPostString("design");
  2338. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2339. string orderState = GetPostString("orderState");
  2340. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2341. string sellermemo = GetPostString("seller_memo");
  2342. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2343. string date1 = GetPostString("date1");
  2344. string date2 = GetPostString("date2");
  2345. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2346. if (dw.Length > 0) lw.Add(dw);
  2347. string price1 = GetPostString("price1");
  2348. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2349. string price2 = GetPostString("price2");
  2350. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2351. string urgency = GetPostString("urgency");
  2352. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2353. string after = GetPostString("after");
  2354. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2355. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2356. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2357. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2358. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2359. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2360. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2361. if (dt != null && dt.Rows.Count > 0)
  2362. {
  2363. foreach (DataRow dr in dt.Rows)
  2364. {
  2365. try
  2366. {
  2367. // 对象操作
  2368. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2369. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2370. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2371. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2372. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2373. if (dStruct.PageSize != 100000)
  2374. {
  2375. if (dr["DispatchSort"].ToString() == "2")
  2376. {
  2377. dr["gongchuang"] = 200;
  2378. }
  2379. else if ("外协".Equals(dr["ToType"].ToString()))
  2380. {
  2381. dr["gongchuang"] = 200;
  2382. }
  2383. else if ("内部".Equals(dr["ToType"].ToString()))
  2384. {
  2385. dr["gongchuang"] = -1;
  2386. }
  2387. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2388. {
  2389. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2390. dr["gongchuang"] = response.code;
  2391. }
  2392. }
  2393. }
  2394. catch (NullReferenceException ex)
  2395. {
  2396. }
  2397. }
  2398. }
  2399. writeGridDataTableJson(dStruct.TotalCount, dt);
  2400. }
  2401. public void get_erp_myreturnorderlist()
  2402. {
  2403. DataStruct dStruct = GetPostStruct();
  2404. List<string> lw = new List<string>();
  2405. string tid = GetPostString("ctid");
  2406. if (tid.Length > 0)
  2407. {
  2408. string select_tid = getTidByCtid(tid);
  2409. lw.Add(string.Format("tid='{0}'", select_tid));
  2410. }
  2411. else
  2412. {
  2413. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2414. }
  2415. string shopname = GetPostString("shopname");
  2416. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2417. string buyernick = GetPostString("buyer_nick");
  2418. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2419. string design = GetPostString("design");
  2420. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2421. string orderState = GetPostString("orderState");
  2422. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2423. string sellermemo = GetPostString("seller_memo");
  2424. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2425. string date1 = GetPostString("date1");
  2426. string date2 = GetPostString("date2");
  2427. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2428. if (dw.Length > 0) lw.Add(dw);
  2429. string price1 = GetPostString("price1");
  2430. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2431. string price2 = GetPostString("price2");
  2432. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2433. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2434. {
  2435. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2436. }
  2437. else
  2438. {
  2439. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2440. }
  2441. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2442. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2443. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2444. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2445. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2446. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2447. if (dt != null && dt.Rows.Count > 0)
  2448. {
  2449. foreach (DataRow dr in dt.Rows)
  2450. {
  2451. try
  2452. {
  2453. // 对象操作
  2454. if (dStruct.PageSize != 100000)
  2455. {
  2456. if (dr["DispatchSort"].ToString() == "2")
  2457. {
  2458. dr["gongchuang"] = 200;
  2459. }
  2460. else if ("外协".Equals(dr["ToType"].ToString()))
  2461. {
  2462. dr["gongchuang"] = 200;
  2463. }
  2464. else if ("内部".Equals(dr["ToType"].ToString()))
  2465. {
  2466. dr["gongchuang"] = -1;
  2467. }
  2468. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2469. {
  2470. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2471. dr["gongchuang"] = response.code;
  2472. }
  2473. }
  2474. }
  2475. catch (NullReferenceException ex)
  2476. {
  2477. // 处理空引用异常
  2478. }
  2479. }
  2480. }
  2481. writeGridDataTableJson(dStruct.TotalCount, dt);
  2482. }
  2483. public void get_erp_myorderlist_pregather()
  2484. {
  2485. string date1 = GetPostString("date1");
  2486. string date2 = GetPostString("date2");
  2487. int userId = CurrentUser.UserID; //客服id
  2488. string orderWhere = "";
  2489. List<string> lw = new List<string>();
  2490. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2491. if (dw.Length > 0) lw.Add(dw);
  2492. lw.Add(string.Format("CustomerUserId={0}", userId));
  2493. lw.Add(string.Format("OrderState<9"));
  2494. orderWhere = string.Join(" and ", lw.ToArray());
  2495. string orderWhere2 = "";
  2496. List<string> lw2 = new List<string>();
  2497. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2498. if (dw2.Length > 0) lw2.Add(dw2);
  2499. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2500. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2501. string sql = string.Format("select *" +
  2502. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2503. "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 " +
  2504. "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 " +
  2505. "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");
  2506. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2507. //writeGridDataTableJson(dt.Rows.Count, dt);
  2508. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2509. }
  2510. public void upd_erp_publishorder()
  2511. {
  2512. if (UrlPostParmsCheck("ctid"))
  2513. {
  2514. string eid = GetPostString("ctid");
  2515. CeErpTradeCell entity = null;
  2516. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2517. if (entity != null)
  2518. {
  2519. entity.OrderState = 0; //发布后,变为待抢单
  2520. entity.Update();
  2521. commonHelper.UpdateRelationOrder(entity.ctid);
  2522. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2523. returnSuccessMsg("发布成功!");
  2524. return;
  2525. }
  2526. returnErrorMsg("找不到记录");
  2527. }
  2528. }
  2529. public void get_erp_my_tiporder()
  2530. {
  2531. StringBuilder sql = new StringBuilder();
  2532. int userId = 0;
  2533. if (CurrentUser != null) userId = CurrentUser.UserID;
  2534. string posCode = CurrentUser.UserPost.Post.Code;
  2535. string isTipedAfterSaleVerify = GetPostString("af");
  2536. DataTable dt = new DataTable();
  2537. if (posCode != "Supplier")
  2538. {
  2539. if (posCode == "CustomerService" || posCode == "Director")
  2540. {
  2541. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2542. }
  2543. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2544. {
  2545. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2546. }
  2547. else
  2548. {
  2549. string teamIds = CurrentUser.User.TeamIds;
  2550. if (teamIds == "")
  2551. {
  2552. teamIds = "0";
  2553. }
  2554. 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);
  2555. }
  2556. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2557. }
  2558. if (dt.Rows.Count <= 0)
  2559. {
  2560. string key = "aftersale_order_" + userId;
  2561. if (RedisHelper.HasKey(key))
  2562. {
  2563. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2564. dt.Columns.Add("ctid", typeof(string));
  2565. dt.Columns.Add("IsReadTag", typeof(int));
  2566. foreach (var i in list)
  2567. {
  2568. DataRow data = dt.NewRow();
  2569. data["ctid"] = i;
  2570. data["IsReadTag"] = 4;
  2571. dt.Rows.Add(data);
  2572. }
  2573. RedisHelper.StringDelete(key);
  2574. }
  2575. }
  2576. if (dt.Rows.Count <= 0)
  2577. {
  2578. sql = new StringBuilder();
  2579. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2580. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2581. }
  2582. if (posCode == "Supplier")
  2583. {
  2584. string ids = CurrentUser.User.pemVend;
  2585. if (ids != null && ids.Length > 0)
  2586. {
  2587. string[] ids_list = ids.Split(',');
  2588. foreach (var item in ids_list)
  2589. {
  2590. string key = "return_order_" + item;
  2591. if (RedisHelper.HasKey(key))
  2592. {
  2593. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2594. dt.Columns.Add("ctid", typeof(string));
  2595. dt.Columns.Add("IsReadTag", typeof(int));
  2596. foreach (var i in list)
  2597. {
  2598. DataRow data = dt.NewRow();
  2599. data["ctid"] = i;
  2600. data["IsReadTag"] = 1;
  2601. dt.Rows.Add(data);
  2602. }
  2603. RedisHelper.StringDelete(key);
  2604. }
  2605. }
  2606. }
  2607. if (dt.Rows.Count <= 0)
  2608. {
  2609. sql = new StringBuilder();
  2610. 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);
  2611. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2612. }
  2613. }
  2614. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2615. }
  2616. public void reset_erp_tiporder()
  2617. {
  2618. string ids = GetPostString("ids");
  2619. string[] ctidList = ids.Split(',');
  2620. foreach (string ctid in ctidList)
  2621. {
  2622. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2623. if (enty != null)
  2624. {
  2625. enty.IsReadTag = 0;
  2626. enty.Update();
  2627. }
  2628. }
  2629. returnSuccessMsg("成功!");
  2630. return;
  2631. }
  2632. public void get_erp_designlist()
  2633. {
  2634. DataStruct dStruct = GetPostStruct();
  2635. List<string> lw = new List<string>();
  2636. string tid = GetPostString("ctid");
  2637. if (tid.Length > 0)
  2638. {
  2639. string select_tid = getTidByCtid(tid);
  2640. lw.Add(string.Format("tid='{0}'", select_tid));
  2641. }
  2642. string shopname = GetPostString("shopname");
  2643. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2644. string buyernick = GetPostString("buyer_nick");
  2645. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2646. string customer = GetPostString("customer");
  2647. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2648. string design = GetPostString("design");
  2649. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2650. string orderState = GetPostString("orderState");
  2651. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2652. lw.Add(string.Format("OrderState<6"));
  2653. string address = GetPostString("address");
  2654. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2655. string sellermemo = GetPostString("seller_memo");
  2656. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2657. string date1 = GetPostString("date1");
  2658. string date2 = GetPostString("date2");
  2659. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2660. if (dw.Length > 0) lw.Add(dw);
  2661. string apdate1 = GetPostString("apdate1");
  2662. string apdate2 = GetPostString("apdate2");
  2663. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2664. if (dwap.Length > 0) lw.Add(dwap);
  2665. string price1 = GetPostString("price1");
  2666. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2667. string price2 = GetPostString("price2");
  2668. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2669. string designTime = GetPostString("designtime");
  2670. if (designTime.Length > 0)
  2671. {
  2672. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2673. }
  2674. string usershop = CurrentUser.User.pemShop;
  2675. if (usershop.Length > 0)
  2676. {
  2677. lw.Add(string.Format("shopId in ({0})", usershop));
  2678. }
  2679. int myOrgid = CurrentUser.UserPost.OrgID;
  2680. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2681. if (myOrgCode.IndexOf("Designer") != -1)
  2682. {
  2683. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2684. {
  2685. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2686. }
  2687. else
  2688. {
  2689. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2690. }
  2691. }
  2692. else
  2693. {
  2694. string orgId = GetPostString("designerhd");
  2695. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2696. }
  2697. if (tid.Length > 0 || buyernick.Length > 0)
  2698. {
  2699. lw.Add(string.Format("OrderState >= 3"));
  2700. }
  2701. else
  2702. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2703. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2704. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2705. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2706. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2707. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2708. if (dt != null && dt.Rows.Count > 0)
  2709. {
  2710. foreach (DataRow dr in dt.Rows)
  2711. {
  2712. try
  2713. {
  2714. // 对象操作
  2715. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2716. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2717. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2718. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2719. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2720. if (dStruct.PageSize != 100000)
  2721. {
  2722. if (dr["DispatchSort"].ToString() == "2")
  2723. {
  2724. dr["gongchuang"] = 200;
  2725. }
  2726. else if ("外协".Equals(dr["ToType"].ToString()))
  2727. {
  2728. dr["gongchuang"] = 200;
  2729. }
  2730. else if ("内部".Equals(dr["ToType"].ToString()))
  2731. {
  2732. dr["gongchuang"] = -1;
  2733. }
  2734. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2735. {
  2736. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2737. dr["gongchuang"] = response.code;
  2738. }
  2739. }
  2740. }
  2741. catch (NullReferenceException ex)
  2742. {
  2743. }
  2744. }
  2745. }
  2746. writeGridDataTableJson(dStruct.TotalCount, dt);
  2747. }
  2748. public void get_erp_mydesignlist()
  2749. {
  2750. DataStruct dStruct = GetPostStruct();
  2751. List<string> lw = new List<string>();
  2752. string tid = GetPostString("ctid");
  2753. if (tid.Length > 0)
  2754. {
  2755. string select_tid = getTidByCtid(tid);
  2756. lw.Add(string.Format("tid='{0}'", select_tid));
  2757. }
  2758. string shopname = GetPostString("shopname");
  2759. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2760. string buyernick = GetPostString("buyer_nick");
  2761. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2762. string customer = GetPostString("customer");
  2763. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2764. string orderState = GetPostString("orderState");
  2765. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2766. //lw.Add(string.Format("OrderState<6"));
  2767. string date1 = GetPostString("date1");
  2768. string date2 = GetPostString("date2");
  2769. string dw = GetDateWhere("pay_time", date1, date2);
  2770. if (dw.Length > 0) lw.Add(dw);
  2771. string apdate1 = GetPostString("apdate1");
  2772. string apdate2 = GetPostString("apdate2");
  2773. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2774. if (dwap.Length > 0) lw.Add(dwap);
  2775. string price1 = GetPostString("price1");
  2776. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2777. string price2 = GetPostString("price2");
  2778. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2779. string olddownload = GetPostString("olddown");
  2780. if (olddownload == "1")
  2781. {
  2782. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2783. }
  2784. else if (olddownload == "2")
  2785. {
  2786. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2787. }
  2788. string sellermemo = GetPostString("seller_memo");
  2789. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2790. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2791. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2792. {
  2793. if (CurrentUser.User.TeamIds.Length > 0)
  2794. {
  2795. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2796. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2797. else
  2798. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2799. }
  2800. else
  2801. {
  2802. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2803. }
  2804. }
  2805. if (tid.Length <= 0)
  2806. {
  2807. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2808. }
  2809. lw.Add(string.Format("IsReturn!=3"));
  2810. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2811. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2812. string teamids = CurrentUser.User.TeamIds.ToString();
  2813. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2814. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2815. if (dt != null && dt.Rows.Count > 0)
  2816. {
  2817. foreach (DataRow dr in dt.Rows)
  2818. {
  2819. try
  2820. {
  2821. // 对象操作
  2822. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2823. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2824. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2825. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2826. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2827. if (dStruct.PageSize != 100000)
  2828. {
  2829. if (dr["DispatchSort"].ToString() == "2")
  2830. {
  2831. dr["gongchuang"] = 200;
  2832. }
  2833. else if ("外协".Equals(dr["ToType"].ToString()))
  2834. {
  2835. dr["gongchuang"] = 200;
  2836. }
  2837. else if ("内部".Equals(dr["ToType"].ToString()))
  2838. {
  2839. dr["gongchuang"] = -1;
  2840. }
  2841. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2842. {
  2843. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2844. dr["gongchuang"] = response.code;
  2845. }
  2846. }
  2847. }
  2848. catch (NullReferenceException ex)
  2849. {
  2850. }
  2851. }
  2852. }
  2853. writeGridDataTableJson(dStruct.TotalCount, dt);
  2854. }
  2855. public void set_erp_startdesign()
  2856. {
  2857. if (UrlPostParmsCheck("ctid"))
  2858. {
  2859. string eid = GetPostString("ctid");
  2860. CeErpTradeCell entity = null;
  2861. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2862. if (entity != null)
  2863. {
  2864. if (entity.OrderState != 3)
  2865. {
  2866. returnErrorMsg("请刷新,订单已经设计了");
  2867. return;
  2868. }
  2869. entity.StartDesignTime = DateTime.Now;
  2870. entity.OrderState = 4;
  2871. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2872. {
  2873. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2874. entity.SupplierId = suid;
  2875. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2876. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2877. }
  2878. entity.UpdateTime = DateTime.Now;
  2879. //entity.MakeSupplier = suname;
  2880. entity.Update();
  2881. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2882. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2883. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2884. commonHelper.getCytPrice(entity);
  2885. returnSuccessMsg("操作成功!");
  2886. return;
  2887. }
  2888. returnErrorMsg("找不到记录");
  2889. }
  2890. }
  2891. public void ins_erp_designselfmemo()
  2892. {
  2893. if (UrlPostParmsCheck("ctid"))
  2894. {
  2895. string eid = GetPostString("ctid");
  2896. string con = GetPostString("con");
  2897. CeErpTradeCell entity = null;
  2898. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2899. if (entity != null)
  2900. {
  2901. entity.DesignSelfMemo = con;
  2902. entity.Update();
  2903. returnSuccessMsg("操作成功!");
  2904. return;
  2905. }
  2906. returnErrorMsg("找不到记录");
  2907. }
  2908. }
  2909. public void ins_erp_designprice()
  2910. {
  2911. if (UrlPostParmsCheck("ctid"))
  2912. {
  2913. string eid = GetPostString("ctid");
  2914. int uid = CurrentUser.UserID;
  2915. string userName = CurrentUser.UserName;
  2916. CeErpTradeCell entity = null;
  2917. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2918. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2919. if (entitys == null)
  2920. {
  2921. entitys = new CeErpDesignerBill();
  2922. }
  2923. if (entity != null)
  2924. {
  2925. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2926. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2927. entity.StartDesignTime = DateTime.Now;
  2928. entity.OrderState = 4;
  2929. string suname = "";
  2930. if (entity.SupplierId == 0)
  2931. {
  2932. int sid = commonHelper.autoDistributeToSupplier(entity);
  2933. entity.SupplierId = sid;
  2934. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2935. }
  2936. entity.Update();
  2937. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2938. if (ceErpUserPost != null)
  2939. {
  2940. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2941. if (ceErpPost != null)
  2942. {
  2943. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2944. {
  2945. entitys.tid = entity.ctid;
  2946. entitys.oid = entity.tid;
  2947. entitys.uid = uid;
  2948. entitys.userName = userName;
  2949. entitys.designerType = 1;
  2950. entitys.designerTypeText = "内部设计师";
  2951. entitys.price = Convert.ToDouble(GetPostString("price"));
  2952. entitys.designNum = GetPostInt("designNum");
  2953. entitys.modifyNum = GetPostInt("modifyNum");
  2954. entitys.designSize = GetPostString("designSize");
  2955. entitys.modifySize = GetPostString("modifySize");
  2956. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2957. {
  2958. entitys.create_time = DateTime.Now;
  2959. entitys.create_u_id = uid;
  2960. entitys.create_u_name = userName;
  2961. entitys.Save();
  2962. }
  2963. else
  2964. {
  2965. entitys.update_time = DateTime.Now;
  2966. entitys.update_u_id = uid;
  2967. entitys.update_u_name = userName;
  2968. entitys.Update();
  2969. }
  2970. }
  2971. }
  2972. }
  2973. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2974. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2975. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2976. if (suname != "")
  2977. {
  2978. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2979. }
  2980. commonHelper.getCytPrice(entity);
  2981. returnSuccessMsg("操作成功!");
  2982. return;
  2983. }
  2984. returnErrorMsg("找不到记录");
  2985. }
  2986. }
  2987. public void upload_erp_filecomplete()
  2988. {
  2989. if (UrlPostParmsCheck("ctid"))
  2990. {
  2991. string eid = GetPostString("ctid");
  2992. CeErpTradeCell entity = null;
  2993. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2994. if (entity != null)
  2995. {
  2996. entity.OrderState = 5; //设计完成
  2997. entity.Update();
  2998. returnSuccessMsg(eid + "上传成功,设计完成!");
  2999. return;
  3000. }
  3001. returnErrorMsg("找不到订单记录");
  3002. }
  3003. }
  3004. public void get_erp_designovertimelist()
  3005. {
  3006. DataStruct dStruct = GetPostStruct();
  3007. List<string> lw = new List<string>();
  3008. string tid = GetPostString("ctid");
  3009. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3010. string shopname = GetPostString("shopname");
  3011. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3012. string buyernick = GetPostString("buyer_nick");
  3013. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3014. string ResponsibleMan = GetPostString("responsible");
  3015. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3016. string date1 = GetPostString("date1");
  3017. string date2 = GetPostString("date2");
  3018. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3019. if (dw.Length > 0) lw.Add(dw);
  3020. string price1 = GetPostString("price1");
  3021. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3022. string price2 = GetPostString("price2");
  3023. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3024. string orderState = GetPostString("orderState");
  3025. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3026. string sellermemo = GetPostString("seller_memo");
  3027. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3028. lw.Add(string.Format("UnusualTag=3"));
  3029. lw.Add(string.Format("IsRefund<={0}", 1));
  3030. dStruct.Order = "WaitDesignTime desc";
  3031. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3032. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3033. writeGridDataTableJson(dStruct.TotalCount, dt);
  3034. }
  3035. //设计管理 获取抢单大厅列表
  3036. public void get_erp_grabinglist()
  3037. {
  3038. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3039. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3040. bool oldOrder = false;
  3041. if (org != null)
  3042. {
  3043. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3044. }
  3045. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3046. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3047. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3048. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3049. //先处理订单数据
  3050. if (dt.Rows.Count > 0)
  3051. {
  3052. Dictionary<string, int> design = null;
  3053. int count = 0;
  3054. foreach (DataRow row in dt.Rows)
  3055. {
  3056. if (map.ContainsKey(row["ShopId"].ToString()))
  3057. {
  3058. map.TryGetValue(row["ShopId"].ToString(), out design);
  3059. }
  3060. else
  3061. {
  3062. design = new Dictionary<string, int>();
  3063. }
  3064. if (design.ContainsKey(row["ProductId"].ToString()))
  3065. {
  3066. design.TryGetValue(row["ProductId"].ToString(), out count);
  3067. }
  3068. count++;
  3069. design[row["ProductId"].ToString()] = count;
  3070. map[row["ShopId"].ToString()] = design;
  3071. }
  3072. }
  3073. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3074. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3075. //把店铺排序和技能排序分类
  3076. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3077. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3078. if (design_dt.Rows.Count > 0)
  3079. {
  3080. Dictionary<string, string> design = null;
  3081. List<string> shopIds = null;
  3082. foreach (DataRow row in design_dt.Rows)
  3083. {
  3084. if ("0".Equals(row["designId"].ToString()))
  3085. {
  3086. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3087. {
  3088. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3089. }
  3090. else
  3091. {
  3092. shopIds = new List<string>();
  3093. }
  3094. shopIds.Add(row["shopId"].ToString());
  3095. shop_orders[row["orders"].ToString()] = shopIds;
  3096. }
  3097. else
  3098. {
  3099. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3100. {
  3101. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3102. }
  3103. else
  3104. {
  3105. design = new Dictionary<string, string>();
  3106. }
  3107. design[row["orders"].ToString()] = row["designId"].ToString();
  3108. design_orders[row["shopId"].ToString()] = design;
  3109. }
  3110. }
  3111. //处理成key value后根据key排序
  3112. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3113. foreach (List<string> val in shop_orders.Values)
  3114. {
  3115. if (val != null)
  3116. {
  3117. foreach (string key in val)
  3118. {
  3119. if (design_orders.ContainsKey(key.ToString()))
  3120. {
  3121. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3122. }
  3123. }
  3124. }
  3125. }
  3126. }
  3127. //校验哪个优先级有订单
  3128. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3129. foreach (string key in shop_orders.Keys)
  3130. {
  3131. List<string> ids = null;
  3132. shop_orders.TryGetValue(key, out ids);
  3133. //id为shopid
  3134. foreach (string id in ids)
  3135. {
  3136. Dictionary<string, int> list = null;
  3137. Dictionary<string, string> desing = null;
  3138. map.TryGetValue(id, out list);
  3139. design_orders.TryGetValue(id, out desing);
  3140. if (list != null && desing != null)
  3141. {
  3142. foreach (var item in desing)
  3143. {
  3144. int count = 0;
  3145. if (list.ContainsKey(item.Value))
  3146. {
  3147. list.TryGetValue(item.Value, out count);
  3148. if (count > 0)
  3149. {
  3150. designIds[id] = item.Value;
  3151. break;
  3152. }
  3153. }
  3154. }
  3155. }
  3156. }
  3157. if (designIds.Count > 0)
  3158. {
  3159. break;
  3160. }
  3161. }
  3162. DataTable table = new DataTable();
  3163. table.Columns.Add("tid", typeof(string));
  3164. table.Columns.Add("ctid", typeof(string));
  3165. table.Columns.Add("seller_nick", typeof(string));
  3166. table.Columns.Add("productName", typeof(string));
  3167. table.Columns.Add("pay_time", typeof(string));
  3168. table.Columns.Add("seller_memo", typeof(string));
  3169. if (designIds.Count > 0)
  3170. {
  3171. string shopId = "";
  3172. string productId = "";
  3173. foreach (var designInfo in designIds)
  3174. {
  3175. shopId = designInfo.Key;
  3176. productId = designInfo.Value;
  3177. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3178. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3179. if (dt.Rows.Count > 0)
  3180. {
  3181. foreach (DataRow row in dt.Rows)
  3182. {
  3183. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3184. {
  3185. DataRow data = table.NewRow();
  3186. data["ctid"] = row["ctid"].ToString();
  3187. data["tid"] = row["tid"].ToString();
  3188. data["seller_nick"] = ceErpShop.ShopName;
  3189. data["pay_time"] = row["pay_time"].ToString();
  3190. data["seller_memo"] = row["seller_memo"].ToString();
  3191. data["productName"] = ceErpProduct.PType;
  3192. table.Rows.Add(data);
  3193. }
  3194. }
  3195. }
  3196. }
  3197. }
  3198. writeGridDataTableJson(table.Rows.Count, table);
  3199. }
  3200. private object rushLockObject = new object();
  3201. public void set_erp_grabingorder()
  3202. {
  3203. if (UrlPostParmsCheck("ctid"))
  3204. {
  3205. int total = CurrentUser.User.Person.Total;
  3206. int userId = CurrentUser.User.ID;
  3207. int noFinish = CurrentUser.User.Person.NoFinish;
  3208. int finalization = CurrentUser.User.Person.Finalization;
  3209. string eids = GetPostString("ctid");
  3210. string key = "RushKey_" + userId;
  3211. int count = 0;
  3212. if (erpRedis.RedisHelper.KeyExists(key))
  3213. {
  3214. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3215. if (redisCount != null)
  3216. {
  3217. count = Convert.ToInt32(redisCount);
  3218. }
  3219. }
  3220. if (count >= total)
  3221. {
  3222. returnErrorMsg("半小时内已经抢" + total + "单");
  3223. return;
  3224. }
  3225. string[] ctidlist = eids.Split(',');
  3226. if (count + ctidlist.Length > total)
  3227. {
  3228. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3229. return;
  3230. }
  3231. int itag = 0;
  3232. lock (rushLockObject)
  3233. {
  3234. if (ctidlist.Length > 0)
  3235. {
  3236. string[] dtList = new string[ctidlist.Length];
  3237. for (int i = 0; i < ctidlist.Length; i++)
  3238. {
  3239. dtList[i] = "'" + ctidlist[i] + "'";
  3240. }
  3241. 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"));
  3242. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3243. if (dt_user.Rows.Count > 0)
  3244. {
  3245. int doing = 0;//未定稿
  3246. int finish = 0;//已完成
  3247. foreach (DataRow dr in dt_user.Rows)
  3248. {
  3249. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3250. {
  3251. doing++;
  3252. }
  3253. else
  3254. {
  3255. finish++;
  3256. }
  3257. }
  3258. if (doing >= noFinish)
  3259. {
  3260. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3261. return;
  3262. }
  3263. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3264. {
  3265. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3266. return;
  3267. }
  3268. }
  3269. //校验选择单子状态
  3270. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3271. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3272. if (dt.Rows.Count > 0)
  3273. {
  3274. List<string> list = new List<string>();
  3275. foreach (DataRow dr in dt.Rows)
  3276. {
  3277. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3278. {
  3279. list.Add(dr["ctid"].ToString());
  3280. }
  3281. }
  3282. if (list.Count > 0)
  3283. {
  3284. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3285. return;
  3286. }
  3287. }
  3288. foreach (string ctid in ctidlist)
  3289. {
  3290. CeErpTradeCell entity = null;
  3291. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3292. if (entity != null)
  3293. {
  3294. entity.OrderState = 3;
  3295. entity.DesignUserId = CurrentUser.UserID;
  3296. entity.WaitDesignTime = DateTime.Now;
  3297. entity.StartDesignTime = DateTime.Now;
  3298. entity.Update();
  3299. commonHelper.UpdateRelationOrder(entity.ctid);
  3300. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3301. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3302. itag++;
  3303. }
  3304. }
  3305. }
  3306. }
  3307. count += ctidlist.Length;
  3308. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3309. if (itag == 0)
  3310. returnErrorMsg("没有找到相关订单");
  3311. else
  3312. returnSuccessMsg("抢单成功!");
  3313. return;
  3314. }
  3315. }
  3316. public void get_erp_waitorderlist()
  3317. {
  3318. DataStruct dStruct = GetPostStruct();
  3319. List<string> lw = new List<string>();
  3320. string tid = GetPostString("ctid");
  3321. if (tid.Length > 0)
  3322. {
  3323. string select_tid = getTidByCtid(tid);
  3324. lw.Add(string.Format("tid='{0}'", select_tid));
  3325. }
  3326. string shopname = GetPostString("shopname");
  3327. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3328. string buyernick = GetPostString("buyer_nick");
  3329. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3330. string customer = GetPostString("customer");
  3331. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3332. string design = GetPostString("design");
  3333. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3334. string orderState = GetPostString("orderState");
  3335. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3336. string supplier = GetPostString("supplier");
  3337. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3338. string sellermemo = GetPostString("seller_memo");
  3339. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3340. string otherMemo = GetPostString("otherMemo");
  3341. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3342. string address = GetPostString("address");
  3343. 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));
  3344. string date1 = GetPostString("date1");
  3345. string date2 = GetPostString("date2");
  3346. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3347. if (dw.Length > 0) lw.Add(dw);
  3348. string price1 = GetPostString("price1");
  3349. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3350. string price2 = GetPostString("price2");
  3351. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3352. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3353. lw.Add(string.Format("IsSample != 2 "));
  3354. lw.Add(string.Format("OrderState = 5 "));
  3355. lw.Add(string.Format("IsRefund<={0}", 1));
  3356. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3357. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3358. string pagesize = GetPostString("pagesize");
  3359. if (pagesize != null)
  3360. {
  3361. dStruct.PageSize = 200;
  3362. }
  3363. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3364. if (dt != null)
  3365. {
  3366. foreach (DataRow dr in dt.Rows)
  3367. {
  3368. 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();
  3369. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3370. {
  3371. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3372. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3373. entity.SupplierId = suid;
  3374. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3375. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3376. entity.Update();
  3377. }
  3378. }
  3379. }
  3380. writeGridDataTableJson(dStruct.TotalCount, dt);
  3381. }
  3382. public void get_erp_supplierwaitorderlist()
  3383. {
  3384. DataStruct dStruct = GetPostStruct();
  3385. List<string> lw = new List<string>();
  3386. string tid = GetPostString("ctid");
  3387. if (tid.Length > 0)
  3388. {
  3389. string select_tid = getTidByCtid(tid);
  3390. lw.Add(string.Format("tid='{0}'", select_tid));
  3391. }
  3392. string shopname = GetPostString("shopname");
  3393. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3394. string sellermemo = GetPostString("seller_memo");
  3395. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3396. string date1 = GetPostString("date1");
  3397. string date2 = GetPostString("date2");
  3398. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3399. if (dw.Length > 0) lw.Add(dw);
  3400. lw.Add(string.Format("OrderState = 5 "));
  3401. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3402. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3403. {
  3404. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3405. }
  3406. string supplier = GetPostString("supplier");
  3407. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3408. {
  3409. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3410. }
  3411. lw.Add(string.Format("IsRefund<={0}", 1));
  3412. dStruct.Order = "FinishDesignTime desc";
  3413. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3414. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3415. if (dt != null)
  3416. {
  3417. foreach (DataRow dr in dt.Rows)
  3418. {
  3419. 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();
  3420. }
  3421. }
  3422. writeGridDataTableJson(dStruct.TotalCount, dt);
  3423. }
  3424. public void upd_erp_verifytosupplier()
  3425. {
  3426. if (UrlPostParmsCheck("ctid"))
  3427. {
  3428. string eids = GetPostString("ctid");
  3429. CeErpTradeCell entity = null;
  3430. string[] eidsList = eids.Split(',');
  3431. if (eidsList.Length <= 0)
  3432. {
  3433. returnErrorMsg("订单号不能空");
  3434. return;
  3435. }
  3436. List<string> tLst = new List<string>();
  3437. foreach (string ctidstr in eidsList)
  3438. {
  3439. tLst.Add("'" + ctidstr + "'");
  3440. CeErpDataSendOrderInfo.createObject(ctidstr);
  3441. }
  3442. string needtids = string.Join(",", tLst.ToArray());
  3443. StringBuilder sql = new StringBuilder();
  3444. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3445. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3446. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3447. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3448. returnSuccessMsg("操作成功!");
  3449. return;
  3450. /**foreach (string ctidstr in eidsList)
  3451. {
  3452. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3453. if (entity != null)
  3454. {
  3455. if (entity.SupplierId == 0)
  3456. {
  3457. continue;
  3458. }
  3459. entity.IsVerifyToSupplier = true;
  3460. if (entity.IsReturn == 1) //1是供应商打回
  3461. {
  3462. entity.IsReturn = 0;
  3463. }
  3464. entity.FinishPlaceTime = DateTime.Now;
  3465. entity.PlaceUserId = CurrentUser.UserID;
  3466. entity.Update();
  3467. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3468. }
  3469. }
  3470. returnSuccessMsg("操作成功!");
  3471. return;**/
  3472. }
  3473. }
  3474. public void upd_erp_supplierback()
  3475. {
  3476. if (UrlPostParmsCheck("ctid"))
  3477. {
  3478. string eid = GetPostString("ctid");
  3479. string reason = GetPostString("returnreason");
  3480. CeErpTradeCell entity = null;
  3481. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3482. if (entity != null)
  3483. {
  3484. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3485. {
  3486. string key = "return_order_" + entity.SupplierId;
  3487. List<string> list = new List<string>();
  3488. if (RedisHelper.HasKey(key))
  3489. {
  3490. object data = RedisHelper.StringGet(key);
  3491. list = Convert.ToString(data).Split(',').ToList();
  3492. }
  3493. list.Add(eid);
  3494. RedisHelper.StringSet(key, string.Join(",", list));
  3495. }
  3496. entity.IsVerifyToSupplier = false;
  3497. entity.IsReturn = 1;
  3498. entity.ReturnTime = DateTime.Now;
  3499. entity.ReturnReason = reason;
  3500. if (entity.OrderState == 6)
  3501. {
  3502. entity.OrderState = 5;
  3503. }
  3504. entity.Update();
  3505. CeErpSukuraData.createInfo(entity.ctid, 5);
  3506. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3507. returnSuccessMsg("操作成功!");
  3508. return;
  3509. }
  3510. returnErrorMsg("找不到订单记录");
  3511. }
  3512. }
  3513. public void upd_erp_toaftersaleorder()
  3514. {
  3515. if (UrlPostParmsCheck("ctid"))
  3516. {
  3517. string eid = GetPostString("ctid");
  3518. string reason = GetPostString("returnreason");
  3519. CeErpTradeCell entity = null;
  3520. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3521. if (entity != null)
  3522. {
  3523. if (entity.isAfterSaleOrder != 1)
  3524. {
  3525. returnErrorMsg("带S的售后单才能打回给售后");
  3526. return;
  3527. }
  3528. if (entity.OrderState >= 5)
  3529. {
  3530. returnErrorMsg("已经设计完成了不能打回给售后");
  3531. return;
  3532. }
  3533. entity.OrderState = 0;
  3534. entity.IsReturn = 3;
  3535. entity.ReturnTime = DateTime.Now;
  3536. entity.UpdateTime = DateTime.Now;
  3537. entity.ReturnReason = reason;
  3538. entity.Update();
  3539. CeErpSukuraData.createInfo(entity.ctid, 5);
  3540. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3541. returnSuccessMsg("操作成功!");
  3542. return;
  3543. }
  3544. returnErrorMsg("找不到订单记录");
  3545. }
  3546. }
  3547. public void upd_erp_aftersaletodesign()
  3548. {
  3549. if (UrlPostParmsCheck("ctid"))
  3550. {
  3551. string eid = GetPostString("ctid");
  3552. CeErpTradeCell entity = null;
  3553. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3554. if (entity != null)
  3555. {
  3556. entity.OrderState = 3;
  3557. entity.IsReturn = 0;
  3558. entity.UpdateTime = DateTime.Now;
  3559. entity.Update();
  3560. CeErpSukuraData.createInfo(entity.ctid, 5);
  3561. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3562. returnSuccessMsg("操作成功!");
  3563. return;
  3564. }
  3565. returnErrorMsg("找不到订单记录");
  3566. }
  3567. }
  3568. public void assign_erp_supplier()
  3569. {
  3570. if (UrlPostParmsCheck("ctid"))
  3571. {
  3572. string eids = GetPostString("ctid");
  3573. int sid = GetPostInt("SupplierName");
  3574. string fromTag = GetPostString("tag");
  3575. string[] eidList = eids.Split(',');
  3576. if (eidList.Length <= 0)
  3577. {
  3578. returnErrorMsg("指派不能为空");
  3579. return;
  3580. }
  3581. string errMsg = "";
  3582. string suname = commonHelper.getSupplierNameById(sid);
  3583. foreach (string ctid in eidList)
  3584. {
  3585. CeErpTradeCell entity = null;
  3586. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3587. if (entity != null)
  3588. {
  3589. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3590. {
  3591. errMsg += (ctid + "指派失败!!!");
  3592. continue;
  3593. }
  3594. entity.SupplierId = sid;
  3595. entity.Update();
  3596. commonHelper.UpdateRelationOrder(entity.ctid);
  3597. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3598. if (entity.OrderState >= 6)
  3599. {
  3600. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3601. //{
  3602. // string msl = entity.MakeSupplier;
  3603. // string[] mslist = msl.Split(',');
  3604. // 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);
  3605. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3606. //}
  3607. //else
  3608. //{
  3609. StringBuilder sql = new StringBuilder();
  3610. 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);
  3611. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3612. //}
  3613. }
  3614. }
  3615. else
  3616. {
  3617. continue;
  3618. }
  3619. }
  3620. if (errMsg.Length > 0)
  3621. {
  3622. returnErrorMsg(errMsg);
  3623. return;
  3624. }
  3625. returnSuccessMsg("操作成功!");
  3626. return;
  3627. }
  3628. }
  3629. public void assign_erp_makesupplier()
  3630. {
  3631. if (UrlPostParmsCheck("ctid"))
  3632. {
  3633. string eids = GetPostString("ctid");
  3634. string sname = GetPostString("SupplierName");
  3635. string[] eidList = eids.Split(',');
  3636. if (eidList.Length <= 0)
  3637. {
  3638. returnErrorMsg("指派不能为空");
  3639. return;
  3640. }
  3641. List<string> tLst = new List<string>();
  3642. foreach (string ctid in eidList)
  3643. {
  3644. CeErpTradeCell entity = null;
  3645. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3646. if (entity != null)
  3647. {
  3648. entity.MakeSupplier = sname;
  3649. entity.Update();
  3650. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3651. tLst.Add("'" + ctid + "'");
  3652. }
  3653. else
  3654. {
  3655. continue;
  3656. }
  3657. }
  3658. string ctids = string.Join(",", tLst.ToArray());
  3659. StringBuilder sql2 = new StringBuilder();
  3660. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3661. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3662. returnSuccessMsg("操作成功!");
  3663. return;
  3664. }
  3665. }
  3666. public void ins_erp_returnreason()
  3667. {
  3668. if (UrlPostParmsCheck("ctid"))
  3669. {
  3670. string eid = GetPostString("ctid");
  3671. CeErpTradeCell entity = null;
  3672. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3673. string userpost = CurrentUser.UserPost.Post.Code;
  3674. if (entity != null)
  3675. {
  3676. bool isPlace = false;
  3677. if (entity.OrderState > 6)
  3678. {
  3679. returnErrorMsg("已发货无法打回!");
  3680. return;
  3681. }
  3682. if (entity.OrderState == 6)
  3683. {
  3684. isPlace = true;
  3685. }
  3686. bool isNeedUpdateCell2 = false;
  3687. if (entity.OrderState >= 6)
  3688. {
  3689. isNeedUpdateCell2 = true;
  3690. }
  3691. int returnTag = 2;
  3692. if (userpost == "Supplier")
  3693. {
  3694. returnTag = 1;
  3695. }
  3696. int toType = GetPostInt("totype");
  3697. string fromType = "3";
  3698. if (entity.OrderState < 5)
  3699. {
  3700. fromType = "3";
  3701. }
  3702. else
  3703. {
  3704. fromType = "4";
  3705. }
  3706. if (entity.IsXianHuo == 0)
  3707. {
  3708. if (returnTag == 2)
  3709. {
  3710. if (toType == 1)
  3711. {
  3712. entity.OrderState = 0;
  3713. entity.ReturnUserType = 1;
  3714. string clearman = GetPostString("clearman");
  3715. if (!string.IsNullOrEmpty(clearman))
  3716. {
  3717. entity.DesignUserId = 0;
  3718. }
  3719. }
  3720. else
  3721. {
  3722. entity.OrderState = 3;
  3723. entity.ReturnUserType = 2;
  3724. }
  3725. entity.IsReadTag = 1;
  3726. }
  3727. else if (returnTag == 1)
  3728. {
  3729. entity.OrderState = 5;
  3730. }
  3731. entity.IsVerifyToSupplier = false;
  3732. }
  3733. if (entity.IsXianHuo == 1)
  3734. {
  3735. entity.OrderState = 5;
  3736. }
  3737. entity.UnusualTag = 0;
  3738. entity.UnusualTime = null;
  3739. entity.UnusualCon = "";
  3740. entity.IsReturn = returnTag;
  3741. entity.ReturnTime = DateTime.Now;
  3742. entity.UpdateTime = DateTime.Now;
  3743. entity.ReturnReason = GetPostString("returnreason");
  3744. entity.Update();
  3745. if (entity.OrderState == 3)
  3746. {
  3747. ApiVo apiVo = new ApiVo();
  3748. apiVo.orderNumber = entity.ctid;
  3749. apiVo.actionName = "rebutDesign";
  3750. apiVo.orderRemarks = entity.ReturnReason;
  3751. designHelper.API_WorkCore(apiVo);//rebutDesign
  3752. }
  3753. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3754. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3755. {
  3756. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3757. }
  3758. CeErpSukuraData.createInfo(entity.ctid, 5);
  3759. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3760. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3761. if (isPlace)
  3762. {
  3763. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3764. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3765. if (dth != null && dth.Rows.Count > 0)
  3766. {
  3767. dataSendOrderBean dataSendOrderBean = null;
  3768. foreach (DataRow item in dth.Rows)
  3769. {
  3770. try
  3771. {
  3772. dataSendOrderBean = new dataSendOrderBean();
  3773. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3774. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3775. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3776. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3777. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3778. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3779. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3780. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3781. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3782. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3783. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3784. dataSendOrderBean.Radio1723534706288 = "打回";
  3785. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3786. if (result != null)
  3787. {
  3788. if ("0".Equals(result.errcode))
  3789. {
  3790. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3791. }
  3792. else
  3793. {
  3794. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3795. }
  3796. }
  3797. }
  3798. catch (Exception ex)
  3799. {
  3800. }
  3801. }
  3802. }
  3803. }
  3804. if (isNeedUpdateCell2)
  3805. {
  3806. if (entity.MakeSupplier.IndexOf(",") != -1)
  3807. {
  3808. StringBuilder sql2 = new StringBuilder();
  3809. 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);
  3810. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3811. }
  3812. else
  3813. {
  3814. StringBuilder sql2 = new StringBuilder();
  3815. 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);
  3816. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3817. }
  3818. }
  3819. returnSuccessMsg("操作成功!");
  3820. return;
  3821. }
  3822. returnErrorMsg("找不到订单记录");
  3823. }
  3824. }
  3825. public void cyt_erp_returnreason()
  3826. {
  3827. if (UrlPostParmsCheck("ctid"))
  3828. {
  3829. string eid = GetPostString("ctid");
  3830. CeErpTradeCell entity = null;
  3831. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3832. string userpost = CurrentUser.UserPost.Post.Code;
  3833. if (entity != null)
  3834. {
  3835. if (entity.OrderState > 6)
  3836. {
  3837. returnErrorMsg("已发货无法打回!");
  3838. return;
  3839. }
  3840. JObject jsonObject = new JObject
  3841. {
  3842. { "Userid", "77886" },
  3843. { "Pwd", "lt666888" },
  3844. { "LTOrderId",eid }
  3845. };
  3846. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3847. JObject jsonObjects = JObject.Parse(response);
  3848. string msg = (string)jsonObjects["msg"];
  3849. if (msg != "取消成功")
  3850. {
  3851. returnErrorMsg(msg);
  3852. return;
  3853. }
  3854. bool isNeedUpdateCell2 = false;
  3855. if (entity.OrderState >= 6)
  3856. {
  3857. isNeedUpdateCell2 = true;
  3858. }
  3859. int returnTag = 2;
  3860. if (userpost == "Supplier")
  3861. {
  3862. returnTag = 1;
  3863. }
  3864. if (entity.IsXianHuo == 0)
  3865. {
  3866. if (returnTag == 2)
  3867. {
  3868. int toType = GetPostInt("totype");
  3869. if (toType == 1)
  3870. {
  3871. entity.OrderState = 0;
  3872. entity.ReturnUserType = 1;
  3873. }
  3874. else
  3875. {
  3876. entity.OrderState = 4;
  3877. entity.ReturnUserType = 2;
  3878. }
  3879. entity.IsReadTag = 1;
  3880. }
  3881. else if (returnTag == 1)
  3882. {
  3883. entity.OrderState = 5;
  3884. }
  3885. entity.IsVerifyToSupplier = false;
  3886. }
  3887. entity.UnusualTag = 0;
  3888. entity.UnusualTime = null;
  3889. entity.UnusualCon = "";
  3890. entity.IsReturn = returnTag;
  3891. entity.ReturnTime = DateTime.Now;
  3892. entity.ReturnReason = GetPostString("returnreason");
  3893. entity.Update();
  3894. if (entity.OrderState == 4)
  3895. {
  3896. ApiVo apiVo = new ApiVo();
  3897. apiVo.orderNumber = entity.ctid;
  3898. apiVo.actionName = "rebutDesign";
  3899. apiVo.orderRemarks = entity.ReturnReason;
  3900. designHelper.API_WorkCore(apiVo);//rebutDesign
  3901. }
  3902. CeErpSukuraData.createInfo(entity.ctid, 5);
  3903. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3904. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3905. if (isNeedUpdateCell2)
  3906. {
  3907. if (entity.MakeSupplier.IndexOf(",") != -1)
  3908. {
  3909. StringBuilder sql2 = new StringBuilder();
  3910. 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);
  3911. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3912. }
  3913. else
  3914. {
  3915. StringBuilder sql2 = new StringBuilder();
  3916. 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);
  3917. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3918. }
  3919. }
  3920. returnSuccessMsg("操作成功!");
  3921. return;
  3922. }
  3923. returnErrorMsg("找不到订单记录");
  3924. }
  3925. }
  3926. public void upd_erp_xianhuoreturntag()
  3927. {
  3928. if (UrlPostParmsCheck("ctid"))
  3929. {
  3930. string eids = GetPostString("ctid");
  3931. string[] ctids = eids.Split(',');
  3932. foreach (string ctid in ctids)
  3933. {
  3934. CeErpTradeCell entity = null;
  3935. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3936. if (entity != null)
  3937. {
  3938. entity.IsReturn = 0;
  3939. entity.Update();
  3940. CeErpSukuraData.createInfo(entity.ctid, 5);
  3941. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3942. }
  3943. }
  3944. returnSuccessMsg("操作成功!");
  3945. return;
  3946. }
  3947. }
  3948. public void get_erp_waitdeliverylist()
  3949. {
  3950. DataStruct dStruct = GetPostStruct();
  3951. List<string> lw = new List<string>();
  3952. string tid = GetPostString("ctid");
  3953. if (tid.Length > 0)
  3954. {
  3955. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3956. if (tid.Length > 5)
  3957. {
  3958. List<string> tids = getTidByCtidLike(tid);
  3959. if (tids.Count > 0 && tids.Count < 10)
  3960. {
  3961. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3962. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  3963. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  3964. {
  3965. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  3966. }
  3967. }
  3968. }
  3969. lw.Add(tid_sql);
  3970. }
  3971. string shopname = GetPostString("shopname");
  3972. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3973. string buyernick = GetPostString("buyer_nick");
  3974. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3975. //if (tid.Length == 0 && buyernick.Length == 0)
  3976. //{
  3977. // lw.Add(string.Format("IsRefund<={0}", 1));
  3978. //}
  3979. string customer = GetPostString("customer");
  3980. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3981. string design = GetPostString("design");
  3982. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3983. string orderState = GetPostString("orderState");
  3984. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3985. string address = GetPostString("address");
  3986. 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));
  3987. string sellermemo = GetPostString("seller_memo");
  3988. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3989. string supplier = GetPostString("supplier");
  3990. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3991. string OrderArea = GetPostString("order_area");
  3992. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3993. string placedate1 = GetPostString("placedate1");
  3994. string placedate2 = GetPostString("placedate2");
  3995. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3996. if (fdw.Length > 0) lw.Add(fdw);
  3997. string price1 = GetPostString("price1");
  3998. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3999. string price2 = GetPostString("price2");
  4000. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4001. string unusualCon = GetPostString("unusualcon");
  4002. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4003. string otherMemo = GetPostString("otherMemo");
  4004. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4005. string posTag = CurrentUser.UserPost.Post.Code;
  4006. if (posTag == "Supplier")
  4007. {
  4008. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4009. }
  4010. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4011. lw.Add(string.Format("type != 'PDD' "));
  4012. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4013. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4014. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4015. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4016. writeGridDataTableJson(dStruct.TotalCount, dt);
  4017. }
  4018. public void get_erp_changedeliverylist()
  4019. {
  4020. DataStruct dStruct = GetPostStruct();
  4021. List<string> lw = new List<string>();
  4022. string tid = GetPostString("ctid");
  4023. if (tid.Length > 0)
  4024. {
  4025. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4026. if (tid.Length > 5)
  4027. {
  4028. List<string> tids = getTidByCtidLike(tid);
  4029. if (tids.Count > 0 && tids.Count < 10)
  4030. {
  4031. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4032. }
  4033. }
  4034. lw.Add(tid_sql);
  4035. }
  4036. string shopname = GetPostString("shopname");
  4037. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4038. string buyernick = GetPostString("buyer_nick");
  4039. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4040. //if (tid.Length == 0 && buyernick.Length == 0)
  4041. //{
  4042. // lw.Add(string.Format("IsRefund<={0}", 1));
  4043. //}
  4044. string customer = GetPostString("customer");
  4045. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4046. string design = GetPostString("design");
  4047. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4048. string orderState = GetPostString("orderState");
  4049. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4050. string address = GetPostString("address");
  4051. 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));
  4052. string sellermemo = GetPostString("seller_memo");
  4053. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4054. string supplier = GetPostString("supplier");
  4055. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4056. string OrderArea = GetPostString("order_area");
  4057. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4058. string placedate1 = GetPostString("placedate1");
  4059. string placedate2 = GetPostString("placedate2");
  4060. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4061. if (fdw.Length > 0) lw.Add(fdw);
  4062. string price1 = GetPostString("price1");
  4063. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4064. string price2 = GetPostString("price2");
  4065. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4066. string unusualCon = GetPostString("unusualcon");
  4067. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4068. string otherMemo = GetPostString("otherMemo");
  4069. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4070. string posTag = CurrentUser.UserPost.Post.Code;
  4071. if (posTag == "Supplier")
  4072. {
  4073. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4074. }
  4075. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4076. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4077. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4078. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4079. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4080. /*if (tid.Length > 0)
  4081. {
  4082. List<string> tids = new List<string>();
  4083. if (dt != null && dt.Rows.Count > 0)
  4084. {
  4085. foreach (DataRow item in dt.Rows)
  4086. {
  4087. tids.Add("'" + item["tid"] + "'");
  4088. }
  4089. }
  4090. if (tids.Count > 0)
  4091. {
  4092. lw.RemoveAt(0);
  4093. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4094. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4095. dt = WebCache.GetData("view_erptradecell", dStruct);
  4096. }
  4097. }*/
  4098. writeGridDataTableJson(dStruct.TotalCount, dt);
  4099. }
  4100. public void get_erp_pddderiving()
  4101. {
  4102. DataStruct dStruct = GetPostStruct();
  4103. List<string> lw = new List<string>();
  4104. string tid = GetPostString("ctid");
  4105. if (tid.Length > 0)
  4106. {
  4107. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4108. if (tid.Length > 5)
  4109. {
  4110. List<string> tids = getTidByCtidLike(tid);
  4111. if (tids.Count > 0 && tids.Count < 10)
  4112. {
  4113. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4114. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4115. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4116. {
  4117. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4118. }
  4119. }
  4120. }
  4121. lw.Add(tid_sql);
  4122. }
  4123. string shopname = GetPostString("shopname");
  4124. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4125. string buyernick = GetPostString("buyer_nick");
  4126. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4127. //if (tid.Length == 0 && buyernick.Length == 0)
  4128. //{
  4129. // lw.Add(string.Format("IsRefund<={0}", 1));
  4130. //}
  4131. string customer = GetPostString("customer");
  4132. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4133. string design = GetPostString("design");
  4134. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4135. string orderState = GetPostString("orderState");
  4136. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4137. string address = GetPostString("address");
  4138. 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));
  4139. string sellermemo = GetPostString("seller_memo");
  4140. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4141. string supplier = GetPostString("supplier");
  4142. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4143. string OrderArea = GetPostString("order_area");
  4144. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4145. string placedate1 = GetPostString("placedate1");
  4146. string placedate2 = GetPostString("placedate2");
  4147. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4148. if (fdw.Length > 0) lw.Add(fdw);
  4149. string price1 = GetPostString("price1");
  4150. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4151. string price2 = GetPostString("price2");
  4152. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4153. string unusualCon = GetPostString("unusualcon");
  4154. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4155. string posTag = CurrentUser.UserPost.Post.Code;
  4156. if (posTag == "Supplier")
  4157. {
  4158. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4159. }
  4160. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4161. lw.Add(string.Format("type = 'PDD' "));
  4162. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4163. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4164. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4165. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4166. /*if (tid.Length > 0)
  4167. {
  4168. List<string> tids = new List<string>();
  4169. if (dt != null && dt.Rows.Count > 0)
  4170. {
  4171. foreach (DataRow item in dt.Rows)
  4172. {
  4173. tids.Add("'" + item["tid"] + "'");
  4174. }
  4175. }
  4176. if (tids.Count > 0)
  4177. {
  4178. lw.RemoveAt(0);
  4179. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4180. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4181. dt = WebCache.GetData("view_erptradecell", dStruct);
  4182. }
  4183. }*/
  4184. writeGridDataTableJson(dStruct.TotalCount, dt);
  4185. }
  4186. public void get_erp_jdderiving()
  4187. {
  4188. DataStruct dStruct = GetPostStruct();
  4189. List<string> lw = new List<string>();
  4190. string tid = GetPostString("ctid");
  4191. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4192. string shopname = GetPostString("shopname");
  4193. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4194. string buyernick = GetPostString("buyer_nick");
  4195. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4196. //if (tid.Length == 0 && buyernick.Length == 0)
  4197. //{
  4198. // lw.Add(string.Format("IsRefund<={0}", 1));
  4199. //}
  4200. string customer = GetPostString("customer");
  4201. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4202. string design = GetPostString("design");
  4203. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4204. string orderState = GetPostString("orderState");
  4205. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4206. string address = GetPostString("address");
  4207. 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));
  4208. string sellermemo = GetPostString("seller_memo");
  4209. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4210. string supplier = GetPostString("supplier");
  4211. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4212. string OrderArea = GetPostString("order_area");
  4213. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4214. string placedate1 = GetPostString("placedate1");
  4215. string placedate2 = GetPostString("placedate2");
  4216. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4217. if (fdw.Length > 0) lw.Add(fdw);
  4218. string price1 = GetPostString("price1");
  4219. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4220. string price2 = GetPostString("price2");
  4221. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4222. string unusualCon = GetPostString("unusualcon");
  4223. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4224. string posTag = CurrentUser.UserPost.Post.Code;
  4225. if (posTag == "Supplier")
  4226. {
  4227. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4228. }
  4229. lw.Add(string.Format("OrderState = 6 "));
  4230. lw.Add(string.Format("type = 'JD' "));
  4231. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4232. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4233. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4234. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4235. writeGridDataTableJson(dStruct.TotalCount, dt);
  4236. }
  4237. public void get_erp_demoorderlist()
  4238. {
  4239. DataStruct dStruct = GetPostStruct();
  4240. List<string> lw = new List<string>();
  4241. string tid = GetPostString("ctid");
  4242. if (tid.Length > 0)
  4243. {
  4244. string select_tid = getTidByCtid(tid);
  4245. lw.Add(string.Format("tid='{0}'", select_tid));
  4246. }
  4247. string shopname = GetPostString("shopname");
  4248. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4249. string buyernick = GetPostString("buyer_nick");
  4250. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4251. string customer = GetPostString("customer");
  4252. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4253. string design = GetPostString("design");
  4254. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4255. string orderState = GetPostString("orderState");
  4256. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4257. string address = GetPostString("address");
  4258. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4259. string sellermemo = GetPostString("seller_memo");
  4260. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4261. string supplier = GetPostString("supplier");
  4262. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4263. string OrderArea = GetPostString("order_area");
  4264. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4265. string date1 = GetPostString("date1");
  4266. string date2 = GetPostString("date2");
  4267. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4268. if (dw.Length > 0) lw.Add(dw);
  4269. string price1 = GetPostString("price1");
  4270. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4271. string price2 = GetPostString("price2");
  4272. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4273. string posTag = CurrentUser.UserPost.Post.Code;
  4274. if (posTag == "Supplier")
  4275. {
  4276. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4277. }
  4278. //lw.Add(string.Format("OrderState = 6 "));
  4279. lw.Add(string.Format("IsSample={0}", 3));
  4280. lw.Add(string.Format("IsRefund<={0}", 1));
  4281. dStruct.Order = "pay_time desc";
  4282. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4283. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4284. writeGridDataTableJson(dStruct.TotalCount, dt);
  4285. }
  4286. public void save_erp_checkmemo()
  4287. {
  4288. if (UrlPostParmsCheck("ctid"))
  4289. {
  4290. string ctid = GetPostString("ctid");
  4291. CeErpTradeCell entity = null;
  4292. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4293. if (entity != null)
  4294. {
  4295. entity.CheckMemo = GetPostString("CheckMemo");
  4296. entity.Update();
  4297. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4298. if (trade != null)
  4299. {
  4300. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4301. }
  4302. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4303. returnSuccessMsg("保存成功!");
  4304. return;
  4305. }
  4306. returnErrorMsg("找不到记录");
  4307. }
  4308. }
  4309. public void get_erp_returnlist()
  4310. {
  4311. DataStruct dStruct = GetPostStruct();
  4312. List<string> lw = new List<string>();
  4313. string tid = GetPostString("ctid");
  4314. if (tid.Length > 0)
  4315. {
  4316. string select_tid = getTidByCtid(tid);
  4317. lw.Add(string.Format("tid='{0}'", select_tid));
  4318. }
  4319. string shopname = GetPostString("shopname");
  4320. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4321. string buyernick = GetPostString("buyer_nick");
  4322. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4323. string customer = GetPostString("customer");
  4324. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4325. string design = GetPostString("design");
  4326. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4327. string orderState = GetPostString("orderState");
  4328. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4329. string address = GetPostString("address");
  4330. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4331. string sellermemo = GetPostString("seller_memo");
  4332. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4333. string supplier = GetPostString("supplier");
  4334. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4335. string date1 = GetPostString("date1");
  4336. string date2 = GetPostString("date2");
  4337. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4338. if (dw.Length > 0) lw.Add(dw);
  4339. string bdate1 = GetPostString("backdate1");
  4340. string bdate2 = GetPostString("backdate2");
  4341. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4342. if (dw_back.Length > 0) lw.Add(dw_back);
  4343. string price1 = GetPostString("price1");
  4344. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4345. string price2 = GetPostString("price2");
  4346. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4347. lw.Add(string.Format("IsReturn>0"));
  4348. lw.Add(string.Format("IsXianHuo=0"));
  4349. lw.Add(string.Format("IsReturn!=3"));
  4350. string backtype = GetPostString("backtype");
  4351. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4352. dStruct.Order = "FinishDesignTime desc";
  4353. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4354. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4355. writeGridDataTableJson(dStruct.TotalCount, dt);
  4356. }
  4357. public void get_erp_today_sumreturn()
  4358. {
  4359. DataStruct dStruct = GetPostStruct();
  4360. List<string> lw = new List<string>();
  4361. string bdate1 = GetPostString("returnTimeS");
  4362. string bdate2 = GetPostString("returnTimeE");
  4363. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4364. if (dw_back.Length > 0) lw.Add(dw_back);
  4365. lw.Add(string.Format("IsReturn=0"));
  4366. lw.Add(string.Format("IsXianHuo=0"));
  4367. string mainWhere = string.Join(" and ", lw.ToArray());
  4368. string sql = "";
  4369. if (dw_back.Length > 0)
  4370. {
  4371. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4372. }
  4373. else
  4374. {
  4375. 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 + "'";
  4376. }
  4377. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4378. decimal total = 0, today_finish = 0;
  4379. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4380. {
  4381. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4382. }
  4383. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4384. {
  4385. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4386. }
  4387. var res = new
  4388. {
  4389. data = total,
  4390. data1 = today_finish,
  4391. };
  4392. string ro_jsond = JsonConvert.SerializeObject(res);
  4393. returnSuccess(ro_jsond);
  4394. return;
  4395. }
  4396. public void get_erp_allreturnlist()
  4397. {
  4398. DataStruct dStruct = GetPostStruct();
  4399. List<string> lw = new List<string>();
  4400. string tid = GetPostString("ctid");
  4401. if (tid.Length > 0)
  4402. {
  4403. string select_tid = getTidByCtid(tid);
  4404. lw.Add(string.Format("tid='{0}'", select_tid));
  4405. }
  4406. string shopname = GetPostString("shopname");
  4407. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4408. string buyernick = GetPostString("buyer_nick");
  4409. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4410. string customer = GetPostString("customer");
  4411. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4412. string design = GetPostString("design");
  4413. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4414. string orderState = GetPostString("orderState");
  4415. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4416. string address = GetPostString("address");
  4417. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4418. string sellermemo = GetPostString("seller_memo");
  4419. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4420. string supplier = GetPostString("supplier");
  4421. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4422. string date1 = GetPostString("date1");
  4423. string date2 = GetPostString("date2");
  4424. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4425. if (dw.Length > 0) lw.Add(dw);
  4426. string bdate1 = GetPostString("backdate1");
  4427. string bdate2 = GetPostString("backdate2");
  4428. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4429. if (dw_back.Length > 0) lw.Add(dw_back);
  4430. string price1 = GetPostString("price1");
  4431. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4432. string price2 = GetPostString("price2");
  4433. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4434. string backreason = GetPostString("backreason");
  4435. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4436. lw.Add(string.Format("IsXianHuo=0"));
  4437. lw.Add(string.Format("ReturnTime != ''"));
  4438. string backtype = GetPostString("backtype");
  4439. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4440. dStruct.Order = "FinishDesignTime desc";
  4441. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4442. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4443. writeGridDataTableJson(dStruct.TotalCount, dt);
  4444. }
  4445. public void get_erp_aftersalereturnlist()
  4446. {
  4447. DataStruct dStruct = GetPostStruct();
  4448. List<string> lw = new List<string>();
  4449. string tid = GetPostString("ctid");
  4450. if (tid.Length > 0)
  4451. {
  4452. string select_tid = getTidByCtid(tid);
  4453. lw.Add(string.Format("tid='{0}'", select_tid));
  4454. }
  4455. string shopname = GetPostString("shopname");
  4456. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4457. string buyernick = GetPostString("buyer_nick");
  4458. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4459. string customer = GetPostString("customer");
  4460. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4461. string design = GetPostString("design");
  4462. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4463. string orderState = GetPostString("orderState");
  4464. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4465. string address = GetPostString("address");
  4466. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4467. string sellermemo = GetPostString("seller_memo");
  4468. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4469. string supplier = GetPostString("supplier");
  4470. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4471. string date1 = GetPostString("date1");
  4472. string date2 = GetPostString("date2");
  4473. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4474. if (dw.Length > 0) lw.Add(dw);
  4475. string bdate1 = GetPostString("backdate1");
  4476. string bdate2 = GetPostString("backdate2");
  4477. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4478. if (dw_back.Length > 0) lw.Add(dw_back);
  4479. string price1 = GetPostString("price1");
  4480. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4481. string price2 = GetPostString("price2");
  4482. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4483. lw.Add(string.Format("IsReturn=3"));
  4484. string backtype = GetPostString("backtype");
  4485. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4486. string backreason = GetPostString("backreason");
  4487. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4488. dStruct.Order = "ReturnTime desc";
  4489. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4490. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4491. writeGridDataTableJson(dStruct.TotalCount, dt);
  4492. }
  4493. public void get_erp_xianhuoreturnlist()
  4494. {
  4495. DataStruct dStruct = GetPostStruct();
  4496. List<string> lw = new List<string>();
  4497. string tid = GetPostString("ctid");
  4498. if (tid.Length > 0)
  4499. {
  4500. string select_tid = getTidByCtid(tid);
  4501. lw.Add(string.Format("tid='{0}'", select_tid));
  4502. }
  4503. string shopname = GetPostString("shopname");
  4504. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4505. string buyernick = GetPostString("buyer_nick");
  4506. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4507. string customer = GetPostString("customer");
  4508. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4509. string design = GetPostString("design");
  4510. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4511. string orderState = GetPostString("orderState");
  4512. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4513. string address = GetPostString("address");
  4514. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4515. string sellermemo = GetPostString("seller_memo");
  4516. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4517. string supplier = GetPostString("supplier");
  4518. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4519. string OrderArea = GetPostString("order_area");
  4520. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4521. string date1 = GetPostString("date1");
  4522. string date2 = GetPostString("date2");
  4523. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4524. if (dw.Length > 0) lw.Add(dw);
  4525. string price1 = GetPostString("price1");
  4526. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4527. string price2 = GetPostString("price2");
  4528. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4529. string posTag = CurrentUser.UserPost.Post.Code;
  4530. if (posTag == "Supplier")
  4531. {
  4532. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4533. }
  4534. lw.Add(string.Format("OrderState=6 "));
  4535. lw.Add(string.Format("IsXianHuo=1 "));
  4536. lw.Add(string.Format("IsReturn>0 "));
  4537. lw.Add(string.Format("IsReturn!=3"));
  4538. lw.Add(string.Format("IsRefund<={0}", 1));
  4539. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4540. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4541. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4542. writeGridDataTableJson(dStruct.TotalCount, dt);
  4543. }
  4544. public void set_erp_orderdelivery()
  4545. {
  4546. if (UrlPostParmsCheck("ctid"))
  4547. {
  4548. string eid = GetPostString("ctid");
  4549. CeErpTradeCell entity = null;
  4550. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4551. if (entity != null)
  4552. {
  4553. if (entity.OrderState >= 7)
  4554. {
  4555. returnErrorMsg("此单已发货,无需重复发货");
  4556. return;
  4557. }
  4558. if (entity.OrderState != 6)
  4559. {
  4560. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4561. return;
  4562. }
  4563. string shop = GetPostString("seller_nick");
  4564. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4565. string comName = GetPostString("comName");
  4566. string comCode = GetPostString("comCode");
  4567. string outSid = GetPostString("outSid");
  4568. string deliveryType = GetPostString("deliveryType");
  4569. string deliveryMemo = GetPostString("deliveryMemo");
  4570. outSid = outSid.Trim();
  4571. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4572. if (mainEn == null)
  4573. {
  4574. returnErrorMsg("找不到原始订单记录");
  4575. return;
  4576. }
  4577. bool isInitOrderDeliv = false;
  4578. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4579. {
  4580. isInitOrderDeliv = true;
  4581. }
  4582. string apires = "";
  4583. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4584. 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)
  4585. {
  4586. apires = "发货成功true";
  4587. }
  4588. else
  4589. {
  4590. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4591. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4592. }
  4593. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4594. {
  4595. entity.OrderState = 7;//发货后订单已发货
  4596. entity.OutSid = outSid;
  4597. entity.MemoOpt = 0;
  4598. entity.UpdateTime = DateTime.Now;
  4599. entity.FinishDeliveryTime = DateTime.Now;
  4600. entity.Update();
  4601. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4602. commonHelper.UpdateRelationOrder(entity.ctid);
  4603. //还要插入快递信息到 快递信息表
  4604. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4605. exinfo.tid = eid;
  4606. exinfo.out_sid = outSid;
  4607. exinfo.company_code = comCode;
  4608. exinfo.company_name = comName;
  4609. exinfo.delivery_memo = deliveryMemo;
  4610. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4611. exinfo.deliveryType = deliveryType;
  4612. exinfo.Create();
  4613. returnSuccessMsg("发货操作成功!");
  4614. commonHelper.UpdateRelationOrder(entity.ctid);
  4615. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4616. CeErpSukuraData.createInfo(entity.ctid, 4);
  4617. if (entity.SupplierId == 64)
  4618. {
  4619. commonHelper.sendCytExpress(exinfo);
  4620. }
  4621. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4622. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4623. }
  4624. else
  4625. {
  4626. string errmsg = commonHelper.KeepChinese(apires);
  4627. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4628. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4629. }
  4630. return;
  4631. }
  4632. returnErrorMsg("找不到订单记录");
  4633. }
  4634. }
  4635. public void set_erp_multidelivery()
  4636. {
  4637. string eids = GetPostString("tids");
  4638. string[] eidList = eids.Split(',');
  4639. if (eidList.Length <= 0)
  4640. {
  4641. returnErrorMsg("发货不能为空");
  4642. return;
  4643. }
  4644. foreach (string ctid in eidList)
  4645. {
  4646. if (ctid.Length <= 0) continue;
  4647. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4648. if (expInfo != null)
  4649. {
  4650. StringBuilder sql = new StringBuilder();
  4651. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4652. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4653. if (dt.Rows.Count > 0)
  4654. {
  4655. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4656. {
  4657. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4658. expInfo.state = "异常";
  4659. expInfo.isMultiDelivery = 1;
  4660. expInfo.Update();
  4661. continue;
  4662. }
  4663. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4664. {
  4665. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4666. expInfo.state = "异常";
  4667. expInfo.Update();
  4668. continue;
  4669. }
  4670. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4671. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4672. bool isInitOrderDeliv = false;
  4673. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4674. {
  4675. isInitOrderDeliv = true;
  4676. expInfo.isMultiDelivery = 1;
  4677. }
  4678. if (ctid.IndexOf("N") != -1)
  4679. {
  4680. StringBuilder sqlbucha = new StringBuilder();
  4681. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4682. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4683. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4684. commonHelper.UpdateRelationOrder(ctid);
  4685. expInfo.delivery_memo = "发货成功";
  4686. expInfo.state = "发货成功";
  4687. expInfo.isMultiDelivery = 1;
  4688. expInfo.Update();
  4689. }
  4690. else
  4691. {
  4692. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4693. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4694. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4695. {
  4696. expInfo.delivery_memo = "发货成功";
  4697. expInfo.state = "发货成功";
  4698. expInfo.isMultiDelivery = 1;
  4699. expInfo.Update();
  4700. commonHelper.UpdateRelationOrder(ctid);
  4701. CeErpSukuraData.createInfo(ctid, 4);
  4702. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4703. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4704. }
  4705. else
  4706. {
  4707. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4708. expInfo.state = "异常";
  4709. expInfo.Update();
  4710. }
  4711. }
  4712. }
  4713. }
  4714. }
  4715. returnSuccessMsg("操作完成");
  4716. }
  4717. public void reset_erp_memoopt()
  4718. {
  4719. if (UrlPostParmsCheck("ctid"))
  4720. {
  4721. string eid = GetPostString("ctid");
  4722. CeErpTradeCell entity = null;
  4723. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4724. if (entity != null)
  4725. {
  4726. string stropt = "";
  4727. if (entity.MemoOpt == 1)
  4728. {
  4729. stropt = "“改稿”";
  4730. }
  4731. else if (entity.MemoOpt == 2)
  4732. {
  4733. stropt = "“定稿”";
  4734. }
  4735. else if (entity.MemoOpt == 3)
  4736. {
  4737. stropt = "“完成查货”";
  4738. CeErpSukuraData.createInfo(entity.ctid, 6);
  4739. }
  4740. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4741. entity.UpdateTime = DateTime.Now;
  4742. entity.MemoOpt = 0;
  4743. entity.Update();
  4744. returnSuccessMsg("操作成功!");
  4745. return;
  4746. }
  4747. returnErrorMsg("找不到记录");
  4748. }
  4749. }
  4750. public void get_erp_deliveryunusual()
  4751. {
  4752. DataStruct dStruct = GetPostStruct();
  4753. List<string> lw = new List<string>();
  4754. string tid = GetPostString("ctid");
  4755. if (tid.Length > 0)
  4756. {
  4757. string select_tid = getTidByCtid(tid);
  4758. lw.Add(string.Format("tid='{0}'", select_tid));
  4759. }
  4760. string shopname = GetPostString("shopname");
  4761. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4762. string buyernick = GetPostString("buyer_nick");
  4763. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4764. string customer = GetPostString("customer");
  4765. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4766. string design = GetPostString("design");
  4767. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4768. string sellermemo = GetPostString("seller_memo");
  4769. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4770. string supplier = GetPostString("supplier");
  4771. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4772. string date1 = GetPostString("date1");
  4773. string date2 = GetPostString("date2");
  4774. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4775. if (dw.Length > 0) lw.Add(dw);
  4776. string placedate1 = GetPostString("placedate1");
  4777. string placedate2 = GetPostString("placedate2");
  4778. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4779. if (dw_place.Length > 0) lw.Add(dw_place);
  4780. string price1 = GetPostString("price1");
  4781. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4782. string price2 = GetPostString("price2");
  4783. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4784. string unusualCon = GetPostString("unusualcon");
  4785. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4786. string posTag = CurrentUser.UserPost.Post.Code;
  4787. if (posTag == "Supplier")
  4788. {
  4789. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4790. }
  4791. lw.Add(string.Format("OrderState = 6"));
  4792. lw.Add(string.Format("UnusualTag = 5"));
  4793. lw.Add(string.Format("IsRefund<={0}", 1));
  4794. dStruct.Order = "FinishPlaceTime desc";
  4795. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4796. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4797. writeGridDataTableJson(dStruct.TotalCount, dt);
  4798. }
  4799. public void get_erp_deliveryedlist()
  4800. {
  4801. DataStruct dStruct = GetPostStruct();
  4802. List<string> lw = new List<string>();
  4803. string tid = GetPostString("ctid");
  4804. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4805. string shopname = GetPostString("shopname");
  4806. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4807. string buyernick = GetPostString("buyer_nick");
  4808. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4809. string customer = GetPostString("customer");
  4810. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4811. string design = GetPostString("design");
  4812. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4813. string sellermemo = GetPostString("seller_memo");
  4814. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4815. string logistics = GetPostString("logistics");
  4816. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4817. string date1 = GetPostString("date1");
  4818. string date2 = GetPostString("date2");
  4819. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4820. //if (dw.Length > 0) lw.Add(dw);
  4821. string placedate1 = GetPostString("placedate1");
  4822. string placedate2 = GetPostString("placedate2");
  4823. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4824. if (fdw.Length > 0) lw.Add(fdw);
  4825. string devdate1 = GetPostString("deliverydate1");
  4826. string devdate2 = GetPostString("deliverydate2");
  4827. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4828. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4829. string price1 = GetPostString("price1");
  4830. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4831. string price2 = GetPostString("price2");
  4832. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4833. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4834. {
  4835. if (tid.Length > 0)
  4836. {
  4837. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4838. if (tid.Length > 5)
  4839. {
  4840. List<string> tids = getTidByCtidLike(tid);
  4841. if (tids.Count > 0 && tids.Count < 10)
  4842. {
  4843. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4844. }
  4845. }
  4846. lw.Add(tid_sql);
  4847. }
  4848. if (buyernick.Length > 0)
  4849. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4850. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4851. if (dw.Length > 0) lw.Add(dw);
  4852. }
  4853. else
  4854. {
  4855. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4856. }
  4857. string posTag = CurrentUser.UserPost.Post.Code;
  4858. if (posTag == "Supplier")
  4859. {
  4860. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4861. }
  4862. else
  4863. {
  4864. string supplier = GetPostString("supplier");
  4865. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4866. }
  4867. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4868. lw.Add(string.Format("type != 'PDD' "));
  4869. lw.Add(string.Format("IsRefund!={0}", 2));
  4870. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4871. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4872. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4873. /*if (tid.Length > 0)
  4874. {
  4875. List<string> tids = new List<string>();
  4876. if (dt != null && dt.Rows.Count > 0)
  4877. {
  4878. foreach (DataRow item in dt.Rows)
  4879. {
  4880. tids.Add("'" + item["tid"] + "'");
  4881. }
  4882. }
  4883. if (tids.Count > 0)
  4884. {
  4885. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4886. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4887. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4888. dt = WebCache.GetData("view_erptradecell", dStruct);
  4889. }
  4890. }*/
  4891. if (dt != null)
  4892. {
  4893. foreach (DataRow dr in dt.Rows)
  4894. {
  4895. 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();
  4896. }
  4897. }
  4898. writeGridDataTableJson(dStruct.TotalCount, dt);
  4899. }
  4900. public void get_erp_pdddeliveryed()
  4901. {
  4902. DataStruct dStruct = GetPostStruct();
  4903. List<string> lw = new List<string>();
  4904. string tid = GetPostString("ctid");
  4905. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4906. string shopname = GetPostString("shopname");
  4907. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4908. string buyernick = GetPostString("buyer_nick");
  4909. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4910. string customer = GetPostString("customer");
  4911. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4912. string design = GetPostString("design");
  4913. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4914. string sellermemo = GetPostString("seller_memo");
  4915. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4916. string logistics = GetPostString("logistics");
  4917. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4918. string date1 = GetPostString("date1");
  4919. string date2 = GetPostString("date2");
  4920. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4921. //if (dw.Length > 0) lw.Add(dw);
  4922. string placedate1 = GetPostString("placedate1");
  4923. string placedate2 = GetPostString("placedate2");
  4924. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4925. if (fdw.Length > 0) lw.Add(fdw);
  4926. string devdate1 = GetPostString("deliverydate1");
  4927. string devdate2 = GetPostString("deliverydate2");
  4928. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4929. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4930. string price1 = GetPostString("price1");
  4931. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4932. string price2 = GetPostString("price2");
  4933. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4934. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4935. {
  4936. if (tid.Length > 0)
  4937. {
  4938. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4939. if (tid.Length > 5)
  4940. {
  4941. List<string> tids = getTidByCtidLike(tid);
  4942. if (tids.Count > 0 && tids.Count < 10)
  4943. {
  4944. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4945. }
  4946. }
  4947. lw.Add(tid_sql);
  4948. }
  4949. if (buyernick.Length > 0)
  4950. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4951. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4952. if (dw.Length > 0) lw.Add(dw);
  4953. }
  4954. else
  4955. {
  4956. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4957. }
  4958. string posTag = CurrentUser.UserPost.Post.Code;
  4959. if (posTag == "Supplier")
  4960. {
  4961. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4962. }
  4963. else
  4964. {
  4965. string supplier = GetPostString("supplier");
  4966. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4967. }
  4968. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4969. lw.Add(string.Format("type = 'PDD' "));
  4970. lw.Add(string.Format("IsRefund!={0}", 2));
  4971. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4972. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4973. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4974. /* if (tid.Length > 0)
  4975. {
  4976. List<string> tids = new List<string>();
  4977. if (dt != null && dt.Rows.Count > 0)
  4978. {
  4979. foreach (DataRow item in dt.Rows)
  4980. {
  4981. tids.Add("'" + item["tid"] + "'");
  4982. }
  4983. }
  4984. if (tids.Count > 0)
  4985. {
  4986. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4987. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4988. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4989. dt = WebCache.GetData("view_erptradecell", dStruct);
  4990. }
  4991. }*/
  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_jddeliveryed()
  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='{0}' or tid='{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 date1 = GetPostString("date1");
  5015. string date2 = GetPostString("date2");
  5016. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5017. //if (dw.Length > 0) lw.Add(dw);
  5018. string placedate1 = GetPostString("placedate1");
  5019. string placedate2 = GetPostString("placedate2");
  5020. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5021. if (fdw.Length > 0) lw.Add(fdw);
  5022. string devdate1 = GetPostString("deliverydate1");
  5023. string devdate2 = GetPostString("deliverydate2");
  5024. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5025. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5026. string price1 = GetPostString("price1");
  5027. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5028. string price2 = GetPostString("price2");
  5029. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5030. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5031. {
  5032. if (tid.Length > 0)
  5033. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5034. if (buyernick.Length > 0)
  5035. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5036. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5037. if (dw.Length > 0) lw.Add(dw);
  5038. }
  5039. else
  5040. {
  5041. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5042. }
  5043. string posTag = CurrentUser.UserPost.Post.Code;
  5044. if (posTag == "Supplier")
  5045. {
  5046. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5047. }
  5048. else
  5049. {
  5050. string supplier = GetPostString("supplier");
  5051. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5052. }
  5053. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5054. lw.Add(string.Format("type = 'JD' "));
  5055. lw.Add(string.Format("IsRefund!={0}", 2));
  5056. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5057. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5058. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5059. foreach (DataRow dr in dt.Rows)
  5060. {
  5061. 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();
  5062. }
  5063. writeGridDataTableJson(dStruct.TotalCount, dt);
  5064. }
  5065. public void get_erp_allplacelist()
  5066. {
  5067. DataStruct dStruct = GetPostStruct();
  5068. List<string> lw = new List<string>();
  5069. string tid = GetPostString("ctid");
  5070. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  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 = '{0}'", supplier));
  5083. string date1 = GetPostString("date1");
  5084. string date2 = GetPostString("date2");
  5085. string pldate1 = GetPostString("placedate1");
  5086. string pldate2 = GetPostString("placedate2");
  5087. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5088. //if (dw.Length > 0) lw.Add(dw);
  5089. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5090. {
  5091. if (tid.Length > 0)
  5092. {
  5093. string select_tid = getTidByCtid(tid);
  5094. lw.Add(string.Format("tid='{0}'", select_tid));
  5095. }
  5096. if (buyernick.Length > 0)
  5097. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5098. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5099. if (dw.Length > 0) lw.Add(dw);
  5100. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5101. if (dw_place.Length > 0) lw.Add(dw_place);
  5102. }
  5103. else
  5104. {
  5105. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5106. {
  5107. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5108. }
  5109. }
  5110. string price1 = GetPostString("price1");
  5111. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5112. string price2 = GetPostString("price2");
  5113. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5114. string posTag = CurrentUser.UserPost.Post.Code;
  5115. if (posTag == "Supplier")
  5116. {
  5117. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5118. }
  5119. lw.Add(string.Format("OrderState >= 6"));
  5120. lw.Add(string.Format("IsSample != 2 "));
  5121. //lw.Add(string.Format("isDianziOrder = 0 "));
  5122. lw.Add(string.Format("SupplierId > 0 "));
  5123. //lw.Add(string.Format("IsRefund<={0}", 1));
  5124. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5125. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5126. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5127. foreach (DataRow dr in dt.Rows)
  5128. {
  5129. 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();
  5130. }
  5131. writeGridDataTableJson(dStruct.TotalCount, dt);
  5132. }
  5133. public void get_erp_financeallplacelist()
  5134. {
  5135. DataStruct dStruct = GetPostStruct();
  5136. List<string> lw = new List<string>();
  5137. string tid = GetPostString("ctid");
  5138. string shopname = GetPostString("shopname");
  5139. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5140. string buyernick = GetPostString("buyer_nick");
  5141. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5142. string customer = GetPostString("customer");
  5143. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5144. string design = GetPostString("design");
  5145. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5146. string sellermemo = GetPostString("seller_memo");
  5147. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5148. string supplier = GetPostString("supplier");
  5149. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5150. string date1 = GetPostString("date1");
  5151. string date2 = GetPostString("date2");
  5152. string pldate1 = GetPostString("placedate1");
  5153. string pldate2 = GetPostString("placedate2");
  5154. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5155. {
  5156. if (tid.Length > 0)
  5157. {
  5158. string select_tid = getTidByCtid(tid);
  5159. lw.Add(string.Format("tid='{0}'", select_tid));
  5160. }
  5161. if (buyernick.Length > 0)
  5162. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5163. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5164. if (dw.Length > 0) lw.Add(dw);
  5165. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5166. if (dw_place.Length > 0) lw.Add(dw_place);
  5167. }
  5168. else
  5169. {
  5170. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5171. {
  5172. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5173. }
  5174. }
  5175. string price1 = GetPostString("price1");
  5176. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5177. string price2 = GetPostString("price2");
  5178. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5179. string posTag = CurrentUser.UserPost.Post.Code;
  5180. if (posTag == "Supplier")
  5181. {
  5182. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5183. }
  5184. //lw.Add(string.Format("OrderState >= 6"));
  5185. lw.Add(string.Format("IsSample != 2 "));
  5186. lw.Add(string.Format("isDianziOrder = 0 "));
  5187. //lw.Add(string.Format("IsRefund<={0}", 1));
  5188. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5189. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5190. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5191. foreach (DataRow dr in dt.Rows)
  5192. {
  5193. 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();
  5194. }
  5195. writeGridDataTableJson(dStruct.TotalCount, dt);
  5196. }
  5197. public void get_erp_expresslist()
  5198. {
  5199. int listtype = GetInt("ltype");
  5200. DataStruct dStruct = GetPostStruct();
  5201. List<string> lw = new List<string>();
  5202. string tid = GetPostString("tid");
  5203. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5204. string outsid = GetPostString("out_sid");
  5205. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5206. string importer = GetPostString("ImportUserName");
  5207. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5208. string file = GetPostString("import_file");
  5209. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5210. string printman = GetPostString("printman");
  5211. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5212. string date1 = GetPostString("date1");
  5213. string date2 = GetPostString("date2");
  5214. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5215. if (dw.Length > 0) lw.Add(dw);
  5216. string fdate1 = GetPostString("finishdate1");
  5217. string fdate2 = GetPostString("finishdate2");
  5218. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5219. if (fdw.Length > 0) lw.Add(fdw);
  5220. string supplierId = GetPostString("supplierId");
  5221. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5222. if (listtype == 1)
  5223. {
  5224. lw.Add(string.Format("importUserId !=0"));
  5225. }
  5226. string posTag = CurrentUser.UserPost.Post.Code;
  5227. if (posTag == "Supplier")
  5228. {
  5229. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5230. }
  5231. if (dStruct.PageSize != 100000)
  5232. {
  5233. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5234. }
  5235. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5236. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5237. writeGridDataTableJson(dStruct.TotalCount, dt);
  5238. }
  5239. public void set_erp_buchaorderdelivery()
  5240. {
  5241. if (UrlPostParmsCheck("ctid"))
  5242. {
  5243. string eid = GetPostString("ctid");
  5244. CeErpTradeCell entity = null;
  5245. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5246. if (entity != null)
  5247. {
  5248. if (entity.IsSample != 2)
  5249. {
  5250. returnErrorMsg("补差价单才能标记为已发货");
  5251. return;
  5252. }
  5253. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5254. entity.OrderState = 7;
  5255. entity.Update();
  5256. returnSuccessMsg("操作成功!");
  5257. return;
  5258. }
  5259. returnErrorMsg("找不到记录");
  5260. }
  5261. }
  5262. public void get_stdtemplates()
  5263. {
  5264. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5265. //string res = taobaoHelper.test();
  5266. string res = apiHelper.API_PrintTemplate();
  5267. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5268. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5269. {
  5270. int sidx = res.IndexOf("error_code");
  5271. int eidx = res.IndexOf("success");
  5272. string msg = res.Substring(sidx, eidx - sidx);
  5273. returnErrorMsg(msg);
  5274. return;
  5275. }
  5276. if (res.Length <= 0)
  5277. {
  5278. returnErrorMsg("模板数据为空!");
  5279. return;
  5280. }
  5281. ReturnSuccess(res);
  5282. }
  5283. public void cancel_print_order()
  5284. {
  5285. if (UrlPostParmsCheck("ctid"))
  5286. {
  5287. string ctid = GetPostString("ctid");
  5288. CeErpTradeCell entity = null;
  5289. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5290. if (entity != null)
  5291. {
  5292. string res = "";
  5293. string code = entity.LastBillWaybillCode;
  5294. if (code == "")
  5295. {
  5296. code = entity.OutSid;
  5297. }
  5298. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5299. XLog.SaveLog(0, "取消面单" + res);
  5300. }
  5301. }
  5302. }
  5303. public void set_erp_printwaybill()
  5304. {
  5305. if (UrlPostParmsCheck("ctid"))
  5306. {
  5307. string ctid = GetPostString("ctid");
  5308. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5309. string cpName = GetPostString("cpname");
  5310. string isTogether = GetPostString("together");
  5311. //var res_obj = new
  5312. //{
  5313. // restype = 1,
  5314. // 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\"}"
  5315. //};
  5316. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5317. //ReturnSuccess(ro_json);
  5318. //return;
  5319. bool isUseLastWayBillCode = false;
  5320. CeErpTradeCell entity = null;
  5321. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5322. if (entity != null)
  5323. {
  5324. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5325. {
  5326. isUseLastWayBillCode = true;
  5327. }
  5328. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5329. {
  5330. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5331. return;
  5332. }
  5333. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5334. {
  5335. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5336. return;
  5337. }
  5338. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5339. {
  5340. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5341. return;
  5342. }
  5343. }
  5344. string res = "";
  5345. Api_waybill_code_response_Obj fullObj = null;
  5346. string pData_str = "";
  5347. string curUseWayBillCode = "";
  5348. if (isUseLastWayBillCode == false)
  5349. {
  5350. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5351. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5352. if (res.IndexOf("failure") != -1)
  5353. {
  5354. //int idx = res.IndexOf("sub_message");
  5355. //int idx2 = res.IndexOf("flag");
  5356. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5357. string errMsgNeed = commonHelper.KeepChinese(res);
  5358. var res_objd = new
  5359. {
  5360. restype = 0,
  5361. data = "获取面单失败" + errMsgNeed
  5362. };
  5363. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5364. returnSuccess(ro_jsond);
  5365. if (res.IndexOf("停发") != -1)
  5366. {
  5367. entity.UnusualCon = "物流停发";
  5368. entity.Update();
  5369. }
  5370. //returnErrorMsg("获取面单失败,"+emsg);
  5371. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5372. return;
  5373. }
  5374. else if (res.IndexOf("errorMsg") != -1)
  5375. {
  5376. //int idx = res.IndexOf("errorMsg");
  5377. //int idx2 = res.IndexOf("}]}");
  5378. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5379. string errMsgNeed = commonHelper.KeepChinese(res);
  5380. var res_objf = new
  5381. {
  5382. restype = 0,
  5383. data = "获取面单失败2" + errMsgNeed
  5384. };
  5385. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5386. if (res.IndexOf("停发") != -1)
  5387. {
  5388. entity.UnusualCon = "物流停发";
  5389. entity.Update();
  5390. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5391. if (trade != null)
  5392. {
  5393. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5394. }
  5395. }
  5396. returnSuccess(ro_jsonf);
  5397. //returnErrorMsg("获取面单失败," + emsg);
  5398. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5399. return;
  5400. }
  5401. try
  5402. {
  5403. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5404. //res = res.Replace(" ", "");
  5405. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5406. }
  5407. catch (Exception ex)
  5408. {
  5409. XLog.SaveLog(0, "生成fullObj" + res);
  5410. var res_objf = new
  5411. {
  5412. restype = 0,
  5413. data = "生成fullObj发生错误" + ex.Message
  5414. };
  5415. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5416. returnSuccess(ro_jsonf);
  5417. return;
  5418. }
  5419. if (fullObj.response.data.content.Count > 0)
  5420. {
  5421. ContentItem codeObj = fullObj.response.data.content[0];
  5422. if (cpCode.IndexOf("SFFQ-") != -1)
  5423. {
  5424. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5425. }
  5426. else
  5427. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5428. curUseWayBillCode = codeObj.waybillCode;
  5429. }
  5430. else
  5431. {
  5432. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5433. var res_objf = new
  5434. {
  5435. restype = 0,
  5436. data = "生成fullObj找不到快递单号waybillCode"
  5437. };
  5438. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5439. returnSuccess(ro_jsonf);
  5440. return;
  5441. }
  5442. }
  5443. else
  5444. {
  5445. //使用上次打印的快递单号
  5446. if (cpCode == "SFFQ-LY")
  5447. {
  5448. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5449. }
  5450. else
  5451. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5452. curUseWayBillCode = entity.LastBillWaybillCode;
  5453. }
  5454. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5455. {
  5456. var res_obje = new
  5457. {
  5458. restype = 0,
  5459. data = "获取加密打印数据失败"
  5460. };
  5461. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5462. returnSuccess(ro_jsone);
  5463. entity.LastBillCpCode = cpCode;
  5464. entity.LastBillWaybillCode = curUseWayBillCode;
  5465. entity.Update();
  5466. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5467. //returnErrorMsg("获取加密打印数据失败");
  5468. return;
  5469. }
  5470. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5471. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5472. string btnType = "";
  5473. string errorMsg = "";
  5474. if (entity != null)
  5475. {
  5476. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5477. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5478. //cpcode是 YTO-CAINIAO
  5479. //string comCode = cpCode.Split('-')[0].ToString();
  5480. string apires = "";
  5481. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5482. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5483. {
  5484. if (ctid.IndexOf("N") != -1)
  5485. {
  5486. apires = "发货成功";
  5487. }
  5488. else
  5489. {
  5490. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5491. }
  5492. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5493. //打单后发货
  5494. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5495. {
  5496. try
  5497. {
  5498. btnType = "待发货";
  5499. entity.OutSid = curUseWayBillCode;
  5500. entity.OrderState = 7;
  5501. entity.IsUrgency = false;
  5502. entity.LastBillCpCode = "";
  5503. entity.LastBillWaybillCode = "";
  5504. entity.FinishDeliveryTime = DateTime.Now;
  5505. entity.IsReturn = 0;
  5506. entity.MemoOpt = 0;
  5507. entity.UpdateTime = DateTime.Now;
  5508. entity.Update();
  5509. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5510. //还要插入快递信息到 快递信息表
  5511. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5512. exinfo.tid = entity.ctid;
  5513. exinfo.out_sid = curUseWayBillCode;
  5514. exinfo.company_code = cpCode;
  5515. exinfo.company_name = cpName;
  5516. exinfo.supplierUserName = supplierName;
  5517. exinfo.deliveryType = "发货成功";
  5518. exinfo.print_time = DateTime.Now;
  5519. exinfo.printUser = CurrentUser.UserName;
  5520. exinfo.postData = pData_str;
  5521. exinfo.Create();
  5522. commonHelper.UpdateRelationOrder(entity.ctid);
  5523. CeErpSukuraData.createInfo(ctid, 4);
  5524. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5525. if (entity.SupplierId == 64)
  5526. {
  5527. commonHelper.sendCytExpress(exinfo);
  5528. }
  5529. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5530. if (!string.IsNullOrEmpty(isTogether))
  5531. {
  5532. if (Convert.ToInt32(isTogether) > 0)
  5533. {
  5534. StringBuilder sqlsb = new StringBuilder();
  5535. 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);
  5536. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5537. }
  5538. }
  5539. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5540. }
  5541. catch (Exception ex)
  5542. {
  5543. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5544. }
  5545. }
  5546. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5547. {
  5548. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5549. if (entity.OrderState == 6)
  5550. {
  5551. entity.OrderState = 7;
  5552. }
  5553. entity.UpdateTime = DateTime.Now;
  5554. entity.FinishDeliveryTime = DateTime.Now;
  5555. btnType = "已发货";
  5556. entity.Update();
  5557. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5558. exinfo.tid = entity.ctid;
  5559. exinfo.out_sid = curUseWayBillCode;
  5560. exinfo.company_code = cpCode;
  5561. exinfo.company_name = cpName;
  5562. exinfo.supplierUserName = supplierName;
  5563. exinfo.deliveryType = "发货成功";
  5564. exinfo.print_time = DateTime.Now;
  5565. exinfo.printUser = CurrentUser.UserName;
  5566. exinfo.postData = pData_str;
  5567. exinfo.Create();
  5568. commonHelper.UpdateRelationOrder(entity.ctid);
  5569. CeErpSukuraData.createInfo(entity.ctid, 4);
  5570. if (entity.SupplierId == 64)
  5571. {
  5572. commonHelper.sendCytExpress(exinfo);
  5573. }
  5574. if (!string.IsNullOrEmpty(isTogether))
  5575. {
  5576. if (Convert.ToInt32(isTogether) > 0)
  5577. {
  5578. StringBuilder sqlsb = new StringBuilder();
  5579. 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);
  5580. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5581. }
  5582. }
  5583. //不处理
  5584. }
  5585. else
  5586. {
  5587. entity.UpdateTime = DateTime.Now;
  5588. entity.LastBillCpCode = cpCode;
  5589. entity.LastBillWaybillCode = curUseWayBillCode;
  5590. entity.Update();
  5591. string errmsg = commonHelper.KeepChinese(apires);
  5592. var res_objz = new
  5593. {
  5594. restype = 0,
  5595. data = "打单后发货失败"
  5596. };
  5597. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5598. returnSuccess(ro_jsonz);
  5599. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5600. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5601. return;
  5602. }
  5603. }
  5604. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5605. {
  5606. StringBuilder allSql = new StringBuilder();
  5607. allSql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,tid from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  5608. if (string.IsNullOrEmpty(mainEn.receiverId))
  5609. {
  5610. allSql.AppendFormat(" and (tid='{0}');", entity.tid);
  5611. }
  5612. else
  5613. {
  5614. //查询同车间同状态下的收货地址相同的单子
  5615. allSql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}') );", entity.tid, mainEn.receiverId, entity.IsSF);
  5616. }
  5617. DataTable dt = DbHelper.DbConn.ExecuteDataset(allSql.ToString()).Tables[0];
  5618. List<string> list = new List<string>();
  5619. List<string> send_list = new List<string>();
  5620. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5621. CeErpTrade ceErpTrade = new CeErpTrade();
  5622. foreach (DataRow row in dt.Rows)
  5623. {
  5624. list.Add("'" + row["ctid"] + "'");
  5625. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5626. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5627. if (ctid.IndexOf("N") != -1)
  5628. {
  5629. apires = "发货成功";
  5630. }
  5631. else
  5632. {
  5633. if (!send_list.Contains(ceErpTrade.tid))
  5634. {
  5635. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5636. }
  5637. else
  5638. {
  5639. apires = "发货成功";
  5640. }
  5641. }
  5642. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5643. {
  5644. send_list.Add(ceErpTrade.tid);
  5645. try
  5646. {
  5647. btnType = "待发货";
  5648. ceErpTradeCell.OutSid = curUseWayBillCode;
  5649. ceErpTradeCell.OrderState = 7;
  5650. ceErpTradeCell.IsUrgency = false;
  5651. ceErpTradeCell.LastBillCpCode = "";
  5652. ceErpTradeCell.LastBillWaybillCode = "";
  5653. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5654. ceErpTradeCell.IsReturn = 0;
  5655. ceErpTradeCell.MemoOpt = 0;
  5656. ceErpTradeCell.UpdateTime = DateTime.Now;
  5657. ceErpTradeCell.Update();
  5658. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5659. //还要插入快递信息到 快递信息表
  5660. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5661. exinfo.tid = ceErpTradeCell.ctid;
  5662. exinfo.out_sid = curUseWayBillCode;
  5663. exinfo.company_code = cpCode;
  5664. exinfo.company_name = cpName;
  5665. exinfo.supplierUserName = supplierName;
  5666. exinfo.deliveryType = "发货成功";
  5667. exinfo.print_time = DateTime.Now;
  5668. exinfo.printUser = CurrentUser.UserName;
  5669. exinfo.postData = pData_str;
  5670. exinfo.Create();
  5671. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5672. CeErpSukuraData.createInfo(ctid, 4);
  5673. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5674. if (ceErpTradeCell.SupplierId == 64)
  5675. {
  5676. commonHelper.sendCytExpress(exinfo);
  5677. }
  5678. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5679. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5680. }
  5681. catch (Exception ex)
  5682. {
  5683. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5684. }
  5685. }
  5686. else
  5687. {
  5688. ceErpTradeCell.UpdateTime = DateTime.Now;
  5689. ceErpTradeCell.LastBillCpCode = cpCode;
  5690. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5691. ceErpTradeCell.Update();
  5692. string errmsg = commonHelper.KeepChinese(apires);
  5693. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5694. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5695. }
  5696. }
  5697. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5698. }
  5699. }
  5700. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5701. var res_obj = new
  5702. {
  5703. restype = 1,
  5704. data = pData_str,
  5705. errorMsg
  5706. };
  5707. string ro_json = JsonConvert.SerializeObject(res_obj);
  5708. ReturnSuccess(ro_json);
  5709. return;
  5710. }
  5711. }
  5712. private string GetUTF8String(byte[] vs)
  5713. {
  5714. throw new NotImplementedException();
  5715. }
  5716. public void set_erp_printwaybill_cn()
  5717. {
  5718. if (UrlPostParmsCheck("ctid"))
  5719. {
  5720. string ctid = GetPostString("ctid");
  5721. string cpCode = GetPostString("cpcode");
  5722. string cpName = GetPostString("cpname");
  5723. string tempUrl = GetPostString("tempurl");
  5724. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5725. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5726. //string res = taobaoHelper.test();
  5727. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5728. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5729. {
  5730. int sidx = res.IndexOf("errorMsg");
  5731. int eidx = res.IndexOf("}");
  5732. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5733. var res_objzxx = new
  5734. {
  5735. restype = 0,
  5736. data = msg
  5737. };
  5738. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5739. returnSuccess(ro_jsonzxx);
  5740. //returnErrorMsg(msg);
  5741. return;
  5742. }
  5743. int idx = res.IndexOf("waybillCode");
  5744. int idx2 = res.IndexOf("printData");
  5745. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5746. string eid = GetPostString("ctid");
  5747. CeErpTradeCell entity = null;
  5748. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5749. if (entity != null)
  5750. {
  5751. string osid = entity.OutSid;
  5752. entity.OutSid = osid + "," + outsid;
  5753. entity.FinishDeliveryTime = DateTime.Now;
  5754. entity.OrderState = 7;
  5755. entity.UpdateTime = DateTime.Now;
  5756. entity.IsReturn = 0;
  5757. entity.Update();
  5758. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5759. exinfo.tid = entity.ctid;
  5760. exinfo.out_sid = outsid;
  5761. exinfo.company_code = cpCode;
  5762. exinfo.company_name = cpName;
  5763. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5764. exinfo.deliveryType = "发货成功";
  5765. exinfo.print_time = DateTime.Now;
  5766. exinfo.printUser = CurrentUser.UserName;
  5767. exinfo.Create();
  5768. if (entity.SupplierId == 64)
  5769. {
  5770. commonHelper.sendCytExpress(exinfo);
  5771. }
  5772. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5773. }
  5774. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5775. var res_objz = new
  5776. {
  5777. restype = 1,
  5778. data = res
  5779. };
  5780. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5781. returnSuccess(ro_jsonz);
  5782. //ReturnSuccess(res);
  5783. }
  5784. }
  5785. ////打单,打印面单 获取面单号
  5786. //public void set_erp_printwaybill()
  5787. //{
  5788. // if (UrlPostParmsCheck("ctid"))
  5789. // {
  5790. // string ctid = GetPostString("ctid");
  5791. // string cpCode = GetPostString("cpcode");
  5792. // string tempUrl = GetPostString("tempurl");
  5793. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5794. // //string res = taobaoHelper.test();
  5795. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5796. // if (res.IndexOf("error_response") != -1)
  5797. // {
  5798. // int sidx = res.IndexOf("sub_msg");
  5799. // int eidx = res.IndexOf("request_id");
  5800. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5801. // returnErrorMsg(msg);
  5802. // return;
  5803. // }
  5804. // int idx = res.IndexOf("waybill_code");
  5805. // int idx2 = res.IndexOf("}]}");
  5806. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5807. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5808. // ReturnSuccess(res);
  5809. // }
  5810. //}
  5811. public void cancel_erp_aftersale()
  5812. {
  5813. if (UrlPostParmsCheck("ctid"))
  5814. {
  5815. string eid = GetPostString("ctid");
  5816. CeErpTradeCell entity = null;
  5817. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5818. if (entity != null)
  5819. {
  5820. //有过处理的售后,取消也不能删除 售 字,保留
  5821. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5822. {
  5823. entity.AfterSaleState = 4;
  5824. }
  5825. else
  5826. entity.AfterSaleState = 0;
  5827. entity.UpdateTime = DateTime.Now;
  5828. entity.Update();
  5829. returnSuccessMsg("操作成功!");
  5830. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5831. return;
  5832. }
  5833. returnErrorMsg("找不到订单记录");
  5834. }
  5835. }
  5836. public void get_erp_aftersalelist()
  5837. {
  5838. DataStruct dStruct = GetPostStruct();
  5839. List<string> lw = new List<string>();
  5840. int st = GetInt("st");
  5841. string tid = GetPostString("ctid");
  5842. if (st == 3)
  5843. {
  5844. if (tid.Length > 0)
  5845. {
  5846. string select_tid = getTidByCtid(tid);
  5847. lw.Add(string.Format("tid='{0}'", select_tid));
  5848. }
  5849. }
  5850. else
  5851. {
  5852. if (tid.Length > 0)
  5853. {
  5854. string select_tid = getTidByCtid(tid);
  5855. lw.Add(string.Format("tid='{0}'", select_tid));
  5856. }
  5857. }
  5858. string shopname = GetPostString("shopname");
  5859. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5860. string buyernick = GetPostString("buyer_nick");
  5861. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5862. string sellermemo = GetPostString("seller_memo");
  5863. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5864. string orderState = GetPostString("orderState");
  5865. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5866. string afterState = GetPostString("afterstate");
  5867. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5868. string date1 = GetPostString("date1");
  5869. string date2 = GetPostString("date2");
  5870. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5871. if (dw.Length > 0) lw.Add(dw);
  5872. string price1 = GetPostString("price1");
  5873. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5874. string price2 = GetPostString("price2");
  5875. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5876. //lw.Add(string.Format("IsRefund!={0}", 1));
  5877. string reason = GetPostString("reason");
  5878. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5879. string method = GetPostString("method");
  5880. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5881. string handler = GetPostString("handler");
  5882. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5883. string handledate1 = GetPostString("handledate1");
  5884. string handledate2 = GetPostString("handledate2");
  5885. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5886. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5887. string finish1 = GetPostString("finishdate1");
  5888. string finish2 = GetPostString("finishdate2");
  5889. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5890. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5891. string afterdate1 = GetPostString("afterdate1");
  5892. string afterdate2 = GetPostString("afterdate2");
  5893. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5894. if (afterDate.Length > 0) lw.Add(afterDate);
  5895. string supplier = GetPostString("supplier");
  5896. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5897. string responsible = GetPostString("responsibleman");
  5898. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5899. string customer = GetPostString("customer");
  5900. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5901. string design = GetPostString("design");
  5902. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5903. string afterMemoType = GetPostString("aftermemotype");
  5904. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5905. string posCode = CurrentUser.UserPost.Post.Code;
  5906. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5907. //{
  5908. // string vstate = GetPostString("vstate");
  5909. // if (vstate.Length > 0)
  5910. // {
  5911. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5912. // }
  5913. // if (posCode == "Supplier")
  5914. // {
  5915. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5916. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5917. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5918. // }
  5919. // else
  5920. // {
  5921. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5922. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5923. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5924. // {
  5925. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5926. // }
  5927. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5928. // {
  5929. // int orgid = CurrentUser.UserPost.OrgID;
  5930. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5931. // }
  5932. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5933. // {
  5934. // string shopid = CurrentUser.User.pemShop;
  5935. // lw.Add(string.Format("shopId in ({0})", shopid));
  5936. // }
  5937. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5938. // //{
  5939. // // int org_id = CurrentUser.UserPost.OrgID;
  5940. // // lw.Add(string.Format("OrgID={0}", org_id));
  5941. // //}
  5942. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5943. // }
  5944. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5945. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5946. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5947. //}
  5948. if (st == 5)
  5949. {
  5950. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5951. {
  5952. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5953. {
  5954. string shopid = CurrentUser.User.pemShop;
  5955. lw.Add(string.Format("shopId in ({0})", shopid));
  5956. }
  5957. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5958. {
  5959. int mrOrgid = CurrentUser.UserPost.OrgID;
  5960. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5961. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5962. }
  5963. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5964. //{
  5965. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5966. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5967. //}
  5968. else
  5969. {
  5970. string userIdStr = "";
  5971. if (posCode == "CustomerService")
  5972. {
  5973. userIdStr = CurrentUser.UserID + "_k";
  5974. }
  5975. else if (posCode == "Designer" || posCode == "wxDesigner")
  5976. {
  5977. userIdStr = CurrentUser.UserID + "_s";
  5978. }
  5979. else if (posCode == "Place")
  5980. {
  5981. userIdStr = CurrentUser.UserID + "_x";
  5982. }
  5983. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5984. }
  5985. }
  5986. string placedate1 = GetPostString("placedate1");
  5987. string placedate2 = GetPostString("placedate2");
  5988. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5989. if (dwplace.Length > 0) lw.Add(dwplace);
  5990. string supState = GetPostString("supState");
  5991. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  5992. string searchType = GetPostString("searchType");
  5993. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  5994. {
  5995. lw.Add(string.Format("BackNum>1"));
  5996. }
  5997. lw.Add(string.Format("AfterSaleState>0"));
  5998. if (ex_psize > 0)
  5999. {
  6000. if (CurrentUser.UserPost.Post.Code == "Finance")
  6001. dStruct.Order = "pay_time desc";
  6002. else
  6003. dStruct.Order = "HandleTime desc";
  6004. }
  6005. else
  6006. dStruct.Order = "HandleTime desc";
  6007. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6008. DataTable dt = WebCache.GetData("view_test", dStruct);
  6009. writeGridDataTableJson(dStruct.TotalCount, dt);
  6010. }
  6011. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6012. //{
  6013. // lw.Add(string.Format("AfterSaleState=4"));
  6014. // string code = CurrentUser.UserPost.Post.Code;
  6015. // if (code == "CustomerService")
  6016. // {
  6017. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6018. // }
  6019. // else if (code == "Designer" || code == "DesignerMr")
  6020. // {
  6021. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6022. // }
  6023. // else if (code == "Place" || code == "PlaceMr")
  6024. // {
  6025. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6026. // }
  6027. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6028. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6029. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6030. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6031. //}
  6032. //else //处理中的售后,待处理和处理中合并
  6033. //{
  6034. // if (afterState.Length <= 0)
  6035. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6036. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6037. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6038. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6039. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6040. //}
  6041. }
  6042. public void get_erp_disagreeftersalelist()
  6043. {
  6044. DataStruct dStruct = GetPostStruct();
  6045. List<string> lw = new List<string>();
  6046. int st = 2;
  6047. string tid = GetPostString("ctid");
  6048. if (tid.Length > 0)
  6049. {
  6050. string select_tid = getTidByCtid(tid);
  6051. lw.Add(string.Format("tid='{0}'", select_tid));
  6052. }
  6053. string shopname = GetPostString("shopname");
  6054. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6055. string buyernick = GetPostString("buyer_nick");
  6056. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6057. string sellermemo = GetPostString("seller_memo");
  6058. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6059. string orderState = GetPostString("orderState");
  6060. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6061. string afterState = GetPostString("afterstate");
  6062. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6063. string date1 = GetPostString("date1");
  6064. string date2 = GetPostString("date2");
  6065. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6066. if (dw.Length > 0) lw.Add(dw);
  6067. string price1 = GetPostString("price1");
  6068. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6069. string price2 = GetPostString("price2");
  6070. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6071. //lw.Add(string.Format("IsRefund!={0}", 1));
  6072. string reason = GetPostString("reason");
  6073. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6074. string method = GetPostString("method");
  6075. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6076. string handler = GetPostString("handler");
  6077. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6078. string handledate1 = GetPostString("handledate1");
  6079. string handledate2 = GetPostString("handledate2");
  6080. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6081. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6082. string afterdate1 = GetPostString("afterdate1");
  6083. string afterdate2 = GetPostString("afterdate2");
  6084. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6085. if (afterDate.Length > 0) lw.Add(afterDate);
  6086. string backdate1 = GetPostString("backdate1");
  6087. string backdate2 = GetPostString("backdate2");
  6088. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6089. if (backDate.Length > 0) lw.Add(backDate);
  6090. string supplier = GetPostString("supplier");
  6091. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6092. string responsible = GetPostString("responsibleman");
  6093. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6094. string customer = GetPostString("customer");
  6095. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6096. string design = GetPostString("design");
  6097. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6098. string afterSaleMemo = GetPostString("afterSaleMemo");
  6099. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6100. string afterMemoType = GetPostString("aftermemotype");
  6101. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6102. string aftersakereason = GetPostString("aftersakereason");
  6103. if (aftersakereason.Length > 0)
  6104. {
  6105. if (aftersakereason == "1")
  6106. {
  6107. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6108. }
  6109. if (aftersakereason == "2")
  6110. {
  6111. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6112. }
  6113. }
  6114. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6115. string poscode = CurrentUser.UserPost.Post.Code;
  6116. if (poscode != "SysAdmin")
  6117. {
  6118. string shopid = CurrentUser.User.pemShop;
  6119. lw.Add(string.Format("shopId in ({0})", shopid));
  6120. }
  6121. string searchType = GetPostString("searchType");
  6122. if (searchType == "wait")
  6123. {
  6124. lw.Add(string.Format("HandleTime is null"));
  6125. }
  6126. if (searchType == "handling")
  6127. {
  6128. lw.Add(string.Format("HandleTime is not null "));
  6129. }
  6130. if (searchType == "back" || searchType == "puBack")
  6131. {
  6132. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6133. }
  6134. if (searchType == "reBack")
  6135. {
  6136. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6137. }
  6138. if (searchType == "moreBack")
  6139. {
  6140. lw.Add(string.Format("backNum > 1"));
  6141. }
  6142. lw.Add(string.Format("(AfterSaleState=5)"));
  6143. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6144. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6145. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6146. writeGridDataTableJson(dStruct.TotalCount, dt);
  6147. }
  6148. public void get_erp_handlingaftersalelist()
  6149. {
  6150. DataStruct dStruct = GetPostStruct();
  6151. List<string> lw = new List<string>();
  6152. int st = 2;
  6153. string tid = GetPostString("ctid");
  6154. if (tid.Length > 0)
  6155. {
  6156. string select_tid = getTidByCtid(tid);
  6157. lw.Add(string.Format("tid='{0}'", select_tid));
  6158. }
  6159. string shopname = GetPostString("shopname");
  6160. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6161. string buyernick = GetPostString("buyer_nick");
  6162. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6163. string sellermemo = GetPostString("seller_memo");
  6164. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6165. string orderState = GetPostString("orderState");
  6166. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6167. string afterState = GetPostString("afterstate");
  6168. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6169. string date1 = GetPostString("date1");
  6170. string date2 = GetPostString("date2");
  6171. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6172. if (dw.Length > 0) lw.Add(dw);
  6173. string price1 = GetPostString("price1");
  6174. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6175. string price2 = GetPostString("price2");
  6176. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6177. //lw.Add(string.Format("IsRefund!={0}", 1));
  6178. string reason = GetPostString("reason");
  6179. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6180. string method = GetPostString("method");
  6181. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6182. string handler = GetPostString("handler");
  6183. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6184. string handledate1 = GetPostString("handledate1");
  6185. string handledate2 = GetPostString("handledate2");
  6186. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6187. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6188. string afterdate1 = GetPostString("afterdate1");
  6189. string afterdate2 = GetPostString("afterdate2");
  6190. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6191. if (afterDate.Length > 0) lw.Add(afterDate);
  6192. string supplier = GetPostString("supplier");
  6193. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6194. string responsible = GetPostString("responsibleman");
  6195. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6196. string customer = GetPostString("customer");
  6197. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6198. string design = GetPostString("design");
  6199. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6200. string afterSaleMemo = GetPostString("afterSaleMemo");
  6201. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6202. string afterMemoType = GetPostString("aftermemotype");
  6203. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6204. string afterresult = GetPostString("afterresult");
  6205. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6206. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6207. string poscode = CurrentUser.UserPost.Post.Code;
  6208. if (poscode != "SysAdmin")
  6209. {
  6210. string shopid = CurrentUser.User.pemShop;
  6211. lw.Add(string.Format("shopId in ({0})", shopid));
  6212. }
  6213. string searchType = GetPostString("searchType");
  6214. if (searchType == "wait")
  6215. {
  6216. lw.Add(string.Format("HandleTime is null"));
  6217. }
  6218. if (searchType == "documentary")
  6219. {
  6220. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6221. }
  6222. if (searchType == "handling")
  6223. {
  6224. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6225. }
  6226. if (searchType == "back" || searchType == "puBack")
  6227. {
  6228. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6229. }
  6230. if (searchType == "reBack")
  6231. {
  6232. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6233. }
  6234. if (afterState.Length <= 0)
  6235. {
  6236. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6237. }
  6238. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6239. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6240. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6241. writeGridDataTableJson(dStruct.TotalCount, dt);
  6242. }
  6243. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6244. //public void get_erp_back_handlingaftersalelist()
  6245. //{
  6246. // DataStruct dStruct = GetPostStruct();
  6247. // List<string> lw = new List<string>();
  6248. // string tid = GetPostString("ctid");
  6249. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6250. // string shopname = GetPostString("shopname");
  6251. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6252. // string buyernick = GetPostString("buyer_nick");
  6253. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6254. // string sellermemo = GetPostString("seller_memo");
  6255. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6256. // string orderState = GetPostString("orderState");
  6257. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6258. // string afterState = GetPostString("afterstate");
  6259. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6260. // string date1 = GetPostString("date1");
  6261. // string date2 = GetPostString("date2");
  6262. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6263. // if (dw.Length > 0) lw.Add(dw);
  6264. // string price1 = GetPostString("price1");
  6265. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6266. // string price2 = GetPostString("price2");
  6267. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6268. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6269. // string reason = GetPostString("reason");
  6270. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6271. // string method = GetPostString("method");
  6272. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6273. // string handler = GetPostString("handler");
  6274. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6275. // string handledate1 = GetPostString("handledate1");
  6276. // string handledate2 = GetPostString("handledate2");
  6277. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6278. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6279. // string afterdate1 = GetPostString("afterdate1");
  6280. // string afterdate2 = GetPostString("afterdate2");
  6281. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6282. // if (afterDate.Length > 0) lw.Add(afterDate);
  6283. // string supplier = GetPostString("supplier");
  6284. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6285. // string responsible = GetPostString("responsibleman");
  6286. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6287. // string customer = GetPostString("customer");
  6288. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6289. // string design = GetPostString("design");
  6290. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6291. // string afterMemoType = GetPostString("aftermemotype");
  6292. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6293. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6294. // if (afterState.Length <= 0)
  6295. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6296. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6297. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6298. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6299. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6300. //}
  6301. public void get_erp_aftersaleverifylist()
  6302. {
  6303. DataStruct dStruct = GetPostStruct();
  6304. List<string> lw = new List<string>();
  6305. string tid = GetPostString("ctid");
  6306. if (tid.Length > 0)
  6307. {
  6308. string select_tid = getTidByCtid(tid);
  6309. lw.Add(string.Format("tid='{0}'", select_tid));
  6310. }
  6311. string shopname = GetPostString("shopname");
  6312. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6313. string buyernick = GetPostString("buyer_nick");
  6314. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6315. string sellermemo = GetPostString("seller_memo");
  6316. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6317. string orderState = GetPostString("orderState");
  6318. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6319. //lw.Add(string.Format("IsRefund!={0}", 1));
  6320. string reason = GetPostString("reason");
  6321. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6322. string method = GetPostString("method");
  6323. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6324. string handler = GetPostString("handler");
  6325. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6326. string handledate1 = GetPostString("handledate1");
  6327. string handledate2 = GetPostString("handledate2");
  6328. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6329. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6330. string finish1 = GetPostString("finishdate1");
  6331. string finish2 = GetPostString("finishdate2");
  6332. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6333. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6334. string supplier = GetPostString("supplier");
  6335. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6336. string responsible = GetPostString("responsibleman");
  6337. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6338. string posCode = CurrentUser.UserPost.Post.Code;
  6339. string vstate = GetPostString("vstate");
  6340. if (vstate.Length > 0)
  6341. {
  6342. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6343. }
  6344. if (posCode == "Supplier")
  6345. {
  6346. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6347. lw.Add(string.Format("VerifyState = 0"));
  6348. lw.Add("type = 1");
  6349. lw.Add(string.Format("AfterSaleState={0}", 3));
  6350. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6351. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6352. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6353. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6354. writeGridDataTableJson(dStruct.TotalCount, dt);
  6355. }
  6356. else if (posCode == "logistics")
  6357. {
  6358. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6359. lw.Add(string.Format("VerifyState = 0"));
  6360. lw.Add("type = 2");
  6361. lw.Add(string.Format("AfterSaleState={0}", 3));
  6362. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6363. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6364. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6365. writeGridDataTableJson(dStruct.TotalCount, dt);
  6366. }
  6367. else
  6368. {
  6369. lw.Add(string.Format("(AfterSaleState = 3)"));
  6370. string reasonState = GetPostString("reasonState");
  6371. lw.Add("type = 0");
  6372. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6373. || posCode == "Summarize" || posCode == "Finance")
  6374. {
  6375. if (reasonState == "2")
  6376. {
  6377. lw.Add("VerifyState = 3");
  6378. }
  6379. else if (reasonState == "1")
  6380. {
  6381. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6382. }
  6383. else
  6384. {
  6385. lw.Add("VerifyState in (0,3)");
  6386. }
  6387. //不加条件,可以看全部
  6388. }
  6389. 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")
  6390. {
  6391. int orgid = CurrentUser.UserPost.OrgID;
  6392. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6393. if (string.IsNullOrEmpty(manageOrgId))
  6394. {
  6395. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6396. }
  6397. else
  6398. {
  6399. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6400. }
  6401. if (reasonState == "1")
  6402. {
  6403. lw.Add("VerifyState = 3");
  6404. }
  6405. else if (reasonState == "2")
  6406. {
  6407. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6408. }
  6409. else
  6410. {
  6411. }
  6412. }
  6413. else
  6414. {
  6415. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6416. }
  6417. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6418. //{
  6419. // int org_id = CurrentUser.UserPost.OrgID;
  6420. // lw.Add(string.Format("OrgID={0}", org_id));
  6421. //}
  6422. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6423. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6424. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6425. writeGridDataTableJson(dStruct.TotalCount, dt);
  6426. }
  6427. }
  6428. public void get_erp_finishaftersalelist()
  6429. {
  6430. DataStruct dStruct = GetPostStruct();
  6431. List<string> lw = new List<string>();
  6432. int st = 4;
  6433. string tid = GetPostString("ctid");
  6434. if (tid.Length > 0)
  6435. {
  6436. string select_tid = getTidByCtid(tid);
  6437. lw.Add(string.Format("tid='{0}'", select_tid));
  6438. }
  6439. string shopname = GetPostString("shopname");
  6440. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6441. //lw.Add(string.Format("IsRefund!={0}", 1));
  6442. string reason = GetPostString("reason");
  6443. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6444. string method = GetPostString("method");
  6445. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6446. string buyernick = GetPostString("buyer_nick");
  6447. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6448. string handler = GetPostString("handler");
  6449. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6450. string handledate1 = GetPostString("handledate1");
  6451. string handledate2 = GetPostString("handledate2");
  6452. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6453. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6454. string finish1 = GetPostString("finishdate1");
  6455. string finish2 = GetPostString("finishdate2");
  6456. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6457. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6458. string supplier = GetPostString("supplier");
  6459. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6460. string responsible = GetPostString("responsibleman");
  6461. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6462. string vstate = GetPostString("vstate");
  6463. if (vstate.Length > 0)
  6464. {
  6465. if ("3".Equals(vstate))
  6466. {
  6467. lw.Add(string.Format("IsTem=1"));
  6468. }
  6469. else
  6470. {
  6471. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6472. }
  6473. }
  6474. lw.Add(string.Format("AfterSaleState=4"));
  6475. string code = CurrentUser.UserPost.Post.Code;
  6476. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6477. {
  6478. //不加条件,可以看全部
  6479. }
  6480. else if (code == "Supplier")
  6481. {
  6482. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6483. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6484. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6485. }
  6486. else if (code == "logistics")
  6487. {
  6488. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6489. lw.Add("type = 2");
  6490. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6491. }
  6492. 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")
  6493. {
  6494. int orgid = CurrentUser.UserPost.OrgID;
  6495. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6496. if (string.IsNullOrEmpty(manageOrgIds))
  6497. {
  6498. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6499. }
  6500. else
  6501. {
  6502. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6503. }
  6504. }
  6505. else
  6506. {
  6507. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6508. }
  6509. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6510. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6511. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6512. writeGridDataTableJson(dStruct.TotalCount, dt);
  6513. }
  6514. public void handle_erp_aftersale()
  6515. {
  6516. if (UrlPostParmsCheck("ctid"))
  6517. {
  6518. string eid = GetPostString("ctid");
  6519. string responStr = GetPostString("AfterSaleResponsible");
  6520. if (responStr.Length <= 0)
  6521. {
  6522. returnErrorMsg("售后责任人不能为空");
  6523. return;
  6524. }
  6525. bool isDesign = false;
  6526. double designFree = 0.00;
  6527. int responsibleId = 0;
  6528. CeErpTradeCell entity = null;
  6529. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6530. if (entity != null)
  6531. {
  6532. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6533. string afterMethod = GetPostString("AfterSaleMethod");
  6534. if (isNeedNewOrder == 1)
  6535. {
  6536. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6537. bool ishav = true;
  6538. if (newentity == null)
  6539. {
  6540. newentity = entity.Clone() as CeErpTradeCell;
  6541. ishav = false;
  6542. newentity.ctid = "S_" + entity.ctid;
  6543. newentity.OrderState = 0;
  6544. //唯一标识
  6545. newentity.OrderSn = newentity.ctid;
  6546. string orderSn = dataHelper.getSaleOrderSn();
  6547. if (orderSn != "")
  6548. {
  6549. newentity.OrderSn = orderSn;
  6550. }
  6551. }
  6552. newentity.UpdateTime = DateTime.Now;
  6553. newentity.AfterSaleState = 0;
  6554. newentity.AfterSaleMethod = afterMethod;
  6555. if (!ishav)
  6556. {
  6557. string memo_str = newentity.seller_memo;
  6558. memo_str = memo_str.Replace("(", "(");
  6559. memo_str = memo_str.Replace(")", ")");
  6560. int sIndex = memo_str.IndexOf("(");
  6561. int eIndex = memo_str.IndexOf(")");
  6562. if (sIndex == -1 || eIndex == -1)
  6563. {
  6564. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6565. return;
  6566. }
  6567. string first = memo_str.Substring(0, sIndex + 1);
  6568. string memoCtid = newentity.OrderSn;
  6569. //if (memoCtid.IndexOf("C") != -1)
  6570. //{
  6571. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6572. //if (CIdx.IndexOf("+") != -1)
  6573. //{
  6574. //CIdx = "C" + CIdx.Split('+')[1];
  6575. //}
  6576. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6577. //}
  6578. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6579. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6580. string newMemo = first + memoCtid + last;
  6581. newentity.seller_memo = newMemo;
  6582. newentity.FinishPlaceTime = null;
  6583. newentity.UnusualTag = 0;
  6584. newentity.UnusualCon = "";
  6585. newentity.UnusualTime = null;
  6586. newentity.AfterSaleMemo = "";
  6587. newentity.AfterSaleMethod = afterMethod;
  6588. newentity.AfterSalePreTime = null;
  6589. newentity.AfterSaleReason = "";
  6590. newentity.AfterSaleResponsible = "";
  6591. newentity.AfterSaleState = 0;
  6592. newentity.AfterSaleTime = null;
  6593. newentity.AfterSaleUserId = 0;
  6594. newentity.AfterSaleSupplierState = 0;
  6595. newentity.LastBillWaybillCode = "";
  6596. newentity.LastBillCpCode = "";
  6597. newentity.FinishAfterSaleTime = null;
  6598. newentity.HandleTime = null;
  6599. newentity.IsSF = 0;
  6600. newentity.IsOldCustomer = 0;
  6601. newentity.UrgencyTime = null;
  6602. newentity.ResponsibleUserId = "";
  6603. newentity.IsVerifyToSupplier = false;
  6604. newentity.payment = 0;
  6605. newentity.CheckMemo = "";
  6606. newentity.OutSid = "";
  6607. newentity.CheckOrderTime = null;
  6608. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6609. }
  6610. newentity.isAfterSaleOrder = 1;
  6611. newentity.IsRefund = 0;
  6612. string receiveMobile = GetPostString("receiver_mobile");
  6613. if (receiveMobile.Length > 0)
  6614. {
  6615. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6616. if (trade != null)
  6617. {
  6618. trade.receiver_name = GetPostString("receiver_name");
  6619. trade.receiver_mobile = receiveMobile;
  6620. trade.receiver_state = GetPostString("receiver_state");
  6621. trade.receiver_city = GetPostString("receiver_city");
  6622. trade.receiver_district = GetPostString("receiver_district");
  6623. trade.receiver_address = GetPostString("receiver_address");
  6624. newentity.IsOffLineOrder = 1;
  6625. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6626. }
  6627. }
  6628. string st = GetPostString("ToState");
  6629. if (st.Length > 0)
  6630. {
  6631. if (newentity.OrderState <= 3)
  6632. {
  6633. newentity.WaitDesignTime = DateTime.Now;
  6634. newentity.StartDesignTime = null;
  6635. newentity.FinishDesignTime = null;
  6636. newentity.OrderState = 3;
  6637. if (st == "下单员")
  6638. {
  6639. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6640. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6641. {
  6642. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6643. }
  6644. }
  6645. else
  6646. {
  6647. newentity.WaitDesignTime = DateTime.Now;
  6648. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6649. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6650. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6651. {
  6652. DataRow user = dt1.Rows[0];
  6653. //找主管
  6654. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6655. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6656. if (dt != null && dt.Rows.Count > 0)
  6657. {
  6658. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6659. newentity.DesignUserId = designMr;
  6660. string key = "aftersale_order_" + designMr;
  6661. if (RedisHelper.HasKey(key))
  6662. {
  6663. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6664. list.Add(newentity.ctid);
  6665. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6666. }
  6667. }
  6668. //账号正常
  6669. if (user["State"].ToString() == "0")
  6670. {
  6671. newentity.DesignUserId = entity.DesignUserId;
  6672. string key = "aftersale_order_" + entity.DesignUserId;
  6673. if (RedisHelper.HasKey(key))
  6674. {
  6675. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6676. list.Add(newentity.ctid);
  6677. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6678. }
  6679. }
  6680. }
  6681. }
  6682. }
  6683. if (entity.IsXianHuo == 1)
  6684. {
  6685. newentity.OrderState = 6;
  6686. entity.FinishPlaceTime = DateTime.Now;
  6687. }
  6688. }
  6689. if (ishav)
  6690. {
  6691. newentity.Update();
  6692. }
  6693. else
  6694. {
  6695. newentity.Create();
  6696. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6697. newCellExtend.ctid = newentity.ctid;
  6698. newCellExtend.orderFrom = 20;
  6699. newCellExtend.orderType = 30;
  6700. if (st == "下单员")
  6701. {
  6702. }
  6703. else
  6704. {
  6705. newCellExtend.ReprintTime = DateTime.Now;
  6706. }
  6707. newCellExtend.Create();
  6708. }
  6709. if (st != "下单员")
  6710. {
  6711. designHelper.API_GetPrintData_CreateOrder(newentity);
  6712. }
  6713. }
  6714. //处理售后扩展
  6715. string resIdStr = GetPostString("ResponsibleUserId");
  6716. string refundFees = GetPostString("refundFrees");
  6717. int IsComplain = GetPostInt("isComplain");
  6718. int IsBad = GetPostInt("isBad");
  6719. string IsOriginal = GetPostString("isOriginal");
  6720. double diffResultPrice = GetPostDouble("diffResultPrice");
  6721. string textResult = GetPostString("textResult");
  6722. string supplierResponsible = GetPostString("supplierResponsible");
  6723. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6724. if (ceErpTradeAfterSaleExtend == null)
  6725. {
  6726. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6727. ceErpTradeAfterSaleExtend.tid = eid;
  6728. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6729. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6730. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6731. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6732. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6733. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6734. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6735. ceErpTradeAfterSaleExtend.Create();
  6736. }
  6737. else
  6738. {
  6739. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6740. {
  6741. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6742. }
  6743. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6744. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6745. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6746. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6747. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6748. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6749. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6750. ceErpTradeAfterSaleExtend.Update();
  6751. }
  6752. int gysid = GetPostInt("ResponsibleSupId");
  6753. if (entity.AfterSaleUserId == 0)
  6754. {
  6755. entity.AfterSaleUserId = CurrentUser.UserID;
  6756. }
  6757. entity.ResponsibleUserId = resIdStr;
  6758. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6759. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6760. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6761. {
  6762. CeErpTradeResponsible.DelByTid(eid, -1);
  6763. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6764. int backNum = 0;
  6765. if (number != null)
  6766. {
  6767. backNum = number.BackNum;
  6768. }
  6769. char[] separator = { ',' };
  6770. string[] sArray = resIdStr.Split(separator);
  6771. string[] refundFreeList = { };
  6772. if (refundFees.Length > 0)
  6773. {
  6774. refundFreeList = refundFees.Split(separator);
  6775. }
  6776. int index = -1;
  6777. foreach (string i in sArray)
  6778. {
  6779. index++;
  6780. if (i.Length <= 0) continue;
  6781. char[] separator2 = { '_' };
  6782. string idstr = i.Split(separator2)[0];
  6783. string idtype = i.Split(separator2)[1];
  6784. double refudFree = 0;
  6785. if (refundFreeList.Length > 0)
  6786. {
  6787. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6788. }
  6789. if (idtype == "s")
  6790. {
  6791. isDesign = true;
  6792. designFree = refudFree;
  6793. }
  6794. int userId = Convert.ToInt32(idstr);
  6795. int type = 0;
  6796. if (idtype == "g")
  6797. {
  6798. type = 1;
  6799. }
  6800. if (idtype == "w")
  6801. {
  6802. type = 2;
  6803. }
  6804. if (idtype == "t")
  6805. {
  6806. type = 3;
  6807. }
  6808. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6809. if (ceErpTradeResponsible == null)
  6810. {
  6811. ceErpTradeResponsible = new CeErpTradeResponsible();
  6812. ceErpTradeResponsible.tid = eid;
  6813. ceErpTradeResponsible.UserId = userId;
  6814. ceErpTradeResponsible.createdTime = DateTime.Now;
  6815. ceErpTradeResponsible.type = type;
  6816. if (type == 1)
  6817. {
  6818. ceErpTradeResponsible.IsSup = 1;
  6819. }
  6820. if (type == 2)
  6821. {
  6822. ceErpTradeResponsible.IsFlow = 1;
  6823. }
  6824. }
  6825. ceErpTradeResponsible.RefundFee = refudFree;
  6826. ceErpTradeResponsible.VerifyState = 0;
  6827. if (userId == 2125 || idtype == "w")
  6828. {
  6829. ceErpTradeResponsible.VerifyState = 1;
  6830. }
  6831. if (idtype == "w" && userId == 101)
  6832. {
  6833. ceErpTradeResponsible.VerifyState = 0;
  6834. }
  6835. if (ceErpTradeResponsible.ID > 0)
  6836. {
  6837. ceErpTradeResponsible.Update();
  6838. }
  6839. else
  6840. {
  6841. ceErpTradeResponsible.Create();
  6842. }
  6843. if (isDesign)
  6844. {
  6845. responsibleId = ceErpTradeResponsible.ID;
  6846. }
  6847. }
  6848. CeErpTradeResponsible.NumByTid(backNum, eid);
  6849. }
  6850. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6851. if (ceErpTradeCellExtend != null)
  6852. {
  6853. ceErpTradeCellExtend.returnVisit = 0;
  6854. ceErpTradeCellExtend.Update();
  6855. }
  6856. if (entity.HandleTime != null)
  6857. {
  6858. if (entity.AfterSaleState == 1)
  6859. {
  6860. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6861. }
  6862. else
  6863. {
  6864. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6865. }
  6866. }
  6867. else
  6868. {
  6869. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6870. entity.HandleTime = DateTime.Now;
  6871. }
  6872. bool isCompale = false;
  6873. if (entity.AfterSaleState == 5)
  6874. {
  6875. isCompale = true;
  6876. entity.AfterSaleState = 3;
  6877. }
  6878. entity.AfterSaleSupplierState = 0;
  6879. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6880. {
  6881. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6882. }
  6883. string sImgs = GetPostString("img");
  6884. entity.AfterSaleSupplierImg = sImgs;
  6885. entity.supRefundType = GetPostString("supRefundType");
  6886. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6887. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6888. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6889. entity.AfterSaleMemoType = GetPostString("MemoType");
  6890. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6891. {
  6892. //entity.AfterSaleSupplierState = 2;
  6893. }
  6894. string df = GetPostString("DeductFee");
  6895. if (df == "")
  6896. {
  6897. df = "0";
  6898. }
  6899. string rf = GetPostString("RefundFee");
  6900. if (rf == "")
  6901. {
  6902. rf = "0";
  6903. }
  6904. string pm = GetPostString("AfterSalePayment");
  6905. if (pm == "")
  6906. {
  6907. pm = "0";
  6908. }
  6909. entity.AfterSalePayment = Convert.ToDouble(pm);
  6910. entity.DeductFee = Convert.ToDouble(df);
  6911. entity.RefundFee = Convert.ToDouble(rf);
  6912. entity.UpdateTime = DateTime.Now;
  6913. entity.Update();
  6914. string toState = GetPostString("ToState");
  6915. string original = GetPostString("isOriginal");
  6916. ApiVo apiVo = new ApiVo();
  6917. apiVo.orderNumber = entity.ctid;
  6918. apiVo.actionName = "afterDesign";
  6919. apiVo.orderRemarks = entity.AfterSaleMethod;
  6920. apiVo.reasonRemarks = entity.AfterSaleReason;
  6921. apiVo.isDesign = isDesign;
  6922. apiVo.designFree = designFree;
  6923. apiVo.responsibleId = responsibleId;
  6924. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6925. if (toState == "设计师")
  6926. {
  6927. apiVo.isOriginal = Convert.ToBoolean(original);
  6928. }
  6929. designHelper.API_WorkCore(apiVo);//afterDesign
  6930. CeErpMethod methodSql = new CeErpMethod();
  6931. methodSql.con = entity.AfterSaleMethod;
  6932. methodSql.addTime = DateTime.Now;
  6933. methodSql.Create();
  6934. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6935. CeErpMethod.ExecuteNonQuery(delsql);
  6936. if (isCompale)
  6937. {
  6938. aftersale_data_change(entity.ctid);
  6939. }
  6940. returnSuccessMsg("操作成功!");
  6941. return;
  6942. }
  6943. returnErrorMsg("找不到订单记录");
  6944. }
  6945. }
  6946. public void ins_erp_toresponsible()
  6947. {
  6948. if (UrlPostParmsCheck("ctid"))
  6949. {
  6950. string eid = GetPostString("ctid");
  6951. CeErpTradeCell entity = null;
  6952. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6953. if (entity != null)
  6954. {
  6955. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6956. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6957. {
  6958. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6959. return;
  6960. }
  6961. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6962. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6963. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6964. if (entity.AfterSalePreTime == null)
  6965. {
  6966. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6967. {
  6968. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6969. }
  6970. }
  6971. entity.AfterSalePreTime = DateTime.Now;
  6972. //预完成给售后主管审核客户问题直接完成
  6973. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6974. {
  6975. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6976. {
  6977. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6978. }
  6979. }
  6980. ceErpTradeAfterSaleExtend.Update();
  6981. entity.AfterSaleState = 2;
  6982. entity.UpdateTime = DateTime.Now;
  6983. entity.Update();
  6984. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  6985. aftersale_data_change(entity.ctid);
  6986. returnSuccessMsg("操作成功!");
  6987. return;
  6988. }
  6989. returnErrorMsg("找不到订单记录");
  6990. }
  6991. }
  6992. public void cancel_erp_aftersaleanddelnew()
  6993. {
  6994. if (UrlPostParmsCheck("ctid"))
  6995. {
  6996. string eid = GetPostString("ctid");
  6997. CeErpTradeCell entity = null;
  6998. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6999. if (entity != null)
  7000. {
  7001. entity.AfterSaleState = 0;
  7002. entity.AfterSaleReason = "";
  7003. entity.AfterSaleMethod = "";
  7004. entity.AfterSaleMemo = "";
  7005. entity.AfterSaleResponsible = "";
  7006. entity.ResponsibleUserId = "";
  7007. entity.DeductFee = 0;
  7008. entity.RefundFee = 0;
  7009. entity.IsArbitrate = 0;
  7010. CeErpTradeResponsible.DelByTid(eid, -1);
  7011. entity.Update();
  7012. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7013. if (after != null)
  7014. {
  7015. if (after.OrderState < 5)
  7016. CeErpTradeCell.DelByCtid("S_" + eid);
  7017. }
  7018. returnSuccessMsg("操作成功!");
  7019. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7020. return;
  7021. }
  7022. returnErrorMsg("找不到订单记录");
  7023. }
  7024. }
  7025. public void get_erp_aftersale_pregather()
  7026. {
  7027. List<string> lw = new List<string>();
  7028. int st = GetInt("st");
  7029. string tid = GetPostString("ctid");
  7030. if (tid.Length > 0)
  7031. {
  7032. string select_tid = getTidByCtid(tid);
  7033. lw.Add(string.Format("tid='{0}'", select_tid));
  7034. }
  7035. string shopname = GetPostString("shopname");
  7036. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7037. string buyernick = GetPostString("buyer_nick");
  7038. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7039. string sellermemo = GetPostString("seller_memo");
  7040. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7041. string orderState = GetPostString("orderState");
  7042. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7043. string reason = GetPostString("reason");
  7044. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7045. string method = GetPostString("method");
  7046. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7047. string handler = GetPostString("handler");
  7048. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7049. string handledate1 = GetPostString("handledate1");
  7050. string handledate2 = GetPostString("handledate2");
  7051. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7052. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7053. string supplier = GetPostString("supplier");
  7054. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7055. string responsible = GetPostString("responsibleman");
  7056. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7057. string customer = GetPostString("customer");
  7058. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7059. string design = GetPostString("design");
  7060. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7061. string afterMemoType = GetPostString("aftermemotype");
  7062. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7063. string afterSaleMemo = GetPostString("afterSaleMemo");
  7064. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7065. string afterresult = GetPostString("afterresult");
  7066. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7067. string poscode = CurrentUser.UserPost.Post.Code;
  7068. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7069. {
  7070. string shopid = CurrentUser.User.pemShop;
  7071. lw.Add(string.Format("shopId in ({0})", shopid));
  7072. }
  7073. var mainwhere = string.Join(" and ", lw.ToArray());
  7074. string ro_json = "";
  7075. string type = GetPostString("gather_type");
  7076. int number = 0;
  7077. if (poscode == "AfterSale")
  7078. {
  7079. //处理中
  7080. if (type == "Handling")
  7081. {
  7082. 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) : ""));
  7083. DataTable dt = null;
  7084. try
  7085. {
  7086. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7087. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7088. }
  7089. catch (Exception e)
  7090. {
  7091. dt = new DataTable();
  7092. }
  7093. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7094. return;
  7095. }
  7096. if (type == "Wait")
  7097. {
  7098. //待处理
  7099. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7100. DataTable dt1 = null;
  7101. try
  7102. {
  7103. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7104. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7105. }
  7106. catch (Exception e)
  7107. {
  7108. dt1 = new DataTable();
  7109. }
  7110. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7111. return;
  7112. }
  7113. if (type == "back")
  7114. {
  7115. //打回
  7116. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7117. DataTable dt2 = null;
  7118. try
  7119. {
  7120. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7121. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7122. }
  7123. catch (Exception e)
  7124. {
  7125. dt2 = new DataTable();
  7126. }
  7127. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7128. return;
  7129. }
  7130. if (type == "preCompletion")
  7131. {
  7132. //预完成
  7133. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7134. DataTable dt3 = null;
  7135. try
  7136. {
  7137. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7138. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7139. }
  7140. catch (Exception e)
  7141. {
  7142. dt3 = new DataTable();
  7143. }
  7144. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7145. return;
  7146. }
  7147. if (type == "documentary")
  7148. {
  7149. //跟单中
  7150. 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) : ""));
  7151. DataTable dt4 = null;
  7152. try
  7153. {
  7154. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7155. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7156. }
  7157. catch (Exception e)
  7158. {
  7159. dt4 = new DataTable();
  7160. }
  7161. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7162. return;
  7163. }
  7164. if (type == "reBack")
  7165. {
  7166. //被打回
  7167. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7168. DataTable dt1 = null;
  7169. try
  7170. {
  7171. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7172. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7173. }
  7174. catch (Exception e)
  7175. {
  7176. dt1 = new DataTable();
  7177. }
  7178. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7179. return;
  7180. }
  7181. }
  7182. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7183. {
  7184. if (type == "puBack")
  7185. {
  7186. //退回
  7187. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7188. DataTable dt = null;
  7189. try
  7190. {
  7191. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7192. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7193. }
  7194. catch (Exception e)
  7195. {
  7196. dt = new DataTable();
  7197. }
  7198. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7199. return;
  7200. }
  7201. if (type == "reBack")
  7202. {
  7203. //打回
  7204. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7205. DataTable dt1 = null;
  7206. try
  7207. {
  7208. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7209. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7210. }
  7211. catch (Exception e)
  7212. {
  7213. dt1 = new DataTable();
  7214. }
  7215. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7216. return;
  7217. }
  7218. if (type == "examEd")
  7219. {
  7220. //已审核
  7221. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7222. DataTable dt2 = null;
  7223. try
  7224. {
  7225. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7226. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7227. }
  7228. catch (Exception e)
  7229. {
  7230. dt2 = new DataTable();
  7231. }
  7232. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7233. return;
  7234. }
  7235. if (type == "waitExam")
  7236. {
  7237. //待审核
  7238. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7239. DataTable dt3 = null;
  7240. try
  7241. {
  7242. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7243. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7244. }
  7245. catch (Exception e)
  7246. {
  7247. dt3 = new DataTable();
  7248. }
  7249. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7250. return;
  7251. }
  7252. if (type == "Handling")
  7253. {
  7254. //处理中
  7255. 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) : ""));
  7256. DataTable dt4 = null;
  7257. try
  7258. {
  7259. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7260. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7261. }
  7262. catch (Exception e)
  7263. {
  7264. dt4 = new DataTable();
  7265. }
  7266. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7267. return;
  7268. }
  7269. if (type == "Wait")
  7270. {
  7271. //待处理
  7272. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7273. DataTable dt5 = null;
  7274. try
  7275. {
  7276. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7277. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7278. }
  7279. catch (Exception e)
  7280. {
  7281. dt5 = new DataTable();
  7282. }
  7283. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7284. return;
  7285. }
  7286. if (type == "documentary")
  7287. {
  7288. //跟单中
  7289. 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) : ""));
  7290. DataTable dt6 = null;
  7291. try
  7292. {
  7293. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7294. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7295. }
  7296. catch (Exception e)
  7297. {
  7298. dt6 = new DataTable();
  7299. }
  7300. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7301. return;
  7302. }
  7303. }
  7304. returnSuccess(ro_json);
  7305. }
  7306. public void end_erp_aftersale()
  7307. {
  7308. if (UrlPostParmsCheck("ctid"))
  7309. {
  7310. string eid = GetPostString("ctid");
  7311. CeErpTradeCell entity = null;
  7312. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7313. if (entity != null)
  7314. {
  7315. string stype = GetPostString("stype");
  7316. string typeStr = stype;
  7317. entity.AfterSaleState = 4;
  7318. entity.FinishAfterSaleTime = DateTime.Now;
  7319. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7320. entity.Update();
  7321. ApiVo apiVo = new ApiVo();
  7322. apiVo.orderNumber = entity.ctid;
  7323. apiVo.actionName = "afterOver";
  7324. designHelper.API_WorkCore(apiVo); //afterOver
  7325. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7326. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7327. CeErpSukuraData.createInfo(entity.ctid, 8);
  7328. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7329. returnSuccessMsg("操作成功!");
  7330. return;
  7331. }
  7332. returnErrorMsg("找不到订单记录");
  7333. }
  7334. }
  7335. public void ins_erp_finishaftersale()
  7336. {
  7337. if (UrlPostParmsCheck("id"))
  7338. {
  7339. string eid = GetPostString("id");
  7340. CeErpTradeResponsible entity = null;
  7341. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7342. if (entity != null)
  7343. {
  7344. entity.VerifyState = 1;
  7345. entity.VerifyTime = DateTime.Now;
  7346. entity.Update();
  7347. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7348. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7349. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7350. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7351. if (dt.Rows.Count <= 0)
  7352. {
  7353. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7354. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7355. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7356. CeErpSukuraData.createInfo(entity.tid, 8);
  7357. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7358. {
  7359. CeErpDesignerBill.Del(entity.tid);
  7360. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7361. }
  7362. }
  7363. returnSuccessMsg("操作成功!");
  7364. return;
  7365. }
  7366. returnErrorMsg("找不到订单记录");
  7367. }
  7368. }
  7369. public void upd_erp_arbitrateaftersale()
  7370. {
  7371. if (UrlPostParmsCheck("id"))
  7372. {
  7373. string eid = GetPostString("id");
  7374. CeErpTradeResponsible entity = null;
  7375. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7376. if (entity != null)
  7377. {
  7378. entity.IsArbitrate = 1;
  7379. entity.ArbitradeMemo = GetPostString("reason");
  7380. entity.VerifyState = 2;
  7381. entity.Update();
  7382. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7383. if (tradecell != null)
  7384. {
  7385. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7386. tradecell.IsArbitrate = 1;
  7387. tradecell.Update();
  7388. }
  7389. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7390. returnSuccessMsg("操作成功!");
  7391. return;
  7392. }
  7393. returnErrorMsg("找不到订单记录");
  7394. }
  7395. }
  7396. public void upd_erp_backaftersale()
  7397. {
  7398. if (UrlPostParmsCheck("tid"))
  7399. {
  7400. string eid = GetPostString("tid");
  7401. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7402. int backNum = 0;
  7403. if (number != null)
  7404. {
  7405. backNum = number.BackNum;
  7406. }
  7407. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7408. CeErpTradeCell entity = null;
  7409. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7410. if (entity != null)
  7411. {
  7412. entity.AfterSaleBackReason = GetPostString("backreason");
  7413. entity.AfterSaleState = 1;
  7414. entity.AfterSaleSupplierState = 0;
  7415. entity.UpdateTime = DateTime.Now;
  7416. entity.Update();
  7417. returnSuccessMsg("操作成功!");
  7418. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7419. return;
  7420. }
  7421. returnErrorMsg("找不到订单记录");
  7422. }
  7423. }
  7424. public void get_erp_supplieraftersalelist()
  7425. {
  7426. DataStruct dStruct = GetPostStruct();
  7427. List<string> lw = new List<string>();
  7428. string tid = GetPostString("ctid");
  7429. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7430. string shopname = GetPostString("shopname");
  7431. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7432. string buyernick = GetPostString("buyer_nick");
  7433. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7434. string sellermemo = GetPostString("seller_memo");
  7435. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7436. string orderState = GetPostString("orderState");
  7437. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7438. string afterState = GetPostString("afterstate");
  7439. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7440. string date1 = GetPostString("date1");
  7441. string date2 = GetPostString("date2");
  7442. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7443. if (dw.Length > 0) lw.Add(dw);
  7444. string price1 = GetPostString("price1");
  7445. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7446. string price2 = GetPostString("price2");
  7447. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7448. string reason = GetPostString("reason");
  7449. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7450. string method = GetPostString("method");
  7451. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7452. string handledate1 = GetPostString("handledate1");
  7453. string handledate2 = GetPostString("handledate2");
  7454. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7455. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7456. string handler = GetPostString("handler");
  7457. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7458. string afterdate1 = GetPostString("afterdate1");
  7459. string afterdate2 = GetPostString("afterdate2");
  7460. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7461. if (afterDate.Length > 0) lw.Add(afterDate);
  7462. string customer = GetPostString("customer");
  7463. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7464. string design = GetPostString("design");
  7465. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7466. string afterMemoType = GetPostString("aftermemotype");
  7467. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7468. string vstate = GetPostString("vstate");
  7469. if (vstate.Length > 0)
  7470. {
  7471. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7472. }
  7473. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7474. string supplier = GetPostString("supplier");
  7475. int supid = commonHelper.getSupplierIDByName(supplier);
  7476. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7477. string posCode = CurrentUser.UserPost.Post.Code;
  7478. if (posCode == "Supplier")
  7479. {
  7480. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7481. }
  7482. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7483. {
  7484. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7485. }
  7486. else
  7487. {
  7488. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7489. }
  7490. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7491. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7492. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7493. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7494. writeGridDataTableJson(dStruct.TotalCount, dt);
  7495. }
  7496. public void upd_erp_supverifyaftersale()
  7497. {
  7498. if (UrlPostParmsCheck("id"))
  7499. {
  7500. string id = GetPostString("id");
  7501. int st = GetPostInt("afterstate");
  7502. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7503. CeErpTradeCell entity = null;
  7504. if (ceErpTradeResponsible != null)
  7505. {
  7506. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7507. }
  7508. string afmemo = GetPostString("supmemo");
  7509. string image = GetPostString("image");
  7510. if (entity != null)
  7511. {
  7512. entity.AfterSaleSupplierState = st;
  7513. entity.AfterSaleSupplierMemo = afmemo;
  7514. if (st == 1)
  7515. {
  7516. ceErpTradeResponsible.VerifyState = 1;
  7517. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7518. ceErpTradeResponsible.Update();
  7519. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7520. if (isAll)
  7521. {
  7522. entity.AfterSaleState = 4;
  7523. entity.FinishAfterSaleTime = DateTime.Now;
  7524. }
  7525. }
  7526. else
  7527. {
  7528. CeErpTradeResponsible.dateByTid(entity.ctid);
  7529. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7530. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7531. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7532. if (num <= 1)
  7533. {
  7534. entity.AfterSaleState = 1;
  7535. }
  7536. else
  7537. {
  7538. entity.AfterSaleState = 5;
  7539. }
  7540. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7541. if (ceErpTradeAfterSaleExtend != null)
  7542. {
  7543. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7544. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7545. ceErpTradeAfterSaleExtend.Update();
  7546. }
  7547. else
  7548. {
  7549. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7550. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7551. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7552. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7553. ceErpTradeAfterSaleExtend.Create();
  7554. }
  7555. }
  7556. if (entity.AfterSaleState == 4)
  7557. {
  7558. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7559. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7560. {
  7561. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7562. }
  7563. ApiVo apiVo = new ApiVo();
  7564. apiVo.orderNumber = entity.ctid;
  7565. apiVo.actionName = "afterOver";
  7566. designHelper.API_WorkCore(apiVo); //afterOver
  7567. }
  7568. entity.UpdateTime = DateTime.Now;
  7569. entity.Update();
  7570. returnSuccessMsg("操作成功!");
  7571. CeErpSukuraData.createInfo(entity.ctid, 8);
  7572. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7573. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7574. return;
  7575. }
  7576. returnErrorMsg("找不到订单记录");
  7577. }
  7578. }
  7579. public void upd_erp_masteraftersale()
  7580. {
  7581. if (UrlPostParmsCheck("id"))
  7582. {
  7583. string id = GetPostString("id");
  7584. int st = GetPostInt("afterstate");
  7585. string afmemo = GetPostString("supmemo");
  7586. string image = GetPostString("image");
  7587. string textResult = GetPostString("textResult");
  7588. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7589. if (ceErpTradeResponsible != null)
  7590. {
  7591. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7592. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7593. ceErpTradeResponsible.Update();
  7594. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7595. if (entity != null)
  7596. {
  7597. entity.AfterSaleSupplierState = st;
  7598. entity.AfterSaleSupplierMemo = afmemo;
  7599. if (st == 1)
  7600. {
  7601. }
  7602. else
  7603. {
  7604. CeErpTradeResponsible.dateByTid(entity.ctid);
  7605. //退回到售后
  7606. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7607. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7608. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7609. if (num <= 1)
  7610. {
  7611. entity.AfterSaleState = 1;
  7612. }
  7613. else
  7614. {
  7615. entity.AfterSaleState = 5;
  7616. }
  7617. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7618. if (ceErpTradeAfterSaleExtend != null)
  7619. {
  7620. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7621. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7622. ceErpTradeAfterSaleExtend.Update();
  7623. }
  7624. else
  7625. {
  7626. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7627. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7628. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7629. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7630. ceErpTradeAfterSaleExtend.Create();
  7631. }
  7632. }
  7633. entity.UpdateTime = DateTime.Now;
  7634. entity.Update();
  7635. returnSuccessMsg("操作成功!");
  7636. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7637. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7638. return;
  7639. }
  7640. }
  7641. returnErrorMsg("找不到订单记录");
  7642. }
  7643. }
  7644. public void upd_erp_personaftersale()
  7645. {
  7646. if (UrlPostParmsCheck("id"))
  7647. {
  7648. //林小连
  7649. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7650. {
  7651. upd_erp_masteraftersale();
  7652. return;
  7653. }
  7654. string id = GetPostString("id");
  7655. int st = GetPostInt("afterstate");
  7656. string afmemo = GetPostString("supmemo");
  7657. string image = GetPostString("image");
  7658. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7659. if (ceErpTradeResponsible != null)
  7660. {
  7661. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7662. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7663. ceErpTradeResponsible.Update();
  7664. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7665. if (entity != null)
  7666. {
  7667. entity.AfterSaleSupplierMemo = afmemo;
  7668. entity.AfterSaleSupplierState = st;
  7669. if (st == 1)
  7670. {
  7671. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7672. if (isAll)
  7673. {
  7674. entity.AfterSaleState = 4;
  7675. entity.FinishAfterSaleTime = DateTime.Now;
  7676. }
  7677. }
  7678. else
  7679. {
  7680. CeErpTradeResponsible.dateByTid(entity.ctid);
  7681. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7682. if (ceErpTradeAfterSaleExtend != null)
  7683. {
  7684. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7685. ceErpTradeAfterSaleExtend.Update();
  7686. }
  7687. else
  7688. {
  7689. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7690. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7691. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7692. ceErpTradeAfterSaleExtend.Create();
  7693. }
  7694. //退回到主管
  7695. //entity.AfterSaleState = 2;
  7696. }
  7697. if (entity.AfterSaleState == 4)
  7698. {
  7699. ApiVo apiVo = new ApiVo();
  7700. apiVo.orderNumber = entity.ctid;
  7701. apiVo.actionName = "afterOver";
  7702. designHelper.API_WorkCore(apiVo); //afterOver
  7703. }
  7704. entity.UpdateTime = DateTime.Now;
  7705. entity.Update();
  7706. returnSuccessMsg("操作成功!");
  7707. CeErpSukuraData.createInfo(entity.ctid, 8);
  7708. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7709. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7710. return;
  7711. }
  7712. }
  7713. returnErrorMsg("找不到订单记录");
  7714. }
  7715. }
  7716. public void set_erp_supplierrefundtag()
  7717. {
  7718. if (UrlPostParmsCheck("ctid"))
  7719. {
  7720. string eid = GetPostString("ctid");
  7721. CeErpTradeCell entity = null;
  7722. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7723. if (entity != null)
  7724. {
  7725. entity.IsSupplierRefund = GetPostInt("tag");
  7726. entity.Update();
  7727. returnSuccessMsg("操作成功!");
  7728. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7729. return;
  7730. }
  7731. returnErrorMsg("找不到订单记录");
  7732. }
  7733. }
  7734. public void get_erp_refundlist()
  7735. {
  7736. DataStruct dStruct = GetPostStruct();
  7737. List<string> lw = new List<string>();
  7738. string tid = GetPostString("tid");
  7739. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7740. //string rid = GetPostString("refund_id");
  7741. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7742. string shopname = GetPostString("shopname");
  7743. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7744. string buyernick = GetPostString("buyer_nick");
  7745. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7746. string customer = GetPostString("customer");
  7747. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7748. string design = GetPostString("design");
  7749. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7750. string sellermemo = GetPostString("seller_memo");
  7751. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7752. //string date1 = GetPostString("date1");
  7753. //string date2 = GetPostString("date2");
  7754. //string dateType = GetPostString("dateType");
  7755. //if (dateType.Length > 0)
  7756. //{
  7757. // if (dateType == "1001") dateType = "0";
  7758. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7759. // if (searchDT.Count == 2)
  7760. // {
  7761. // date1 = searchDT[0].ToString();
  7762. // date2 = searchDT[1].ToString();
  7763. // }
  7764. //}
  7765. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7766. //if (dw.Length > 0) lw.Add(dw);
  7767. string redate1 = GetPostString("refunddate1");
  7768. string redate2 = GetPostString("refunddate2");
  7769. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7770. if (dwdate.Length > 0) lw.Add(dwdate);
  7771. string price1 = GetPostString("price1");
  7772. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7773. string price2 = GetPostString("price2");
  7774. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7775. string ispartrefund = GetPostString("ispartrefund");
  7776. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7777. string refundState = GetPostString("refundvstate");
  7778. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7779. int st = GetInt("st");
  7780. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7781. {
  7782. string responsible = GetPostString("responsibleman");
  7783. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7784. lw.Add(string.Format("RefundState>={0}", st));
  7785. string code = CurrentUser.UserPost.Post.Code;
  7786. if (code == "CustomerService")
  7787. {
  7788. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7789. }
  7790. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7791. {
  7792. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7793. }
  7794. else if (code == "Place" || code == "PlaceMr")
  7795. {
  7796. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7797. }
  7798. dStruct.Order = "RefundState asc,created desc";
  7799. }
  7800. else if (st == 10)
  7801. {
  7802. string responsible = GetPostString("responsibleman");
  7803. if (responsible == "空白")
  7804. {
  7805. lw.Add(string.Format("ResponsibleUserName = ''"));
  7806. }
  7807. else if (responsible.Length > 0)
  7808. {
  7809. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7810. }
  7811. lw.Add(string.Format("RefundState>=0"));
  7812. dStruct.Order = "created desc";
  7813. }
  7814. else
  7815. {
  7816. string responsible = GetPostString("responsibleman");
  7817. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7818. lw.Add(string.Format("RefundState={0}", st));
  7819. dStruct.Order = "created desc";
  7820. }
  7821. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7822. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7823. dt.Columns.Add("refund_fees");
  7824. foreach (DataRow dr in dt.Rows)
  7825. {
  7826. String status = dr["status"].ToString();
  7827. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7828. {
  7829. dr["refund_fees"] = dr["refund_fee"];
  7830. }
  7831. else
  7832. {
  7833. dr["refund_fees"] = "0.0";
  7834. }
  7835. }
  7836. writeGridDataTableJson(dStruct.TotalCount, dt);
  7837. }
  7838. public void get_erp_refunddesignlist()
  7839. {
  7840. DataStruct dStruct = GetPostStruct();
  7841. List<string> lw = new List<string>();
  7842. string tid = GetPostString("tid");
  7843. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7844. string shopname = GetPostString("shopname");
  7845. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7846. string buyernick = GetPostString("buyer_nick");
  7847. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7848. string customer = GetPostString("customer");
  7849. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7850. string design = GetPostString("design");
  7851. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7852. string sellermemo = GetPostString("seller_memo");
  7853. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7854. string redate1 = GetPostString("refunddate1");
  7855. string redate2 = GetPostString("refunddate2");
  7856. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7857. if (dwdate.Length > 0) lw.Add(dwdate);
  7858. string price1 = GetPostString("price1");
  7859. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7860. string price2 = GetPostString("price2");
  7861. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7862. string ispartrefund = GetPostString("ispartrefund");
  7863. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7864. string designerorg = GetPostString("designerorg");
  7865. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7866. string refundState = GetPostString("refundState");
  7867. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7868. int myOrgid = CurrentUser.UserPost.OrgID;
  7869. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7870. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7871. {
  7872. if (CurrentUser.User.TeamIds.Length > 0)
  7873. {
  7874. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7875. }
  7876. else
  7877. {
  7878. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7879. }
  7880. }
  7881. else if ("SysAdmin".Equals(myOrgCode))
  7882. {
  7883. }
  7884. else
  7885. {
  7886. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7887. {
  7888. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7889. }
  7890. else
  7891. {
  7892. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7893. }
  7894. }
  7895. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7896. dStruct.Order = "created desc";
  7897. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7898. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7899. dt.Columns.Add("refund_fees");
  7900. foreach (DataRow dr in dt.Rows)
  7901. {
  7902. String status = dr["status"].ToString();
  7903. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7904. {
  7905. dr["refund_fees"] = dr["refund_fee"];
  7906. }
  7907. else
  7908. {
  7909. dr["refund_fees"] = "0.0";
  7910. }
  7911. }
  7912. writeGridDataTableJson(dStruct.TotalCount, dt);
  7913. }
  7914. public void handle_erp_refundtag()
  7915. {
  7916. if (UrlPostParmsCheck("refund_id"))
  7917. {
  7918. string eid = GetPostString("refund_id");
  7919. string respMan = GetPostString("ResponsibleName");
  7920. if (respMan.Length <= 0)
  7921. {
  7922. returnErrorMsg("责任人不能为空");
  7923. return;
  7924. }
  7925. CeErpTradeRefund entity = null;
  7926. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7927. if (entity != null)
  7928. {
  7929. entity.ResponsibleUserName = respMan;
  7930. string userid = GetPostString("ResponsibleUserId");
  7931. if (userid.Length > 0)
  7932. {
  7933. entity.ResponsibleUserId = userid;
  7934. }
  7935. entity.Memo = GetPostString("Memo");
  7936. if (respMan.IndexOf("客服") != -1 ||
  7937. respMan.IndexOf("设计师") != -1 ||
  7938. respMan.IndexOf("下单员") != -1)
  7939. {
  7940. entity.RefundState = 2;
  7941. }
  7942. else
  7943. {
  7944. entity.RefundState = 3;
  7945. }
  7946. entity.modified = DateTime.Now;
  7947. entity.Update();
  7948. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7949. returnSuccessMsg("操作成功!");
  7950. return;
  7951. }
  7952. returnErrorMsg("找不到订单记录");
  7953. }
  7954. }
  7955. public void handle_erp_designrefundtag()
  7956. {
  7957. if (UrlPostParmsCheck("refund_id"))
  7958. {
  7959. string eid = GetPostString("refund_id");
  7960. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7961. if (ceErpTradeCellExtend == null)
  7962. {
  7963. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7964. ceErpTradeCellExtend.ctid = eid;
  7965. }
  7966. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7967. if (ceErpTradeCellExtend.ID > 0)
  7968. {
  7969. ceErpTradeCellExtend.Update();
  7970. }
  7971. else
  7972. {
  7973. ceErpTradeCellExtend.Create();
  7974. }
  7975. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7976. returnSuccessMsg("操作成功!");
  7977. return;
  7978. }
  7979. returnErrorMsg("找不到订单记录");
  7980. }
  7981. public void upd_erp_refundverify()
  7982. {
  7983. if (UrlPostParmsCheck("refund_id"))
  7984. {
  7985. string eid = GetPostString("refund_id");
  7986. CeErpTradeRefund entity = null;
  7987. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7988. if (entity != null)
  7989. {
  7990. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  7991. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  7992. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  7993. {
  7994. entity.RefundState = 2;
  7995. }
  7996. else
  7997. {
  7998. entity.RefundState = 3;
  7999. }
  8000. entity.Update();
  8001. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8002. returnSuccessMsg("操作成功!");
  8003. return;
  8004. }
  8005. returnErrorMsg("找不到订单记录");
  8006. }
  8007. }
  8008. public void upd_erp_refundapprove()
  8009. {
  8010. if (UrlPostParmsCheck("refund_id"))
  8011. {
  8012. string eid = GetPostString("refund_id");
  8013. CeErpTradeRefund entity = null;
  8014. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8015. if (entity != null)
  8016. {
  8017. int apr = GetPostInt("approve");
  8018. if (apr == 0)
  8019. {
  8020. entity.RefundState = 1;
  8021. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8022. }
  8023. else if (apr == 1)
  8024. {
  8025. entity.RefundState = 3;
  8026. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8027. }
  8028. entity.modified = DateTime.Now;
  8029. entity.Update();
  8030. returnSuccessMsg("操作成功!");
  8031. return;
  8032. }
  8033. returnErrorMsg("找不到订单记录");
  8034. }
  8035. }
  8036. public void get_erp_billlist()
  8037. {
  8038. DataStruct dStruct = GetPostStruct();
  8039. List<string> lw = new List<string>();
  8040. string title = GetPostString("title");
  8041. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8042. string tid = GetPostString("tid");
  8043. string tids = GetPostString("tids");
  8044. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8045. if (tids.Length > 0)
  8046. {
  8047. tids = "'" + tids + "'";
  8048. tids = tids.Replace(",", "','");
  8049. lw.Add(string.Format("tid in ({0})", tids));
  8050. }
  8051. string shopname = GetPostString("shopname");
  8052. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8053. string buyernick = GetPostString("buyer_nick");
  8054. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8055. string customer = GetPostString("customer");
  8056. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8057. string date1 = GetPostString("date1");
  8058. string date2 = GetPostString("date2");
  8059. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8060. if (dw.Length > 0) lw.Add(dw);
  8061. string price1 = GetPostString("price1");
  8062. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8063. string price2 = GetPostString("price2");
  8064. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8065. string returndate1 = GetPostString("returndate1");
  8066. string returndate2 = GetPostString("returndate2");
  8067. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8068. if (dw1.Length > 0) lw.Add(dw1);
  8069. string billtype = GetPostString("billtype");
  8070. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8071. string billstate = GetPostString("billstate");
  8072. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8073. string usershop = CurrentUser.User.pemShop;
  8074. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8075. dStruct.Order = "createTime desc";
  8076. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8077. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8078. //foreach (DataRow dr in dt.Rows)
  8079. //{
  8080. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8081. //}
  8082. writeGridDataTableJson(dStruct.TotalCount, dt);
  8083. }
  8084. public void modify_erp_billinfo()
  8085. {
  8086. if (UrlPostParmsCheck("ID"))
  8087. {
  8088. string eid = GetPostString("ID");
  8089. CeErpBill bill_entity = null;
  8090. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8091. if (bill_entity != null)
  8092. {
  8093. bill_entity.tid = GetPostString("tid");
  8094. bill_entity.title = GetPostString("title");
  8095. bill_entity.tax = GetPostString("tax");
  8096. bill_entity.bank = GetPostString("bank");
  8097. bill_entity.bankac = GetPostString("bankac");
  8098. bill_entity.address = GetPostString("address");
  8099. bill_entity.phone = GetPostString("phone");
  8100. bill_entity.price = GetPostString("price");
  8101. bill_entity.productId = GetPostInt("ProductName");
  8102. bill_entity.num = GetPostInt("num");
  8103. bill_entity.unit = GetPostString("unit");
  8104. bill_entity.type = GetPostString("type");
  8105. bill_entity.sendType = GetPostString("SendType");
  8106. bill_entity.email = GetPostString("email");
  8107. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8108. bill_entity.shopName = GetPostString("ShopName");
  8109. bill_entity.applymemo = GetPostString("applymemo");
  8110. bill_entity.modifyTime = DateTime.Now;
  8111. bill_entity.createTime = DateTime.Now;
  8112. bill_entity.state = 0;
  8113. bill_entity.Update();
  8114. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8115. returnSuccessMsg("发票修改成功!");
  8116. return;
  8117. }
  8118. returnErrorMsg("找不到对应记录");
  8119. }
  8120. }
  8121. public void set_erp_invoicing()
  8122. {
  8123. if (UrlPostParmsCheck("id"))
  8124. {
  8125. try
  8126. {
  8127. string eid = GetPostString("id");
  8128. CeErpBill bill_entity = null;
  8129. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8130. if (bill_entity != null)
  8131. {
  8132. int ComId = GetPostInt("ComId");
  8133. //string memo = GetPostString("Memo");
  8134. int allInfo = GetPostInt("allinfo");
  8135. string clert = CurrentUser.User.Name;
  8136. //string detailValue = GetPostString("detailvalue");
  8137. string billId = bill_entity.billOrderId;
  8138. string[] billIdList = billId.Split(',');
  8139. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8140. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8141. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8142. {
  8143. billCount += 1;
  8144. }
  8145. if (billId.Length <= 0 || billIdList.Length != billCount)
  8146. {
  8147. bill_entity.billOrderId = "";
  8148. string prebill = "ltb";
  8149. for (int idx = 1; idx <= billCount; idx++)
  8150. {
  8151. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8152. string billoid = prebill + idx + dtstr;
  8153. bill_entity.billOrderId += billoid;
  8154. if (idx < billCount)
  8155. {
  8156. bill_entity.billOrderId += ",";
  8157. }
  8158. }
  8159. }
  8160. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8161. if (bill_entity.state == 5)
  8162. {
  8163. string errMsg = bill_entity.failerror;
  8164. string[] errlist = errMsg.Split('|');
  8165. string[] errTags = new string[errlist.Length];
  8166. for (int itag = 0; itag < errlist.Length; itag++)
  8167. {
  8168. if (errlist[itag].Length <= 0) continue;
  8169. errTags[itag] = errlist[itag].Split('&')[0];
  8170. }
  8171. for (int iii = 0; iii < errTags.Length; iii++)
  8172. {
  8173. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8174. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8175. if (billOrderList.Length >= erroBillOrderTag)
  8176. {
  8177. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8178. if (needModifyBillId.Length <= 19)
  8179. {
  8180. needModifyBillId = needModifyBillId + "1";
  8181. }
  8182. else
  8183. {
  8184. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8185. last = last + 1;
  8186. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8187. }
  8188. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8189. }
  8190. }
  8191. }
  8192. bool isHaveBillSucces = false;
  8193. string totalRes = "";
  8194. bill_entity.failerror = "";
  8195. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8196. {
  8197. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8198. totalRes += res;
  8199. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8200. {
  8201. isHaveBillSucces = true;
  8202. bill_entity.comId = ComId;
  8203. bill_entity.state = 1;
  8204. bill_entity.executeTime = DateTime.Now;
  8205. bill_entity.executeUser = clert;
  8206. }
  8207. else
  8208. {
  8209. bill_entity.state = 5;
  8210. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8211. }
  8212. }
  8213. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8214. bill_entity.Update();
  8215. if (isHaveBillSucces)
  8216. {
  8217. StringBuilder sql = new StringBuilder();
  8218. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8219. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8220. }
  8221. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8222. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8223. {
  8224. returnErrorMsg("开票失败");
  8225. }
  8226. else
  8227. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8228. return;
  8229. }
  8230. returnErrorMsg("找不到对应记录");
  8231. }
  8232. catch (Exception ex)
  8233. {
  8234. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8235. returnErrorMsg("操作失败");
  8236. }
  8237. }
  8238. }
  8239. public void get_erp_invoicing_back()
  8240. {
  8241. if (UrlPostParmsCheck("id"))
  8242. {
  8243. try
  8244. {
  8245. string id = GetPostString("id");
  8246. CeErpBill entiy = CeErpBill.Get(id);
  8247. if (entiy != null)
  8248. {
  8249. if (entiy.state == 0)
  8250. {
  8251. returnErrorMsg("发票还未开具");
  8252. return;
  8253. }
  8254. string[] billOrderList = entiy.billOrderId.Split(',');
  8255. int iTag = 0;
  8256. entiy.fplsh = "";
  8257. entiy.fpdm = "";
  8258. entiy.fphm = "";
  8259. foreach (string billOrderId in billOrderList)
  8260. {
  8261. iTag++;
  8262. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8263. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8264. {
  8265. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8266. try
  8267. {
  8268. Invoicing_get_response_Obj iObj = null;
  8269. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8270. if (iObj != null)
  8271. {
  8272. entiy.state = 2;
  8273. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8274. entiy.fpdm += iObj.list[0].c_fpdm;
  8275. entiy.fphm += iObj.list[0].c_fphm;
  8276. if (iTag < billOrderList.Length)
  8277. {
  8278. entiy.fplsh += ",";
  8279. entiy.fpdm += ",";
  8280. entiy.fphm += ",";
  8281. }
  8282. entiy.Update();
  8283. }
  8284. StringBuilder sql = new StringBuilder();
  8285. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8286. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8287. returnSuccessMsg("开票成功");
  8288. }
  8289. catch (Exception ex)
  8290. {
  8291. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8292. }
  8293. return;
  8294. }
  8295. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8296. {
  8297. var res_obj = new
  8298. {
  8299. data = "开票中"
  8300. };
  8301. string ro_json = JsonConvert.SerializeObject(res_obj);
  8302. returnSuccess(ro_json);
  8303. return;
  8304. }
  8305. else
  8306. {
  8307. int eidx = res.IndexOf("c_resultmsg");
  8308. int lidx = res.IndexOf("c_status");
  8309. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8310. entiy.state = 5;
  8311. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8312. entiy.Update();
  8313. returnErrorMsg("开票失败");
  8314. return;
  8315. }
  8316. }
  8317. }
  8318. }
  8319. catch (Exception ex)
  8320. {
  8321. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8322. }
  8323. return;
  8324. }
  8325. }
  8326. public void get_erp_invoicing()
  8327. {
  8328. if (UrlPostParmsCheck("id"))
  8329. {
  8330. try
  8331. {
  8332. string id = GetPostString("id");
  8333. CeErpBill entiy = CeErpBill.Get(id);
  8334. if (entiy != null)
  8335. {
  8336. if (entiy.state == 0)
  8337. {
  8338. returnErrorMsg("发票还未开具");
  8339. return;
  8340. }
  8341. if (entiy.sendType == "纸质发票")
  8342. {
  8343. if (entiy.img.Length <= 0)
  8344. {
  8345. returnErrorMsg("查无纸质发票");
  8346. return;
  8347. }
  8348. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8349. returnSuccess(returnres);
  8350. return;
  8351. }
  8352. string[] billOrderList = entiy.billOrderId.Split(',');
  8353. int iTag = 0;
  8354. string fpUrl = "";
  8355. entiy.fplsh = "";
  8356. entiy.fpdm = "";
  8357. entiy.fphm = "";
  8358. foreach (string billOrderId in billOrderList)
  8359. {
  8360. iTag++;
  8361. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8362. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8363. {
  8364. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8365. Invoicing_get_response_Obj iObj = null;
  8366. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8367. if (iObj != null)
  8368. {
  8369. //entiy.state = 2;
  8370. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8371. entiy.fpdm += iObj.list[0].c_fpdm;
  8372. entiy.fphm += iObj.list[0].c_fphm;
  8373. if (iTag < billOrderList.Length)
  8374. {
  8375. entiy.fplsh += ",";
  8376. entiy.fpdm += ",";
  8377. entiy.fphm += ",";
  8378. }
  8379. entiy.Update();
  8380. fpUrl += iObj.list[0].c_url + ",";
  8381. }
  8382. //returnSuccess(res);
  8383. StringBuilder sql = new StringBuilder();
  8384. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8385. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8386. }
  8387. else
  8388. {
  8389. int eidx = res.IndexOf("c_resultmsg");
  8390. //int lidx = res.IndexOf("c_status");
  8391. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8392. //开票失败
  8393. entiy.state = 5;
  8394. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8395. entiy.Update();
  8396. returnErrorMsg("开票失败");
  8397. return;
  8398. }
  8399. }
  8400. var returnObj = new
  8401. {
  8402. data = fpUrl
  8403. };
  8404. string ro_json = JsonConvert.SerializeObject(returnObj);
  8405. returnSuccess(ro_json);
  8406. }
  8407. }
  8408. catch (Exception ex)
  8409. {
  8410. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8411. }
  8412. return;
  8413. }
  8414. }
  8415. public void save_erp_billimg()
  8416. {
  8417. if (UrlPostParmsCheck("id"))
  8418. {
  8419. string eid = GetPostString("id");
  8420. CeErpBill bill_entity = null;
  8421. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8422. if (bill_entity != null)
  8423. {
  8424. bill_entity.img = GetPostString("img");
  8425. bill_entity.executeTime = DateTime.Now;
  8426. bill_entity.state = 2;
  8427. bill_entity.Update();
  8428. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8429. returnSuccessMsg("保存成功");
  8430. }
  8431. return;
  8432. }
  8433. }
  8434. public void upd_erp_billreturnback()
  8435. {
  8436. if (UrlPostParmsCheck("id"))
  8437. {
  8438. int eid = GetPostInt("id");
  8439. CeErpBill bill_entity = null;
  8440. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8441. if (bill_entity != null)
  8442. {
  8443. bill_entity.state = 3;
  8444. bill_entity.returnReason = GetPostString("reason");
  8445. bill_entity.Update();
  8446. returnSuccessMsg("驳回成功!");
  8447. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8448. }
  8449. return;
  8450. }
  8451. }
  8452. public void cancel_erp_bill()
  8453. {
  8454. if (UrlPostParmsCheck("id"))
  8455. {
  8456. int eid = GetPostInt("id");
  8457. int detailValue = GetPostInt("detailvalue");
  8458. CeErpBill bill_entity = null;
  8459. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8460. string cres = "";
  8461. string gres = "";
  8462. if (bill_entity != null)
  8463. {
  8464. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8465. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8466. {
  8467. int iTag = 0;
  8468. bill_entity.fplsh = "";
  8469. bill_entity.fpdm = "";
  8470. bill_entity.fphm = "";
  8471. foreach (string billOrderId in billOrderList)
  8472. {
  8473. iTag++;
  8474. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8475. if (gres.IndexOf("success") != -1)
  8476. {
  8477. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8478. Invoicing_get_response_Obj iObj = null;
  8479. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8480. if (iObj != null)
  8481. {
  8482. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8483. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8484. bill_entity.fphm += iObj.list[0].c_fphm;
  8485. if (iTag < billOrderList.Length)
  8486. {
  8487. bill_entity.fplsh += ",";
  8488. bill_entity.fpdm += ",";
  8489. bill_entity.fphm += ",";
  8490. }
  8491. bill_entity.Update();
  8492. }
  8493. }
  8494. else
  8495. {
  8496. returnErrorMsg(gres);
  8497. return;
  8498. }
  8499. }
  8500. }
  8501. if (bill_entity.sendType == "纸质发票")
  8502. {
  8503. //作废
  8504. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8505. //if (DateTime.Now.Month == extime.Month)
  8506. //{
  8507. //cres = taobaoHelper.cancel_invoicing(eid);
  8508. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8509. //{
  8510. bill_entity.state = 4;//已作废
  8511. bill_entity.Update();
  8512. returnSuccessMsg("发票已作废");
  8513. return;
  8514. //}
  8515. //else
  8516. //{
  8517. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8518. // bill_entity.Update();
  8519. // returnErrorMsg(cres);
  8520. // return;
  8521. //}
  8522. //}
  8523. //else
  8524. //{
  8525. // returnErrorMsg("纸质发票只能作废本月的发票");
  8526. // return;
  8527. //}
  8528. }
  8529. //红冲
  8530. int redTag = 0;
  8531. string[] fpdmList = bill_entity.fpdm.Split(',');
  8532. string[] fphmList = bill_entity.fphm.Split(',');
  8533. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8534. {
  8535. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8536. return;
  8537. }
  8538. foreach (string billOrderId in billOrderList)
  8539. {
  8540. redTag++;
  8541. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8542. cres += onecres;
  8543. cres += ",";
  8544. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8545. {
  8546. bill_entity.state = 4;//已作废
  8547. //bill_entity.Update();
  8548. //returnSuccessMsg("发票已红冲");
  8549. }
  8550. else if (onecres.IndexOf("重复冲红") != -1)
  8551. {
  8552. bill_entity.state = 4;//已作废
  8553. //bill_entity.Update();
  8554. //returnSuccessMsg("发票已红冲");
  8555. }
  8556. else
  8557. {
  8558. string errmsg = commonHelper.KeepChinese(onecres);
  8559. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8560. }
  8561. }
  8562. bill_entity.Update();
  8563. if (cres.IndexOf("失败") != -1)
  8564. returnErrorMsg("红冲失败");
  8565. else
  8566. returnSuccessMsg("发票已红冲");
  8567. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8568. return;
  8569. }
  8570. return;
  8571. }
  8572. }
  8573. public void del_erp_billorder()
  8574. {
  8575. if (UrlPostParmsCheck("id"))
  8576. {
  8577. string eid = GetPostString("id");
  8578. CeErpBill.Del(eid);
  8579. CeErpBill bill = CeErpBill.Get(eid);
  8580. if (bill != null)
  8581. {
  8582. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8583. }
  8584. returnSuccessMsg("删除成功");
  8585. }
  8586. }
  8587. public void finish_erp_bill()
  8588. {
  8589. if (UrlPostParmsCheck("ids"))
  8590. {
  8591. string eids = GetPostString("ids");
  8592. string[] list = eids.Split(',');
  8593. foreach (string eid in list)
  8594. {
  8595. CeErpBill bill = CeErpBill.Get(eid);
  8596. if (bill != null)
  8597. {
  8598. bill.state = 2;
  8599. bill.Update();
  8600. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8601. }
  8602. }
  8603. returnSuccessMsg("操作成功");
  8604. }
  8605. }
  8606. public void get_erp_returncash()
  8607. {
  8608. DataStruct dStruct = GetPostStruct();
  8609. List<string> lw = new List<string>();
  8610. string tid = GetPostString("tid");
  8611. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8612. string shopname = GetPostString("shopname");
  8613. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8614. string buyernick = GetPostString("buyer_nick");
  8615. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8616. string customer = GetPostString("customer");
  8617. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8618. string returndate1 = GetPostString("returndate1");
  8619. string returndate2 = GetPostString("returndate2");
  8620. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8621. if (dw.Length > 0) lw.Add(dw);
  8622. string finishDate1 = GetPostString("finishdate1");
  8623. string finishDate2 = GetPostString("finishdate2");
  8624. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8625. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8626. string returntype = GetPostString("returntype");
  8627. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8628. string returnvstate = GetPostString("returnvstate");
  8629. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8630. dStruct.Order = "created desc";
  8631. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8632. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8633. writeGridDataTableJson(dStruct.TotalCount, dt);
  8634. }
  8635. public void get_erp_staygoods()
  8636. {
  8637. DataStruct dStruct = GetPostStruct();
  8638. List<string> lw = new List<string>();
  8639. string tid = GetPostString("tid");
  8640. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8641. string shopname = GetPostString("shopname");
  8642. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8643. string wangwang = GetPostString("wangwang");
  8644. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8645. string customer = GetPostString("customer");
  8646. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8647. string returndate1 = GetPostString("returndate1");
  8648. string returndate2 = GetPostString("returndate2");
  8649. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8650. if (dw.Length > 0) lw.Add(dw);
  8651. string finishDate1 = GetPostString("finishdate1");
  8652. string finishDate2 = GetPostString("finishdate2");
  8653. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8654. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8655. string returnvstate = GetPostString("returnvstate");
  8656. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8657. string persuadetype = GetPostString("persuadetype");
  8658. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8659. string customerOrg = GetPostString("customerOrg");
  8660. if (customerOrg.Length > 0)
  8661. {
  8662. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8663. }
  8664. dStruct.Order = "creata_time desc";
  8665. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8666. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8667. writeGridDataTableJson(dStruct.TotalCount, dt);
  8668. }
  8669. public void upd_erp_staygoods()
  8670. {
  8671. if (UrlPostParmsCheck("id"))
  8672. {
  8673. int eid = GetPostInt("id");
  8674. CeErpStayGoods entity = null;
  8675. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8676. if (entity != null)
  8677. {
  8678. entity.audit_type = 1;
  8679. entity.audit_time = DateTime.Now;
  8680. entity.audit_u_id = CurrentUser.UserID;
  8681. entity.audit_u_name = CurrentUser.UserName;
  8682. entity.Update();
  8683. returnSuccessMsg("审核成功!");
  8684. return;
  8685. }
  8686. returnErrorMsg("找不到订单记录");
  8687. }
  8688. }
  8689. public void upd_erp_stayGoodsback()
  8690. {
  8691. if (UrlPostParmsCheck("id"))
  8692. {
  8693. int eid = GetPostInt("id");
  8694. CeErpStayGoods entity = null;
  8695. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8696. if (entity != null)
  8697. {
  8698. entity.audit_text = GetPostString("reason");
  8699. entity.audit_type = 2;
  8700. entity.audit_time = DateTime.Now;
  8701. entity.audit_u_id = CurrentUser.UserID;
  8702. entity.audit_u_name = CurrentUser.UserName;
  8703. entity.Update();
  8704. returnSuccessMsg("退回成功!");
  8705. return;
  8706. }
  8707. returnErrorMsg("找不到订单记录");
  8708. }
  8709. }
  8710. public void upd_erp_returncashverify()
  8711. {
  8712. if (UrlPostParmsCheck("ID"))
  8713. {
  8714. int eid = GetPostInt("ID");
  8715. CeErpReturnCash entity = null;
  8716. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8717. if (entity != null)
  8718. {
  8719. entity.cashstate = 1;
  8720. entity.verifytime = DateTime.Now;
  8721. entity.verifyuserid = CurrentUser.UserID;
  8722. entity.Update();
  8723. returnSuccessMsg("审核成功!");
  8724. return;
  8725. }
  8726. returnErrorMsg("找不到订单记录");
  8727. }
  8728. }
  8729. public void upd_all_erp_returncashverify()
  8730. {
  8731. if (UrlPostParmsCheck("ID"))
  8732. {
  8733. String[] list = GetPostString("ID").Split(',');
  8734. CeErpReturnCash entity = null;
  8735. for (int i = 0; i < list.Length; i++)
  8736. {
  8737. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8738. if (entity != null)
  8739. {
  8740. if (entity.cashstate == 1)
  8741. {
  8742. returnErrorMsg("已审核过的订单不需要在审核!");
  8743. return;
  8744. }
  8745. entity.cashstate = 1;
  8746. entity.verifytime = DateTime.Now;
  8747. entity.verifyuserid = CurrentUser.UserID;
  8748. entity.Update();
  8749. }
  8750. }
  8751. returnSuccessMsg("审核成功!");
  8752. return;
  8753. }
  8754. }
  8755. public void upd_erp_returncashback()
  8756. {
  8757. if (UrlPostParmsCheck("ID"))
  8758. {
  8759. int eid = GetPostInt("ID");
  8760. CeErpReturnCash entity = null;
  8761. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8762. if (entity != null)
  8763. {
  8764. entity.backreason = GetPostString("reason");
  8765. entity.cashstate = 2;
  8766. entity.verifytime = DateTime.Now;
  8767. entity.verifyuserid = CurrentUser.UserID;
  8768. entity.Update();
  8769. returnSuccessMsg("退回成功!");
  8770. return;
  8771. }
  8772. returnErrorMsg("找不到订单记录");
  8773. }
  8774. }
  8775. public void upd_erp_returnprice()
  8776. {
  8777. if (UrlPostParmsCheck("ID"))
  8778. {
  8779. int eid = GetPostInt("ID");
  8780. CeErpReturnCash entity = null;
  8781. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8782. if (entity != null)
  8783. {
  8784. if (entity.cashstate == 1)
  8785. {
  8786. returnErrorMsg("审核通过了不能改");
  8787. return;
  8788. }
  8789. entity.returnprice = GetPostDouble("returnprice");
  8790. entity.Update();
  8791. returnSuccessMsg("修改成功!");
  8792. return;
  8793. }
  8794. returnErrorMsg("找不到订单记录");
  8795. }
  8796. }
  8797. public void del_erp_returncash()
  8798. {
  8799. if (UrlPostParmsCheck("ID"))
  8800. {
  8801. int eid = GetPostInt("ID");
  8802. CeErpReturnCash.Del(eid);
  8803. returnSuccessMsg("操作成功");
  8804. return;
  8805. }
  8806. }
  8807. public void test_for_do_sql()
  8808. {
  8809. string sql = GetPostString("sqlstr");
  8810. if (sql.Length > 0)
  8811. {
  8812. try
  8813. {
  8814. DbHelper.DbConn.ExecuteNonQuery(sql);
  8815. var res_obj = new
  8816. {
  8817. data = "成功",
  8818. };
  8819. string ro_json = JsonConvert.SerializeObject(res_obj);
  8820. returnSuccess(ro_json);
  8821. }
  8822. catch (Exception ex)
  8823. {
  8824. var res_obj = new
  8825. {
  8826. data = ex.Message,
  8827. };
  8828. string ro_json = JsonConvert.SerializeObject(res_obj);
  8829. returnSuccess(ro_json);
  8830. }
  8831. }
  8832. }
  8833. public void get_user_info()
  8834. {
  8835. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8836. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8837. }
  8838. public void get_total_data()
  8839. {
  8840. int userId = CurrentUser.UserID;
  8841. string sql = "";
  8842. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8843. {
  8844. 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);
  8845. }
  8846. else
  8847. {
  8848. 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 " +
  8849. "(select ID from CE_ErpUser where ID = {0}) d " +
  8850. "left join " +
  8851. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8852. ") a on d.ID = a.id left join " +
  8853. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8854. ") b on a.id = b.id1 left join" +
  8855. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8856. ") c on a.id = c.id2;", userId);
  8857. }
  8858. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8859. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8860. }
  8861. public void get_date_area_total_data2()
  8862. {
  8863. int userId = CurrentUser.UserID;
  8864. string date_type = GetPostString("timetype");
  8865. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8866. string sql = "";
  8867. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8868. {
  8869. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8870. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8871. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8872. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8873. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8874. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8875. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8876. ") a on e.ID = a.id left join " +
  8877. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8878. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8879. ") b on a.id = b.id1 " +
  8880. "left join " +
  8881. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8882. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8883. ") c on a.id = c.id2 " +
  8884. "left join " +
  8885. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8886. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8887. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8888. }
  8889. else
  8890. {
  8891. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8892. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8893. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8894. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8895. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8896. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8897. ") a on e.ID = a.id left join " +
  8898. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8899. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8900. ") c on a.id = c.id2 " +
  8901. "left join " +
  8902. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8903. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8904. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8905. }
  8906. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8907. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8908. }
  8909. public void get_date_area_total_data()
  8910. {
  8911. int userId = CurrentUser.UserID;
  8912. string date_type = GetPostString("timetype");
  8913. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8914. string date1 = searchDT[0].ToString();
  8915. string date2 = searchDT[1].ToString();
  8916. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8917. {
  8918. SqlParameter[] sqlParameter ={
  8919. new SqlParameter("@userId", SqlDbType.Int,4),
  8920. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8921. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8922. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8923. };
  8924. sqlParameter[0].Value = userId;
  8925. sqlParameter[1].Value = date1;
  8926. sqlParameter[2].Value = date2;
  8927. sqlParameter[3].Direction = ParameterDirection.Output;
  8928. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8929. string res = sqlParameter[3].Value.ToString();
  8930. var res_obj = new
  8931. {
  8932. data = res
  8933. };
  8934. string ro_json = JsonConvert.SerializeObject(res_obj);
  8935. returnSuccess(ro_json);
  8936. }
  8937. else
  8938. {
  8939. SqlParameter[] sqlParameter ={
  8940. new SqlParameter("@userId", SqlDbType.Int,4),
  8941. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8942. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8943. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8944. };
  8945. sqlParameter[0].Value = userId;
  8946. sqlParameter[1].Value = date1;
  8947. sqlParameter[2].Value = date2;
  8948. sqlParameter[3].Direction = ParameterDirection.Output;
  8949. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8950. string res = sqlParameter[3].Value.ToString();
  8951. var res_obj = new
  8952. {
  8953. data = res
  8954. };
  8955. string ro_json = JsonConvert.SerializeObject(res_obj);
  8956. returnSuccess(ro_json);
  8957. }
  8958. //writeGridDataViewJson(dt.Rows.Count, dv);
  8959. }
  8960. public void get_order_list()
  8961. {
  8962. string strFields = GetPostString("paraFields");
  8963. string strOrder = GetPostString("paraOrder");
  8964. string strWhere = GetPostString("paraWhere");
  8965. string strPageSize = GetPostString("paraPageSize");
  8966. DataStruct dStruct = GetPostStruct();
  8967. dStruct.PageSize = int.Parse(strPageSize);
  8968. dStruct.Fileds = strFields;
  8969. dStruct.Order = strOrder;
  8970. dStruct.MainWhere = strWhere;
  8971. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8972. writeGridDataTableJson(dStruct.TotalCount, dt);
  8973. }
  8974. ////获取待开始订单列表
  8975. //public void get_wait_design_order_list()
  8976. //{
  8977. // string date_type = GetPostString("date_type");
  8978. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8979. // DataStruct dStruct = GetPostStruct();
  8980. // dStruct.PageSize = 1000;
  8981. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8982. // List<string> lw = new List<string>();
  8983. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8984. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  8985. // dStruct.Order = "WaitDesignTime asc";
  8986. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8987. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8988. // writeGridDataTableJson(dStruct.TotalCount, dt);
  8989. //}
  8990. //获取完成单量排名
  8991. public void get_finish_order_count_ranking()
  8992. {
  8993. /* string date_type = GetPostString("date_type");
  8994. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8995. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8996. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8997. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  8998. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8999. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9000. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9001. writeGridDataTableJson(0, new DataTable());
  9002. }
  9003. public void get_finish_order_amount_ranking()
  9004. {
  9005. /*string date_type = GetPostString("date_type");
  9006. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9007. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9008. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9009. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9010. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9011. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9012. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9013. writeGridDataTableJson(0, new DataTable());
  9014. }
  9015. public void get_finish_refund_count_ranking()
  9016. {
  9017. string date_type = GetPostString("date_type");
  9018. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9019. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9020. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9021. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9022. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9023. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9024. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9025. writeGridDataTableJson(dt.Rows.Count, dt);
  9026. }
  9027. public void get_finish_refund_amount_ranking()
  9028. {
  9029. string date_type = GetPostString("date_type");
  9030. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9031. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9032. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9033. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9034. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9035. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9036. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9037. writeGridDataTableJson(dt.Rows.Count, dt);
  9038. }
  9039. public void set_erp_finishorder_director()
  9040. {
  9041. if (UrlPostParmsCheck("ctid"))
  9042. {
  9043. string eid = GetPostString("ctid");
  9044. CeErpTradeCell entity = null;
  9045. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9046. if (entity != null)
  9047. {
  9048. entity.OrderState = 8;
  9049. entity.Update();
  9050. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9051. returnSuccessMsg("操作成功!");
  9052. return;
  9053. }
  9054. returnErrorMsg("找不到记录");
  9055. }
  9056. }
  9057. public void get_erp_placeregistlist()
  9058. {
  9059. DataStruct dStruct = GetPostStruct();
  9060. List<string> lw = new List<string>();
  9061. string outsid = GetPostString("outsid");
  9062. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9063. string memo = GetPostString("memo");
  9064. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9065. string filename = GetPostString("filename");
  9066. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9067. string islate = GetPostString("islate");
  9068. if (islate.Length > 0)
  9069. {
  9070. if (islate == "1")
  9071. lw.Add(string.Format("OutLate>0"));
  9072. else
  9073. lw.Add(string.Format("OutLate=0"));
  9074. }
  9075. string placedate1 = GetPostString("placedate1");
  9076. string placedate2 = GetPostString("placedate2");
  9077. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9078. if (dw.Length > 0) lw.Add(dw);
  9079. string deliveryDate1 = GetPostString("deliverydate1");
  9080. string deliveryDate2 = GetPostString("deliverydate2");
  9081. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9082. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9083. dStruct.Order = "ID desc";
  9084. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9085. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9086. writeGridDataTableJson(dStruct.TotalCount, dt);
  9087. }
  9088. public void ins_erp_placeregist()
  9089. {
  9090. if (UrlPostParmsCheck("id"))
  9091. {
  9092. string eid = GetPostString("id");
  9093. CeErpPlaceRegister entity = null;
  9094. if (eid == "0")//新增
  9095. {
  9096. entity = new CeErpPlaceRegister();
  9097. string xdTime = GetPostString("placeTime");
  9098. if (xdTime.Length > 0)
  9099. {
  9100. entity.PlactTime = Convert.ToDateTime(xdTime);
  9101. }
  9102. string fhTime = GetPostString("deliveryTime");
  9103. if (fhTime.Length > 0)
  9104. {
  9105. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9106. }
  9107. string preTime = GetPostString("preOutTime");
  9108. if (preTime.Length > 0)
  9109. {
  9110. entity.PreOutTime = Convert.ToDateTime(preTime);
  9111. }
  9112. entity.DeliveryCount = GetPostInt("deliveryCount");
  9113. entity.ReceiveCount = GetPostInt("receiveCount");
  9114. entity.OutSid = GetPostString("outSid");
  9115. entity.FileName = GetPostString("fileName");
  9116. entity.Memo = GetPostString("memo");
  9117. entity.AddUserId = CurrentUser.UserID;
  9118. entity.CreateTime = DateTime.Now;
  9119. entity.Img = GetPostString("img");
  9120. entity.Supplier = GetPostInt("supplier");
  9121. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9122. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9123. {
  9124. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9125. DateTime dt2 = (DateTime)entity.PreOutTime;
  9126. TimeSpan span = dt1.Subtract(dt2);
  9127. if (span.Days > 0)
  9128. {
  9129. entity.OutLate = span.Days;
  9130. }
  9131. }
  9132. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9133. entity.Create();
  9134. returnSuccessMsg("添加成功!");
  9135. return;
  9136. }
  9137. else //修改
  9138. {
  9139. entity = CeErpPlaceRegister.Get(eid);
  9140. if (entity != null)
  9141. {
  9142. string xdTime = GetPostString("placeTime");
  9143. if (xdTime.Length > 0)
  9144. {
  9145. entity.PlactTime = Convert.ToDateTime(xdTime);
  9146. }
  9147. string fhTime = GetPostString("deliveryTime");
  9148. if (fhTime.Length > 0)
  9149. {
  9150. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9151. }
  9152. string preTime = GetPostString("preOutTime");
  9153. if (preTime.Length > 0)
  9154. {
  9155. entity.PreOutTime = Convert.ToDateTime(preTime);
  9156. }
  9157. entity.DeliveryCount = GetPostInt("deliveryCount");
  9158. entity.ReceiveCount = GetPostInt("receiveCount");
  9159. if (entity.DeliveryCount == entity.ReceiveCount)
  9160. {
  9161. entity.CurState = "已完成";
  9162. }
  9163. else
  9164. {
  9165. entity.CurState = "未完成";
  9166. }
  9167. entity.OutSid = GetPostString("outSid");
  9168. entity.FileName = GetPostString("fileName");
  9169. entity.Memo = GetPostString("memo");
  9170. entity.Img = GetPostString("img");
  9171. entity.Supplier = GetPostInt("supplier");
  9172. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9173. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9174. {
  9175. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9176. DateTime dt2 = (DateTime)entity.PreOutTime;
  9177. TimeSpan span = dt1.Subtract(dt2);
  9178. if (span.Days > 0)
  9179. {
  9180. entity.OutLate = span.Days;
  9181. }
  9182. }
  9183. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9184. entity.Update();
  9185. returnSuccessMsg("修改成功");
  9186. return;
  9187. }
  9188. returnErrorMsg("找不到对应的记录");
  9189. return;
  9190. }
  9191. }
  9192. returnErrorMsg("缺少必要参数");
  9193. }
  9194. public void del_erp_placeregist()
  9195. {
  9196. string eid = GetPostString("id");
  9197. CeErpPlaceRegister.Del(eid);
  9198. returnSuccessMsg("删除成功!");
  9199. return;
  9200. }
  9201. public void ins_erp_placeregistbyorder()
  9202. {
  9203. string ctid = GetPostString("ctid");
  9204. if (ctid.Length > 0)
  9205. {
  9206. StringBuilder sql = new StringBuilder();
  9207. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9208. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9209. if (dt.Rows.Count > 0)
  9210. {
  9211. foreach (DataRow dr in dt.Rows)
  9212. {
  9213. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9214. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9215. entity.AddUserId = CurrentUser.UserID;
  9216. entity.tid = dr["tid"].ToString();
  9217. entity.Did = Convert.ToString(dr["ctid"]);
  9218. entity.splitTag = dr["SplitTag"].ToString();
  9219. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9220. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9221. if (pre_ctid.Length > 0)
  9222. {
  9223. sellmemo = sellmemo.Replace(pre_ctid, "");
  9224. }
  9225. sellmemo = sellmemo.Replace("[", "");
  9226. sellmemo = sellmemo.Replace("]", "");
  9227. entity.FileName = sellmemo;
  9228. string count = dr["ProductCount"].ToString();
  9229. int usecount = commonHelper.getIntCountFromString(count);
  9230. entity.DeliveryCount = usecount;
  9231. entity.CurState = "未完成";
  9232. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9233. {
  9234. entity.Supplier = 24;//dl手提袋定制
  9235. }
  9236. else
  9237. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9238. entity.CreateTime = DateTime.Now;
  9239. entity.Create();
  9240. }
  9241. returnSuccessMsg("操作成功");
  9242. return;
  9243. }
  9244. returnErrorMsg("没有找到对应订单");
  9245. return;
  9246. }
  9247. returnErrorMsg("缺少订单编号");
  9248. return;
  9249. }
  9250. public void get_erp_persuadelist()
  9251. {
  9252. DataStruct dStruct = GetPostStruct();
  9253. List<string> lw = new List<string>();
  9254. string ctid = GetPostString("ctid");
  9255. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9256. string shopname = GetPostString("shopname");
  9257. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9258. string buyernick = GetPostString("buyer_nick");
  9259. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9260. string customer = GetPostString("customer");
  9261. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9262. string returndate1 = GetPostString("returndate1");
  9263. string returndate2 = GetPostString("returndate2");
  9264. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9265. if (dw.Length > 0) lw.Add(dw);
  9266. string finishDate1 = GetPostString("finishdate1");
  9267. string finishDate2 = GetPostString("finishdate2");
  9268. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9269. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9270. string persuadetype = GetPostString("persuadetype");
  9271. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9272. string returnvstate = GetPostString("returnvstate");
  9273. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9274. dStruct.Order = "created desc";
  9275. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9276. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9277. writeGridDataTableJson(dStruct.TotalCount, dt);
  9278. }
  9279. public void upd_erp_returnpersuadeback()
  9280. {
  9281. if (UrlPostParmsCheck("ID"))
  9282. {
  9283. int eid = GetPostInt("ID");
  9284. CeErpPersuade entity = null;
  9285. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9286. if (entity != null)
  9287. {
  9288. entity.backreason = GetPostString("reason");
  9289. entity.pstate = 2;
  9290. entity.verifytime = DateTime.Now;
  9291. entity.verifyuserid = CurrentUser.UserID;
  9292. entity.Update();
  9293. returnSuccessMsg("退回成功!");
  9294. return;
  9295. }
  9296. returnErrorMsg("找不到订单记录");
  9297. }
  9298. }
  9299. public void upd_erp_returnpersuadeverify()
  9300. {
  9301. if (UrlPostParmsCheck("ID"))
  9302. {
  9303. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9304. {
  9305. returnErrorMsg("暂无权限审核");
  9306. return;
  9307. }
  9308. int eid = GetPostInt("ID");
  9309. CeErpPersuade entity = null;
  9310. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9311. if (entity != null)
  9312. {
  9313. entity.pstate = 1;
  9314. entity.verifytime = DateTime.Now;
  9315. entity.verifyuserid = CurrentUser.UserID;
  9316. entity.Update();
  9317. returnSuccessMsg("审核成功!");
  9318. return;
  9319. }
  9320. returnErrorMsg("找不到订单记录");
  9321. }
  9322. }
  9323. public void del_erp_persuade()
  9324. {
  9325. if (UrlPostParmsCheck("ID"))
  9326. {
  9327. int eid = GetPostInt("ID");
  9328. CeErpPersuade.Del(eid);
  9329. returnSuccessMsg("操作成功");
  9330. return;
  9331. }
  9332. }
  9333. public void get_erp_oldcustoupload()
  9334. {
  9335. DataStruct dStruct = GetPostStruct();
  9336. List<string> lw = new List<string>();
  9337. string buyernick = GetPostString("buyer_nick");
  9338. if (buyernick.Length > 0)
  9339. {
  9340. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9341. }
  9342. else
  9343. return;
  9344. dStruct.Order = "pay_time desc";
  9345. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9346. DataTable dt = null;
  9347. dt = WebCache.GetData("view_erptradecell", dStruct);
  9348. writeGridDataTableJson(dStruct.TotalCount, dt);
  9349. }
  9350. public void get_erp_checkorderlist()
  9351. {
  9352. DataStruct dStruct = GetPostStruct();
  9353. List<string> lw = new List<string>();
  9354. string tid = GetPostString("ctid");
  9355. if (tid.Length > 0)
  9356. {
  9357. string select_tid = getTidByCtid(tid);
  9358. lw.Add(string.Format("tid='{0}'", select_tid));
  9359. }
  9360. string shopname = GetPostString("shopname");
  9361. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9362. string buyernick = GetPostString("buyer_nick");
  9363. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9364. string customer = GetPostString("customer");
  9365. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9366. string design = GetPostString("design");
  9367. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9368. string orderState = GetPostString("orderState");
  9369. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9370. string address = GetPostString("address");
  9371. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9372. string sellermemo = GetPostString("seller_memo");
  9373. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9374. string supplier = GetPostString("supplier");
  9375. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9376. {
  9377. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9378. }
  9379. else
  9380. {
  9381. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9382. }
  9383. string date1 = GetPostString("date1");
  9384. string date2 = GetPostString("date2");
  9385. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9386. if (dw.Length > 0) lw.Add(dw);
  9387. string placedate1 = GetPostString("placedate1");
  9388. string placedate2 = GetPostString("placedate2");
  9389. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9390. if (fdw.Length > 0) lw.Add(fdw);
  9391. string price1 = GetPostString("price1");
  9392. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9393. string price2 = GetPostString("price2");
  9394. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9395. string checkst = GetPostString("checkstate");
  9396. if (checkst.Length > 0 && "10".Equals(checkst))
  9397. {
  9398. lw.Add(string.Format("CheckOut>0"));
  9399. }
  9400. else
  9401. {
  9402. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9403. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9404. }
  9405. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9406. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9407. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9408. writeGridDataTableJson(dStruct.TotalCount, dt);
  9409. }
  9410. public void ins_erp_startCheck()
  9411. {
  9412. if (UrlPostParmsCheck("ctid"))
  9413. {
  9414. string eid = GetPostString("ctid");
  9415. CeErpTradeCell entity = null;
  9416. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9417. if (entity != null)
  9418. {
  9419. entity.MemoOpt = 4;
  9420. entity.UpdateTime = DateTime.Now;
  9421. entity.Update();
  9422. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9423. CeErpSukuraData.createInfo(entity.ctid, 6);
  9424. returnSuccessMsg("操作成功!");
  9425. return;
  9426. }
  9427. returnErrorMsg("找不到记录");
  9428. }
  9429. }
  9430. public void upd_erp_sendXlw()
  9431. {
  9432. if (UrlPostParmsCheck("ctid"))
  9433. {
  9434. string eid = GetPostString("ctid");
  9435. CeErpTradeCell entity = null;
  9436. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9437. if (entity != null)
  9438. {
  9439. if (entity.IsSendGift == 1)
  9440. {
  9441. returnErrorMsg("请勿重复标记");
  9442. return;
  9443. }
  9444. entity.IsSendGift = 1;
  9445. entity.Update();
  9446. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9447. returnSuccessMsg("操作成功!");
  9448. return;
  9449. }
  9450. returnErrorMsg("找不到记录");
  9451. }
  9452. }
  9453. public void cancel_sendXlw()
  9454. {
  9455. if (UrlPostParmsCheck("ctid"))
  9456. {
  9457. string eid = GetPostString("ctid");
  9458. CeErpTradeCell entity = null;
  9459. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9460. if (entity != null)
  9461. {
  9462. if (entity.IsSendGift == 0)
  9463. {
  9464. returnErrorMsg("未标记小礼物");
  9465. return;
  9466. }
  9467. entity.IsSendGift = 0;
  9468. entity.Update();
  9469. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9470. returnSuccessMsg("操作成功!");
  9471. return;
  9472. }
  9473. returnErrorMsg("找不到记录");
  9474. }
  9475. }
  9476. public void get_erp_designbill()
  9477. {
  9478. DataStruct dStruct = GetPostStruct();
  9479. List<string> lw = new List<string>();
  9480. int isMy = GetInt("my");
  9481. if (isMy == 1)
  9482. {
  9483. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9484. }
  9485. string tid = GetPostString("tid");
  9486. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9487. string userName = GetPostString("design");
  9488. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9489. string price1 = GetPostString("price1");
  9490. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9491. string price2 = GetPostString("price2");
  9492. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9493. string rePrice1 = GetPostString("rePrice1");
  9494. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9495. string rePrice2 = GetPostString("rePrice2");
  9496. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9497. string designerType = GetPostString("designerType");
  9498. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9499. string orderState = GetPostString("orderState");
  9500. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9501. string endTime1 = GetPostString("endTime1");
  9502. string endTime2 = GetPostString("endTime2");
  9503. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9504. if (dw.Length > 0) lw.Add(dw);
  9505. string isDk = GetPostString("isDk");
  9506. if (isDk == "1")
  9507. {
  9508. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9509. }
  9510. else if (isDk == "0")
  9511. {
  9512. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9513. }
  9514. dStruct.Order = "oid, create_time desc";
  9515. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9516. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9517. writeGridDataTableJson(dStruct.TotalCount, dt);
  9518. }
  9519. public void upd_erp_designerbill()
  9520. {
  9521. if (UrlPostParmsCheck("ID"))
  9522. {
  9523. string eid = GetPostString("ID");
  9524. CeErpDesignerBill entity = null;
  9525. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9526. if (entity != null)
  9527. {
  9528. if (GetPostDouble("designerpirce") > 0)
  9529. {
  9530. entity.realPrice = GetPostDouble("designerpirce");
  9531. entity.update_time = DateTime.Now;
  9532. entity.update_u_id = CurrentUser.UserID;
  9533. entity.update_u_name = CurrentUser.UserName;
  9534. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9535. entity.Update();
  9536. returnSuccessMsg("操作成功!");
  9537. return;
  9538. }
  9539. else
  9540. {
  9541. entity.price = GetPostDouble("price");
  9542. entity.update_time = DateTime.Now;
  9543. entity.update_u_id = CurrentUser.UserID;
  9544. entity.update_u_name = CurrentUser.UserName;
  9545. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9546. entity.Update();
  9547. returnSuccessMsg("操作成功!");
  9548. return;
  9549. }
  9550. }
  9551. returnErrorMsg("找不到记录");
  9552. }
  9553. }
  9554. public void audit_erp_designerbill()
  9555. {
  9556. if (UrlPostParmsCheck("ID"))
  9557. {
  9558. string eid = GetPostString("ID");
  9559. CeErpDesignerBill entity = null;
  9560. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9561. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9562. if (entity != null)
  9563. {
  9564. entity.realPrice = GetPostDouble("designerpirce");
  9565. entity.update_time = DateTime.Now;
  9566. entity.update_u_id = CurrentUser.UserID;
  9567. entity.update_u_name = CurrentUser.UserName;
  9568. entity.isAudit = 1;
  9569. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9570. entity.Update();
  9571. if (orderEntity != null)
  9572. {
  9573. orderEntity.IsReadTag = 3;
  9574. orderEntity.Update();
  9575. }
  9576. returnSuccessMsg("操作成功!");
  9577. return;
  9578. }
  9579. returnErrorMsg("找不到记录");
  9580. }
  9581. }
  9582. public void all_audit_erp_designerbill()
  9583. {
  9584. if (UrlPostParmsCheck("idList"))
  9585. {
  9586. string[] list = GetPostString("idList").Split(',');
  9587. CeErpDesignerBill entity = null;
  9588. for (int i = 0; i < list.Length; i++)
  9589. {
  9590. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9591. if (entity == null) return;
  9592. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9593. if (orderEntity == null) return;
  9594. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9595. entity.update_time = DateTime.Now;
  9596. entity.update_u_id = CurrentUser.UserID;
  9597. entity.update_u_name = CurrentUser.UserName;
  9598. entity.isAudit = 1;
  9599. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9600. entity.Update();
  9601. orderEntity.IsReadTag = 3;
  9602. orderEntity.Update();
  9603. }
  9604. returnSuccessMsg("操作成功!");
  9605. return;
  9606. }
  9607. }
  9608. public void get_erp_sameorders()
  9609. {
  9610. if (UrlPostParmsCheck("ctid"))
  9611. {
  9612. string eid = GetPostString("ctid");
  9613. CeErpTradeCell entity = null;
  9614. entity = CeErpTradeCell.GetByCtid(eid);
  9615. if (entity != null)
  9616. {
  9617. StringBuilder sql = new StringBuilder();
  9618. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9619. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9620. var res = new
  9621. {
  9622. data = dt.Rows.Count
  9623. };
  9624. string ro_jsond = JsonConvert.SerializeObject(res);
  9625. returnSuccess(ro_jsond);
  9626. return;
  9627. }
  9628. returnErrorMsg("未找到订单");
  9629. return;
  9630. }
  9631. returnErrorMsg("缺少必要的参数");
  9632. }
  9633. public void get_erp_islasthavesameorder()
  9634. {
  9635. if (UrlPostParmsCheck("ctid"))
  9636. {
  9637. string eid = GetPostString("ctid");
  9638. string[] ctidList = eid.Split(',');
  9639. StringBuilder sql = new StringBuilder();
  9640. string tisCtid = "";
  9641. foreach (string ctid in ctidList)
  9642. {
  9643. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9644. if (entity != null)
  9645. {
  9646. sql = new StringBuilder();
  9647. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9648. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9649. if (dth.Rows.Count > 0)
  9650. {
  9651. tisCtid += entity.ctid;
  9652. tisCtid += ",";
  9653. }
  9654. }
  9655. }
  9656. if (tisCtid.Length > 0)
  9657. {
  9658. var res = new
  9659. {
  9660. data = tisCtid
  9661. };
  9662. string ro_jsond = JsonConvert.SerializeObject(res);
  9663. returnSuccess(ro_jsond);
  9664. }
  9665. else
  9666. {
  9667. var res = new
  9668. {
  9669. data = ""
  9670. };
  9671. string ro_jsond = JsonConvert.SerializeObject(res);
  9672. returnSuccess(ro_jsond);
  9673. }
  9674. return;
  9675. }
  9676. returnErrorMsg("缺少必要的参数");
  9677. }
  9678. public void file_client_down_url()
  9679. {
  9680. if (!UrlPostParmsCheck("userId"))
  9681. {
  9682. returnErrorMsg("缺少必要的参数");
  9683. }
  9684. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9685. }
  9686. public void checkout_form_data()
  9687. {
  9688. if (!UrlPostParmsCheck("tid"))
  9689. {
  9690. returnErrorMsg("缺少必要的参数");
  9691. }
  9692. string tid = GetPostString("tid");
  9693. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9694. if (ceErpOrderFormData != null)
  9695. {
  9696. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9697. returnSuccess(ro_jsond);
  9698. return;
  9699. }
  9700. returnErrorMsg("尚未有文件!");
  9701. }
  9702. public void back_supplier_audit()
  9703. {
  9704. int userId = CurrentUser.UserID;
  9705. StringBuilder sql = new StringBuilder();
  9706. 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);
  9707. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9708. if (dt.Rows.Count > 0)
  9709. {
  9710. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9711. }
  9712. else
  9713. {
  9714. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9715. }
  9716. }
  9717. public void back_supplier_query()
  9718. {
  9719. string eid = GetPostString("ctid");
  9720. if (eid != "")
  9721. {
  9722. StringBuilder sql = new StringBuilder();
  9723. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9724. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9725. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9726. }
  9727. else
  9728. {
  9729. returnErrorMsg("找不到订单记录");
  9730. return;
  9731. }
  9732. }
  9733. public void verified_to_order()
  9734. {
  9735. int userId = CurrentUser.UserID;
  9736. StringBuilder sql = new StringBuilder();
  9737. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9738. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9739. if (dt.Rows.Count > 0)
  9740. {
  9741. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9742. }
  9743. else
  9744. {
  9745. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9746. }
  9747. }
  9748. public void upd_supplier_audit()
  9749. {
  9750. if (UrlPostParmsCheck("ctid"))
  9751. {
  9752. string eid = GetPostString("ctid");
  9753. string reason = GetPostString("returnreason");
  9754. CeErpTradeCell entity = null;
  9755. CeWithdraw withdraw = null;
  9756. withdraw = CeWithdraw.GetByTid(eid);
  9757. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9758. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9759. {
  9760. if (withdraw != null)
  9761. {
  9762. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9763. {
  9764. returnSuccessMsg("您没有权限操作!");
  9765. return;
  9766. }
  9767. else
  9768. {
  9769. if (reason.Equals("1"))
  9770. {
  9771. if (entity.OrderState == -1)
  9772. {
  9773. if (entity.FinishPlaceTime == null)
  9774. {
  9775. entity.OrderState = 2;
  9776. }
  9777. else
  9778. {
  9779. entity.OrderState = 6;
  9780. }
  9781. }
  9782. entity.Update();
  9783. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9784. if (withdraw != null)
  9785. {
  9786. withdraw.status = int.Parse(reason);
  9787. withdraw.Update();
  9788. }
  9789. returnSuccessMsg("操作成功!");
  9790. return;
  9791. }
  9792. else
  9793. {
  9794. withdraw.status = int.Parse(reason);
  9795. withdraw.acknowledgingtime = DateTime.Now;
  9796. withdraw.Update();
  9797. returnSuccessMsg("查看详细请点击线下订单查询");
  9798. return;
  9799. }
  9800. }
  9801. }
  9802. // 第一个字符是 'N'
  9803. }
  9804. if (eid[0] != 'N')
  9805. {
  9806. }
  9807. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9808. {
  9809. entity.IsVerifyToSupplier = false;
  9810. entity.IsReturn = 1;
  9811. entity.ReturnTime = DateTime.Now;
  9812. entity.ReturnReason = reason;
  9813. if (entity.OrderState == 6)
  9814. {
  9815. entity.OrderState = 5;
  9816. }
  9817. entity.Update();
  9818. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9819. if (withdraw != null)
  9820. {
  9821. withdraw.status = int.Parse(reason);
  9822. withdraw.Update();
  9823. }
  9824. returnSuccessMsg("操作成功!");
  9825. return;
  9826. }
  9827. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9828. {
  9829. ;
  9830. if (withdraw != null)
  9831. {
  9832. withdraw.status = int.Parse(reason);
  9833. withdraw.acknowledgingtime = DateTime.Now;
  9834. withdraw.Update();
  9835. returnSuccessMsg("供应商取消撤回!");
  9836. return;
  9837. }
  9838. }
  9839. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9840. {
  9841. if (entity.OrderState == -1)
  9842. {
  9843. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9844. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9845. {
  9846. returnErrorMsg("订单spu没有确认无法通过审核!");
  9847. return;
  9848. }
  9849. if (entity.FinishPlaceTime == null)
  9850. {
  9851. entity.OrderState = 2;
  9852. }
  9853. else
  9854. {
  9855. entity.OrderState = 3;
  9856. }
  9857. commonHelper.getCytPrice(entity);
  9858. }
  9859. entity.Update();
  9860. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9861. if (withdraw != null)
  9862. {
  9863. withdraw.status = int.Parse(reason);
  9864. withdraw.Update();
  9865. }
  9866. returnSuccessMsg("操作成功!");
  9867. return;
  9868. }
  9869. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9870. {
  9871. if (withdraw == null)
  9872. {
  9873. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9874. return;
  9875. }
  9876. }
  9877. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9878. {
  9879. if (withdraw != null)
  9880. {
  9881. withdraw.status = int.Parse(reason);
  9882. withdraw.acknowledgingtime = DateTime.Now;
  9883. withdraw.Update();
  9884. returnSuccessMsg("查看详细请点击线下订单查询");
  9885. return;
  9886. }
  9887. }
  9888. return;
  9889. }
  9890. }
  9891. //校验报价
  9892. public void refund_order_tip()
  9893. {
  9894. int userid = CurrentUser.UserID;
  9895. int sectionId = CurrentUser.UserPost.OrgID;
  9896. StringBuilder sql = new StringBuilder();
  9897. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9898. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9899. List<string> ids = new List<string>();
  9900. if (dth.Rows.Count > 0)
  9901. {
  9902. foreach (DataRow dr in dth.Rows)
  9903. {
  9904. ids.Add(dr["ID"].ToString());
  9905. }
  9906. try
  9907. {
  9908. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9909. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9910. }
  9911. catch (Exception ex)
  9912. {
  9913. }
  9914. }
  9915. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9916. }
  9917. public void refund_order_Design()
  9918. {
  9919. int userid = CurrentUser.UserID;
  9920. int sectionId = CurrentUser.UserPost.OrgID;
  9921. StringBuilder sql = new StringBuilder();
  9922. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9923. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9924. List<string> ids = new List<string>();
  9925. if (dth.Rows.Count > 0)
  9926. {
  9927. foreach (DataRow dr in dth.Rows)
  9928. {
  9929. ids.Add(dr["ID"].ToString());
  9930. }
  9931. try
  9932. {
  9933. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9934. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9935. }
  9936. catch (Exception ex)
  9937. {
  9938. }
  9939. }
  9940. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9941. }
  9942. public void change_order_info()
  9943. {
  9944. int userid = CurrentUser.UserID;
  9945. StringBuilder sql = new StringBuilder();
  9946. 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);
  9947. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9948. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9949. }
  9950. public void change_win_mome()
  9951. {
  9952. if (UrlPostParmsCheck("id,ctid"))
  9953. {
  9954. string id = GetPostString("id");
  9955. string ctid = GetPostString("ctid");
  9956. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9957. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9958. if (ce == null || ceErpMessageTip == null)
  9959. {
  9960. returnSuccessMsg("未找到对应的订单!");
  9961. return;
  9962. }
  9963. if (ce.OrderState >= 5)
  9964. {
  9965. returnSuccessMsg("已上传文件无法修改!");
  9966. return;
  9967. }
  9968. int type = GetPostInt("type");
  9969. string content = GetPostString("content");
  9970. if (type == 0)
  9971. {
  9972. content = content.Replace("(", "(");
  9973. content = content.Replace(")", ")");
  9974. string check = MidStrEx(content, "(", ")").Trim();
  9975. if (string.IsNullOrEmpty(check))
  9976. {
  9977. returnSuccessMsg("文件名格式不正确");
  9978. return;
  9979. }
  9980. }
  9981. ce.DispatchSort = 0;
  9982. ce.seller_memo = content;
  9983. ce.Update();
  9984. ceErpMessageTip.isVisit = true;
  9985. ceErpMessageTip.Update();
  9986. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  9987. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  9988. ApiVo apiVo = new ApiVo();
  9989. apiVo.orderNumber = ce.ctid;
  9990. apiVo.actionName = "demandDesign";
  9991. apiVo.orderRemarks = content;
  9992. apiVo.demandExamine = type + 1;
  9993. designHelper.API_WorkCore(apiVo);//demandDesign
  9994. returnSuccessMsg("修改成功!");
  9995. }
  9996. }
  9997. public static string MidStrEx(string sourse, string startstr, string endstr)
  9998. {
  9999. string result = string.Empty;
  10000. int startindex, endindex;
  10001. try
  10002. {
  10003. startindex = sourse.IndexOf(startstr);
  10004. if (startindex == -1)
  10005. return result;
  10006. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10007. endindex = tmpstr.IndexOf(endstr);
  10008. if (endindex == -1)
  10009. return result;
  10010. result = tmpstr.Remove(endindex);
  10011. }
  10012. catch (Exception ex)
  10013. {
  10014. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10015. }
  10016. return result;
  10017. }
  10018. public void refund_order_list()
  10019. {
  10020. int userid = CurrentUser.UserID;
  10021. int sectionId = CurrentUser.UserPost.OrgID;
  10022. StringBuilder sql = new StringBuilder();
  10023. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10024. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10025. DataStruct dStruct = GetPostStruct();
  10026. DataTable dt = null;
  10027. List<string> ids = new List<string>();
  10028. List<string> tids = new List<string>();
  10029. if (dth.Rows.Count > 0)
  10030. {
  10031. foreach (DataRow dr in dth.Rows)
  10032. {
  10033. tids.Add("'" + dr["tid"].ToString() + "'");
  10034. ids.Add(dr["id"].ToString());
  10035. }
  10036. try
  10037. {
  10038. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10039. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10040. List<string> lw = new List<string>();
  10041. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10042. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10043. dt = WebCache.GetData("view_orderlist", dStruct);
  10044. }
  10045. catch (Exception ex)
  10046. {
  10047. }
  10048. }
  10049. writeGridDataTableJson(dStruct.TotalCount, dt);
  10050. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10051. }
  10052. //新增
  10053. public void order_batch_downloads()
  10054. {
  10055. string ceid = GetPostString("tid");
  10056. String[] tid = ceid.Split(',');
  10057. order_batch_caiyingtong(tid);
  10058. /* (string success, string errors) = UploadFiles(tid);
  10059. returnSuccessMsg(success + errors);*/
  10060. return;
  10061. }
  10062. //报价接口
  10063. public void Get_To_Quote()
  10064. {
  10065. string ceid = GetPostString("ctid");
  10066. if (ceid != null)
  10067. {
  10068. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10069. if (entity != null)
  10070. {
  10071. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10072. {
  10073. return;
  10074. }
  10075. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10076. double price = 0;
  10077. if (cp == null)
  10078. {
  10079. JObject jsonObject12 = new JObject
  10080. {
  10081. { "UserId", "77886" },
  10082. { "Pwd", "lt666888" },
  10083. { "Filename", entity.seller_memo }
  10084. };
  10085. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10086. JObject jsonObjects1 = JObject.Parse(response1);
  10087. string ms1g = (string)jsonObjects1["msg"];
  10088. if (ms1g == "报价成功")
  10089. {
  10090. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10091. string data = (string)jsonObject1["price"];
  10092. 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 + "');";
  10093. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10094. returnSuccessMsg("获取报价成功:" + data);
  10095. price = Convert.ToDouble(data);
  10096. }
  10097. else
  10098. {
  10099. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10100. return;
  10101. }
  10102. }
  10103. String[] beizhu = entity.seller_memo.Split('-');
  10104. String chanp = "";
  10105. if (beizhu.Length > 0)
  10106. {
  10107. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10108. }
  10109. else
  10110. {
  10111. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10112. }
  10113. JObject jsonObject = new JObject
  10114. {
  10115. { "UserId", "77886" },
  10116. { "Pwd", "lt666888" },
  10117. { "Filename", chanp }
  10118. };
  10119. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10120. JObject jsonObjects = JObject.Parse(response);
  10121. string msg = (string)jsonObjects["msg"];
  10122. if (msg == "报价成功")
  10123. {
  10124. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10125. string data = (string)jsonObject1["price"];
  10126. 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 + "');";
  10127. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10128. returnSuccessMsg("获取报价成功:" + data);
  10129. price = Convert.ToDouble(data);
  10130. }
  10131. else
  10132. {
  10133. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10134. return;
  10135. }
  10136. if (price > 0)
  10137. {
  10138. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10139. if (ceErpTradeCellExtend == null)
  10140. {
  10141. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10142. ceErpTradeCellExtend.ctid = entity.ctid;
  10143. ceErpTradeCellExtend.payment_cyt = price;
  10144. ceErpTradeCellExtend.Create();
  10145. }
  10146. else
  10147. {
  10148. ceErpTradeCellExtend.payment_cyt = price;
  10149. ceErpTradeCellExtend.Update();
  10150. }
  10151. }
  10152. return;
  10153. }
  10154. }
  10155. else
  10156. {
  10157. returnErrorMsg("请至少选择一条数据");
  10158. return;
  10159. }
  10160. }
  10161. //新增
  10162. public void order_To_Supplier()
  10163. {
  10164. string ceid = GetPostString("tid");
  10165. String[] tid = ceid.Split(',');
  10166. if (tid.Length > 0)
  10167. {
  10168. try
  10169. {
  10170. for (int i = 0; i < tid.Length; i++)
  10171. {
  10172. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10173. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10174. entity.SupplierId = suid;
  10175. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10176. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10177. entity.Update();
  10178. }
  10179. }
  10180. catch (Exception ex)
  10181. {
  10182. returnErrorMsg("自动匹配供应商失败");
  10183. return;
  10184. }
  10185. }
  10186. else
  10187. {
  10188. returnErrorMsg("请至少选择一条数据");
  10189. return;
  10190. }
  10191. returnSuccessMsg("自动匹配供应商成功");
  10192. return;
  10193. }
  10194. public (string, string) UploadFiles(string[] urls)
  10195. {
  10196. string success = "";
  10197. string errors = "";
  10198. int userid = CurrentUser.UserID;
  10199. foreach (string url in urls)
  10200. {
  10201. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10202. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10203. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10204. {
  10205. JObject jsonObject = new JObject
  10206. {
  10207. { "Userid", "77886" },
  10208. { "pwd", "cyt86435015" },
  10209. { "content", base64FileContent },
  10210. { "ext", Path.GetExtension(fileName) }
  10211. };
  10212. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10213. JObject jsonObjects = JObject.Parse(response);
  10214. string msg = (string)jsonObjects["msg"];
  10215. if (msg.Equals("上传成功"))
  10216. {
  10217. success += url + " 上传成功";
  10218. }
  10219. else
  10220. {
  10221. errors += url + " 上传失败";
  10222. }
  10223. }
  10224. else
  10225. {
  10226. errors += url + " 格式出现问题";
  10227. }
  10228. }
  10229. if (urls.Length == 0)
  10230. {
  10231. return (success, errors);
  10232. }
  10233. return (success, errors);
  10234. }
  10235. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10236. {
  10237. return true; //总是接受
  10238. }
  10239. public static string HttpPost(string url, string param = null)
  10240. {
  10241. HttpWebRequest request;
  10242. //如果是发送HTTPS请求
  10243. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10244. {
  10245. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10246. request = WebRequest.Create(url) as HttpWebRequest;
  10247. request.ProtocolVersion = HttpVersion.Version10;
  10248. }
  10249. else
  10250. {
  10251. request = WebRequest.Create(url) as HttpWebRequest;
  10252. }
  10253. request.Method = "POST";
  10254. request.ContentType = "application/json";
  10255. request.Accept = "*/*";
  10256. request.Timeout = 120000;
  10257. request.AllowAutoRedirect = false;
  10258. StreamWriter requestStream = null;
  10259. WebResponse response = null;
  10260. string responseStr = null;
  10261. try
  10262. {
  10263. requestStream = new StreamWriter(request.GetRequestStream());
  10264. requestStream.Write(param);
  10265. requestStream.Close();
  10266. response = request.GetResponse();
  10267. if (response != null)
  10268. {
  10269. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10270. responseStr = reader.ReadToEnd();
  10271. reader.Close();
  10272. }
  10273. }
  10274. catch (Exception ex)
  10275. {
  10276. return ex.Message;
  10277. }
  10278. finally
  10279. {
  10280. request = null;
  10281. requestStream = null;
  10282. response = null;
  10283. }
  10284. return responseStr;
  10285. }
  10286. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10287. {
  10288. string base64FileContent;
  10289. string fileName;
  10290. using (WebClient webClient = new WebClient())
  10291. {
  10292. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10293. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10294. {
  10295. using (Stream stream = response.GetResponseStream())
  10296. {
  10297. using (MemoryStream memoryStream = new MemoryStream())
  10298. {
  10299. stream.CopyTo(memoryStream);
  10300. byte[] fileBytes = memoryStream.ToArray();
  10301. base64FileContent = Convert.ToBase64String(fileBytes);
  10302. fileName = response.Headers["Content-Disposition"];
  10303. if (!string.IsNullOrEmpty(fileName))
  10304. {
  10305. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10306. if (index >= 0)
  10307. {
  10308. fileName = fileName.Substring(index + 9).Trim('\"');
  10309. }
  10310. }
  10311. else
  10312. {
  10313. fileName = Path.GetFileName(downloadUrl);
  10314. }
  10315. }
  10316. }
  10317. }
  10318. }
  10319. return (fileName, base64FileContent);
  10320. }
  10321. //新增
  10322. public void order_batch_caiyingtong(string[] downloadUrls)
  10323. {
  10324. try
  10325. {
  10326. //遍历文件
  10327. DataStruct dStruct = GetPostStruct();
  10328. DataTable dt = null;
  10329. int userid = CurrentUser.UserID;
  10330. List<string> ids = new List<string>();//失败组
  10331. List<string> tids = new List<string>();
  10332. using (WebClient webClient = new WebClient())
  10333. {
  10334. foreach (var url in downloadUrls)
  10335. {
  10336. try
  10337. {
  10338. tids.Add("'" + url + "'");
  10339. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10340. if (entity != null)
  10341. {
  10342. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10343. if (cp == null)
  10344. {
  10345. JObject jsonObject = new JObject
  10346. {
  10347. { "Userid", "77886" },
  10348. { "pwd", "lt666888" },
  10349. { "Filename",entity.seller_memo }
  10350. };
  10351. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10352. JObject jsonObjects = JObject.Parse(response);
  10353. string msg = (string)jsonObjects["msg"];
  10354. if (msg == "报价成功")
  10355. {
  10356. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10357. DownloadAndConvertToBase64(url1);
  10358. }
  10359. else
  10360. {
  10361. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10362. }
  10363. }
  10364. else
  10365. {
  10366. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10367. JObject jsonObject = new JObject
  10368. {
  10369. { "Userid", "77886" },
  10370. { "pwd", "lt666888" },
  10371. { "Filename",chanp }
  10372. };
  10373. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10374. JObject jsonObjects = JObject.Parse(response);
  10375. string msg = (string)jsonObjects["msg"];
  10376. if (msg == "报价成功")
  10377. {
  10378. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10379. DownloadAndConvertToBase64(url1);
  10380. }
  10381. else
  10382. {
  10383. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10384. }
  10385. }
  10386. }
  10387. // 上传文件到FTP
  10388. }
  10389. catch (Exception ex)
  10390. {
  10391. Console.WriteLine($"An error occurred: {ex.Message}");
  10392. }
  10393. }
  10394. List<string> lw = new List<string>();
  10395. lw.Add(string.Format("( OrderState < 6 )"));
  10396. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10397. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10398. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10399. if (dt.Rows.Count > 0)
  10400. {
  10401. foreach (DataRow dr in dt.Rows)
  10402. {
  10403. ids.Add(dr["ctid"].ToString());
  10404. }
  10405. }
  10406. String ErrorMsgs = "";
  10407. foreach (String id in ids)
  10408. {
  10409. ErrorMsgs += id + ",";
  10410. }
  10411. if (ErrorMsgs.Length > 1)
  10412. {
  10413. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10414. }
  10415. if (ErrorMsgs.Length < 1)
  10416. {
  10417. ErrorMsgs = "上传成功";
  10418. returnSuccessMsg(ErrorMsgs);
  10419. }
  10420. else
  10421. {
  10422. returnErrorMsg("以下订单" + ErrorMsgs);
  10423. }
  10424. }
  10425. // 删除文件夹及其内容
  10426. /* Directory.Delete(localDirectory, true);*/
  10427. }
  10428. catch { }
  10429. }
  10430. public void get_center_data()
  10431. {
  10432. int userId = CurrentUser.UserID;
  10433. string postCode = CurrentUser.UserPost.Post.Code;
  10434. List<string> lw = new List<string>();
  10435. List<string> ww = new List<string>();
  10436. DateTime currentTime = DateTime.Now;
  10437. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10438. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10439. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10440. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10441. string sql = " SELECT ";
  10442. string startTime = "2023-10-01 11:22:31";
  10443. //设计
  10444. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10445. {
  10446. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10447. 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));
  10448. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10449. 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));
  10450. }
  10451. //客服
  10452. else if (postCode == "CustomerService" || postCode == "Director")
  10453. {
  10454. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10455. 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));
  10456. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10457. 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));
  10458. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10459. 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));
  10460. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10461. 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));
  10462. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10463. 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));
  10464. }
  10465. //售后
  10466. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10467. {
  10468. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10469. 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));
  10470. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10471. 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));
  10472. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10473. 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));
  10474. }
  10475. //下单部
  10476. else if (postCode == "Place" || postCode == "PlaceMr")
  10477. {
  10478. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10479. 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));
  10480. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10481. 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));
  10482. }
  10483. //车间
  10484. else if (postCode == "Supplier")
  10485. {
  10486. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10487. 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));
  10488. }
  10489. DataTable dt = new DataTable();
  10490. if (lw.Count > 0)
  10491. {
  10492. sql += string.Join(" , ", lw);
  10493. sql += " FROM ";
  10494. sql += string.Join(" , ", ww);
  10495. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10496. }
  10497. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10498. }
  10499. public void get_center_data_list()
  10500. {
  10501. int userId = CurrentUser.UserID;
  10502. string postCode = CurrentUser.UserPost.Post.Code;
  10503. string shopIds = CurrentUser.User.pemShop;
  10504. DataStruct dStruct = GetPostStruct();
  10505. List<string> lw = new List<string>();
  10506. DateTime currentTime = DateTime.Now;
  10507. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10508. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10509. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10510. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10511. string startTime = "2023-10-01 11:22:31";
  10512. int order_type = GetPostInt("order_type");
  10513. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10514. {
  10515. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10516. if (order_type == 0)
  10517. {
  10518. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10519. }
  10520. else if (order_type == 3)
  10521. {
  10522. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10523. }
  10524. else
  10525. {
  10526. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10527. }
  10528. }
  10529. //客服
  10530. if (postCode == "CustomerService" || postCode == "Director")
  10531. {
  10532. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10533. if (order_type == 0)
  10534. {
  10535. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10536. }
  10537. else if (order_type == 1)
  10538. {
  10539. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10540. }
  10541. else if (order_type == 2)
  10542. {
  10543. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10544. }
  10545. else if (order_type == 3)
  10546. {
  10547. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10548. }
  10549. else if (order_type == 4)
  10550. {
  10551. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10552. }
  10553. else
  10554. {
  10555. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10556. }
  10557. }
  10558. //售后
  10559. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10560. {
  10561. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10562. if (shopIds != "")
  10563. {
  10564. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10565. }
  10566. if (order_type == 2)
  10567. {
  10568. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10569. }
  10570. else if (order_type == 4)
  10571. {
  10572. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10573. }
  10574. else if (order_type == 5)
  10575. {
  10576. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10577. }
  10578. else
  10579. {
  10580. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10581. }
  10582. }
  10583. //下单部
  10584. if (postCode == "Place" || postCode == "PlaceMr")
  10585. {
  10586. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10587. if (shopIds != "")
  10588. {
  10589. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10590. }
  10591. else if (order_type == 1)
  10592. {
  10593. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10594. }
  10595. else if (order_type == 2)
  10596. {
  10597. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10598. }
  10599. else
  10600. {
  10601. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10602. }
  10603. }
  10604. //车间
  10605. if (postCode == "Supplier")
  10606. {
  10607. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10608. if (order_type == 5)
  10609. {
  10610. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10611. }
  10612. else
  10613. {
  10614. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10615. }
  10616. }
  10617. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10618. dStruct.Fileds = "tid,ctid";
  10619. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10620. writeGridDataTableJson(dStruct.TotalCount, dt);
  10621. }
  10622. public void aftersale_audit_master()
  10623. {
  10624. if (UrlPostParmsCheck("ctid"))
  10625. {
  10626. string ctid = GetPostString("ctid");
  10627. if (ctid.Length > 0)
  10628. {
  10629. bool result = aftersale_data_change(ctid);
  10630. if (result)
  10631. {
  10632. returnSuccessMsg("修改成功!");
  10633. return;
  10634. }
  10635. }
  10636. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10637. }
  10638. }
  10639. public void aftersale_batch_audit_master()
  10640. {
  10641. if (UrlPostParmsCheck("ctids"))
  10642. {
  10643. string ctids = GetPostString("ctids");
  10644. if (ctids.Length > 0)
  10645. {
  10646. List<string> list = new List<string>();
  10647. string[] ctid_list = ctids.Split(',');
  10648. foreach (var item in ctid_list)
  10649. {
  10650. bool result = aftersale_data_change(item);
  10651. if (!result)
  10652. {
  10653. list.Add(item);
  10654. }
  10655. }
  10656. if (list.Count > 0)
  10657. {
  10658. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10659. return;
  10660. }
  10661. returnSuccessMsg("修改成功!");
  10662. return;
  10663. }
  10664. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10665. }
  10666. }
  10667. public bool aftersale_data_change(string ctid)
  10668. {
  10669. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10670. if (ceErpTradeCell != null)
  10671. {
  10672. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10673. ceErpTradeCell.AfterSaleSupplierState = 0;
  10674. StringBuilder sql = new StringBuilder();
  10675. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10676. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10677. CeErpTradeResponsible.DelByTid(ctid, 0);
  10678. 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 == "不理赔")
  10679. {
  10680. CeErpTradeResponsible.DelByTid(ctid, 1);
  10681. ceErpTradeCell.AfterSaleSupplierState = 1;
  10682. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10683. ceErpTradeCell.AfterSaleState = 4;
  10684. }
  10685. else
  10686. {
  10687. ceErpTradeCell.AfterSaleState = 3;
  10688. }
  10689. bool needCyt = false;
  10690. if (dt != null)
  10691. {
  10692. if (dt.Rows.Count == 1)
  10693. {
  10694. bool isEnd = false;
  10695. foreach (DataRow dr in dt.Rows)
  10696. {
  10697. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10698. {
  10699. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10700. isEnd = true;
  10701. }
  10702. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10703. {
  10704. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10705. isEnd = true;
  10706. }
  10707. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10708. {
  10709. needCyt = true;
  10710. }
  10711. }
  10712. if (isEnd)
  10713. {
  10714. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10715. ceErpTradeCell.AfterSaleState = 4;
  10716. ceErpTradeCell.AfterSaleSupplierState = 1;
  10717. }
  10718. }
  10719. else
  10720. {
  10721. bool isAll = true;
  10722. foreach (DataRow dr in dt.Rows)
  10723. {
  10724. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10725. {
  10726. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10727. continue;
  10728. }
  10729. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10730. {
  10731. string path = "";
  10732. int OrgID = 0;
  10733. if (!Convert.IsDBNull(dr["OrgPath"]))
  10734. {
  10735. path = dr["OrgPath"].ToString();
  10736. }
  10737. if (!Convert.IsDBNull(dr["OrgID"]))
  10738. {
  10739. OrgID = Convert.ToInt32(dr["OrgID"]);
  10740. }
  10741. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10742. {
  10743. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10744. continue;
  10745. }
  10746. }
  10747. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10748. {
  10749. needCyt = true;
  10750. }
  10751. isAll = false;
  10752. }
  10753. if (isAll)
  10754. {
  10755. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10756. ceErpTradeCell.AfterSaleState = 4;
  10757. ceErpTradeCell.AfterSaleSupplierState = 1;
  10758. }
  10759. }
  10760. }
  10761. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10762. {
  10763. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10764. }
  10765. if (ceErpTradeCell.AfterSaleState == 4)
  10766. {
  10767. ApiVo apiVo = new ApiVo();
  10768. apiVo.orderNumber = ceErpTradeCell.ctid;
  10769. apiVo.actionName = "afterOver";
  10770. designHelper.API_WorkCore(apiVo); //afterOver
  10771. }
  10772. ceErpTradeCell.Update();
  10773. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10774. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10775. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10776. return true;
  10777. }
  10778. return false;
  10779. }
  10780. public void get_erp_wechatorder()
  10781. {
  10782. DataStruct dStruct = GetPostStruct();
  10783. List<string> lw = new List<string>();
  10784. string tid = GetPostString("tid");
  10785. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10786. string shopname = GetPostString("shopname");
  10787. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10788. string buyernick = GetPostString("buyer_nick");
  10789. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10790. string customer = GetPostString("customer");
  10791. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10792. string returndate1 = GetPostString("returndate1");
  10793. string returndate2 = GetPostString("returndate2");
  10794. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10795. if (dw.Length > 0) lw.Add(dw);
  10796. string finishDate1 = GetPostString("finishdate1");
  10797. string finishDate2 = GetPostString("finishdate2");
  10798. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10799. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10800. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10801. dStruct.Order = "created desc";
  10802. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10803. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10804. writeGridDataTableJson(dStruct.TotalCount, dt);
  10805. }
  10806. public void get_erp_wechatlist_sumprice()
  10807. {
  10808. DataStruct dStruct = GetPostStruct();
  10809. List<string> lw = new List<string>();
  10810. string tid = GetPostString("tid");
  10811. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10812. string shopname = GetPostString("shopname");
  10813. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10814. string buyernick = GetPostString("buyer_nick");
  10815. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10816. string customer = GetPostString("customer");
  10817. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10818. string returndate1 = GetPostString("returndate1");
  10819. string returndate2 = GetPostString("returndate2");
  10820. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10821. if (dw.Length > 0) lw.Add(dw);
  10822. string finishDate1 = GetPostString("finishdate1");
  10823. string finishDate2 = GetPostString("finishdate2");
  10824. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10825. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10826. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10827. string mainWhere = string.Join(" and ", lw.ToArray());
  10828. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10829. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10830. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10831. decimal total = 0;
  10832. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10833. {
  10834. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10835. }
  10836. var res = new
  10837. {
  10838. data = total
  10839. };
  10840. string ro_jsond = JsonConvert.SerializeObject(res);
  10841. returnSuccess(ro_jsond);
  10842. return;
  10843. }
  10844. public void get_erp_qr_waitdeliverylist()
  10845. {
  10846. DataStruct dStruct = GetPostStruct();
  10847. List<string> lw = new List<string>();
  10848. string tid = GetPostString("ctid");
  10849. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10850. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10851. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10852. var res_objz = new
  10853. {
  10854. restype = 1,
  10855. data = dt
  10856. };
  10857. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10858. returnSuccess(ro_jsonz);
  10859. }
  10860. public void get_erp_yield_list()
  10861. {
  10862. DataStruct dStruct = GetPostStruct();
  10863. List<string> lw = new List<string>();
  10864. string tid = GetPostString("ctid");
  10865. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10866. string shopname = GetPostString("shopname");
  10867. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10868. string buyernick = GetPostString("buyer_nick");
  10869. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10870. //if (tid.Length == 0 && buyernick.Length == 0)
  10871. //{
  10872. // lw.Add(string.Format("IsRefund<={0}", 1));
  10873. //}
  10874. string customer = GetPostString("customer");
  10875. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10876. string design = GetPostString("design");
  10877. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10878. string orderState = GetPostString("orderState");
  10879. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10880. string address = GetPostString("address");
  10881. 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));
  10882. string sellermemo = GetPostString("seller_memo");
  10883. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10884. string supplier = GetPostString("supplier");
  10885. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10886. string OrderArea = GetPostString("order_area");
  10887. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10888. string placedate1 = GetPostString("placedate1");
  10889. string placedate2 = GetPostString("placedate2");
  10890. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10891. if (fdw.Length > 0) lw.Add(fdw);
  10892. string price1 = GetPostString("price1");
  10893. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10894. string price2 = GetPostString("price2");
  10895. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10896. string unusualCon = GetPostString("unusualcon");
  10897. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10898. string posTag = CurrentUser.UserPost.Post.Code;
  10899. if (posTag == "Supplier")
  10900. {
  10901. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10902. }
  10903. lw.Add(string.Format("OrderState = 6 "));
  10904. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10905. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10906. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10907. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10908. writeGridDataTableJson(dStruct.TotalCount, dt);
  10909. }
  10910. public void change_erp_sup_state()
  10911. {
  10912. if (UrlPostParmsCheck("ctid"))
  10913. {
  10914. string ctid = GetPostString("ctid");
  10915. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10916. if (ceErpTradeCell != null)
  10917. {
  10918. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10919. if (ceErpTradeCellExtend == null)
  10920. {
  10921. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10922. ceErpTradeCellExtend.ctid = ctid;
  10923. ceErpTradeCellExtend.SupState = 1;
  10924. ceErpTradeCellExtend.Create();
  10925. }
  10926. else
  10927. {
  10928. ceErpTradeCellExtend.SupState = 1;
  10929. ceErpTradeCellExtend.Update();
  10930. }
  10931. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10932. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10933. return;
  10934. }
  10935. returnErrorMsg("找不到订单");
  10936. }
  10937. }
  10938. public void supplier_all_downs()
  10939. {
  10940. if (UrlPostParmsCheck("tids"))
  10941. {
  10942. string tids = GetPostString("tids");
  10943. if (tids != null && tids.Length > 0)
  10944. {
  10945. StringBuilder sql = new StringBuilder();
  10946. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10947. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10948. sql = new StringBuilder();
  10949. 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, "下载设计文件");
  10950. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10951. string[] list = tids.Split(',');
  10952. foreach (string ctid in list)
  10953. {
  10954. CeErpSukuraData.createInfo(ctid, 3);
  10955. }
  10956. designHelper.api_approveDesign(tids); //approveDesign
  10957. returnSuccessMsg("下载成功!");
  10958. return;
  10959. }
  10960. returnErrorMsg("下载订单更新失败");
  10961. }
  10962. }
  10963. public void uploaderFileSuccess()
  10964. {
  10965. if (UrlPostParmsCheck("fileName"))
  10966. {
  10967. string fileName = GetPostString("fileName");
  10968. ApiVo apiVo = new ApiVo();
  10969. apiVo.orderNumber = fileName;
  10970. apiVo.actionName = "finishDesign";
  10971. designHelper.API_WorkCore(apiVo);//finishDesign
  10972. returnSuccessMsg("");
  10973. }
  10974. }
  10975. public void get_sample2_order()
  10976. {
  10977. if (UrlPostParmsCheck("ctid"))
  10978. {
  10979. string ctid = GetPostString("ctid");
  10980. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10981. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10982. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10983. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10984. double total = 0.0;
  10985. double order_price = 0.0;
  10986. if (dt_bu.Rows.Count > 0)
  10987. {
  10988. foreach (DataRow dr in dt_bu.Rows)
  10989. {
  10990. total += Convert.ToDouble(dr["payment"]);
  10991. }
  10992. }
  10993. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  10994. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  10995. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  10996. string tid = ctid.Replace("S_", "");
  10997. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  10998. double paymant = 0.0;
  10999. if (entity != null)
  11000. {
  11001. paymant = entity.payment;
  11002. }
  11003. string return_reason = "";
  11004. if (dt_after != null && dt_after.Rows.Count > 0)
  11005. {
  11006. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11007. }
  11008. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11009. }
  11010. }
  11011. public void get_erp_design_status()
  11012. {
  11013. string designName = GetPostString("designName");
  11014. DataStruct dStruct = GetPostStruct();
  11015. if (designName.Length > 0)
  11016. {
  11017. 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";
  11018. sql_user += " and Name like '%" + designName + "%'";
  11019. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11020. List<string> ids_list = new List<string>();
  11021. if (user_table.Rows.Count > 0)
  11022. {
  11023. foreach (DataRow item in user_table.Rows)
  11024. {
  11025. ids_list.Add(item["id"].ToString());
  11026. string ids_s = item["TeamIds"].ToString();
  11027. if (ids_s.Length > 0)
  11028. {
  11029. ids_list.AddRange(ids_s.Split(','));
  11030. }
  11031. }
  11032. }
  11033. HashSet<string> set = new HashSet<string>(ids_list);
  11034. ids_list = set.ToList();
  11035. if (ids_list.Count > 0)
  11036. {
  11037. 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));
  11038. dStruct.MainWhere = sql;
  11039. DataTable dt = null;
  11040. dt = WebCache.GetData("view_ErpUser", dStruct);
  11041. writeGridDataTableJson(dStruct.TotalCount, dt);
  11042. }
  11043. }
  11044. }
  11045. public void change_erp_order_price()
  11046. {
  11047. string ctid = GetPostString("ctid");
  11048. double price = GetPostDouble("price");
  11049. if (ctid.Length > 0)
  11050. {
  11051. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11052. if (ceErpTradeCellExtend == null)
  11053. {
  11054. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11055. ceErpTradeCellExtend.ctid = ctid;
  11056. ceErpTradeCellExtend.payment_cyt = price;
  11057. ceErpTradeCellExtend.Create();
  11058. }
  11059. else
  11060. {
  11061. ceErpTradeCellExtend.payment_cyt = price;
  11062. ceErpTradeCellExtend.Update();
  11063. }
  11064. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11065. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11066. {
  11067. ceErpDataSendOrderInfo.isSync = false;
  11068. ceErpDataSendOrderInfo.Update();
  11069. }
  11070. if (ceErpDataSendOrderInfo == null)
  11071. {
  11072. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11073. ceErpDataSendOrderInfo.isSync = false;
  11074. ceErpDataSendOrderInfo.ctid = ctid;
  11075. ceErpDataSendOrderInfo.Create();
  11076. }
  11077. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11078. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11079. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11080. if (dth != null && dth.Rows.Count > 0)
  11081. {
  11082. dataSendOrderBean dataSendOrderBean = null;
  11083. foreach (DataRow item in dth.Rows)
  11084. {
  11085. try
  11086. {
  11087. dataSendOrderBean = new dataSendOrderBean();
  11088. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11089. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11090. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11091. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11092. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11093. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11094. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11095. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11096. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11097. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11098. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11099. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11100. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11101. if (result != null)
  11102. {
  11103. if ("0".Equals(result.errcode))
  11104. {
  11105. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11106. }
  11107. else
  11108. {
  11109. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11110. }
  11111. }
  11112. }
  11113. catch (Exception ex)
  11114. {
  11115. }
  11116. }
  11117. }
  11118. returnSuccessMsg("修改成功!");
  11119. return;
  11120. }
  11121. returnErrorMsg("找不到订单");
  11122. }
  11123. public void find_he_together()
  11124. {
  11125. string ctid = GetPostString("ctid");
  11126. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11127. List<string> list = new List<string>();
  11128. if (ceErpTradeCell != null)
  11129. {
  11130. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11131. {
  11132. 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);
  11133. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11134. if (table != null && table.Rows.Count > 0)
  11135. {
  11136. foreach (TableRow row in table.Rows)
  11137. {
  11138. }
  11139. }
  11140. }
  11141. }
  11142. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11143. }
  11144. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11145. {
  11146. //chy----19
  11147. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11148. //GD-CYT-----64
  11149. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11150. //ZHX----3
  11151. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11152. //JK----97
  11153. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11154. //ZT----70
  11155. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11156. //LHCY-----98
  11157. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11158. //XD-----90
  11159. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11160. //CYCY-----14
  11161. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11162. };
  11163. //其他改名
  11164. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11165. {
  11166. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11167. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11168. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11169. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11170. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11171. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11172. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11173. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11174. };
  11175. //不统计
  11176. List<int> no_suppliers = new List<int>()
  11177. {
  11178. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11179. };
  11180. //配件单
  11181. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11182. {
  11183. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11184. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11185. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11186. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11187. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11188. {"旗杆",new List<string>(){ "班旗" } },
  11189. {"牙签",new List<string>(){ "不干胶" } }
  11190. };
  11191. public void get_place_order_data()
  11192. {
  11193. string date1 = GetPostString("date1");
  11194. string date2 = GetPostString("date2");
  11195. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11196. DateTime start = DateTime.Parse(starttime);
  11197. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11198. DateTime end = DateTime.Parse(endtime);
  11199. if (date1 != null && date1.Length > 0)
  11200. {
  11201. DateTime dateTime = DateTime.Parse(date1);
  11202. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11203. start = DateTime.Parse(starttime);
  11204. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11205. end = DateTime.Parse(endtime);
  11206. }
  11207. if (date2 != null && date2.Length > 0)
  11208. {
  11209. DateTime dateTime = DateTime.Parse(date2);
  11210. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11211. end = DateTime.Parse(endtime);
  11212. }
  11213. 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);
  11214. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11215. //不干胶-----1,卡片-----29
  11216. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11217. foreach (DataRow row in data.Rows)
  11218. {
  11219. int productId = Convert.ToInt32(row["ProductId"]);
  11220. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11221. if (no_suppliers.Contains(supplierId))
  11222. {
  11223. continue;
  11224. }
  11225. string seller_memo = row["seller_memo"].ToString();
  11226. bool ispj = false;//是否配件单
  11227. bool isfirst = true;//第一个配
  11228. maps.Keys.ForEach(key =>
  11229. {
  11230. //备注包含配件
  11231. if (seller_memo.Contains(key) && isfirst)
  11232. {
  11233. List<string> list = maps[key];
  11234. ispj = true;
  11235. isfirst = false;
  11236. for (int i = 0; i < list.Count; i++)
  11237. {
  11238. if (seller_memo.Contains(list[i]))
  11239. {
  11240. ispj = false;
  11241. break;
  11242. }
  11243. }
  11244. }
  11245. });
  11246. if (ispj)
  11247. {
  11248. continue;
  11249. }
  11250. seller_memo = seller_memo.Replace("UV", "uv");
  11251. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11252. //吊牌归到卡片
  11253. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11254. seller_memo = seller_memo.Replace("卡套", "卡片");
  11255. seller_memo = seller_memo.Replace("封套", "卡片");
  11256. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11257. seller_memo = seller_memo.Replace("腰封", "卡片");
  11258. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11259. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11260. seller_memo = seller_memo.Replace("横幅", "条幅");
  11261. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11262. string map_key = "";
  11263. string type = "";
  11264. if (supplierMap.ContainsKey(supplierId))
  11265. {
  11266. foreach (var kvp in supplierMap[supplierId])
  11267. {
  11268. if (seller_memo.Contains(kvp.Key))
  11269. {
  11270. map_key = kvp.Value;
  11271. type = kvp.Value;
  11272. break;
  11273. }
  11274. }
  11275. }
  11276. if (map_key == "")
  11277. {
  11278. type = "其他";
  11279. map_key = "其他";
  11280. }
  11281. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11282. {
  11283. map_key = suppliers[supplierId];
  11284. }
  11285. if (supplierId == 70)
  11286. {
  11287. supplierId = 70;
  11288. }
  11289. map_key += "_" + row["SupplierName"].ToString();
  11290. Dictionary<string, int> map = null;
  11291. if (other_map.ContainsKey(map_key))
  11292. {
  11293. other_map.TryGetValue(map_key, out map);
  11294. }
  11295. else
  11296. {
  11297. map = new Dictionary<string, int>();
  11298. map.Add("dayDev", 0);//当天出货
  11299. map.Add("dayTotal", 0);//下单总数
  11300. map.Add("payTotal", 0);//500以上
  11301. map.Add("today", 0);//当天出货数量
  11302. map.Add("unusua", 0);//异常数
  11303. other_map.Add(map_key, map);
  11304. other_map.TryGetValue(map_key, out map);
  11305. }
  11306. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11307. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11308. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11309. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11310. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11311. {
  11312. map["dayTotal"]++;
  11313. if (supplierId == 97)
  11314. {
  11315. supplierId = 97;
  11316. }
  11317. }
  11318. if (Convert.ToDecimal(row["payment"]) >= 500)
  11319. {
  11320. map["payTotal"]++;
  11321. }
  11322. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11323. {
  11324. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11325. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11326. {
  11327. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11328. {
  11329. map["today"]++;
  11330. }
  11331. }
  11332. else
  11333. {
  11334. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11335. {
  11336. map["today"]++;
  11337. }
  11338. else
  11339. {
  11340. if (supplierId == 119)
  11341. {
  11342. Debug.WriteLine(row["seller_memo"].ToString());
  11343. }
  11344. }
  11345. }
  11346. }
  11347. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11348. {
  11349. map["unusua"]++;
  11350. }
  11351. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11352. //GD-CYT-----64
  11353. DateTime two = palceTimeStart.AddHours(14);
  11354. DateTime three = palceTimeStart.AddHours(15);
  11355. DateTime four = palceTimeStart.AddHours(16);
  11356. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11357. {
  11358. //下午四点前 500-1000
  11359. string count = row["ProductCount"].ToString();
  11360. if (count != null && count.Length > 0)
  11361. {
  11362. int productCount = commonHelper.getPlaceProductCount(count);
  11363. if (productCount >= 500 && productCount <= 1000)
  11364. {
  11365. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11366. {
  11367. map["dayDev"]++;
  11368. }
  11369. }
  11370. }
  11371. }
  11372. //UV
  11373. else if ("uv".Equals(type))
  11374. {
  11375. //ZT----70
  11376. //ZHX----3
  11377. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11378. {
  11379. map["dayDev"]++;
  11380. }
  11381. //JK----97
  11382. //HZX----105
  11383. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11384. {
  11385. map["dayDev"]++;
  11386. if (supplierId == 97)
  11387. {
  11388. supplierId = 97;
  11389. }
  11390. }
  11391. }
  11392. //帆布---52|条幅---27
  11393. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11394. {
  11395. //LHCY-----98
  11396. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11397. {
  11398. map["dayDev"]++;
  11399. }
  11400. }
  11401. //条幅
  11402. else if ("条幅".Equals(type))
  11403. {
  11404. //XD-----90
  11405. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11406. {
  11407. map["dayDev"]++;
  11408. }
  11409. }
  11410. //桌布
  11411. else if ("桌布".Equals(type))
  11412. {
  11413. //XD-----90
  11414. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11415. {
  11416. map["dayDev"]++;
  11417. }
  11418. }
  11419. //DL---10
  11420. //AYTW---119
  11421. //FS-CYT-DY ----80
  11422. //JK----97
  11423. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11424. {
  11425. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11426. {
  11427. map["dayDev"]++;
  11428. }
  11429. }
  11430. }
  11431. DataTable dt = new DataTable();
  11432. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11433. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11434. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11435. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11436. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11437. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11438. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11439. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11440. other_map.Keys.ForEach(key =>
  11441. {
  11442. DataRow dr = dt.NewRow();
  11443. Dictionary<string, int> map = other_map[key];
  11444. string[] key_list = key.Split('_');
  11445. dr[0] = key_list[0];
  11446. dr[1] = key_list[1];
  11447. if (key_list.Length > 2)
  11448. {
  11449. dr[1] += "(" + key_list[2] + ")";
  11450. }
  11451. dr[2] = map["dayTotal"];
  11452. dr[3] = map["payTotal"];
  11453. dr[4] = map["today"];
  11454. dr[5] = map["unusua"];
  11455. dr[6] = map["dayDev"];
  11456. double rate = 0.00;
  11457. if (map["dayDev"] > 0)
  11458. {
  11459. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11460. }
  11461. dr[7] = rate.ToString();
  11462. dt.Rows.Add(dr);
  11463. });
  11464. DataView dv = new DataView(dt);
  11465. dv.Sort = "SupplierName";
  11466. //dv.Sort = "AllOrder desc";
  11467. DataTable dtNew = dv.ToTable();
  11468. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11469. }
  11470. public void check_order_desing_info()
  11471. {
  11472. string ctid = GetPostString("ctid");
  11473. if (!string.IsNullOrEmpty(ctid))
  11474. {
  11475. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11476. if (ceErpTradeCell != null)
  11477. {
  11478. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11479. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11480. return;
  11481. }
  11482. returnErrorMsg("找不到订单");
  11483. return;
  11484. }
  11485. returnErrorMsg("找不到订单");
  11486. }
  11487. public void get_timeout_detail()
  11488. {
  11489. string poscode = CurrentUser.UserPost.Post.Code;
  11490. DataStruct dStruct = GetPostStruct();
  11491. List<string> lw = new List<string>();
  11492. string id = GetPostString("id");
  11493. string pay_date1 = GetPostString("pay_date1");
  11494. string pay_date2 = GetPostString("pay_date2");
  11495. int type = GetPostInt("type");
  11496. if (type == 0)
  11497. {
  11498. if (pay_date1.Length > 0)
  11499. {
  11500. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11501. }
  11502. if (pay_date2.Length > 0)
  11503. {
  11504. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11505. }
  11506. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11507. }
  11508. if (type == 1)
  11509. {
  11510. if (pay_date1.Length > 0)
  11511. {
  11512. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11513. }
  11514. if (pay_date2.Length > 0)
  11515. {
  11516. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11517. }
  11518. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11519. }
  11520. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11521. DataTable dt = null;
  11522. dt = WebCache.GetData("view_orderlist", dStruct);
  11523. writeGridDataTableJson(dStruct.TotalCount, dt);
  11524. }
  11525. public void saveUrgentChargePrice()
  11526. {
  11527. string ctid = GetPostString("ctid");
  11528. if (!string.IsNullOrEmpty(ctid))
  11529. {
  11530. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11531. if (ceErpTradeCell != null)
  11532. {
  11533. double price = GetPostDouble("price");
  11534. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11535. if (ceErpTradeCellExtend == null)
  11536. {
  11537. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11538. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11539. }
  11540. ceErpTradeCellExtend.urgentCharge = price;
  11541. if (ceErpTradeCellExtend.ID > 0)
  11542. {
  11543. ceErpTradeCellExtend.Update();
  11544. }
  11545. else
  11546. {
  11547. ceErpTradeCellExtend.Save();
  11548. }
  11549. returnSuccessMsg("修改成功!");
  11550. return;
  11551. }
  11552. returnErrorMsg("找不到订单");
  11553. return;
  11554. }
  11555. returnErrorMsg("找不到订单");
  11556. }
  11557. public void finish_erp_order()
  11558. {
  11559. string ctid = GetPostString("ctid");
  11560. if (!string.IsNullOrEmpty(ctid))
  11561. {
  11562. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11563. {
  11564. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11565. if (ceErpTradeCell != null)
  11566. {
  11567. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11568. ceErpTradeCell.Update();
  11569. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11570. returnSuccessMsg("修改成功!");
  11571. return;
  11572. }
  11573. }
  11574. }
  11575. returnErrorMsg("找不到订单");
  11576. }
  11577. public void get_trade_order_list()
  11578. {
  11579. string tid = GetPostString("tid");
  11580. if (!string.IsNullOrEmpty(tid))
  11581. {
  11582. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11583. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11584. writeGridDataTableJson(data.Rows.Count, data);
  11585. return;
  11586. }
  11587. returnErrorMsg("找不到订单");
  11588. }
  11589. public void save_cell_spu()
  11590. {
  11591. string ctid = GetPostString("ctid");
  11592. string spu_id = GetPostString("spu_id");
  11593. if (!string.IsNullOrEmpty(ctid))
  11594. {
  11595. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11596. if (ceErpTradeCellExtend == null)
  11597. {
  11598. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11599. ceErpTradeCellExtend.ctid = ctid;
  11600. }
  11601. ceErpTradeCellExtend.spu_id = spu_id;
  11602. if (!string.IsNullOrEmpty(spu_id))
  11603. {
  11604. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11605. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  11606. ceErpTradeCellExtend.ToType = result;
  11607. List<int> products = new List<int>() { 13, 2524, 2557, 4, 2554, 57, 19 };
  11608. if (products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  11609. {
  11610. ceErpTradeCellExtend.ToType = "外协";
  11611. }
  11612. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  11613. {
  11614. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  11615. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  11616. }
  11617. }
  11618. if (ceErpTradeCellExtend.ID == 0)
  11619. {
  11620. ceErpTradeCellExtend.Create();
  11621. }
  11622. else
  11623. {
  11624. ceErpTradeCellExtend.Update();
  11625. }
  11626. returnSuccessMsg("修改成功!");
  11627. return;
  11628. }
  11629. returnErrorMsg("找不到订单");
  11630. }
  11631. public void change_express_info()
  11632. {
  11633. string ctid = GetPostString("ctid");
  11634. string transNo = GetPostString("transNo");
  11635. string transCom = GetPostString("transCom");
  11636. if (!string.IsNullOrEmpty(ctid))
  11637. {
  11638. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11639. if (ceErpTradeCellExtend == null)
  11640. {
  11641. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11642. ceErpTradeCellExtend.ctid = ctid;
  11643. }
  11644. ceErpTradeCellExtend.modExpressNo = transNo;
  11645. ceErpTradeCellExtend.modExpressCom = transCom;
  11646. ceErpTradeCellExtend.readMod = 2;
  11647. if (ceErpTradeCellExtend.ID == 0)
  11648. {
  11649. ceErpTradeCellExtend.Create();
  11650. }
  11651. else
  11652. {
  11653. ceErpTradeCellExtend.Update();
  11654. }
  11655. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11656. returnSuccessMsg("修改成功!");
  11657. return;
  11658. }
  11659. returnErrorMsg("找不到订单");
  11660. }
  11661. public void get_change_express_list()
  11662. {
  11663. DataStruct dStruct = GetPostStruct();
  11664. List<string> lw = new List<string>();
  11665. int st = 2;
  11666. string tid = GetPostString("ctid");
  11667. if (tid.Length > 0)
  11668. {
  11669. string select_tid = getTidByCtid(tid);
  11670. lw.Add(string.Format("tid='{0}'", select_tid));
  11671. }
  11672. string shopname = GetPostString("shopname");
  11673. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11674. string buyernick = GetPostString("buyer_nick");
  11675. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11676. string sellermemo = GetPostString("seller_memo");
  11677. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11678. string supplier = GetPostString("supplier");
  11679. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11680. string customer = GetPostString("customer");
  11681. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11682. string design = GetPostString("design");
  11683. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11684. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11685. string poscode = CurrentUser.UserPost.Post.Code;
  11686. if (poscode != "SysAdmin")
  11687. {
  11688. string shopid = CurrentUser.User.pemShop;
  11689. lw.Add(string.Format("shopId in ({0})", shopid));
  11690. }
  11691. lw.Add("readMod = 2");
  11692. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11693. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11694. writeGridDataTableJson(dStruct.TotalCount, dt);
  11695. }
  11696. public void deal_express_complete()
  11697. {
  11698. string ctid = GetPostString("ctid");
  11699. if (!string.IsNullOrEmpty(ctid))
  11700. {
  11701. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11702. if (ceErpTradeCellExtend == null)
  11703. {
  11704. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11705. ceErpTradeCellExtend.ctid = ctid;
  11706. }
  11707. ceErpTradeCellExtend.readMod = 1;
  11708. if (ceErpTradeCellExtend.ID == 0)
  11709. {
  11710. ceErpTradeCellExtend.Create();
  11711. }
  11712. else
  11713. {
  11714. ceErpTradeCellExtend.Update();
  11715. }
  11716. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11717. returnSuccessMsg("修改成功!");
  11718. return;
  11719. }
  11720. returnErrorMsg("找不到订单");
  11721. }
  11722. public void aftersale_return_visit()
  11723. {
  11724. string ctid = GetPostString("ctid");
  11725. if (!string.IsNullOrEmpty(ctid))
  11726. {
  11727. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11728. if (ceErpTradeCellExtend == null)
  11729. {
  11730. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11731. ceErpTradeCellExtend.ctid = ctid;
  11732. }
  11733. ceErpTradeCellExtend.returnVisit = 1;
  11734. if (ceErpTradeCellExtend.ID == 0)
  11735. {
  11736. ceErpTradeCellExtend.Create();
  11737. }
  11738. else
  11739. {
  11740. ceErpTradeCellExtend.Update();
  11741. }
  11742. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11743. if (ceErpTradeAfterSaleExtend != null)
  11744. {
  11745. ceErpTradeAfterSaleExtend.TextResult = "";
  11746. ceErpTradeAfterSaleExtend.Update();
  11747. }
  11748. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11749. returnSuccessMsg("修改成功!");
  11750. return;
  11751. }
  11752. returnErrorMsg("找不到订单");
  11753. }
  11754. public void orderPlaceInfo()
  11755. {
  11756. string ctids = GetPostString("ctids");
  11757. string[] list = ctids.Split(',');
  11758. foreach (string ctid in list)
  11759. {
  11760. CeErpSukuraData.createInfo(ctid, 3);
  11761. }
  11762. StringBuilder sql = new StringBuilder();
  11763. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11764. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11765. designHelper.api_approveDesign(ctids); //approveDesign
  11766. returnSuccessMsg("");
  11767. }
  11768. public void get_issue_list()
  11769. {
  11770. DataStruct dStruct = GetPostStruct();
  11771. List<string> lw = new List<string>();
  11772. int st = 2;
  11773. string tid = GetPostString("ctid");
  11774. if (tid.Length > 0)
  11775. {
  11776. string select_tid = getTidByCtid(tid);
  11777. lw.Add(string.Format("tid='{0}'", select_tid));
  11778. }
  11779. string shopname = GetPostString("shopname");
  11780. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11781. string buyernick = GetPostString("buyer_nick");
  11782. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11783. string sellermemo = GetPostString("seller_memo");
  11784. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11785. string supplier = GetPostString("supplier");
  11786. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11787. string customer = GetPostString("customer");
  11788. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11789. string design = GetPostString("design");
  11790. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11791. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11792. string poscode = CurrentUser.UserPost.Post.Code;
  11793. if (poscode != "SysAdmin")
  11794. {
  11795. string shopid = CurrentUser.User.pemShop;
  11796. lw.Add(string.Format("shopId in ({0})", shopid));
  11797. }
  11798. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11799. {
  11800. lw.Add("IssueState = 1");
  11801. }
  11802. lw.Add("IssueState > 0");
  11803. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11804. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11805. writeGridDataTableJson(dStruct.TotalCount, dt);
  11806. }
  11807. public void saveIssueContent()
  11808. {
  11809. string ctid = GetPostString("ctid");
  11810. if (!string.IsNullOrEmpty(ctid))
  11811. {
  11812. string content = GetPostString("content");
  11813. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11814. if (ceErpTradeAfterSaleExtend == null)
  11815. {
  11816. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11817. ceErpTradeAfterSaleExtend.tid = ctid;
  11818. }
  11819. ceErpTradeAfterSaleExtend.IssueContent = content;
  11820. ceErpTradeAfterSaleExtend.IssueState = 1;
  11821. if (ceErpTradeAfterSaleExtend.ID > 0)
  11822. {
  11823. ceErpTradeAfterSaleExtend.Update();
  11824. }
  11825. else
  11826. {
  11827. ceErpTradeAfterSaleExtend.Create();
  11828. }
  11829. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11830. returnSuccessMsg("添加成功!");
  11831. return;
  11832. }
  11833. returnErrorMsg("找不到订单");
  11834. }
  11835. public void dealIssueContent()
  11836. {
  11837. string ctid = GetPostString("ctid");
  11838. if (!string.IsNullOrEmpty(ctid))
  11839. {
  11840. string content = GetPostString("content");
  11841. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11842. if (ceErpTradeAfterSaleExtend != null)
  11843. {
  11844. ceErpTradeAfterSaleExtend.IssueState = 2;
  11845. ceErpTradeAfterSaleExtend.Update();
  11846. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11847. returnSuccessMsg("修改完成!");
  11848. return;
  11849. }
  11850. }
  11851. returnErrorMsg("找不到订单");
  11852. }
  11853. public void set_tid_attachments()
  11854. {
  11855. string tid = GetPostString("tid");
  11856. string atta = GetPostString("atta");
  11857. if (!string.IsNullOrEmpty(tid))
  11858. {
  11859. if (string.IsNullOrEmpty(atta))
  11860. {
  11861. returnErrorMsg("文件地址为空");
  11862. return;
  11863. }
  11864. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11865. if (ceErpTradeCell != null)
  11866. {
  11867. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11868. if (ceErpTrade == null)
  11869. {
  11870. returnErrorMsg("找不到订单");
  11871. return;
  11872. }
  11873. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11874. bool isSend = false;
  11875. if (dt != null && dt.Rows.Count > 0)
  11876. {
  11877. foreach (DataRow row in dt.Rows)
  11878. {
  11879. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11880. {
  11881. isSend = true;
  11882. }
  11883. }
  11884. if (isSend)
  11885. {
  11886. returnErrorMsg("已发货无法修改");
  11887. return;
  11888. }
  11889. ceErpTrade.Attachments = atta;
  11890. ceErpTrade.Update();
  11891. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11892. returnSuccessMsg("上传成功!");
  11893. return;
  11894. }
  11895. }
  11896. }
  11897. returnErrorMsg("找不到订单");
  11898. }
  11899. public void get_tid_attachments()
  11900. {
  11901. string tid = GetPostString("tid");
  11902. if (!string.IsNullOrEmpty(tid))
  11903. {
  11904. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11905. if (ceErpTradeCell != null)
  11906. {
  11907. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11908. if (ceErpTrade == null)
  11909. {
  11910. returnErrorMsg("找不到订单");
  11911. return;
  11912. }
  11913. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11914. return;
  11915. }
  11916. }
  11917. returnErrorMsg("找不到订单");
  11918. }
  11919. public void check_erp_sameorders()
  11920. {
  11921. if (UrlPostParmsCheck("ctid"))
  11922. {
  11923. string eid = GetPostString("ctid");
  11924. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11925. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11926. if (entity != null && ceErpTrade != null)
  11927. {
  11928. if (entity.OrderState > 6)
  11929. {
  11930. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11931. return;
  11932. }
  11933. StringBuilder sql = new StringBuilder();
  11934. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  11935. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11936. {
  11937. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11938. }
  11939. else
  11940. {
  11941. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11942. }
  11943. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11944. List<string> ids = new List<string>();
  11945. if (dt != null && dt.Rows.Count > 1)
  11946. {
  11947. bool needhe = true;
  11948. foreach (DataRow dr in dt.Rows)
  11949. {
  11950. ids.Add("'" + dr["ctid"] + "'");
  11951. /* //备注有合包
  11952. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11953. {
  11954. needhe = true;
  11955. }
  11956. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11957. {
  11958. needhe = true;
  11959. }
  11960. //顺丰快递
  11961. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11962. {
  11963. needhe = true;
  11964. }*/
  11965. }
  11966. if (!needhe)
  11967. {
  11968. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11969. return;
  11970. }
  11971. sql = new StringBuilder();
  11972. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11973. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11974. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11975. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11976. foreach (DataRow dr in dt.Rows)
  11977. {
  11978. dr["dstate"] = 0;
  11979. dr["dnumber"] = 0;
  11980. foreach (DataRow row in dt1.Rows)
  11981. {
  11982. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  11983. {
  11984. dr["dstate"] = 2;
  11985. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  11986. }
  11987. }
  11988. if (eid.Equals(dr["ctid"].ToString()))
  11989. {
  11990. dr["dstate"] = 1;
  11991. }
  11992. }
  11993. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  11994. return;
  11995. }
  11996. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11997. return;
  11998. }
  11999. returnErrorMsg("未找到订单");
  12000. return;
  12001. }
  12002. returnErrorMsg("缺少必要的参数");
  12003. }
  12004. public void get_mark_number()
  12005. {
  12006. string eid = GetPostString("ctid");
  12007. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12008. if (entity != null)
  12009. {
  12010. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12011. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12012. int current = 1;
  12013. if (ceErpDeliverMark == null)
  12014. {
  12015. StringBuilder sql = new StringBuilder();
  12016. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  12017. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12018. {
  12019. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12020. }
  12021. else
  12022. {
  12023. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12024. }
  12025. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12026. List<string> ids = new List<string>();
  12027. if (dt != null && dt.Rows.Count > 1)
  12028. {
  12029. foreach (DataRow dr in dt.Rows)
  12030. {
  12031. ids.Add("'" + dr["ctid"] + "'");
  12032. }
  12033. //查询已有的编号
  12034. sql = new StringBuilder();
  12035. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12036. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12037. if (dt1 == null || dt1.Rows.Count == 0)
  12038. {
  12039. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12040. List<int> list_number = new List<int>();
  12041. foreach (DataRow row in numbers.Rows)
  12042. {
  12043. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12044. }
  12045. //查询空余编号
  12046. for (int i = 0; i < list_number.Count + 2; i++)
  12047. {
  12048. if (!list_number.Contains(current))
  12049. {
  12050. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12051. //防止查询过程中有新数据生成
  12052. if (ceErpDeliverMark1 == null)
  12053. {
  12054. break;
  12055. }
  12056. }
  12057. current++;
  12058. }
  12059. }
  12060. else
  12061. {
  12062. foreach (DataRow row in dt1.Rows)
  12063. {
  12064. current = Convert.ToInt32(row["markNumber"]);
  12065. }
  12066. }
  12067. ceErpDeliverMark = new CeErpDeliverMark();
  12068. ceErpDeliverMark.ctid = eid;
  12069. ceErpDeliverMark.createtime = DateTime.Now;
  12070. if (ceErpTrade != null)
  12071. {
  12072. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12073. }
  12074. ceErpDeliverMark.markNumber = current;
  12075. ceErpDeliverMark.Create();
  12076. }
  12077. }
  12078. else
  12079. {
  12080. current = ceErpDeliverMark.markNumber;
  12081. }
  12082. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12083. return;
  12084. }
  12085. }
  12086. public void packOrderInfo()
  12087. {
  12088. string ctids = GetPostString("ctids");
  12089. if (!string.IsNullOrEmpty(ctids))
  12090. {
  12091. string[] ctid_list = ctids.Split(',');
  12092. if (ctid_list.Length > 20)
  12093. {
  12094. returnErrorMsg("单次下载次数不能超过20个");
  12095. return;
  12096. }
  12097. StringBuilder sql = new StringBuilder();
  12098. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  12099. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12100. int supplierId = 0;
  12101. StringBuilder insterSql = new StringBuilder();
  12102. for (int i = 0; i < dt.Rows.Count; i++)
  12103. {
  12104. DataRow row = dt.Rows[i];
  12105. if (i == 0)
  12106. {
  12107. supplierId = Convert.ToInt32(row["SupplierId"]);
  12108. }
  12109. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12110. {
  12111. returnErrorMsg("同车间的订单才能一起打包");
  12112. return;
  12113. }
  12114. int orderState = Convert.ToInt32(row["OrderState"]);
  12115. if (orderState != 5)
  12116. {
  12117. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12118. return;
  12119. }
  12120. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12121. }
  12122. CeErpPackData ceErpPackData = new CeErpPackData();
  12123. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip";
  12124. ceErpPackData.supplierId = supplierId;
  12125. ceErpPackData.createtime = DateTime.Now;
  12126. ceErpPackData.createBy = CurrentUser.UserID;
  12127. ceErpPackData.createName = CurrentUser.UserName;
  12128. ceErpPackData.Create();
  12129. if (ceErpPackData.ID > 0)
  12130. {
  12131. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12132. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12133. }
  12134. returnSuccessMsg("打包成功");
  12135. return;
  12136. }
  12137. returnErrorMsg("缺少必要的参数");
  12138. }
  12139. }
  12140. }