sync.order.cs 660 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. using NPOI.POIFS.Properties;
  51. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  52. using static SiteCore.taoObj.Api_tmc_refund_info_Obj;
  53. namespace SiteCore.Handler
  54. {
  55. public partial class sync
  56. {
  57. public void get_erp_orderlist()
  58. {
  59. string poscode = CurrentUser.UserPost.Post.Code;
  60. DataStruct dStruct = GetPostStruct();
  61. //string a = SecurityHelper.DecryptSymmetric("BnK3+504SQ8=");
  62. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\(250924170328638492)-210x140mm-10个-UV转印贴彩色模切-GL-gzb520gzb-广东省-龙井《4765947843000325546-琳19890725》.ai");
  63. //apiHelper.Api_SyncOrderByTime("598825");
  64. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  65. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  66. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  67. //banniuApiHelper.sendLogisticsInfo(null);
  68. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  69. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  70. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  71. //int sid = commonHelper.autoDistributeToSupplier(entity);
  72. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  73. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1756945416000,\"deliveryType\":\"OFFLINE\",\"discountFee\":20.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1757118213000,\"lines\":[{\"latestDeliveryTime\":1757118213000,\"mark2\":[\"DELIVERED\"],\"num\":1,\"outerId\":\"JSBHUVZYT\",\"payment\":10.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/490100363/O1CN01pEaojF1EYIjYhp76h_!!490100363.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"4718408366815008220\",\"refSkuId\":\"5139754537453\",\"refSpuId\":\"641811002682\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":10.0,\"singleFee\":10.0,\"spuOuterId\":\"JSBHUVZYT\",\"standards\":\"【撕膜留字 | 易撕无残留】\",\"status\":\"SHIPPED\",\"title\":\"水晶标贴UV转印贴logo定制透明标识贴纸设计金属商标烫金标签定做\",\"totalFee\":10.0,\"totalPrice\":30.0,\"totalSellPrice\":10.0}],\"logisticsOrderNo\":\"YT7568465598389\",\"mark2\":[],\"modifyTime\":1756946987000,\"openBuyerId\":\"AAEVRHraABkUZRPgSx3gFRIR\",\"openBuyerNick\":\"a**\",\"openSellerNick\":\"琳19890725\",\"orderSource\":\"SYNC\",\"orderTime\":1756945412000,\"payTime\":1756945413000,\"payment\":10.0,\"platServiceFee\":0.0,\"posCode\":\"guliang\",\"posId\":598696,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0,\"logisticList\":[{\"logisticNo\":\"YT7568465598389\",\"logisticName\":\"圆通速递\"}]},\"receivedPayment\":0.0,\"receiverCity\":\"苏州市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"吴江区\",\"receiverId\":\"871dbaa880a955e031c5061436d7a5c1$\",\"receiverState\":\"江苏省\",\"receiverTown\":\"江陵街道\",\"refOid\":\"4718408366815008220\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"寄样-不干胶-uv转印贴小尺寸字母银色黑色-aa_小f-龙井-5,寄样-不干胶-金属标字母银色黑色-aa_小f-龙井-5\",\"serviceFee\":0.0,\"shippingTime\":1756946983000,\"status\":\"SHIPPED\",\"sysTags\":[],\"totalFee\":10.0,\"totalPrice\":30.0,\"totalSellPrice\":10.0,\"type\":\"SALE\"}}");
  74. //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}}");
  75. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  76. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  77. //preSalesHelper.dealMessageInfo("{\"bizOrder\":{\"id\":235819,\"parentId\":null,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderNo\":\"4624034580248409502\",\"shopId\":4,\"shopCode\":\"aolifu\",\"customerId\":345874,\"customerServiceId\":3184,\"thirdOrderId\":\"4624034580248409502\",\"orderPlatform\":\"TMALL\",\"openBuyerId\":\"AAEORHraABkUZRHgSx6ksuhU\",\"openBuyerNick\":\"tb278604202340\",\"openSellerNick\":\"奥丽芙旗舰店\",\"productUrl\":null,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"payAmount\":125.0,\"unrefundedAmount\":125.0,\"discountAmount\":5.0,\"csDiscountAmount\":-35.0,\"num\":13,\"province\":\"山西省\",\"city\":\"吕梁市\",\"area\":\"孝义市\",\"receiverTown\":\"孝义市\",\"address\":null,\"thirdReceiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"receiverName\":null,\"receiverMobile\":null,\"weChatId\":null,\"phone\":null,\"designContent\":\"\",\"designPics\":\"[]\",\"weChatQrPics\":\"[]\",\"addressFileUrl\":\"\",\"thirdFlag\":\"NONE\",\"remark\":null,\"sellerRemark\":\"\",\"buyerRemark\":\"\",\"timeoutRemark\":null,\"discountRemark\":null,\"status\":\"NOT_SHIPPED\",\"refundStatus\":0,\"internalStatus\":2,\"auditStatus\":null,\"auditUserId\":null,\"auditor\":null,\"customTag\":null,\"isRepurchase\":false,\"isOffline\":false,\"paymentFile\":null,\"orderTime\":\"2025-07-10 14:46:13\",\"modifyTime\":\"2025-07-10 14:46:37\",\"payTime\":\"2025-07-10 14:46:37\",\"confirmTime\":\"2025-07-10 14:51:23\",\"auditTime\":null,\"shippingTime\":null,\"finishTime\":null,\"erpCustomerServiceId\":3319,\"openBuyerID\":\"AAEORHraABkUZRHgSx6ksuhU\",\"orderFrom\":\"10\",\"receiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"bizOrderItems\":[{\"id\":310334,\"orderId\":235819,\"thirdOrderItemId\":\"4624034580248409502\",\"thirdSpuId\":\"740203900330\",\"thirdSkuId\":\"0\",\"title\":\"pvc贴纸定制防水不干胶圆形贴标自粘商标logo广告二维码标签印刷\",\"specification\":\"\",\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2433960672/O1CN01D0ZzzR1GppCHSoBjD_!!4611686018427382496-0-item_pic.jpg\",\"price\":10.0,\"sellPrice\":9.62,\"amount\":9.62,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"totalAmount\":125.0,\"num\":13,\"refundStatus\":\"NO_REFUND\"}],\"bizOrderSplits\":[{\"id\":151557,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328848\",\"splitNo\":\"C1_4624034580248409502\",\"splitInfoNo\":\"C2+1\",\"splitAmount\":52.64,\"quoteRecordId\":520208,\"quoteAmount\":40.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328848)-[C2+1]-80x20mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328848\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":40.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":80.00,\"width\":20.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"80x20mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":40.00,\"numberType\":\"\",\"isDianziOrder\":0},{\"id\":151558,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328853\",\"splitNo\":\"C2_4624034580248409502\",\"splitInfoNo\":\"C2+2\",\"splitAmount\":72.36,\"quoteRecordId\":520209,\"quoteAmount\":55.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328853)-[C2+2]-90x50mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328853\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":55.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":90.00,\"width\":50.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"90x50mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":55.00,\"numberType\":\"\",\"isDianziOrder\":0}]}}");
  78. /*string path = "C:\\Users\\231010\\Downloads\\tids.txt";
  79. string path1 = "C:\\Users\\231010\\Downloads\\tid.txt";
  80. string tids = File.ReadAllText(path);
  81. List<string> list = tids.Split(',').ToList();
  82. int index = 0;
  83. foreach (string item in list)
  84. {
  85. CeErpTrade ceErpTrade = CeErpTrade.Get(item.Replace("'", ""));
  86. try
  87. {
  88. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  89. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  90. {
  91. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  92. }
  93. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  94. List<string> tidList = new List<string>();
  95. if (dataTable != null && dataTable.Rows.Count > 0)
  96. {
  97. foreach (DataRow row in dataTable.Rows)
  98. {
  99. tidList.Add("'" + row["tid"].ToString() + "'");
  100. }
  101. }
  102. if (tidList.Count > 0)
  103. {
  104. sql = string.Format("SELECT count(*) as number FROM [dbo].[CE_ErpTradeCell] WITH(NOLOCK) WHERE tid in ({0}) AND IsSample = 0 ", string.Join(",", tidList));
  105. dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  106. if (dataTable != null && dataTable.Rows.Count > 0)
  107. {
  108. int count = Convert.ToInt32(dataTable.Rows[0]["number"]);
  109. if (count > 0)
  110. {
  111. Debug.WriteLine(index++);
  112. continue;
  113. }
  114. }
  115. }
  116. File.AppendAllText(path1, ceErpTrade.tid + "\n");
  117. }
  118. catch (Exception e)
  119. {
  120. File.AppendAllText(path1, "e:" + ceErpTrade.tid + "\n");
  121. }
  122. Debug.WriteLine(index++);
  123. }*/
  124. //string a = commonHelper.convertQNMemo("48x61mm-4款各40个-铜版纸-不干胶-覆膜模切-tb963561715-金陵-顺丰到付.粘成品.6.5cm牙签-老客户改稿找金陵拉群-16发", CeErpTradeCell.GetByCtid("2879265072537265386"));
  125. List<string> lw = new List<string>();
  126. string tid = GetPostString("ctid");
  127. string date1 = GetPostString("date1");
  128. //12-1 修改
  129. string urgent = GetPostString("urgent");
  130. string back = GetPostString("back");
  131. string offlineSearch = GetPostString("offlineSearch");
  132. int paramsCount = 0;
  133. if (!string.IsNullOrWhiteSpace(urgent))
  134. {
  135. if (urgent.Equals("true"))
  136. {
  137. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  138. }
  139. }
  140. if (!string.IsNullOrWhiteSpace(back))
  141. {
  142. if (back.Equals("true"))
  143. {
  144. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  145. }
  146. }
  147. if (!string.IsNullOrWhiteSpace(offlineSearch))
  148. {
  149. if (offlineSearch.Equals("true"))
  150. {
  151. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  152. }
  153. }
  154. //end
  155. string date2 = GetPostString("date2");
  156. string buyernick = GetPostString("buyer_nick");
  157. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  158. {
  159. if (tid.Length <= 0 && buyernick.Length <= 0)
  160. {
  161. return;
  162. }
  163. }
  164. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  165. {
  166. if (tid.Length > 0)
  167. {
  168. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  169. if (ceErpTradeCell != null)
  170. {
  171. tid = ceErpTradeCell.tid;
  172. }
  173. List<string> select_tid = getTidByCtidMore(tid);
  174. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  175. }
  176. if (buyernick.Length > 0)
  177. {
  178. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  179. }
  180. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  181. if (dw.Length > 0)
  182. {
  183. lw.Add(dw);
  184. }
  185. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  186. {
  187. string usershop = CurrentUser.User.pemShop;
  188. lw.Add(string.Format("ShopId in ({0})", usershop));
  189. }
  190. }
  191. else
  192. {
  193. if (ex_psize == 0)
  194. {
  195. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  196. }
  197. if (PKey != "admin" && poscode != "SysAdmin")
  198. {
  199. string usershop = CurrentUser.User.pemShop;
  200. lw.Add(string.Format("ShopId in ({0})", usershop));
  201. paramsCount++;
  202. }
  203. }
  204. string uploaddate1 = GetPostString("uploaddate1");
  205. string uploaddate2 = GetPostString("uploaddate2");
  206. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  207. if (update.Length > 0) lw.Add(update);
  208. string deliverydate1 = GetPostString("deliverydate1");
  209. string deliverydate2 = GetPostString("deliverydate2");
  210. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  211. if (deliverydate.Length > 0)
  212. {
  213. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  214. };
  215. string shopname = GetPostString("shopname");
  216. if (shopname.Length > 0)
  217. {
  218. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopname);
  219. if(ceErpShop != null)
  220. {
  221. lw.Add(string.Format("shopId = {0}", ceErpShop.ID));
  222. }
  223. }
  224. string addwechat = GetPostString("addwechat");
  225. if (addwechat.Length > 0)
  226. {
  227. int addWt = Convert.ToInt32(addwechat);
  228. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  229. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  230. }
  231. string customer = GetPostString("customer");
  232. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  233. string design = GetPostString("design");
  234. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  235. string orderState = GetPostString("orderState");
  236. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  237. string address = GetPostString("address");
  238. 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));
  239. string sellermemo = GetPostString("seller_memo");
  240. if (sellermemo.Length > 0)
  241. {
  242. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  243. }
  244. string otherMemo = GetPostString("otherMemo");
  245. if (otherMemo.Length > 0)
  246. {
  247. lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  248. }
  249. string backReason = GetPostString("backReason");
  250. if (backReason.Length > 0)
  251. {
  252. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  253. }
  254. string apdate1 = GetPostString("apdate1");
  255. string apdate2 = GetPostString("apdate2");
  256. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  257. if (dwap.Length > 0) lw.Add(dwap);
  258. string price1 = GetPostString("price1");
  259. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  260. string price2 = GetPostString("price2");
  261. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  262. string isoldcustomer = GetPostString("isoldcus");
  263. string spudata = GetPostString("spudata");
  264. if ("0".Equals(spudata))
  265. {
  266. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  267. }
  268. if ("1".Equals(spudata))
  269. {
  270. lw.Add(string.Format("spu_id <> ''"));
  271. }
  272. string finishdate1 = GetPostString("finishdate1");
  273. string finishdate2 = GetPostString("finishdate2");
  274. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  275. bool isFinish = false;
  276. if (finishdate.Length > 0)
  277. {
  278. lw.Add(finishdate);
  279. isFinish = true;
  280. paramsCount++;
  281. }
  282. if (isoldcustomer.Length > 0)
  283. {
  284. if ("2".Equals(isoldcustomer))
  285. {
  286. lw.Add(string.Format("VipCustomer=1"));
  287. }
  288. else
  289. {
  290. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  291. }
  292. }
  293. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  294. if (ex_psize > 0)
  295. {
  296. int UserID = CurrentUser.UserID;
  297. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  298. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  299. {
  300. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  301. }
  302. dStruct.Order = "pay_time desc";
  303. }
  304. string isNew = GetPostString("isNew");
  305. if (isNew == "true")
  306. {
  307. lw.Add(string.Format("IsNew = {0}", 1));
  308. }
  309. string overtime = GetPostString("overtime");
  310. if (overtime == "1")
  311. {
  312. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  313. }
  314. String usePost = CurrentUser.UserPost.Post.Code;
  315. if (usePost.Equals("Operation") == true)
  316. {
  317. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  318. }
  319. else
  320. {
  321. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  322. }
  323. //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";
  324. if (dStruct.PageSize == 100000)
  325. {
  326. dStruct.Order = "";
  327. }
  328. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  329. DataTable dt = null;
  330. string tablename = "view_orderlist";
  331. if (isFinish)
  332. {
  333. tablename = "view_orderlist_end";
  334. }
  335. dt = WebCache.GetData(tablename, dStruct);
  336. if (dt != null && dt.Rows.Count > 0)
  337. {
  338. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  339. foreach (DataRow dr in dt.Rows)
  340. {
  341. try
  342. {
  343. if (dr["refund_fees"] != null)
  344. {
  345. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  346. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  347. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  348. if (payment == refund_fees)
  349. {
  350. dr["refund_fees"] = Math.Round(refund_fees, 2);
  351. }
  352. else if (refund_fees == total_fee)
  353. {
  354. dr["refund_fees"] = payment;
  355. }
  356. else
  357. {
  358. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  359. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  360. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  361. }
  362. }
  363. // 对象操作
  364. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  365. ceErpTradeCell.ctid = dr["ctid"].ToString();
  366. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  367. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  368. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  369. if (dStruct.PageSize != 100000)
  370. {
  371. if (dr["DispatchSort"].ToString() == "2")
  372. {
  373. dr["gongchuang"] = 200;
  374. }
  375. else if ("外协".Equals(dr["ToType"].ToString()))
  376. {
  377. dr["gongchuang"] = 200;
  378. }
  379. else if ("内部".Equals(dr["ToType"].ToString()))
  380. {
  381. dr["gongchuang"] = -1;
  382. }
  383. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  384. {
  385. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  386. dr["gongchuang"] = response.code;
  387. }
  388. }
  389. }
  390. catch (NullReferenceException ex)
  391. {
  392. // 处理空引用异常
  393. dr["refund_fees"] = "0.00";
  394. }
  395. }
  396. }
  397. writeGridDataTableJson(dStruct.TotalCount, dt);
  398. }
  399. public void get_erp_orderlist_sumprice()
  400. {
  401. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  402. return;
  403. List<string> lw = new List<string>();
  404. string tid = GetPostString("ctid");
  405. string date1 = GetPostString("date1");
  406. string date2 = GetPostString("date2");
  407. if (tid.Length > 0 || date1.Length > 0)
  408. {
  409. lw.Add(string.Format("ctid like '%{0}%'", tid));
  410. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  411. if (dw.Length > 0) lw.Add(dw);
  412. }
  413. else
  414. {
  415. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  416. }
  417. string shopname = GetPostString("shopname");
  418. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  419. string buyernick = GetPostString("buyer_nick");
  420. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  421. string customer = GetPostString("customer");
  422. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  423. string design = GetPostString("design");
  424. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  425. string orderState = GetPostString("orderState");
  426. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  427. string address = GetPostString("address");
  428. 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));
  429. string sellermemo = GetPostString("seller_memo");
  430. if (sellermemo.Length > 0)
  431. {
  432. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  433. }
  434. string apdate1 = GetPostString("apdate1");
  435. string apdate2 = GetPostString("apdate2");
  436. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  437. if (dwap.Length > 0) lw.Add(dwap);
  438. string price1 = GetPostString("price1");
  439. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  440. string price2 = GetPostString("price2");
  441. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  442. string isoldcustomer = GetPostString("isoldcus");
  443. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  444. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  445. if (PKey != "admin")
  446. {
  447. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  448. lw.Add(string.Format("shopId in ({0})", usershop));
  449. }
  450. //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";
  451. string mainWhere = string.Join(" and ", lw.ToArray());
  452. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  453. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  454. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  455. decimal total = 0;
  456. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  457. {
  458. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  459. }
  460. var res = new
  461. {
  462. data = total
  463. };
  464. string ro_jsond = JsonConvert.SerializeObject(res);
  465. returnSuccess(ro_jsond);
  466. return;
  467. }
  468. public void get_erp_CustomerServiceGather()
  469. {
  470. string userWhere = "", orderWhere = "";
  471. List<string> lw = new List<string>();
  472. string customer = GetPostString("customer");
  473. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  474. string shopname = GetPostString("shopname");
  475. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  476. string date1 = GetPostString("date1");
  477. string date2 = GetPostString("date2");
  478. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  479. if (dw.Length > 0) lw.Add(dw);
  480. orderWhere = string.Join(" and ", lw.ToArray());
  481. 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 " +
  482. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  483. "left join " +
  484. "( " +
  485. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  486. ") as b on a.ID = b.CustomerUserId " +
  487. "left join " +
  488. "( " +
  489. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  490. ") as d on a.ID = d.CustomerUserId " +
  491. "left join " +
  492. "( " +
  493. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  494. ") as e on a.ID = e.CustomerUserId " +
  495. "left join " +
  496. "( " +
  497. " select CustomerUserId, RefundCount, RefundSum from " +
  498. " ( " +
  499. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  500. " from CE_ErpTradeRefund a " +
  501. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  502. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  503. " group by CustomerUserId " +
  504. " ) as a " +
  505. ") as f on a.ID = f.CustomerUserId " +
  506. "where a.PostCode = 'CustomerService'",
  507. userWhere, orderWhere);
  508. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  509. writeGridDataTableJson(dt.Rows.Count, dt);
  510. //writeGridDataTableJson(dt.Rows.Count, dt);
  511. }
  512. //设计汇总
  513. public void get_erp_DesignerGather()
  514. {
  515. string userWhere = "", orderWhere = "";
  516. List<string> lw = new List<string>();
  517. string Designer = GetPostString("designer");
  518. int org = GetPostInt("org");
  519. if (Designer.Length > 0)
  520. {
  521. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  522. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  523. }
  524. else if (org > 0)
  525. {
  526. userWhere = string.Format(" where OrgID ={0}", org);
  527. }
  528. string shopname = GetPostString("shopname");
  529. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  530. string state = GetPostString("state");
  531. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  532. string OrderArea = GetPostString("order_area");
  533. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  534. string date1 = GetPostString("date1");
  535. string date2 = GetPostString("date2");
  536. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  537. if (dw.Length > 0) lw.Add(dw);
  538. string UpDate1 = GetPostString("UpDate1");
  539. string UpDate2 = GetPostString("UpDate2");
  540. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  541. if (dw.Length > 0) lw.Add(dw);
  542. orderWhere = string.Join(" and ", lw.ToArray());
  543. 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 (" +
  544. "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 " +
  545. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  546. "left join " +
  547. "( " +
  548. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  549. ") as b on a.ID = b.DesignUserId " +
  550. "left join " +
  551. "( " +
  552. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  553. ") as d on a.ID = d.DesignUserId " +
  554. "left join " +
  555. "( " +
  556. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  557. ") as e on a.ID = e.DesignUserId " +
  558. "left join " +
  559. "( " +
  560. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  561. ") as g on a.ID = g.DesignUserId " +
  562. "left join " +
  563. "( " +
  564. " select CustomerUserId, RefundCount, RefundSum from " +
  565. " ( " +
  566. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  567. " from CE_ErpTradeRefund a " +
  568. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  569. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  570. " group by CustomerUserId " +
  571. " ) as a " +
  572. ") as f on a.ID = f.CustomerUserId " +
  573. "where a.PostCode = 'Designer') as z",
  574. userWhere, orderWhere);
  575. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  576. writeGridDataTableJson(dt.Rows.Count, dt);
  577. }
  578. //删除tradecell的订单
  579. public void del_erp_cellorder()
  580. {
  581. if (UrlPostParmsCheck("ctid"))
  582. {
  583. string eid = GetPostString("ctid");
  584. CeErpTradeCell.DelByCtid(eid);
  585. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  586. returnSuccessMsg("删除成功");
  587. }
  588. }
  589. public void clear_erp_refundstate()
  590. {
  591. if (UrlPostParmsCheck("ids"))
  592. {
  593. string eids = GetPostString("ids");
  594. string[] ctidList = eids.Split(',');
  595. foreach (string ctid in ctidList)
  596. {
  597. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  598. if (entity != null)
  599. {
  600. entity.IsRefund = 0;
  601. entity.Update();
  602. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  603. }
  604. else
  605. continue;
  606. }
  607. returnSuccessMsg("操作成功");
  608. return;
  609. }
  610. returnErrorMsg("缺少必要参数");
  611. }
  612. public void set_erp_urgency()
  613. {
  614. if (UrlPostParmsCheck("ctid"))
  615. {
  616. string eid = GetPostString("ctid");
  617. CeErpTradeCell entity = null;
  618. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  619. if (entity != null)
  620. {
  621. double prices = commonHelper.calculationPrice(entity);
  622. if (prices <= 100)
  623. {
  624. returnErrorMsg("此订单金额不足100元,无法加急。");
  625. return;
  626. }
  627. string utime = GetPostString("urgencytime");
  628. if (utime.Length > 0)
  629. {
  630. entity.UrgencyTime = Convert.ToDateTime(utime);
  631. }
  632. else
  633. {
  634. returnErrorMsg("请选择加急时间");
  635. return;
  636. }
  637. if (entity.OrderState <= 4)
  638. {
  639. //entity.seller_memo = entity.seller_memo + "-加急";
  640. string smemo = entity.seller_memo;
  641. int kindex = smemo.IndexOf(")");
  642. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  643. if (lastoneStr != "-")
  644. {
  645. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  646. }
  647. string prememo = smemo.Substring(0, kindex + 2);
  648. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  649. int lastkindex = lastmemo.IndexOf("(");
  650. DateTime urgtime = Convert.ToDateTime(utime);
  651. string newlastmemo = "";
  652. if (lastkindex == 0)
  653. {
  654. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  655. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  656. }
  657. else
  658. {
  659. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  660. }
  661. entity.seller_memo = prememo + newlastmemo;
  662. }
  663. entity.IsUrgency = true;
  664. entity.UpdateTime = DateTime.Now;
  665. entity.Update();
  666. ApiVo apiVo = new ApiVo();
  667. apiVo.orderNumber = entity.ctid;
  668. apiVo.actionName = "changeDesign";
  669. apiVo.orderRemarks = entity.seller_memo;
  670. apiVo.remarkSign = 3;
  671. designHelper.API_WorkCore(apiVo); //changeDesign
  672. CeErpSukuraData.createInfo(entity.ctid, 7);
  673. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  674. returnSuccessMsg("设置成功!");
  675. return;
  676. }
  677. returnErrorMsg("找不到记录");
  678. }
  679. }
  680. public void set_erp_reset()
  681. {
  682. if (UrlPostParmsCheck("ctid"))
  683. {
  684. string eid = GetPostString("ctid");
  685. CeErpTradeCell entity = null;
  686. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  687. if (entity != null)
  688. {
  689. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  690. {
  691. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  692. {
  693. returnErrorMsg("财务要求已下单已发货无法重置");
  694. return;
  695. }
  696. }
  697. entity.IsUrgency = false;
  698. entity.seller_memo = "";
  699. entity.OtherMemo = "";
  700. entity.OrderState = 0;
  701. entity.IsReturn = 0;
  702. //entity.IsRefund = 0;
  703. entity.MemoOpt = 0;
  704. entity.AfterSaleState = 0;
  705. entity.AfterSaleResponsible = "";
  706. entity.AfterSaleUserId = 0;
  707. entity.IsNeedBill = 0;
  708. entity.CustomerUserId = 0;
  709. entity.DesignUserId = 0;
  710. entity.SupplierId = 0;
  711. entity.PlaceUserId = 0;
  712. entity.ptid = "";
  713. entity.IsSample = 0;
  714. entity.IsXianHuo = 0;
  715. entity.isDianziOrder = 0;
  716. entity.DispatchSort = 0;
  717. entity.IsVerifyToSupplier = false;
  718. entity.FinishPlaceTime = null;
  719. entity.Update();
  720. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  721. if (trade != null)
  722. {
  723. trade.seller_memo = "";
  724. trade.Update();
  725. }
  726. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  727. returnSuccessMsg("重置成功!");
  728. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  729. if (desginBill != null)
  730. {
  731. desginBill.isDel = 1;
  732. desginBill.Update();
  733. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  734. }
  735. ApiVo apiVo = new ApiVo();
  736. apiVo.orderNumber = entity.ctid;
  737. apiVo.actionName = "resetDesign";
  738. designHelper.API_WorkCore(apiVo);//resetDesign
  739. return;
  740. }
  741. returnErrorMsg("找不到记录");
  742. }
  743. }
  744. public void save_erp_sellermemo()
  745. {
  746. if (UrlPostParmsCheck("ctid"))
  747. {
  748. string ctid = GetPostString("ctid");
  749. CeErpTradeCell entity = null;
  750. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  751. if (entity != null)
  752. {
  753. string memo = GetPostString("seller_memo");
  754. string qn_memo = GetPostString("qn_memo");
  755. memo = memo.Replace(" ", "");
  756. if (memo.Contains("补差"))
  757. {
  758. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  759. return;
  760. }
  761. List<string> bitList = new List<string>
  762. {
  763. "\\","/",":","*","?", "\"","<" ,">","|"
  764. };
  765. bool isIn = false;
  766. foreach (string bit in bitList)
  767. {
  768. if (memo.Contains(bit))
  769. {
  770. isIn = true;
  771. }
  772. }
  773. if (isIn)
  774. {
  775. returnErrorMsg("不能使用 一些符合作为文件名");
  776. return;
  777. }
  778. if (entity.seller_memo != memo)
  779. {
  780. if (entity.IsSample == 2)
  781. {
  782. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  783. return;
  784. }
  785. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  786. {
  787. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  788. {
  789. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  790. return;
  791. }
  792. /*if (CurrentUser.UserPost.Post.Code != "Place")
  793. {
  794. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  795. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  796. {
  797. returnErrorMsg("售前系统订单无法再此修改!");
  798. return;
  799. }
  800. }*/
  801. }
  802. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  803. }
  804. if (!string.IsNullOrEmpty(qn_memo) && !(entity.IsSample > 0 || entity.ctid.Contains("N_") || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物")))
  805. {
  806. if (entity.OrderState >= 5)
  807. {
  808. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  809. return;
  810. }
  811. string delMemo = commonHelper.convertQNMemo(qn_memo, ref entity);
  812. if (string.IsNullOrEmpty(delMemo))
  813. {
  814. returnErrorMsg("备注不规范,无法识别");
  815. return;
  816. }
  817. memo = delMemo;
  818. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统千牛修改为:" + memo, entity.OrderState, 1);
  819. }
  820. commonHelper.getCytPrice(entity);
  821. int memoopt = GetPostInt("MemoOpt");
  822. Boolean ismemoopt = false;
  823. if (memoopt > 0)
  824. {
  825. string stropt = "";
  826. if (memoopt == 1)
  827. {
  828. stropt = "“改稿”";
  829. ismemoopt = true;
  830. }
  831. else if (memoopt == 2)
  832. {
  833. stropt = "“定稿”";
  834. }
  835. else if (memoopt == 3)
  836. {
  837. stropt = "“查货”";
  838. CeErpSukuraData.createInfo(entity.ctid, 6);
  839. }
  840. entity.MemoOpt = Convert.ToInt32(memoopt);
  841. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  842. }
  843. if (entity.OrderState < 5)
  844. {
  845. memo = memo.Replace("(", "(");
  846. memo = memo.Replace(")", ")");
  847. }
  848. /* if (entity.OrderState < 3)
  849. {
  850. entity.DispatchSort = 0;
  851. }*/
  852. entity.seller_memo = memo;
  853. entity.UpdateTime = DateTime.Now;
  854. entity.Update();
  855. ApiVo apiVo = new ApiVo();
  856. apiVo.orderNumber = entity.ctid;
  857. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  858. apiVo.orderRemarks = memo;
  859. apiVo.remarkSign = memoopt;
  860. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  861. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  862. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  863. {
  864. dataHelper.api_orderBack(entity.ctid, "0", "");
  865. }
  866. if (entity.seller_memo.Contains("改稿"))
  867. {
  868. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  869. }
  870. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  871. returnSuccessMsg("保存成功!");
  872. return;
  873. }
  874. returnErrorMsg("找不到记录");
  875. }
  876. }
  877. public void ins_erp_checkorder()
  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. if (entity.OrderState < 6)
  887. {
  888. returnErrorMsg("下单完成后才可查货");
  889. return;
  890. }
  891. /*if (entity.OrderState > 6)
  892. {
  893. returnErrorMsg("订单已发货");
  894. return;
  895. }*/
  896. if (entity.FinishPlaceTime != null)
  897. {
  898. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  899. {
  900. returnErrorMsg("下单时间不足,无法查货");
  901. return;
  902. }
  903. }
  904. entity.MemoOpt = 3;
  905. entity.CheckOrderTime = DateTime.Now;
  906. entity.UpdateTime = DateTime.Now;
  907. entity.Update();
  908. CeErpSukuraData.createInfo(entity.ctid, 6);
  909. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  910. returnSuccessMsg("操作成功!");
  911. return;
  912. }
  913. returnErrorMsg("找不到记录");
  914. }
  915. }
  916. public void save_erp_othermemo()
  917. {
  918. if (UrlPostParmsCheck("ctid"))
  919. {
  920. string ctid = GetPostString("ctid");
  921. CeErpTradeCell entity = null;
  922. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  923. if (entity != null)
  924. {
  925. entity.OtherMemo = GetPostString("otherMemo");
  926. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  927. {
  928. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  929. StringBuilder sql = new StringBuilder();
  930. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  931. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  932. if (dt != null && dt.Rows.Count > 0)
  933. {
  934. foreach (DataRow dr in dt.Rows)
  935. {
  936. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  937. {
  938. //品类一直
  939. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  940. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  941. if (ceErpSampleCustomer == null)
  942. {
  943. ceErpSampleCustomer = new CeErpSampleCustomer();
  944. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  945. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  946. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  947. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  948. ceErpSampleCustomer.shopId = entity.ShopId;
  949. }
  950. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  951. ceErpSampleCustomer.lastTid = entity.tid;
  952. if (ceErpSampleCustomer.ID > 0)
  953. {
  954. ceErpSampleCustomer.Update();
  955. }
  956. else
  957. {
  958. ceErpSampleCustomer.Create();
  959. }
  960. }
  961. }
  962. }
  963. }
  964. //if (entity.IsOldCustomer == 1)
  965. //{
  966. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  967. //{
  968. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  969. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  970. //}
  971. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  972. //{
  973. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  974. // {
  975. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  976. // {
  977. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  978. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  979. // }
  980. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  981. // {
  982. // entity.OrderState = 2;
  983. // entity.DesignUserId = 0;
  984. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  985. // }
  986. // else
  987. // {
  988. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  989. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  990. // }
  991. // }
  992. //}
  993. //}
  994. entity.UpdateTime = DateTime.Now;
  995. entity.Update();
  996. returnSuccessMsg("保存成功!");
  997. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  998. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  999. if (entity.OtherMemo.Contains("改稿"))
  1000. {
  1001. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1002. }
  1003. return;
  1004. }
  1005. returnErrorMsg("找不到记录");
  1006. }
  1007. }
  1008. public void save_erp_customermemo()
  1009. {
  1010. if (UrlPostParmsCheck("ctid"))
  1011. {
  1012. string ctid = GetPostString("ctid");
  1013. CeErpTradeCell entity = null;
  1014. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1015. if (entity != null)
  1016. {
  1017. entity.UpdateTime = DateTime.Now;
  1018. entity.CustomerMemo = GetPostString("CustomerMemo");
  1019. entity.Update();
  1020. ApiVo apiVo = new ApiVo();
  1021. apiVo.orderNumber = entity.ctid;
  1022. apiVo.actionName = "followRemarks";
  1023. apiVo.orderRemarks = entity.CustomerMemo;
  1024. designHelper.API_WorkCore(apiVo);//followRemarks
  1025. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  1026. returnSuccessMsg("保存成功!");
  1027. return;
  1028. }
  1029. returnErrorMsg("找不到记录");
  1030. }
  1031. }
  1032. public void upd_erp_addmemotag()
  1033. {
  1034. if (UrlPostParmsCheck("ctid"))
  1035. {
  1036. ;
  1037. string eid = GetPostString("ctid");
  1038. string sfTagstr = GetPostString("memotag");
  1039. CeErpTradeCell entity = null;
  1040. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1041. if (entity != null)
  1042. {
  1043. ApiVo apiVo = new ApiVo();
  1044. if (entity.OrderState == 0)
  1045. {
  1046. returnErrorMsg("请先领单");
  1047. return;
  1048. }
  1049. //撤销顺丰
  1050. if (sfTagstr == "撤销顺丰")
  1051. {
  1052. entity.IsSF = 0;
  1053. string reMsg = "";
  1054. string oldmemo = entity.seller_memo;
  1055. if (entity.OrderState < 5)
  1056. {
  1057. oldmemo = oldmemo.Replace("顺丰到付", "");
  1058. oldmemo = oldmemo.Replace("顺丰寄付", "");
  1059. entity.seller_memo = oldmemo;
  1060. }
  1061. else
  1062. {
  1063. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  1064. {
  1065. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  1066. }
  1067. }
  1068. entity.Update();
  1069. apiVo.orderNumber = entity.ctid;
  1070. apiVo.actionName = "orderRemarks";
  1071. apiVo.orderRemarks = entity.seller_memo;
  1072. apiVo.isSf = entity.IsSF.ToString();
  1073. designHelper.API_WorkCore(apiVo);//orderRemarks
  1074. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  1075. returnSuccessMsg("撤销成功!" + reMsg);
  1076. return;
  1077. }
  1078. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  1079. {
  1080. //string oldmemo = entity.seller_memo;
  1081. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1082. string sfStr = GetPostString("memotag");
  1083. string smemo = entity.seller_memo;
  1084. int kindex = smemo.IndexOf(")");
  1085. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1086. if (lastoneStr != "-")
  1087. {
  1088. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1089. }
  1090. string prememo = smemo.Substring(0, kindex + 2);
  1091. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1092. int lastkindex = lastmemo.IndexOf("(");
  1093. string newlastmemo = "";
  1094. if (lastkindex == 0)
  1095. {
  1096. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1097. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1098. }
  1099. else
  1100. {
  1101. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1102. }
  1103. entity.seller_memo = prememo + newlastmemo;
  1104. }
  1105. string sfTagMSg = "";
  1106. if (sfTagstr == "顺丰寄付")
  1107. {
  1108. entity.IsSF = 1;
  1109. sfTagMSg = "顺丰寄付";
  1110. }
  1111. else if (sfTagstr == "顺丰到付")
  1112. {
  1113. entity.IsSF = 2;
  1114. sfTagMSg = "顺丰到付";
  1115. }
  1116. if (entity.SupplierId == 19 && entity.OrderState == 6)
  1117. {
  1118. string deliveryWayName = "";
  1119. if (sfTagstr == "撤销顺丰")
  1120. {
  1121. sfTagstr = "普通快递";
  1122. }
  1123. if (sfTagstr == "顺丰寄付")
  1124. {
  1125. sfTagstr = "顺丰特快寄付";
  1126. }
  1127. if (sfTagstr == "顺丰到付")
  1128. {
  1129. sfTagstr = "顺丰特快到付";
  1130. }
  1131. string result = apichyHelper.updateExpressMark(entity.tid, sfTagstr);
  1132. if ("修改失败".Equals(result))
  1133. {
  1134. returnErrorMsg("修改失败");
  1135. return;
  1136. }
  1137. }
  1138. entity.Update();
  1139. apiVo = new ApiVo();
  1140. apiVo.orderNumber = entity.ctid;
  1141. apiVo.actionName = "orderRemarks";
  1142. apiVo.orderRemarks = entity.seller_memo;
  1143. apiVo.isSf = entity.IsSF.ToString();
  1144. designHelper.API_WorkCore(apiVo);//orderRemarks
  1145. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1146. returnSuccessMsg("标记成功!");
  1147. return;
  1148. }
  1149. returnErrorMsg("找不到记录");
  1150. }
  1151. }
  1152. public void upd_erp_ordertag()
  1153. {
  1154. if (UrlPostParmsCheck("ctid"))
  1155. {
  1156. string eid = GetPostString("ctid");
  1157. CeErpTradeCell entity = null;
  1158. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1159. if (entity != null)
  1160. {
  1161. int tag = GetPostInt("wechattag");
  1162. //if(tag==4 && entity.IsSample == 2)
  1163. //{
  1164. // returnErrorMsg("补差价单不能标记微信单");
  1165. // return;
  1166. //}
  1167. entity.wechatTag = tag;
  1168. entity.Update();
  1169. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1170. if (tag == 1)
  1171. {
  1172. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1173. if (cash == null)
  1174. {
  1175. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1176. cash = new CeErpReturnCash();
  1177. cash.tid = entity.tid;
  1178. cash.seller_nick = main.seller_nick;
  1179. cash.payment = trade.payment;
  1180. cash.buyer_nick = main.buyer_nick;
  1181. cash.cashstate = 0;
  1182. cash.rtype = "微信返现";
  1183. cash.returnprice = 0;
  1184. cash.created = DateTime.Now;
  1185. cash.con = "订单标记微信单";
  1186. cash.img = "";
  1187. cash.applyuserid = CurrentUser.UserID;
  1188. cash.Create();
  1189. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1190. }
  1191. else
  1192. {
  1193. cash.cashstate = 0;
  1194. cash.Update();
  1195. }
  1196. CeErpSukuraData.createInfo(entity.ctid, 9);
  1197. }
  1198. else if (tag == 2)
  1199. {
  1200. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1201. if (cash == null)
  1202. {
  1203. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1204. cash = new CeErpReturnCash();
  1205. cash.tid = entity.tid;
  1206. cash.seller_nick = main.seller_nick;
  1207. cash.payment = trade.payment;
  1208. cash.buyer_nick = main.buyer_nick;
  1209. cash.cashstate = 0;
  1210. cash.rtype = "推购返现";
  1211. cash.returnprice = 5;
  1212. cash.created = DateTime.Now;
  1213. cash.con = "订单标记推购单";
  1214. cash.img = "";
  1215. cash.applyuserid = CurrentUser.UserID;
  1216. cash.Create();
  1217. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1218. }
  1219. else
  1220. {
  1221. cash.cashstate = 0;
  1222. cash.Update();
  1223. }
  1224. CeErpSukuraData.createInfo(entity.ctid, 9);
  1225. }
  1226. else if (tag == 3)
  1227. {
  1228. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1229. if (pers == null)
  1230. {
  1231. pers = new CeErpPersuade();
  1232. pers.ctid = entity.ctid;
  1233. pers.pstate = 0;
  1234. pers.created = DateTime.Now;
  1235. pers.applyuserid = CurrentUser.UserID;
  1236. pers.Create();
  1237. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1238. }
  1239. else
  1240. {
  1241. pers.pstate = 0;
  1242. pers.Update();
  1243. }
  1244. }
  1245. else if (tag == 4 || tag == 5)
  1246. {
  1247. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1248. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1249. if (pers == null)
  1250. {
  1251. pers = CeErpStayGoods.GetByTid(entity.tid);
  1252. }
  1253. if (pers == null)
  1254. {
  1255. pers = new CeErpStayGoods();
  1256. pers.t_id = entity.tid;
  1257. pers.ctid = entity.ctid;
  1258. pers.status = "待审核";
  1259. pers.audit_type = 0;
  1260. if (tag == 4)
  1261. {
  1262. pers.stay_type = "微信推购";
  1263. }
  1264. else
  1265. {
  1266. pers.stay_type = "旺旺推购";
  1267. }
  1268. if (entity.IsXianHuo == 0)
  1269. {
  1270. pers.product_id = entity.ProductId;
  1271. }
  1272. pers.wangwang = main.buyer_nick;
  1273. pers.shop_name = main.seller_nick;
  1274. pers.creata_time = DateTime.Now;
  1275. pers.create_u_id = CurrentUser.UserID;
  1276. pers.create_u_name = CurrentUser.UserName;
  1277. pers.Create();
  1278. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1279. }
  1280. else
  1281. {
  1282. pers.ctid = entity.ctid;
  1283. pers.audit_type = 0;
  1284. pers.Update();
  1285. }
  1286. CeErpSukuraData.createInfo(entity.ctid, 10);
  1287. }
  1288. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1289. returnSuccessMsg("标记成功!");
  1290. return;
  1291. }
  1292. returnErrorMsg("找不到记录");
  1293. }
  1294. }
  1295. public void upd_erp_ordertag_cancel()
  1296. {
  1297. if (UrlPostParmsCheck("ctid"))
  1298. {
  1299. string eid = GetPostString("ctid");
  1300. CeErpTradeCell entity = null;
  1301. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1302. if (entity != null)
  1303. {
  1304. entity.wechatTag = 0;
  1305. entity.Update();
  1306. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1307. if (pers != null)
  1308. {
  1309. pers.status = "取消推购";
  1310. pers.audit_type = 3;
  1311. pers.Update();
  1312. }
  1313. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1314. returnSuccessMsg("标记成功!");
  1315. return;
  1316. }
  1317. returnErrorMsg("找不到记录");
  1318. }
  1319. }
  1320. public void upd_erp_addweichattag()
  1321. {
  1322. if (UrlPostParmsCheck("ctid"))
  1323. {
  1324. ;
  1325. string eid = GetPostString("ctid");
  1326. CeErpTradeCell entity = null;
  1327. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1328. if (entity != null)
  1329. {
  1330. if (entity.IsAddWechat > 0)
  1331. {
  1332. returnErrorMsg("此单已经标记过了");
  1333. return;
  1334. }
  1335. 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);
  1336. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1337. if (dt.Rows.Count > 0)
  1338. {
  1339. entity.IsAddWechat = 2;
  1340. }
  1341. else
  1342. {
  1343. entity.IsAddWechat = 1;
  1344. }
  1345. entity.Update();
  1346. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1347. returnSuccessMsg("标记成功!");
  1348. return;
  1349. }
  1350. returnErrorMsg("找不到记录");
  1351. }
  1352. }
  1353. public void upd_erp_getmyorder()
  1354. {
  1355. if (UrlPostParmsCheck("ctid"))
  1356. {
  1357. string eid = GetPostString("ctid");
  1358. CeErpTradeCell entity = null;
  1359. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1360. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1361. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1362. {
  1363. returnErrorMsg("台湾客户需填写身份证号!");
  1364. return;
  1365. }
  1366. if (commonHelper.isFarAddress(father.receiver_state) && father.delivery_paymant == 0)
  1367. {
  1368. returnErrorMsg("偏远地区需要填写物流费!");
  1369. return;
  1370. }
  1371. if (entity != null)
  1372. {
  1373. if (entity.ctid.IndexOf("C") != -1)
  1374. {
  1375. StringBuilder sql = new StringBuilder();
  1376. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1377. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1378. if (dt.Rows.Count > 0)
  1379. {
  1380. decimal total = 0;
  1381. foreach (DataRow dr in dt.Rows)
  1382. {
  1383. total += Convert.ToDecimal(dr["payment"]);
  1384. }
  1385. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1386. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1387. {
  1388. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1389. return;
  1390. }
  1391. }
  1392. }
  1393. if (entity.OrderState == -1)
  1394. {
  1395. returnErrorMsg("待审核订单无法领取!");
  1396. return;
  1397. }
  1398. entity.CustomerUserId = CurrentUser.UserID;
  1399. if (entity.OrderState < 2)
  1400. {
  1401. entity.OrderState = 2;
  1402. if (entity.ShopId != 0)
  1403. {
  1404. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1405. }
  1406. }
  1407. entity.UpdateTime = DateTime.Now;
  1408. entity.Update();
  1409. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1410. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1411. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1412. {
  1413. dataHelper.api_orderBack(entity.ctid, "0", "");
  1414. }
  1415. returnSuccessMsg("领单成功!");
  1416. return;
  1417. }
  1418. returnErrorMsg("找不到记录");
  1419. }
  1420. }
  1421. public void getmyorder_from_init()
  1422. {
  1423. if (UrlPostParmsCheck("ctid"))
  1424. {
  1425. string eid = GetPostString("ctid");
  1426. CeErpTradeCell entity = null;
  1427. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1428. if (entity != null)
  1429. {
  1430. string sellerMemo = GetPostString("sellerMemo");
  1431. if (sellerMemo.Length > 0)
  1432. {
  1433. entity.seller_memo = sellerMemo;
  1434. }
  1435. string oterhMemo = GetPostString("otherMemo");
  1436. if (oterhMemo.Length > 0)
  1437. {
  1438. entity.OtherMemo = oterhMemo;
  1439. }
  1440. int urg = GetPostInt("urgency");
  1441. entity.IsUrgency = (urg == 1 ? true : false);
  1442. int wechat = GetPostInt("wechat");
  1443. int command = GetPostInt("command");
  1444. if (wechat == 1)
  1445. {
  1446. entity.wechatTag = 1;
  1447. }
  1448. if (command == 1)
  1449. {
  1450. entity.wechatTag = 2;
  1451. }
  1452. string pPro = GetPostString("pprofession");
  1453. if (pPro.Length > 0)
  1454. {
  1455. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1456. string spro = GetPostString("profession");
  1457. if (spro.Length > 0)
  1458. {
  1459. entity.ProfessionId = Convert.ToInt32(spro);
  1460. }
  1461. }
  1462. string proId = GetPostString("productId");
  1463. if (proId.Length > 0)
  1464. {
  1465. entity.ProductId = Convert.ToInt32(proId);
  1466. }
  1467. entity.Material = GetPostString("material");
  1468. entity.Craft = GetPostString("craft");
  1469. entity.CustomerUserId = CurrentUser.UserID;
  1470. if (entity.OrderState < 2)
  1471. {
  1472. entity.OrderState = 2;
  1473. if (entity.ShopId != 0)
  1474. {
  1475. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1476. }
  1477. }
  1478. entity.Update();
  1479. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1480. returnSuccessMsg("领单成功!");
  1481. return;
  1482. }
  1483. returnErrorMsg("找不到记录");
  1484. }
  1485. }
  1486. public void upd_erp_setrelationorder()
  1487. {
  1488. if (UrlPostParmsCheck("ctid"))
  1489. {
  1490. ;
  1491. string eid = GetPostString("ctid");
  1492. string ftid = GetPostString("ftid");
  1493. CeErpTradeCell entity = null;
  1494. CeErpTradeCell fentity = null;
  1495. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1496. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1497. if (fentity == null)
  1498. {
  1499. returnErrorMsg("找不到关联的主订单");
  1500. return;
  1501. }
  1502. if (entity != null)
  1503. {
  1504. if (entity.OrderState >= 5)
  1505. {
  1506. returnErrorMsg("本单已经设计完成无法关联");
  1507. return;
  1508. }
  1509. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1510. {
  1511. returnErrorMsg("线下单续审核后才能关联!");
  1512. return;
  1513. }
  1514. entity.ptid = ftid;
  1515. entity.OrderState = fentity.OrderState;
  1516. //entity.status = fentity.status;
  1517. entity.CustomerUserId = fentity.CustomerUserId;
  1518. entity.DesignUserId = fentity.DesignUserId;
  1519. entity.seller_memo = "补差价单:" + ftid;
  1520. entity.IsSample = 2;
  1521. entity.Update();
  1522. ApiVo apiVo = new ApiVo();
  1523. apiVo.orderNumber = ftid;
  1524. apiVo.payment = entity.payment;
  1525. apiVo.actionName = "repairDesign";
  1526. designHelper.API_WorkCore(apiVo);//repairDesign
  1527. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1528. returnSuccessMsg("关联成功!");
  1529. return;
  1530. }
  1531. else
  1532. returnErrorMsg("找不到记录");
  1533. }
  1534. }
  1535. public void download_erp_neworder()
  1536. {
  1537. string seller = GetPostString("seller_nick");
  1538. string tid = GetPostString("tid");
  1539. if (seller.Length <= 0 || tid.Length <= 0)
  1540. {
  1541. returnErrorMsg("数据错误");
  1542. }
  1543. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1544. //{
  1545. // returnErrorMsg("找不到店铺Sessionkey");
  1546. //}
  1547. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1548. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1549. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1550. if (res.IndexOf("refOid") == -1)
  1551. {
  1552. returnErrorMsg("下载订单数据失败");
  1553. return;
  1554. }
  1555. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1556. returnSuccessMsg("下载完成");
  1557. //tmcHelper.createNewOrder(res);
  1558. //CeErpTrade entr = null;
  1559. //entr = CeErpTrade.Get(tid);
  1560. //if (entr != null)
  1561. //{
  1562. // returnSuccess("下载成功");
  1563. // //下载成功之后,Cell表生成对应的订单;
  1564. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1565. //}
  1566. //else
  1567. //{
  1568. // returnErrorMsg("下载失败或者创建订单失败");
  1569. //}
  1570. }
  1571. public void set_erp_atersale()
  1572. {
  1573. if (UrlPostParmsCheck("ctid"))
  1574. {
  1575. string eid = GetPostString("ctid");
  1576. string reason = GetPostString("AfterSaleReason");
  1577. CeErpTradeCell entity = null;
  1578. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1579. if (entity != null)
  1580. {
  1581. /*if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1582. {
  1583. returnErrorMsg("此订单已经在售后");
  1584. return;
  1585. }*/
  1586. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1587. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1588. entity.AfterSaleTime = DateTime.Now;
  1589. entity.HandleTime = null;
  1590. entity.Update();
  1591. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1592. returnSuccessMsg("转售后成功!");
  1593. return;
  1594. }
  1595. returnErrorMsg("找不到记录");
  1596. }
  1597. }
  1598. public void set_erp_withdraw()
  1599. {
  1600. if (UrlPostParmsCheck("ctid"))
  1601. {
  1602. try
  1603. {
  1604. string eid = GetPostString("ctid");//商品id
  1605. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1606. CeWithdraw ceWithdrawSelect = null;
  1607. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1608. if (ceWithdrawSelect != null)
  1609. {
  1610. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1611. {
  1612. ceWithdrawSelect.status = -1;
  1613. ceWithdrawSelect.Update();
  1614. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1615. returnSuccessMsg("重新发起审核成功");
  1616. return;
  1617. }
  1618. else
  1619. {
  1620. returnSuccessMsg("请勿重复申请!");
  1621. return;
  1622. }
  1623. }
  1624. else
  1625. {
  1626. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1627. if (string.IsNullOrEmpty(CustomerUserId))
  1628. {
  1629. CustomerUserId = "-1";
  1630. }
  1631. int Userid = CurrentUser.UserID;//用户id
  1632. CeWithdraw ceWithdraw = new CeWithdraw();
  1633. ceWithdraw.tid = eid;
  1634. ceWithdraw.userid = Userid;
  1635. ceWithdraw.providerid = CustomerUserId;
  1636. ceWithdraw.status = 3;
  1637. ceWithdraw.creationtime = DateTime.Now;
  1638. ceWithdraw.Create();
  1639. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1640. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1641. return;
  1642. }
  1643. }
  1644. catch
  1645. {
  1646. returnErrorMsg("申请撤回订单失败");
  1647. return;
  1648. }
  1649. }
  1650. }
  1651. public void ins_erp_billinfo()
  1652. {
  1653. if (UrlPostParmsCheck("ctid"))
  1654. {
  1655. string eid = GetPostString("ctid");
  1656. CeErpTradeCell entity = null;
  1657. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1658. if (entity != null)
  1659. {
  1660. CeErpBill bill = CeErpBill.GetByTid(eid);
  1661. bool isHave = false;
  1662. if (bill != null)
  1663. {
  1664. isHave = true;
  1665. if (bill.state != 4)
  1666. {
  1667. returnErrorMsg("此单已经申请过发票了");
  1668. return;
  1669. }
  1670. }
  1671. if (entity.IsNeedBill == 0)
  1672. {
  1673. entity.IsNeedBill = 1;
  1674. }
  1675. entity.Update();
  1676. string errjson = "";
  1677. try
  1678. {
  1679. CeErpBill bill_entity = new CeErpBill();
  1680. bill_entity.tid = entity.tid;
  1681. bill_entity.title = GetPostString("title");
  1682. string taxstr = GetPostString("tax");
  1683. taxstr = taxstr.Replace(" ", "");
  1684. bill_entity.tax = taxstr;
  1685. bill_entity.bank = GetPostString("bank");
  1686. string bankacstr = GetPostString("bankac");
  1687. bankacstr = bankacstr.Replace(" ", "");
  1688. bill_entity.bankac = bankacstr;
  1689. bill_entity.address = GetPostString("address");
  1690. bill_entity.phone = GetPostString("phone");
  1691. bill_entity.price = GetPostString("price");
  1692. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1693. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1694. {
  1695. billCount += 1;
  1696. }
  1697. string prebill = "ltb";
  1698. for (int idx = 1; idx <= billCount; idx++)
  1699. {
  1700. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1701. string billoid = prebill + idx + dtstr;
  1702. bill_entity.billOrderId += billoid;
  1703. if (idx < billCount)
  1704. {
  1705. bill_entity.billOrderId += ",";
  1706. }
  1707. }
  1708. bill_entity.productId = GetPostInt("ProductName");
  1709. bill_entity.num = GetPostInt("num");
  1710. bill_entity.unit = GetPostString("unit");
  1711. bill_entity.type = GetPostString("type");
  1712. bill_entity.sendType = GetPostString("SendType");
  1713. bill_entity.email = GetPostString("email");
  1714. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1715. bill_entity.shopName = GetPostString("ShopName");
  1716. bill_entity.applymemo = GetPostString("applyMemo");
  1717. bill_entity.createTime = DateTime.Now;
  1718. bill_entity.state = 0;
  1719. bill_entity.userId = CurrentUser.UserID;
  1720. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1721. bill_entity.Create();
  1722. }
  1723. catch (Exception ex)
  1724. {
  1725. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1726. returnErrorMsg("创建发票出错!");
  1727. return;
  1728. }
  1729. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1730. returnSuccessMsg("发票申请成功!");
  1731. return;
  1732. }
  1733. returnErrorMsg("找不到记录");
  1734. }
  1735. }
  1736. public void ins_erp_neworder()
  1737. {
  1738. if (UrlPostParmsCheck("receiver_name"))
  1739. {
  1740. CeErpTrade entity = new CeErpTrade();
  1741. string plat_form = GetPostString("platform");
  1742. string preStr = "N_";
  1743. if (plat_form == "拼多多")
  1744. {
  1745. preStr = "P_";
  1746. }
  1747. else if (plat_form == "阿里巴巴")
  1748. {
  1749. preStr = "A_";
  1750. }
  1751. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1752. entity.seller_nick = GetPostString("seller_nick");
  1753. entity.buyer_nick = GetPostString("buyer_nick");
  1754. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1755. entity.total_fee = entity.payment;
  1756. entity.pay_time = DateTime.Now;
  1757. entity.status = "NOT_SHIPPED";
  1758. entity.receiver_name = GetPostString("receiver_name");
  1759. entity.receiver_mobile = GetPostString("receiver_mobile");
  1760. entity.receiver_state = GetPostString("receiver_state");
  1761. entity.receiver_city = GetPostString("receiver_city");
  1762. entity.receiver_district = GetPostString("receiver_district");
  1763. entity.receiver_address = GetPostString("receiver_address");
  1764. if (entity.receiver_state == "" || entity.receiver_city == "")
  1765. {
  1766. returnErrorMsg("收件地址不能为空");
  1767. return;
  1768. }
  1769. int shopId = 0;
  1770. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1771. if (nShop != null)
  1772. {
  1773. shopId = nShop.ID;
  1774. }
  1775. if (shopId != 34 && entity.payment == 0)
  1776. {
  1777. returnErrorMsg("公司自用的单金额才能为0");
  1778. return;
  1779. }
  1780. entity.Create();
  1781. CeErpTradeCell entitycell = new CeErpTradeCell();
  1782. entitycell.ctid = entity.tid;
  1783. entitycell.tid = entity.tid;
  1784. entitycell.ShopId = shopId;
  1785. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1786. entitycell.OrderState = 0;
  1787. entitycell.pay_time = entity.pay_time;
  1788. entitycell.IsOffLineOrder = 1;
  1789. entitycell.Create();
  1790. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1791. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1792. return;
  1793. }
  1794. }
  1795. public void ins_erp_neworder2()
  1796. {
  1797. if (UrlPostParmsCheck("receiver_name"))
  1798. {
  1799. //string plat_form = GetPostString("platform");
  1800. string preStr = "X_";
  1801. string memo = GetPostString("memo");
  1802. string productId = GetPostString("productId");
  1803. string primg = GetPostString("proofimg");
  1804. string sellerNick = GetPostString("seller_nick");
  1805. string addFrom = GetPostString("addfrom");
  1806. if (addFrom == "1")
  1807. {
  1808. preStr = "N_";
  1809. }
  1810. int shopId = 0;
  1811. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1812. if (nShop != null)
  1813. {
  1814. shopId = nShop.ID;
  1815. }
  1816. else
  1817. {
  1818. returnErrorMsg("找不到对应店铺");
  1819. return;
  1820. }
  1821. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1822. {
  1823. returnErrorMsg("必须上传付款凭证");
  1824. return;
  1825. }
  1826. CeErpTrade entity = new CeErpTrade();
  1827. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1828. entity.seller_nick = sellerNick;
  1829. entity.buyer_nick = GetPostString("buyer_nick");
  1830. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1831. entity.total_fee = entity.payment;
  1832. entity.pay_time = DateTime.Now;
  1833. entity.status = "NOT_SHIPPED";
  1834. entity.receiver_name = GetPostString("receiver_name");
  1835. entity.receiver_mobile = GetPostString("receiver_mobile");
  1836. entity.receiver_state = GetPostString("receiver_state");
  1837. entity.receiver_city = GetPostString("receiver_city");
  1838. entity.receiver_district = GetPostString("receiver_district");
  1839. entity.receiver_address = GetPostString("receiver_address");
  1840. entity.seller_memo = memo;
  1841. entity.orderFrom = 20;
  1842. entity.orderType = 15;
  1843. if (entity.receiver_state == "" || entity.receiver_city == "")
  1844. {
  1845. returnErrorMsg("收件地址不能为空");
  1846. return;
  1847. }
  1848. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1849. {
  1850. returnErrorMsg("公司自用的单金额才能为0");
  1851. return;
  1852. }
  1853. entity.Create();
  1854. string toWhere = GetPostString("towhere");
  1855. CeErpTradeCell entitycell = new CeErpTradeCell();
  1856. entitycell.ctid = entity.tid;
  1857. //唯一标识
  1858. entitycell.OrderSn = entity.tid;
  1859. string orderSn = dataHelper.getSaleOrderSn();
  1860. if (orderSn != "")
  1861. {
  1862. entitycell.OrderSn = orderSn;
  1863. }
  1864. entitycell.tid = entity.tid;
  1865. //if (preStr == "X_")
  1866. //{
  1867. entitycell.IsOffLineOrder = 1;
  1868. //}
  1869. entitycell.CustomerUserId = CurrentUser.UserID;
  1870. entitycell.PayProofImg = primg;
  1871. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1872. entitycell.ProductId = Convert.ToInt32(productId);
  1873. entitycell.ShopId = shopId;
  1874. entitycell.UpdateTime = DateTime.Now;
  1875. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1876. if (entitycell.ProductId > 0)
  1877. {
  1878. CeErpProduct ceErpProduct = CeErpProduct.GetById(entitycell.ProductId);
  1879. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1880. {
  1881. entitycell.NewProduct = 1;
  1882. }
  1883. }
  1884. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1885. {
  1886. entitycell.IsXianHuo = 1;
  1887. }
  1888. entitycell.pay_time = entity.pay_time;
  1889. if (toWhere == "1")
  1890. {
  1891. entitycell.OrderState = 2;
  1892. }
  1893. else
  1894. {
  1895. entitycell.OrderState = 6;
  1896. entitycell.FinishPlaceTime = entitycell.pay_time;
  1897. }
  1898. if (shopId == 94)
  1899. {
  1900. entitycell.OrderState = 4;
  1901. entitycell.WaitDesignTime = entitycell.pay_time;
  1902. entitycell.StartDesignTime = entitycell.pay_time;
  1903. entitycell.DesignUserId = 218;
  1904. }
  1905. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1906. {
  1907. entitycell.OrderState = -1;//修改12-5
  1908. CeWithdraw ceWithdraw = new CeWithdraw();
  1909. ceWithdraw.tid = entity.tid;
  1910. ceWithdraw.providerid = "-1";
  1911. ceWithdraw.status = -1;
  1912. ceWithdraw.creationtime = DateTime.Now;
  1913. ceWithdraw.userid = 4634;
  1914. ceWithdraw.Create();
  1915. }
  1916. entitycell.Create();
  1917. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1918. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1919. {
  1920. addPlaceRegist(entitycell, CurrentUser.UserID);
  1921. }
  1922. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1923. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1924. return;
  1925. }
  1926. }
  1927. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1928. {
  1929. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1930. entity.PlactTime = tradecell.pay_time;
  1931. entity.AddUserId = userid;
  1932. entity.FileName = tradecell.seller_memo;
  1933. entity.Supplier = 24;
  1934. entity.CreateTime = DateTime.Now;
  1935. entity.Did = tradecell.ctid;
  1936. entity.tid = tradecell.tid;
  1937. entity.splitTag = tradecell.SplitTag;
  1938. entity.CurState = "未完成";
  1939. entity.Create();
  1940. }
  1941. public void get_erp_offlinelist()
  1942. {
  1943. DataStruct dStruct = GetPostStruct();
  1944. List<string> lw = new List<string>();
  1945. string tid = GetPostString("ctid");
  1946. string date1 = GetPostString("date1");
  1947. string date2 = GetPostString("date2");
  1948. if (tid.Length > 0 || date1.Length > 0)
  1949. {
  1950. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1951. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1952. if (dw.Length > 0) lw.Add(dw);
  1953. }
  1954. else
  1955. {
  1956. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1957. }
  1958. string shopname = GetPostString("shopname");
  1959. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1960. string buyernick = GetPostString("buyer_nick");
  1961. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1962. string customer = GetPostString("customer");
  1963. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1964. string design = GetPostString("design");
  1965. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1966. string orderState = GetPostString("orderState");
  1967. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1968. string address = GetPostString("address");
  1969. 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));
  1970. string sellermemo = GetPostString("seller_memo");
  1971. if (sellermemo.Length > 0)
  1972. {
  1973. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1974. }
  1975. string price1 = GetPostString("price1");
  1976. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1977. string price2 = GetPostString("price2");
  1978. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1979. //if (PKey != "admin")
  1980. //{
  1981. // string usershop = CurrentUser.User.pemShop;
  1982. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1983. //}
  1984. //if (ex_psize > 0)
  1985. //{
  1986. dStruct.Order = "pay_time desc";
  1987. //}
  1988. //else
  1989. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1990. lw.Add(string.Format("IsOffLineOrder=1"));
  1991. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1992. DataTable dt = null;
  1993. dt = WebCache.GetData("view_erptradecell", dStruct);
  1994. writeGridDataTableJson(dStruct.TotalCount, dt);
  1995. }
  1996. public void get_erp_returncashrecord()
  1997. {
  1998. DataStruct dStruct = GetPostStruct();
  1999. List<string> lw = new List<string>();
  2000. string tid = GetPostString("ctid");
  2001. if (tid.Length > 0)
  2002. {
  2003. lw.Add(string.Format("tid like '%{0}%'", tid));
  2004. dStruct.Order = "id desc";
  2005. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2006. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  2007. //writeGridDataTableJson(dStruct.TotalCount, dt);
  2008. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2009. return;
  2010. }
  2011. returnErrorMsg("id数据错误!");
  2012. }
  2013. public void ins_erp_returncashrecord()
  2014. {
  2015. if (UrlPostParmsCheck("tid"))
  2016. {
  2017. string tid = GetPostString("tid");
  2018. string retype = GetPostString("type");
  2019. StringBuilder sql = new StringBuilder();
  2020. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  2021. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2022. if (dt.Rows.Count > 0)
  2023. {
  2024. returnErrorMsg("相同返现类型记录已存在");
  2025. return;
  2026. }
  2027. CeErpReturnCash entity = new CeErpReturnCash();
  2028. entity.tid = tid;
  2029. entity.seller_nick = GetPostString("seller_nick");
  2030. string pment = GetPostString("payment");
  2031. if (pment.Length > 0)
  2032. {
  2033. entity.payment = Convert.ToDouble(pment);
  2034. }
  2035. entity.buyer_nick = GetPostString("buyer_nick");
  2036. entity.cashstate = 0;
  2037. entity.rtype = retype;
  2038. string rPrice = GetPostString("returnprice");
  2039. if (rPrice.Length > 0)
  2040. {
  2041. entity.returnprice = Convert.ToDouble(rPrice);
  2042. }
  2043. entity.created = DateTime.Now;
  2044. entity.con = GetPostString("con");
  2045. entity.img = GetPostString("img");
  2046. entity.applyuserid = CurrentUser.UserID;
  2047. entity.Create();
  2048. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  2049. returnSuccessMsg("操作成功!");
  2050. return;
  2051. }
  2052. }
  2053. public void set_erp_predelivery()
  2054. {
  2055. if (UrlPostParmsCheck("ctid"))
  2056. {
  2057. string eid = GetPostString("ctid");
  2058. CeErpTradeCell entity = null;
  2059. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2060. if (entity != null)
  2061. {
  2062. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  2063. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  2064. //{
  2065. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  2066. // return;
  2067. //}
  2068. entity.IsPreDelivery = 1;
  2069. entity.Update();
  2070. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2071. returnSuccessMsg("预发货成功!");
  2072. return;
  2073. //string shop = GetPostString("seller_nick");
  2074. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  2075. //string comName = GetPostString("comName");
  2076. //string comCode = GetPostString("comCode");
  2077. //string outSid = GetPostString("outSid");//运单号
  2078. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  2079. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  2080. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  2081. //string apires = "";
  2082. //if (deliveryType == "虚拟发货")
  2083. //{
  2084. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  2085. //}
  2086. //else
  2087. //{
  2088. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  2089. //}
  2090. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  2091. ////{
  2092. //if (apires.IndexOf("发货成功") != -1)
  2093. //{
  2094. // if (deliveryType != "虚拟发货")
  2095. // {
  2096. // //还要插入快递信息到 快递信息表
  2097. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  2098. // exinfo.tid = eid;
  2099. // exinfo.out_sid = outSid;
  2100. // exinfo.company_code = comCode;
  2101. // exinfo.company_name = comName;
  2102. // exinfo.delivery_memo = deliveryMemo;
  2103. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  2104. // exinfo.deliveryType = deliveryType;
  2105. // exinfo.Create();
  2106. // }
  2107. // returnSuccessMsg("发货成功!");
  2108. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2109. //}
  2110. //else
  2111. //{
  2112. // returnErrorMsg("淘宝发货失败!!");
  2113. //}
  2114. //return;
  2115. }
  2116. returnErrorMsg("找不到订单记录");
  2117. }
  2118. }
  2119. public void get_erp_unusuallist()
  2120. {
  2121. DataStruct dStruct = GetPostStruct();
  2122. List<string> lw = new List<string>();
  2123. string tid = GetPostString("ctid");
  2124. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2125. string shopname = GetPostString("shopname");
  2126. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2127. string buyernick = GetPostString("buyer_nick");
  2128. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2129. string ResponsibleMan = GetPostString("responsible");
  2130. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2131. string date1 = GetPostString("date1");
  2132. string date2 = GetPostString("date2");
  2133. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2134. if (dw.Length > 0) lw.Add(dw);
  2135. string price1 = GetPostString("price1");
  2136. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2137. string price2 = GetPostString("price2");
  2138. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2139. string orderState = GetPostString("orderState");
  2140. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2141. string sellermemo = GetPostString("seller_memo");
  2142. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2143. lw.Add(string.Format("UnusualTag > 0"));
  2144. lw.Add(string.Format("IsRefund<={0}", 1));
  2145. dStruct.Order = "pay_time desc";
  2146. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2147. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2148. writeGridDataTableJson(dStruct.TotalCount, dt);
  2149. }
  2150. public void set_erp_unusualtonomal()
  2151. {
  2152. if (UrlPostParmsCheck("ctid"))
  2153. {
  2154. string eid = GetPostString("ctid");
  2155. CeErpTradeCell entity = null;
  2156. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2157. if (entity != null)
  2158. {
  2159. entity.UnusualTag = -1;
  2160. entity.Update();
  2161. returnSuccessMsg("忽略成功!");
  2162. return;
  2163. }
  2164. returnErrorMsg("找不到记录");
  2165. }
  2166. }
  2167. public void ins_erp_unusualreason()
  2168. {
  2169. if (UrlPostParmsCheck("ctid"))
  2170. {
  2171. string eid = GetPostString("ctid");
  2172. CeErpTradeCell entity = null;
  2173. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2174. if (entity != null)
  2175. {
  2176. entity.MemoOpt = 4;
  2177. entity.UnusualCon = GetPostString("con");
  2178. entity.Update();
  2179. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2180. if (trade != null)
  2181. {
  2182. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2183. }
  2184. //查货是否超时
  2185. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2186. if (ceErpTradeCellExtend == null)
  2187. {
  2188. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2189. ceErpTradeCellExtend.ctid = entity.ctid;
  2190. }
  2191. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2192. {
  2193. ceErpTradeCellExtend.CheckOut += 1;
  2194. }
  2195. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2196. if (ceErpTradeCellExtend.ID > 0)
  2197. {
  2198. ceErpTradeCellExtend.Update();
  2199. }
  2200. else
  2201. {
  2202. ceErpTradeCellExtend.Create();
  2203. }
  2204. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2205. returnSuccessMsg("操作成功!");
  2206. return;
  2207. }
  2208. returnErrorMsg("找不到记录");
  2209. }
  2210. }
  2211. public void upd_erp_sampleorder()
  2212. {
  2213. if (UrlPostParmsCheck("ctid"))
  2214. {
  2215. string eid = GetPostString("ctid");
  2216. string[] eArr = eid.Split(',');
  2217. if (eArr.Length > 1)
  2218. {
  2219. List<string> eLst = new List<string>();
  2220. for (int i = 0; i < eArr.Length; i++)
  2221. {
  2222. eLst.Add("'" + eArr[i] + "'");
  2223. }
  2224. eid = string.Join(",", eLst.ToArray());
  2225. }
  2226. else
  2227. {
  2228. eid = "'" + eid + "'";
  2229. }
  2230. StringBuilder sql = new StringBuilder();
  2231. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2232. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2233. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2234. if (dt.Rows.Count > 0)
  2235. {
  2236. string errmsg = "";
  2237. foreach (DataRow dr in dt.Rows)
  2238. {
  2239. StringBuilder sqlsb = new StringBuilder();
  2240. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2241. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2242. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2243. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2244. //string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2245. /*if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2246. {
  2247. continue;
  2248. }
  2249. else
  2250. {
  2251. string emsg = commonHelper.KeepChinese(apires);
  2252. errmsg += emsg;
  2253. }*/
  2254. }
  2255. if (errmsg.Length > 0)
  2256. {
  2257. returnErrorMsg(errmsg);
  2258. return;
  2259. }
  2260. returnSuccessMsg("操作成功");
  2261. return;
  2262. }
  2263. returnErrorMsg("找不到记录");
  2264. }
  2265. }
  2266. public void upd_erp_transcustomer()
  2267. {
  2268. if (UrlPostParmsCheck("ctid"))
  2269. {
  2270. string eid = GetPostString("ctid");
  2271. int userid = GetPostInt("CustomerUserId");
  2272. CeErpTradeCell entity = null;
  2273. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2274. if (entity != null)
  2275. {
  2276. //string[] mlist = entity.seller_memo.Split('-');
  2277. //string sql = "select * from view_erpuser where id=" + userid;
  2278. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2279. //if (dt != null && dt.Rows.Count > 0)
  2280. //{
  2281. // string nmemo = "";
  2282. // for(int i = 0; i < mlist.Length - 1; i++)
  2283. // {
  2284. // nmemo += mlist[i];
  2285. // nmemo += "-";
  2286. // }
  2287. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2288. // entity.seller_memo = nmemo;
  2289. //}
  2290. entity.CustomerUserId = userid;
  2291. entity.Update();
  2292. returnSuccessMsg("操作成功!");
  2293. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2294. return;
  2295. }
  2296. returnErrorMsg("找不到记录");
  2297. }
  2298. }
  2299. public void upd_erp_transdesigner()
  2300. {
  2301. if (UrlPostParmsCheck("ctid"))
  2302. {
  2303. string eids = GetPostString("ctid");
  2304. string[] ctidList = eids.Split(',');
  2305. int userid = GetPostInt("DesignUserId");
  2306. foreach (string ctid in ctidList)
  2307. {
  2308. CeErpTradeCell entity = null;
  2309. CeErpDesignerBill entitys = null;
  2310. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2311. entitys = CeErpDesignerBill.GetByTid(ctid);
  2312. if (entity != null)
  2313. {
  2314. if (entity.OrderState > 4)
  2315. {
  2316. continue;
  2317. }
  2318. //存在退款不能流转
  2319. if (entity.IsRefund > 0)
  2320. {
  2321. continue;
  2322. }
  2323. entity.DesignUserId = userid;
  2324. entity.WaitDesignTime = DateTime.Now;
  2325. entity.Update();
  2326. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2327. }
  2328. }
  2329. returnSuccessMsg("操作成功!");
  2330. }
  2331. }
  2332. public void upd_erp_distributedesigner()
  2333. {
  2334. if (UrlPostParmsCheck("ctid"))
  2335. {
  2336. string eid = GetPostString("ctid");
  2337. int userid = GetPostInt("DesignUserId");
  2338. string[] idlist = eid.Split(',');
  2339. if (idlist.Length <= 0)
  2340. {
  2341. returnErrorMsg("订单不能为空");
  2342. return;
  2343. }
  2344. foreach (string ctid in idlist)
  2345. {
  2346. CeErpTradeCell entity = null;
  2347. CeErpDesignerBill entitys = null;
  2348. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2349. else continue;
  2350. if (entity != null)
  2351. {
  2352. if (userid == 2125 || userid == 3542)
  2353. { }
  2354. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2355. {
  2356. returnErrorMsg("金额错误的订单无法指派");
  2357. return;
  2358. }
  2359. if (entity.OrderState >= 5)
  2360. {
  2361. returnErrorMsg("已经设计完成无法指派");
  2362. return;
  2363. }
  2364. if (entity.OrderState == -1)
  2365. {
  2366. returnErrorMsg("审核中的订单无法指派");
  2367. return;
  2368. }
  2369. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2370. {
  2371. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2372. return;
  2373. }
  2374. //157赖橙帆 159林晨 73 静之颖
  2375. 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)
  2376. {
  2377. returnErrorMsg("指派设计共创无法再次指派!");
  2378. return;
  2379. }
  2380. entity.OrderState = 3;
  2381. if (entity.SupplierId == 0)
  2382. {
  2383. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2384. entity.SupplierId = suid;
  2385. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2386. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2387. }
  2388. if (userid == 2125 && entity.seller_memo != "")
  2389. {
  2390. apiDesign.API_GetPrintData_CreateOrder(entity);
  2391. }
  2392. if (userid == 3542 && entity.seller_memo != "")
  2393. {
  2394. string userPost = CurrentUser.UserPost.Post.Code;
  2395. if (CurrentUser.UserID == 73)
  2396. {
  2397. userPost = "SysAdmin";
  2398. }
  2399. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2400. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2401. if (response.msg != "设计共创:成功")
  2402. {
  2403. returnErrorMsg(response.msg);
  2404. return;
  2405. }
  2406. entity.DispatchSort = 2;
  2407. }
  2408. else
  2409. {
  2410. if (entity.DispatchSort == 2)
  2411. {
  2412. ApiVo apiVo = new ApiVo();
  2413. apiVo.actionName = "closeDesign";
  2414. apiVo.orderNumber = entity.ctid;
  2415. designHelper.API_WorkCore(apiVo);//closeDesign
  2416. }
  2417. entity.DispatchSort = 0;
  2418. }
  2419. entity.DesignUserId = userid;
  2420. entity.WaitDesignTime = DateTime.Now;
  2421. entity.UpdateTime = DateTime.Now;
  2422. entity.Update();
  2423. string name = commonHelper.getUserNameById(userid);
  2424. commonHelper.UpdateRelationOrder(entity.ctid);
  2425. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2426. }
  2427. }
  2428. returnSuccessMsg("操作成功!");
  2429. return;
  2430. }
  2431. }
  2432. public string getTidByCtid(string ctid)
  2433. {
  2434. string tid = "";
  2435. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2436. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2437. if (dataTable != null && dataTable.Rows.Count > 0)
  2438. {
  2439. tid = dataTable.Rows[0]["tid"].ToString();
  2440. }
  2441. return tid;
  2442. }
  2443. public List<string> getTidByCtidMore(string ctid)
  2444. {
  2445. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2446. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2447. List<string> list = new List<string>();
  2448. if (dataTable != null && dataTable.Rows.Count > 0)
  2449. {
  2450. foreach (DataRow item in dataTable.Rows)
  2451. {
  2452. list.Add("'" + item["tid"].ToString() + "'");
  2453. }
  2454. }
  2455. return list;
  2456. }
  2457. public List<string> getTidByCtidLike(string ctid)
  2458. {
  2459. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2460. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2461. List<string> list = new List<string>();
  2462. if (dataTable != null && dataTable.Rows.Count > 0)
  2463. {
  2464. foreach (DataRow item in dataTable.Rows)
  2465. {
  2466. list.Add("'" + item["tid"].ToString() + "'");
  2467. }
  2468. }
  2469. return list;
  2470. }
  2471. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2472. {
  2473. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2474. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2475. List<string> list = new List<string>();
  2476. if (dataTable != null && dataTable.Rows.Count > 0)
  2477. {
  2478. foreach (DataRow item in dataTable.Rows)
  2479. {
  2480. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2481. {
  2482. continue;
  2483. }
  2484. list.Add("'" + item["receiverId"].ToString() + "'");
  2485. }
  2486. }
  2487. return list;
  2488. }
  2489. public void get_erp_myorderlist()
  2490. {
  2491. DataStruct dStruct = GetPostStruct();
  2492. List<string> lw = new List<string>();
  2493. string tid = GetPostString("ctid");
  2494. if (tid.Length > 0)
  2495. {
  2496. string select_tid = getTidByCtid(tid);
  2497. lw.Add(string.Format("tid='{0}'", select_tid));
  2498. }
  2499. else
  2500. {
  2501. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2502. }
  2503. //12-1 修改
  2504. string urgent = GetPostString("urgent");
  2505. string back = GetPostString("back");
  2506. string offlineSearch = GetPostString("offlineSearch");
  2507. if (!string.IsNullOrWhiteSpace(urgent))
  2508. {
  2509. if (urgent.Equals("true"))
  2510. {
  2511. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2512. }
  2513. }
  2514. if (!string.IsNullOrWhiteSpace(back))
  2515. {
  2516. if (back.Equals("true"))
  2517. {
  2518. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2519. }
  2520. }
  2521. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2522. {
  2523. if (offlineSearch.Equals("true"))
  2524. {
  2525. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2526. }
  2527. }
  2528. //end
  2529. string shopname = GetPostString("shopname");
  2530. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2531. string buyernick = GetPostString("buyer_nick");
  2532. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2533. string design = GetPostString("design");
  2534. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2535. string orderState = GetPostString("orderState");
  2536. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2537. string sellermemo = GetPostString("seller_memo");
  2538. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2539. string date1 = GetPostString("date1");
  2540. string date2 = GetPostString("date2");
  2541. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2542. if (dw.Length > 0) lw.Add(dw);
  2543. string price1 = GetPostString("price1");
  2544. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2545. string price2 = GetPostString("price2");
  2546. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2547. string urgency = GetPostString("urgency");
  2548. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2549. string after = GetPostString("after");
  2550. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2551. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2552. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2553. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2554. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2555. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2556. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2557. if (dt != null && dt.Rows.Count > 0)
  2558. {
  2559. foreach (DataRow dr in dt.Rows)
  2560. {
  2561. try
  2562. {
  2563. // 对象操作
  2564. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2565. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2566. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2567. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2568. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2569. if (dStruct.PageSize != 100000)
  2570. {
  2571. if (dr["DispatchSort"].ToString() == "2")
  2572. {
  2573. dr["gongchuang"] = 200;
  2574. }
  2575. else if ("外协".Equals(dr["ToType"].ToString()))
  2576. {
  2577. dr["gongchuang"] = 200;
  2578. }
  2579. else if ("内部".Equals(dr["ToType"].ToString()))
  2580. {
  2581. dr["gongchuang"] = -1;
  2582. }
  2583. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2584. {
  2585. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2586. dr["gongchuang"] = response.code;
  2587. }
  2588. }
  2589. }
  2590. catch (NullReferenceException ex)
  2591. {
  2592. }
  2593. }
  2594. }
  2595. writeGridDataTableJson(dStruct.TotalCount, dt);
  2596. }
  2597. public void get_erp_myreturnorderlist()
  2598. {
  2599. DataStruct dStruct = GetPostStruct();
  2600. List<string> lw = new List<string>();
  2601. string tid = GetPostString("ctid");
  2602. if (tid.Length > 0)
  2603. {
  2604. string select_tid = getTidByCtid(tid);
  2605. lw.Add(string.Format("tid='{0}'", select_tid));
  2606. }
  2607. else
  2608. {
  2609. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2610. }
  2611. string shopname = GetPostString("shopname");
  2612. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2613. string buyernick = GetPostString("buyer_nick");
  2614. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2615. string design = GetPostString("design");
  2616. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2617. string orderState = GetPostString("orderState");
  2618. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2619. string sellermemo = GetPostString("seller_memo");
  2620. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2621. string date1 = GetPostString("date1");
  2622. string date2 = GetPostString("date2");
  2623. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2624. if (dw.Length > 0) lw.Add(dw);
  2625. string price1 = GetPostString("price1");
  2626. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2627. string price2 = GetPostString("price2");
  2628. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2629. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2630. {
  2631. lw.Add(string.Format("CusOrgID = 94"));
  2632. }
  2633. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2634. {
  2635. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2636. }
  2637. else
  2638. {
  2639. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2640. }
  2641. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2642. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2643. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2644. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2645. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2646. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2647. if (dt != null && dt.Rows.Count > 0)
  2648. {
  2649. foreach (DataRow dr in dt.Rows)
  2650. {
  2651. try
  2652. {
  2653. // 对象操作
  2654. if (dStruct.PageSize != 100000)
  2655. {
  2656. if (dr["DispatchSort"].ToString() == "2")
  2657. {
  2658. dr["gongchuang"] = 200;
  2659. }
  2660. else if ("外协".Equals(dr["ToType"].ToString()))
  2661. {
  2662. dr["gongchuang"] = 200;
  2663. }
  2664. else if ("内部".Equals(dr["ToType"].ToString()))
  2665. {
  2666. dr["gongchuang"] = -1;
  2667. }
  2668. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2669. {
  2670. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2671. dr["gongchuang"] = response.code;
  2672. }
  2673. }
  2674. }
  2675. catch (NullReferenceException ex)
  2676. {
  2677. // 处理空引用异常
  2678. }
  2679. }
  2680. }
  2681. writeGridDataTableJson(dStruct.TotalCount, dt);
  2682. }
  2683. public void get_erp_myorderlist_pregather()
  2684. {
  2685. string date1 = GetPostString("date1");
  2686. string date2 = GetPostString("date2");
  2687. int userId = CurrentUser.UserID; //客服id
  2688. string orderWhere = "";
  2689. List<string> lw = new List<string>();
  2690. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2691. if (dw.Length > 0) lw.Add(dw);
  2692. lw.Add(string.Format("CustomerUserId={0}", userId));
  2693. lw.Add(string.Format("OrderState<9"));
  2694. orderWhere = string.Join(" and ", lw.ToArray());
  2695. string orderWhere2 = "";
  2696. List<string> lw2 = new List<string>();
  2697. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2698. if (dw2.Length > 0) lw2.Add(dw2);
  2699. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2700. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2701. string sql = string.Format("select *" +
  2702. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2703. "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 " +
  2704. "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 " +
  2705. "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");
  2706. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2707. //writeGridDataTableJson(dt.Rows.Count, dt);
  2708. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2709. }
  2710. public void upd_erp_publishorder()
  2711. {
  2712. if (UrlPostParmsCheck("ctid"))
  2713. {
  2714. string eid = GetPostString("ctid");
  2715. CeErpTradeCell entity = null;
  2716. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2717. if (entity != null)
  2718. {
  2719. entity.OrderState = 0; //发布后,变为待抢单
  2720. entity.Update();
  2721. commonHelper.UpdateRelationOrder(entity.ctid);
  2722. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2723. returnSuccessMsg("发布成功!");
  2724. return;
  2725. }
  2726. returnErrorMsg("找不到记录");
  2727. }
  2728. }
  2729. public void get_erp_my_tiporder()
  2730. {
  2731. StringBuilder sql = new StringBuilder();
  2732. int userId = 0;
  2733. if (CurrentUser != null) userId = CurrentUser.UserID;
  2734. string posCode = CurrentUser.UserPost.Post.Code;
  2735. string isTipedAfterSaleVerify = GetPostString("af");
  2736. DataTable dt = new DataTable();
  2737. if (posCode != "Supplier")
  2738. {
  2739. if (posCode == "CustomerService" || posCode == "Director")
  2740. {
  2741. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2742. }
  2743. else if (posCode == "Place" || posCode == "PlaceMr")
  2744. {
  2745. }
  2746. else
  2747. {
  2748. string teamIds = CurrentUser.User.TeamIds;
  2749. if (teamIds == "")
  2750. {
  2751. teamIds = "0";
  2752. }
  2753. 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);
  2754. }
  2755. if (sql.Length > 0)
  2756. {
  2757. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2758. }
  2759. }
  2760. if (dt.Rows.Count <= 0)
  2761. {
  2762. string key = "aftersale_order_" + userId;
  2763. if (RedisHelper.HasKey(key))
  2764. {
  2765. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2766. dt.Columns.Add("ctid", typeof(string));
  2767. dt.Columns.Add("IsReadTag", typeof(int));
  2768. foreach (var i in list)
  2769. {
  2770. DataRow data = dt.NewRow();
  2771. data["ctid"] = i;
  2772. data["IsReadTag"] = 4;
  2773. dt.Rows.Add(data);
  2774. }
  2775. RedisHelper.StringDelete(key);
  2776. }
  2777. }
  2778. if (dt.Rows.Count <= 0)
  2779. {
  2780. sql = new StringBuilder();
  2781. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2782. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2783. }
  2784. if (posCode == "Supplier")
  2785. {
  2786. string ids = CurrentUser.User.pemVend;
  2787. if (ids != null && ids.Length > 0)
  2788. {
  2789. string[] ids_list = ids.Split(',');
  2790. foreach (var item in ids_list)
  2791. {
  2792. string key = "return_order_" + item;
  2793. if (RedisHelper.HasKey(key))
  2794. {
  2795. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2796. dt.Columns.Add("ctid", typeof(string));
  2797. dt.Columns.Add("IsReadTag", typeof(int));
  2798. foreach (var i in list)
  2799. {
  2800. DataRow data = dt.NewRow();
  2801. data["ctid"] = i;
  2802. data["IsReadTag"] = 1;
  2803. dt.Rows.Add(data);
  2804. }
  2805. RedisHelper.StringDelete(key);
  2806. }
  2807. }
  2808. }
  2809. if (dt.Rows.Count <= 0)
  2810. {
  2811. sql = new StringBuilder();
  2812. 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);
  2813. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2814. }
  2815. }
  2816. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2817. }
  2818. public void reset_erp_tiporder()
  2819. {
  2820. string ids = GetPostString("ids");
  2821. string[] ctidList = ids.Split(',');
  2822. foreach (string ctid in ctidList)
  2823. {
  2824. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2825. if (enty != null)
  2826. {
  2827. enty.IsReadTag = 0;
  2828. enty.Update();
  2829. }
  2830. }
  2831. returnSuccessMsg("成功!");
  2832. return;
  2833. }
  2834. public void get_erp_designlist()
  2835. {
  2836. DataStruct dStruct = GetPostStruct();
  2837. List<string> lw = new List<string>();
  2838. string tid = GetPostString("ctid");
  2839. if (tid.Length > 0)
  2840. {
  2841. string select_tid = getTidByCtid(tid);
  2842. lw.Add(string.Format("tid='{0}'", select_tid));
  2843. }
  2844. string shopname = GetPostString("shopname");
  2845. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2846. string buyernick = GetPostString("buyer_nick");
  2847. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2848. string customer = GetPostString("customer");
  2849. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2850. string design = GetPostString("design");
  2851. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2852. string orderState = GetPostString("orderState");
  2853. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2854. lw.Add(string.Format("OrderState<6"));
  2855. string address = GetPostString("address");
  2856. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2857. string sellermemo = GetPostString("seller_memo");
  2858. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2859. string date1 = GetPostString("date1");
  2860. string date2 = GetPostString("date2");
  2861. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2862. if (dw.Length > 0) lw.Add(dw);
  2863. string apdate1 = GetPostString("apdate1");
  2864. string apdate2 = GetPostString("apdate2");
  2865. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2866. if (dwap.Length > 0) lw.Add(dwap);
  2867. string price1 = GetPostString("price1");
  2868. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2869. string price2 = GetPostString("price2");
  2870. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2871. string designTime = GetPostString("designtime");
  2872. if (designTime.Length > 0)
  2873. {
  2874. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2875. }
  2876. string usershop = CurrentUser.User.pemShop;
  2877. if (usershop.Length > 0)
  2878. {
  2879. lw.Add(string.Format("shopId in ({0})", usershop));
  2880. }
  2881. int myOrgid = CurrentUser.UserPost.OrgID;
  2882. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2883. if (myOrgCode.IndexOf("Designer") != -1)
  2884. {
  2885. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2886. {
  2887. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2888. }
  2889. else
  2890. {
  2891. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2892. }
  2893. }
  2894. else
  2895. {
  2896. string orgId = GetPostString("designerhd");
  2897. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2898. }
  2899. if (tid.Length > 0 || buyernick.Length > 0)
  2900. {
  2901. lw.Add(string.Format("OrderState >= 3"));
  2902. }
  2903. else
  2904. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2905. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2906. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2907. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2908. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2909. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2910. if (dt != null && dt.Rows.Count > 0)
  2911. {
  2912. foreach (DataRow dr in dt.Rows)
  2913. {
  2914. try
  2915. {
  2916. // 对象操作
  2917. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2918. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2919. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2920. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2921. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2922. if (dStruct.PageSize != 100000)
  2923. {
  2924. if (dr["DispatchSort"].ToString() == "2")
  2925. {
  2926. dr["gongchuang"] = 200;
  2927. }
  2928. else if ("外协".Equals(dr["ToType"].ToString()))
  2929. {
  2930. dr["gongchuang"] = 200;
  2931. }
  2932. else if ("内部".Equals(dr["ToType"].ToString()))
  2933. {
  2934. dr["gongchuang"] = -1;
  2935. }
  2936. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2937. {
  2938. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2939. dr["gongchuang"] = response.code;
  2940. }
  2941. }
  2942. }
  2943. catch (NullReferenceException ex)
  2944. {
  2945. }
  2946. }
  2947. }
  2948. writeGridDataTableJson(dStruct.TotalCount, dt);
  2949. }
  2950. public void get_erp_mydesignlist()
  2951. {
  2952. DataStruct dStruct = GetPostStruct();
  2953. List<string> lw = new List<string>();
  2954. string tid = GetPostString("ctid");
  2955. if (tid.Length > 0)
  2956. {
  2957. string select_tid = getTidByCtid(tid);
  2958. lw.Add(string.Format("tid='{0}'", select_tid));
  2959. }
  2960. string shopname = GetPostString("shopname");
  2961. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2962. string buyernick = GetPostString("buyer_nick");
  2963. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2964. string customer = GetPostString("customer");
  2965. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2966. string orderState = GetPostString("orderState");
  2967. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2968. //lw.Add(string.Format("OrderState<6"));
  2969. string date1 = GetPostString("date1");
  2970. string date2 = GetPostString("date2");
  2971. string dw = GetDateWhere("pay_time", date1, date2);
  2972. if (dw.Length > 0) lw.Add(dw);
  2973. string apdate1 = GetPostString("apdate1");
  2974. string apdate2 = GetPostString("apdate2");
  2975. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2976. if (dwap.Length > 0) lw.Add(dwap);
  2977. string price1 = GetPostString("price1");
  2978. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2979. string price2 = GetPostString("price2");
  2980. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2981. string olddownload = GetPostString("olddown");
  2982. if (olddownload == "1")
  2983. {
  2984. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2985. }
  2986. else if (olddownload == "2")
  2987. {
  2988. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2989. }
  2990. string sellermemo = GetPostString("seller_memo");
  2991. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2992. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2993. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2994. {
  2995. if (CurrentUser.User.TeamIds.Length > 0)
  2996. {
  2997. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2998. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2999. else
  3000. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3001. }
  3002. else
  3003. {
  3004. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  3005. }
  3006. }
  3007. if (tid.Length <= 0)
  3008. {
  3009. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  3010. }
  3011. lw.Add(string.Format("IsReturn!=3"));
  3012. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  3013. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3014. string teamids = CurrentUser.User.TeamIds.ToString();
  3015. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3016. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  3017. if (dt != null && dt.Rows.Count > 0)
  3018. {
  3019. foreach (DataRow dr in dt.Rows)
  3020. {
  3021. try
  3022. {
  3023. // 对象操作
  3024. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  3025. ceErpTradeCell.ctid = dr["ctid"].ToString();
  3026. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  3027. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  3028. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  3029. if (dStruct.PageSize != 100000)
  3030. {
  3031. if (dr["DispatchSort"].ToString() == "2")
  3032. {
  3033. dr["gongchuang"] = 200;
  3034. }
  3035. else if ("外协".Equals(dr["ToType"].ToString()))
  3036. {
  3037. dr["gongchuang"] = 200;
  3038. }
  3039. else if ("内部".Equals(dr["ToType"].ToString()))
  3040. {
  3041. dr["gongchuang"] = -1;
  3042. }
  3043. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3044. {
  3045. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3046. dr["gongchuang"] = response.code;
  3047. }
  3048. }
  3049. }
  3050. catch (NullReferenceException ex)
  3051. {
  3052. }
  3053. }
  3054. }
  3055. writeGridDataTableJson(dStruct.TotalCount, dt);
  3056. }
  3057. public void set_erp_startdesign()
  3058. {
  3059. if (UrlPostParmsCheck("ctid"))
  3060. {
  3061. string eid = GetPostString("ctid");
  3062. CeErpTradeCell entity = null;
  3063. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3064. if (entity != null)
  3065. {
  3066. if (entity.OrderState != 3)
  3067. {
  3068. returnErrorMsg("请刷新,订单已经设计了");
  3069. return;
  3070. }
  3071. entity.StartDesignTime = DateTime.Now;
  3072. entity.OrderState = 4;
  3073. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3074. {
  3075. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3076. entity.SupplierId = suid;
  3077. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3078. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3079. }
  3080. entity.UpdateTime = DateTime.Now;
  3081. //entity.MakeSupplier = suname;
  3082. entity.Update();
  3083. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3084. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3085. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3086. commonHelper.getCytPrice(entity);
  3087. returnSuccessMsg("操作成功!");
  3088. return;
  3089. }
  3090. returnErrorMsg("找不到记录");
  3091. }
  3092. }
  3093. public void ins_erp_designselfmemo()
  3094. {
  3095. if (UrlPostParmsCheck("ctid"))
  3096. {
  3097. string eid = GetPostString("ctid");
  3098. string con = GetPostString("con");
  3099. CeErpTradeCell entity = null;
  3100. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3101. if (entity != null)
  3102. {
  3103. entity.DesignSelfMemo = con;
  3104. entity.Update();
  3105. returnSuccessMsg("操作成功!");
  3106. return;
  3107. }
  3108. returnErrorMsg("找不到记录");
  3109. }
  3110. }
  3111. public void ins_erp_designprice()
  3112. {
  3113. if (UrlPostParmsCheck("ctid"))
  3114. {
  3115. string eid = GetPostString("ctid");
  3116. int uid = CurrentUser.UserID;
  3117. string userName = CurrentUser.UserName;
  3118. CeErpTradeCell entity = null;
  3119. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3120. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3121. if (entitys == null)
  3122. {
  3123. entitys = new CeErpDesignerBill();
  3124. }
  3125. if (entity != null)
  3126. {
  3127. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3128. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3129. entity.StartDesignTime = DateTime.Now;
  3130. entity.OrderState = 4;
  3131. string suname = "";
  3132. if (entity.SupplierId == 0)
  3133. {
  3134. int sid = commonHelper.autoDistributeToSupplier(entity);
  3135. entity.SupplierId = sid;
  3136. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3137. }
  3138. entity.Update();
  3139. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3140. if (ceErpUserPost != null)
  3141. {
  3142. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3143. if (ceErpPost != null)
  3144. {
  3145. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3146. {
  3147. entitys.tid = entity.ctid;
  3148. entitys.oid = entity.tid;
  3149. entitys.uid = uid;
  3150. entitys.userName = userName;
  3151. entitys.designerType = 1;
  3152. entitys.designerTypeText = "内部设计师";
  3153. entitys.price = Convert.ToDouble(GetPostString("price"));
  3154. entitys.designNum = GetPostInt("designNum");
  3155. entitys.modifyNum = GetPostInt("modifyNum");
  3156. entitys.designSize = GetPostString("designSize");
  3157. entitys.modifySize = GetPostString("modifySize");
  3158. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3159. {
  3160. entitys.create_time = DateTime.Now;
  3161. entitys.create_u_id = uid;
  3162. entitys.create_u_name = userName;
  3163. entitys.Save();
  3164. }
  3165. else
  3166. {
  3167. entitys.update_time = DateTime.Now;
  3168. entitys.update_u_id = uid;
  3169. entitys.update_u_name = userName;
  3170. entitys.Update();
  3171. }
  3172. }
  3173. }
  3174. }
  3175. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3176. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3177. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3178. if (suname != "")
  3179. {
  3180. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3181. }
  3182. commonHelper.getCytPrice(entity);
  3183. returnSuccessMsg("操作成功!");
  3184. return;
  3185. }
  3186. returnErrorMsg("找不到记录");
  3187. }
  3188. }
  3189. public void upload_erp_filecomplete()
  3190. {
  3191. if (UrlPostParmsCheck("ctid"))
  3192. {
  3193. string eid = GetPostString("ctid");
  3194. CeErpTradeCell entity = null;
  3195. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3196. if (entity != null)
  3197. {
  3198. entity.OrderState = 5; //设计完成
  3199. entity.Update();
  3200. returnSuccessMsg(eid + "上传成功,设计完成!");
  3201. return;
  3202. }
  3203. returnErrorMsg("找不到订单记录");
  3204. }
  3205. }
  3206. public void get_erp_designovertimelist()
  3207. {
  3208. DataStruct dStruct = GetPostStruct();
  3209. List<string> lw = new List<string>();
  3210. string tid = GetPostString("ctid");
  3211. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3212. string shopname = GetPostString("shopname");
  3213. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3214. string buyernick = GetPostString("buyer_nick");
  3215. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3216. string ResponsibleMan = GetPostString("responsible");
  3217. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3218. string date1 = GetPostString("date1");
  3219. string date2 = GetPostString("date2");
  3220. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3221. if (dw.Length > 0) lw.Add(dw);
  3222. string price1 = GetPostString("price1");
  3223. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3224. string price2 = GetPostString("price2");
  3225. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3226. string orderState = GetPostString("orderState");
  3227. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3228. string sellermemo = GetPostString("seller_memo");
  3229. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3230. lw.Add(string.Format("UnusualTag=3"));
  3231. lw.Add(string.Format("IsRefund<={0}", 1));
  3232. dStruct.Order = "WaitDesignTime desc";
  3233. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3234. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3235. writeGridDataTableJson(dStruct.TotalCount, dt);
  3236. }
  3237. //设计管理 获取抢单大厅列表
  3238. public void get_erp_grabinglist()
  3239. {
  3240. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3241. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3242. bool oldOrder = false;
  3243. if (org != null)
  3244. {
  3245. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3246. }
  3247. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3248. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3249. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3250. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3251. //先处理订单数据
  3252. if (dt.Rows.Count > 0)
  3253. {
  3254. Dictionary<string, int> design = null;
  3255. int count = 0;
  3256. foreach (DataRow row in dt.Rows)
  3257. {
  3258. if (map.ContainsKey(row["ShopId"].ToString()))
  3259. {
  3260. map.TryGetValue(row["ShopId"].ToString(), out design);
  3261. }
  3262. else
  3263. {
  3264. design = new Dictionary<string, int>();
  3265. }
  3266. if (design.ContainsKey(row["ProductId"].ToString()))
  3267. {
  3268. design.TryGetValue(row["ProductId"].ToString(), out count);
  3269. }
  3270. count++;
  3271. design[row["ProductId"].ToString()] = count;
  3272. map[row["ShopId"].ToString()] = design;
  3273. }
  3274. }
  3275. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3276. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3277. //把店铺排序和技能排序分类
  3278. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3279. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3280. if (design_dt.Rows.Count > 0)
  3281. {
  3282. Dictionary<string, string> design = null;
  3283. List<string> shopIds = null;
  3284. foreach (DataRow row in design_dt.Rows)
  3285. {
  3286. if ("0".Equals(row["designId"].ToString()))
  3287. {
  3288. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3289. {
  3290. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3291. }
  3292. else
  3293. {
  3294. shopIds = new List<string>();
  3295. }
  3296. shopIds.Add(row["shopId"].ToString());
  3297. shop_orders[row["orders"].ToString()] = shopIds;
  3298. }
  3299. else
  3300. {
  3301. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3302. {
  3303. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3304. }
  3305. else
  3306. {
  3307. design = new Dictionary<string, string>();
  3308. }
  3309. design[row["orders"].ToString()] = row["designId"].ToString();
  3310. design_orders[row["shopId"].ToString()] = design;
  3311. }
  3312. }
  3313. //处理成key value后根据key排序
  3314. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3315. foreach (List<string> val in shop_orders.Values)
  3316. {
  3317. if (val != null)
  3318. {
  3319. foreach (string key in val)
  3320. {
  3321. if (design_orders.ContainsKey(key.ToString()))
  3322. {
  3323. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3324. }
  3325. }
  3326. }
  3327. }
  3328. }
  3329. //校验哪个优先级有订单
  3330. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3331. foreach (string key in shop_orders.Keys)
  3332. {
  3333. List<string> ids = null;
  3334. shop_orders.TryGetValue(key, out ids);
  3335. //id为shopid
  3336. foreach (string id in ids)
  3337. {
  3338. Dictionary<string, int> list = null;
  3339. Dictionary<string, string> desing = null;
  3340. map.TryGetValue(id, out list);
  3341. design_orders.TryGetValue(id, out desing);
  3342. if (list != null && desing != null)
  3343. {
  3344. foreach (var item in desing)
  3345. {
  3346. int count = 0;
  3347. if (list.ContainsKey(item.Value))
  3348. {
  3349. list.TryGetValue(item.Value, out count);
  3350. if (count > 0)
  3351. {
  3352. designIds[id] = item.Value;
  3353. break;
  3354. }
  3355. }
  3356. }
  3357. }
  3358. }
  3359. if (designIds.Count > 0)
  3360. {
  3361. break;
  3362. }
  3363. }
  3364. DataTable table = new DataTable();
  3365. table.Columns.Add("tid", typeof(string));
  3366. table.Columns.Add("ctid", typeof(string));
  3367. table.Columns.Add("seller_nick", typeof(string));
  3368. table.Columns.Add("productName", typeof(string));
  3369. table.Columns.Add("pay_time", typeof(string));
  3370. table.Columns.Add("seller_memo", typeof(string));
  3371. if (designIds.Count > 0)
  3372. {
  3373. string shopId = "";
  3374. string productId = "";
  3375. foreach (var designInfo in designIds)
  3376. {
  3377. shopId = designInfo.Key;
  3378. productId = designInfo.Value;
  3379. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3380. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3381. if (dt.Rows.Count > 0)
  3382. {
  3383. foreach (DataRow row in dt.Rows)
  3384. {
  3385. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3386. {
  3387. DataRow data = table.NewRow();
  3388. data["ctid"] = row["ctid"].ToString();
  3389. data["tid"] = row["tid"].ToString();
  3390. data["seller_nick"] = ceErpShop.ShopName;
  3391. data["pay_time"] = row["pay_time"].ToString();
  3392. data["seller_memo"] = row["seller_memo"].ToString();
  3393. data["productName"] = ceErpProduct.PType;
  3394. table.Rows.Add(data);
  3395. }
  3396. }
  3397. }
  3398. }
  3399. }
  3400. writeGridDataTableJson(table.Rows.Count, table);
  3401. }
  3402. private object rushLockObject = new object();
  3403. public void set_erp_grabingorder()
  3404. {
  3405. if (UrlPostParmsCheck("ctid"))
  3406. {
  3407. int total = CurrentUser.User.Person.Total;
  3408. int userId = CurrentUser.User.ID;
  3409. int noFinish = CurrentUser.User.Person.NoFinish;
  3410. int finalization = CurrentUser.User.Person.Finalization;
  3411. string eids = GetPostString("ctid");
  3412. string key = "RushKey_" + userId;
  3413. int count = 0;
  3414. if (erpRedis.RedisHelper.KeyExists(key))
  3415. {
  3416. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3417. if (redisCount != null)
  3418. {
  3419. count = Convert.ToInt32(redisCount);
  3420. }
  3421. }
  3422. if (count >= total)
  3423. {
  3424. returnErrorMsg("半小时内已经抢" + total + "单");
  3425. return;
  3426. }
  3427. string[] ctidlist = eids.Split(',');
  3428. if (count + ctidlist.Length > total)
  3429. {
  3430. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3431. return;
  3432. }
  3433. int itag = 0;
  3434. lock (rushLockObject)
  3435. {
  3436. if (ctidlist.Length > 0)
  3437. {
  3438. string[] dtList = new string[ctidlist.Length];
  3439. for (int i = 0; i < ctidlist.Length; i++)
  3440. {
  3441. dtList[i] = "'" + ctidlist[i] + "'";
  3442. }
  3443. 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"));
  3444. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3445. if (dt_user.Rows.Count > 0)
  3446. {
  3447. int doing = 0;//未定稿
  3448. int finish = 0;//已完成
  3449. foreach (DataRow dr in dt_user.Rows)
  3450. {
  3451. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3452. {
  3453. doing++;
  3454. }
  3455. else
  3456. {
  3457. finish++;
  3458. }
  3459. }
  3460. if (doing >= noFinish)
  3461. {
  3462. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3463. return;
  3464. }
  3465. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3466. {
  3467. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3468. return;
  3469. }
  3470. }
  3471. //校验选择单子状态
  3472. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3473. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3474. if (dt.Rows.Count > 0)
  3475. {
  3476. List<string> list = new List<string>();
  3477. foreach (DataRow dr in dt.Rows)
  3478. {
  3479. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3480. {
  3481. list.Add(dr["ctid"].ToString());
  3482. }
  3483. }
  3484. if (list.Count > 0)
  3485. {
  3486. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3487. return;
  3488. }
  3489. }
  3490. foreach (string ctid in ctidlist)
  3491. {
  3492. CeErpTradeCell entity = null;
  3493. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3494. if (entity != null)
  3495. {
  3496. entity.OrderState = 3;
  3497. entity.DesignUserId = CurrentUser.UserID;
  3498. entity.WaitDesignTime = DateTime.Now;
  3499. entity.StartDesignTime = DateTime.Now;
  3500. entity.Update();
  3501. commonHelper.UpdateRelationOrder(entity.ctid);
  3502. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3503. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3504. itag++;
  3505. }
  3506. }
  3507. }
  3508. }
  3509. count += ctidlist.Length;
  3510. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3511. if (itag == 0)
  3512. returnErrorMsg("没有找到相关订单");
  3513. else
  3514. returnSuccessMsg("抢单成功!");
  3515. return;
  3516. }
  3517. }
  3518. public void get_erp_waitorderlist()
  3519. {
  3520. DataStruct dStruct = GetPostStruct();
  3521. List<string> lw = new List<string>();
  3522. string tid = GetPostString("ctid");
  3523. if (tid.Length > 0)
  3524. {
  3525. string select_tid = getTidByCtid(tid);
  3526. lw.Add(string.Format("tid='{0}'", select_tid));
  3527. }
  3528. string shopname = GetPostString("shopname");
  3529. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3530. string buyernick = GetPostString("buyer_nick");
  3531. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3532. string customer = GetPostString("customer");
  3533. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3534. string design = GetPostString("design");
  3535. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3536. string orderState = GetPostString("orderState");
  3537. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3538. string supplier = GetPostString("supplier");
  3539. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3540. string sellermemo = GetPostString("seller_memo");
  3541. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3542. string otherMemo = GetPostString("otherMemo");
  3543. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3544. string address = GetPostString("address");
  3545. 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));
  3546. string date1 = GetPostString("date1");
  3547. string date2 = GetPostString("date2");
  3548. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3549. if (dw.Length > 0) lw.Add(dw);
  3550. string price1 = GetPostString("price1");
  3551. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3552. string price2 = GetPostString("price2");
  3553. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3554. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3555. lw.Add(string.Format("IsSample != 2 "));
  3556. lw.Add(string.Format("OrderState = 5 "));
  3557. lw.Add(string.Format("IsRefund<={0}", 1));
  3558. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3559. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3560. string pagesize = GetPostString("pagesize");
  3561. if (pagesize != null)
  3562. {
  3563. dStruct.PageSize = 200;
  3564. }
  3565. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3566. List<string> tids = new List<string>();
  3567. if (dt != null)
  3568. {
  3569. dt.Columns.Add("compenPrice", typeof(double));
  3570. foreach (DataRow dr in dt.Rows)
  3571. {
  3572. if (Convert.IsDBNull(dr["compenPrice"]))
  3573. {
  3574. dr["compenPrice"] = 0;
  3575. }
  3576. tids.Add("'" + dr["tid"].ToString() + "'");
  3577. 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();
  3578. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3579. {
  3580. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3581. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3582. entity.SupplierId = suid;
  3583. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3584. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3585. entity.Update();
  3586. }
  3587. }
  3588. }
  3589. if (tids.Count > 0)
  3590. {
  3591. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3592. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3593. if (dt_price != null && dt_price.Rows.Count > 0)
  3594. {
  3595. foreach (DataRow dr in dt_price.Rows)
  3596. {
  3597. foreach (DataRow row in dt.Rows)
  3598. {
  3599. if (row["tid"].Equals(dr["ptid"]))
  3600. {
  3601. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3602. break;
  3603. }
  3604. }
  3605. }
  3606. }
  3607. }
  3608. writeGridDataTableJson(dStruct.TotalCount, dt);
  3609. }
  3610. public void get_erp_supplierwaitorderlist()
  3611. {
  3612. DataStruct dStruct = GetPostStruct();
  3613. List<string> lw = new List<string>();
  3614. string tid = GetPostString("ctid");
  3615. if (tid.Length > 0)
  3616. {
  3617. string select_tid = getTidByCtid(tid);
  3618. lw.Add(string.Format("tid='{0}'", select_tid));
  3619. }
  3620. string shopname = GetPostString("shopname");
  3621. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3622. string sellermemo = GetPostString("seller_memo");
  3623. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3624. string date1 = GetPostString("date1");
  3625. string date2 = GetPostString("date2");
  3626. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3627. if (dw.Length > 0) lw.Add(dw);
  3628. lw.Add(string.Format("OrderState = 5 "));
  3629. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3630. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3631. {
  3632. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3633. }
  3634. string supplier = GetPostString("supplier");
  3635. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3636. {
  3637. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3638. }
  3639. lw.Add(string.Format("IsRefund<={0}", 1));
  3640. dStruct.Order = "FinishDesignTime desc";
  3641. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3642. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3643. if (dt != null)
  3644. {
  3645. foreach (DataRow dr in dt.Rows)
  3646. {
  3647. 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();
  3648. }
  3649. }
  3650. writeGridDataTableJson(dStruct.TotalCount, dt);
  3651. }
  3652. public void upd_erp_verifytosupplier()
  3653. {
  3654. if (UrlPostParmsCheck("ctid"))
  3655. {
  3656. string eids = GetPostString("ctid");
  3657. CeErpTradeCell entity = null;
  3658. string[] eidsList = eids.Split(',');
  3659. if (eidsList.Length <= 0)
  3660. {
  3661. returnErrorMsg("订单号不能空");
  3662. return;
  3663. }
  3664. List<string> tLst = new List<string>();
  3665. foreach (string ctidstr in eidsList)
  3666. {
  3667. tLst.Add("'" + ctidstr + "'");
  3668. CeErpDataSendOrderInfo.createObject(ctidstr);
  3669. }
  3670. string needtids = string.Join(",", tLst.ToArray());
  3671. StringBuilder sql = new StringBuilder();
  3672. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3673. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 AND OrderState = 5 and ctid in ({0});", needtids, CurrentUser.UserID);
  3674. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3675. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3676. returnSuccessMsg("操作成功!");
  3677. return;
  3678. /**foreach (string ctidstr in eidsList)
  3679. {
  3680. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3681. if (entity != null)
  3682. {
  3683. if (entity.SupplierId == 0)
  3684. {
  3685. continue;
  3686. }
  3687. entity.IsVerifyToSupplier = true;
  3688. if (entity.IsReturn == 1) //1是供应商打回
  3689. {
  3690. entity.IsReturn = 0;
  3691. }
  3692. entity.FinishPlaceTime = DateTime.Now;
  3693. entity.PlaceUserId = CurrentUser.UserID;
  3694. entity.Update();
  3695. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3696. }
  3697. }
  3698. returnSuccessMsg("操作成功!");
  3699. return;**/
  3700. }
  3701. }
  3702. public void upd_erp_supplierback()
  3703. {
  3704. if (UrlPostParmsCheck("ctid"))
  3705. {
  3706. string eid = GetPostString("ctid");
  3707. string reason = GetPostString("returnreason");
  3708. CeErpTradeCell entity = null;
  3709. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3710. if (entity != null)
  3711. {
  3712. string message = "操作成功!";
  3713. string isDown = "";
  3714. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3715. {
  3716. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3717. isDown = "被点击下载";
  3718. }
  3719. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3720. {
  3721. string key = "return_order_" + entity.SupplierId;
  3722. List<string> list = new List<string>();
  3723. if (RedisHelper.HasKey(key))
  3724. {
  3725. object data = RedisHelper.StringGet(key);
  3726. list = Convert.ToString(data).Split(',').ToList();
  3727. }
  3728. list.Add(eid);
  3729. RedisHelper.StringSet(key, string.Join(",", list));
  3730. }
  3731. entity.IsVerifyToSupplier = false;
  3732. entity.IsReturn = 1;
  3733. entity.IsHaveNewOrder = 0;
  3734. entity.ReturnTime = DateTime.Now;
  3735. entity.ReturnReason = reason;
  3736. if (entity.OrderState == 6)
  3737. {
  3738. entity.OrderState = 5;
  3739. }
  3740. entity.Update();
  3741. CeErpSukuraData.createInfo(entity.ctid, 5);
  3742. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3743. returnSuccessMsg(message);
  3744. return;
  3745. }
  3746. returnErrorMsg("找不到订单记录");
  3747. }
  3748. }
  3749. public void upd_erp_toaftersaleorder()
  3750. {
  3751. if (UrlPostParmsCheck("ctid"))
  3752. {
  3753. string eid = GetPostString("ctid");
  3754. string reason = GetPostString("returnreason");
  3755. CeErpTradeCell entity = null;
  3756. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3757. if (entity != null)
  3758. {
  3759. if (entity.isAfterSaleOrder != 1)
  3760. {
  3761. returnErrorMsg("带S的售后单才能打回给售后");
  3762. return;
  3763. }
  3764. if (entity.OrderState >= 5)
  3765. {
  3766. returnErrorMsg("已经设计完成了不能打回给售后");
  3767. return;
  3768. }
  3769. entity.OrderState = 0;
  3770. entity.IsReturn = 3;
  3771. entity.ReturnTime = DateTime.Now;
  3772. entity.UpdateTime = DateTime.Now;
  3773. entity.ReturnReason = reason;
  3774. entity.Update();
  3775. CeErpSukuraData.createInfo(entity.ctid, 5);
  3776. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3777. returnSuccessMsg("操作成功!");
  3778. return;
  3779. }
  3780. returnErrorMsg("找不到订单记录");
  3781. }
  3782. }
  3783. public void upd_erp_aftersaletodesign()
  3784. {
  3785. if (UrlPostParmsCheck("ctid"))
  3786. {
  3787. string eid = GetPostString("ctid");
  3788. CeErpTradeCell entity = null;
  3789. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3790. if (entity != null)
  3791. {
  3792. entity.OrderState = 3;
  3793. entity.IsReturn = 0;
  3794. entity.UpdateTime = DateTime.Now;
  3795. entity.Update();
  3796. CeErpSukuraData.createInfo(entity.ctid, 5);
  3797. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3798. returnSuccessMsg("操作成功!");
  3799. return;
  3800. }
  3801. returnErrorMsg("找不到订单记录");
  3802. }
  3803. }
  3804. public void assign_erp_supplier()
  3805. {
  3806. if (UrlPostParmsCheck("ctid"))
  3807. {
  3808. string eids = GetPostString("ctid");
  3809. int sid = GetPostInt("SupplierName");
  3810. string fromTag = GetPostString("tag");
  3811. string[] eidList = eids.Split(',');
  3812. if (eidList.Length <= 0)
  3813. {
  3814. returnErrorMsg("指派不能为空");
  3815. return;
  3816. }
  3817. string errMsg = "";
  3818. string suname = commonHelper.getSupplierNameById(sid);
  3819. foreach (string ctid in eidList)
  3820. {
  3821. CeErpTradeCell entity = null;
  3822. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3823. if (entity != null)
  3824. {
  3825. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3826. {
  3827. errMsg += (ctid + "指派失败!!!");
  3828. continue;
  3829. }
  3830. entity.SupplierId = sid;
  3831. entity.Update();
  3832. commonHelper.UpdateRelationOrder(entity.ctid);
  3833. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3834. if (entity.OrderState >= 6)
  3835. {
  3836. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3837. //{
  3838. // string msl = entity.MakeSupplier;
  3839. // string[] mslist = msl.Split(',');
  3840. // 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);
  3841. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3842. //}
  3843. //else
  3844. //{
  3845. StringBuilder sql = new StringBuilder();
  3846. 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);
  3847. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3848. //}
  3849. }
  3850. }
  3851. else
  3852. {
  3853. continue;
  3854. }
  3855. }
  3856. if (errMsg.Length > 0)
  3857. {
  3858. returnErrorMsg(errMsg);
  3859. return;
  3860. }
  3861. returnSuccessMsg("操作成功!");
  3862. return;
  3863. }
  3864. }
  3865. public void assign_erp_makesupplier()
  3866. {
  3867. if (UrlPostParmsCheck("ctid"))
  3868. {
  3869. string eids = GetPostString("ctid");
  3870. string sname = GetPostString("SupplierName");
  3871. string[] eidList = eids.Split(',');
  3872. if (eidList.Length <= 0)
  3873. {
  3874. returnErrorMsg("指派不能为空");
  3875. return;
  3876. }
  3877. List<string> tLst = new List<string>();
  3878. foreach (string ctid in eidList)
  3879. {
  3880. CeErpTradeCell entity = null;
  3881. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3882. if (entity != null)
  3883. {
  3884. entity.MakeSupplier = sname;
  3885. entity.Update();
  3886. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3887. tLst.Add("'" + ctid + "'");
  3888. }
  3889. else
  3890. {
  3891. continue;
  3892. }
  3893. }
  3894. string ctids = string.Join(",", tLst.ToArray());
  3895. StringBuilder sql2 = new StringBuilder();
  3896. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3897. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3898. returnSuccessMsg("操作成功!");
  3899. return;
  3900. }
  3901. }
  3902. public void ins_erp_returnreason()
  3903. {
  3904. if (UrlPostParmsCheck("ctid"))
  3905. {
  3906. string eid = GetPostString("ctid");
  3907. CeErpTradeCell entity = null;
  3908. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3909. string userpost = CurrentUser.UserPost.Post.Code;
  3910. if (entity != null)
  3911. {
  3912. bool isPlace = false;
  3913. if (entity.OrderState > 6)
  3914. {
  3915. returnErrorMsg("已发货无法打回!");
  3916. return;
  3917. }
  3918. if (entity.OrderState == 6)
  3919. {
  3920. isPlace = true;
  3921. }
  3922. bool isNeedUpdateCell2 = false;
  3923. if (entity.OrderState >= 6)
  3924. {
  3925. isNeedUpdateCell2 = true;
  3926. }
  3927. int returnTag = 2;
  3928. if (userpost == "Supplier")
  3929. {
  3930. returnTag = 1;
  3931. }
  3932. int toType = GetPostInt("totype");
  3933. string fromType = "3";
  3934. if (entity.OrderState < 5)
  3935. {
  3936. fromType = "3";
  3937. }
  3938. else
  3939. {
  3940. fromType = "4";
  3941. }
  3942. if (entity.IsXianHuo == 0)
  3943. {
  3944. if (returnTag == 2)
  3945. {
  3946. if (toType == 1)
  3947. {
  3948. entity.OrderState = 0;
  3949. entity.ReturnUserType = 1;
  3950. string clearman = GetPostString("clearman");
  3951. if (!string.IsNullOrEmpty(clearman))
  3952. {
  3953. entity.DesignUserId = 0;
  3954. }
  3955. }
  3956. else
  3957. {
  3958. entity.OrderState = 3;
  3959. entity.ReturnUserType = 2;
  3960. }
  3961. entity.IsReadTag = 1;
  3962. }
  3963. else if (returnTag == 1)
  3964. {
  3965. entity.OrderState = 5;
  3966. }
  3967. entity.IsVerifyToSupplier = false;
  3968. }
  3969. if (entity.IsXianHuo == 1)
  3970. {
  3971. entity.OrderState = 5;
  3972. }
  3973. entity.UnusualTag = 0;
  3974. entity.UnusualTime = null;
  3975. entity.UnusualCon = "";
  3976. entity.IsReturn = returnTag;
  3977. entity.ReturnTime = DateTime.Now;
  3978. entity.UpdateTime = DateTime.Now;
  3979. entity.ReturnReason = GetPostString("returnreason");
  3980. entity.Update();
  3981. if (entity.OrderState == 3)
  3982. {
  3983. ApiVo apiVo = new ApiVo();
  3984. apiVo.orderNumber = entity.ctid;
  3985. apiVo.actionName = "rebutDesign";
  3986. apiVo.orderRemarks = entity.ReturnReason;
  3987. designHelper.API_WorkCore(apiVo);//rebutDesign
  3988. }
  3989. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3990. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3991. {
  3992. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3993. }
  3994. CeErpSukuraData.createInfo(entity.ctid, 5);
  3995. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3996. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3997. if (isPlace)
  3998. {
  3999. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4000. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4001. if (dth != null && dth.Rows.Count > 0)
  4002. {
  4003. dataSendOrderBean dataSendOrderBean = null;
  4004. foreach (DataRow item in dth.Rows)
  4005. {
  4006. try
  4007. {
  4008. dataSendOrderBean = new dataSendOrderBean();
  4009. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4010. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4011. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4012. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4013. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4014. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4015. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4016. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4017. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4018. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4019. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4020. dataSendOrderBean.Radio1723534706288 = "打回";
  4021. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4022. if (result != null)
  4023. {
  4024. if ("0".Equals(result.errcode))
  4025. {
  4026. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4027. }
  4028. else
  4029. {
  4030. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4031. }
  4032. }
  4033. }
  4034. catch (Exception ex)
  4035. {
  4036. }
  4037. }
  4038. }
  4039. }
  4040. if (isNeedUpdateCell2)
  4041. {
  4042. if (entity.MakeSupplier.IndexOf(",") != -1)
  4043. {
  4044. StringBuilder sql2 = new StringBuilder();
  4045. 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);
  4046. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4047. }
  4048. else
  4049. {
  4050. StringBuilder sql2 = new StringBuilder();
  4051. 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);
  4052. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4053. }
  4054. }
  4055. returnSuccessMsg("操作成功!");
  4056. return;
  4057. }
  4058. returnErrorMsg("找不到订单记录");
  4059. }
  4060. }
  4061. public void cyt_erp_returnreason()
  4062. {
  4063. if (UrlPostParmsCheck("ctid"))
  4064. {
  4065. string eid = GetPostString("ctid");
  4066. CeErpTradeCell entity = null;
  4067. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4068. string userpost = CurrentUser.UserPost.Post.Code;
  4069. if (entity != null)
  4070. {
  4071. if (entity.OrderState > 6)
  4072. {
  4073. returnErrorMsg("已发货无法打回!");
  4074. return;
  4075. }
  4076. JObject jsonObject = new JObject
  4077. {
  4078. { "Userid", "77886" },
  4079. { "Pwd", "lt666888" },
  4080. { "LTOrderId",eid }
  4081. };
  4082. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4083. JObject jsonObjects = JObject.Parse(response);
  4084. string msg = (string)jsonObjects["msg"];
  4085. if (msg != "取消成功")
  4086. {
  4087. returnErrorMsg(msg);
  4088. return;
  4089. }
  4090. bool isNeedUpdateCell2 = false;
  4091. if (entity.OrderState >= 6)
  4092. {
  4093. isNeedUpdateCell2 = true;
  4094. }
  4095. int returnTag = 2;
  4096. if (userpost == "Supplier")
  4097. {
  4098. returnTag = 1;
  4099. }
  4100. if (entity.IsXianHuo == 0)
  4101. {
  4102. if (returnTag == 2)
  4103. {
  4104. int toType = GetPostInt("totype");
  4105. if (toType == 1)
  4106. {
  4107. entity.OrderState = 0;
  4108. entity.ReturnUserType = 1;
  4109. }
  4110. else
  4111. {
  4112. entity.OrderState = 4;
  4113. entity.ReturnUserType = 2;
  4114. }
  4115. entity.IsReadTag = 1;
  4116. }
  4117. else if (returnTag == 1)
  4118. {
  4119. entity.OrderState = 5;
  4120. }
  4121. entity.IsVerifyToSupplier = false;
  4122. }
  4123. entity.UnusualTag = 0;
  4124. entity.UnusualTime = null;
  4125. entity.UnusualCon = "";
  4126. entity.IsReturn = returnTag;
  4127. entity.ReturnTime = DateTime.Now;
  4128. entity.ReturnReason = GetPostString("returnreason");
  4129. entity.Update();
  4130. if (entity.OrderState == 4)
  4131. {
  4132. ApiVo apiVo = new ApiVo();
  4133. apiVo.orderNumber = entity.ctid;
  4134. apiVo.actionName = "rebutDesign";
  4135. apiVo.orderRemarks = entity.ReturnReason;
  4136. designHelper.API_WorkCore(apiVo);//rebutDesign
  4137. }
  4138. CeErpSukuraData.createInfo(entity.ctid, 5);
  4139. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4140. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4141. if (isNeedUpdateCell2)
  4142. {
  4143. if (entity.MakeSupplier.IndexOf(",") != -1)
  4144. {
  4145. StringBuilder sql2 = new StringBuilder();
  4146. 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);
  4147. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4148. }
  4149. else
  4150. {
  4151. StringBuilder sql2 = new StringBuilder();
  4152. 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);
  4153. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4154. }
  4155. }
  4156. returnSuccessMsg("操作成功!");
  4157. return;
  4158. }
  4159. returnErrorMsg("找不到订单记录");
  4160. }
  4161. }
  4162. public void upd_erp_xianhuoreturntag()
  4163. {
  4164. if (UrlPostParmsCheck("ctid"))
  4165. {
  4166. string eids = GetPostString("ctid");
  4167. string[] ctids = eids.Split(',');
  4168. foreach (string ctid in ctids)
  4169. {
  4170. CeErpTradeCell entity = null;
  4171. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4172. if (entity != null)
  4173. {
  4174. entity.IsReturn = 0;
  4175. entity.Update();
  4176. CeErpSukuraData.createInfo(entity.ctid, 5);
  4177. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4178. }
  4179. }
  4180. returnSuccessMsg("操作成功!");
  4181. return;
  4182. }
  4183. }
  4184. public void get_erp_waitdeliverylist()
  4185. {
  4186. DataStruct dStruct = GetPostStruct();
  4187. List<string> lw = new List<string>();
  4188. string tid = GetPostString("ctid");
  4189. if (tid.Length > 0)
  4190. {
  4191. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4192. if (tid.Length > 5)
  4193. {
  4194. List<string> tids = getTidByCtidLike(tid);
  4195. if (tids.Count > 0 && tids.Count < 10)
  4196. {
  4197. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4198. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4199. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4200. {
  4201. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4202. }*/
  4203. }
  4204. }
  4205. lw.Add(tid_sql);
  4206. }
  4207. string shopname = GetPostString("shopname");
  4208. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4209. string buyernick = GetPostString("buyer_nick");
  4210. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4211. //if (tid.Length == 0 && buyernick.Length == 0)
  4212. //{
  4213. // lw.Add(string.Format("IsRefund<={0}", 1));
  4214. //}
  4215. string customer = GetPostString("customer");
  4216. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4217. string design = GetPostString("design");
  4218. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4219. string orderState = GetPostString("orderState");
  4220. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4221. string address = GetPostString("address");
  4222. 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));
  4223. string sellermemo = GetPostString("seller_memo");
  4224. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4225. string supplier = GetPostString("supplier");
  4226. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4227. string OrderArea = GetPostString("order_area");
  4228. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4229. string placedate1 = GetPostString("placedate1");
  4230. string placedate2 = GetPostString("placedate2");
  4231. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4232. if (fdw.Length > 0) lw.Add(fdw);
  4233. string price1 = GetPostString("price1");
  4234. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4235. string price2 = GetPostString("price2");
  4236. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4237. string unusualCon = GetPostString("unusualcon");
  4238. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4239. string otherMemo = GetPostString("otherMemo");
  4240. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4241. string posTag = CurrentUser.UserPost.Post.Code;
  4242. if (posTag == "Supplier")
  4243. {
  4244. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4245. }
  4246. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4247. lw.Add(string.Format("type != 'PDD' "));
  4248. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4249. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4250. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4251. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4252. writeGridDataTableJson(dStruct.TotalCount, dt);
  4253. }
  4254. public void get_erp_changedeliverylist()
  4255. {
  4256. DataStruct dStruct = GetPostStruct();
  4257. List<string> lw = new List<string>();
  4258. string tid = GetPostString("ctid");
  4259. if (tid.Length > 0)
  4260. {
  4261. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4262. if (tid.Length > 5)
  4263. {
  4264. List<string> tids = getTidByCtidLike(tid);
  4265. if (tids.Count > 0 && tids.Count < 10)
  4266. {
  4267. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4268. }
  4269. }
  4270. lw.Add(tid_sql);
  4271. }
  4272. string shopname = GetPostString("shopname");
  4273. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4274. string buyernick = GetPostString("buyer_nick");
  4275. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4276. //if (tid.Length == 0 && buyernick.Length == 0)
  4277. //{
  4278. // lw.Add(string.Format("IsRefund<={0}", 1));
  4279. //}
  4280. string customer = GetPostString("customer");
  4281. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4282. string design = GetPostString("design");
  4283. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4284. string orderState = GetPostString("orderState");
  4285. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4286. string address = GetPostString("address");
  4287. 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));
  4288. string sellermemo = GetPostString("seller_memo");
  4289. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4290. string supplier = GetPostString("supplier");
  4291. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4292. string OrderArea = GetPostString("order_area");
  4293. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4294. string placedate1 = GetPostString("placedate1");
  4295. string placedate2 = GetPostString("placedate2");
  4296. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4297. if (fdw.Length > 0) lw.Add(fdw);
  4298. string price1 = GetPostString("price1");
  4299. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4300. string price2 = GetPostString("price2");
  4301. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4302. string unusualCon = GetPostString("unusualcon");
  4303. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4304. string otherMemo = GetPostString("otherMemo");
  4305. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4306. string posTag = CurrentUser.UserPost.Post.Code;
  4307. if (posTag == "Supplier")
  4308. {
  4309. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4310. }
  4311. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4312. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4313. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4314. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4315. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4316. /*if (tid.Length > 0)
  4317. {
  4318. List<string> tids = new List<string>();
  4319. if (dt != null && dt.Rows.Count > 0)
  4320. {
  4321. foreach (DataRow item in dt.Rows)
  4322. {
  4323. tids.Add("'" + item["tid"] + "'");
  4324. }
  4325. }
  4326. if (tids.Count > 0)
  4327. {
  4328. lw.RemoveAt(0);
  4329. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4330. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4331. dt = WebCache.GetData("view_erptradecell", dStruct);
  4332. }
  4333. }*/
  4334. writeGridDataTableJson(dStruct.TotalCount, dt);
  4335. }
  4336. public void get_erp_pddderiving()
  4337. {
  4338. DataStruct dStruct = GetPostStruct();
  4339. List<string> lw = new List<string>();
  4340. string tid = GetPostString("ctid");
  4341. if (tid.Length > 0)
  4342. {
  4343. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4344. if (tid.Length > 5)
  4345. {
  4346. List<string> tids = getTidByCtidLike(tid);
  4347. if (tids.Count > 0 && tids.Count < 10)
  4348. {
  4349. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4350. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4351. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4352. {
  4353. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4354. }*/
  4355. }
  4356. }
  4357. lw.Add(tid_sql);
  4358. }
  4359. string shopname = GetPostString("shopname");
  4360. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4361. string buyernick = GetPostString("buyer_nick");
  4362. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4363. //if (tid.Length == 0 && buyernick.Length == 0)
  4364. //{
  4365. // lw.Add(string.Format("IsRefund<={0}", 1));
  4366. //}
  4367. string customer = GetPostString("customer");
  4368. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4369. string design = GetPostString("design");
  4370. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4371. string orderState = GetPostString("orderState");
  4372. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4373. string address = GetPostString("address");
  4374. 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));
  4375. string sellermemo = GetPostString("seller_memo");
  4376. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4377. string supplier = GetPostString("supplier");
  4378. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4379. string OrderArea = GetPostString("order_area");
  4380. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4381. string placedate1 = GetPostString("placedate1");
  4382. string placedate2 = GetPostString("placedate2");
  4383. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4384. if (fdw.Length > 0) lw.Add(fdw);
  4385. string price1 = GetPostString("price1");
  4386. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4387. string price2 = GetPostString("price2");
  4388. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4389. string unusualCon = GetPostString("unusualcon");
  4390. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4391. string posTag = CurrentUser.UserPost.Post.Code;
  4392. if (posTag == "Supplier")
  4393. {
  4394. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4395. }
  4396. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4397. lw.Add(string.Format("type = 'PDD' "));
  4398. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4399. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4400. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4401. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4402. /*if (tid.Length > 0)
  4403. {
  4404. List<string> tids = new List<string>();
  4405. if (dt != null && dt.Rows.Count > 0)
  4406. {
  4407. foreach (DataRow item in dt.Rows)
  4408. {
  4409. tids.Add("'" + item["tid"] + "'");
  4410. }
  4411. }
  4412. if (tids.Count > 0)
  4413. {
  4414. lw.RemoveAt(0);
  4415. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4416. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4417. dt = WebCache.GetData("view_erptradecell", dStruct);
  4418. }
  4419. }*/
  4420. writeGridDataTableJson(dStruct.TotalCount, dt);
  4421. }
  4422. public void get_erp_jdderiving()
  4423. {
  4424. DataStruct dStruct = GetPostStruct();
  4425. List<string> lw = new List<string>();
  4426. string tid = GetPostString("ctid");
  4427. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4428. string shopname = GetPostString("shopname");
  4429. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4430. string buyernick = GetPostString("buyer_nick");
  4431. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4432. //if (tid.Length == 0 && buyernick.Length == 0)
  4433. //{
  4434. // lw.Add(string.Format("IsRefund<={0}", 1));
  4435. //}
  4436. string customer = GetPostString("customer");
  4437. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4438. string design = GetPostString("design");
  4439. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4440. string orderState = GetPostString("orderState");
  4441. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4442. string address = GetPostString("address");
  4443. 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));
  4444. string sellermemo = GetPostString("seller_memo");
  4445. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4446. string supplier = GetPostString("supplier");
  4447. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4448. string OrderArea = GetPostString("order_area");
  4449. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4450. string placedate1 = GetPostString("placedate1");
  4451. string placedate2 = GetPostString("placedate2");
  4452. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4453. if (fdw.Length > 0) lw.Add(fdw);
  4454. string price1 = GetPostString("price1");
  4455. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4456. string price2 = GetPostString("price2");
  4457. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4458. string unusualCon = GetPostString("unusualcon");
  4459. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4460. string posTag = CurrentUser.UserPost.Post.Code;
  4461. if (posTag == "Supplier")
  4462. {
  4463. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4464. }
  4465. lw.Add(string.Format("OrderState = 6 "));
  4466. lw.Add(string.Format("type = 'JD' "));
  4467. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4468. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4469. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4470. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4471. writeGridDataTableJson(dStruct.TotalCount, dt);
  4472. }
  4473. public void get_erp_demoorderlist()
  4474. {
  4475. DataStruct dStruct = GetPostStruct();
  4476. List<string> lw = new List<string>();
  4477. string tid = GetPostString("ctid");
  4478. if (tid.Length > 0)
  4479. {
  4480. string select_tid = getTidByCtid(tid);
  4481. lw.Add(string.Format("tid='{0}'", select_tid));
  4482. }
  4483. string shopname = GetPostString("shopname");
  4484. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4485. string buyernick = GetPostString("buyer_nick");
  4486. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4487. string customer = GetPostString("customer");
  4488. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4489. string design = GetPostString("design");
  4490. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4491. string orderState = GetPostString("orderState");
  4492. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4493. string address = GetPostString("address");
  4494. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4495. string sellermemo = GetPostString("seller_memo");
  4496. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4497. string supplier = GetPostString("supplier");
  4498. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4499. string OrderArea = GetPostString("order_area");
  4500. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4501. string date1 = GetPostString("date1");
  4502. string date2 = GetPostString("date2");
  4503. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4504. if (dw.Length > 0) lw.Add(dw);
  4505. string price1 = GetPostString("price1");
  4506. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4507. string price2 = GetPostString("price2");
  4508. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4509. string posTag = CurrentUser.UserPost.Post.Code;
  4510. if (posTag == "Supplier")
  4511. {
  4512. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4513. }
  4514. //lw.Add(string.Format("OrderState = 6 "));
  4515. lw.Add(string.Format("IsSample={0}", 3));
  4516. lw.Add(string.Format("IsRefund<={0}", 1));
  4517. dStruct.Order = "pay_time desc";
  4518. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4519. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4520. writeGridDataTableJson(dStruct.TotalCount, dt);
  4521. }
  4522. public void save_erp_checkmemo()
  4523. {
  4524. if (UrlPostParmsCheck("ctid"))
  4525. {
  4526. string ctid = GetPostString("ctid");
  4527. CeErpTradeCell entity = null;
  4528. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4529. if (entity != null)
  4530. {
  4531. entity.CheckMemo = GetPostString("CheckMemo");
  4532. entity.Update();
  4533. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4534. if (trade != null)
  4535. {
  4536. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4537. }
  4538. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4539. returnSuccessMsg("保存成功!");
  4540. return;
  4541. }
  4542. returnErrorMsg("找不到记录");
  4543. }
  4544. }
  4545. public void get_erp_returnlist()
  4546. {
  4547. DataStruct dStruct = GetPostStruct();
  4548. List<string> lw = new List<string>();
  4549. string tid = GetPostString("ctid");
  4550. if (tid.Length > 0)
  4551. {
  4552. string select_tid = getTidByCtid(tid);
  4553. lw.Add(string.Format("tid='{0}'", select_tid));
  4554. }
  4555. string shopname = GetPostString("shopname");
  4556. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4557. string buyernick = GetPostString("buyer_nick");
  4558. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4559. string customer = GetPostString("customer");
  4560. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4561. string design = GetPostString("design");
  4562. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4563. string orderState = GetPostString("orderState");
  4564. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4565. string address = GetPostString("address");
  4566. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4567. string sellermemo = GetPostString("seller_memo");
  4568. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4569. string supplier = GetPostString("supplier");
  4570. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4571. string date1 = GetPostString("date1");
  4572. string date2 = GetPostString("date2");
  4573. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4574. if (dw.Length > 0) lw.Add(dw);
  4575. string bdate1 = GetPostString("backdate1");
  4576. string bdate2 = GetPostString("backdate2");
  4577. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4578. if (dw_back.Length > 0) lw.Add(dw_back);
  4579. string price1 = GetPostString("price1");
  4580. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4581. string price2 = GetPostString("price2");
  4582. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4583. lw.Add(string.Format("IsReturn>0"));
  4584. lw.Add(string.Format("IsXianHuo=0"));
  4585. lw.Add(string.Format("IsReturn!=3"));
  4586. string backtype = GetPostString("backtype");
  4587. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4588. dStruct.Order = "FinishDesignTime desc";
  4589. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4590. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4591. writeGridDataTableJson(dStruct.TotalCount, dt);
  4592. }
  4593. public void get_erp_today_sumreturn()
  4594. {
  4595. DataStruct dStruct = GetPostStruct();
  4596. List<string> lw = new List<string>();
  4597. string bdate1 = GetPostString("returnTimeS");
  4598. string bdate2 = GetPostString("returnTimeE");
  4599. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4600. if (dw_back.Length > 0) lw.Add(dw_back);
  4601. lw.Add(string.Format("IsReturn=0"));
  4602. lw.Add(string.Format("IsXianHuo=0"));
  4603. string mainWhere = string.Join(" and ", lw.ToArray());
  4604. string sql = "";
  4605. if (dw_back.Length > 0)
  4606. {
  4607. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4608. }
  4609. else
  4610. {
  4611. 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 + "'";
  4612. }
  4613. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4614. decimal total = 0, today_finish = 0;
  4615. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4616. {
  4617. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4618. }
  4619. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4620. {
  4621. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4622. }
  4623. var res = new
  4624. {
  4625. data = total,
  4626. data1 = today_finish,
  4627. };
  4628. string ro_jsond = JsonConvert.SerializeObject(res);
  4629. returnSuccess(ro_jsond);
  4630. return;
  4631. }
  4632. public void get_erp_allreturnlist()
  4633. {
  4634. DataStruct dStruct = GetPostStruct();
  4635. List<string> lw = new List<string>();
  4636. string tid = GetPostString("ctid");
  4637. if (tid.Length > 0)
  4638. {
  4639. string select_tid = getTidByCtid(tid);
  4640. lw.Add(string.Format("tid='{0}'", select_tid));
  4641. }
  4642. string shopname = GetPostString("shopname");
  4643. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4644. string buyernick = GetPostString("buyer_nick");
  4645. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4646. string customer = GetPostString("customer");
  4647. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4648. string design = GetPostString("design");
  4649. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4650. string orderState = GetPostString("orderState");
  4651. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4652. string address = GetPostString("address");
  4653. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4654. string sellermemo = GetPostString("seller_memo");
  4655. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4656. string supplier = GetPostString("supplier");
  4657. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4658. string date1 = GetPostString("date1");
  4659. string date2 = GetPostString("date2");
  4660. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4661. if (dw.Length > 0) lw.Add(dw);
  4662. string bdate1 = GetPostString("backdate1");
  4663. string bdate2 = GetPostString("backdate2");
  4664. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4665. if (dw_back.Length > 0) lw.Add(dw_back);
  4666. string price1 = GetPostString("price1");
  4667. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4668. string price2 = GetPostString("price2");
  4669. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4670. string backreason = GetPostString("backreason");
  4671. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4672. lw.Add(string.Format("IsXianHuo=0"));
  4673. lw.Add(string.Format("ReturnTime != ''"));
  4674. string backtype = GetPostString("backtype");
  4675. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4676. dStruct.Order = "FinishDesignTime desc";
  4677. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4678. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4679. writeGridDataTableJson(dStruct.TotalCount, dt);
  4680. }
  4681. public void get_erp_aftersalereturnlist()
  4682. {
  4683. DataStruct dStruct = GetPostStruct();
  4684. List<string> lw = new List<string>();
  4685. string tid = GetPostString("ctid");
  4686. if (tid.Length > 0)
  4687. {
  4688. string select_tid = getTidByCtid(tid);
  4689. lw.Add(string.Format("tid='{0}'", select_tid));
  4690. }
  4691. string shopname = GetPostString("shopname");
  4692. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4693. string buyernick = GetPostString("buyer_nick");
  4694. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4695. string customer = GetPostString("customer");
  4696. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4697. string design = GetPostString("design");
  4698. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4699. string orderState = GetPostString("orderState");
  4700. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4701. string address = GetPostString("address");
  4702. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4703. string sellermemo = GetPostString("seller_memo");
  4704. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4705. string supplier = GetPostString("supplier");
  4706. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4707. string date1 = GetPostString("date1");
  4708. string date2 = GetPostString("date2");
  4709. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4710. if (dw.Length > 0) lw.Add(dw);
  4711. string bdate1 = GetPostString("backdate1");
  4712. string bdate2 = GetPostString("backdate2");
  4713. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4714. if (dw_back.Length > 0) lw.Add(dw_back);
  4715. string price1 = GetPostString("price1");
  4716. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4717. string price2 = GetPostString("price2");
  4718. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4719. lw.Add(string.Format("IsReturn=3"));
  4720. string backtype = GetPostString("backtype");
  4721. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4722. string backreason = GetPostString("backreason");
  4723. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4724. dStruct.Order = "ReturnTime desc";
  4725. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4726. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4727. writeGridDataTableJson(dStruct.TotalCount, dt);
  4728. }
  4729. public void get_erp_xianhuoreturnlist()
  4730. {
  4731. DataStruct dStruct = GetPostStruct();
  4732. List<string> lw = new List<string>();
  4733. string tid = GetPostString("ctid");
  4734. if (tid.Length > 0)
  4735. {
  4736. string select_tid = getTidByCtid(tid);
  4737. lw.Add(string.Format("tid='{0}'", select_tid));
  4738. }
  4739. string shopname = GetPostString("shopname");
  4740. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4741. string buyernick = GetPostString("buyer_nick");
  4742. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4743. string customer = GetPostString("customer");
  4744. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4745. string design = GetPostString("design");
  4746. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4747. string orderState = GetPostString("orderState");
  4748. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4749. string address = GetPostString("address");
  4750. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4751. string sellermemo = GetPostString("seller_memo");
  4752. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4753. string supplier = GetPostString("supplier");
  4754. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4755. string OrderArea = GetPostString("order_area");
  4756. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4757. string date1 = GetPostString("date1");
  4758. string date2 = GetPostString("date2");
  4759. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4760. if (dw.Length > 0) lw.Add(dw);
  4761. string price1 = GetPostString("price1");
  4762. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4763. string price2 = GetPostString("price2");
  4764. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4765. string posTag = CurrentUser.UserPost.Post.Code;
  4766. if (posTag == "Supplier")
  4767. {
  4768. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4769. }
  4770. lw.Add(string.Format("OrderState=6 "));
  4771. lw.Add(string.Format("IsXianHuo=1 "));
  4772. lw.Add(string.Format("IsReturn>0 "));
  4773. lw.Add(string.Format("IsReturn!=3"));
  4774. lw.Add(string.Format("IsRefund<={0}", 1));
  4775. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4776. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4777. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4778. writeGridDataTableJson(dStruct.TotalCount, dt);
  4779. }
  4780. public void set_erp_orderdelivery()
  4781. {
  4782. if (UrlPostParmsCheck("ctid"))
  4783. {
  4784. string eid = GetPostString("ctid");
  4785. CeErpTradeCell entity = null;
  4786. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4787. if (entity != null)
  4788. {
  4789. if (entity.OrderState >= 7)
  4790. {
  4791. returnErrorMsg("此单已发货,无需重复发货");
  4792. return;
  4793. }
  4794. if (entity.OrderState != 6)
  4795. {
  4796. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4797. return;
  4798. }
  4799. string shop = GetPostString("seller_nick");
  4800. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4801. string comName = GetPostString("comName");
  4802. string comCode = GetPostString("comCode");
  4803. string outSid = GetPostString("outSid");
  4804. string deliveryType = GetPostString("deliveryType");
  4805. string deliveryMemo = GetPostString("deliveryMemo");
  4806. outSid = outSid.Trim();
  4807. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4808. if (mainEn == null)
  4809. {
  4810. returnErrorMsg("找不到原始订单记录");
  4811. return;
  4812. }
  4813. bool isInitOrderDeliv = false;
  4814. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4815. {
  4816. isInitOrderDeliv = true;
  4817. }
  4818. string apires = "";
  4819. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4820. 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)
  4821. {
  4822. apires = "发货成功true";
  4823. }
  4824. else
  4825. {
  4826. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4827. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4828. }
  4829. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4830. {
  4831. entity.OrderState = 7;//发货后订单已发货
  4832. entity.OutSid = outSid;
  4833. entity.MemoOpt = 0;
  4834. entity.UpdateTime = DateTime.Now;
  4835. entity.FinishDeliveryTime = DateTime.Now;
  4836. entity.Update();
  4837. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4838. commonHelper.UpdateRelationOrder(entity.ctid);
  4839. //还要插入快递信息到 快递信息表
  4840. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4841. exinfo.tid = eid;
  4842. exinfo.out_sid = outSid;
  4843. exinfo.company_code = comCode;
  4844. exinfo.company_name = comName;
  4845. exinfo.delivery_memo = deliveryMemo;
  4846. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4847. exinfo.deliveryType = deliveryType;
  4848. exinfo.Create();
  4849. returnSuccessMsg("发货操作成功!");
  4850. commonHelper.UpdateRelationOrder(entity.ctid);
  4851. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4852. CeErpSukuraData.createInfo(entity.ctid, 4);
  4853. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  4854. {
  4855. commonHelper.sendCytExpress(exinfo);
  4856. }
  4857. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4858. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  4859. }
  4860. else
  4861. {
  4862. string errmsg = commonHelper.KeepChinese(apires);
  4863. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4864. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4865. }
  4866. return;
  4867. }
  4868. returnErrorMsg("找不到订单记录");
  4869. }
  4870. }
  4871. public void set_erp_multidelivery()
  4872. {
  4873. string eids = GetPostString("tids");
  4874. string[] eidList = eids.Split(',');
  4875. if (eidList.Length <= 0)
  4876. {
  4877. returnErrorMsg("发货不能为空");
  4878. return;
  4879. }
  4880. foreach (string ctid in eidList)
  4881. {
  4882. if (ctid.Length <= 0) continue;
  4883. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4884. if (expInfo != null)
  4885. {
  4886. StringBuilder sql = new StringBuilder();
  4887. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4888. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4889. if (dt.Rows.Count > 0)
  4890. {
  4891. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4892. {
  4893. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4894. expInfo.state = "异常";
  4895. expInfo.isMultiDelivery = 1;
  4896. expInfo.Update();
  4897. continue;
  4898. }
  4899. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4900. {
  4901. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4902. expInfo.state = "异常";
  4903. expInfo.Update();
  4904. continue;
  4905. }
  4906. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4907. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4908. bool isInitOrderDeliv = false;
  4909. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4910. {
  4911. isInitOrderDeliv = true;
  4912. expInfo.isMultiDelivery = 1;
  4913. }
  4914. if (ctid.IndexOf("N") != -1)
  4915. {
  4916. StringBuilder sqlbucha = new StringBuilder();
  4917. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4918. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4919. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4920. commonHelper.UpdateRelationOrder(ctid);
  4921. expInfo.delivery_memo = "发货成功";
  4922. expInfo.state = "发货成功";
  4923. expInfo.isMultiDelivery = 1;
  4924. expInfo.Update();
  4925. }
  4926. else
  4927. {
  4928. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4929. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4930. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4931. {
  4932. expInfo.delivery_memo = "发货成功";
  4933. expInfo.state = "发货成功";
  4934. expInfo.isMultiDelivery = 1;
  4935. expInfo.Update();
  4936. commonHelper.UpdateRelationOrder(ctid);
  4937. CeErpSukuraData.createInfo(ctid, 4);
  4938. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4939. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4940. }
  4941. else
  4942. {
  4943. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4944. expInfo.state = "异常";
  4945. expInfo.Update();
  4946. }
  4947. }
  4948. }
  4949. }
  4950. }
  4951. returnSuccessMsg("操作完成");
  4952. }
  4953. public void reset_erp_memoopt()
  4954. {
  4955. if (UrlPostParmsCheck("ctid"))
  4956. {
  4957. string eid = GetPostString("ctid");
  4958. CeErpTradeCell entity = null;
  4959. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4960. if (entity != null)
  4961. {
  4962. string stropt = "";
  4963. if (entity.MemoOpt == 1)
  4964. {
  4965. stropt = "“改稿”";
  4966. }
  4967. else if (entity.MemoOpt == 2)
  4968. {
  4969. stropt = "“定稿”";
  4970. }
  4971. else if (entity.MemoOpt == 3)
  4972. {
  4973. stropt = "“完成查货”";
  4974. CeErpSukuraData.createInfo(entity.ctid, 6);
  4975. }
  4976. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4977. entity.UpdateTime = DateTime.Now;
  4978. entity.MemoOpt = 0;
  4979. entity.Update();
  4980. returnSuccessMsg("操作成功!");
  4981. return;
  4982. }
  4983. returnErrorMsg("找不到记录");
  4984. }
  4985. }
  4986. public void get_erp_deliveryunusual()
  4987. {
  4988. DataStruct dStruct = GetPostStruct();
  4989. List<string> lw = new List<string>();
  4990. string tid = GetPostString("ctid");
  4991. if (tid.Length > 0)
  4992. {
  4993. string select_tid = getTidByCtid(tid);
  4994. lw.Add(string.Format("tid='{0}'", select_tid));
  4995. }
  4996. string shopname = GetPostString("shopname");
  4997. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4998. string buyernick = GetPostString("buyer_nick");
  4999. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5000. string customer = GetPostString("customer");
  5001. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5002. string design = GetPostString("design");
  5003. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5004. string sellermemo = GetPostString("seller_memo");
  5005. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5006. string supplier = GetPostString("supplier");
  5007. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5008. string date1 = GetPostString("date1");
  5009. string date2 = GetPostString("date2");
  5010. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5011. if (dw.Length > 0) lw.Add(dw);
  5012. string placedate1 = GetPostString("placedate1");
  5013. string placedate2 = GetPostString("placedate2");
  5014. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5015. if (dw_place.Length > 0) lw.Add(dw_place);
  5016. string price1 = GetPostString("price1");
  5017. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5018. string price2 = GetPostString("price2");
  5019. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5020. string unusualCon = GetPostString("unusualcon");
  5021. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  5022. string posTag = CurrentUser.UserPost.Post.Code;
  5023. if (posTag == "Supplier")
  5024. {
  5025. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5026. }
  5027. lw.Add(string.Format("OrderState = 6"));
  5028. lw.Add(string.Format("UnusualTag = 5"));
  5029. lw.Add(string.Format("IsRefund<={0}", 1));
  5030. dStruct.Order = "FinishPlaceTime desc";
  5031. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5032. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5033. writeGridDataTableJson(dStruct.TotalCount, dt);
  5034. }
  5035. public void get_erp_deliveryedlist()
  5036. {
  5037. DataStruct dStruct = GetPostStruct();
  5038. List<string> lw = new List<string>();
  5039. string tid = GetPostString("ctid");
  5040. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5041. string shopname = GetPostString("shopname");
  5042. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5043. string buyernick = GetPostString("buyer_nick");
  5044. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5045. string customer = GetPostString("customer");
  5046. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5047. string design = GetPostString("design");
  5048. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5049. string sellermemo = GetPostString("seller_memo");
  5050. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5051. string logistics = GetPostString("logistics");
  5052. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5053. string date1 = GetPostString("date1");
  5054. string date2 = GetPostString("date2");
  5055. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5056. //if (dw.Length > 0) lw.Add(dw);
  5057. string placedate1 = GetPostString("placedate1");
  5058. string placedate2 = GetPostString("placedate2");
  5059. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5060. if (fdw.Length > 0) lw.Add(fdw);
  5061. string devdate1 = GetPostString("deliverydate1");
  5062. string devdate2 = GetPostString("deliverydate2");
  5063. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5064. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5065. string price1 = GetPostString("price1");
  5066. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5067. string price2 = GetPostString("price2");
  5068. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5069. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5070. {
  5071. if (tid.Length > 0)
  5072. {
  5073. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5074. if (tid.Length > 5)
  5075. {
  5076. List<string> tids = getTidByCtidLike(tid);
  5077. if (tids.Count > 0 && tids.Count < 10)
  5078. {
  5079. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5080. }
  5081. }
  5082. lw.Add(tid_sql);
  5083. }
  5084. if (buyernick.Length > 0)
  5085. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5086. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5087. if (dw.Length > 0) lw.Add(dw);
  5088. }
  5089. else
  5090. {
  5091. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5092. }
  5093. string posTag = CurrentUser.UserPost.Post.Code;
  5094. if (posTag == "Supplier")
  5095. {
  5096. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5097. }
  5098. else
  5099. {
  5100. string supplier = GetPostString("supplier");
  5101. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5102. }
  5103. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5104. lw.Add(string.Format("type != 'PDD' "));
  5105. lw.Add(string.Format("IsRefund!={0}", 2));
  5106. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5107. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5108. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5109. /*if (tid.Length > 0)
  5110. {
  5111. List<string> tids = new List<string>();
  5112. if (dt != null && dt.Rows.Count > 0)
  5113. {
  5114. foreach (DataRow item in dt.Rows)
  5115. {
  5116. tids.Add("'" + item["tid"] + "'");
  5117. }
  5118. }
  5119. if (tids.Count > 0)
  5120. {
  5121. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5122. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5123. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5124. dt = WebCache.GetData("view_erptradecell", dStruct);
  5125. }
  5126. }*/
  5127. if (dt != null)
  5128. {
  5129. foreach (DataRow dr in dt.Rows)
  5130. {
  5131. 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();
  5132. }
  5133. }
  5134. writeGridDataTableJson(dStruct.TotalCount, dt);
  5135. }
  5136. public void get_erp_pdddeliveryed()
  5137. {
  5138. DataStruct dStruct = GetPostStruct();
  5139. List<string> lw = new List<string>();
  5140. string tid = GetPostString("ctid");
  5141. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5142. string shopname = GetPostString("shopname");
  5143. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5144. string buyernick = GetPostString("buyer_nick");
  5145. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5146. string customer = GetPostString("customer");
  5147. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5148. string design = GetPostString("design");
  5149. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5150. string sellermemo = GetPostString("seller_memo");
  5151. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5152. string logistics = GetPostString("logistics");
  5153. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5154. string date1 = GetPostString("date1");
  5155. string date2 = GetPostString("date2");
  5156. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5157. //if (dw.Length > 0) lw.Add(dw);
  5158. string placedate1 = GetPostString("placedate1");
  5159. string placedate2 = GetPostString("placedate2");
  5160. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5161. if (fdw.Length > 0) lw.Add(fdw);
  5162. string devdate1 = GetPostString("deliverydate1");
  5163. string devdate2 = GetPostString("deliverydate2");
  5164. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5165. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5166. string price1 = GetPostString("price1");
  5167. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5168. string price2 = GetPostString("price2");
  5169. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5170. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5171. {
  5172. if (tid.Length > 0)
  5173. {
  5174. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5175. if (tid.Length > 5)
  5176. {
  5177. List<string> tids = getTidByCtidLike(tid);
  5178. if (tids.Count > 0 && tids.Count < 10)
  5179. {
  5180. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5181. }
  5182. }
  5183. lw.Add(tid_sql);
  5184. }
  5185. if (buyernick.Length > 0)
  5186. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5187. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5188. if (dw.Length > 0) lw.Add(dw);
  5189. }
  5190. else
  5191. {
  5192. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5193. }
  5194. string posTag = CurrentUser.UserPost.Post.Code;
  5195. if (posTag == "Supplier")
  5196. {
  5197. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5198. }
  5199. else
  5200. {
  5201. string supplier = GetPostString("supplier");
  5202. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5203. }
  5204. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5205. lw.Add(string.Format("type = 'PDD' "));
  5206. lw.Add(string.Format("IsRefund!={0}", 2));
  5207. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5208. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5209. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5210. /* if (tid.Length > 0)
  5211. {
  5212. List<string> tids = new List<string>();
  5213. if (dt != null && dt.Rows.Count > 0)
  5214. {
  5215. foreach (DataRow item in dt.Rows)
  5216. {
  5217. tids.Add("'" + item["tid"] + "'");
  5218. }
  5219. }
  5220. if (tids.Count > 0)
  5221. {
  5222. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5223. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5224. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5225. dt = WebCache.GetData("view_erptradecell", dStruct);
  5226. }
  5227. }*/
  5228. foreach (DataRow dr in dt.Rows)
  5229. {
  5230. 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();
  5231. }
  5232. writeGridDataTableJson(dStruct.TotalCount, dt);
  5233. }
  5234. public void get_erp_jddeliveryed()
  5235. {
  5236. DataStruct dStruct = GetPostStruct();
  5237. List<string> lw = new List<string>();
  5238. string tid = GetPostString("ctid");
  5239. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5240. string shopname = GetPostString("shopname");
  5241. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5242. string buyernick = GetPostString("buyer_nick");
  5243. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5244. string customer = GetPostString("customer");
  5245. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5246. string design = GetPostString("design");
  5247. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5248. string sellermemo = GetPostString("seller_memo");
  5249. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5250. string date1 = GetPostString("date1");
  5251. string date2 = GetPostString("date2");
  5252. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5253. //if (dw.Length > 0) lw.Add(dw);
  5254. string placedate1 = GetPostString("placedate1");
  5255. string placedate2 = GetPostString("placedate2");
  5256. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5257. if (fdw.Length > 0) lw.Add(fdw);
  5258. string devdate1 = GetPostString("deliverydate1");
  5259. string devdate2 = GetPostString("deliverydate2");
  5260. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5261. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5262. string price1 = GetPostString("price1");
  5263. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5264. string price2 = GetPostString("price2");
  5265. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5266. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5267. {
  5268. if (tid.Length > 0)
  5269. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5270. if (buyernick.Length > 0)
  5271. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5272. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5273. if (dw.Length > 0) lw.Add(dw);
  5274. }
  5275. else
  5276. {
  5277. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5278. }
  5279. string posTag = CurrentUser.UserPost.Post.Code;
  5280. if (posTag == "Supplier")
  5281. {
  5282. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5283. }
  5284. else
  5285. {
  5286. string supplier = GetPostString("supplier");
  5287. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5288. }
  5289. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5290. lw.Add(string.Format("type = 'JD' "));
  5291. lw.Add(string.Format("IsRefund!={0}", 2));
  5292. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5293. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5294. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5295. foreach (DataRow dr in dt.Rows)
  5296. {
  5297. 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();
  5298. }
  5299. writeGridDataTableJson(dStruct.TotalCount, dt);
  5300. }
  5301. public void get_erp_allplacelist()
  5302. {
  5303. DataStruct dStruct = GetPostStruct();
  5304. List<string> lw = new List<string>();
  5305. string tid = GetPostString("ctid");
  5306. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5307. string shopname = GetPostString("shopname");
  5308. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5309. string buyernick = GetPostString("buyer_nick");
  5310. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5311. string customer = GetPostString("customer");
  5312. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5313. string design = GetPostString("design");
  5314. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5315. string sellermemo = GetPostString("seller_memo");
  5316. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5317. string supplier = GetPostString("supplier");
  5318. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5319. string date1 = GetPostString("date1");
  5320. string date2 = GetPostString("date2");
  5321. string pldate1 = GetPostString("placedate1");
  5322. string pldate2 = GetPostString("placedate2");
  5323. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5324. //if (dw.Length > 0) lw.Add(dw);
  5325. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5326. {
  5327. if (tid.Length > 0)
  5328. {
  5329. string select_tid = getTidByCtid(tid);
  5330. lw.Add(string.Format("tid='{0}'", select_tid));
  5331. }
  5332. if (buyernick.Length > 0)
  5333. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5334. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5335. if (dw.Length > 0) lw.Add(dw);
  5336. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5337. if (dw_place.Length > 0) lw.Add(dw_place);
  5338. }
  5339. else
  5340. {
  5341. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5342. {
  5343. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5344. }
  5345. }
  5346. string price1 = GetPostString("price1");
  5347. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5348. string price2 = GetPostString("price2");
  5349. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5350. string posTag = CurrentUser.UserPost.Post.Code;
  5351. if (posTag == "Supplier")
  5352. {
  5353. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5354. }
  5355. lw.Add(string.Format("OrderState >= 6"));
  5356. lw.Add(string.Format("IsSample != 2 "));
  5357. //lw.Add(string.Format("isDianziOrder = 0 "));
  5358. lw.Add(string.Format("SupplierId > 0 "));
  5359. //lw.Add(string.Format("IsRefund<={0}", 1));
  5360. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5361. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5362. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5363. foreach (DataRow dr in dt.Rows)
  5364. {
  5365. 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();
  5366. }
  5367. writeGridDataTableJson(dStruct.TotalCount, dt);
  5368. }
  5369. public void get_erp_financeallplacelist()
  5370. {
  5371. DataStruct dStruct = GetPostStruct();
  5372. List<string> lw = new List<string>();
  5373. string tid = GetPostString("ctid");
  5374. string shopname = GetPostString("shopname");
  5375. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5376. string buyernick = GetPostString("buyer_nick");
  5377. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5378. string customer = GetPostString("customer");
  5379. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5380. string design = GetPostString("design");
  5381. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5382. string sellermemo = GetPostString("seller_memo");
  5383. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5384. string supplier = GetPostString("supplier");
  5385. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5386. string date1 = GetPostString("date1");
  5387. string date2 = GetPostString("date2");
  5388. string pldate1 = GetPostString("placedate1");
  5389. string pldate2 = GetPostString("placedate2");
  5390. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5391. {
  5392. if (tid.Length > 0)
  5393. {
  5394. string select_tid = getTidByCtid(tid);
  5395. lw.Add(string.Format("tid='{0}'", select_tid));
  5396. }
  5397. if (buyernick.Length > 0)
  5398. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5399. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5400. if (dw.Length > 0) lw.Add(dw);
  5401. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5402. if (dw_place.Length > 0) lw.Add(dw_place);
  5403. }
  5404. else
  5405. {
  5406. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5407. {
  5408. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5409. }
  5410. }
  5411. string price1 = GetPostString("price1");
  5412. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5413. string price2 = GetPostString("price2");
  5414. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5415. string posTag = CurrentUser.UserPost.Post.Code;
  5416. if (posTag == "Supplier")
  5417. {
  5418. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5419. }
  5420. //lw.Add(string.Format("OrderState >= 6"));
  5421. lw.Add(string.Format("IsSample != 2 "));
  5422. lw.Add(string.Format("isDianziOrder = 0 "));
  5423. //lw.Add(string.Format("IsRefund<={0}", 1));
  5424. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5425. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5426. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5427. foreach (DataRow dr in dt.Rows)
  5428. {
  5429. 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();
  5430. }
  5431. writeGridDataTableJson(dStruct.TotalCount, dt);
  5432. }
  5433. public void get_erp_expresslist()
  5434. {
  5435. int listtype = GetInt("ltype");
  5436. DataStruct dStruct = GetPostStruct();
  5437. List<string> lw = new List<string>();
  5438. string tid = GetPostString("tid");
  5439. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5440. string outsid = GetPostString("out_sid");
  5441. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5442. string importer = GetPostString("ImportUserName");
  5443. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5444. string file = GetPostString("import_file");
  5445. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5446. string printman = GetPostString("printman");
  5447. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5448. string date1 = GetPostString("date1");
  5449. string date2 = GetPostString("date2");
  5450. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5451. if (dw.Length > 0) lw.Add(dw);
  5452. string fdate1 = GetPostString("finishdate1");
  5453. string fdate2 = GetPostString("finishdate2");
  5454. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5455. if (fdw.Length > 0) lw.Add(fdw);
  5456. string supplierId = GetPostString("supplierId");
  5457. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5458. if (listtype == 1)
  5459. {
  5460. lw.Add(string.Format("importUserId !=0"));
  5461. }
  5462. string posTag = CurrentUser.UserPost.Post.Code;
  5463. if (posTag == "Supplier")
  5464. {
  5465. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5466. }
  5467. if (dStruct.PageSize != 100000)
  5468. {
  5469. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5470. }
  5471. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5472. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5473. writeGridDataTableJson(dStruct.TotalCount, dt);
  5474. }
  5475. public void set_erp_buchaorderdelivery()
  5476. {
  5477. if (UrlPostParmsCheck("ctid"))
  5478. {
  5479. string eid = GetPostString("ctid");
  5480. CeErpTradeCell entity = null;
  5481. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5482. if (entity != null)
  5483. {
  5484. if (entity.IsSample != 2)
  5485. {
  5486. returnErrorMsg("补差价单才能标记为已发货");
  5487. return;
  5488. }
  5489. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5490. entity.OrderState = 7;
  5491. entity.Update();
  5492. returnSuccessMsg("操作成功!");
  5493. return;
  5494. }
  5495. returnErrorMsg("找不到记录");
  5496. }
  5497. }
  5498. public void get_stdtemplates()
  5499. {
  5500. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5501. //string res = taobaoHelper.test();
  5502. string res = apiHelper.API_PrintTemplate();
  5503. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5504. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5505. {
  5506. int sidx = res.IndexOf("error_code");
  5507. int eidx = res.IndexOf("success");
  5508. string msg = res.Substring(sidx, eidx - sidx);
  5509. returnErrorMsg(msg);
  5510. return;
  5511. }
  5512. if (res.Length <= 0)
  5513. {
  5514. returnErrorMsg("模板数据为空!");
  5515. return;
  5516. }
  5517. ReturnSuccess(res);
  5518. }
  5519. public void cancel_print_order()
  5520. {
  5521. if (UrlPostParmsCheck("ctid"))
  5522. {
  5523. string ctid = GetPostString("ctid");
  5524. CeErpTradeCell entity = null;
  5525. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5526. if (entity != null)
  5527. {
  5528. string res = "";
  5529. string code = entity.LastBillWaybillCode;
  5530. if (code == "")
  5531. {
  5532. code = entity.OutSid;
  5533. }
  5534. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5535. XLog.SaveLog(0, "取消面单" + res);
  5536. }
  5537. }
  5538. }
  5539. public void set_erp_printwaybill()
  5540. {
  5541. if (UrlPostParmsCheck("ctid"))
  5542. {
  5543. string ctid = GetPostString("ctid");
  5544. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5545. string cpName = GetPostString("cpname");
  5546. string isTogether = GetPostString("together");
  5547. string printType = GetPostString("printType");
  5548. //var res_obj = new
  5549. //{
  5550. // restype = 1,
  5551. // 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\"}"
  5552. //};
  5553. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5554. //ReturnSuccess(ro_json);
  5555. //return;
  5556. bool isUseLastWayBillCode = false;
  5557. CeErpTradeCell entity = null;
  5558. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5559. if (entity != null)
  5560. {
  5561. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5562. {
  5563. isUseLastWayBillCode = true;
  5564. }
  5565. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5566. {
  5567. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5568. return;
  5569. }
  5570. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5571. {
  5572. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5573. return;
  5574. }
  5575. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5576. {
  5577. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5578. return;
  5579. }
  5580. }
  5581. string res = "";
  5582. Api_waybill_code_response_Obj fullObj = null;
  5583. string pData_str = "";
  5584. string curUseWayBillCode = "";
  5585. if (isUseLastWayBillCode == false)
  5586. {
  5587. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5588. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5589. if (res.IndexOf("failure") != -1)
  5590. {
  5591. //int idx = res.IndexOf("sub_message");
  5592. //int idx2 = res.IndexOf("flag");
  5593. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5594. string errMsgNeed = commonHelper.KeepChinese(res);
  5595. var res_objd = new
  5596. {
  5597. restype = 0,
  5598. data = "获取面单失败" + errMsgNeed
  5599. };
  5600. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5601. returnSuccess(ro_jsond);
  5602. if (res.IndexOf("停发") != -1)
  5603. {
  5604. entity.UnusualCon = "物流停发";
  5605. entity.Update();
  5606. }
  5607. //returnErrorMsg("获取面单失败,"+emsg);
  5608. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5609. return;
  5610. }
  5611. else if (res.IndexOf("errorMsg") != -1)
  5612. {
  5613. //int idx = res.IndexOf("errorMsg");
  5614. //int idx2 = res.IndexOf("}]}");
  5615. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5616. string errMsgNeed = commonHelper.KeepChinese(res);
  5617. var res_objf = new
  5618. {
  5619. restype = 0,
  5620. data = "获取面单失败2" + errMsgNeed
  5621. };
  5622. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5623. if (res.IndexOf("停发") != -1)
  5624. {
  5625. entity.UnusualCon = "物流停发";
  5626. entity.Update();
  5627. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5628. if (trade != null)
  5629. {
  5630. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5631. }
  5632. }
  5633. returnSuccess(ro_jsonf);
  5634. //returnErrorMsg("获取面单失败," + emsg);
  5635. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5636. return;
  5637. }
  5638. try
  5639. {
  5640. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5641. //res = res.Replace(" ", "");
  5642. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5643. }
  5644. catch (Exception ex)
  5645. {
  5646. XLog.SaveLog(0, "生成fullObj" + res);
  5647. var res_objf = new
  5648. {
  5649. restype = 0,
  5650. data = "生成fullObj发生错误" + ex.Message
  5651. };
  5652. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5653. returnSuccess(ro_jsonf);
  5654. return;
  5655. }
  5656. if (fullObj.response.data.content.Count > 0)
  5657. {
  5658. ContentItem codeObj = fullObj.response.data.content[0];
  5659. if (cpCode.IndexOf("SFFQ-") != -1)
  5660. {
  5661. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5662. }
  5663. else
  5664. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5665. curUseWayBillCode = codeObj.waybillCode;
  5666. }
  5667. else
  5668. {
  5669. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5670. var res_objf = new
  5671. {
  5672. restype = 0,
  5673. data = "生成fullObj找不到快递单号waybillCode"
  5674. };
  5675. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5676. returnSuccess(ro_jsonf);
  5677. return;
  5678. }
  5679. }
  5680. else
  5681. {
  5682. //使用上次打印的快递单号
  5683. if (cpCode == "SFFQ-LY")
  5684. {
  5685. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5686. }
  5687. else
  5688. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5689. curUseWayBillCode = entity.LastBillWaybillCode;
  5690. }
  5691. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5692. {
  5693. var res_obje = new
  5694. {
  5695. restype = 0,
  5696. data = "获取加密打印数据失败"
  5697. };
  5698. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5699. returnSuccess(ro_jsone);
  5700. entity.LastBillCpCode = cpCode;
  5701. entity.LastBillWaybillCode = curUseWayBillCode;
  5702. entity.Update();
  5703. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5704. //returnErrorMsg("获取加密打印数据失败");
  5705. return;
  5706. }
  5707. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5708. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5709. string btnType = "";
  5710. string errorMsg = "";
  5711. if (entity != null)
  5712. {
  5713. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5714. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5715. //cpcode是 YTO-CAINIAO
  5716. //string comCode = cpCode.Split('-')[0].ToString();
  5717. string apires = "";
  5718. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5719. //isTogether=2是新的合包弹窗
  5720. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5721. {
  5722. if (ctid.IndexOf("N") != -1)
  5723. {
  5724. apires = "发货成功";
  5725. }
  5726. else
  5727. {
  5728. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5729. }
  5730. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5731. //打单后发货
  5732. StringBuilder sql = new StringBuilder();
  5733. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5734. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5735. {
  5736. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5737. }
  5738. else
  5739. {
  5740. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5741. }
  5742. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5743. foreach (DataRow row in dt.Rows)
  5744. {
  5745. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5746. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5747. {
  5748. try
  5749. {
  5750. btnType = "待发货";
  5751. entity.OutSid = curUseWayBillCode;
  5752. entity.OrderState = 7;
  5753. entity.IsUrgency = false;
  5754. entity.LastBillCpCode = "";
  5755. entity.LastBillWaybillCode = "";
  5756. entity.FinishDeliveryTime = DateTime.Now;
  5757. entity.IsReturn = 0;
  5758. entity.MemoOpt = 0;
  5759. entity.UpdateTime = DateTime.Now;
  5760. entity.Update();
  5761. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5762. //还要插入快递信息到 快递信息表
  5763. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5764. exinfo.tid = entity.ctid;
  5765. exinfo.out_sid = curUseWayBillCode;
  5766. exinfo.company_code = cpCode;
  5767. exinfo.company_name = cpName;
  5768. exinfo.supplierUserName = supplierName;
  5769. exinfo.deliveryType = "发货成功";
  5770. exinfo.print_time = DateTime.Now;
  5771. exinfo.printUser = CurrentUser.UserName;
  5772. exinfo.postData = pData_str;
  5773. exinfo.Create();
  5774. commonHelper.UpdateRelationOrder(entity.ctid);
  5775. CeErpSukuraData.createInfo(ctid, 4);
  5776. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5777. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5778. {
  5779. commonHelper.sendCytExpress(exinfo);
  5780. }
  5781. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5782. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5783. }
  5784. catch (Exception ex)
  5785. {
  5786. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5787. }
  5788. }
  5789. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5790. {
  5791. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5792. if (entity.OrderState == 6)
  5793. {
  5794. entity.OrderState = 7;
  5795. }
  5796. entity.UpdateTime = DateTime.Now;
  5797. entity.FinishDeliveryTime = DateTime.Now;
  5798. btnType = "已发货";
  5799. entity.Update();
  5800. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5801. exinfo.tid = entity.ctid;
  5802. exinfo.out_sid = curUseWayBillCode;
  5803. exinfo.company_code = cpCode;
  5804. exinfo.company_name = cpName;
  5805. exinfo.supplierUserName = supplierName;
  5806. exinfo.deliveryType = "发货成功";
  5807. exinfo.print_time = DateTime.Now;
  5808. exinfo.printUser = CurrentUser.UserName;
  5809. exinfo.postData = pData_str;
  5810. exinfo.Create();
  5811. commonHelper.UpdateRelationOrder(entity.ctid);
  5812. CeErpSukuraData.createInfo(entity.ctid, 4);
  5813. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5814. {
  5815. commonHelper.sendCytExpress(exinfo);
  5816. }
  5817. //不处理
  5818. }
  5819. else
  5820. {
  5821. entity.UpdateTime = DateTime.Now;
  5822. entity.LastBillCpCode = cpCode;
  5823. entity.LastBillWaybillCode = curUseWayBillCode;
  5824. entity.Update();
  5825. string errmsg = commonHelper.KeepChinese(apires);
  5826. var res_objz = new
  5827. {
  5828. restype = 0,
  5829. data = "打单后发货失败"
  5830. };
  5831. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5832. returnSuccess(ro_jsonz);
  5833. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5834. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5835. return;
  5836. }
  5837. }
  5838. }
  5839. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5840. {
  5841. string ctids = GetPostString("ctids");
  5842. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5843. List<string> list = new List<string>();
  5844. List<string> send_list = new List<string>();
  5845. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5846. CeErpTrade ceErpTrade = new CeErpTrade();
  5847. //可合包的合并一起发货
  5848. if (dt == null && string.IsNullOrEmpty(ctids))
  5849. {
  5850. var res_objz = new
  5851. {
  5852. restype = 0,
  5853. data = "打单后发货失败"
  5854. };
  5855. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5856. returnSuccess(ro_jsonz);
  5857. return;
  5858. }
  5859. if (!string.IsNullOrEmpty(ctids))
  5860. {
  5861. StringBuilder sql = new StringBuilder();
  5862. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5863. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5864. }
  5865. foreach (DataRow row in dt.Rows)
  5866. {
  5867. list.Add("'" + row["ctid"] + "'");
  5868. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5869. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5870. if (ctid.IndexOf("N") != -1)
  5871. {
  5872. apires = "发货成功";
  5873. }
  5874. else
  5875. {
  5876. if (!send_list.Contains(ceErpTrade.tid))
  5877. {
  5878. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5879. }
  5880. else
  5881. {
  5882. apires = "发货成功";
  5883. }
  5884. }
  5885. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5886. {
  5887. send_list.Add(ceErpTrade.tid);
  5888. try
  5889. {
  5890. btnType = "待发货";
  5891. ceErpTradeCell.OutSid = curUseWayBillCode;
  5892. ceErpTradeCell.OrderState = 7;
  5893. ceErpTradeCell.IsUrgency = false;
  5894. ceErpTradeCell.LastBillCpCode = "";
  5895. ceErpTradeCell.LastBillWaybillCode = "";
  5896. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5897. ceErpTradeCell.IsReturn = 0;
  5898. ceErpTradeCell.MemoOpt = 0;
  5899. ceErpTradeCell.UpdateTime = DateTime.Now;
  5900. ceErpTradeCell.Update();
  5901. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5902. //还要插入快递信息到 快递信息表
  5903. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5904. exinfo.tid = ceErpTradeCell.ctid;
  5905. exinfo.out_sid = curUseWayBillCode;
  5906. exinfo.company_code = cpCode;
  5907. exinfo.company_name = cpName;
  5908. exinfo.supplierUserName = supplierName;
  5909. exinfo.deliveryType = "发货成功";
  5910. exinfo.print_time = DateTime.Now;
  5911. exinfo.printUser = CurrentUser.UserName;
  5912. exinfo.postData = pData_str;
  5913. exinfo.Create();
  5914. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5915. CeErpSukuraData.createInfo(ctid, 4);
  5916. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5917. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80 || entity.SupplierId == 126)
  5918. {
  5919. commonHelper.sendCytExpress(exinfo);
  5920. }
  5921. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5922. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5923. }
  5924. catch (Exception ex)
  5925. {
  5926. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5927. }
  5928. }
  5929. else
  5930. {
  5931. ceErpTradeCell.UpdateTime = DateTime.Now;
  5932. ceErpTradeCell.LastBillCpCode = cpCode;
  5933. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5934. ceErpTradeCell.Update();
  5935. string errmsg = commonHelper.KeepChinese(apires);
  5936. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5937. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5938. }
  5939. }
  5940. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5941. }
  5942. }
  5943. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5944. var res_obj = new
  5945. {
  5946. restype = 1,
  5947. data = pData_str,
  5948. errorMsg
  5949. };
  5950. string ro_json = JsonConvert.SerializeObject(res_obj);
  5951. ReturnSuccess(ro_json);
  5952. return;
  5953. }
  5954. }
  5955. private string GetUTF8String(byte[] vs)
  5956. {
  5957. throw new NotImplementedException();
  5958. }
  5959. public void set_erp_printwaybill_cn()
  5960. {
  5961. if (UrlPostParmsCheck("ctid"))
  5962. {
  5963. string ctid = GetPostString("ctid");
  5964. string cpCode = GetPostString("cpcode");
  5965. string cpName = GetPostString("cpname");
  5966. string tempUrl = GetPostString("tempurl");
  5967. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5968. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5969. //string res = taobaoHelper.test();
  5970. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5971. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5972. {
  5973. int sidx = res.IndexOf("errorMsg");
  5974. int eidx = res.IndexOf("}");
  5975. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5976. var res_objzxx = new
  5977. {
  5978. restype = 0,
  5979. data = msg
  5980. };
  5981. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5982. returnSuccess(ro_jsonzxx);
  5983. //returnErrorMsg(msg);
  5984. return;
  5985. }
  5986. int idx = res.IndexOf("waybillCode");
  5987. int idx2 = res.IndexOf("printData");
  5988. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5989. string eid = GetPostString("ctid");
  5990. CeErpTradeCell entity = null;
  5991. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5992. if (entity != null)
  5993. {
  5994. string osid = entity.OutSid;
  5995. entity.OutSid = osid + "," + outsid;
  5996. entity.FinishDeliveryTime = DateTime.Now;
  5997. entity.OrderState = 7;
  5998. entity.UpdateTime = DateTime.Now;
  5999. entity.IsReturn = 0;
  6000. entity.Update();
  6001. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6002. exinfo.tid = entity.ctid;
  6003. exinfo.out_sid = outsid;
  6004. exinfo.company_code = cpCode;
  6005. exinfo.company_name = cpName;
  6006. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  6007. exinfo.deliveryType = "发货成功";
  6008. exinfo.print_time = DateTime.Now;
  6009. exinfo.printUser = CurrentUser.UserName;
  6010. exinfo.Create();
  6011. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  6012. {
  6013. commonHelper.sendCytExpress(exinfo);
  6014. }
  6015. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6016. }
  6017. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  6018. var res_objz = new
  6019. {
  6020. restype = 1,
  6021. data = res
  6022. };
  6023. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6024. returnSuccess(ro_jsonz);
  6025. //ReturnSuccess(res);
  6026. }
  6027. }
  6028. ////打单,打印面单 获取面单号
  6029. //public void set_erp_printwaybill()
  6030. //{
  6031. // if (UrlPostParmsCheck("ctid"))
  6032. // {
  6033. // string ctid = GetPostString("ctid");
  6034. // string cpCode = GetPostString("cpcode");
  6035. // string tempUrl = GetPostString("tempurl");
  6036. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6037. // //string res = taobaoHelper.test();
  6038. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6039. // if (res.IndexOf("error_response") != -1)
  6040. // {
  6041. // int sidx = res.IndexOf("sub_msg");
  6042. // int eidx = res.IndexOf("request_id");
  6043. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6044. // returnErrorMsg(msg);
  6045. // return;
  6046. // }
  6047. // int idx = res.IndexOf("waybill_code");
  6048. // int idx2 = res.IndexOf("}]}");
  6049. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6050. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6051. // ReturnSuccess(res);
  6052. // }
  6053. //}
  6054. public void cancel_erp_aftersale()
  6055. {
  6056. if (UrlPostParmsCheck("ctid"))
  6057. {
  6058. string eid = GetPostString("ctid");
  6059. CeErpTradeCell entity = null;
  6060. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6061. if (entity != null)
  6062. {
  6063. //有过处理的售后,取消也不能删除 售 字,保留
  6064. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6065. {
  6066. entity.AfterSaleState = 4;
  6067. }
  6068. else
  6069. entity.AfterSaleState = 0;
  6070. entity.UpdateTime = DateTime.Now;
  6071. entity.Update();
  6072. returnSuccessMsg("操作成功!");
  6073. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6074. return;
  6075. }
  6076. returnErrorMsg("找不到订单记录");
  6077. }
  6078. }
  6079. public void get_erp_aftersalelist()
  6080. {
  6081. DataStruct dStruct = GetPostStruct();
  6082. List<string> lw = new List<string>();
  6083. int st = GetInt("st");
  6084. string tid = GetPostString("ctid");
  6085. if (st == 3)
  6086. {
  6087. if (tid.Length > 0)
  6088. {
  6089. string select_tid = getTidByCtid(tid);
  6090. lw.Add(string.Format("tid='{0}'", select_tid));
  6091. }
  6092. }
  6093. else
  6094. {
  6095. if (tid.Length > 0)
  6096. {
  6097. string select_tid = getTidByCtid(tid);
  6098. lw.Add(string.Format("tid='{0}'", select_tid));
  6099. }
  6100. }
  6101. string shopname = GetPostString("shopname");
  6102. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6103. string buyernick = GetPostString("buyer_nick");
  6104. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6105. string sellermemo = GetPostString("seller_memo");
  6106. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6107. string orderState = GetPostString("orderState");
  6108. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6109. string afterState = GetPostString("afterstate");
  6110. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6111. string date1 = GetPostString("date1");
  6112. string date2 = GetPostString("date2");
  6113. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6114. if (dw.Length > 0) lw.Add(dw);
  6115. string price1 = GetPostString("price1");
  6116. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6117. string price2 = GetPostString("price2");
  6118. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6119. //lw.Add(string.Format("IsRefund!={0}", 1));
  6120. string reason = GetPostString("reason");
  6121. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6122. string method = GetPostString("method");
  6123. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6124. string handler = GetPostString("handler");
  6125. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6126. string handledate1 = GetPostString("handledate1");
  6127. string handledate2 = GetPostString("handledate2");
  6128. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6129. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6130. string finish1 = GetPostString("finishdate1");
  6131. string finish2 = GetPostString("finishdate2");
  6132. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6133. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6134. string afterdate1 = GetPostString("afterdate1");
  6135. string afterdate2 = GetPostString("afterdate2");
  6136. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6137. if (afterDate.Length > 0) lw.Add(afterDate);
  6138. string supplier = GetPostString("supplier");
  6139. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6140. string responsible = GetPostString("responsibleman");
  6141. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6142. string customer = GetPostString("customer");
  6143. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6144. string design = GetPostString("design");
  6145. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6146. string afterMemoType = GetPostString("aftermemotype");
  6147. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6148. string posCode = CurrentUser.UserPost.Post.Code;
  6149. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6150. //{
  6151. // string vstate = GetPostString("vstate");
  6152. // if (vstate.Length > 0)
  6153. // {
  6154. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6155. // }
  6156. // if (posCode == "Supplier")
  6157. // {
  6158. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6159. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6160. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6161. // }
  6162. // else
  6163. // {
  6164. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6165. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6166. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6167. // {
  6168. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6169. // }
  6170. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6171. // {
  6172. // int orgid = CurrentUser.UserPost.OrgID;
  6173. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6174. // }
  6175. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6176. // {
  6177. // string shopid = CurrentUser.User.pemShop;
  6178. // lw.Add(string.Format("shopId in ({0})", shopid));
  6179. // }
  6180. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6181. // //{
  6182. // // int org_id = CurrentUser.UserPost.OrgID;
  6183. // // lw.Add(string.Format("OrgID={0}", org_id));
  6184. // //}
  6185. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6186. // }
  6187. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6188. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6189. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6190. //}
  6191. if (st == 5)
  6192. {
  6193. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6194. {
  6195. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6196. {
  6197. string shopid = CurrentUser.User.pemShop;
  6198. lw.Add(string.Format("shopId in ({0})", shopid));
  6199. }
  6200. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6201. {
  6202. int mrOrgid = CurrentUser.UserPost.OrgID;
  6203. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6204. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6205. }
  6206. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6207. //{
  6208. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6209. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6210. //}
  6211. else
  6212. {
  6213. string userIdStr = "";
  6214. if (posCode == "CustomerService")
  6215. {
  6216. userIdStr = CurrentUser.UserID + "_k";
  6217. }
  6218. else if (posCode == "Designer" || posCode == "wxDesigner")
  6219. {
  6220. userIdStr = CurrentUser.UserID + "_s";
  6221. }
  6222. else if (posCode == "Place")
  6223. {
  6224. userIdStr = CurrentUser.UserID + "_x";
  6225. }
  6226. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6227. }
  6228. }
  6229. string placedate1 = GetPostString("placedate1");
  6230. string placedate2 = GetPostString("placedate2");
  6231. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6232. if (dwplace.Length > 0) lw.Add(dwplace);
  6233. string supState = GetPostString("supState");
  6234. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6235. string searchType = GetPostString("searchType");
  6236. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6237. {
  6238. lw.Add(string.Format("BackNum>1"));
  6239. }
  6240. lw.Add(string.Format("AfterSaleState>0"));
  6241. if (ex_psize > 0)
  6242. {
  6243. if (CurrentUser.UserPost.Post.Code == "Finance")
  6244. dStruct.Order = "pay_time desc";
  6245. else
  6246. dStruct.Order = "HandleTime desc";
  6247. }
  6248. else
  6249. dStruct.Order = "HandleTime desc";
  6250. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6251. DataTable dt = WebCache.GetData("view_test", dStruct);
  6252. writeGridDataTableJson(dStruct.TotalCount, dt);
  6253. }
  6254. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6255. //{
  6256. // lw.Add(string.Format("AfterSaleState=4"));
  6257. // string code = CurrentUser.UserPost.Post.Code;
  6258. // if (code == "CustomerService")
  6259. // {
  6260. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6261. // }
  6262. // else if (code == "Designer" || code == "DesignerMr")
  6263. // {
  6264. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6265. // }
  6266. // else if (code == "Place" || code == "PlaceMr")
  6267. // {
  6268. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6269. // }
  6270. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6271. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6272. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6273. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6274. //}
  6275. //else //处理中的售后,待处理和处理中合并
  6276. //{
  6277. // if (afterState.Length <= 0)
  6278. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6279. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6280. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6281. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6282. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6283. //}
  6284. }
  6285. public void get_erp_disagreeftersalelist()
  6286. {
  6287. DataStruct dStruct = GetPostStruct();
  6288. List<string> lw = new List<string>();
  6289. int st = 2;
  6290. string tid = GetPostString("ctid");
  6291. if (tid.Length > 0)
  6292. {
  6293. string select_tid = getTidByCtid(tid);
  6294. lw.Add(string.Format("tid='{0}'", select_tid));
  6295. }
  6296. string shopname = GetPostString("shopname");
  6297. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6298. string buyernick = GetPostString("buyer_nick");
  6299. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6300. string sellermemo = GetPostString("seller_memo");
  6301. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6302. string orderState = GetPostString("orderState");
  6303. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6304. string afterState = GetPostString("afterstate");
  6305. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6306. string date1 = GetPostString("date1");
  6307. string date2 = GetPostString("date2");
  6308. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6309. if (dw.Length > 0) lw.Add(dw);
  6310. string price1 = GetPostString("price1");
  6311. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6312. string price2 = GetPostString("price2");
  6313. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6314. //lw.Add(string.Format("IsRefund!={0}", 1));
  6315. string reason = GetPostString("reason");
  6316. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6317. string method = GetPostString("method");
  6318. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6319. string handler = GetPostString("handler");
  6320. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6321. string handledate1 = GetPostString("handledate1");
  6322. string handledate2 = GetPostString("handledate2");
  6323. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6324. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6325. string afterdate1 = GetPostString("afterdate1");
  6326. string afterdate2 = GetPostString("afterdate2");
  6327. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6328. if (afterDate.Length > 0) lw.Add(afterDate);
  6329. string backdate1 = GetPostString("backdate1");
  6330. string backdate2 = GetPostString("backdate2");
  6331. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6332. if (backDate.Length > 0) lw.Add(backDate);
  6333. string supplier = GetPostString("supplier");
  6334. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6335. string responsible = GetPostString("responsibleman");
  6336. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6337. string customer = GetPostString("customer");
  6338. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6339. string design = GetPostString("design");
  6340. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6341. string afterSaleMemo = GetPostString("afterSaleMemo");
  6342. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6343. string afterMemoType = GetPostString("aftermemotype");
  6344. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6345. string aftersakereason = GetPostString("aftersakereason");
  6346. if (aftersakereason.Length > 0)
  6347. {
  6348. if (aftersakereason == "1")
  6349. {
  6350. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6351. }
  6352. if (aftersakereason == "2")
  6353. {
  6354. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6355. }
  6356. }
  6357. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6358. string poscode = CurrentUser.UserPost.Post.Code;
  6359. if (poscode != "SysAdmin")
  6360. {
  6361. string shopid = CurrentUser.User.pemShop;
  6362. lw.Add(string.Format("shopId in ({0})", shopid));
  6363. }
  6364. string searchType = GetPostString("searchType");
  6365. if (searchType == "wait")
  6366. {
  6367. lw.Add(string.Format("HandleTime is null"));
  6368. }
  6369. if (searchType == "handling")
  6370. {
  6371. lw.Add(string.Format("HandleTime is not null "));
  6372. }
  6373. if (searchType == "back" || searchType == "puBack")
  6374. {
  6375. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6376. }
  6377. if (searchType == "reBack")
  6378. {
  6379. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6380. }
  6381. if (searchType == "moreBack")
  6382. {
  6383. lw.Add(string.Format("backNum > 1"));
  6384. }
  6385. lw.Add(string.Format("(AfterSaleState=5)"));
  6386. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6387. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6388. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6389. writeGridDataTableJson(dStruct.TotalCount, dt);
  6390. }
  6391. public void get_erp_handlingaftersalelist()
  6392. {
  6393. DataStruct dStruct = GetPostStruct();
  6394. List<string> lw = new List<string>();
  6395. int st = 2;
  6396. string tid = GetPostString("ctid");
  6397. if (tid.Length > 0)
  6398. {
  6399. string select_tid = getTidByCtid(tid);
  6400. lw.Add(string.Format("tid='{0}'", select_tid));
  6401. }
  6402. string shopname = GetPostString("shopname");
  6403. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6404. string buyernick = GetPostString("buyer_nick");
  6405. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6406. string sellermemo = GetPostString("seller_memo");
  6407. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6408. string orderState = GetPostString("orderState");
  6409. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6410. string afterState = GetPostString("afterstate");
  6411. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6412. string date1 = GetPostString("date1");
  6413. string date2 = GetPostString("date2");
  6414. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6415. if (dw.Length > 0) lw.Add(dw);
  6416. string price1 = GetPostString("price1");
  6417. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6418. string price2 = GetPostString("price2");
  6419. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6420. //lw.Add(string.Format("IsRefund!={0}", 1));
  6421. string reason = GetPostString("reason");
  6422. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6423. string method = GetPostString("method");
  6424. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6425. string handler = GetPostString("handler");
  6426. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6427. string handledate1 = GetPostString("handledate1");
  6428. string handledate2 = GetPostString("handledate2");
  6429. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6430. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6431. string afterdate1 = GetPostString("afterdate1");
  6432. string afterdate2 = GetPostString("afterdate2");
  6433. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6434. if (afterDate.Length > 0) lw.Add(afterDate);
  6435. string supplier = GetPostString("supplier");
  6436. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6437. string responsible = GetPostString("responsibleman");
  6438. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6439. string customer = GetPostString("customer");
  6440. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6441. string design = GetPostString("design");
  6442. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6443. string afterSaleMemo = GetPostString("afterSaleMemo");
  6444. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6445. string afterMemoType = GetPostString("aftermemotype");
  6446. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6447. string afterresult = GetPostString("afterresult");
  6448. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6449. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6450. string poscode = CurrentUser.UserPost.Post.Code;
  6451. if (poscode != "SysAdmin")
  6452. {
  6453. string shopid = CurrentUser.User.pemShop;
  6454. lw.Add(string.Format("shopId in ({0})", shopid));
  6455. }
  6456. string searchType = GetPostString("searchType");
  6457. if (searchType == "wait")
  6458. {
  6459. lw.Add(string.Format("HandleTime is null"));
  6460. }
  6461. if (searchType == "documentary")
  6462. {
  6463. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6464. }
  6465. if (searchType == "handling")
  6466. {
  6467. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6468. }
  6469. if (searchType == "back" || searchType == "puBack")
  6470. {
  6471. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6472. }
  6473. if (searchType == "reBack")
  6474. {
  6475. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6476. }
  6477. if (afterState.Length <= 0)
  6478. {
  6479. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6480. }
  6481. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6482. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6483. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6484. writeGridDataTableJson(dStruct.TotalCount, dt);
  6485. }
  6486. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6487. //public void get_erp_back_handlingaftersalelist()
  6488. //{
  6489. // DataStruct dStruct = GetPostStruct();
  6490. // List<string> lw = new List<string>();
  6491. // string tid = GetPostString("ctid");
  6492. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6493. // string shopname = GetPostString("shopname");
  6494. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6495. // string buyernick = GetPostString("buyer_nick");
  6496. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6497. // string sellermemo = GetPostString("seller_memo");
  6498. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6499. // string orderState = GetPostString("orderState");
  6500. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6501. // string afterState = GetPostString("afterstate");
  6502. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6503. // string date1 = GetPostString("date1");
  6504. // string date2 = GetPostString("date2");
  6505. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6506. // if (dw.Length > 0) lw.Add(dw);
  6507. // string price1 = GetPostString("price1");
  6508. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6509. // string price2 = GetPostString("price2");
  6510. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6511. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6512. // string reason = GetPostString("reason");
  6513. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6514. // string method = GetPostString("method");
  6515. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6516. // string handler = GetPostString("handler");
  6517. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6518. // string handledate1 = GetPostString("handledate1");
  6519. // string handledate2 = GetPostString("handledate2");
  6520. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6521. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6522. // string afterdate1 = GetPostString("afterdate1");
  6523. // string afterdate2 = GetPostString("afterdate2");
  6524. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6525. // if (afterDate.Length > 0) lw.Add(afterDate);
  6526. // string supplier = GetPostString("supplier");
  6527. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6528. // string responsible = GetPostString("responsibleman");
  6529. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6530. // string customer = GetPostString("customer");
  6531. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6532. // string design = GetPostString("design");
  6533. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6534. // string afterMemoType = GetPostString("aftermemotype");
  6535. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6536. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6537. // if (afterState.Length <= 0)
  6538. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6539. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6540. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6541. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6542. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6543. //}
  6544. public void get_erp_aftersaleverifylist()
  6545. {
  6546. DataStruct dStruct = GetPostStruct();
  6547. List<string> lw = new List<string>();
  6548. string tid = GetPostString("ctid");
  6549. if (tid.Length > 0)
  6550. {
  6551. string select_tid = getTidByCtid(tid);
  6552. lw.Add(string.Format("otid='{0}'", select_tid));
  6553. }
  6554. string shopname = GetPostString("shopname");
  6555. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6556. string buyernick = GetPostString("buyer_nick");
  6557. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6558. string sellermemo = GetPostString("seller_memo");
  6559. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6560. string orderState = GetPostString("orderState");
  6561. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6562. //lw.Add(string.Format("IsRefund!={0}", 1));
  6563. string reason = GetPostString("reason");
  6564. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6565. string method = GetPostString("method");
  6566. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6567. string handler = GetPostString("handler");
  6568. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6569. string handledate1 = GetPostString("handledate1");
  6570. string handledate2 = GetPostString("handledate2");
  6571. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6572. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6573. string finish1 = GetPostString("finishdate1");
  6574. string finish2 = GetPostString("finishdate2");
  6575. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6576. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6577. string supplier = GetPostString("supplier");
  6578. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6579. string responsible = GetPostString("responsibleman");
  6580. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6581. string posCode = CurrentUser.UserPost.Post.Code;
  6582. string vstate = GetPostString("vstate");
  6583. if (vstate.Length > 0)
  6584. {
  6585. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6586. }
  6587. if (posCode == "Supplier")
  6588. {
  6589. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6590. lw.Add(string.Format("VerifyState = 0"));
  6591. lw.Add("type = 1");
  6592. lw.Add(string.Format("AfterSaleState={0}", 3));
  6593. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6594. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6595. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6596. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6597. writeGridDataTableJson(dStruct.TotalCount, dt);
  6598. }
  6599. else if (posCode == "logistics")
  6600. {
  6601. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6602. lw.Add(string.Format("VerifyState = 0"));
  6603. lw.Add("type = 2");
  6604. lw.Add(string.Format("AfterSaleState={0}", 3));
  6605. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6606. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6607. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6608. writeGridDataTableJson(dStruct.TotalCount, dt);
  6609. }
  6610. else
  6611. {
  6612. lw.Add(string.Format("(AfterSaleState = 3)"));
  6613. lw.Add("type = 0");
  6614. string reasonState = GetPostString("reasonState");
  6615. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6616. {
  6617. if (reasonState == "2")
  6618. {
  6619. lw.Add("VerifyState = 3");
  6620. }
  6621. else if (reasonState == "1")
  6622. {
  6623. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6624. }
  6625. else
  6626. {
  6627. lw.Add("VerifyState in (0,3)");
  6628. }
  6629. //不加条件,可以看全部
  6630. }
  6631. 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")
  6632. {
  6633. int orgid = CurrentUser.UserPost.OrgID;
  6634. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6635. if (string.IsNullOrEmpty(manageOrgId))
  6636. {
  6637. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6638. }
  6639. else
  6640. {
  6641. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6642. }
  6643. if (reasonState == "1")
  6644. {
  6645. lw.Add("VerifyState = 3");
  6646. }
  6647. else if (reasonState == "2")
  6648. {
  6649. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6650. }
  6651. else
  6652. {
  6653. }
  6654. }
  6655. else
  6656. {
  6657. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6658. }
  6659. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6660. //{
  6661. // int org_id = CurrentUser.UserPost.OrgID;
  6662. // lw.Add(string.Format("OrgID={0}", org_id));
  6663. //}
  6664. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6665. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6666. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6667. writeGridDataTableJson(dStruct.TotalCount, dt);
  6668. }
  6669. }
  6670. public void get_erp_finishaftersalelist()
  6671. {
  6672. DataStruct dStruct = GetPostStruct();
  6673. List<string> lw = new List<string>();
  6674. int st = 4;
  6675. string tid = GetPostString("ctid");
  6676. if (tid.Length > 0)
  6677. {
  6678. string select_tid = getTidByCtid(tid);
  6679. lw.Add(string.Format("otid='{0}'", select_tid));
  6680. }
  6681. string shopname = GetPostString("shopname");
  6682. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6683. //lw.Add(string.Format("IsRefund!={0}", 1));
  6684. string reason = GetPostString("reason");
  6685. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6686. string method = GetPostString("method");
  6687. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6688. string buyernick = GetPostString("buyer_nick");
  6689. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6690. string handler = GetPostString("handler");
  6691. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6692. string handledate1 = GetPostString("handledate1");
  6693. string handledate2 = GetPostString("handledate2");
  6694. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6695. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6696. string finish1 = GetPostString("finishdate1");
  6697. string finish2 = GetPostString("finishdate2");
  6698. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6699. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6700. string supplier = GetPostString("supplier");
  6701. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6702. string responsible = GetPostString("responsibleman");
  6703. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6704. string vstate = GetPostString("vstate");
  6705. if (vstate.Length > 0)
  6706. {
  6707. if ("3".Equals(vstate))
  6708. {
  6709. lw.Add(string.Format("IsTem=1"));
  6710. }
  6711. else
  6712. {
  6713. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6714. }
  6715. }
  6716. lw.Add(string.Format("AfterSaleState=4"));
  6717. string code = CurrentUser.UserPost.Post.Code;
  6718. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6719. {
  6720. //不加条件,可以看全部
  6721. }
  6722. else if (code == "Supplier")
  6723. {
  6724. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6725. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6726. lw.Add("type = 1");
  6727. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6728. }
  6729. else if (code == "logistics")
  6730. {
  6731. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6732. lw.Add("type = 2");
  6733. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6734. }
  6735. 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")
  6736. {
  6737. lw.Add("type = 0");
  6738. int orgid = CurrentUser.UserPost.OrgID;
  6739. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6740. if (string.IsNullOrEmpty(manageOrgIds))
  6741. {
  6742. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6743. }
  6744. else
  6745. {
  6746. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6747. }
  6748. }
  6749. else
  6750. {
  6751. lw.Add("type = 0");
  6752. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6753. }
  6754. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6755. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6756. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6757. writeGridDataTableJson(dStruct.TotalCount, dt);
  6758. }
  6759. public void handle_erp_aftersale()
  6760. {
  6761. if (UrlPostParmsCheck("ctid"))
  6762. {
  6763. string eid = GetPostString("ctid");
  6764. string responStr = GetPostString("AfterSaleResponsible");
  6765. if (responStr.Length <= 0)
  6766. {
  6767. returnErrorMsg("售后责任人不能为空");
  6768. return;
  6769. }
  6770. bool isDesign = false;
  6771. double designFree = 0.00;
  6772. int responsibleId = 0;
  6773. CeErpTradeCell entity = null;
  6774. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6775. if (entity != null)
  6776. {
  6777. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6778. string afterMethod = GetPostString("AfterSaleMethod");
  6779. if (isNeedNewOrder == 1)
  6780. {
  6781. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6782. bool ishav = true;
  6783. if (newentity == null)
  6784. {
  6785. newentity = entity.Clone() as CeErpTradeCell;
  6786. ishav = false;
  6787. newentity.ctid = "S_" + entity.ctid;
  6788. newentity.OrderState = 0;
  6789. //唯一标识
  6790. newentity.OrderSn = newentity.ctid;
  6791. string orderSn = dataHelper.getSaleOrderSn();
  6792. if (orderSn != "")
  6793. {
  6794. newentity.OrderSn = orderSn;
  6795. }
  6796. }
  6797. newentity.UpdateTime = DateTime.Now;
  6798. newentity.AfterSaleState = 0;
  6799. newentity.AfterSaleMethod = afterMethod;
  6800. if (!ishav)
  6801. {
  6802. string memo_str = newentity.seller_memo;
  6803. memo_str = memo_str.Replace("(", "(");
  6804. memo_str = memo_str.Replace(")", ")");
  6805. int sIndex = memo_str.IndexOf("(");
  6806. int eIndex = memo_str.IndexOf(")");
  6807. if (sIndex == -1 || eIndex == -1)
  6808. {
  6809. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6810. return;
  6811. }
  6812. string first = memo_str.Substring(0, sIndex + 1);
  6813. string memoCtid = newentity.OrderSn;
  6814. //if (memoCtid.IndexOf("C") != -1)
  6815. //{
  6816. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6817. //if (CIdx.IndexOf("+") != -1)
  6818. //{
  6819. //CIdx = "C" + CIdx.Split('+')[1];
  6820. //}
  6821. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6822. //}
  6823. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6824. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6825. string newMemo = first + memoCtid + last;
  6826. newentity.seller_memo = newMemo;
  6827. newentity.FinishPlaceTime = null;
  6828. newentity.UnusualTag = 0;
  6829. newentity.UnusualCon = "";
  6830. newentity.UnusualTime = null;
  6831. newentity.AfterSaleMemo = "";
  6832. newentity.AfterSaleMethod = afterMethod;
  6833. newentity.AfterSalePreTime = null;
  6834. newentity.AfterSaleReason = "";
  6835. newentity.AfterSaleResponsible = "";
  6836. newentity.AfterSaleState = 0;
  6837. newentity.AfterSaleTime = null;
  6838. newentity.AfterSaleUserId = 0;
  6839. newentity.AfterSaleSupplierState = 0;
  6840. newentity.LastBillWaybillCode = "";
  6841. newentity.LastBillCpCode = "";
  6842. newentity.FinishAfterSaleTime = null;
  6843. newentity.HandleTime = null;
  6844. newentity.IsSF = 0;
  6845. newentity.IsOldCustomer = 0;
  6846. newentity.UrgencyTime = null;
  6847. newentity.ResponsibleUserId = "";
  6848. newentity.IsVerifyToSupplier = false;
  6849. newentity.payment = 0;
  6850. newentity.CheckMemo = "";
  6851. newentity.OutSid = "";
  6852. newentity.CheckOrderTime = null;
  6853. newentity.MemoOpt = 0;
  6854. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6855. }
  6856. newentity.isAfterSaleOrder = 1;
  6857. newentity.IsRefund = 0;
  6858. string receiveMobile = GetPostString("receiver_mobile");
  6859. if (receiveMobile.Length > 0)
  6860. {
  6861. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6862. if (trade != null)
  6863. {
  6864. trade.receiver_name = GetPostString("receiver_name");
  6865. trade.receiver_mobile = receiveMobile;
  6866. trade.receiver_state = GetPostString("receiver_state");
  6867. trade.receiver_city = GetPostString("receiver_city");
  6868. trade.receiver_district = GetPostString("receiver_district");
  6869. trade.receiver_address = GetPostString("receiver_address");
  6870. newentity.IsOffLineOrder = 1;
  6871. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6872. }
  6873. }
  6874. string st = GetPostString("ToState");
  6875. if (st.Length > 0)
  6876. {
  6877. if (newentity.OrderState <= 3)
  6878. {
  6879. newentity.WaitDesignTime = DateTime.Now;
  6880. newentity.StartDesignTime = null;
  6881. newentity.FinishDesignTime = null;
  6882. newentity.OrderState = 3;
  6883. if (st == "下单员")
  6884. {
  6885. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6886. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6887. {
  6888. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6889. }
  6890. }
  6891. else
  6892. {
  6893. newentity.WaitDesignTime = DateTime.Now;
  6894. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6895. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6896. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6897. {
  6898. DataRow user = dt1.Rows[0];
  6899. //找主管
  6900. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6901. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6902. if (dt != null && dt.Rows.Count > 0)
  6903. {
  6904. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6905. newentity.DesignUserId = designMr;
  6906. string key = "aftersale_order_" + designMr;
  6907. if (RedisHelper.HasKey(key))
  6908. {
  6909. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6910. list.Add(newentity.ctid);
  6911. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6912. }
  6913. }
  6914. //账号正常
  6915. if (user["State"].ToString() == "0")
  6916. {
  6917. newentity.DesignUserId = entity.DesignUserId;
  6918. string key = "aftersale_order_" + entity.DesignUserId;
  6919. if (RedisHelper.HasKey(key))
  6920. {
  6921. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6922. list.Add(newentity.ctid);
  6923. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6924. }
  6925. }
  6926. }
  6927. }
  6928. }
  6929. if (entity.IsXianHuo == 1)
  6930. {
  6931. newentity.OrderState = 6;
  6932. entity.FinishPlaceTime = DateTime.Now;
  6933. }
  6934. }
  6935. if (ishav)
  6936. {
  6937. newentity.Update();
  6938. }
  6939. else
  6940. {
  6941. newentity.Create();
  6942. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6943. newCellExtend.ctid = newentity.ctid;
  6944. newCellExtend.orderFrom = 20;
  6945. newCellExtend.orderType = 30;
  6946. if (st == "下单员")
  6947. {
  6948. }
  6949. else
  6950. {
  6951. newCellExtend.ReprintTime = DateTime.Now;
  6952. }
  6953. newCellExtend.Create();
  6954. }
  6955. if (st != "下单员")
  6956. {
  6957. if (entity.DispatchSort == 2)
  6958. {
  6959. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6960. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6961. }
  6962. }
  6963. }
  6964. //处理售后扩展
  6965. string resIdStr = GetPostString("ResponsibleUserId");
  6966. string refundFees = GetPostString("refundFrees");
  6967. int IsComplain = GetPostInt("isComplain");
  6968. int IsBad = GetPostInt("isBad");
  6969. string IsOriginal = GetPostString("isOriginal");
  6970. double diffResultPrice = GetPostDouble("diffResultPrice");
  6971. string textResult = GetPostString("textResult");
  6972. string supplierResponsible = GetPostString("supplierResponsible");
  6973. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6974. if (ceErpTradeAfterSaleExtend == null)
  6975. {
  6976. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6977. ceErpTradeAfterSaleExtend.tid = eid;
  6978. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6979. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6980. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6981. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6982. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6983. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6984. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6985. ceErpTradeAfterSaleExtend.Create();
  6986. }
  6987. else
  6988. {
  6989. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6990. {
  6991. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6992. }
  6993. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6994. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6995. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6996. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6997. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6998. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6999. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7000. ceErpTradeAfterSaleExtend.Update();
  7001. }
  7002. int gysid = GetPostInt("ResponsibleSupId");
  7003. if (entity.AfterSaleUserId == 0)
  7004. {
  7005. entity.AfterSaleUserId = CurrentUser.UserID;
  7006. }
  7007. entity.ResponsibleUserId = resIdStr;
  7008. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  7009. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  7010. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  7011. {
  7012. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7013. int backNum = 0;
  7014. if (number != null)
  7015. {
  7016. backNum = number.BackNum;
  7017. }
  7018. char[] separator = { ',' };
  7019. string[] sArray = resIdStr.Split(separator);
  7020. string[] refundFreeList = { };
  7021. if (refundFees.Length > 0)
  7022. {
  7023. refundFreeList = refundFees.Split(separator);
  7024. }
  7025. int index = -1;
  7026. List<int> responsibleIds = new List<int>();
  7027. foreach (string i in sArray)
  7028. {
  7029. index++;
  7030. if (i.Length <= 0) continue;
  7031. char[] separator2 = { '_' };
  7032. string idstr = i.Split(separator2)[0];
  7033. string idtype = i.Split(separator2)[1];
  7034. double refudFree = 0;
  7035. if (refundFreeList.Length > 0)
  7036. {
  7037. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  7038. }
  7039. if (idtype == "s")
  7040. {
  7041. isDesign = true;
  7042. designFree = refudFree;
  7043. }
  7044. int userId = Convert.ToInt32(idstr);
  7045. int type = 0;
  7046. if (idtype == "g")
  7047. {
  7048. type = 1;
  7049. }
  7050. if (idtype == "w")
  7051. {
  7052. type = 2;
  7053. }
  7054. if (idtype == "t")
  7055. {
  7056. type = 3;
  7057. }
  7058. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7059. if (ceErpTradeResponsible == null)
  7060. {
  7061. ceErpTradeResponsible = new CeErpTradeResponsible();
  7062. ceErpTradeResponsible.tid = eid;
  7063. ceErpTradeResponsible.UserId = userId;
  7064. ceErpTradeResponsible.createdTime = DateTime.Now;
  7065. ceErpTradeResponsible.type = type;
  7066. if (type == 1)
  7067. {
  7068. ceErpTradeResponsible.IsSup = 1;
  7069. }
  7070. if (type == 2)
  7071. {
  7072. ceErpTradeResponsible.IsFlow = 1;
  7073. }
  7074. }
  7075. int state = 0;
  7076. //已认可的不需要再次认可
  7077. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7078. {
  7079. state = 1;
  7080. }
  7081. ceErpTradeResponsible.RefundFee = refudFree;
  7082. ceErpTradeResponsible.VerifyState = state;
  7083. if (userId == 2125 || idtype == "w")
  7084. {
  7085. ceErpTradeResponsible.VerifyState = 1;
  7086. }
  7087. if (idtype == "w" && userId == 101)
  7088. {
  7089. ceErpTradeResponsible.VerifyState = state;
  7090. }
  7091. if (ceErpTradeResponsible.ID > 0)
  7092. {
  7093. ceErpTradeResponsible.Update();
  7094. }
  7095. else
  7096. {
  7097. ceErpTradeResponsible.Create();
  7098. }
  7099. if (isDesign)
  7100. {
  7101. responsibleId = ceErpTradeResponsible.ID;
  7102. }
  7103. responsibleIds.Add(ceErpTradeResponsible.ID);
  7104. }
  7105. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7106. CeErpTradeResponsible.NumByTid(backNum, eid);
  7107. }
  7108. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7109. if (ceErpTradeCellExtend != null)
  7110. {
  7111. ceErpTradeCellExtend.returnVisit = 0;
  7112. ceErpTradeCellExtend.Update();
  7113. }
  7114. if (entity.HandleTime != null)
  7115. {
  7116. if (entity.AfterSaleState == 1)
  7117. {
  7118. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7119. }
  7120. else
  7121. {
  7122. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7123. }
  7124. }
  7125. else
  7126. {
  7127. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7128. entity.HandleTime = DateTime.Now;
  7129. }
  7130. bool isCompale = false;
  7131. if (entity.AfterSaleState == 5)
  7132. {
  7133. isCompale = true;
  7134. entity.AfterSaleState = 3;
  7135. }
  7136. entity.AfterSaleSupplierState = 0;
  7137. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7138. {
  7139. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7140. }
  7141. string sImgs = GetPostString("img");
  7142. entity.AfterSaleSupplierImg = sImgs;
  7143. entity.supRefundType = GetPostString("supRefundType");
  7144. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7145. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7146. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7147. entity.AfterSaleMemoType = GetPostString("MemoType");
  7148. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7149. {
  7150. //entity.AfterSaleSupplierState = 2;
  7151. }
  7152. string df = GetPostString("DeductFee");
  7153. if (df == "")
  7154. {
  7155. df = "0";
  7156. }
  7157. string rf = GetPostString("RefundFee");
  7158. if (rf == "")
  7159. {
  7160. rf = "0";
  7161. }
  7162. string pm = GetPostString("AfterSalePayment");
  7163. if (pm == "")
  7164. {
  7165. pm = "0";
  7166. }
  7167. entity.AfterSalePayment = Convert.ToDouble(pm);
  7168. entity.DeductFee = Convert.ToDouble(df);
  7169. entity.RefundFee = Convert.ToDouble(rf);
  7170. entity.UpdateTime = DateTime.Now;
  7171. entity.Update();
  7172. string toState = GetPostString("ToState");
  7173. string original = GetPostString("isOriginal");
  7174. ApiVo apiVo = new ApiVo();
  7175. apiVo.orderNumber = entity.ctid;
  7176. apiVo.actionName = "afterDesign";
  7177. apiVo.orderRemarks = entity.AfterSaleMethod;
  7178. apiVo.reasonRemarks = entity.AfterSaleReason;
  7179. apiVo.isDesign = isDesign;
  7180. apiVo.designFree = designFree;
  7181. apiVo.responsibleId = responsibleId;
  7182. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7183. if (toState == "设计师")
  7184. {
  7185. apiVo.isOriginal = Convert.ToBoolean(original);
  7186. }
  7187. designHelper.API_WorkCore(apiVo);//afterDesign
  7188. CeErpMethod methodSql = new CeErpMethod();
  7189. methodSql.con = entity.AfterSaleMethod;
  7190. methodSql.addTime = DateTime.Now;
  7191. methodSql.Create();
  7192. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7193. CeErpMethod.ExecuteNonQuery(delsql);
  7194. if (isCompale)
  7195. {
  7196. aftersale_data_change(entity.ctid);
  7197. }
  7198. returnSuccessMsg("操作成功!");
  7199. return;
  7200. }
  7201. returnErrorMsg("找不到订单记录");
  7202. }
  7203. }
  7204. public void ins_erp_toresponsible()
  7205. {
  7206. if (UrlPostParmsCheck("ctid"))
  7207. {
  7208. string eid = GetPostString("ctid");
  7209. CeErpTradeCell entity = null;
  7210. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7211. if (entity != null)
  7212. {
  7213. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7214. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7215. {
  7216. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7217. return;
  7218. }
  7219. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7220. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7221. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7222. if (entity.AfterSalePreTime == null)
  7223. {
  7224. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7225. {
  7226. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7227. }
  7228. }
  7229. entity.AfterSalePreTime = DateTime.Now;
  7230. //预完成给售后主管审核客户问题直接完成
  7231. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7232. {
  7233. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7234. {
  7235. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7236. }
  7237. }
  7238. ceErpTradeAfterSaleExtend.Update();
  7239. entity.AfterSaleState = 2;
  7240. entity.UpdateTime = DateTime.Now;
  7241. entity.Update();
  7242. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7243. aftersale_data_change(entity.ctid);
  7244. returnSuccessMsg("操作成功!");
  7245. return;
  7246. }
  7247. returnErrorMsg("找不到订单记录");
  7248. }
  7249. }
  7250. public void cancel_erp_aftersaleanddelnew()
  7251. {
  7252. if (UrlPostParmsCheck("ctid"))
  7253. {
  7254. string eid = GetPostString("ctid");
  7255. CeErpTradeCell entity = null;
  7256. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7257. if (entity != null)
  7258. {
  7259. entity.AfterSaleState = 0;
  7260. entity.AfterSaleReason = "";
  7261. entity.AfterSaleMethod = "";
  7262. entity.AfterSaleMemo = "";
  7263. entity.AfterSaleResponsible = "";
  7264. entity.ResponsibleUserId = "";
  7265. entity.DeductFee = 0;
  7266. entity.RefundFee = 0;
  7267. entity.IsArbitrate = 0;
  7268. CeErpTradeResponsible.DelByTid(eid, -1);
  7269. entity.Update();
  7270. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7271. if (after != null)
  7272. {
  7273. if (after.OrderState < 5)
  7274. CeErpTradeCell.DelByCtid("S_" + eid);
  7275. }
  7276. returnSuccessMsg("操作成功!");
  7277. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7278. return;
  7279. }
  7280. returnErrorMsg("找不到订单记录");
  7281. }
  7282. }
  7283. public void get_erp_aftersale_pregather()
  7284. {
  7285. List<string> lw = new List<string>();
  7286. int st = GetInt("st");
  7287. string tid = GetPostString("ctid");
  7288. if (tid.Length > 0)
  7289. {
  7290. string select_tid = getTidByCtid(tid);
  7291. lw.Add(string.Format("tid='{0}'", select_tid));
  7292. }
  7293. string shopname = GetPostString("shopname");
  7294. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7295. string buyernick = GetPostString("buyer_nick");
  7296. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7297. string sellermemo = GetPostString("seller_memo");
  7298. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7299. string orderState = GetPostString("orderState");
  7300. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7301. string reason = GetPostString("reason");
  7302. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7303. string method = GetPostString("method");
  7304. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7305. string handler = GetPostString("handler");
  7306. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7307. string handledate1 = GetPostString("handledate1");
  7308. string handledate2 = GetPostString("handledate2");
  7309. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7310. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7311. string supplier = GetPostString("supplier");
  7312. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7313. string responsible = GetPostString("responsibleman");
  7314. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7315. string customer = GetPostString("customer");
  7316. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7317. string design = GetPostString("design");
  7318. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7319. string afterMemoType = GetPostString("aftermemotype");
  7320. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7321. string afterSaleMemo = GetPostString("afterSaleMemo");
  7322. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7323. string afterresult = GetPostString("afterresult");
  7324. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7325. string poscode = CurrentUser.UserPost.Post.Code;
  7326. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7327. {
  7328. string shopid = CurrentUser.User.pemShop;
  7329. lw.Add(string.Format("shopId in ({0})", shopid));
  7330. }
  7331. var mainwhere = string.Join(" and ", lw.ToArray());
  7332. string ro_json = "";
  7333. string type = GetPostString("gather_type");
  7334. int number = 0;
  7335. if (poscode == "AfterSale")
  7336. {
  7337. //处理中
  7338. if (type == "Handling")
  7339. {
  7340. 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) : ""));
  7341. DataTable dt = null;
  7342. try
  7343. {
  7344. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7345. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7346. }
  7347. catch (Exception e)
  7348. {
  7349. dt = new DataTable();
  7350. }
  7351. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7352. return;
  7353. }
  7354. if (type == "Wait")
  7355. {
  7356. //待处理
  7357. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7358. DataTable dt1 = null;
  7359. try
  7360. {
  7361. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7362. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7363. }
  7364. catch (Exception e)
  7365. {
  7366. dt1 = new DataTable();
  7367. }
  7368. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7369. return;
  7370. }
  7371. if (type == "back")
  7372. {
  7373. //打回
  7374. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7375. DataTable dt2 = null;
  7376. try
  7377. {
  7378. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7379. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7380. }
  7381. catch (Exception e)
  7382. {
  7383. dt2 = new DataTable();
  7384. }
  7385. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7386. return;
  7387. }
  7388. if (type == "preCompletion")
  7389. {
  7390. //预完成
  7391. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7392. DataTable dt3 = null;
  7393. try
  7394. {
  7395. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7396. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7397. }
  7398. catch (Exception e)
  7399. {
  7400. dt3 = new DataTable();
  7401. }
  7402. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7403. return;
  7404. }
  7405. if (type == "documentary")
  7406. {
  7407. //跟单中
  7408. 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) : ""));
  7409. DataTable dt4 = null;
  7410. try
  7411. {
  7412. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7413. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7414. }
  7415. catch (Exception e)
  7416. {
  7417. dt4 = new DataTable();
  7418. }
  7419. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7420. return;
  7421. }
  7422. if (type == "reBack")
  7423. {
  7424. //被打回
  7425. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7426. DataTable dt1 = null;
  7427. try
  7428. {
  7429. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7430. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7431. }
  7432. catch (Exception e)
  7433. {
  7434. dt1 = new DataTable();
  7435. }
  7436. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7437. return;
  7438. }
  7439. }
  7440. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7441. {
  7442. if (type == "puBack")
  7443. {
  7444. //退回
  7445. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7446. DataTable dt = null;
  7447. try
  7448. {
  7449. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7450. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7451. }
  7452. catch (Exception e)
  7453. {
  7454. dt = new DataTable();
  7455. }
  7456. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7457. return;
  7458. }
  7459. if (type == "reBack")
  7460. {
  7461. //打回
  7462. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7463. DataTable dt1 = null;
  7464. try
  7465. {
  7466. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7467. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7468. }
  7469. catch (Exception e)
  7470. {
  7471. dt1 = new DataTable();
  7472. }
  7473. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7474. return;
  7475. }
  7476. if (type == "examEd")
  7477. {
  7478. //已审核
  7479. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7480. DataTable dt2 = null;
  7481. try
  7482. {
  7483. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7484. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7485. }
  7486. catch (Exception e)
  7487. {
  7488. dt2 = new DataTable();
  7489. }
  7490. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7491. return;
  7492. }
  7493. if (type == "waitExam")
  7494. {
  7495. //待审核
  7496. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7497. DataTable dt3 = null;
  7498. try
  7499. {
  7500. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7501. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7502. }
  7503. catch (Exception e)
  7504. {
  7505. dt3 = new DataTable();
  7506. }
  7507. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7508. return;
  7509. }
  7510. if (type == "Handling")
  7511. {
  7512. //处理中
  7513. 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) : ""));
  7514. DataTable dt4 = null;
  7515. try
  7516. {
  7517. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7518. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7519. }
  7520. catch (Exception e)
  7521. {
  7522. dt4 = new DataTable();
  7523. }
  7524. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7525. return;
  7526. }
  7527. if (type == "Wait")
  7528. {
  7529. //待处理
  7530. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7531. DataTable dt5 = null;
  7532. try
  7533. {
  7534. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7535. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7536. }
  7537. catch (Exception e)
  7538. {
  7539. dt5 = new DataTable();
  7540. }
  7541. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7542. return;
  7543. }
  7544. if (type == "documentary")
  7545. {
  7546. //跟单中
  7547. 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) : ""));
  7548. DataTable dt6 = null;
  7549. try
  7550. {
  7551. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7552. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7553. }
  7554. catch (Exception e)
  7555. {
  7556. dt6 = new DataTable();
  7557. }
  7558. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7559. return;
  7560. }
  7561. }
  7562. returnSuccess(ro_json);
  7563. }
  7564. public void end_erp_aftersale()
  7565. {
  7566. if (UrlPostParmsCheck("ctid"))
  7567. {
  7568. string eid = GetPostString("ctid");
  7569. CeErpTradeCell entity = null;
  7570. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7571. if (entity != null)
  7572. {
  7573. string stype = GetPostString("stype");
  7574. string typeStr = stype;
  7575. entity.AfterSaleState = 4;
  7576. entity.FinishAfterSaleTime = DateTime.Now;
  7577. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7578. entity.Update();
  7579. ApiVo apiVo = new ApiVo();
  7580. apiVo.orderNumber = entity.ctid;
  7581. apiVo.actionName = "afterOver";
  7582. designHelper.API_WorkCore(apiVo); //afterOver
  7583. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7584. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7585. CeErpSukuraData.createInfo(entity.ctid, 8);
  7586. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7587. returnSuccessMsg("操作成功!");
  7588. return;
  7589. }
  7590. returnErrorMsg("找不到订单记录");
  7591. }
  7592. }
  7593. public void ins_erp_finishaftersale()
  7594. {
  7595. if (UrlPostParmsCheck("id"))
  7596. {
  7597. string eid = GetPostString("id");
  7598. CeErpTradeResponsible entity = null;
  7599. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7600. if (entity != null)
  7601. {
  7602. entity.VerifyState = 1;
  7603. entity.VerifyTime = DateTime.Now;
  7604. entity.Update();
  7605. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7606. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7607. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7608. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7609. if (dt.Rows.Count <= 0)
  7610. {
  7611. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7612. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7613. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7614. CeErpSukuraData.createInfo(entity.tid, 8);
  7615. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7616. {
  7617. CeErpDesignerBill.Del(entity.tid);
  7618. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7619. }
  7620. }
  7621. returnSuccessMsg("操作成功!");
  7622. return;
  7623. }
  7624. returnErrorMsg("找不到订单记录");
  7625. }
  7626. }
  7627. public void upd_erp_arbitrateaftersale()
  7628. {
  7629. if (UrlPostParmsCheck("id"))
  7630. {
  7631. string eid = GetPostString("id");
  7632. CeErpTradeResponsible entity = null;
  7633. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7634. if (entity != null)
  7635. {
  7636. entity.IsArbitrate = 1;
  7637. entity.ArbitradeMemo = GetPostString("reason");
  7638. entity.VerifyState = 2;
  7639. entity.Update();
  7640. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7641. if (tradecell != null)
  7642. {
  7643. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7644. tradecell.IsArbitrate = 1;
  7645. tradecell.Update();
  7646. }
  7647. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7648. returnSuccessMsg("操作成功!");
  7649. return;
  7650. }
  7651. returnErrorMsg("找不到订单记录");
  7652. }
  7653. }
  7654. public void upd_erp_backaftersale()
  7655. {
  7656. if (UrlPostParmsCheck("tid"))
  7657. {
  7658. string eid = GetPostString("tid");
  7659. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7660. int backNum = 0;
  7661. if (number != null)
  7662. {
  7663. backNum = number.BackNum;
  7664. }
  7665. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7666. CeErpTradeCell entity = null;
  7667. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7668. if (entity != null)
  7669. {
  7670. entity.AfterSaleBackReason = GetPostString("backreason");
  7671. entity.AfterSaleState = 1;
  7672. entity.AfterSaleSupplierState = 0;
  7673. entity.UpdateTime = DateTime.Now;
  7674. entity.Update();
  7675. returnSuccessMsg("操作成功!");
  7676. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7677. return;
  7678. }
  7679. returnErrorMsg("找不到订单记录");
  7680. }
  7681. }
  7682. public void get_erp_supplieraftersalelist()
  7683. {
  7684. DataStruct dStruct = GetPostStruct();
  7685. List<string> lw = new List<string>();
  7686. string tid = GetPostString("ctid");
  7687. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7688. string shopname = GetPostString("shopname");
  7689. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7690. string buyernick = GetPostString("buyer_nick");
  7691. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7692. string sellermemo = GetPostString("seller_memo");
  7693. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7694. string orderState = GetPostString("orderState");
  7695. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7696. string afterState = GetPostString("afterstate");
  7697. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7698. string date1 = GetPostString("date1");
  7699. string date2 = GetPostString("date2");
  7700. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7701. if (dw.Length > 0) lw.Add(dw);
  7702. string price1 = GetPostString("price1");
  7703. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7704. string price2 = GetPostString("price2");
  7705. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7706. string reason = GetPostString("reason");
  7707. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7708. string method = GetPostString("method");
  7709. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7710. string handledate1 = GetPostString("handledate1");
  7711. string handledate2 = GetPostString("handledate2");
  7712. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7713. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7714. string handler = GetPostString("handler");
  7715. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7716. string afterdate1 = GetPostString("afterdate1");
  7717. string afterdate2 = GetPostString("afterdate2");
  7718. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7719. if (afterDate.Length > 0) lw.Add(afterDate);
  7720. string customer = GetPostString("customer");
  7721. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7722. string design = GetPostString("design");
  7723. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7724. string afterMemoType = GetPostString("aftermemotype");
  7725. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7726. string vstate = GetPostString("vstate");
  7727. if (vstate.Length > 0)
  7728. {
  7729. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7730. }
  7731. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7732. string supplier = GetPostString("supplier");
  7733. int supid = commonHelper.getSupplierIDByName(supplier);
  7734. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7735. string posCode = CurrentUser.UserPost.Post.Code;
  7736. if (posCode == "Supplier")
  7737. {
  7738. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7739. }
  7740. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7741. {
  7742. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7743. }
  7744. else
  7745. {
  7746. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7747. }
  7748. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7749. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7750. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7751. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7752. writeGridDataTableJson(dStruct.TotalCount, dt);
  7753. }
  7754. public void upd_erp_supverifyaftersale()
  7755. {
  7756. if (UrlPostParmsCheck("id"))
  7757. {
  7758. string id = GetPostString("id");
  7759. int st = GetPostInt("afterstate");
  7760. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7761. CeErpTradeCell entity = null;
  7762. if (ceErpTradeResponsible != null)
  7763. {
  7764. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7765. }
  7766. string afmemo = GetPostString("supmemo");
  7767. string image = GetPostString("image");
  7768. if (entity != null)
  7769. {
  7770. entity.AfterSaleSupplierState = st;
  7771. entity.AfterSaleSupplierMemo = afmemo;
  7772. if (st == 1)
  7773. {
  7774. ceErpTradeResponsible.VerifyState = 1;
  7775. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7776. ceErpTradeResponsible.Update();
  7777. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7778. if (isAll)
  7779. {
  7780. entity.AfterSaleState = 4;
  7781. entity.FinishAfterSaleTime = DateTime.Now;
  7782. }
  7783. }
  7784. else
  7785. {
  7786. CeErpTradeResponsible.dateByTid(entity.ctid);
  7787. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7788. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7789. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7790. if (num <= 1)
  7791. {
  7792. entity.AfterSaleState = 1;
  7793. }
  7794. else
  7795. {
  7796. entity.AfterSaleState = 5;
  7797. }
  7798. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7799. if (ceErpTradeAfterSaleExtend != null)
  7800. {
  7801. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7802. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7803. ceErpTradeAfterSaleExtend.Update();
  7804. }
  7805. else
  7806. {
  7807. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7808. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7809. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7810. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7811. ceErpTradeAfterSaleExtend.Create();
  7812. }
  7813. }
  7814. if (entity.AfterSaleState == 4)
  7815. {
  7816. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7817. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7818. {
  7819. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7820. }
  7821. ApiVo apiVo = new ApiVo();
  7822. apiVo.orderNumber = entity.ctid;
  7823. apiVo.actionName = "afterOver";
  7824. designHelper.API_WorkCore(apiVo); //afterOver
  7825. }
  7826. entity.UpdateTime = DateTime.Now;
  7827. entity.Update();
  7828. returnSuccessMsg("操作成功!");
  7829. CeErpSukuraData.createInfo(entity.ctid, 8);
  7830. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7831. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7832. return;
  7833. }
  7834. returnErrorMsg("找不到订单记录");
  7835. }
  7836. }
  7837. public void upd_erp_masteraftersale()
  7838. {
  7839. if (UrlPostParmsCheck("id"))
  7840. {
  7841. string id = GetPostString("id");
  7842. int st = GetPostInt("afterstate");
  7843. string afmemo = GetPostString("supmemo");
  7844. string image = GetPostString("image");
  7845. string textResult = GetPostString("textResult");
  7846. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7847. if (ceErpTradeResponsible != null)
  7848. {
  7849. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7850. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7851. ceErpTradeResponsible.Update();
  7852. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7853. if (entity != null)
  7854. {
  7855. entity.AfterSaleSupplierState = st;
  7856. entity.AfterSaleSupplierMemo = afmemo;
  7857. if (st == 1)
  7858. {
  7859. }
  7860. else
  7861. {
  7862. CeErpTradeResponsible.dateByTid(entity.ctid);
  7863. //退回到售后
  7864. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7865. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7866. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7867. if (num <= 1)
  7868. {
  7869. entity.AfterSaleState = 1;
  7870. }
  7871. else
  7872. {
  7873. entity.AfterSaleState = 5;
  7874. }
  7875. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7876. if (ceErpTradeAfterSaleExtend != null)
  7877. {
  7878. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7879. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7880. ceErpTradeAfterSaleExtend.Update();
  7881. }
  7882. else
  7883. {
  7884. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7885. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7886. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7887. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7888. ceErpTradeAfterSaleExtend.Create();
  7889. }
  7890. }
  7891. entity.UpdateTime = DateTime.Now;
  7892. entity.Update();
  7893. returnSuccessMsg("操作成功!");
  7894. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7895. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7896. return;
  7897. }
  7898. }
  7899. returnErrorMsg("找不到订单记录");
  7900. }
  7901. }
  7902. public void upd_erp_personaftersale()
  7903. {
  7904. if (UrlPostParmsCheck("id"))
  7905. {
  7906. //林小连
  7907. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7908. {
  7909. upd_erp_masteraftersale();
  7910. return;
  7911. }
  7912. string id = GetPostString("id");
  7913. int st = GetPostInt("afterstate");
  7914. string afmemo = GetPostString("supmemo");
  7915. string image = GetPostString("image");
  7916. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7917. if (ceErpTradeResponsible != null)
  7918. {
  7919. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7920. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7921. ceErpTradeResponsible.Update();
  7922. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7923. if (entity != null)
  7924. {
  7925. entity.AfterSaleSupplierMemo = afmemo;
  7926. entity.AfterSaleSupplierState = st;
  7927. if (st == 1)
  7928. {
  7929. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7930. if (isAll)
  7931. {
  7932. entity.AfterSaleState = 4;
  7933. entity.FinishAfterSaleTime = DateTime.Now;
  7934. }
  7935. }
  7936. else
  7937. {
  7938. CeErpTradeResponsible.dateByTid(entity.ctid);
  7939. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7940. if (ceErpTradeAfterSaleExtend != null)
  7941. {
  7942. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7943. ceErpTradeAfterSaleExtend.Update();
  7944. }
  7945. else
  7946. {
  7947. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7948. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7949. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7950. ceErpTradeAfterSaleExtend.Create();
  7951. }
  7952. //退回到主管
  7953. //entity.AfterSaleState = 2;
  7954. }
  7955. if (entity.AfterSaleState == 4)
  7956. {
  7957. ApiVo apiVo = new ApiVo();
  7958. apiVo.orderNumber = entity.ctid;
  7959. apiVo.actionName = "afterOver";
  7960. designHelper.API_WorkCore(apiVo); //afterOver
  7961. }
  7962. entity.UpdateTime = DateTime.Now;
  7963. entity.Update();
  7964. returnSuccessMsg("操作成功!");
  7965. CeErpSukuraData.createInfo(entity.ctid, 8);
  7966. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7967. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7968. return;
  7969. }
  7970. }
  7971. returnErrorMsg("找不到订单记录");
  7972. }
  7973. }
  7974. public void set_erp_supplierrefundtag()
  7975. {
  7976. if (UrlPostParmsCheck("ctid"))
  7977. {
  7978. string eid = GetPostString("ctid");
  7979. CeErpTradeCell entity = null;
  7980. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7981. if (entity != null)
  7982. {
  7983. entity.IsSupplierRefund = GetPostInt("tag");
  7984. entity.Update();
  7985. returnSuccessMsg("操作成功!");
  7986. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7987. return;
  7988. }
  7989. returnErrorMsg("找不到订单记录");
  7990. }
  7991. }
  7992. public void get_erp_refundlist()
  7993. {
  7994. DataStruct dStruct = GetPostStruct();
  7995. List<string> lw = new List<string>();
  7996. string tid = GetPostString("tid");
  7997. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7998. //string rid = GetPostString("refund_id");
  7999. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  8000. string shopname = GetPostString("shopname");
  8001. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8002. string buyernick = GetPostString("buyer_nick");
  8003. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8004. string customer = GetPostString("customer");
  8005. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8006. string design = GetPostString("design");
  8007. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8008. string sellermemo = GetPostString("seller_memo");
  8009. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8010. //string date1 = GetPostString("date1");
  8011. //string date2 = GetPostString("date2");
  8012. //string dateType = GetPostString("dateType");
  8013. //if (dateType.Length > 0)
  8014. //{
  8015. // if (dateType == "1001") dateType = "0";
  8016. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  8017. // if (searchDT.Count == 2)
  8018. // {
  8019. // date1 = searchDT[0].ToString();
  8020. // date2 = searchDT[1].ToString();
  8021. // }
  8022. //}
  8023. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8024. //if (dw.Length > 0) lw.Add(dw);
  8025. string redate1 = GetPostString("refunddate1");
  8026. string redate2 = GetPostString("refunddate2");
  8027. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8028. if (dwdate.Length > 0) lw.Add(dwdate);
  8029. string price1 = GetPostString("price1");
  8030. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8031. string price2 = GetPostString("price2");
  8032. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8033. string ispartrefund = GetPostString("ispartrefund");
  8034. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8035. string refundState = GetPostString("refundvstate");
  8036. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  8037. int st = GetInt("st");
  8038. if (st == 2) //待确认列表中,把state=3已确认的也显示
  8039. {
  8040. string responsible = GetPostString("responsibleman");
  8041. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8042. lw.Add(string.Format("RefundState>={0}", st));
  8043. string code = CurrentUser.UserPost.Post.Code;
  8044. if (code == "CustomerService")
  8045. {
  8046. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8047. }
  8048. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8049. {
  8050. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8051. }
  8052. else if (code == "Place" || code == "PlaceMr")
  8053. {
  8054. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8055. }
  8056. dStruct.Order = "RefundState asc,created desc";
  8057. }
  8058. else if (st == 10)
  8059. {
  8060. string responsible = GetPostString("responsibleman");
  8061. if (responsible == "空白")
  8062. {
  8063. lw.Add(string.Format("ResponsibleUserName = ''"));
  8064. }
  8065. else if (responsible.Length > 0)
  8066. {
  8067. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8068. }
  8069. lw.Add(string.Format("RefundState>=0"));
  8070. dStruct.Order = "created desc";
  8071. }
  8072. else
  8073. {
  8074. string responsible = GetPostString("responsibleman");
  8075. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8076. lw.Add(string.Format("RefundState={0}", st));
  8077. dStruct.Order = "created desc";
  8078. }
  8079. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8080. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8081. dt.Columns.Add("refund_fees");
  8082. foreach (DataRow dr in dt.Rows)
  8083. {
  8084. String status = dr["status"].ToString();
  8085. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8086. {
  8087. dr["refund_fees"] = dr["refund_fee"];
  8088. }
  8089. else
  8090. {
  8091. dr["refund_fees"] = "0.0";
  8092. }
  8093. }
  8094. writeGridDataTableJson(dStruct.TotalCount, dt);
  8095. }
  8096. public void get_erp_refunddesignlist()
  8097. {
  8098. DataStruct dStruct = GetPostStruct();
  8099. List<string> lw = new List<string>();
  8100. string tid = GetPostString("tid");
  8101. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8102. string shopname = GetPostString("shopname");
  8103. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8104. string buyernick = GetPostString("buyer_nick");
  8105. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8106. string customer = GetPostString("customer");
  8107. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8108. string design = GetPostString("design");
  8109. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8110. string sellermemo = GetPostString("seller_memo");
  8111. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8112. string redate1 = GetPostString("refunddate1");
  8113. string redate2 = GetPostString("refunddate2");
  8114. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8115. if (dwdate.Length > 0) lw.Add(dwdate);
  8116. string price1 = GetPostString("price1");
  8117. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8118. string price2 = GetPostString("price2");
  8119. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8120. string ispartrefund = GetPostString("ispartrefund");
  8121. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8122. string designerorg = GetPostString("designerorg");
  8123. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8124. string refundState = GetPostString("refundState");
  8125. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8126. int myOrgid = CurrentUser.UserPost.OrgID;
  8127. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8128. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8129. {
  8130. if (CurrentUser.User.TeamIds.Length > 0)
  8131. {
  8132. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8133. }
  8134. else
  8135. {
  8136. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8137. }
  8138. }
  8139. else if ("SysAdmin".Equals(myOrgCode))
  8140. {
  8141. }
  8142. else
  8143. {
  8144. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8145. {
  8146. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8147. }
  8148. else
  8149. {
  8150. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8151. }
  8152. }
  8153. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8154. dStruct.Order = "created desc";
  8155. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8156. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8157. dt.Columns.Add("refund_fees");
  8158. foreach (DataRow dr in dt.Rows)
  8159. {
  8160. String status = dr["status"].ToString();
  8161. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8162. {
  8163. dr["refund_fees"] = dr["refund_fee"];
  8164. }
  8165. else
  8166. {
  8167. dr["refund_fees"] = "0.0";
  8168. }
  8169. }
  8170. writeGridDataTableJson(dStruct.TotalCount, dt);
  8171. }
  8172. public void handle_erp_refundtag()
  8173. {
  8174. if (UrlPostParmsCheck("refund_id"))
  8175. {
  8176. string eid = GetPostString("refund_id");
  8177. string respMan = GetPostString("ResponsibleName");
  8178. if (respMan.Length <= 0)
  8179. {
  8180. returnErrorMsg("责任人不能为空");
  8181. return;
  8182. }
  8183. CeErpTradeRefund entity = null;
  8184. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8185. if (entity != null)
  8186. {
  8187. entity.ResponsibleUserName = respMan;
  8188. string userid = GetPostString("ResponsibleUserId");
  8189. if (userid.Length > 0)
  8190. {
  8191. entity.ResponsibleUserId = userid;
  8192. }
  8193. entity.Memo = GetPostString("Memo");
  8194. if (respMan.IndexOf("客服") != -1 ||
  8195. respMan.IndexOf("设计师") != -1 ||
  8196. respMan.IndexOf("下单员") != -1)
  8197. {
  8198. entity.RefundState = 2;
  8199. }
  8200. else
  8201. {
  8202. entity.RefundState = 3;
  8203. }
  8204. entity.modified = DateTime.Now;
  8205. entity.Update();
  8206. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8207. returnSuccessMsg("操作成功!");
  8208. return;
  8209. }
  8210. returnErrorMsg("找不到订单记录");
  8211. }
  8212. }
  8213. public void handle_erp_designrefundtag()
  8214. {
  8215. if (UrlPostParmsCheck("refund_id"))
  8216. {
  8217. string eid = GetPostString("refund_id");
  8218. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8219. if (ceErpTradeCellExtend == null)
  8220. {
  8221. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8222. ceErpTradeCellExtend.ctid = eid;
  8223. }
  8224. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8225. if (ceErpTradeCellExtend.ID > 0)
  8226. {
  8227. ceErpTradeCellExtend.Update();
  8228. }
  8229. else
  8230. {
  8231. ceErpTradeCellExtend.Create();
  8232. }
  8233. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8234. returnSuccessMsg("操作成功!");
  8235. return;
  8236. }
  8237. returnErrorMsg("找不到订单记录");
  8238. }
  8239. public void upd_erp_refundverify()
  8240. {
  8241. if (UrlPostParmsCheck("refund_id"))
  8242. {
  8243. string eid = GetPostString("refund_id");
  8244. CeErpTradeRefund entity = null;
  8245. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8246. if (entity != null)
  8247. {
  8248. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8249. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8250. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8251. {
  8252. entity.RefundState = 2;
  8253. }
  8254. else
  8255. {
  8256. entity.RefundState = 3;
  8257. }
  8258. entity.Update();
  8259. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8260. returnSuccessMsg("操作成功!");
  8261. return;
  8262. }
  8263. returnErrorMsg("找不到订单记录");
  8264. }
  8265. }
  8266. public void upd_erp_refundapprove()
  8267. {
  8268. if (UrlPostParmsCheck("refund_id"))
  8269. {
  8270. string eid = GetPostString("refund_id");
  8271. CeErpTradeRefund entity = null;
  8272. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8273. if (entity != null)
  8274. {
  8275. int apr = GetPostInt("approve");
  8276. if (apr == 0)
  8277. {
  8278. entity.RefundState = 1;
  8279. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8280. }
  8281. else if (apr == 1)
  8282. {
  8283. entity.RefundState = 3;
  8284. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8285. }
  8286. entity.modified = DateTime.Now;
  8287. entity.Update();
  8288. returnSuccessMsg("操作成功!");
  8289. return;
  8290. }
  8291. returnErrorMsg("找不到订单记录");
  8292. }
  8293. }
  8294. public void get_erp_billlist()
  8295. {
  8296. DataStruct dStruct = GetPostStruct();
  8297. List<string> lw = new List<string>();
  8298. string title = GetPostString("title");
  8299. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8300. string tid = GetPostString("tid");
  8301. string tids = GetPostString("tids");
  8302. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8303. if (tids.Length > 0)
  8304. {
  8305. tids = "'" + tids + "'";
  8306. tids = tids.Replace(",", "','");
  8307. lw.Add(string.Format("tid in ({0})", tids));
  8308. }
  8309. string shopname = GetPostString("shopname");
  8310. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8311. string buyernick = GetPostString("buyer_nick");
  8312. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8313. string customer = GetPostString("customer");
  8314. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8315. string date1 = GetPostString("date1");
  8316. string date2 = GetPostString("date2");
  8317. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8318. if (dw.Length > 0) lw.Add(dw);
  8319. string price1 = GetPostString("price1");
  8320. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8321. string price2 = GetPostString("price2");
  8322. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8323. string returndate1 = GetPostString("returndate1");
  8324. string returndate2 = GetPostString("returndate2");
  8325. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8326. if (dw1.Length > 0) lw.Add(dw1);
  8327. string billtype = GetPostString("billtype");
  8328. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8329. string billstate = GetPostString("billstate");
  8330. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8331. string usershop = CurrentUser.User.pemShop;
  8332. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8333. dStruct.Order = "createTime desc";
  8334. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8335. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8336. //foreach (DataRow dr in dt.Rows)
  8337. //{
  8338. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8339. //}
  8340. writeGridDataTableJson(dStruct.TotalCount, dt);
  8341. }
  8342. public void modify_erp_billinfo()
  8343. {
  8344. if (UrlPostParmsCheck("ID"))
  8345. {
  8346. string eid = GetPostString("ID");
  8347. CeErpBill bill_entity = null;
  8348. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8349. if (bill_entity != null)
  8350. {
  8351. bill_entity.tid = GetPostString("tid");
  8352. bill_entity.title = GetPostString("title");
  8353. bill_entity.tax = GetPostString("tax");
  8354. bill_entity.bank = GetPostString("bank");
  8355. bill_entity.bankac = GetPostString("bankac");
  8356. bill_entity.address = GetPostString("address");
  8357. bill_entity.phone = GetPostString("phone");
  8358. bill_entity.price = GetPostString("price");
  8359. bill_entity.productId = GetPostInt("ProductName");
  8360. bill_entity.num = GetPostInt("num");
  8361. bill_entity.unit = GetPostString("unit");
  8362. bill_entity.type = GetPostString("type");
  8363. bill_entity.sendType = GetPostString("SendType");
  8364. bill_entity.email = GetPostString("email");
  8365. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8366. bill_entity.shopName = GetPostString("ShopName");
  8367. bill_entity.applymemo = GetPostString("applymemo");
  8368. bill_entity.modifyTime = DateTime.Now;
  8369. bill_entity.createTime = DateTime.Now;
  8370. bill_entity.state = 0;
  8371. bill_entity.Update();
  8372. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8373. returnSuccessMsg("发票修改成功!");
  8374. return;
  8375. }
  8376. returnErrorMsg("找不到对应记录");
  8377. }
  8378. }
  8379. public void set_erp_invoicing()
  8380. {
  8381. if (UrlPostParmsCheck("id"))
  8382. {
  8383. try
  8384. {
  8385. string eid = GetPostString("id");
  8386. CeErpBill bill_entity = null;
  8387. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8388. if (bill_entity != null)
  8389. {
  8390. int ComId = GetPostInt("ComId");
  8391. //string memo = GetPostString("Memo");
  8392. int allInfo = GetPostInt("allinfo");
  8393. string clert = CurrentUser.User.Name;
  8394. //string detailValue = GetPostString("detailvalue");
  8395. string billId = bill_entity.billOrderId;
  8396. string[] billIdList = billId.Split(',');
  8397. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8398. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8399. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8400. {
  8401. billCount += 1;
  8402. }
  8403. if (billId.Length <= 0 || billIdList.Length != billCount)
  8404. {
  8405. bill_entity.billOrderId = "";
  8406. string prebill = "ltb";
  8407. for (int idx = 1; idx <= billCount; idx++)
  8408. {
  8409. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8410. string billoid = prebill + idx + dtstr;
  8411. bill_entity.billOrderId += billoid;
  8412. if (idx < billCount)
  8413. {
  8414. bill_entity.billOrderId += ",";
  8415. }
  8416. }
  8417. }
  8418. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8419. if (bill_entity.state == 5)
  8420. {
  8421. string errMsg = bill_entity.failerror;
  8422. string[] errlist = errMsg.Split('|');
  8423. string[] errTags = new string[errlist.Length];
  8424. for (int itag = 0; itag < errlist.Length; itag++)
  8425. {
  8426. if (errlist[itag].Length <= 0) continue;
  8427. errTags[itag] = errlist[itag].Split('&')[0];
  8428. }
  8429. for (int iii = 0; iii < errTags.Length; iii++)
  8430. {
  8431. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8432. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8433. if (billOrderList.Length >= erroBillOrderTag)
  8434. {
  8435. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8436. if (needModifyBillId.Length <= 19)
  8437. {
  8438. needModifyBillId = needModifyBillId + "1";
  8439. }
  8440. else
  8441. {
  8442. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8443. last = last + 1;
  8444. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8445. }
  8446. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8447. }
  8448. }
  8449. }
  8450. bool isHaveBillSucces = false;
  8451. string totalRes = "";
  8452. bill_entity.failerror = "";
  8453. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8454. {
  8455. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8456. totalRes += res;
  8457. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8458. {
  8459. isHaveBillSucces = true;
  8460. bill_entity.comId = ComId;
  8461. bill_entity.state = 1;
  8462. bill_entity.executeTime = DateTime.Now;
  8463. bill_entity.executeUser = clert;
  8464. }
  8465. else
  8466. {
  8467. bill_entity.state = 5;
  8468. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8469. }
  8470. }
  8471. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8472. bill_entity.Update();
  8473. if (isHaveBillSucces)
  8474. {
  8475. StringBuilder sql = new StringBuilder();
  8476. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8477. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8478. }
  8479. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8480. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8481. {
  8482. returnErrorMsg("开票失败");
  8483. }
  8484. else
  8485. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8486. return;
  8487. }
  8488. returnErrorMsg("找不到对应记录");
  8489. }
  8490. catch (Exception ex)
  8491. {
  8492. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8493. returnErrorMsg("操作失败");
  8494. }
  8495. }
  8496. }
  8497. public void get_erp_invoicing_back()
  8498. {
  8499. if (UrlPostParmsCheck("id"))
  8500. {
  8501. try
  8502. {
  8503. string id = GetPostString("id");
  8504. CeErpBill entiy = CeErpBill.Get(id);
  8505. if (entiy != null)
  8506. {
  8507. if (entiy.state == 0)
  8508. {
  8509. returnErrorMsg("发票还未开具");
  8510. return;
  8511. }
  8512. string[] billOrderList = entiy.billOrderId.Split(',');
  8513. int iTag = 0;
  8514. entiy.fplsh = "";
  8515. entiy.fpdm = "";
  8516. entiy.fphm = "";
  8517. foreach (string billOrderId in billOrderList)
  8518. {
  8519. iTag++;
  8520. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8521. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8522. {
  8523. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8524. try
  8525. {
  8526. Invoicing_get_response_Obj iObj = null;
  8527. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8528. if (iObj != null)
  8529. {
  8530. entiy.state = 2;
  8531. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8532. entiy.fpdm += iObj.list[0].c_fpdm;
  8533. entiy.fphm += iObj.list[0].c_fphm;
  8534. if (iTag < billOrderList.Length)
  8535. {
  8536. entiy.fplsh += ",";
  8537. entiy.fpdm += ",";
  8538. entiy.fphm += ",";
  8539. }
  8540. entiy.Update();
  8541. }
  8542. StringBuilder sql = new StringBuilder();
  8543. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8544. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8545. returnSuccessMsg("开票成功");
  8546. }
  8547. catch (Exception ex)
  8548. {
  8549. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8550. }
  8551. return;
  8552. }
  8553. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8554. {
  8555. var res_obj = new
  8556. {
  8557. data = "开票中"
  8558. };
  8559. string ro_json = JsonConvert.SerializeObject(res_obj);
  8560. returnSuccess(ro_json);
  8561. return;
  8562. }
  8563. else
  8564. {
  8565. int eidx = res.IndexOf("c_resultmsg");
  8566. int lidx = res.IndexOf("c_status");
  8567. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8568. entiy.state = 5;
  8569. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8570. entiy.Update();
  8571. returnErrorMsg("开票失败");
  8572. return;
  8573. }
  8574. }
  8575. }
  8576. }
  8577. catch (Exception ex)
  8578. {
  8579. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8580. }
  8581. return;
  8582. }
  8583. }
  8584. public void get_erp_invoicing()
  8585. {
  8586. if (UrlPostParmsCheck("id"))
  8587. {
  8588. try
  8589. {
  8590. string id = GetPostString("id");
  8591. CeErpBill entiy = CeErpBill.Get(id);
  8592. if (entiy != null)
  8593. {
  8594. if (entiy.state == 0)
  8595. {
  8596. returnErrorMsg("发票还未开具");
  8597. return;
  8598. }
  8599. if (entiy.sendType == "纸质发票")
  8600. {
  8601. if (entiy.img.Length <= 0)
  8602. {
  8603. returnErrorMsg("查无纸质发票");
  8604. return;
  8605. }
  8606. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8607. returnSuccess(returnres);
  8608. return;
  8609. }
  8610. string[] billOrderList = entiy.billOrderId.Split(',');
  8611. int iTag = 0;
  8612. string fpUrl = "";
  8613. entiy.fplsh = "";
  8614. entiy.fpdm = "";
  8615. entiy.fphm = "";
  8616. foreach (string billOrderId in billOrderList)
  8617. {
  8618. iTag++;
  8619. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8620. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8621. {
  8622. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8623. Invoicing_get_response_Obj iObj = null;
  8624. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8625. if (iObj != null)
  8626. {
  8627. //entiy.state = 2;
  8628. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8629. entiy.fpdm += iObj.list[0].c_fpdm;
  8630. entiy.fphm += iObj.list[0].c_fphm;
  8631. if (iTag < billOrderList.Length)
  8632. {
  8633. entiy.fplsh += ",";
  8634. entiy.fpdm += ",";
  8635. entiy.fphm += ",";
  8636. }
  8637. entiy.Update();
  8638. fpUrl += iObj.list[0].c_url + ",";
  8639. }
  8640. //returnSuccess(res);
  8641. StringBuilder sql = new StringBuilder();
  8642. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8643. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8644. }
  8645. else
  8646. {
  8647. int eidx = res.IndexOf("c_resultmsg");
  8648. //int lidx = res.IndexOf("c_status");
  8649. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8650. //开票失败
  8651. entiy.state = 5;
  8652. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8653. entiy.Update();
  8654. returnErrorMsg("开票失败");
  8655. return;
  8656. }
  8657. }
  8658. var returnObj = new
  8659. {
  8660. data = fpUrl
  8661. };
  8662. string ro_json = JsonConvert.SerializeObject(returnObj);
  8663. returnSuccess(ro_json);
  8664. }
  8665. }
  8666. catch (Exception ex)
  8667. {
  8668. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8669. }
  8670. return;
  8671. }
  8672. }
  8673. public void save_erp_billimg()
  8674. {
  8675. if (UrlPostParmsCheck("id"))
  8676. {
  8677. string eid = GetPostString("id");
  8678. CeErpBill bill_entity = null;
  8679. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8680. if (bill_entity != null)
  8681. {
  8682. bill_entity.img = GetPostString("img");
  8683. bill_entity.executeTime = DateTime.Now;
  8684. bill_entity.state = 2;
  8685. bill_entity.Update();
  8686. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8687. returnSuccessMsg("保存成功");
  8688. }
  8689. return;
  8690. }
  8691. }
  8692. public void upd_erp_billreturnback()
  8693. {
  8694. if (UrlPostParmsCheck("id"))
  8695. {
  8696. int eid = GetPostInt("id");
  8697. CeErpBill bill_entity = null;
  8698. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8699. if (bill_entity != null)
  8700. {
  8701. bill_entity.state = 3;
  8702. bill_entity.returnReason = GetPostString("reason");
  8703. bill_entity.Update();
  8704. returnSuccessMsg("驳回成功!");
  8705. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8706. }
  8707. return;
  8708. }
  8709. }
  8710. public void cancel_erp_bill()
  8711. {
  8712. if (UrlPostParmsCheck("id"))
  8713. {
  8714. int eid = GetPostInt("id");
  8715. int detailValue = GetPostInt("detailvalue");
  8716. CeErpBill bill_entity = null;
  8717. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8718. string cres = "";
  8719. string gres = "";
  8720. if (bill_entity != null)
  8721. {
  8722. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8723. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8724. {
  8725. int iTag = 0;
  8726. bill_entity.fplsh = "";
  8727. bill_entity.fpdm = "";
  8728. bill_entity.fphm = "";
  8729. foreach (string billOrderId in billOrderList)
  8730. {
  8731. iTag++;
  8732. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8733. if (gres.IndexOf("success") != -1)
  8734. {
  8735. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8736. Invoicing_get_response_Obj iObj = null;
  8737. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8738. if (iObj != null)
  8739. {
  8740. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8741. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8742. bill_entity.fphm += iObj.list[0].c_fphm;
  8743. if (iTag < billOrderList.Length)
  8744. {
  8745. bill_entity.fplsh += ",";
  8746. bill_entity.fpdm += ",";
  8747. bill_entity.fphm += ",";
  8748. }
  8749. bill_entity.Update();
  8750. }
  8751. }
  8752. else
  8753. {
  8754. returnErrorMsg(gres);
  8755. return;
  8756. }
  8757. }
  8758. }
  8759. if (bill_entity.sendType == "纸质发票")
  8760. {
  8761. //作废
  8762. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8763. //if (DateTime.Now.Month == extime.Month)
  8764. //{
  8765. //cres = taobaoHelper.cancel_invoicing(eid);
  8766. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8767. //{
  8768. bill_entity.state = 4;//已作废
  8769. bill_entity.Update();
  8770. returnSuccessMsg("发票已作废");
  8771. return;
  8772. //}
  8773. //else
  8774. //{
  8775. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8776. // bill_entity.Update();
  8777. // returnErrorMsg(cres);
  8778. // return;
  8779. //}
  8780. //}
  8781. //else
  8782. //{
  8783. // returnErrorMsg("纸质发票只能作废本月的发票");
  8784. // return;
  8785. //}
  8786. }
  8787. //红冲
  8788. int redTag = 0;
  8789. string[] fpdmList = bill_entity.fpdm.Split(',');
  8790. string[] fphmList = bill_entity.fphm.Split(',');
  8791. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8792. {
  8793. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8794. return;
  8795. }
  8796. foreach (string billOrderId in billOrderList)
  8797. {
  8798. redTag++;
  8799. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8800. cres += onecres;
  8801. cres += ",";
  8802. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8803. {
  8804. bill_entity.state = 4;//已作废
  8805. //bill_entity.Update();
  8806. //returnSuccessMsg("发票已红冲");
  8807. }
  8808. else if (onecres.IndexOf("重复冲红") != -1)
  8809. {
  8810. bill_entity.state = 4;//已作废
  8811. //bill_entity.Update();
  8812. //returnSuccessMsg("发票已红冲");
  8813. }
  8814. else
  8815. {
  8816. string errmsg = commonHelper.KeepChinese(onecres);
  8817. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8818. }
  8819. }
  8820. bill_entity.Update();
  8821. if (cres.IndexOf("失败") != -1)
  8822. returnErrorMsg("红冲失败");
  8823. else
  8824. returnSuccessMsg("发票已红冲");
  8825. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8826. return;
  8827. }
  8828. return;
  8829. }
  8830. }
  8831. public void del_erp_billorder()
  8832. {
  8833. if (UrlPostParmsCheck("id"))
  8834. {
  8835. string eid = GetPostString("id");
  8836. CeErpBill.Del(eid);
  8837. CeErpBill bill = CeErpBill.Get(eid);
  8838. if (bill != null)
  8839. {
  8840. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8841. }
  8842. returnSuccessMsg("删除成功");
  8843. }
  8844. }
  8845. public void finish_erp_bill()
  8846. {
  8847. if (UrlPostParmsCheck("ids"))
  8848. {
  8849. string eids = GetPostString("ids");
  8850. string[] list = eids.Split(',');
  8851. foreach (string eid in list)
  8852. {
  8853. CeErpBill bill = CeErpBill.Get(eid);
  8854. if (bill != null)
  8855. {
  8856. bill.state = 2;
  8857. bill.Update();
  8858. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8859. }
  8860. }
  8861. returnSuccessMsg("操作成功");
  8862. }
  8863. }
  8864. public void get_erp_returncash()
  8865. {
  8866. DataStruct dStruct = GetPostStruct();
  8867. List<string> lw = new List<string>();
  8868. string tid = GetPostString("tid");
  8869. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8870. string shopname = GetPostString("shopname");
  8871. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8872. string buyernick = GetPostString("buyer_nick");
  8873. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8874. string customer = GetPostString("customer");
  8875. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8876. string returndate1 = GetPostString("returndate1");
  8877. string returndate2 = GetPostString("returndate2");
  8878. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8879. if (dw.Length > 0) lw.Add(dw);
  8880. string finishDate1 = GetPostString("finishdate1");
  8881. string finishDate2 = GetPostString("finishdate2");
  8882. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8883. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8884. string returntype = GetPostString("returntype");
  8885. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8886. string returnvstate = GetPostString("returnvstate");
  8887. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8888. dStruct.Order = "created desc";
  8889. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8890. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8891. writeGridDataTableJson(dStruct.TotalCount, dt);
  8892. }
  8893. public void get_erp_staygoods()
  8894. {
  8895. DataStruct dStruct = GetPostStruct();
  8896. List<string> lw = new List<string>();
  8897. string tid = GetPostString("tid");
  8898. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8899. string shopname = GetPostString("shopname");
  8900. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8901. string wangwang = GetPostString("wangwang");
  8902. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8903. string customer = GetPostString("customer");
  8904. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8905. string returndate1 = GetPostString("returndate1");
  8906. string returndate2 = GetPostString("returndate2");
  8907. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8908. if (dw.Length > 0) lw.Add(dw);
  8909. string finishDate1 = GetPostString("finishdate1");
  8910. string finishDate2 = GetPostString("finishdate2");
  8911. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8912. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8913. string returnvstate = GetPostString("returnvstate");
  8914. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8915. string persuadetype = GetPostString("persuadetype");
  8916. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8917. string customerOrg = GetPostString("customerOrg");
  8918. if (customerOrg.Length > 0)
  8919. {
  8920. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8921. }
  8922. string designerorg = GetPostString("designerorg");
  8923. if (designerorg.Length > 0)
  8924. {
  8925. lw.Add(string.Format("OrgID = {0}", designerorg));
  8926. }
  8927. dStruct.Order = "creata_time desc";
  8928. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8929. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8930. writeGridDataTableJson(dStruct.TotalCount, dt);
  8931. }
  8932. public void upd_erp_staygoods()
  8933. {
  8934. if (UrlPostParmsCheck("id"))
  8935. {
  8936. int eid = GetPostInt("id");
  8937. CeErpStayGoods entity = null;
  8938. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8939. if (entity != null)
  8940. {
  8941. entity.audit_type = 1;
  8942. entity.audit_time = DateTime.Now;
  8943. entity.audit_u_id = CurrentUser.UserID;
  8944. entity.audit_u_name = CurrentUser.UserName;
  8945. entity.Update();
  8946. returnSuccessMsg("审核成功!");
  8947. return;
  8948. }
  8949. returnErrorMsg("找不到订单记录");
  8950. }
  8951. }
  8952. public void upd_erp_stayGoodsback()
  8953. {
  8954. if (UrlPostParmsCheck("id"))
  8955. {
  8956. int eid = GetPostInt("id");
  8957. CeErpStayGoods entity = null;
  8958. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8959. if (entity != null)
  8960. {
  8961. entity.audit_text = GetPostString("reason");
  8962. entity.audit_type = 2;
  8963. entity.audit_time = DateTime.Now;
  8964. entity.audit_u_id = CurrentUser.UserID;
  8965. entity.audit_u_name = CurrentUser.UserName;
  8966. entity.Update();
  8967. returnSuccessMsg("退回成功!");
  8968. return;
  8969. }
  8970. returnErrorMsg("找不到订单记录");
  8971. }
  8972. }
  8973. public void upd_erp_returncashverify()
  8974. {
  8975. if (UrlPostParmsCheck("ID"))
  8976. {
  8977. int eid = GetPostInt("ID");
  8978. CeErpReturnCash entity = null;
  8979. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8980. if (entity != null)
  8981. {
  8982. entity.cashstate = 1;
  8983. entity.verifytime = DateTime.Now;
  8984. entity.verifyuserid = CurrentUser.UserID;
  8985. entity.Update();
  8986. returnSuccessMsg("审核成功!");
  8987. return;
  8988. }
  8989. returnErrorMsg("找不到订单记录");
  8990. }
  8991. }
  8992. public void upd_all_erp_returncashverify()
  8993. {
  8994. if (UrlPostParmsCheck("ID"))
  8995. {
  8996. String[] list = GetPostString("ID").Split(',');
  8997. CeErpReturnCash entity = null;
  8998. for (int i = 0; i < list.Length; i++)
  8999. {
  9000. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  9001. if (entity != null)
  9002. {
  9003. if (entity.cashstate == 1)
  9004. {
  9005. returnErrorMsg("已审核过的订单不需要在审核!");
  9006. return;
  9007. }
  9008. entity.cashstate = 1;
  9009. entity.verifytime = DateTime.Now;
  9010. entity.verifyuserid = CurrentUser.UserID;
  9011. entity.Update();
  9012. }
  9013. }
  9014. returnSuccessMsg("审核成功!");
  9015. return;
  9016. }
  9017. }
  9018. public void upd_erp_returncashback()
  9019. {
  9020. if (UrlPostParmsCheck("ID"))
  9021. {
  9022. int eid = GetPostInt("ID");
  9023. CeErpReturnCash entity = null;
  9024. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9025. if (entity != null)
  9026. {
  9027. entity.backreason = GetPostString("reason");
  9028. entity.cashstate = 2;
  9029. entity.verifytime = DateTime.Now;
  9030. entity.verifyuserid = CurrentUser.UserID;
  9031. entity.Update();
  9032. returnSuccessMsg("退回成功!");
  9033. return;
  9034. }
  9035. returnErrorMsg("找不到订单记录");
  9036. }
  9037. }
  9038. public void upd_erp_returnprice()
  9039. {
  9040. if (UrlPostParmsCheck("ID"))
  9041. {
  9042. int eid = GetPostInt("ID");
  9043. CeErpReturnCash entity = null;
  9044. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9045. if (entity != null)
  9046. {
  9047. if (entity.cashstate == 1)
  9048. {
  9049. returnErrorMsg("审核通过了不能改");
  9050. return;
  9051. }
  9052. entity.returnprice = GetPostDouble("returnprice");
  9053. entity.Update();
  9054. returnSuccessMsg("修改成功!");
  9055. return;
  9056. }
  9057. returnErrorMsg("找不到订单记录");
  9058. }
  9059. }
  9060. public void del_erp_returncash()
  9061. {
  9062. if (UrlPostParmsCheck("ID"))
  9063. {
  9064. int eid = GetPostInt("ID");
  9065. CeErpReturnCash.Del(eid);
  9066. returnSuccessMsg("操作成功");
  9067. return;
  9068. }
  9069. }
  9070. public void test_for_do_sql()
  9071. {
  9072. string sql = GetPostString("sqlstr");
  9073. if (sql.Length > 0)
  9074. {
  9075. try
  9076. {
  9077. DbHelper.DbConn.ExecuteNonQuery(sql);
  9078. var res_obj = new
  9079. {
  9080. data = "成功",
  9081. };
  9082. string ro_json = JsonConvert.SerializeObject(res_obj);
  9083. returnSuccess(ro_json);
  9084. }
  9085. catch (Exception ex)
  9086. {
  9087. var res_obj = new
  9088. {
  9089. data = ex.Message,
  9090. };
  9091. string ro_json = JsonConvert.SerializeObject(res_obj);
  9092. returnSuccess(ro_json);
  9093. }
  9094. }
  9095. }
  9096. public void get_user_info()
  9097. {
  9098. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9099. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9100. }
  9101. public void get_total_data()
  9102. {
  9103. int userId = CurrentUser.UserID;
  9104. string sql = "";
  9105. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9106. {
  9107. 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);
  9108. }
  9109. else
  9110. {
  9111. 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 " +
  9112. "(select ID from CE_ErpUser where ID = {0}) d " +
  9113. "left join " +
  9114. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9115. ") a on d.ID = a.id left join " +
  9116. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9117. ") b on a.id = b.id1 left join" +
  9118. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9119. ") c on a.id = c.id2;", userId);
  9120. }
  9121. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9122. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9123. }
  9124. public void get_date_area_total_data2()
  9125. {
  9126. int userId = CurrentUser.UserID;
  9127. string date_type = GetPostString("timetype");
  9128. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9129. string sql = "";
  9130. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9131. {
  9132. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9133. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9134. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9135. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9136. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9137. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9138. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9139. ") a on e.ID = a.id left join " +
  9140. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9141. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9142. ") b on a.id = b.id1 " +
  9143. "left join " +
  9144. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9145. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9146. ") c on a.id = c.id2 " +
  9147. "left join " +
  9148. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9149. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9150. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9151. }
  9152. else
  9153. {
  9154. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9155. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9156. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9157. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9158. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9159. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9160. ") a on e.ID = a.id left join " +
  9161. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9162. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9163. ") c on a.id = c.id2 " +
  9164. "left join " +
  9165. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9166. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9167. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9168. }
  9169. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9170. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9171. }
  9172. public void get_date_area_total_data()
  9173. {
  9174. int userId = CurrentUser.UserID;
  9175. string date_type = GetPostString("timetype");
  9176. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9177. string date1 = searchDT[0].ToString();
  9178. string date2 = searchDT[1].ToString();
  9179. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9180. {
  9181. SqlParameter[] sqlParameter ={
  9182. new SqlParameter("@userId", SqlDbType.Int,4),
  9183. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9184. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9185. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9186. };
  9187. sqlParameter[0].Value = userId;
  9188. sqlParameter[1].Value = date1;
  9189. sqlParameter[2].Value = date2;
  9190. sqlParameter[3].Direction = ParameterDirection.Output;
  9191. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9192. string res = sqlParameter[3].Value.ToString();
  9193. var res_obj = new
  9194. {
  9195. data = res
  9196. };
  9197. string ro_json = JsonConvert.SerializeObject(res_obj);
  9198. returnSuccess(ro_json);
  9199. }
  9200. else
  9201. {
  9202. SqlParameter[] sqlParameter ={
  9203. new SqlParameter("@userId", SqlDbType.Int,4),
  9204. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9205. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9206. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9207. };
  9208. sqlParameter[0].Value = userId;
  9209. sqlParameter[1].Value = date1;
  9210. sqlParameter[2].Value = date2;
  9211. sqlParameter[3].Direction = ParameterDirection.Output;
  9212. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9213. string res = sqlParameter[3].Value.ToString();
  9214. var res_obj = new
  9215. {
  9216. data = res
  9217. };
  9218. string ro_json = JsonConvert.SerializeObject(res_obj);
  9219. returnSuccess(ro_json);
  9220. }
  9221. //writeGridDataViewJson(dt.Rows.Count, dv);
  9222. }
  9223. public void get_order_list()
  9224. {
  9225. string strFields = GetPostString("paraFields");
  9226. string strOrder = GetPostString("paraOrder");
  9227. string strWhere = GetPostString("paraWhere");
  9228. string strPageSize = GetPostString("paraPageSize");
  9229. DataStruct dStruct = GetPostStruct();
  9230. dStruct.PageSize = int.Parse(strPageSize);
  9231. dStruct.Fileds = strFields;
  9232. dStruct.Order = strOrder;
  9233. dStruct.MainWhere = strWhere;
  9234. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9235. writeGridDataTableJson(dStruct.TotalCount, dt);
  9236. }
  9237. ////获取待开始订单列表
  9238. //public void get_wait_design_order_list()
  9239. //{
  9240. // string date_type = GetPostString("date_type");
  9241. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9242. // DataStruct dStruct = GetPostStruct();
  9243. // dStruct.PageSize = 1000;
  9244. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9245. // List<string> lw = new List<string>();
  9246. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9247. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9248. // dStruct.Order = "WaitDesignTime asc";
  9249. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9250. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9251. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9252. //}
  9253. //获取完成单量排名
  9254. public void get_finish_order_count_ranking()
  9255. {
  9256. /* string date_type = GetPostString("date_type");
  9257. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9258. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9259. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9260. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9261. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9262. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9263. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9264. writeGridDataTableJson(0, new DataTable());
  9265. }
  9266. public void get_finish_order_amount_ranking()
  9267. {
  9268. /*string date_type = GetPostString("date_type");
  9269. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9270. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9271. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9272. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9273. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9274. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9275. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9276. writeGridDataTableJson(0, new DataTable());
  9277. }
  9278. public void get_finish_refund_count_ranking()
  9279. {
  9280. string date_type = GetPostString("date_type");
  9281. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9282. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9283. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9284. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9285. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9286. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9287. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9288. writeGridDataTableJson(dt.Rows.Count, dt);
  9289. }
  9290. public void get_finish_refund_amount_ranking()
  9291. {
  9292. string date_type = GetPostString("date_type");
  9293. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9294. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9295. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9296. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9297. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9298. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9299. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9300. writeGridDataTableJson(dt.Rows.Count, dt);
  9301. }
  9302. public void set_erp_finishorder_director()
  9303. {
  9304. if (UrlPostParmsCheck("ctid"))
  9305. {
  9306. string eid = GetPostString("ctid");
  9307. CeErpTradeCell entity = null;
  9308. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9309. if (entity != null)
  9310. {
  9311. entity.OrderState = 8;
  9312. entity.Update();
  9313. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9314. returnSuccessMsg("操作成功!");
  9315. return;
  9316. }
  9317. returnErrorMsg("找不到记录");
  9318. }
  9319. }
  9320. public void get_erp_placeregistlist()
  9321. {
  9322. DataStruct dStruct = GetPostStruct();
  9323. List<string> lw = new List<string>();
  9324. string outsid = GetPostString("outsid");
  9325. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9326. string memo = GetPostString("memo");
  9327. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9328. string filename = GetPostString("filename");
  9329. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9330. string islate = GetPostString("islate");
  9331. if (islate.Length > 0)
  9332. {
  9333. if (islate == "1")
  9334. lw.Add(string.Format("OutLate>0"));
  9335. else
  9336. lw.Add(string.Format("OutLate=0"));
  9337. }
  9338. string placedate1 = GetPostString("placedate1");
  9339. string placedate2 = GetPostString("placedate2");
  9340. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9341. if (dw.Length > 0) lw.Add(dw);
  9342. string deliveryDate1 = GetPostString("deliverydate1");
  9343. string deliveryDate2 = GetPostString("deliverydate2");
  9344. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9345. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9346. dStruct.Order = "ID desc";
  9347. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9348. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9349. writeGridDataTableJson(dStruct.TotalCount, dt);
  9350. }
  9351. public void ins_erp_placeregist()
  9352. {
  9353. if (UrlPostParmsCheck("id"))
  9354. {
  9355. string eid = GetPostString("id");
  9356. CeErpPlaceRegister entity = null;
  9357. if (eid == "0")//新增
  9358. {
  9359. entity = new CeErpPlaceRegister();
  9360. string xdTime = GetPostString("placeTime");
  9361. if (xdTime.Length > 0)
  9362. {
  9363. entity.PlactTime = Convert.ToDateTime(xdTime);
  9364. }
  9365. string fhTime = GetPostString("deliveryTime");
  9366. if (fhTime.Length > 0)
  9367. {
  9368. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9369. }
  9370. string preTime = GetPostString("preOutTime");
  9371. if (preTime.Length > 0)
  9372. {
  9373. entity.PreOutTime = Convert.ToDateTime(preTime);
  9374. }
  9375. entity.DeliveryCount = GetPostInt("deliveryCount");
  9376. entity.ReceiveCount = GetPostInt("receiveCount");
  9377. entity.OutSid = GetPostString("outSid");
  9378. entity.FileName = GetPostString("fileName");
  9379. entity.Memo = GetPostString("memo");
  9380. entity.AddUserId = CurrentUser.UserID;
  9381. entity.CreateTime = DateTime.Now;
  9382. entity.Img = GetPostString("img");
  9383. entity.Supplier = GetPostInt("supplier");
  9384. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9385. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9386. {
  9387. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9388. DateTime dt2 = (DateTime)entity.PreOutTime;
  9389. TimeSpan span = dt1.Subtract(dt2);
  9390. if (span.Days > 0)
  9391. {
  9392. entity.OutLate = span.Days;
  9393. }
  9394. }
  9395. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9396. entity.Create();
  9397. returnSuccessMsg("添加成功!");
  9398. return;
  9399. }
  9400. else //修改
  9401. {
  9402. entity = CeErpPlaceRegister.Get(eid);
  9403. if (entity != null)
  9404. {
  9405. string xdTime = GetPostString("placeTime");
  9406. if (xdTime.Length > 0)
  9407. {
  9408. entity.PlactTime = Convert.ToDateTime(xdTime);
  9409. }
  9410. string fhTime = GetPostString("deliveryTime");
  9411. if (fhTime.Length > 0)
  9412. {
  9413. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9414. }
  9415. string preTime = GetPostString("preOutTime");
  9416. if (preTime.Length > 0)
  9417. {
  9418. entity.PreOutTime = Convert.ToDateTime(preTime);
  9419. }
  9420. entity.DeliveryCount = GetPostInt("deliveryCount");
  9421. entity.ReceiveCount = GetPostInt("receiveCount");
  9422. if (entity.DeliveryCount == entity.ReceiveCount)
  9423. {
  9424. entity.CurState = "已完成";
  9425. }
  9426. else
  9427. {
  9428. entity.CurState = "未完成";
  9429. }
  9430. entity.OutSid = GetPostString("outSid");
  9431. entity.FileName = GetPostString("fileName");
  9432. entity.Memo = GetPostString("memo");
  9433. entity.Img = GetPostString("img");
  9434. entity.Supplier = GetPostInt("supplier");
  9435. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9436. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9437. {
  9438. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9439. DateTime dt2 = (DateTime)entity.PreOutTime;
  9440. TimeSpan span = dt1.Subtract(dt2);
  9441. if (span.Days > 0)
  9442. {
  9443. entity.OutLate = span.Days;
  9444. }
  9445. }
  9446. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9447. entity.Update();
  9448. returnSuccessMsg("修改成功");
  9449. return;
  9450. }
  9451. returnErrorMsg("找不到对应的记录");
  9452. return;
  9453. }
  9454. }
  9455. returnErrorMsg("缺少必要参数");
  9456. }
  9457. public void del_erp_placeregist()
  9458. {
  9459. string eid = GetPostString("id");
  9460. CeErpPlaceRegister.Del(eid);
  9461. returnSuccessMsg("删除成功!");
  9462. return;
  9463. }
  9464. public void ins_erp_placeregistbyorder()
  9465. {
  9466. string ctid = GetPostString("ctid");
  9467. if (ctid.Length > 0)
  9468. {
  9469. StringBuilder sql = new StringBuilder();
  9470. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9471. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9472. if (dt.Rows.Count > 0)
  9473. {
  9474. foreach (DataRow dr in dt.Rows)
  9475. {
  9476. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9477. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9478. entity.AddUserId = CurrentUser.UserID;
  9479. entity.tid = dr["tid"].ToString();
  9480. entity.Did = Convert.ToString(dr["ctid"]);
  9481. entity.splitTag = dr["SplitTag"].ToString();
  9482. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9483. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9484. if (pre_ctid.Length > 0)
  9485. {
  9486. sellmemo = sellmemo.Replace(pre_ctid, "");
  9487. }
  9488. sellmemo = sellmemo.Replace("[", "");
  9489. sellmemo = sellmemo.Replace("]", "");
  9490. entity.FileName = sellmemo;
  9491. string count = dr["ProductCount"].ToString();
  9492. int usecount = commonHelper.getIntCountFromString(count);
  9493. entity.DeliveryCount = usecount;
  9494. entity.CurState = "未完成";
  9495. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9496. {
  9497. entity.Supplier = 24;//dl手提袋定制
  9498. }
  9499. else
  9500. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9501. entity.CreateTime = DateTime.Now;
  9502. entity.Create();
  9503. }
  9504. returnSuccessMsg("操作成功");
  9505. return;
  9506. }
  9507. returnErrorMsg("没有找到对应订单");
  9508. return;
  9509. }
  9510. returnErrorMsg("缺少订单编号");
  9511. return;
  9512. }
  9513. public void get_erp_persuadelist()
  9514. {
  9515. DataStruct dStruct = GetPostStruct();
  9516. List<string> lw = new List<string>();
  9517. string ctid = GetPostString("ctid");
  9518. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9519. string shopname = GetPostString("shopname");
  9520. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9521. string buyernick = GetPostString("buyer_nick");
  9522. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9523. string customer = GetPostString("customer");
  9524. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9525. string returndate1 = GetPostString("returndate1");
  9526. string returndate2 = GetPostString("returndate2");
  9527. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9528. if (dw.Length > 0) lw.Add(dw);
  9529. string finishDate1 = GetPostString("finishdate1");
  9530. string finishDate2 = GetPostString("finishdate2");
  9531. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9532. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9533. string persuadetype = GetPostString("persuadetype");
  9534. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9535. string returnvstate = GetPostString("returnvstate");
  9536. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9537. dStruct.Order = "created desc";
  9538. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9539. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9540. writeGridDataTableJson(dStruct.TotalCount, dt);
  9541. }
  9542. public void upd_erp_returnpersuadeback()
  9543. {
  9544. if (UrlPostParmsCheck("ID"))
  9545. {
  9546. int eid = GetPostInt("ID");
  9547. CeErpPersuade entity = null;
  9548. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9549. if (entity != null)
  9550. {
  9551. entity.backreason = GetPostString("reason");
  9552. entity.pstate = 2;
  9553. entity.verifytime = DateTime.Now;
  9554. entity.verifyuserid = CurrentUser.UserID;
  9555. entity.Update();
  9556. returnSuccessMsg("退回成功!");
  9557. return;
  9558. }
  9559. returnErrorMsg("找不到订单记录");
  9560. }
  9561. }
  9562. public void upd_erp_returnpersuadeverify()
  9563. {
  9564. if (UrlPostParmsCheck("ID"))
  9565. {
  9566. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9567. {
  9568. returnErrorMsg("暂无权限审核");
  9569. return;
  9570. }
  9571. int eid = GetPostInt("ID");
  9572. CeErpPersuade entity = null;
  9573. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9574. if (entity != null)
  9575. {
  9576. entity.pstate = 1;
  9577. entity.verifytime = DateTime.Now;
  9578. entity.verifyuserid = CurrentUser.UserID;
  9579. entity.Update();
  9580. returnSuccessMsg("审核成功!");
  9581. return;
  9582. }
  9583. returnErrorMsg("找不到订单记录");
  9584. }
  9585. }
  9586. public void del_erp_persuade()
  9587. {
  9588. if (UrlPostParmsCheck("ID"))
  9589. {
  9590. int eid = GetPostInt("ID");
  9591. CeErpPersuade.Del(eid);
  9592. returnSuccessMsg("操作成功");
  9593. return;
  9594. }
  9595. }
  9596. public void get_erp_oldcustoupload()
  9597. {
  9598. DataStruct dStruct = GetPostStruct();
  9599. List<string> lw = new List<string>();
  9600. string buyernick = GetPostString("buyer_nick");
  9601. if (buyernick.Length > 0)
  9602. {
  9603. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9604. }
  9605. else
  9606. return;
  9607. dStruct.Order = "pay_time desc";
  9608. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9609. DataTable dt = null;
  9610. dt = WebCache.GetData("view_erptradecell", dStruct);
  9611. writeGridDataTableJson(dStruct.TotalCount, dt);
  9612. }
  9613. public void get_erp_checkorderlist()
  9614. {
  9615. DataStruct dStruct = GetPostStruct();
  9616. List<string> lw = new List<string>();
  9617. string tid = GetPostString("ctid");
  9618. if (tid.Length > 0)
  9619. {
  9620. string select_tid = getTidByCtid(tid);
  9621. lw.Add(string.Format("tid='{0}'", select_tid));
  9622. }
  9623. string shopname = GetPostString("shopname");
  9624. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9625. string buyernick = GetPostString("buyer_nick");
  9626. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9627. string customer = GetPostString("customer");
  9628. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9629. string design = GetPostString("design");
  9630. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9631. string orderState = GetPostString("orderState");
  9632. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9633. string address = GetPostString("address");
  9634. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9635. string sellermemo = GetPostString("seller_memo");
  9636. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9637. string supplier = GetPostString("supplier");
  9638. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9639. {
  9640. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9641. }
  9642. else
  9643. {
  9644. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9645. }
  9646. string date1 = GetPostString("date1");
  9647. string date2 = GetPostString("date2");
  9648. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9649. if (dw.Length > 0) lw.Add(dw);
  9650. string placedate1 = GetPostString("placedate1");
  9651. string placedate2 = GetPostString("placedate2");
  9652. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9653. if (fdw.Length > 0) lw.Add(fdw);
  9654. string price1 = GetPostString("price1");
  9655. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9656. string price2 = GetPostString("price2");
  9657. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9658. string checkst = GetPostString("checkstate");
  9659. if (checkst.Length > 0 && "10".Equals(checkst))
  9660. {
  9661. lw.Add(string.Format("CheckOut>0"));
  9662. }
  9663. else
  9664. {
  9665. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9666. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9667. }
  9668. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9669. {
  9670. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9671. }
  9672. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9673. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9674. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9675. writeGridDataTableJson(dStruct.TotalCount, dt);
  9676. }
  9677. public void ins_erp_startCheck()
  9678. {
  9679. if (UrlPostParmsCheck("ctid"))
  9680. {
  9681. string eid = GetPostString("ctid");
  9682. CeErpTradeCell entity = null;
  9683. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9684. if (entity != null)
  9685. {
  9686. entity.MemoOpt = 4;
  9687. entity.UpdateTime = DateTime.Now;
  9688. entity.Update();
  9689. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9690. CeErpSukuraData.createInfo(entity.ctid, 6);
  9691. returnSuccessMsg("操作成功!");
  9692. return;
  9693. }
  9694. returnErrorMsg("找不到记录");
  9695. }
  9696. }
  9697. public void upd_erp_sendXlw()
  9698. {
  9699. if (UrlPostParmsCheck("ctid"))
  9700. {
  9701. string eid = GetPostString("ctid");
  9702. CeErpTradeCell entity = null;
  9703. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9704. if (entity != null)
  9705. {
  9706. if (entity.IsSendGift == 1)
  9707. {
  9708. returnErrorMsg("请勿重复标记");
  9709. return;
  9710. }
  9711. entity.IsSendGift = 1;
  9712. entity.Update();
  9713. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9714. returnSuccessMsg("操作成功!");
  9715. return;
  9716. }
  9717. returnErrorMsg("找不到记录");
  9718. }
  9719. }
  9720. public void cancel_sendXlw()
  9721. {
  9722. if (UrlPostParmsCheck("ctid"))
  9723. {
  9724. string eid = GetPostString("ctid");
  9725. CeErpTradeCell entity = null;
  9726. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9727. if (entity != null)
  9728. {
  9729. if (entity.IsSendGift == 0)
  9730. {
  9731. returnErrorMsg("未标记小礼物");
  9732. return;
  9733. }
  9734. entity.IsSendGift = 0;
  9735. entity.Update();
  9736. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9737. returnSuccessMsg("操作成功!");
  9738. return;
  9739. }
  9740. returnErrorMsg("找不到记录");
  9741. }
  9742. }
  9743. public void get_erp_designbill()
  9744. {
  9745. DataStruct dStruct = GetPostStruct();
  9746. List<string> lw = new List<string>();
  9747. int isMy = GetInt("my");
  9748. if (isMy == 1)
  9749. {
  9750. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9751. }
  9752. string tid = GetPostString("tid");
  9753. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9754. string userName = GetPostString("design");
  9755. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9756. string price1 = GetPostString("price1");
  9757. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9758. string price2 = GetPostString("price2");
  9759. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9760. string rePrice1 = GetPostString("rePrice1");
  9761. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9762. string rePrice2 = GetPostString("rePrice2");
  9763. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9764. string designerType = GetPostString("designerType");
  9765. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9766. string orderState = GetPostString("orderState");
  9767. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9768. string endTime1 = GetPostString("endTime1");
  9769. string endTime2 = GetPostString("endTime2");
  9770. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9771. if (dw.Length > 0) lw.Add(dw);
  9772. string isDk = GetPostString("isDk");
  9773. if (isDk == "1")
  9774. {
  9775. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9776. }
  9777. else if (isDk == "0")
  9778. {
  9779. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9780. }
  9781. dStruct.Order = "oid, create_time desc";
  9782. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9783. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9784. writeGridDataTableJson(dStruct.TotalCount, dt);
  9785. }
  9786. public void upd_erp_designerbill()
  9787. {
  9788. if (UrlPostParmsCheck("ID"))
  9789. {
  9790. string eid = GetPostString("ID");
  9791. CeErpDesignerBill entity = null;
  9792. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9793. if (entity != null)
  9794. {
  9795. if (GetPostDouble("designerpirce") > 0)
  9796. {
  9797. entity.realPrice = GetPostDouble("designerpirce");
  9798. entity.update_time = DateTime.Now;
  9799. entity.update_u_id = CurrentUser.UserID;
  9800. entity.update_u_name = CurrentUser.UserName;
  9801. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9802. entity.Update();
  9803. returnSuccessMsg("操作成功!");
  9804. return;
  9805. }
  9806. else
  9807. {
  9808. entity.price = GetPostDouble("price");
  9809. entity.update_time = DateTime.Now;
  9810. entity.update_u_id = CurrentUser.UserID;
  9811. entity.update_u_name = CurrentUser.UserName;
  9812. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9813. entity.Update();
  9814. returnSuccessMsg("操作成功!");
  9815. return;
  9816. }
  9817. }
  9818. returnErrorMsg("找不到记录");
  9819. }
  9820. }
  9821. public void audit_erp_designerbill()
  9822. {
  9823. if (UrlPostParmsCheck("ID"))
  9824. {
  9825. string eid = GetPostString("ID");
  9826. CeErpDesignerBill entity = null;
  9827. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9828. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9829. if (entity != null)
  9830. {
  9831. entity.realPrice = GetPostDouble("designerpirce");
  9832. entity.update_time = DateTime.Now;
  9833. entity.update_u_id = CurrentUser.UserID;
  9834. entity.update_u_name = CurrentUser.UserName;
  9835. entity.isAudit = 1;
  9836. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9837. entity.Update();
  9838. if (orderEntity != null)
  9839. {
  9840. orderEntity.IsReadTag = 3;
  9841. orderEntity.Update();
  9842. }
  9843. returnSuccessMsg("操作成功!");
  9844. return;
  9845. }
  9846. returnErrorMsg("找不到记录");
  9847. }
  9848. }
  9849. public void all_audit_erp_designerbill()
  9850. {
  9851. if (UrlPostParmsCheck("idList"))
  9852. {
  9853. string[] list = GetPostString("idList").Split(',');
  9854. CeErpDesignerBill entity = null;
  9855. for (int i = 0; i < list.Length; i++)
  9856. {
  9857. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9858. if (entity == null) return;
  9859. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9860. if (orderEntity == null) return;
  9861. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9862. entity.update_time = DateTime.Now;
  9863. entity.update_u_id = CurrentUser.UserID;
  9864. entity.update_u_name = CurrentUser.UserName;
  9865. entity.isAudit = 1;
  9866. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9867. entity.Update();
  9868. orderEntity.IsReadTag = 3;
  9869. orderEntity.Update();
  9870. }
  9871. returnSuccessMsg("操作成功!");
  9872. return;
  9873. }
  9874. }
  9875. public void get_erp_sameorders()
  9876. {
  9877. if (UrlPostParmsCheck("ctid"))
  9878. {
  9879. string eid = GetPostString("ctid");
  9880. CeErpTradeCell entity = null;
  9881. entity = CeErpTradeCell.GetByCtid(eid);
  9882. if (entity != null)
  9883. {
  9884. StringBuilder sql = new StringBuilder();
  9885. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9886. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9887. var res = new
  9888. {
  9889. data = dt.Rows.Count
  9890. };
  9891. string ro_jsond = JsonConvert.SerializeObject(res);
  9892. returnSuccess(ro_jsond);
  9893. return;
  9894. }
  9895. returnErrorMsg("未找到订单");
  9896. return;
  9897. }
  9898. returnErrorMsg("缺少必要的参数");
  9899. }
  9900. public void get_erp_islasthavesameorder()
  9901. {
  9902. if (UrlPostParmsCheck("ctid"))
  9903. {
  9904. string eid = GetPostString("ctid");
  9905. string[] ctidList = eid.Split(',');
  9906. StringBuilder sql = new StringBuilder();
  9907. string tisCtid = "";
  9908. foreach (string ctid in ctidList)
  9909. {
  9910. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9911. if (entity != null)
  9912. {
  9913. sql = new StringBuilder();
  9914. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9915. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9916. if (dth.Rows.Count > 0)
  9917. {
  9918. tisCtid += entity.ctid;
  9919. tisCtid += ",";
  9920. }
  9921. }
  9922. }
  9923. if (tisCtid.Length > 0)
  9924. {
  9925. var res = new
  9926. {
  9927. data = tisCtid
  9928. };
  9929. string ro_jsond = JsonConvert.SerializeObject(res);
  9930. returnSuccess(ro_jsond);
  9931. }
  9932. else
  9933. {
  9934. var res = new
  9935. {
  9936. data = ""
  9937. };
  9938. string ro_jsond = JsonConvert.SerializeObject(res);
  9939. returnSuccess(ro_jsond);
  9940. }
  9941. return;
  9942. }
  9943. returnErrorMsg("缺少必要的参数");
  9944. }
  9945. public void file_client_down_url()
  9946. {
  9947. if (!UrlPostParmsCheck("userId"))
  9948. {
  9949. returnErrorMsg("缺少必要的参数");
  9950. }
  9951. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9952. }
  9953. public void checkout_form_data()
  9954. {
  9955. if (!UrlPostParmsCheck("tid"))
  9956. {
  9957. returnErrorMsg("缺少必要的参数");
  9958. }
  9959. string tid = GetPostString("tid");
  9960. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9961. if (ceErpOrderFormData != null)
  9962. {
  9963. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9964. returnSuccess(ro_jsond);
  9965. return;
  9966. }
  9967. returnErrorMsg("尚未有文件!");
  9968. }
  9969. public void back_supplier_audit()
  9970. {
  9971. int userId = CurrentUser.UserID;
  9972. StringBuilder sql = new StringBuilder();
  9973. 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);
  9974. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9975. if (dt.Rows.Count > 0)
  9976. {
  9977. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9978. }
  9979. else
  9980. {
  9981. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9982. }
  9983. }
  9984. public void back_supplier_query()
  9985. {
  9986. string eid = GetPostString("ctid");
  9987. if (eid != "")
  9988. {
  9989. StringBuilder sql = new StringBuilder();
  9990. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9991. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9992. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9993. }
  9994. else
  9995. {
  9996. returnErrorMsg("找不到订单记录");
  9997. return;
  9998. }
  9999. }
  10000. public void verified_to_order()
  10001. {
  10002. int userId = CurrentUser.UserID;
  10003. StringBuilder sql = new StringBuilder();
  10004. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  10005. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10006. if (dt.Rows.Count > 0)
  10007. {
  10008. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10009. }
  10010. else
  10011. {
  10012. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10013. }
  10014. }
  10015. public void upd_supplier_audit()
  10016. {
  10017. if (UrlPostParmsCheck("ctid"))
  10018. {
  10019. string eid = GetPostString("ctid");
  10020. string reason = GetPostString("returnreason");
  10021. CeErpTradeCell entity = null;
  10022. CeWithdraw withdraw = null;
  10023. withdraw = CeWithdraw.GetByTid(eid);
  10024. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  10025. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  10026. {
  10027. if (withdraw != null)
  10028. {
  10029. if (!withdraw.userid.Equals(CurrentUser.UserID))
  10030. {
  10031. returnSuccessMsg("您没有权限操作!");
  10032. return;
  10033. }
  10034. else
  10035. {
  10036. if (reason.Equals("1"))
  10037. {
  10038. if (entity.OrderState == -1)
  10039. {
  10040. if (entity.FinishPlaceTime == null)
  10041. {
  10042. entity.OrderState = 2;
  10043. }
  10044. else
  10045. {
  10046. entity.OrderState = 6;
  10047. }
  10048. }
  10049. entity.Update();
  10050. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10051. if (withdraw != null)
  10052. {
  10053. withdraw.status = int.Parse(reason);
  10054. withdraw.Update();
  10055. }
  10056. returnSuccessMsg("操作成功!");
  10057. return;
  10058. }
  10059. else
  10060. {
  10061. withdraw.status = int.Parse(reason);
  10062. withdraw.acknowledgingtime = DateTime.Now;
  10063. withdraw.Update();
  10064. returnSuccessMsg("查看详细请点击线下订单查询");
  10065. return;
  10066. }
  10067. }
  10068. }
  10069. // 第一个字符是 'N'
  10070. }
  10071. if (eid[0] != 'N')
  10072. {
  10073. }
  10074. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10075. {
  10076. entity.IsVerifyToSupplier = false;
  10077. entity.IsReturn = 1;
  10078. entity.ReturnTime = DateTime.Now;
  10079. entity.ReturnReason = reason;
  10080. if (entity.OrderState == 6)
  10081. {
  10082. entity.OrderState = 5;
  10083. }
  10084. entity.Update();
  10085. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10086. if (withdraw != null)
  10087. {
  10088. withdraw.status = int.Parse(reason);
  10089. withdraw.Update();
  10090. }
  10091. returnSuccessMsg("操作成功!");
  10092. return;
  10093. }
  10094. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10095. {
  10096. ;
  10097. if (withdraw != null)
  10098. {
  10099. withdraw.status = int.Parse(reason);
  10100. withdraw.acknowledgingtime = DateTime.Now;
  10101. withdraw.Update();
  10102. returnSuccessMsg("供应商取消撤回!");
  10103. return;
  10104. }
  10105. }
  10106. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10107. {
  10108. if (entity.OrderState == -1)
  10109. {
  10110. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10111. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10112. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10113. {
  10114. returnErrorMsg("台湾客户需填写身份证!");
  10115. return;
  10116. }
  10117. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10118. {
  10119. returnErrorMsg("偏远地区需要填写物流费!");
  10120. return;
  10121. }
  10122. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10123. {
  10124. returnErrorMsg("订单spu没有确认无法通过审核!");
  10125. return;
  10126. }
  10127. if (entity.FinishPlaceTime == null)
  10128. {
  10129. entity.OrderState = 2;
  10130. }
  10131. else
  10132. {
  10133. entity.OrderState = 3;
  10134. }
  10135. commonHelper.getCytPrice(entity);
  10136. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10137. {
  10138. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10139. }
  10140. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10141. {
  10142. entity.OrderState = 6;
  10143. }
  10144. }
  10145. entity.Update();
  10146. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10147. if (withdraw != null)
  10148. {
  10149. withdraw.status = int.Parse(reason);
  10150. withdraw.Update();
  10151. }
  10152. returnSuccessMsg("操作成功!");
  10153. return;
  10154. }
  10155. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10156. {
  10157. if (withdraw == null)
  10158. {
  10159. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10160. return;
  10161. }
  10162. }
  10163. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10164. {
  10165. if (withdraw != null)
  10166. {
  10167. withdraw.status = int.Parse(reason);
  10168. withdraw.acknowledgingtime = DateTime.Now;
  10169. withdraw.Update();
  10170. returnSuccessMsg("查看详细请点击线下订单查询");
  10171. return;
  10172. }
  10173. }
  10174. return;
  10175. }
  10176. }
  10177. //校验报价
  10178. public void refund_order_tip()
  10179. {
  10180. int userid = CurrentUser.UserID;
  10181. int sectionId = CurrentUser.UserPost.OrgID;
  10182. StringBuilder sql = new StringBuilder();
  10183. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10184. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10185. List<string> ids = new List<string>();
  10186. if (dth.Rows.Count > 0)
  10187. {
  10188. foreach (DataRow dr in dth.Rows)
  10189. {
  10190. ids.Add(dr["ID"].ToString());
  10191. }
  10192. try
  10193. {
  10194. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10195. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10196. }
  10197. catch (Exception ex)
  10198. {
  10199. }
  10200. }
  10201. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10202. }
  10203. public void refund_order_Design()
  10204. {
  10205. int userid = CurrentUser.UserID;
  10206. int sectionId = CurrentUser.UserPost.OrgID;
  10207. StringBuilder sql = new StringBuilder();
  10208. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10209. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10210. List<string> ids = new List<string>();
  10211. if (dth.Rows.Count > 0)
  10212. {
  10213. foreach (DataRow dr in dth.Rows)
  10214. {
  10215. ids.Add(dr["ID"].ToString());
  10216. }
  10217. try
  10218. {
  10219. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10220. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10221. }
  10222. catch (Exception ex)
  10223. {
  10224. }
  10225. }
  10226. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10227. }
  10228. public void change_order_info()
  10229. {
  10230. int userid = CurrentUser.UserID;
  10231. StringBuilder sql = new StringBuilder();
  10232. 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);
  10233. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10234. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10235. }
  10236. public void change_win_mome()
  10237. {
  10238. if (UrlPostParmsCheck("id,ctid"))
  10239. {
  10240. string id = GetPostString("id");
  10241. string ctid = GetPostString("ctid");
  10242. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10243. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10244. if (ce == null || ceErpMessageTip == null)
  10245. {
  10246. returnSuccessMsg("未找到对应的订单!");
  10247. return;
  10248. }
  10249. if (ce.OrderState >= 5)
  10250. {
  10251. ceErpMessageTip.isVisit = true;
  10252. ceErpMessageTip.Update();
  10253. returnSuccessMsg("已上传文件无法修改!");
  10254. return;
  10255. }
  10256. int type = GetPostInt("type");
  10257. string content = GetPostString("content");
  10258. if (type == 0)
  10259. {
  10260. content = content.Replace("(", "(");
  10261. content = content.Replace(")", ")");
  10262. string check = MidStrEx(content, "(", ")").Trim();
  10263. if (string.IsNullOrEmpty(check))
  10264. {
  10265. returnSuccessMsg("文件名格式不正确");
  10266. return;
  10267. }
  10268. }
  10269. ce.seller_memo = content;
  10270. ce.Update();
  10271. ceErpMessageTip.isVisit = true;
  10272. ceErpMessageTip.Update();
  10273. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10274. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10275. ApiVo apiVo = new ApiVo();
  10276. apiVo.orderNumber = ce.ctid;
  10277. apiVo.actionName = "demandDesign";
  10278. apiVo.orderRemarks = content;
  10279. apiVo.demandExamine = type + 1;
  10280. designHelper.API_WorkCore(apiVo);//demandDesign
  10281. returnSuccessMsg("修改成功!");
  10282. }
  10283. }
  10284. public static string MidStrEx(string sourse, string startstr, string endstr)
  10285. {
  10286. string result = string.Empty;
  10287. int startindex, endindex;
  10288. try
  10289. {
  10290. startindex = sourse.IndexOf(startstr);
  10291. if (startindex == -1)
  10292. return result;
  10293. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10294. endindex = tmpstr.IndexOf(endstr);
  10295. if (endindex == -1)
  10296. return result;
  10297. result = tmpstr.Remove(endindex);
  10298. }
  10299. catch (Exception ex)
  10300. {
  10301. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10302. }
  10303. return result;
  10304. }
  10305. public void refund_order_list()
  10306. {
  10307. int userid = CurrentUser.UserID;
  10308. int sectionId = CurrentUser.UserPost.OrgID;
  10309. StringBuilder sql = new StringBuilder();
  10310. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10311. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10312. DataStruct dStruct = GetPostStruct();
  10313. DataTable dt = null;
  10314. List<string> ids = new List<string>();
  10315. List<string> tids = new List<string>();
  10316. if (dth.Rows.Count > 0)
  10317. {
  10318. foreach (DataRow dr in dth.Rows)
  10319. {
  10320. tids.Add("'" + dr["tid"].ToString() + "'");
  10321. ids.Add(dr["id"].ToString());
  10322. }
  10323. try
  10324. {
  10325. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10326. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10327. List<string> lw = new List<string>();
  10328. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10329. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10330. dt = WebCache.GetData("view_orderlist", dStruct);
  10331. }
  10332. catch (Exception ex)
  10333. {
  10334. }
  10335. }
  10336. writeGridDataTableJson(dStruct.TotalCount, dt);
  10337. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10338. }
  10339. //新增
  10340. public void order_batch_downloads()
  10341. {
  10342. string ceid = GetPostString("tid");
  10343. String[] tid = ceid.Split(',');
  10344. order_batch_caiyingtong(tid);
  10345. /* (string success, string errors) = UploadFiles(tid);
  10346. returnSuccessMsg(success + errors);*/
  10347. return;
  10348. }
  10349. //报价接口
  10350. public void Get_To_Quote()
  10351. {
  10352. string ceid = GetPostString("ctid");
  10353. if (ceid != null)
  10354. {
  10355. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10356. if (entity != null)
  10357. {
  10358. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10359. {
  10360. return;
  10361. }
  10362. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10363. double price = 0;
  10364. if (cp == null)
  10365. {
  10366. JObject jsonObject12 = new JObject
  10367. {
  10368. { "UserId", "77886" },
  10369. { "Pwd", "lt666888" },
  10370. { "Filename", entity.seller_memo }
  10371. };
  10372. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10373. JObject jsonObjects1 = JObject.Parse(response1);
  10374. string ms1g = (string)jsonObjects1["msg"];
  10375. if (ms1g == "报价成功")
  10376. {
  10377. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10378. string data = (string)jsonObject1["price"];
  10379. 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 + "');";
  10380. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10381. returnSuccessMsg("获取报价成功:" + data);
  10382. price = Convert.ToDouble(data);
  10383. }
  10384. else
  10385. {
  10386. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10387. return;
  10388. }
  10389. }
  10390. String[] beizhu = entity.seller_memo.Split('-');
  10391. String chanp = "";
  10392. if (beizhu.Length > 0)
  10393. {
  10394. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10395. }
  10396. else
  10397. {
  10398. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10399. }
  10400. JObject jsonObject = new JObject
  10401. {
  10402. { "UserId", "77886" },
  10403. { "Pwd", "lt666888" },
  10404. { "Filename", chanp }
  10405. };
  10406. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10407. JObject jsonObjects = JObject.Parse(response);
  10408. string msg = (string)jsonObjects["msg"];
  10409. if (msg == "报价成功")
  10410. {
  10411. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10412. string data = (string)jsonObject1["price"];
  10413. 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 + "');";
  10414. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10415. returnSuccessMsg("获取报价成功:" + data);
  10416. price = Convert.ToDouble(data);
  10417. }
  10418. else
  10419. {
  10420. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10421. return;
  10422. }
  10423. if (price > 0)
  10424. {
  10425. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10426. if (ceErpTradeCellExtend == null)
  10427. {
  10428. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10429. ceErpTradeCellExtend.ctid = entity.ctid;
  10430. ceErpTradeCellExtend.payment_cyt = price;
  10431. ceErpTradeCellExtend.Create();
  10432. }
  10433. else
  10434. {
  10435. ceErpTradeCellExtend.payment_cyt = price;
  10436. ceErpTradeCellExtend.Update();
  10437. }
  10438. }
  10439. return;
  10440. }
  10441. }
  10442. else
  10443. {
  10444. returnErrorMsg("请至少选择一条数据");
  10445. return;
  10446. }
  10447. }
  10448. //新增
  10449. public void order_To_Supplier()
  10450. {
  10451. string ceid = GetPostString("tid");
  10452. String[] tid = ceid.Split(',');
  10453. if (tid.Length > 0)
  10454. {
  10455. try
  10456. {
  10457. for (int i = 0; i < tid.Length; i++)
  10458. {
  10459. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10460. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10461. entity.SupplierId = suid;
  10462. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10463. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10464. entity.Update();
  10465. }
  10466. }
  10467. catch (Exception ex)
  10468. {
  10469. returnErrorMsg("自动匹配供应商失败");
  10470. return;
  10471. }
  10472. }
  10473. else
  10474. {
  10475. returnErrorMsg("请至少选择一条数据");
  10476. return;
  10477. }
  10478. returnSuccessMsg("自动匹配供应商成功");
  10479. return;
  10480. }
  10481. public (string, string) UploadFiles(string[] urls)
  10482. {
  10483. string success = "";
  10484. string errors = "";
  10485. int userid = CurrentUser.UserID;
  10486. foreach (string url in urls)
  10487. {
  10488. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10489. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10490. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10491. {
  10492. JObject jsonObject = new JObject
  10493. {
  10494. { "Userid", "77886" },
  10495. { "pwd", "cyt86435015" },
  10496. { "content", base64FileContent },
  10497. { "ext", Path.GetExtension(fileName) }
  10498. };
  10499. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10500. JObject jsonObjects = JObject.Parse(response);
  10501. string msg = (string)jsonObjects["msg"];
  10502. if (msg.Equals("上传成功"))
  10503. {
  10504. success += url + " 上传成功";
  10505. }
  10506. else
  10507. {
  10508. errors += url + " 上传失败";
  10509. }
  10510. }
  10511. else
  10512. {
  10513. errors += url + " 格式出现问题";
  10514. }
  10515. }
  10516. if (urls.Length == 0)
  10517. {
  10518. return (success, errors);
  10519. }
  10520. return (success, errors);
  10521. }
  10522. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10523. {
  10524. return true; //总是接受
  10525. }
  10526. public static string HttpPost(string url, string param = null)
  10527. {
  10528. HttpWebRequest request;
  10529. //如果是发送HTTPS请求
  10530. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10531. {
  10532. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10533. request = WebRequest.Create(url) as HttpWebRequest;
  10534. request.ProtocolVersion = HttpVersion.Version10;
  10535. }
  10536. else
  10537. {
  10538. request = WebRequest.Create(url) as HttpWebRequest;
  10539. }
  10540. request.Method = "POST";
  10541. request.ContentType = "application/json";
  10542. request.Accept = "*/*";
  10543. request.Timeout = 120000;
  10544. request.AllowAutoRedirect = false;
  10545. StreamWriter requestStream = null;
  10546. WebResponse response = null;
  10547. string responseStr = null;
  10548. try
  10549. {
  10550. requestStream = new StreamWriter(request.GetRequestStream());
  10551. requestStream.Write(param);
  10552. requestStream.Close();
  10553. response = request.GetResponse();
  10554. if (response != null)
  10555. {
  10556. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10557. responseStr = reader.ReadToEnd();
  10558. reader.Close();
  10559. }
  10560. }
  10561. catch (Exception ex)
  10562. {
  10563. return ex.Message;
  10564. }
  10565. finally
  10566. {
  10567. request = null;
  10568. requestStream = null;
  10569. response = null;
  10570. }
  10571. return responseStr;
  10572. }
  10573. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10574. {
  10575. string base64FileContent;
  10576. string fileName;
  10577. using (WebClient webClient = new WebClient())
  10578. {
  10579. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10580. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10581. {
  10582. using (Stream stream = response.GetResponseStream())
  10583. {
  10584. using (MemoryStream memoryStream = new MemoryStream())
  10585. {
  10586. stream.CopyTo(memoryStream);
  10587. byte[] fileBytes = memoryStream.ToArray();
  10588. base64FileContent = Convert.ToBase64String(fileBytes);
  10589. fileName = response.Headers["Content-Disposition"];
  10590. if (!string.IsNullOrEmpty(fileName))
  10591. {
  10592. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10593. if (index >= 0)
  10594. {
  10595. fileName = fileName.Substring(index + 9).Trim('\"');
  10596. }
  10597. }
  10598. else
  10599. {
  10600. fileName = Path.GetFileName(downloadUrl);
  10601. }
  10602. }
  10603. }
  10604. }
  10605. }
  10606. return (fileName, base64FileContent);
  10607. }
  10608. //新增
  10609. public void order_batch_caiyingtong(string[] downloadUrls)
  10610. {
  10611. try
  10612. {
  10613. //遍历文件
  10614. DataStruct dStruct = GetPostStruct();
  10615. DataTable dt = null;
  10616. int userid = CurrentUser.UserID;
  10617. List<string> ids = new List<string>();//失败组
  10618. List<string> tids = new List<string>();
  10619. using (WebClient webClient = new WebClient())
  10620. {
  10621. foreach (var url in downloadUrls)
  10622. {
  10623. try
  10624. {
  10625. tids.Add("'" + url + "'");
  10626. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10627. if (entity != null)
  10628. {
  10629. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10630. if (cp == null)
  10631. {
  10632. JObject jsonObject = new JObject
  10633. {
  10634. { "Userid", "77886" },
  10635. { "pwd", "lt666888" },
  10636. { "Filename",entity.seller_memo }
  10637. };
  10638. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10639. JObject jsonObjects = JObject.Parse(response);
  10640. string msg = (string)jsonObjects["msg"];
  10641. if (msg == "报价成功")
  10642. {
  10643. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10644. DownloadAndConvertToBase64(url1);
  10645. }
  10646. else
  10647. {
  10648. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10649. }
  10650. }
  10651. else
  10652. {
  10653. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10654. JObject jsonObject = new JObject
  10655. {
  10656. { "Userid", "77886" },
  10657. { "pwd", "lt666888" },
  10658. { "Filename",chanp }
  10659. };
  10660. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10661. JObject jsonObjects = JObject.Parse(response);
  10662. string msg = (string)jsonObjects["msg"];
  10663. if (msg == "报价成功")
  10664. {
  10665. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10666. DownloadAndConvertToBase64(url1);
  10667. }
  10668. else
  10669. {
  10670. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10671. }
  10672. }
  10673. }
  10674. // 上传文件到FTP
  10675. }
  10676. catch (Exception ex)
  10677. {
  10678. Console.WriteLine($"An error occurred: {ex.Message}");
  10679. }
  10680. }
  10681. List<string> lw = new List<string>();
  10682. lw.Add(string.Format("( OrderState < 6 )"));
  10683. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10684. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10685. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10686. if (dt.Rows.Count > 0)
  10687. {
  10688. foreach (DataRow dr in dt.Rows)
  10689. {
  10690. ids.Add(dr["ctid"].ToString());
  10691. }
  10692. }
  10693. String ErrorMsgs = "";
  10694. foreach (String id in ids)
  10695. {
  10696. ErrorMsgs += id + ",";
  10697. }
  10698. if (ErrorMsgs.Length > 1)
  10699. {
  10700. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10701. }
  10702. if (ErrorMsgs.Length < 1)
  10703. {
  10704. ErrorMsgs = "上传成功";
  10705. returnSuccessMsg(ErrorMsgs);
  10706. }
  10707. else
  10708. {
  10709. returnErrorMsg("以下订单" + ErrorMsgs);
  10710. }
  10711. }
  10712. // 删除文件夹及其内容
  10713. /* Directory.Delete(localDirectory, true);*/
  10714. }
  10715. catch { }
  10716. }
  10717. public void get_center_data()
  10718. {
  10719. int userId = CurrentUser.UserID;
  10720. string postCode = CurrentUser.UserPost.Post.Code;
  10721. List<string> lw = new List<string>();
  10722. List<string> ww = new List<string>();
  10723. DateTime currentTime = DateTime.Now;
  10724. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10725. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10726. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10727. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10728. string sql = " SELECT ";
  10729. string startTime = "2023-10-01 11:22:31";
  10730. //设计
  10731. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10732. {
  10733. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10734. 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));
  10735. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10736. 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));
  10737. }
  10738. //客服
  10739. else if (postCode == "CustomerService" || postCode == "Director")
  10740. {
  10741. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10742. 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));
  10743. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10744. 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));
  10745. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10746. 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));
  10747. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10748. 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));
  10749. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10750. 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));
  10751. }
  10752. //售后
  10753. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10754. {
  10755. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10756. 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));
  10757. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10758. 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));
  10759. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10760. 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));
  10761. }
  10762. //下单部
  10763. else if (postCode == "Place" || postCode == "PlaceMr")
  10764. {
  10765. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10766. 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));
  10767. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10768. 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));
  10769. }
  10770. //车间
  10771. else if (postCode == "Supplier")
  10772. {
  10773. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10774. 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));
  10775. }
  10776. DataTable dt = new DataTable();
  10777. if (lw.Count > 0)
  10778. {
  10779. sql += string.Join(" , ", lw);
  10780. sql += " FROM ";
  10781. sql += string.Join(" , ", ww);
  10782. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10783. }
  10784. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10785. }
  10786. public void get_center_data_list()
  10787. {
  10788. int userId = CurrentUser.UserID;
  10789. string postCode = CurrentUser.UserPost.Post.Code;
  10790. string shopIds = CurrentUser.User.pemShop;
  10791. DataStruct dStruct = GetPostStruct();
  10792. List<string> lw = new List<string>();
  10793. DateTime currentTime = DateTime.Now;
  10794. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10795. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10796. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10797. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10798. string startTime = "2023-10-01 11:22:31";
  10799. int order_type = GetPostInt("order_type");
  10800. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10801. {
  10802. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10803. if (order_type == 0)
  10804. {
  10805. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10806. }
  10807. else if (order_type == 3)
  10808. {
  10809. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10810. }
  10811. else
  10812. {
  10813. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10814. }
  10815. }
  10816. //客服
  10817. if (postCode == "CustomerService" || postCode == "Director")
  10818. {
  10819. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10820. if (order_type == 0)
  10821. {
  10822. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10823. }
  10824. else if (order_type == 1)
  10825. {
  10826. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10827. }
  10828. else if (order_type == 2)
  10829. {
  10830. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10831. }
  10832. else if (order_type == 3)
  10833. {
  10834. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10835. }
  10836. else if (order_type == 4)
  10837. {
  10838. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10839. }
  10840. else
  10841. {
  10842. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10843. }
  10844. }
  10845. //售后
  10846. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10847. {
  10848. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10849. if (shopIds != "")
  10850. {
  10851. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10852. }
  10853. if (order_type == 2)
  10854. {
  10855. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10856. }
  10857. else if (order_type == 4)
  10858. {
  10859. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10860. }
  10861. else if (order_type == 5)
  10862. {
  10863. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10864. }
  10865. else
  10866. {
  10867. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10868. }
  10869. }
  10870. //下单部
  10871. if (postCode == "Place" || postCode == "PlaceMr")
  10872. {
  10873. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10874. if (shopIds != "")
  10875. {
  10876. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10877. }
  10878. else if (order_type == 1)
  10879. {
  10880. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10881. }
  10882. else if (order_type == 2)
  10883. {
  10884. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10885. }
  10886. else
  10887. {
  10888. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10889. }
  10890. }
  10891. //车间
  10892. if (postCode == "Supplier")
  10893. {
  10894. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10895. if (order_type == 5)
  10896. {
  10897. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10898. }
  10899. else
  10900. {
  10901. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10902. }
  10903. }
  10904. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10905. dStruct.Fileds = "tid,ctid";
  10906. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10907. writeGridDataTableJson(dStruct.TotalCount, dt);
  10908. }
  10909. public void aftersale_audit_master()
  10910. {
  10911. if (UrlPostParmsCheck("ctid"))
  10912. {
  10913. string ctid = GetPostString("ctid");
  10914. if (ctid.Length > 0)
  10915. {
  10916. bool result = aftersale_data_change(ctid);
  10917. if (result)
  10918. {
  10919. returnSuccessMsg("修改成功!");
  10920. return;
  10921. }
  10922. }
  10923. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10924. }
  10925. }
  10926. public void aftersale_batch_audit_master()
  10927. {
  10928. if (UrlPostParmsCheck("ctids"))
  10929. {
  10930. string ctids = GetPostString("ctids");
  10931. if (ctids.Length > 0)
  10932. {
  10933. List<string> list = new List<string>();
  10934. string[] ctid_list = ctids.Split(',');
  10935. foreach (var item in ctid_list)
  10936. {
  10937. bool result = aftersale_data_change(item);
  10938. if (!result)
  10939. {
  10940. list.Add(item);
  10941. }
  10942. }
  10943. if (list.Count > 0)
  10944. {
  10945. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10946. return;
  10947. }
  10948. returnSuccessMsg("修改成功!");
  10949. return;
  10950. }
  10951. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10952. }
  10953. }
  10954. public bool aftersale_data_change(string ctid)
  10955. {
  10956. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10957. if (ceErpTradeCell != null)
  10958. {
  10959. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10960. ceErpTradeCell.AfterSaleSupplierState = 0;
  10961. StringBuilder sql = new StringBuilder();
  10962. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10963. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10964. CeErpTradeResponsible.DelByTid(ctid, 0);
  10965. 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 == "不理赔")
  10966. {
  10967. CeErpTradeResponsible.DelByTid(ctid, 1);
  10968. ceErpTradeCell.AfterSaleSupplierState = 1;
  10969. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10970. ceErpTradeCell.AfterSaleState = 4;
  10971. }
  10972. else
  10973. {
  10974. ceErpTradeCell.AfterSaleState = 3;
  10975. }
  10976. bool needCyt = false;
  10977. if (dt != null)
  10978. {
  10979. if (dt.Rows.Count == 1)
  10980. {
  10981. bool isEnd = false;
  10982. foreach (DataRow dr in dt.Rows)
  10983. {
  10984. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10985. {
  10986. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10987. isEnd = true;
  10988. }
  10989. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10990. {
  10991. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10992. isEnd = true;
  10993. }
  10994. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10995. {
  10996. needCyt = true;
  10997. }
  10998. }
  10999. if (isEnd)
  11000. {
  11001. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11002. ceErpTradeCell.AfterSaleState = 4;
  11003. ceErpTradeCell.AfterSaleSupplierState = 1;
  11004. }
  11005. }
  11006. else
  11007. {
  11008. bool isAll = true;
  11009. foreach (DataRow dr in dt.Rows)
  11010. {
  11011. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11012. {
  11013. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11014. continue;
  11015. }
  11016. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  11017. {
  11018. string path = "";
  11019. int OrgID = 0;
  11020. if (!Convert.IsDBNull(dr["OrgPath"]))
  11021. {
  11022. path = dr["OrgPath"].ToString();
  11023. }
  11024. if (!Convert.IsDBNull(dr["OrgID"]))
  11025. {
  11026. OrgID = Convert.ToInt32(dr["OrgID"]);
  11027. }
  11028. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  11029. {
  11030. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11031. continue;
  11032. }
  11033. }
  11034. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11035. {
  11036. needCyt = true;
  11037. }
  11038. isAll = false;
  11039. }
  11040. if (isAll)
  11041. {
  11042. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11043. ceErpTradeCell.AfterSaleState = 4;
  11044. ceErpTradeCell.AfterSaleSupplierState = 1;
  11045. }
  11046. }
  11047. }
  11048. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11049. {
  11050. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11051. }
  11052. if (ceErpTradeCell.AfterSaleState == 4)
  11053. {
  11054. ApiVo apiVo = new ApiVo();
  11055. apiVo.orderNumber = ceErpTradeCell.ctid;
  11056. apiVo.actionName = "afterOver";
  11057. designHelper.API_WorkCore(apiVo); //afterOver
  11058. }
  11059. ceErpTradeCell.Update();
  11060. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11061. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11062. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11063. return true;
  11064. }
  11065. return false;
  11066. }
  11067. public void get_erp_wechatorder()
  11068. {
  11069. DataStruct dStruct = GetPostStruct();
  11070. List<string> lw = new List<string>();
  11071. string tid = GetPostString("tid");
  11072. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11073. string shopname = GetPostString("shopname");
  11074. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11075. string buyernick = GetPostString("buyer_nick");
  11076. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11077. string customer = GetPostString("customer");
  11078. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11079. string returndate1 = GetPostString("returndate1");
  11080. string returndate2 = GetPostString("returndate2");
  11081. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11082. if (dw.Length > 0) lw.Add(dw);
  11083. string finishDate1 = GetPostString("finishdate1");
  11084. string finishDate2 = GetPostString("finishdate2");
  11085. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11086. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11087. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11088. dStruct.Order = "created desc";
  11089. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11090. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11091. writeGridDataTableJson(dStruct.TotalCount, dt);
  11092. }
  11093. public void get_erp_wechatlist_sumprice()
  11094. {
  11095. DataStruct dStruct = GetPostStruct();
  11096. List<string> lw = new List<string>();
  11097. string tid = GetPostString("tid");
  11098. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11099. string shopname = GetPostString("shopname");
  11100. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11101. string buyernick = GetPostString("buyer_nick");
  11102. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11103. string customer = GetPostString("customer");
  11104. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11105. string returndate1 = GetPostString("returndate1");
  11106. string returndate2 = GetPostString("returndate2");
  11107. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11108. if (dw.Length > 0) lw.Add(dw);
  11109. string finishDate1 = GetPostString("finishdate1");
  11110. string finishDate2 = GetPostString("finishdate2");
  11111. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11112. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11113. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11114. string mainWhere = string.Join(" and ", lw.ToArray());
  11115. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11116. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11117. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11118. decimal total = 0;
  11119. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11120. {
  11121. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11122. }
  11123. var res = new
  11124. {
  11125. data = total
  11126. };
  11127. string ro_jsond = JsonConvert.SerializeObject(res);
  11128. returnSuccess(ro_jsond);
  11129. return;
  11130. }
  11131. public void get_erp_qr_waitdeliverylist()
  11132. {
  11133. DataStruct dStruct = GetPostStruct();
  11134. List<string> lw = new List<string>();
  11135. string tid = GetPostString("ctid");
  11136. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11137. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11138. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11139. var res_objz = new
  11140. {
  11141. restype = 1,
  11142. data = dt
  11143. };
  11144. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11145. returnSuccess(ro_jsonz);
  11146. }
  11147. public void get_erp_yield_list()
  11148. {
  11149. DataStruct dStruct = GetPostStruct();
  11150. List<string> lw = new List<string>();
  11151. string tid = GetPostString("ctid");
  11152. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11153. string shopname = GetPostString("shopname");
  11154. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11155. string buyernick = GetPostString("buyer_nick");
  11156. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11157. //if (tid.Length == 0 && buyernick.Length == 0)
  11158. //{
  11159. // lw.Add(string.Format("IsRefund<={0}", 1));
  11160. //}
  11161. string customer = GetPostString("customer");
  11162. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11163. string design = GetPostString("design");
  11164. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11165. string orderState = GetPostString("orderState");
  11166. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11167. string address = GetPostString("address");
  11168. 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));
  11169. string sellermemo = GetPostString("seller_memo");
  11170. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11171. string supplier = GetPostString("supplier");
  11172. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11173. string OrderArea = GetPostString("order_area");
  11174. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11175. string placedate1 = GetPostString("placedate1");
  11176. string placedate2 = GetPostString("placedate2");
  11177. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11178. if (fdw.Length > 0) lw.Add(fdw);
  11179. string price1 = GetPostString("price1");
  11180. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11181. string price2 = GetPostString("price2");
  11182. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11183. string unusualCon = GetPostString("unusualcon");
  11184. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11185. string posTag = CurrentUser.UserPost.Post.Code;
  11186. if (posTag == "Supplier")
  11187. {
  11188. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11189. }
  11190. lw.Add(string.Format("OrderState = 6 "));
  11191. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11192. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11193. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11194. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11195. writeGridDataTableJson(dStruct.TotalCount, dt);
  11196. }
  11197. public void change_erp_sup_state()
  11198. {
  11199. if (UrlPostParmsCheck("ctid"))
  11200. {
  11201. string ctid = GetPostString("ctid");
  11202. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11203. if (ceErpTradeCell != null)
  11204. {
  11205. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11206. if (ceErpTradeCellExtend == null)
  11207. {
  11208. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11209. ceErpTradeCellExtend.ctid = ctid;
  11210. ceErpTradeCellExtend.SupState = 1;
  11211. ceErpTradeCellExtend.Create();
  11212. }
  11213. else
  11214. {
  11215. ceErpTradeCellExtend.SupState = 1;
  11216. ceErpTradeCellExtend.Update();
  11217. }
  11218. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11219. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11220. return;
  11221. }
  11222. returnErrorMsg("找不到订单");
  11223. }
  11224. }
  11225. public void supplier_all_downs()
  11226. {
  11227. if (UrlPostParmsCheck("tids"))
  11228. {
  11229. string tids = GetPostString("tids");
  11230. if (tids != null && tids.Length > 0)
  11231. {
  11232. StringBuilder sql = new StringBuilder();
  11233. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11234. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11235. sql = new StringBuilder();
  11236. 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, "下载设计文件");
  11237. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11238. string[] list = tids.Split(',');
  11239. foreach (string ctid in list)
  11240. {
  11241. CeErpSukuraData.createInfo(ctid, 3);
  11242. }
  11243. designHelper.api_approveDesign(tids); //approveDesign
  11244. returnSuccessMsg("下载成功!");
  11245. return;
  11246. }
  11247. returnErrorMsg("下载订单更新失败");
  11248. }
  11249. }
  11250. public void uploaderFileSuccess()
  11251. {
  11252. if (UrlPostParmsCheck("fileName"))
  11253. {
  11254. string fileName = GetPostString("fileName");
  11255. ApiVo apiVo = new ApiVo();
  11256. apiVo.orderNumber = fileName;
  11257. apiVo.actionName = "finishDesign";
  11258. designHelper.API_WorkCore(apiVo);//finishDesign
  11259. returnSuccessMsg("");
  11260. }
  11261. }
  11262. public void get_sample2_order()
  11263. {
  11264. if (UrlPostParmsCheck("ctid"))
  11265. {
  11266. string ctid = GetPostString("ctid");
  11267. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11268. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11269. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11270. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11271. double total = 0.0;
  11272. double order_price = 0.0;
  11273. if (dt_bu.Rows.Count > 0)
  11274. {
  11275. foreach (DataRow dr in dt_bu.Rows)
  11276. {
  11277. total += Convert.ToDouble(dr["payment"]);
  11278. }
  11279. }
  11280. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11281. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11282. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11283. string tid = ctid.Replace("S_", "");
  11284. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11285. double paymant = 0.0;
  11286. if (entity != null)
  11287. {
  11288. paymant = entity.payment;
  11289. }
  11290. string return_reason = "";
  11291. if (dt_after != null && dt_after.Rows.Count > 0)
  11292. {
  11293. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11294. }
  11295. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11296. }
  11297. }
  11298. public void get_erp_design_status()
  11299. {
  11300. string designName = GetPostString("designName");
  11301. DataStruct dStruct = GetPostStruct();
  11302. if (designName.Length > 0)
  11303. {
  11304. 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";
  11305. sql_user += " and Name like '%" + designName + "%'";
  11306. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11307. List<string> ids_list = new List<string>();
  11308. if (user_table.Rows.Count > 0)
  11309. {
  11310. foreach (DataRow item in user_table.Rows)
  11311. {
  11312. ids_list.Add(item["id"].ToString());
  11313. string ids_s = item["TeamIds"].ToString();
  11314. if (ids_s.Length > 0)
  11315. {
  11316. ids_list.AddRange(ids_s.Split(','));
  11317. }
  11318. }
  11319. }
  11320. HashSet<string> set = new HashSet<string>(ids_list);
  11321. ids_list = set.ToList();
  11322. if (ids_list.Count > 0)
  11323. {
  11324. 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));
  11325. dStruct.MainWhere = sql;
  11326. DataTable dt = null;
  11327. dt = WebCache.GetData("view_ErpUser", dStruct);
  11328. writeGridDataTableJson(dStruct.TotalCount, dt);
  11329. }
  11330. }
  11331. }
  11332. public void change_erp_order_price()
  11333. {
  11334. string ctid = GetPostString("ctid");
  11335. double price = GetPostDouble("price");
  11336. if (ctid.Length > 0)
  11337. {
  11338. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11339. if (ceErpTradeCellExtend == null)
  11340. {
  11341. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11342. ceErpTradeCellExtend.ctid = ctid;
  11343. ceErpTradeCellExtend.payment_cyt = price;
  11344. ceErpTradeCellExtend.Create();
  11345. }
  11346. else
  11347. {
  11348. ceErpTradeCellExtend.payment_cyt = price;
  11349. ceErpTradeCellExtend.Update();
  11350. }
  11351. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11352. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11353. {
  11354. ceErpDataSendOrderInfo.isSync = false;
  11355. ceErpDataSendOrderInfo.Update();
  11356. }
  11357. if (ceErpDataSendOrderInfo == null)
  11358. {
  11359. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11360. ceErpDataSendOrderInfo.isSync = false;
  11361. ceErpDataSendOrderInfo.ctid = ctid;
  11362. ceErpDataSendOrderInfo.Create();
  11363. }
  11364. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11365. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11366. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11367. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11368. {
  11369. dataSendOrderBean dataSendOrderBean = null;
  11370. foreach (DataRow item in dth.Rows)
  11371. {
  11372. try
  11373. {
  11374. dataSendOrderBean = new dataSendOrderBean();
  11375. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11376. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11377. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11378. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11379. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11380. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11381. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11382. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11383. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11384. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11385. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11386. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11387. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11388. if (result != null)
  11389. {
  11390. if ("0".Equals(result.errcode))
  11391. {
  11392. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11393. }
  11394. else
  11395. {
  11396. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11397. }
  11398. }
  11399. }
  11400. catch (Exception ex)
  11401. {
  11402. }
  11403. }
  11404. }
  11405. returnSuccessMsg("修改成功!");
  11406. return;
  11407. }
  11408. returnErrorMsg("找不到订单");
  11409. }
  11410. public void find_he_together()
  11411. {
  11412. string ctid = GetPostString("ctid");
  11413. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11414. List<string> list = new List<string>();
  11415. if (ceErpTradeCell != null)
  11416. {
  11417. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11418. {
  11419. 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);
  11420. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11421. if (table != null && table.Rows.Count > 0)
  11422. {
  11423. foreach (TableRow row in table.Rows)
  11424. {
  11425. }
  11426. }
  11427. }
  11428. }
  11429. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11430. }
  11431. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11432. {
  11433. //chy----19
  11434. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11435. //GD-CYT-----64
  11436. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11437. //ZHX----3
  11438. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11439. //JK----97
  11440. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11441. //ZT----70
  11442. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11443. //GD-CYTUV---126
  11444. {126, new Dictionary<string, string> {{"uv", "uv"}}},
  11445. //LHCY-----98
  11446. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11447. //XD-----90
  11448. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11449. //CYCY-----14
  11450. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11451. };
  11452. //其他改名
  11453. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11454. {
  11455. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11456. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11457. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11458. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11459. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11460. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11461. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11462. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11463. };
  11464. //不统计
  11465. List<int> no_suppliers = new List<int>()
  11466. {
  11467. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11468. };
  11469. //配件单
  11470. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11471. {
  11472. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11473. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11474. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11475. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11476. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11477. {"旗杆",new List<string>(){ "班旗" } },
  11478. {"牙签",new List<string>(){ "不干胶" } }
  11479. };
  11480. public void get_place_order_data()
  11481. {
  11482. string date1 = GetPostString("date1");
  11483. string date2 = GetPostString("date2");
  11484. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11485. DateTime start = DateTime.Parse(starttime);
  11486. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11487. DateTime end = DateTime.Parse(endtime);
  11488. if (date1 != null && date1.Length > 0)
  11489. {
  11490. DateTime dateTime = DateTime.Parse(date1);
  11491. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11492. start = DateTime.Parse(starttime);
  11493. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11494. end = DateTime.Parse(endtime);
  11495. }
  11496. if (date2 != null && date2.Length > 0)
  11497. {
  11498. DateTime dateTime = DateTime.Parse(date2);
  11499. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11500. end = DateTime.Parse(endtime);
  11501. }
  11502. 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);
  11503. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11504. //不干胶-----1,卡片-----29
  11505. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11506. foreach (DataRow row in data.Rows)
  11507. {
  11508. int productId = Convert.ToInt32(row["ProductId"]);
  11509. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11510. if (no_suppliers.Contains(supplierId))
  11511. {
  11512. continue;
  11513. }
  11514. string seller_memo = row["seller_memo"].ToString();
  11515. bool ispj = false;//是否配件单
  11516. bool isfirst = true;//第一个配
  11517. maps.Keys.ForEach(key =>
  11518. {
  11519. //备注包含配件
  11520. if (seller_memo.Contains(key) && isfirst)
  11521. {
  11522. List<string> list = maps[key];
  11523. ispj = true;
  11524. isfirst = false;
  11525. for (int i = 0; i < list.Count; i++)
  11526. {
  11527. if (seller_memo.Contains(list[i]))
  11528. {
  11529. ispj = false;
  11530. break;
  11531. }
  11532. }
  11533. }
  11534. });
  11535. if (ispj)
  11536. {
  11537. continue;
  11538. }
  11539. seller_memo = seller_memo.Replace("UV", "uv");
  11540. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11541. //吊牌归到卡片
  11542. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11543. seller_memo = seller_memo.Replace("卡套", "卡片");
  11544. seller_memo = seller_memo.Replace("封套", "卡片");
  11545. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11546. seller_memo = seller_memo.Replace("腰封", "卡片");
  11547. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11548. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11549. seller_memo = seller_memo.Replace("横幅", "条幅");
  11550. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11551. string map_key = "";
  11552. string type = "";
  11553. if (supplierMap.ContainsKey(supplierId))
  11554. {
  11555. foreach (var kvp in supplierMap[supplierId])
  11556. {
  11557. if (seller_memo.Contains(kvp.Key))
  11558. {
  11559. map_key = kvp.Value;
  11560. type = kvp.Value;
  11561. break;
  11562. }
  11563. }
  11564. }
  11565. if (map_key == "")
  11566. {
  11567. type = "其他";
  11568. map_key = "其他";
  11569. }
  11570. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11571. {
  11572. map_key = suppliers[supplierId];
  11573. }
  11574. if (supplierId == 70)
  11575. {
  11576. supplierId = 70;
  11577. }
  11578. map_key += "_" + row["SupplierName"].ToString();
  11579. Dictionary<string, int> map = null;
  11580. if (other_map.ContainsKey(map_key))
  11581. {
  11582. other_map.TryGetValue(map_key, out map);
  11583. }
  11584. else
  11585. {
  11586. map = new Dictionary<string, int>();
  11587. map.Add("dayDev", 0);//当天出货
  11588. map.Add("dayTotal", 0);//下单总数
  11589. map.Add("payTotal", 0);//500以上
  11590. map.Add("today", 0);//当天出货数量
  11591. map.Add("unusua", 0);//异常数
  11592. other_map.Add(map_key, map);
  11593. other_map.TryGetValue(map_key, out map);
  11594. }
  11595. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11596. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11597. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11598. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11599. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11600. {
  11601. map["dayTotal"]++;
  11602. if (supplierId == 97)
  11603. {
  11604. supplierId = 97;
  11605. }
  11606. }
  11607. if (Convert.ToDecimal(row["payment"]) >= 500)
  11608. {
  11609. map["payTotal"]++;
  11610. }
  11611. bool istoday = false;
  11612. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11613. {
  11614. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11615. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11616. {
  11617. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11618. {
  11619. map["today"]++;
  11620. }
  11621. }
  11622. else
  11623. {
  11624. if (supplierId == 80)
  11625. {
  11626. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11627. {
  11628. map["today"]++;
  11629. }
  11630. }
  11631. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11632. {
  11633. map["today"]++;
  11634. istoday = true;
  11635. }
  11636. }
  11637. }
  11638. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11639. {
  11640. map["unusua"]++;
  11641. }
  11642. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11643. //GD-CYT-----64
  11644. DateTime two = palceTimeStart.AddHours(14);
  11645. DateTime three = palceTimeStart.AddHours(15);
  11646. DateTime four = palceTimeStart.AddHours(16);
  11647. DateTime six = palceTimeStart.AddHours(18);
  11648. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11649. {
  11650. //下午四点前 500-1000
  11651. string count = row["ProductCount"].ToString();
  11652. if (count != null && count.Length > 0)
  11653. {
  11654. int productCount = commonHelper.getPlaceProductCount(count);
  11655. if (productCount >= 500 && productCount <= 1000)
  11656. {
  11657. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11658. {
  11659. map["dayDev"]++;
  11660. }
  11661. }
  11662. }
  11663. }
  11664. //UV
  11665. else if ("uv".Equals(type))
  11666. {
  11667. //ZT----70
  11668. //ZHX----3
  11669. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11670. {
  11671. map["dayDev"]++;
  11672. }
  11673. //JK----97
  11674. //HZX----105
  11675. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11676. {
  11677. map["dayDev"]++;
  11678. }
  11679. if (DateTime.Compare(FinishPlaceTime, six) < 0 && (supplierId == 126))
  11680. {
  11681. map["dayDev"]++;
  11682. }
  11683. }
  11684. //帆布---52|条幅---27
  11685. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11686. {
  11687. //LHCY-----98
  11688. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11689. {
  11690. map["dayDev"]++;
  11691. }
  11692. }
  11693. //条幅
  11694. else if ("条幅".Equals(type))
  11695. {
  11696. //XD-----90
  11697. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11698. {
  11699. map["dayDev"]++;
  11700. }
  11701. }
  11702. //桌布
  11703. else if ("桌布".Equals(type))
  11704. {
  11705. //XD-----90
  11706. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11707. {
  11708. map["dayDev"]++;
  11709. }
  11710. }
  11711. //DL---10
  11712. //AYTW---119
  11713. //FS-CYT-DY ----80
  11714. //JK----97
  11715. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11716. {
  11717. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11718. {
  11719. map["dayDev"]++;
  11720. if (supplierId == 80 && istoday)
  11721. {
  11722. Debug.WriteLine(seller_memo);
  11723. }
  11724. }
  11725. }
  11726. // QC---121
  11727. else if (supplierId == 121)
  11728. {
  11729. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11730. {
  11731. map["dayDev"]++;
  11732. }
  11733. }
  11734. }
  11735. DataTable dt = new DataTable();
  11736. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11737. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11738. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11739. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11740. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11741. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11742. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11743. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11744. other_map.Keys.ForEach(key =>
  11745. {
  11746. DataRow dr = dt.NewRow();
  11747. Dictionary<string, int> map = other_map[key];
  11748. string[] key_list = key.Split('_');
  11749. dr[0] = key_list[0];
  11750. dr[1] = key_list[1];
  11751. if (key_list.Length > 2)
  11752. {
  11753. dr[1] += "(" + key_list[2] + ")";
  11754. }
  11755. dr[2] = map["dayTotal"];
  11756. dr[3] = map["payTotal"];
  11757. dr[4] = map["today"];
  11758. dr[5] = map["unusua"];
  11759. dr[6] = map["dayDev"];
  11760. double rate = 0.00;
  11761. if (map["dayDev"] > 0)
  11762. {
  11763. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11764. }
  11765. dr[7] = rate.ToString();
  11766. dt.Rows.Add(dr);
  11767. });
  11768. DataView dv = new DataView(dt);
  11769. dv.Sort = "SupplierName";
  11770. //dv.Sort = "AllOrder desc";
  11771. DataTable dtNew = dv.ToTable();
  11772. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11773. }
  11774. public void check_order_desing_info()
  11775. {
  11776. string ctid = GetPostString("ctid");
  11777. if (!string.IsNullOrEmpty(ctid))
  11778. {
  11779. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11780. if (ceErpTradeCell != null)
  11781. {
  11782. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11783. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11784. return;
  11785. }
  11786. returnErrorMsg("找不到订单");
  11787. return;
  11788. }
  11789. returnErrorMsg("找不到订单");
  11790. }
  11791. public void get_timeout_detail()
  11792. {
  11793. string poscode = CurrentUser.UserPost.Post.Code;
  11794. DataStruct dStruct = GetPostStruct();
  11795. List<string> lw = new List<string>();
  11796. string id = GetPostString("id");
  11797. string pay_date1 = GetPostString("pay_date1");
  11798. string pay_date2 = GetPostString("pay_date2");
  11799. int type = GetPostInt("type");
  11800. if (type == 0)
  11801. {
  11802. if (pay_date1.Length > 0)
  11803. {
  11804. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11805. }
  11806. if (pay_date2.Length > 0)
  11807. {
  11808. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11809. }
  11810. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11811. }
  11812. if (type == 1)
  11813. {
  11814. if (pay_date1.Length > 0)
  11815. {
  11816. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11817. }
  11818. if (pay_date2.Length > 0)
  11819. {
  11820. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11821. }
  11822. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11823. }
  11824. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11825. DataTable dt = null;
  11826. dt = WebCache.GetData("view_orderlist", dStruct);
  11827. writeGridDataTableJson(dStruct.TotalCount, dt);
  11828. }
  11829. public void saveUrgentChargePrice()
  11830. {
  11831. string ctid = GetPostString("ctid");
  11832. if (!string.IsNullOrEmpty(ctid))
  11833. {
  11834. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11835. if (ceErpTradeCell != null)
  11836. {
  11837. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11838. if (prices <= 100)
  11839. {
  11840. returnErrorMsg("此订单金额不足100元,无法加急。");
  11841. return;
  11842. }
  11843. double price = GetPostDouble("price");
  11844. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11845. if (ceErpTradeCellExtend == null)
  11846. {
  11847. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11848. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11849. }
  11850. ceErpTradeCellExtend.urgentCharge = price;
  11851. if (ceErpTradeCellExtend.ID > 0)
  11852. {
  11853. ceErpTradeCellExtend.Update();
  11854. }
  11855. else
  11856. {
  11857. ceErpTradeCellExtend.Save();
  11858. }
  11859. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11860. returnSuccessMsg("修改成功!");
  11861. return;
  11862. }
  11863. returnErrorMsg("找不到订单");
  11864. return;
  11865. }
  11866. returnErrorMsg("找不到订单");
  11867. }
  11868. public void finish_erp_order()
  11869. {
  11870. string ctid = GetPostString("ctid");
  11871. if (!string.IsNullOrEmpty(ctid))
  11872. {
  11873. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11874. {
  11875. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11876. if (ceErpTradeCell != null)
  11877. {
  11878. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11879. ceErpTradeCell.Update();
  11880. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11881. returnSuccessMsg("修改成功!");
  11882. return;
  11883. }
  11884. }
  11885. }
  11886. returnErrorMsg("找不到订单");
  11887. }
  11888. public void get_trade_order_list()
  11889. {
  11890. string tid = GetPostString("tid");
  11891. if (!string.IsNullOrEmpty(tid))
  11892. {
  11893. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11894. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11895. writeGridDataTableJson(data.Rows.Count, data);
  11896. return;
  11897. }
  11898. returnErrorMsg("找不到订单");
  11899. }
  11900. public void save_cell_spu()
  11901. {
  11902. string ctid = GetPostString("ctid");
  11903. string spu_id = GetPostString("spu_id");
  11904. if (!string.IsNullOrEmpty(ctid))
  11905. {
  11906. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11907. if (ceErpTradeCellExtend == null)
  11908. {
  11909. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11910. ceErpTradeCellExtend.ctid = ctid;
  11911. }
  11912. ceErpTradeCellExtend.spu_id = spu_id;
  11913. if (!string.IsNullOrEmpty(spu_id))
  11914. {
  11915. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11916. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11917. }
  11918. if (ceErpTradeCellExtend.ID == 0)
  11919. {
  11920. ceErpTradeCellExtend.Create();
  11921. }
  11922. else
  11923. {
  11924. ceErpTradeCellExtend.Update();
  11925. }
  11926. returnSuccessMsg("修改成功!");
  11927. return;
  11928. }
  11929. returnErrorMsg("找不到订单");
  11930. }
  11931. public void change_express_info()
  11932. {
  11933. string ctid = GetPostString("ctid");
  11934. string transNo = GetPostString("transNo");
  11935. string transCom = GetPostString("transCom");
  11936. if (!string.IsNullOrEmpty(ctid))
  11937. {
  11938. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11939. if (ceErpTradeCellExtend == null)
  11940. {
  11941. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11942. ceErpTradeCellExtend.ctid = ctid;
  11943. }
  11944. ceErpTradeCellExtend.modExpressNo = transNo;
  11945. ceErpTradeCellExtend.modExpressCom = transCom;
  11946. ceErpTradeCellExtend.readMod = 2;
  11947. if (ceErpTradeCellExtend.ID == 0)
  11948. {
  11949. ceErpTradeCellExtend.Create();
  11950. }
  11951. else
  11952. {
  11953. ceErpTradeCellExtend.Update();
  11954. }
  11955. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11956. returnSuccessMsg("修改成功!");
  11957. return;
  11958. }
  11959. returnErrorMsg("找不到订单");
  11960. }
  11961. public void get_change_express_list()
  11962. {
  11963. DataStruct dStruct = GetPostStruct();
  11964. List<string> lw = new List<string>();
  11965. int st = 2;
  11966. string tid = GetPostString("ctid");
  11967. if (tid.Length > 0)
  11968. {
  11969. string select_tid = getTidByCtid(tid);
  11970. lw.Add(string.Format("tid='{0}'", select_tid));
  11971. }
  11972. string shopname = GetPostString("shopname");
  11973. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11974. string buyernick = GetPostString("buyer_nick");
  11975. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11976. string sellermemo = GetPostString("seller_memo");
  11977. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11978. string supplier = GetPostString("supplier");
  11979. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11980. string customer = GetPostString("customer");
  11981. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11982. string design = GetPostString("design");
  11983. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11984. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11985. string poscode = CurrentUser.UserPost.Post.Code;
  11986. if (poscode != "SysAdmin")
  11987. {
  11988. string shopid = CurrentUser.User.pemShop;
  11989. lw.Add(string.Format("shopId in ({0})", shopid));
  11990. }
  11991. lw.Add("readMod = 2");
  11992. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11993. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11994. writeGridDataTableJson(dStruct.TotalCount, dt);
  11995. }
  11996. public void deal_express_complete()
  11997. {
  11998. string ctid = GetPostString("ctid");
  11999. if (!string.IsNullOrEmpty(ctid))
  12000. {
  12001. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12002. if (ceErpTradeCellExtend == null)
  12003. {
  12004. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12005. ceErpTradeCellExtend.ctid = ctid;
  12006. }
  12007. ceErpTradeCellExtend.readMod = 1;
  12008. if (ceErpTradeCellExtend.ID == 0)
  12009. {
  12010. ceErpTradeCellExtend.Create();
  12011. }
  12012. else
  12013. {
  12014. ceErpTradeCellExtend.Update();
  12015. }
  12016. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  12017. returnSuccessMsg("修改成功!");
  12018. return;
  12019. }
  12020. returnErrorMsg("找不到订单");
  12021. }
  12022. public void aftersale_return_visit()
  12023. {
  12024. string ctid = GetPostString("ctid");
  12025. if (!string.IsNullOrEmpty(ctid))
  12026. {
  12027. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12028. if (ceErpTradeCellExtend == null)
  12029. {
  12030. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12031. ceErpTradeCellExtend.ctid = ctid;
  12032. }
  12033. ceErpTradeCellExtend.returnVisit = 1;
  12034. if (ceErpTradeCellExtend.ID == 0)
  12035. {
  12036. ceErpTradeCellExtend.Create();
  12037. }
  12038. else
  12039. {
  12040. ceErpTradeCellExtend.Update();
  12041. }
  12042. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12043. if (ceErpTradeAfterSaleExtend != null)
  12044. {
  12045. ceErpTradeAfterSaleExtend.TextResult = "";
  12046. ceErpTradeAfterSaleExtend.Update();
  12047. }
  12048. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12049. returnSuccessMsg("修改成功!");
  12050. return;
  12051. }
  12052. returnErrorMsg("找不到订单");
  12053. }
  12054. public void orderPlaceInfo()
  12055. {
  12056. string ctids = GetPostString("ctids");
  12057. string[] list = ctids.Split(',');
  12058. foreach (string ctid in list)
  12059. {
  12060. CeErpSukuraData.createInfo(ctid, 3);
  12061. }
  12062. StringBuilder sql = new StringBuilder();
  12063. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12064. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12065. designHelper.api_approveDesign(ctids); //approveDesign
  12066. returnSuccessMsg("");
  12067. }
  12068. public void get_issue_list()
  12069. {
  12070. DataStruct dStruct = GetPostStruct();
  12071. List<string> lw = new List<string>();
  12072. int st = 2;
  12073. string tid = GetPostString("ctid");
  12074. if (tid.Length > 0)
  12075. {
  12076. string select_tid = getTidByCtid(tid);
  12077. lw.Add(string.Format("tid='{0}'", select_tid));
  12078. }
  12079. string shopname = GetPostString("shopname");
  12080. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12081. string buyernick = GetPostString("buyer_nick");
  12082. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12083. string sellermemo = GetPostString("seller_memo");
  12084. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12085. string supplier = GetPostString("supplier");
  12086. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12087. string customer = GetPostString("customer");
  12088. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12089. string design = GetPostString("design");
  12090. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12091. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12092. string poscode = CurrentUser.UserPost.Post.Code;
  12093. if (poscode != "SysAdmin")
  12094. {
  12095. string shopid = CurrentUser.User.pemShop;
  12096. lw.Add(string.Format("shopId in ({0})", shopid));
  12097. }
  12098. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12099. {
  12100. lw.Add("IssueState = 1");
  12101. }
  12102. else
  12103. {
  12104. string iisstate = GetPostString("iisstate");
  12105. if ("1".Equals(iisstate))
  12106. {
  12107. lw.Add("IssueState =1");
  12108. }
  12109. else if ("2".Equals(iisstate))
  12110. {
  12111. lw.Add("IssueState = 2");
  12112. }
  12113. else
  12114. {
  12115. lw.Add("IssueState > 0");
  12116. }
  12117. }
  12118. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12119. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12120. writeGridDataTableJson(dStruct.TotalCount, dt);
  12121. }
  12122. public void saveIssueContent()
  12123. {
  12124. string ctid = GetPostString("ctid");
  12125. if (!string.IsNullOrEmpty(ctid))
  12126. {
  12127. string content = GetPostString("content");
  12128. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12129. if (ceErpTradeAfterSaleExtend == null)
  12130. {
  12131. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12132. ceErpTradeAfterSaleExtend.tid = ctid;
  12133. }
  12134. ceErpTradeAfterSaleExtend.IssueContent = content;
  12135. ceErpTradeAfterSaleExtend.IssueState = 1;
  12136. if (ceErpTradeAfterSaleExtend.ID > 0)
  12137. {
  12138. ceErpTradeAfterSaleExtend.Update();
  12139. }
  12140. else
  12141. {
  12142. ceErpTradeAfterSaleExtend.Create();
  12143. }
  12144. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12145. returnSuccessMsg("添加成功!");
  12146. return;
  12147. }
  12148. returnErrorMsg("找不到订单");
  12149. }
  12150. public void dealIssueContent()
  12151. {
  12152. string ctid = GetPostString("ctid");
  12153. if (!string.IsNullOrEmpty(ctid))
  12154. {
  12155. string content = GetPostString("content");
  12156. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12157. if (ceErpTradeAfterSaleExtend != null)
  12158. {
  12159. ceErpTradeAfterSaleExtend.IssueState = 2;
  12160. ceErpTradeAfterSaleExtend.Update();
  12161. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12162. returnSuccessMsg("修改完成!");
  12163. return;
  12164. }
  12165. }
  12166. returnErrorMsg("找不到订单");
  12167. }
  12168. public void set_tid_attachments()
  12169. {
  12170. string tid = GetPostString("tid");
  12171. string atta = GetPostString("atta");
  12172. if (!string.IsNullOrEmpty(tid))
  12173. {
  12174. if (string.IsNullOrEmpty(atta))
  12175. {
  12176. returnErrorMsg("文件地址为空");
  12177. return;
  12178. }
  12179. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12180. if (ceErpTradeCell != null)
  12181. {
  12182. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12183. if (ceErpTrade == null)
  12184. {
  12185. returnErrorMsg("找不到订单");
  12186. return;
  12187. }
  12188. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12189. bool isSend = false;
  12190. if (dt != null && dt.Rows.Count > 0)
  12191. {
  12192. foreach (DataRow row in dt.Rows)
  12193. {
  12194. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12195. {
  12196. isSend = true;
  12197. }
  12198. }
  12199. if (isSend)
  12200. {
  12201. returnErrorMsg("已发货无法修改");
  12202. return;
  12203. }
  12204. ceErpTrade.Attachments = atta;
  12205. ceErpTrade.Update();
  12206. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12207. returnSuccessMsg("上传成功!");
  12208. return;
  12209. }
  12210. }
  12211. }
  12212. returnErrorMsg("找不到订单");
  12213. }
  12214. public void get_tid_attachments()
  12215. {
  12216. string tid = GetPostString("tid");
  12217. if (!string.IsNullOrEmpty(tid))
  12218. {
  12219. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12220. if (ceErpTradeCell != null)
  12221. {
  12222. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12223. if (ceErpTrade == null)
  12224. {
  12225. returnErrorMsg("找不到订单");
  12226. return;
  12227. }
  12228. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12229. return;
  12230. }
  12231. }
  12232. returnErrorMsg("找不到订单");
  12233. }
  12234. public void check_erp_sameorders()
  12235. {
  12236. if (UrlPostParmsCheck("ctid"))
  12237. {
  12238. string eid = GetPostString("ctid");
  12239. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12240. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12241. if (entity != null && ceErpTrade != null)
  12242. {
  12243. if (entity.OrderState > 6)
  12244. {
  12245. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12246. return;
  12247. }
  12248. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12249. List<string> ids = new List<string>();
  12250. if (dt != null && dt.Rows.Count > 1)
  12251. {
  12252. bool needhe = true;
  12253. foreach (DataRow dr in dt.Rows)
  12254. {
  12255. ids.Add("'" + dr["ctid"] + "'");
  12256. /* //备注有合包
  12257. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12258. {
  12259. needhe = true;
  12260. }
  12261. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12262. {
  12263. needhe = true;
  12264. }
  12265. //顺丰快递
  12266. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12267. {
  12268. needhe = true;
  12269. }*/
  12270. }
  12271. if (!needhe)
  12272. {
  12273. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12274. return;
  12275. }
  12276. StringBuilder sql = new StringBuilder();
  12277. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12278. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12279. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12280. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12281. foreach (DataRow dr in dt.Rows)
  12282. {
  12283. dr["dstate"] = 0;
  12284. dr["dnumber"] = 0;
  12285. foreach (DataRow row in dt1.Rows)
  12286. {
  12287. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12288. {
  12289. dr["dstate"] = 2;
  12290. dr["default"] = 1;
  12291. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12292. }
  12293. }
  12294. if (eid.Equals(dr["ctid"].ToString()))
  12295. {
  12296. dr["dstate"] = 1;
  12297. dr["default"] = 1;
  12298. }
  12299. }
  12300. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12301. return;
  12302. }
  12303. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12304. return;
  12305. }
  12306. returnErrorMsg("未找到订单");
  12307. return;
  12308. }
  12309. returnErrorMsg("缺少必要的参数");
  12310. }
  12311. public void get_mark_number()
  12312. {
  12313. string eid = GetPostString("ctid");
  12314. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12315. if (entity != null)
  12316. {
  12317. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12318. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12319. int current = 1;
  12320. if (ceErpDeliverMark == null)
  12321. {
  12322. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12323. List<string> ids = new List<string>();
  12324. if (dt != null && dt.Rows.Count > 1)
  12325. {
  12326. foreach (DataRow dr in dt.Rows)
  12327. {
  12328. ids.Add("'" + dr["ctid"] + "'");
  12329. }
  12330. //查询已有的编号
  12331. StringBuilder sql = new StringBuilder();
  12332. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12333. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12334. if (dt1 == null || dt1.Rows.Count == 0)
  12335. {
  12336. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12337. List<int> list_number = new List<int>();
  12338. foreach (DataRow row in numbers.Rows)
  12339. {
  12340. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12341. }
  12342. //查询空余编号
  12343. for (int i = 0; i < list_number.Count + 2; i++)
  12344. {
  12345. if (!list_number.Contains(current))
  12346. {
  12347. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12348. //防止查询过程中有新数据生成
  12349. if (ceErpDeliverMark1 == null)
  12350. {
  12351. break;
  12352. }
  12353. }
  12354. current++;
  12355. }
  12356. }
  12357. else
  12358. {
  12359. foreach (DataRow row in dt1.Rows)
  12360. {
  12361. current = Convert.ToInt32(row["markNumber"]);
  12362. }
  12363. }
  12364. ceErpDeliverMark = new CeErpDeliverMark();
  12365. ceErpDeliverMark.ctid = eid;
  12366. ceErpDeliverMark.createtime = DateTime.Now;
  12367. if (ceErpTrade != null)
  12368. {
  12369. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12370. }
  12371. ceErpDeliverMark.markNumber = current;
  12372. ceErpDeliverMark.Create();
  12373. }
  12374. }
  12375. else
  12376. {
  12377. current = ceErpDeliverMark.markNumber;
  12378. }
  12379. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12380. return;
  12381. }
  12382. }
  12383. public void aftersaleCytSend()
  12384. {
  12385. string ctid = GetPostString("ctid");
  12386. if (!string.IsNullOrEmpty(ctid))
  12387. {
  12388. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12389. if (ceErpTradeCell != null)
  12390. {
  12391. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12392. }
  12393. returnSuccessMsg("推送成功");
  12394. return;
  12395. }
  12396. returnErrorMsg("缺少必要的参数");
  12397. }
  12398. public void packOrderInfo()
  12399. {
  12400. string ctids = GetPostString("ctids");
  12401. if (!string.IsNullOrEmpty(ctids))
  12402. {
  12403. string[] ctid_list = ctids.Split(',');
  12404. if (ctid_list.Length > 20)
  12405. {
  12406. returnErrorMsg("单次下载次数不能超过20个");
  12407. return;
  12408. }
  12409. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12410. StringBuilder sql = new StringBuilder();
  12411. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12412. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12413. int supplierId = 0;
  12414. StringBuilder insterSql = new StringBuilder();
  12415. for (int i = 0; i < dt.Rows.Count; i++)
  12416. {
  12417. DataRow row = dt.Rows[i];
  12418. if (i == 0)
  12419. {
  12420. supplierId = Convert.ToInt32(row["SupplierId"]);
  12421. }
  12422. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12423. {
  12424. returnErrorMsg("同车间的订单才能一起打包");
  12425. return;
  12426. }
  12427. int orderState = Convert.ToInt32(row["OrderState"]);
  12428. if (orderState != 5)
  12429. {
  12430. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12431. return;
  12432. }
  12433. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12434. }
  12435. CeErpPackData ceErpPackData = new CeErpPackData();
  12436. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12437. ceErpPackData.supplierId = supplierId;
  12438. ceErpPackData.createtime = DateTime.Now;
  12439. ceErpPackData.createBy = CurrentUser.UserID;
  12440. ceErpPackData.createName = CurrentUser.UserName;
  12441. ceErpPackData.Create();
  12442. if (ceErpPackData.ID > 0)
  12443. {
  12444. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12445. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12446. }
  12447. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12448. returnSuccessMsg("打包成功");
  12449. return;
  12450. }
  12451. returnErrorMsg("缺少必要的参数");
  12452. }
  12453. public void rePackOrderInfo()
  12454. {
  12455. string id = GetPostString("id");
  12456. if (!string.IsNullOrEmpty(id))
  12457. {
  12458. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12459. if (ceErpPackData == null)
  12460. {
  12461. returnSuccessMsg("查无数据");
  12462. return;
  12463. }
  12464. ceErpPackData.upStatus = 0;
  12465. ceErpPackData.message = "";
  12466. ceErpPackData.Update();
  12467. returnSuccessMsg("打包成功");
  12468. return;
  12469. }
  12470. returnErrorMsg("缺少必要的参数");
  12471. }
  12472. public void backPackOrderInfo()
  12473. {
  12474. string id = GetPostString("id");
  12475. if (!string.IsNullOrEmpty(id))
  12476. {
  12477. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12478. if (ceErpPackData == null)
  12479. {
  12480. returnSuccessMsg("查无数据");
  12481. return;
  12482. }
  12483. ceErpPackData.upStatus = 4;
  12484. ceErpPackData.Update();
  12485. List<string> list = new List<string>();
  12486. StringBuilder sql = new StringBuilder();
  12487. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12488. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12489. for (int i = 0; i < dt.Rows.Count; i++)
  12490. {
  12491. DataRow row = dt.Rows[i];
  12492. list.Add("'" + row["ctid"].ToString() + "'");
  12493. }
  12494. string textCtids = string.Join(",", list);
  12495. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=5,IsVerifyToSupplier=0,IsReturn=1,ReturnTime=GETDATE(),ReturnReason='无法打包' where ctid in ({0}) and OrderState=6", textCtids));
  12496. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", textCtids, (int)OrderState.下单完成, 0, "无法打包退回"));
  12497. returnSuccessMsg("退回成功");
  12498. return;
  12499. }
  12500. returnErrorMsg("缺少必要的参数");
  12501. }
  12502. public void addPackDownNum()
  12503. {
  12504. string id = GetPostString("id");
  12505. if (!string.IsNullOrEmpty(id))
  12506. {
  12507. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12508. returnSuccessMsg("下载成功");
  12509. return;
  12510. }
  12511. returnErrorMsg("缺少必要的参数");
  12512. }
  12513. public void get_pack_list()
  12514. {
  12515. DataStruct dStruct = GetPostStruct();
  12516. List<string> lw = new List<string>();
  12517. string supplier = GetPostString("supplier");
  12518. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12519. string posTag = CurrentUser.UserPost.Post.Code;
  12520. if (posTag == "Supplier")
  12521. {
  12522. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12523. }
  12524. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12525. dStruct.Order = "createtime desc";
  12526. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12527. writeGridDataTableJson(dStruct.TotalCount, dt);
  12528. }
  12529. public void get_pack_order_list()
  12530. {
  12531. string packId = GetPostString("packId");
  12532. if (string.IsNullOrEmpty(packId))
  12533. {
  12534. returnErrorMsg("缺少必要的参数");
  12535. return;
  12536. }
  12537. StringBuilder sql = new StringBuilder();
  12538. sql.AppendFormat("select c.ctid,c.seller_memo,i.message from CE_ErpPackDataItem i left join CE_ErpTradeCell c on i.ctid=c.ctid where i.packId = {0}", packId);
  12539. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12540. if (dt == null || dt.Rows.Count == 0)
  12541. {
  12542. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12543. return;
  12544. }
  12545. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12546. return;
  12547. }
  12548. public void get_supplier_product_time_list()
  12549. {
  12550. DataStruct dStruct = GetPostStruct();
  12551. List<string> lw = new List<string>();
  12552. string supplier = GetPostString("supplier");
  12553. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12554. string posTag = CurrentUser.UserPost.Post.Code;
  12555. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12556. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12557. writeGridDataTableJson(dStruct.TotalCount, dt);
  12558. }
  12559. public void saveSupplierProductTime()
  12560. {
  12561. string productId = GetPostString("productId");
  12562. if (string.IsNullOrEmpty(productId))
  12563. {
  12564. returnErrorMsg("缺少必要的参数");
  12565. return;
  12566. }
  12567. string productName = GetPostString("productName");
  12568. int supplierId = GetPostInt("supplierId");
  12569. if (supplierId == 0)
  12570. {
  12571. returnErrorMsg("缺少必要的参数");
  12572. return;
  12573. }
  12574. int quantity = GetPostInt("quantity");
  12575. int sendDay = GetPostInt("sendTime");
  12576. string supplierName = GetPostString("supplierName");
  12577. string craft = GetPostString("craft");
  12578. string deadLine = GetPostString("deadLine");
  12579. string dayDeadLine = GetPostString("dayDeadLine");
  12580. try
  12581. {
  12582. int eid = GetPostInt("eid");
  12583. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12584. if (ceErpSupplierProductTime == null)
  12585. {
  12586. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12587. }
  12588. ceErpSupplierProductTime.productId = productId;
  12589. ceErpSupplierProductTime.productName = productName;
  12590. ceErpSupplierProductTime.supplierId = supplierId;
  12591. ceErpSupplierProductTime.supplierName = supplierName;
  12592. ceErpSupplierProductTime.craft = craft;
  12593. ceErpSupplierProductTime.sendDay = sendDay;
  12594. ceErpSupplierProductTime.quantity = quantity;
  12595. if (!string.IsNullOrEmpty(deadLine))
  12596. {
  12597. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12598. }
  12599. if (!string.IsNullOrEmpty(dayDeadLine))
  12600. {
  12601. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12602. }
  12603. if (ceErpSupplierProductTime.ID == 0)
  12604. {
  12605. ceErpSupplierProductTime.Save();
  12606. }
  12607. else
  12608. {
  12609. ceErpSupplierProductTime.Update();
  12610. }
  12611. }
  12612. catch (Exception e)
  12613. {
  12614. }
  12615. returnSuccessMsg("保存成功");
  12616. return;
  12617. }
  12618. public void delSupplierProductTime()
  12619. {
  12620. int eid = GetPostInt("eid");
  12621. if (eid > 0)
  12622. {
  12623. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12624. if (ceErpSupplierProductTime == null)
  12625. {
  12626. returnErrorMsg("查无数据");
  12627. return;
  12628. }
  12629. ceErpSupplierProductTime.Delete();
  12630. returnSuccessMsg("保存成功");
  12631. return;
  12632. }
  12633. returnErrorMsg("缺少必要的参数");
  12634. }
  12635. public void getExpressInfo()
  12636. {
  12637. string ctid = GetPostString("ctid");
  12638. if (!string.IsNullOrEmpty(ctid))
  12639. {
  12640. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12641. if (ceErpTradeCell != null)
  12642. {
  12643. string outSid = ceErpTradeCell.OutSid;
  12644. if (outSid.Length > 0)
  12645. {
  12646. string sql = string.Format("SELECT out_sid FROM [dbo].[CE_ErpExpressInfo] WHERE (out_sid in ({0}) or tid = '{1}') and ISNULL(DATALENGTH(postData), 0)>0;", "'" + outSid.Replace(",", "','") + "'", ceErpTradeCell.tid);
  12647. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12648. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12649. return;
  12650. }
  12651. }
  12652. returnErrorMsg("查无记录");
  12653. return;
  12654. }
  12655. returnErrorMsg("缺少必要的参数");
  12656. }
  12657. public void getExpressPostData()
  12658. {
  12659. string express = GetPostString("express");
  12660. if (!string.IsNullOrEmpty(express))
  12661. {
  12662. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12663. if (ceErpExpressInfo != null)
  12664. {
  12665. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12666. return;
  12667. }
  12668. }
  12669. returnErrorMsg("缺少必要的参数");
  12670. }
  12671. public void checkSupplierOrder()
  12672. {
  12673. string ctids = GetPostString("ctids");
  12674. if (ctids != null)
  12675. {
  12676. List<string> list = new List<string>();
  12677. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12678. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12679. for (int i = 0; i < dt.Rows.Count; i++)
  12680. {
  12681. DataRow row = dt.Rows[i];
  12682. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12683. {
  12684. continue;
  12685. }
  12686. list.Add(row["seller_memo"].ToString());
  12687. }
  12688. if (list.Count > 0)
  12689. {
  12690. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", "'" + ctids.Replace(",", "','") + "'", (int)OrderState.下单完成, CurrentUser.UserID, "点击下载按钮"));
  12691. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12692. return;
  12693. }
  12694. }
  12695. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12696. return;
  12697. }
  12698. public void addPersonId()
  12699. {
  12700. string tid = GetPostString("tid");
  12701. string personId = GetPostString("personId");
  12702. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12703. if (ceErpTrade != null)
  12704. {
  12705. ceErpTrade.receiver_zip = personId;
  12706. ceErpTrade.Update();
  12707. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12708. returnSuccessMsg("保存成功");
  12709. return;
  12710. }
  12711. returnErrorMsg("缺少必要的参数");
  12712. }
  12713. public void addDeliveryPaymant()
  12714. {
  12715. string tid = GetPostString("tid");
  12716. string paymant = GetPostString("paymant");
  12717. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12718. if (ceErpTrade != null)
  12719. {
  12720. if (!string.IsNullOrEmpty(paymant))
  12721. {
  12722. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  12723. }
  12724. ceErpTrade.Update();
  12725. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  12726. returnSuccessMsg("保存成功");
  12727. return;
  12728. }
  12729. returnErrorMsg("缺少必要的参数");
  12730. }
  12731. public void saveCellFile()
  12732. {
  12733. string tid = GetPostString("tid");
  12734. string ctid = GetPostString("ctid");
  12735. string urls = GetPostString("urls");
  12736. string type = GetPostString("type");
  12737. string del = GetPostString("del");
  12738. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12739. {
  12740. if ("1".Equals(del))
  12741. {
  12742. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  12743. }
  12744. string[] list = urls.Split(',');
  12745. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  12746. {
  12747. foreach (string item in list)
  12748. {
  12749. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  12750. ceErpTradeCellFile.Create();
  12751. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  12752. }
  12753. }
  12754. returnSuccessMsg("保存成功");
  12755. return;
  12756. }
  12757. returnErrorMsg("缺少必要的参数");
  12758. }
  12759. public void getCellFile()
  12760. {
  12761. string tid = GetPostString("tid");
  12762. string ctid = GetPostString("ctid");
  12763. string type = GetPostString("type");
  12764. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12765. {
  12766. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  12767. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12768. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  12769. return;
  12770. }
  12771. returnErrorMsg("缺少必要的参数");
  12772. }
  12773. public void delCellFile()
  12774. {
  12775. string id = GetPostString("id");
  12776. if (string.IsNullOrEmpty(id))
  12777. {
  12778. returnErrorMsg("缺少必要的参数");
  12779. return;
  12780. }
  12781. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  12782. CeErpTradeCellFile.delByID(id);
  12783. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  12784. returnSuccessMsg("保存成功");
  12785. }
  12786. public void getInvoiceOrder()
  12787. {
  12788. string tid = GetPostString("tid");
  12789. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12790. List<string> tids = new List<string>();
  12791. if (!string.IsNullOrEmpty(ceErpTrade.buyer_nick) && !string.IsNullOrEmpty(ceErpTrade.buyer_id))
  12792. {
  12793. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WHERE buyer_id = '{0}' AND seller_nick = '{1}' order by pay_time desc;", ceErpTrade.buyer_id, ceErpTrade.seller_nick);
  12794. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12795. foreach (DataRow dr in dt.Rows)
  12796. {
  12797. tids.Add("'" + dr["tid"].ToString() + "'");
  12798. }
  12799. }
  12800. else
  12801. {
  12802. tids.Add("'" + ceErpTrade.tid + "'");
  12803. }
  12804. DataTable cell_dt = new DataTable();
  12805. if (tids.Count > 0)
  12806. {
  12807. cell_dt = DbHelper.DbConn.ExecuteDataset(string.Format("SELECT * FROM [dbo].[CE_ErpTradeCell] WHERE tid in ({0});", string.Join(",", tids))).Tables[0];
  12808. }
  12809. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(cell_dt));
  12810. return;
  12811. }
  12812. }
  12813. }