sync.order.cs 640 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875
  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. namespace SiteCore.Handler
  51. {
  52. public partial class sync
  53. {
  54. public void get_erp_orderlist()
  55. {
  56. string poscode = CurrentUser.UserPost.Post.Code;
  57. DataStruct dStruct = GetPostStruct();
  58. //string a = SecurityHelper.DecryptSymmetric("iXI3wJyH6QXRCrZPXvZBSQ==");
  59. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\uv特殊工艺价格(1).xls");
  60. //apiHelper.Api_SyncOrderByTime("598825");
  61. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  62. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  63. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  64. //banniuApiHelper.sendLogisticsInfo(null);
  65. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  66. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  67. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  68. //int sid = commonHelper.autoDistributeToSupplier(entity);
  69. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  70. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1752654175000,\"deliveryType\":\"OFFLINE\",\"discountFee\":0.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1752826970000,\"lines\":[{\"latestDeliveryTime\":1752826970000,\"mark2\":[],\"num\":23,\"outerId\":\"DGCP\",\"payment\":460.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2200806677467/O1CN01Wlpmej251wOGAuYd2_!!0-item_pic.jpg\",\"platServiceFee\":0.0,\"price\":20.0,\"refOlId\":\"4634728491992436446\",\"refSkuId\":\"0\",\"refSpuId\":\"617207822351\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":20.0,\"singleFee\":20.0,\"spuOuterId\":\"DGCP\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"蛋糕logo插牌定制烘焙店插卡插排生日小卡片装饰甜品标签插件设计\",\"totalFee\":460.0,\"totalPrice\":460.0,\"totalSellPrice\":460.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1752658857000,\"openBuyerId\":\"AAHqRHraABkUZRPgSx1P9I8b\",\"openBuyerNick\":\"b**\",\"openSellerNick\":\"翊喜旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1752654168000,\"payTime\":1752654170000,\"payment\":460.0,\"platServiceFee\":0.0,\"posCode\":\"yixi\",\"posId\":598788,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"佛山市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"禅城区\",\"receiverId\":\"882d7aaecddc7a9698cc36e36a46ba24$\",\"receiverState\":\"广东省\",\"receiverTown\":\"石湾镇街道\",\"refOid\":\"4634728491992436446\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"60x12mm-2款各500张-插卡-350克铜板纸-直角单面烫金模切-bowie_s-英子-240元-(纯烫金)-老客户204.02.20,40x40mm-2000张-插卡-350克铜板纸-方形直角裁切-bowie_s-英子-220元--老客户2024.02.20\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":460.0,\"totalPrice\":460.0,\"totalSellPrice\":460.0,\"type\":\"SALE\"}}");
  71. //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}}");
  72. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  73. //commonHelper.loginGetOrder(2152);
  74. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  75. List<string> lw = new List<string>();
  76. string tid = GetPostString("ctid");
  77. string date1 = GetPostString("date1");
  78. //12-1 修改
  79. string urgent = GetPostString("urgent");
  80. string back = GetPostString("back");
  81. string offlineSearch = GetPostString("offlineSearch");
  82. int paramsCount = 0;
  83. if (!string.IsNullOrWhiteSpace(urgent))
  84. {
  85. if (urgent.Equals("true"))
  86. {
  87. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  88. }
  89. }
  90. if (!string.IsNullOrWhiteSpace(back))
  91. {
  92. if (back.Equals("true"))
  93. {
  94. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  95. }
  96. }
  97. if (!string.IsNullOrWhiteSpace(offlineSearch))
  98. {
  99. if (offlineSearch.Equals("true"))
  100. {
  101. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  102. }
  103. }
  104. //end
  105. string date2 = GetPostString("date2");
  106. string buyernick = GetPostString("buyer_nick");
  107. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  108. {
  109. if (tid.Length <= 0 && buyernick.Length <= 0)
  110. {
  111. return;
  112. }
  113. }
  114. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  115. {
  116. if (tid.Length > 0)
  117. {
  118. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  119. if (ceErpTradeCell != null)
  120. {
  121. tid = ceErpTradeCell.tid;
  122. }
  123. List<string> select_tid = getTidByCtidMore(tid);
  124. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  125. }
  126. if (buyernick.Length > 0)
  127. {
  128. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  129. }
  130. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  131. if (dw.Length > 0)
  132. {
  133. lw.Add(dw);
  134. }
  135. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  136. {
  137. string usershop = CurrentUser.User.pemShop;
  138. lw.Add(string.Format("ShopId in ({0})", usershop));
  139. }
  140. }
  141. else
  142. {
  143. if (ex_psize == 0)
  144. {
  145. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  146. }
  147. if (PKey != "admin" && poscode != "SysAdmin")
  148. {
  149. string usershop = CurrentUser.User.pemShop;
  150. lw.Add(string.Format("ShopId in ({0})", usershop));
  151. paramsCount++;
  152. }
  153. }
  154. string uploaddate1 = GetPostString("uploaddate1");
  155. string uploaddate2 = GetPostString("uploaddate2");
  156. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  157. if (update.Length > 0) lw.Add(update);
  158. string deliverydate1 = GetPostString("deliverydate1");
  159. string deliverydate2 = GetPostString("deliverydate2");
  160. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  161. if (deliverydate.Length > 0)
  162. {
  163. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  164. };
  165. string shopname = GetPostString("shopname");
  166. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  167. string addwechat = GetPostString("addwechat");
  168. if (addwechat.Length > 0)
  169. {
  170. int addWt = Convert.ToInt32(addwechat);
  171. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  172. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  173. }
  174. string customer = GetPostString("customer");
  175. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  176. string design = GetPostString("design");
  177. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  178. string orderState = GetPostString("orderState");
  179. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  180. string address = GetPostString("address");
  181. 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));
  182. string sellermemo = GetPostString("seller_memo");
  183. if (sellermemo.Length > 0)
  184. {
  185. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  186. }
  187. string backReason = GetPostString("backReason");
  188. if (backReason.Length > 0)
  189. {
  190. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  191. }
  192. string apdate1 = GetPostString("apdate1");
  193. string apdate2 = GetPostString("apdate2");
  194. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  195. if (dwap.Length > 0) lw.Add(dwap);
  196. string price1 = GetPostString("price1");
  197. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  198. string price2 = GetPostString("price2");
  199. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  200. string isoldcustomer = GetPostString("isoldcus");
  201. string spudata = GetPostString("spudata");
  202. if ("0".Equals(spudata))
  203. {
  204. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  205. }
  206. if ("1".Equals(spudata))
  207. {
  208. lw.Add(string.Format("spu_id <> ''"));
  209. }
  210. string finishdate1 = GetPostString("finishdate1");
  211. string finishdate2 = GetPostString("finishdate2");
  212. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  213. bool isFinish = false;
  214. if (finishdate.Length > 0)
  215. {
  216. lw.Add(finishdate);
  217. isFinish = true;
  218. paramsCount++;
  219. }
  220. if (isoldcustomer.Length > 0)
  221. {
  222. if ("2".Equals(isoldcustomer))
  223. {
  224. lw.Add(string.Format("VipCustomer=1"));
  225. }
  226. else
  227. {
  228. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  229. }
  230. }
  231. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  232. if (ex_psize > 0)
  233. {
  234. int UserID = CurrentUser.UserID;
  235. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  236. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  237. {
  238. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  239. }
  240. dStruct.Order = "pay_time desc";
  241. }
  242. string isNew = GetPostString("isNew");
  243. if (isNew == "true")
  244. {
  245. lw.Add(string.Format("IsNew = {0}", 1));
  246. }
  247. string overtime = GetPostString("overtime");
  248. if (overtime == "1")
  249. {
  250. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  251. }
  252. String usePost = CurrentUser.UserPost.Post.Code;
  253. if (usePost.Equals("Operation") == true)
  254. {
  255. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  256. }
  257. else
  258. {
  259. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  260. }
  261. //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";
  262. if (dStruct.PageSize == 100000)
  263. {
  264. dStruct.Order = "";
  265. }
  266. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  267. DataTable dt = null;
  268. string tablename = "view_orderlist";
  269. if (isFinish)
  270. {
  271. tablename = "view_orderlist_end";
  272. }
  273. dt = WebCache.GetData(tablename, dStruct);
  274. if (dt != null && dt.Rows.Count > 0)
  275. {
  276. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  277. foreach (DataRow dr in dt.Rows)
  278. {
  279. try
  280. {
  281. if (dr["refund_fees"] != null)
  282. {
  283. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  284. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  285. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  286. if (payment == refund_fees)
  287. {
  288. dr["refund_fees"] = Math.Round(refund_fees, 2);
  289. }
  290. else if (refund_fees == total_fee)
  291. {
  292. dr["refund_fees"] = payment;
  293. }
  294. else
  295. {
  296. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  297. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  298. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  299. }
  300. }
  301. // 对象操作
  302. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  303. ceErpTradeCell.ctid = dr["ctid"].ToString();
  304. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  305. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  306. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  307. if (dStruct.PageSize != 100000)
  308. {
  309. if (dr["DispatchSort"].ToString() == "2")
  310. {
  311. dr["gongchuang"] = 200;
  312. }
  313. else if ("外协".Equals(dr["ToType"].ToString()))
  314. {
  315. dr["gongchuang"] = 200;
  316. }
  317. else if ("内部".Equals(dr["ToType"].ToString()))
  318. {
  319. dr["gongchuang"] = -1;
  320. }
  321. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  322. {
  323. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  324. dr["gongchuang"] = response.code;
  325. }
  326. }
  327. }
  328. catch (NullReferenceException ex)
  329. {
  330. // 处理空引用异常
  331. dr["refund_fees"] = "0.00";
  332. }
  333. }
  334. }
  335. writeGridDataTableJson(dStruct.TotalCount, dt);
  336. }
  337. public void get_erp_orderlist_sumprice()
  338. {
  339. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  340. return;
  341. List<string> lw = new List<string>();
  342. string tid = GetPostString("ctid");
  343. string date1 = GetPostString("date1");
  344. string date2 = GetPostString("date2");
  345. if (tid.Length > 0 || date1.Length > 0)
  346. {
  347. lw.Add(string.Format("ctid like '%{0}%'", tid));
  348. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  349. if (dw.Length > 0) lw.Add(dw);
  350. }
  351. else
  352. {
  353. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  354. }
  355. string shopname = GetPostString("shopname");
  356. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  357. string buyernick = GetPostString("buyer_nick");
  358. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  359. string customer = GetPostString("customer");
  360. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  361. string design = GetPostString("design");
  362. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  363. string orderState = GetPostString("orderState");
  364. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  365. string address = GetPostString("address");
  366. 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));
  367. string sellermemo = GetPostString("seller_memo");
  368. if (sellermemo.Length > 0)
  369. {
  370. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  371. }
  372. string apdate1 = GetPostString("apdate1");
  373. string apdate2 = GetPostString("apdate2");
  374. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  375. if (dwap.Length > 0) lw.Add(dwap);
  376. string price1 = GetPostString("price1");
  377. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  378. string price2 = GetPostString("price2");
  379. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  380. string isoldcustomer = GetPostString("isoldcus");
  381. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  382. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  383. if (PKey != "admin")
  384. {
  385. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  386. lw.Add(string.Format("shopId in ({0})", usershop));
  387. }
  388. //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";
  389. string mainWhere = string.Join(" and ", lw.ToArray());
  390. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  391. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  392. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  393. decimal total = 0;
  394. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  395. {
  396. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  397. }
  398. var res = new
  399. {
  400. data = total
  401. };
  402. string ro_jsond = JsonConvert.SerializeObject(res);
  403. returnSuccess(ro_jsond);
  404. return;
  405. }
  406. public void get_erp_CustomerServiceGather()
  407. {
  408. string userWhere = "", orderWhere = "";
  409. List<string> lw = new List<string>();
  410. string customer = GetPostString("customer");
  411. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  412. string shopname = GetPostString("shopname");
  413. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  414. string date1 = GetPostString("date1");
  415. string date2 = GetPostString("date2");
  416. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  417. if (dw.Length > 0) lw.Add(dw);
  418. orderWhere = string.Join(" and ", lw.ToArray());
  419. 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 " +
  420. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  421. "left join " +
  422. "( " +
  423. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  424. ") as b on a.ID = b.CustomerUserId " +
  425. "left join " +
  426. "( " +
  427. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  428. ") as d on a.ID = d.CustomerUserId " +
  429. "left join " +
  430. "( " +
  431. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  432. ") as e on a.ID = e.CustomerUserId " +
  433. "left join " +
  434. "( " +
  435. " select CustomerUserId, RefundCount, RefundSum from " +
  436. " ( " +
  437. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  438. " from CE_ErpTradeRefund a " +
  439. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  440. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  441. " group by CustomerUserId " +
  442. " ) as a " +
  443. ") as f on a.ID = f.CustomerUserId " +
  444. "where a.PostCode = 'CustomerService'",
  445. userWhere, orderWhere);
  446. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  447. writeGridDataTableJson(dt.Rows.Count, dt);
  448. //writeGridDataTableJson(dt.Rows.Count, dt);
  449. }
  450. //设计汇总
  451. public void get_erp_DesignerGather()
  452. {
  453. string userWhere = "", orderWhere = "";
  454. List<string> lw = new List<string>();
  455. string Designer = GetPostString("designer");
  456. int org = GetPostInt("org");
  457. if (Designer.Length > 0)
  458. {
  459. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  460. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  461. }
  462. else if (org > 0)
  463. {
  464. userWhere = string.Format(" where OrgID ={0}", org);
  465. }
  466. string shopname = GetPostString("shopname");
  467. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  468. string state = GetPostString("state");
  469. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  470. string OrderArea = GetPostString("order_area");
  471. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  472. string date1 = GetPostString("date1");
  473. string date2 = GetPostString("date2");
  474. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  475. if (dw.Length > 0) lw.Add(dw);
  476. string UpDate1 = GetPostString("UpDate1");
  477. string UpDate2 = GetPostString("UpDate2");
  478. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  479. if (dw.Length > 0) lw.Add(dw);
  480. orderWhere = string.Join(" and ", lw.ToArray());
  481. 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 (" +
  482. "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 " +
  483. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  484. "left join " +
  485. "( " +
  486. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  487. ") as b on a.ID = b.DesignUserId " +
  488. "left join " +
  489. "( " +
  490. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  491. ") as d on a.ID = d.DesignUserId " +
  492. "left join " +
  493. "( " +
  494. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  495. ") as e on a.ID = e.DesignUserId " +
  496. "left join " +
  497. "( " +
  498. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  499. ") as g on a.ID = g.DesignUserId " +
  500. "left join " +
  501. "( " +
  502. " select CustomerUserId, RefundCount, RefundSum from " +
  503. " ( " +
  504. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  505. " from CE_ErpTradeRefund a " +
  506. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  507. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  508. " group by CustomerUserId " +
  509. " ) as a " +
  510. ") as f on a.ID = f.CustomerUserId " +
  511. "where a.PostCode = 'Designer') as z",
  512. userWhere, orderWhere);
  513. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  514. writeGridDataTableJson(dt.Rows.Count, dt);
  515. }
  516. //删除tradecell的订单
  517. public void del_erp_cellorder()
  518. {
  519. if (UrlPostParmsCheck("ctid"))
  520. {
  521. string eid = GetPostString("ctid");
  522. CeErpTradeCell.DelByCtid(eid);
  523. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  524. returnSuccessMsg("删除成功");
  525. }
  526. }
  527. public void clear_erp_refundstate()
  528. {
  529. if (UrlPostParmsCheck("ids"))
  530. {
  531. string eids = GetPostString("ids");
  532. string[] ctidList = eids.Split(',');
  533. foreach (string ctid in ctidList)
  534. {
  535. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  536. if (entity != null)
  537. {
  538. entity.IsRefund = 0;
  539. entity.Update();
  540. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  541. }
  542. else
  543. continue;
  544. }
  545. returnSuccessMsg("操作成功");
  546. return;
  547. }
  548. returnErrorMsg("缺少必要参数");
  549. }
  550. public void set_erp_urgency()
  551. {
  552. if (UrlPostParmsCheck("ctid"))
  553. {
  554. string eid = GetPostString("ctid");
  555. CeErpTradeCell entity = null;
  556. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  557. if (entity != null)
  558. {
  559. double prices = commonHelper.calculationPrice(entity);
  560. if (prices <= 100)
  561. {
  562. returnErrorMsg("此订单金额不足100元,无法加急。");
  563. return;
  564. }
  565. string utime = GetPostString("urgencytime");
  566. if (utime.Length > 0)
  567. {
  568. entity.UrgencyTime = Convert.ToDateTime(utime);
  569. }
  570. else
  571. {
  572. returnErrorMsg("请选择加急时间");
  573. return;
  574. }
  575. if (entity.OrderState <= 4)
  576. {
  577. //entity.seller_memo = entity.seller_memo + "-加急";
  578. string smemo = entity.seller_memo;
  579. int kindex = smemo.IndexOf(")");
  580. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  581. if (lastoneStr != "-")
  582. {
  583. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  584. }
  585. string prememo = smemo.Substring(0, kindex + 2);
  586. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  587. int lastkindex = lastmemo.IndexOf("(");
  588. DateTime urgtime = Convert.ToDateTime(utime);
  589. string newlastmemo = "";
  590. if (lastkindex == 0)
  591. {
  592. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  593. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  594. }
  595. else
  596. {
  597. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  598. }
  599. entity.seller_memo = prememo + newlastmemo;
  600. }
  601. entity.IsUrgency = true;
  602. entity.UpdateTime = DateTime.Now;
  603. entity.Update();
  604. ApiVo apiVo = new ApiVo();
  605. apiVo.orderNumber = entity.ctid;
  606. apiVo.actionName = "changeDesign";
  607. apiVo.orderRemarks = entity.seller_memo;
  608. apiVo.remarkSign = 3;
  609. designHelper.API_WorkCore(apiVo); //changeDesign
  610. CeErpSukuraData.createInfo(entity.ctid, 7);
  611. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  612. returnSuccessMsg("设置成功!");
  613. return;
  614. }
  615. returnErrorMsg("找不到记录");
  616. }
  617. }
  618. public void set_erp_reset()
  619. {
  620. if (UrlPostParmsCheck("ctid"))
  621. {
  622. string eid = GetPostString("ctid");
  623. CeErpTradeCell entity = null;
  624. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  625. if (entity != null)
  626. {
  627. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  628. {
  629. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  630. {
  631. returnErrorMsg("财务要求已下单已发货无法重置");
  632. return;
  633. }
  634. }
  635. entity.IsUrgency = false;
  636. entity.seller_memo = "";
  637. entity.OtherMemo = "";
  638. entity.OrderState = 0;
  639. entity.IsReturn = 0;
  640. //entity.IsRefund = 0;
  641. entity.MemoOpt = 0;
  642. entity.AfterSaleState = 0;
  643. entity.AfterSaleResponsible = "";
  644. entity.AfterSaleUserId = 0;
  645. entity.IsNeedBill = 0;
  646. entity.CustomerUserId = 0;
  647. entity.DesignUserId = 0;
  648. entity.SupplierId = 0;
  649. entity.PlaceUserId = 0;
  650. entity.ptid = "";
  651. entity.IsSample = 0;
  652. entity.IsXianHuo = 0;
  653. entity.isDianziOrder = 0;
  654. entity.DispatchSort = 0;
  655. entity.FinishPlaceTime = null;
  656. entity.Update();
  657. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  658. if (trade != null)
  659. {
  660. trade.seller_memo = "";
  661. trade.Update();
  662. }
  663. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  664. returnSuccessMsg("重置成功!");
  665. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  666. if (desginBill != null)
  667. {
  668. desginBill.isDel = 1;
  669. desginBill.Update();
  670. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  671. }
  672. ApiVo apiVo = new ApiVo();
  673. apiVo.orderNumber = entity.ctid;
  674. apiVo.actionName = "resetDesign";
  675. designHelper.API_WorkCore(apiVo);//resetDesign
  676. return;
  677. }
  678. returnErrorMsg("找不到记录");
  679. }
  680. }
  681. public void save_erp_sellermemo()
  682. {
  683. if (UrlPostParmsCheck("ctid"))
  684. {
  685. string ctid = GetPostString("ctid");
  686. CeErpTradeCell entity = null;
  687. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  688. if (entity != null)
  689. {
  690. string memo = GetPostString("seller_memo");
  691. memo = memo.Replace(" ", "");
  692. if (memo.Contains("补差"))
  693. {
  694. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  695. return;
  696. }
  697. List<string> bitList = new List<string>
  698. {
  699. "\\","/",":","*","?", "\"","<" ,">","|"
  700. };
  701. bool isIn = false;
  702. foreach (string bit in bitList)
  703. {
  704. if (memo.Contains(bit))
  705. {
  706. isIn = true;
  707. }
  708. }
  709. if (isIn)
  710. {
  711. returnErrorMsg("不能使用 一些符合作为文件名");
  712. return;
  713. }
  714. if (entity.seller_memo != memo)
  715. {
  716. if (entity.IsSample == 2)
  717. {
  718. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  719. return;
  720. }
  721. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  722. {
  723. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  724. {
  725. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  726. return;
  727. }
  728. /*if (CurrentUser.UserPost.Post.Code != "Place")
  729. {
  730. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  731. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  732. {
  733. returnErrorMsg("售前系统订单无法再此修改!");
  734. return;
  735. }
  736. }*/
  737. }
  738. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  739. }
  740. commonHelper.getCytPrice(entity);
  741. int memoopt = GetPostInt("MemoOpt");
  742. Boolean ismemoopt = false;
  743. if (memoopt > 0)
  744. {
  745. string stropt = "";
  746. if (memoopt == 1)
  747. {
  748. stropt = "“改稿”";
  749. ismemoopt = true;
  750. }
  751. else if (memoopt == 2)
  752. {
  753. stropt = "“定稿”";
  754. }
  755. else if (memoopt == 3)
  756. {
  757. stropt = "“查货”";
  758. CeErpSukuraData.createInfo(entity.ctid, 6);
  759. }
  760. entity.MemoOpt = Convert.ToInt32(memoopt);
  761. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  762. }
  763. if (entity.OrderState < 5)
  764. {
  765. memo = memo.Replace("(", "(");
  766. memo = memo.Replace(")", ")");
  767. }
  768. if (entity.OrderState < 3)
  769. {
  770. entity.DispatchSort = 0;
  771. }
  772. entity.seller_memo = memo;
  773. entity.UpdateTime = DateTime.Now;
  774. entity.Update();
  775. ApiVo apiVo = new ApiVo();
  776. apiVo.orderNumber = entity.ctid;
  777. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  778. apiVo.orderRemarks = memo;
  779. apiVo.remarkSign = memoopt;
  780. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  781. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  782. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  783. {
  784. dataHelper.api_orderBack(entity.ctid, "0", "");
  785. }
  786. if (entity.seller_memo.Contains("改稿"))
  787. {
  788. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  789. }
  790. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  791. returnSuccessMsg("保存成功!");
  792. return;
  793. }
  794. returnErrorMsg("找不到记录");
  795. }
  796. }
  797. public void ins_erp_checkorder()
  798. {
  799. if (UrlPostParmsCheck("ctid"))
  800. {
  801. string ctid = GetPostString("ctid");
  802. CeErpTradeCell entity = null;
  803. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  804. if (entity != null)
  805. {
  806. if (entity.OrderState < 6)
  807. {
  808. returnErrorMsg("下单完成后才可查货");
  809. return;
  810. }
  811. /*if (entity.OrderState > 6)
  812. {
  813. returnErrorMsg("订单已发货");
  814. return;
  815. }*/
  816. if (entity.FinishPlaceTime != null)
  817. {
  818. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  819. {
  820. returnErrorMsg("下单时间不足,无法查货");
  821. return;
  822. }
  823. }
  824. entity.MemoOpt = 3;
  825. entity.CheckOrderTime = DateTime.Now;
  826. entity.UpdateTime = DateTime.Now;
  827. entity.Update();
  828. CeErpSukuraData.createInfo(entity.ctid, 6);
  829. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  830. returnSuccessMsg("操作成功!");
  831. return;
  832. }
  833. returnErrorMsg("找不到记录");
  834. }
  835. }
  836. public void save_erp_othermemo()
  837. {
  838. if (UrlPostParmsCheck("ctid"))
  839. {
  840. string ctid = GetPostString("ctid");
  841. CeErpTradeCell entity = null;
  842. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  843. if (entity != null)
  844. {
  845. entity.OtherMemo = GetPostString("otherMemo");
  846. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  847. {
  848. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  849. StringBuilder sql = new StringBuilder();
  850. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  851. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  852. if (dt != null && dt.Rows.Count > 0)
  853. {
  854. foreach (DataRow dr in dt.Rows)
  855. {
  856. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  857. {
  858. //品类一直
  859. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  860. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  861. if (ceErpSampleCustomer == null)
  862. {
  863. ceErpSampleCustomer = new CeErpSampleCustomer();
  864. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  865. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  866. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  867. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  868. ceErpSampleCustomer.shopId = entity.ShopId;
  869. }
  870. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  871. ceErpSampleCustomer.lastTid = entity.tid;
  872. if (ceErpSampleCustomer.ID > 0)
  873. {
  874. ceErpSampleCustomer.Update();
  875. }
  876. else
  877. {
  878. ceErpSampleCustomer.Create();
  879. }
  880. }
  881. }
  882. }
  883. }
  884. //if (entity.IsOldCustomer == 1)
  885. //{
  886. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  887. //{
  888. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  889. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  890. //}
  891. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  892. //{
  893. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  894. // {
  895. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  896. // {
  897. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  898. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  899. // }
  900. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  901. // {
  902. // entity.OrderState = 2;
  903. // entity.DesignUserId = 0;
  904. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  905. // }
  906. // else
  907. // {
  908. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  909. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  910. // }
  911. // }
  912. //}
  913. //}
  914. entity.UpdateTime = DateTime.Now;
  915. entity.Update();
  916. returnSuccessMsg("保存成功!");
  917. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  918. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  919. if (entity.OtherMemo.Contains("改稿"))
  920. {
  921. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  922. }
  923. return;
  924. }
  925. returnErrorMsg("找不到记录");
  926. }
  927. }
  928. public void save_erp_customermemo()
  929. {
  930. if (UrlPostParmsCheck("ctid"))
  931. {
  932. string ctid = GetPostString("ctid");
  933. CeErpTradeCell entity = null;
  934. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  935. if (entity != null)
  936. {
  937. entity.UpdateTime = DateTime.Now;
  938. entity.CustomerMemo = GetPostString("CustomerMemo");
  939. entity.Update();
  940. ApiVo apiVo = new ApiVo();
  941. apiVo.orderNumber = entity.ctid;
  942. apiVo.actionName = "followRemarks";
  943. apiVo.orderRemarks = entity.CustomerMemo;
  944. designHelper.API_WorkCore(apiVo);//followRemarks
  945. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  946. returnSuccessMsg("保存成功!");
  947. return;
  948. }
  949. returnErrorMsg("找不到记录");
  950. }
  951. }
  952. public void upd_erp_addmemotag()
  953. {
  954. if (UrlPostParmsCheck("ctid"))
  955. {
  956. ;
  957. string eid = GetPostString("ctid");
  958. string sfTagstr = GetPostString("memotag");
  959. CeErpTradeCell entity = null;
  960. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  961. if (entity != null)
  962. {
  963. ApiVo apiVo = new ApiVo();
  964. if (entity.OrderState == 0)
  965. {
  966. returnErrorMsg("请先领单");
  967. return;
  968. }
  969. //撤销顺丰
  970. if (sfTagstr == "撤销顺丰")
  971. {
  972. entity.IsSF = 0;
  973. string reMsg = "";
  974. string oldmemo = entity.seller_memo;
  975. if (entity.OrderState < 5)
  976. {
  977. oldmemo = oldmemo.Replace("顺丰到付", "");
  978. oldmemo = oldmemo.Replace("顺丰寄付", "");
  979. entity.seller_memo = oldmemo;
  980. }
  981. else
  982. {
  983. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  984. {
  985. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  986. }
  987. }
  988. entity.Update();
  989. apiVo.orderNumber = entity.ctid;
  990. apiVo.actionName = "orderRemarks";
  991. apiVo.orderRemarks = entity.seller_memo;
  992. apiVo.isSf = entity.IsSF.ToString();
  993. designHelper.API_WorkCore(apiVo);//orderRemarks
  994. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  995. returnSuccessMsg("撤销成功!" + reMsg);
  996. return;
  997. }
  998. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  999. {
  1000. //string oldmemo = entity.seller_memo;
  1001. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1002. string sfStr = GetPostString("memotag");
  1003. string smemo = entity.seller_memo;
  1004. int kindex = smemo.IndexOf(")");
  1005. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1006. if (lastoneStr != "-")
  1007. {
  1008. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1009. }
  1010. string prememo = smemo.Substring(0, kindex + 2);
  1011. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1012. int lastkindex = lastmemo.IndexOf("(");
  1013. string newlastmemo = "";
  1014. if (lastkindex == 0)
  1015. {
  1016. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1017. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1018. }
  1019. else
  1020. {
  1021. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1022. }
  1023. entity.seller_memo = prememo + newlastmemo;
  1024. }
  1025. string sfTagMSg = "";
  1026. if (sfTagstr == "顺丰寄付")
  1027. {
  1028. entity.IsSF = 1;
  1029. sfTagMSg = "顺丰寄付";
  1030. }
  1031. else if (sfTagstr == "顺丰到付")
  1032. {
  1033. entity.IsSF = 2;
  1034. sfTagMSg = "顺丰到付";
  1035. }
  1036. entity.Update();
  1037. apiVo = new ApiVo();
  1038. apiVo.orderNumber = entity.ctid;
  1039. apiVo.actionName = "orderRemarks";
  1040. apiVo.orderRemarks = entity.seller_memo;
  1041. apiVo.isSf = entity.IsSF.ToString();
  1042. designHelper.API_WorkCore(apiVo);//orderRemarks
  1043. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1044. returnSuccessMsg("标记成功!");
  1045. return;
  1046. }
  1047. returnErrorMsg("找不到记录");
  1048. }
  1049. }
  1050. public void upd_erp_ordertag()
  1051. {
  1052. if (UrlPostParmsCheck("ctid"))
  1053. {
  1054. string eid = GetPostString("ctid");
  1055. CeErpTradeCell entity = null;
  1056. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1057. if (entity != null)
  1058. {
  1059. int tag = GetPostInt("wechattag");
  1060. //if(tag==4 && entity.IsSample == 2)
  1061. //{
  1062. // returnErrorMsg("补差价单不能标记微信单");
  1063. // return;
  1064. //}
  1065. entity.wechatTag = tag;
  1066. entity.Update();
  1067. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1068. if (tag == 1)
  1069. {
  1070. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1071. if (cash == null)
  1072. {
  1073. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1074. cash = new CeErpReturnCash();
  1075. cash.tid = entity.tid;
  1076. cash.seller_nick = main.seller_nick;
  1077. cash.payment = trade.payment;
  1078. cash.buyer_nick = main.buyer_nick;
  1079. cash.cashstate = 0;
  1080. cash.rtype = "微信返现";
  1081. cash.returnprice = 0;
  1082. cash.created = DateTime.Now;
  1083. cash.con = "订单标记微信单";
  1084. cash.img = "";
  1085. cash.applyuserid = CurrentUser.UserID;
  1086. cash.Create();
  1087. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1088. }
  1089. else
  1090. {
  1091. cash.cashstate = 0;
  1092. cash.Update();
  1093. }
  1094. CeErpSukuraData.createInfo(entity.ctid, 9);
  1095. }
  1096. else if (tag == 2)
  1097. {
  1098. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1099. if (cash == null)
  1100. {
  1101. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1102. cash = new CeErpReturnCash();
  1103. cash.tid = entity.tid;
  1104. cash.seller_nick = main.seller_nick;
  1105. cash.payment = trade.payment;
  1106. cash.buyer_nick = main.buyer_nick;
  1107. cash.cashstate = 0;
  1108. cash.rtype = "推购返现";
  1109. cash.returnprice = 5;
  1110. cash.created = DateTime.Now;
  1111. cash.con = "订单标记推购单";
  1112. cash.img = "";
  1113. cash.applyuserid = CurrentUser.UserID;
  1114. cash.Create();
  1115. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1116. }
  1117. else
  1118. {
  1119. cash.cashstate = 0;
  1120. cash.Update();
  1121. }
  1122. CeErpSukuraData.createInfo(entity.ctid, 9);
  1123. }
  1124. else if (tag == 3)
  1125. {
  1126. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1127. if (pers == null)
  1128. {
  1129. pers = new CeErpPersuade();
  1130. pers.ctid = entity.ctid;
  1131. pers.pstate = 0;
  1132. pers.created = DateTime.Now;
  1133. pers.applyuserid = CurrentUser.UserID;
  1134. pers.Create();
  1135. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1136. }
  1137. else
  1138. {
  1139. pers.pstate = 0;
  1140. pers.Update();
  1141. }
  1142. }
  1143. else if (tag == 4 || tag == 5)
  1144. {
  1145. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1146. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1147. if (pers == null)
  1148. {
  1149. pers = CeErpStayGoods.GetByTid(entity.tid);
  1150. }
  1151. if (pers == null)
  1152. {
  1153. pers = new CeErpStayGoods();
  1154. pers.t_id = entity.tid;
  1155. pers.ctid = entity.ctid;
  1156. pers.status = "待审核";
  1157. pers.audit_type = 0;
  1158. if (tag == 4)
  1159. {
  1160. pers.stay_type = "微信推购";
  1161. }
  1162. else
  1163. {
  1164. pers.stay_type = "旺旺推购";
  1165. }
  1166. if (entity.IsXianHuo == 0)
  1167. {
  1168. pers.product_id = entity.ProductId;
  1169. }
  1170. pers.wangwang = main.buyer_nick;
  1171. pers.shop_name = main.seller_nick;
  1172. pers.creata_time = DateTime.Now;
  1173. pers.create_u_id = CurrentUser.UserID;
  1174. pers.create_u_name = CurrentUser.UserName;
  1175. pers.Create();
  1176. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1177. }
  1178. else
  1179. {
  1180. pers.ctid = entity.ctid;
  1181. pers.audit_type = 0;
  1182. pers.Update();
  1183. }
  1184. CeErpSukuraData.createInfo(entity.ctid, 10);
  1185. }
  1186. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1187. returnSuccessMsg("标记成功!");
  1188. return;
  1189. }
  1190. returnErrorMsg("找不到记录");
  1191. }
  1192. }
  1193. public void upd_erp_ordertag_cancel()
  1194. {
  1195. if (UrlPostParmsCheck("ctid"))
  1196. {
  1197. string eid = GetPostString("ctid");
  1198. CeErpTradeCell entity = null;
  1199. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1200. if (entity != null)
  1201. {
  1202. entity.wechatTag = 0;
  1203. entity.Update();
  1204. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1205. if (pers != null)
  1206. {
  1207. pers.status = "取消推购";
  1208. pers.audit_type = 3;
  1209. pers.Update();
  1210. }
  1211. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1212. returnSuccessMsg("标记成功!");
  1213. return;
  1214. }
  1215. returnErrorMsg("找不到记录");
  1216. }
  1217. }
  1218. public void upd_erp_addweichattag()
  1219. {
  1220. if (UrlPostParmsCheck("ctid"))
  1221. {
  1222. ;
  1223. string eid = GetPostString("ctid");
  1224. CeErpTradeCell entity = null;
  1225. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1226. if (entity != null)
  1227. {
  1228. if (entity.IsAddWechat > 0)
  1229. {
  1230. returnErrorMsg("此单已经标记过了");
  1231. return;
  1232. }
  1233. 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);
  1234. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1235. if (dt.Rows.Count > 0)
  1236. {
  1237. entity.IsAddWechat = 2;
  1238. }
  1239. else
  1240. {
  1241. entity.IsAddWechat = 1;
  1242. }
  1243. entity.Update();
  1244. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1245. returnSuccessMsg("标记成功!");
  1246. return;
  1247. }
  1248. returnErrorMsg("找不到记录");
  1249. }
  1250. }
  1251. public void upd_erp_getmyorder()
  1252. {
  1253. if (UrlPostParmsCheck("ctid"))
  1254. {
  1255. ;
  1256. string eid = GetPostString("ctid");
  1257. CeErpTradeCell entity = null;
  1258. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1259. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1260. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1261. {
  1262. returnErrorMsg("台湾客户需填写身份证号!");
  1263. return;
  1264. }
  1265. if (entity != null)
  1266. {
  1267. if (entity.ctid.IndexOf("C") != -1)
  1268. {
  1269. StringBuilder sql = new StringBuilder();
  1270. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1271. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1272. if (dt.Rows.Count > 0)
  1273. {
  1274. decimal total = 0;
  1275. foreach (DataRow dr in dt.Rows)
  1276. {
  1277. total += Convert.ToDecimal(dr["payment"]);
  1278. }
  1279. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1280. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1281. {
  1282. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1283. return;
  1284. }
  1285. }
  1286. }
  1287. if (entity.OrderState == -1)
  1288. {
  1289. returnErrorMsg("待审核订单无法领取!");
  1290. return;
  1291. }
  1292. entity.CustomerUserId = CurrentUser.UserID;
  1293. if (entity.OrderState < 2)
  1294. {
  1295. entity.OrderState = 2;
  1296. if (entity.ShopId != 0)
  1297. {
  1298. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1299. }
  1300. }
  1301. entity.UpdateTime = DateTime.Now;
  1302. entity.Update();
  1303. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1304. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1305. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1306. {
  1307. dataHelper.api_orderBack(entity.ctid, "0", "");
  1308. }
  1309. returnSuccessMsg("领单成功!");
  1310. return;
  1311. }
  1312. returnErrorMsg("找不到记录");
  1313. }
  1314. }
  1315. public void getmyorder_from_init()
  1316. {
  1317. if (UrlPostParmsCheck("ctid"))
  1318. {
  1319. string eid = GetPostString("ctid");
  1320. CeErpTradeCell entity = null;
  1321. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1322. if (entity != null)
  1323. {
  1324. string sellerMemo = GetPostString("sellerMemo");
  1325. if (sellerMemo.Length > 0)
  1326. {
  1327. entity.seller_memo = sellerMemo;
  1328. }
  1329. string oterhMemo = GetPostString("otherMemo");
  1330. if (oterhMemo.Length > 0)
  1331. {
  1332. entity.OtherMemo = oterhMemo;
  1333. }
  1334. int urg = GetPostInt("urgency");
  1335. entity.IsUrgency = (urg == 1 ? true : false);
  1336. int wechat = GetPostInt("wechat");
  1337. int command = GetPostInt("command");
  1338. if (wechat == 1)
  1339. {
  1340. entity.wechatTag = 1;
  1341. }
  1342. if (command == 1)
  1343. {
  1344. entity.wechatTag = 2;
  1345. }
  1346. string pPro = GetPostString("pprofession");
  1347. if (pPro.Length > 0)
  1348. {
  1349. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1350. string spro = GetPostString("profession");
  1351. if (spro.Length > 0)
  1352. {
  1353. entity.ProfessionId = Convert.ToInt32(spro);
  1354. }
  1355. }
  1356. string proId = GetPostString("productId");
  1357. if (proId.Length > 0)
  1358. {
  1359. entity.ProductId = Convert.ToInt32(proId);
  1360. }
  1361. entity.Material = GetPostString("material");
  1362. entity.Craft = GetPostString("craft");
  1363. entity.CustomerUserId = CurrentUser.UserID;
  1364. if (entity.OrderState < 2)
  1365. {
  1366. entity.OrderState = 2;
  1367. if (entity.ShopId != 0)
  1368. {
  1369. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1370. }
  1371. }
  1372. entity.Update();
  1373. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1374. returnSuccessMsg("领单成功!");
  1375. return;
  1376. }
  1377. returnErrorMsg("找不到记录");
  1378. }
  1379. }
  1380. public void upd_erp_setrelationorder()
  1381. {
  1382. if (UrlPostParmsCheck("ctid"))
  1383. {
  1384. ;
  1385. string eid = GetPostString("ctid");
  1386. string ftid = GetPostString("ftid");
  1387. CeErpTradeCell entity = null;
  1388. CeErpTradeCell fentity = null;
  1389. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1390. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1391. if (fentity == null)
  1392. {
  1393. returnErrorMsg("找不到关联的主订单");
  1394. return;
  1395. }
  1396. if (entity != null)
  1397. {
  1398. if (entity.OrderState >= 5)
  1399. {
  1400. returnErrorMsg("本单已经设计完成无法关联");
  1401. return;
  1402. }
  1403. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1404. {
  1405. returnErrorMsg("线下单续审核后才能关联!");
  1406. return;
  1407. }
  1408. entity.ptid = ftid;
  1409. entity.OrderState = fentity.OrderState;
  1410. //entity.status = fentity.status;
  1411. entity.CustomerUserId = fentity.CustomerUserId;
  1412. entity.DesignUserId = fentity.DesignUserId;
  1413. entity.seller_memo = "补差价单:" + ftid;
  1414. entity.IsSample = 2;
  1415. entity.Update();
  1416. ApiVo apiVo = new ApiVo();
  1417. apiVo.orderNumber = ftid;
  1418. apiVo.payment = entity.payment;
  1419. apiVo.actionName = "repairDesign";
  1420. designHelper.API_WorkCore(apiVo);//repairDesign
  1421. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1422. returnSuccessMsg("关联成功!");
  1423. return;
  1424. }
  1425. else
  1426. returnErrorMsg("找不到记录");
  1427. }
  1428. }
  1429. public void download_erp_neworder()
  1430. {
  1431. string seller = GetPostString("seller_nick");
  1432. string tid = GetPostString("tid");
  1433. if (seller.Length <= 0 || tid.Length <= 0)
  1434. {
  1435. returnErrorMsg("数据错误");
  1436. }
  1437. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1438. //{
  1439. // returnErrorMsg("找不到店铺Sessionkey");
  1440. //}
  1441. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1442. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1443. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1444. if (res.IndexOf("refOid") == -1)
  1445. {
  1446. returnErrorMsg("下载订单数据失败");
  1447. return;
  1448. }
  1449. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1450. returnSuccessMsg("下载完成");
  1451. //tmcHelper.createNewOrder(res);
  1452. //CeErpTrade entr = null;
  1453. //entr = CeErpTrade.Get(tid);
  1454. //if (entr != null)
  1455. //{
  1456. // returnSuccess("下载成功");
  1457. // //下载成功之后,Cell表生成对应的订单;
  1458. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1459. //}
  1460. //else
  1461. //{
  1462. // returnErrorMsg("下载失败或者创建订单失败");
  1463. //}
  1464. }
  1465. public void set_erp_atersale()
  1466. {
  1467. if (UrlPostParmsCheck("ctid"))
  1468. {
  1469. string eid = GetPostString("ctid");
  1470. string reason = GetPostString("AfterSaleReason");
  1471. CeErpTradeCell entity = null;
  1472. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1473. if (entity != null)
  1474. {
  1475. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1476. {
  1477. returnErrorMsg("此订单已经在售后");
  1478. return;
  1479. }
  1480. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1481. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1482. entity.AfterSaleTime = DateTime.Now;
  1483. entity.Update();
  1484. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1485. returnSuccessMsg("转售后成功!");
  1486. return;
  1487. }
  1488. returnErrorMsg("找不到记录");
  1489. }
  1490. }
  1491. public void set_erp_withdraw()
  1492. {
  1493. if (UrlPostParmsCheck("ctid"))
  1494. {
  1495. try
  1496. {
  1497. string eid = GetPostString("ctid");//商品id
  1498. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1499. CeWithdraw ceWithdrawSelect = null;
  1500. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1501. if (ceWithdrawSelect != null)
  1502. {
  1503. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1504. {
  1505. ceWithdrawSelect.status = -1;
  1506. ceWithdrawSelect.Update();
  1507. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1508. returnSuccessMsg("重新发起审核成功");
  1509. return;
  1510. }
  1511. else
  1512. {
  1513. returnSuccessMsg("请勿重复申请!");
  1514. return;
  1515. }
  1516. }
  1517. else
  1518. {
  1519. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1520. if (string.IsNullOrEmpty(CustomerUserId))
  1521. {
  1522. CustomerUserId = "-1";
  1523. }
  1524. int Userid = CurrentUser.UserID;//用户id
  1525. CeWithdraw ceWithdraw = new CeWithdraw();
  1526. ceWithdraw.tid = eid;
  1527. ceWithdraw.userid = Userid;
  1528. ceWithdraw.providerid = CustomerUserId;
  1529. ceWithdraw.status = 3;
  1530. ceWithdraw.creationtime = DateTime.Now;
  1531. ceWithdraw.Create();
  1532. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1533. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1534. return;
  1535. }
  1536. }
  1537. catch
  1538. {
  1539. returnErrorMsg("申请撤回订单失败");
  1540. return;
  1541. }
  1542. }
  1543. }
  1544. public void ins_erp_billinfo()
  1545. {
  1546. if (UrlPostParmsCheck("ctid"))
  1547. {
  1548. string eid = GetPostString("ctid");
  1549. CeErpTradeCell entity = null;
  1550. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1551. if (entity != null)
  1552. {
  1553. CeErpBill bill = CeErpBill.GetByTid(eid);
  1554. bool isHave = false;
  1555. if (bill != null)
  1556. {
  1557. isHave = true;
  1558. if (bill.state != 4)
  1559. {
  1560. returnErrorMsg("此单已经申请过发票了");
  1561. return;
  1562. }
  1563. }
  1564. if (entity.IsNeedBill == 0)
  1565. {
  1566. entity.IsNeedBill = 1;
  1567. }
  1568. entity.Update();
  1569. string errjson = "";
  1570. try
  1571. {
  1572. CeErpBill bill_entity = new CeErpBill();
  1573. bill_entity.tid = entity.tid;
  1574. bill_entity.title = GetPostString("title");
  1575. string taxstr = GetPostString("tax");
  1576. taxstr = taxstr.Replace(" ", "");
  1577. bill_entity.tax = taxstr;
  1578. bill_entity.bank = GetPostString("bank");
  1579. string bankacstr = GetPostString("bankac");
  1580. bankacstr = bankacstr.Replace(" ", "");
  1581. bill_entity.bankac = bankacstr;
  1582. bill_entity.address = GetPostString("address");
  1583. bill_entity.phone = GetPostString("phone");
  1584. bill_entity.price = GetPostString("price");
  1585. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1586. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1587. {
  1588. billCount += 1;
  1589. }
  1590. string prebill = "ltb";
  1591. for (int idx = 1; idx <= billCount; idx++)
  1592. {
  1593. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1594. string billoid = prebill + idx + dtstr;
  1595. bill_entity.billOrderId += billoid;
  1596. if (idx < billCount)
  1597. {
  1598. bill_entity.billOrderId += ",";
  1599. }
  1600. }
  1601. bill_entity.productId = GetPostInt("ProductName");
  1602. bill_entity.num = GetPostInt("num");
  1603. bill_entity.unit = GetPostString("unit");
  1604. bill_entity.type = GetPostString("type");
  1605. bill_entity.sendType = GetPostString("SendType");
  1606. bill_entity.email = GetPostString("email");
  1607. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1608. bill_entity.shopName = GetPostString("ShopName");
  1609. bill_entity.applymemo = GetPostString("applyMemo");
  1610. bill_entity.createTime = DateTime.Now;
  1611. bill_entity.state = 0;
  1612. bill_entity.userId = CurrentUser.UserID;
  1613. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1614. bill_entity.Create();
  1615. }
  1616. catch (Exception ex)
  1617. {
  1618. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1619. returnErrorMsg("创建发票出错!");
  1620. return;
  1621. }
  1622. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1623. returnSuccessMsg("发票申请成功!");
  1624. return;
  1625. }
  1626. returnErrorMsg("找不到记录");
  1627. }
  1628. }
  1629. public void ins_erp_neworder()
  1630. {
  1631. if (UrlPostParmsCheck("receiver_name"))
  1632. {
  1633. CeErpTrade entity = new CeErpTrade();
  1634. string plat_form = GetPostString("platform");
  1635. string preStr = "N_";
  1636. if (plat_form == "拼多多")
  1637. {
  1638. preStr = "P_";
  1639. }
  1640. else if (plat_form == "阿里巴巴")
  1641. {
  1642. preStr = "A_";
  1643. }
  1644. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1645. entity.seller_nick = GetPostString("seller_nick");
  1646. entity.buyer_nick = GetPostString("buyer_nick");
  1647. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1648. entity.total_fee = entity.payment;
  1649. entity.pay_time = DateTime.Now;
  1650. entity.status = "NOT_SHIPPED";
  1651. entity.receiver_name = GetPostString("receiver_name");
  1652. entity.receiver_mobile = GetPostString("receiver_mobile");
  1653. entity.receiver_state = GetPostString("receiver_state");
  1654. entity.receiver_city = GetPostString("receiver_city");
  1655. entity.receiver_district = GetPostString("receiver_district");
  1656. entity.receiver_address = GetPostString("receiver_address");
  1657. if (entity.receiver_state == "" || entity.receiver_city == "")
  1658. {
  1659. returnErrorMsg("收件地址不能为空");
  1660. return;
  1661. }
  1662. int shopId = 0;
  1663. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1664. if (nShop != null)
  1665. {
  1666. shopId = nShop.ID;
  1667. }
  1668. if (shopId != 34 && entity.payment == 0)
  1669. {
  1670. returnErrorMsg("公司自用的单金额才能为0");
  1671. return;
  1672. }
  1673. entity.Create();
  1674. CeErpTradeCell entitycell = new CeErpTradeCell();
  1675. entitycell.ctid = entity.tid;
  1676. entitycell.tid = entity.tid;
  1677. entitycell.ShopId = shopId;
  1678. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1679. entitycell.OrderState = 0;
  1680. entitycell.pay_time = entity.pay_time;
  1681. entitycell.IsOffLineOrder = 1;
  1682. entitycell.Create();
  1683. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1684. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1685. return;
  1686. }
  1687. }
  1688. public void ins_erp_neworder2()
  1689. {
  1690. if (UrlPostParmsCheck("receiver_name"))
  1691. {
  1692. //string plat_form = GetPostString("platform");
  1693. string preStr = "X_";
  1694. string memo = GetPostString("memo");
  1695. string productId = GetPostString("productId");
  1696. string primg = GetPostString("proofimg");
  1697. string sellerNick = GetPostString("seller_nick");
  1698. string addFrom = GetPostString("addfrom");
  1699. if (addFrom == "1")
  1700. {
  1701. preStr = "N_";
  1702. }
  1703. int shopId = 0;
  1704. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1705. if (nShop != null)
  1706. {
  1707. shopId = nShop.ID;
  1708. }
  1709. else
  1710. {
  1711. returnErrorMsg("找不到对应店铺");
  1712. return;
  1713. }
  1714. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1715. {
  1716. returnErrorMsg("必须上传付款凭证");
  1717. return;
  1718. }
  1719. CeErpTrade entity = new CeErpTrade();
  1720. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1721. entity.seller_nick = sellerNick;
  1722. entity.buyer_nick = GetPostString("buyer_nick");
  1723. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1724. entity.total_fee = entity.payment;
  1725. entity.pay_time = DateTime.Now;
  1726. entity.status = "NOT_SHIPPED";
  1727. entity.receiver_name = GetPostString("receiver_name");
  1728. entity.receiver_mobile = GetPostString("receiver_mobile");
  1729. entity.receiver_state = GetPostString("receiver_state");
  1730. entity.receiver_city = GetPostString("receiver_city");
  1731. entity.receiver_district = GetPostString("receiver_district");
  1732. entity.receiver_address = GetPostString("receiver_address");
  1733. entity.seller_memo = memo;
  1734. entity.orderFrom = 20;
  1735. entity.orderType = 15;
  1736. if (entity.receiver_state == "" || entity.receiver_city == "")
  1737. {
  1738. returnErrorMsg("收件地址不能为空");
  1739. return;
  1740. }
  1741. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1742. {
  1743. returnErrorMsg("公司自用的单金额才能为0");
  1744. return;
  1745. }
  1746. entity.Create();
  1747. string toWhere = GetPostString("towhere");
  1748. CeErpTradeCell entitycell = new CeErpTradeCell();
  1749. entitycell.ctid = entity.tid;
  1750. //唯一标识
  1751. entitycell.OrderSn = entity.tid;
  1752. string orderSn = dataHelper.getSaleOrderSn();
  1753. if (orderSn != "")
  1754. {
  1755. entitycell.OrderSn = orderSn;
  1756. }
  1757. entitycell.tid = entity.tid;
  1758. //if (preStr == "X_")
  1759. //{
  1760. entitycell.IsOffLineOrder = 1;
  1761. //}
  1762. entitycell.CustomerUserId = CurrentUser.UserID;
  1763. entitycell.PayProofImg = primg;
  1764. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1765. entitycell.ProductId = Convert.ToInt32(productId);
  1766. entitycell.ShopId = shopId;
  1767. entitycell.UpdateTime = DateTime.Now;
  1768. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1769. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1770. {
  1771. entitycell.IsXianHuo = 1;
  1772. }
  1773. entitycell.pay_time = entity.pay_time;
  1774. if (toWhere == "1")
  1775. {
  1776. entitycell.OrderState = 2;
  1777. }
  1778. else
  1779. {
  1780. entitycell.OrderState = 6;
  1781. entitycell.FinishPlaceTime = entitycell.pay_time;
  1782. }
  1783. if (shopId == 94)
  1784. {
  1785. entitycell.OrderState = 4;
  1786. entitycell.WaitDesignTime = entitycell.pay_time;
  1787. entitycell.StartDesignTime = entitycell.pay_time;
  1788. entitycell.DesignUserId = 218;
  1789. }
  1790. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1791. {
  1792. entitycell.OrderState = -1;//修改12-5
  1793. CeWithdraw ceWithdraw = new CeWithdraw();
  1794. ceWithdraw.tid = entity.tid;
  1795. ceWithdraw.providerid = "-1";
  1796. ceWithdraw.status = -1;
  1797. ceWithdraw.creationtime = DateTime.Now;
  1798. ceWithdraw.userid = 1337;
  1799. ceWithdraw.Create();
  1800. }
  1801. entitycell.Create();
  1802. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1803. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1804. {
  1805. addPlaceRegist(entitycell, CurrentUser.UserID);
  1806. }
  1807. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1808. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1809. return;
  1810. }
  1811. }
  1812. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1813. {
  1814. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1815. entity.PlactTime = tradecell.pay_time;
  1816. entity.AddUserId = userid;
  1817. entity.FileName = tradecell.seller_memo;
  1818. entity.Supplier = 24;
  1819. entity.CreateTime = DateTime.Now;
  1820. entity.Did = tradecell.ctid;
  1821. entity.tid = tradecell.tid;
  1822. entity.splitTag = tradecell.SplitTag;
  1823. entity.CurState = "未完成";
  1824. entity.Create();
  1825. }
  1826. public void get_erp_offlinelist()
  1827. {
  1828. DataStruct dStruct = GetPostStruct();
  1829. List<string> lw = new List<string>();
  1830. string tid = GetPostString("ctid");
  1831. string date1 = GetPostString("date1");
  1832. string date2 = GetPostString("date2");
  1833. if (tid.Length > 0 || date1.Length > 0)
  1834. {
  1835. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1836. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1837. if (dw.Length > 0) lw.Add(dw);
  1838. }
  1839. else
  1840. {
  1841. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1842. }
  1843. string shopname = GetPostString("shopname");
  1844. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1845. string buyernick = GetPostString("buyer_nick");
  1846. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1847. string customer = GetPostString("customer");
  1848. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1849. string design = GetPostString("design");
  1850. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1851. string orderState = GetPostString("orderState");
  1852. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1853. string address = GetPostString("address");
  1854. 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));
  1855. string sellermemo = GetPostString("seller_memo");
  1856. if (sellermemo.Length > 0)
  1857. {
  1858. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1859. }
  1860. string price1 = GetPostString("price1");
  1861. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1862. string price2 = GetPostString("price2");
  1863. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1864. //if (PKey != "admin")
  1865. //{
  1866. // string usershop = CurrentUser.User.pemShop;
  1867. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1868. //}
  1869. //if (ex_psize > 0)
  1870. //{
  1871. dStruct.Order = "pay_time desc";
  1872. //}
  1873. //else
  1874. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1875. lw.Add(string.Format("IsOffLineOrder=1"));
  1876. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1877. DataTable dt = null;
  1878. dt = WebCache.GetData("view_erptradecell", dStruct);
  1879. writeGridDataTableJson(dStruct.TotalCount, dt);
  1880. }
  1881. public void get_erp_returncashrecord()
  1882. {
  1883. DataStruct dStruct = GetPostStruct();
  1884. List<string> lw = new List<string>();
  1885. string tid = GetPostString("ctid");
  1886. if (tid.Length > 0)
  1887. {
  1888. lw.Add(string.Format("tid like '%{0}%'", tid));
  1889. dStruct.Order = "id desc";
  1890. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1891. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1892. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1893. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1894. return;
  1895. }
  1896. returnErrorMsg("id数据错误!");
  1897. }
  1898. public void ins_erp_returncashrecord()
  1899. {
  1900. if (UrlPostParmsCheck("tid"))
  1901. {
  1902. string tid = GetPostString("tid");
  1903. string retype = GetPostString("type");
  1904. StringBuilder sql = new StringBuilder();
  1905. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1906. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1907. if (dt.Rows.Count > 0)
  1908. {
  1909. returnErrorMsg("相同返现类型记录已存在");
  1910. return;
  1911. }
  1912. CeErpReturnCash entity = new CeErpReturnCash();
  1913. entity.tid = tid;
  1914. entity.seller_nick = GetPostString("seller_nick");
  1915. string pment = GetPostString("payment");
  1916. if (pment.Length > 0)
  1917. {
  1918. entity.payment = Convert.ToDouble(pment);
  1919. }
  1920. entity.buyer_nick = GetPostString("buyer_nick");
  1921. entity.cashstate = 0;
  1922. entity.rtype = retype;
  1923. string rPrice = GetPostString("returnprice");
  1924. if (rPrice.Length > 0)
  1925. {
  1926. entity.returnprice = Convert.ToDouble(rPrice);
  1927. }
  1928. entity.created = DateTime.Now;
  1929. entity.con = GetPostString("con");
  1930. entity.img = GetPostString("img");
  1931. entity.applyuserid = CurrentUser.UserID;
  1932. entity.Create();
  1933. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1934. returnSuccessMsg("操作成功!");
  1935. return;
  1936. }
  1937. }
  1938. public void set_erp_predelivery()
  1939. {
  1940. if (UrlPostParmsCheck("ctid"))
  1941. {
  1942. string eid = GetPostString("ctid");
  1943. CeErpTradeCell entity = null;
  1944. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1945. if (entity != null)
  1946. {
  1947. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1948. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1949. //{
  1950. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1951. // return;
  1952. //}
  1953. entity.IsPreDelivery = 1;
  1954. entity.Update();
  1955. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1956. returnSuccessMsg("预发货成功!");
  1957. return;
  1958. //string shop = GetPostString("seller_nick");
  1959. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1960. //string comName = GetPostString("comName");
  1961. //string comCode = GetPostString("comCode");
  1962. //string outSid = GetPostString("outSid");//运单号
  1963. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1964. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1965. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1966. //string apires = "";
  1967. //if (deliveryType == "虚拟发货")
  1968. //{
  1969. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1970. //}
  1971. //else
  1972. //{
  1973. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1974. //}
  1975. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1976. ////{
  1977. //if (apires.IndexOf("发货成功") != -1)
  1978. //{
  1979. // if (deliveryType != "虚拟发货")
  1980. // {
  1981. // //还要插入快递信息到 快递信息表
  1982. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1983. // exinfo.tid = eid;
  1984. // exinfo.out_sid = outSid;
  1985. // exinfo.company_code = comCode;
  1986. // exinfo.company_name = comName;
  1987. // exinfo.delivery_memo = deliveryMemo;
  1988. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1989. // exinfo.deliveryType = deliveryType;
  1990. // exinfo.Create();
  1991. // }
  1992. // returnSuccessMsg("发货成功!");
  1993. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1994. //}
  1995. //else
  1996. //{
  1997. // returnErrorMsg("淘宝发货失败!!");
  1998. //}
  1999. //return;
  2000. }
  2001. returnErrorMsg("找不到订单记录");
  2002. }
  2003. }
  2004. public void get_erp_unusuallist()
  2005. {
  2006. DataStruct dStruct = GetPostStruct();
  2007. List<string> lw = new List<string>();
  2008. string tid = GetPostString("ctid");
  2009. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2010. string shopname = GetPostString("shopname");
  2011. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2012. string buyernick = GetPostString("buyer_nick");
  2013. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2014. string ResponsibleMan = GetPostString("responsible");
  2015. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2016. string date1 = GetPostString("date1");
  2017. string date2 = GetPostString("date2");
  2018. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2019. if (dw.Length > 0) lw.Add(dw);
  2020. string price1 = GetPostString("price1");
  2021. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2022. string price2 = GetPostString("price2");
  2023. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2024. string orderState = GetPostString("orderState");
  2025. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2026. string sellermemo = GetPostString("seller_memo");
  2027. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2028. lw.Add(string.Format("UnusualTag > 0"));
  2029. lw.Add(string.Format("IsRefund<={0}", 1));
  2030. dStruct.Order = "pay_time desc";
  2031. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2032. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2033. writeGridDataTableJson(dStruct.TotalCount, dt);
  2034. }
  2035. public void set_erp_unusualtonomal()
  2036. {
  2037. if (UrlPostParmsCheck("ctid"))
  2038. {
  2039. string eid = GetPostString("ctid");
  2040. CeErpTradeCell entity = null;
  2041. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2042. if (entity != null)
  2043. {
  2044. entity.UnusualTag = -1;
  2045. entity.Update();
  2046. returnSuccessMsg("忽略成功!");
  2047. return;
  2048. }
  2049. returnErrorMsg("找不到记录");
  2050. }
  2051. }
  2052. public void ins_erp_unusualreason()
  2053. {
  2054. if (UrlPostParmsCheck("ctid"))
  2055. {
  2056. string eid = GetPostString("ctid");
  2057. CeErpTradeCell entity = null;
  2058. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2059. if (entity != null)
  2060. {
  2061. entity.MemoOpt = 4;
  2062. entity.UnusualCon = GetPostString("con");
  2063. entity.Update();
  2064. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2065. if (trade != null)
  2066. {
  2067. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2068. }
  2069. //查货是否超时
  2070. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2071. if (ceErpTradeCellExtend == null)
  2072. {
  2073. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2074. ceErpTradeCellExtend.ctid = entity.ctid;
  2075. }
  2076. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2077. {
  2078. ceErpTradeCellExtend.CheckOut += 1;
  2079. }
  2080. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2081. if (ceErpTradeCellExtend.ID > 0)
  2082. {
  2083. ceErpTradeCellExtend.Update();
  2084. }
  2085. else
  2086. {
  2087. ceErpTradeCellExtend.Create();
  2088. }
  2089. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2090. returnSuccessMsg("操作成功!");
  2091. return;
  2092. }
  2093. returnErrorMsg("找不到记录");
  2094. }
  2095. }
  2096. public void upd_erp_sampleorder()
  2097. {
  2098. if (UrlPostParmsCheck("ctid"))
  2099. {
  2100. string eid = GetPostString("ctid");
  2101. string[] eArr = eid.Split(',');
  2102. if (eArr.Length > 1)
  2103. {
  2104. List<string> eLst = new List<string>();
  2105. for (int i = 0; i < eArr.Length; i++)
  2106. {
  2107. eLst.Add("'" + eArr[i] + "'");
  2108. }
  2109. eid = string.Join(",", eLst.ToArray());
  2110. }
  2111. else
  2112. {
  2113. eid = "'" + eid + "'";
  2114. }
  2115. StringBuilder sql = new StringBuilder();
  2116. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2117. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2118. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2119. if (dt.Rows.Count > 0)
  2120. {
  2121. string errmsg = "";
  2122. foreach (DataRow dr in dt.Rows)
  2123. {
  2124. StringBuilder sqlsb = new StringBuilder();
  2125. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2126. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2127. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2128. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2129. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2130. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2131. {
  2132. continue;
  2133. }
  2134. else
  2135. {
  2136. string emsg = commonHelper.KeepChinese(apires);
  2137. errmsg += emsg;
  2138. }
  2139. }
  2140. if (errmsg.Length > 0)
  2141. {
  2142. returnErrorMsg(errmsg);
  2143. return;
  2144. }
  2145. returnSuccessMsg("操作成功");
  2146. return;
  2147. }
  2148. returnErrorMsg("找不到记录");
  2149. }
  2150. }
  2151. public void upd_erp_transcustomer()
  2152. {
  2153. if (UrlPostParmsCheck("ctid"))
  2154. {
  2155. string eid = GetPostString("ctid");
  2156. int userid = GetPostInt("CustomerUserId");
  2157. CeErpTradeCell entity = null;
  2158. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2159. if (entity != null)
  2160. {
  2161. //string[] mlist = entity.seller_memo.Split('-');
  2162. //string sql = "select * from view_erpuser where id=" + userid;
  2163. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2164. //if (dt != null && dt.Rows.Count > 0)
  2165. //{
  2166. // string nmemo = "";
  2167. // for(int i = 0; i < mlist.Length - 1; i++)
  2168. // {
  2169. // nmemo += mlist[i];
  2170. // nmemo += "-";
  2171. // }
  2172. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2173. // entity.seller_memo = nmemo;
  2174. //}
  2175. entity.CustomerUserId = userid;
  2176. entity.Update();
  2177. returnSuccessMsg("操作成功!");
  2178. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2179. return;
  2180. }
  2181. returnErrorMsg("找不到记录");
  2182. }
  2183. }
  2184. public void upd_erp_transdesigner()
  2185. {
  2186. if (UrlPostParmsCheck("ctid"))
  2187. {
  2188. string eids = GetPostString("ctid");
  2189. string[] ctidList = eids.Split(',');
  2190. int userid = GetPostInt("DesignUserId");
  2191. foreach (string ctid in ctidList)
  2192. {
  2193. CeErpTradeCell entity = null;
  2194. CeErpDesignerBill entitys = null;
  2195. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2196. entitys = CeErpDesignerBill.GetByTid(ctid);
  2197. if (entity != null)
  2198. {
  2199. if (entity.OrderState > 4)
  2200. {
  2201. continue;
  2202. }
  2203. //存在退款不能流转
  2204. if (entity.IsRefund > 0)
  2205. {
  2206. continue;
  2207. }
  2208. entity.DesignUserId = userid;
  2209. entity.WaitDesignTime = DateTime.Now;
  2210. entity.Update();
  2211. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2212. }
  2213. }
  2214. returnSuccessMsg("操作成功!");
  2215. }
  2216. }
  2217. public void upd_erp_distributedesigner()
  2218. {
  2219. if (UrlPostParmsCheck("ctid"))
  2220. {
  2221. string eid = GetPostString("ctid");
  2222. int userid = GetPostInt("DesignUserId");
  2223. string[] idlist = eid.Split(',');
  2224. if (idlist.Length <= 0)
  2225. {
  2226. returnErrorMsg("订单不能为空");
  2227. return;
  2228. }
  2229. foreach (string ctid in idlist)
  2230. {
  2231. CeErpTradeCell entity = null;
  2232. CeErpDesignerBill entitys = null;
  2233. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2234. else continue;
  2235. if (entity != null)
  2236. {
  2237. if (userid == 2125 || userid == 3542)
  2238. { }
  2239. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2240. {
  2241. returnErrorMsg("金额错误的订单无法指派");
  2242. return;
  2243. }
  2244. if (entity.OrderState >= 5)
  2245. {
  2246. returnErrorMsg("已经设计完成无法指派");
  2247. return;
  2248. }
  2249. if (entity.OrderState == -1)
  2250. {
  2251. returnErrorMsg("审核中的订单无法指派");
  2252. return;
  2253. }
  2254. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2255. {
  2256. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2257. return;
  2258. }
  2259. //157赖橙帆 159林晨 73 静之颖
  2260. 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)
  2261. {
  2262. returnErrorMsg("指派设计共创无法再次指派!");
  2263. return;
  2264. }
  2265. entity.OrderState = 3;
  2266. if (entity.SupplierId == 0)
  2267. {
  2268. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2269. entity.SupplierId = suid;
  2270. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2271. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2272. }
  2273. if (userid == 2125 && entity.seller_memo != "")
  2274. {
  2275. apiDesign.API_GetPrintData_CreateOrder(entity);
  2276. }
  2277. if (userid == 3542 && entity.seller_memo != "")
  2278. {
  2279. string userPost = CurrentUser.UserPost.Post.Code;
  2280. if (CurrentUser.UserID == 73)
  2281. {
  2282. userPost = "SysAdmin";
  2283. }
  2284. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2285. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2286. if (response.msg != "设计共创:成功")
  2287. {
  2288. returnErrorMsg(response.msg);
  2289. return;
  2290. }
  2291. entity.DispatchSort = 2;
  2292. }
  2293. else
  2294. {
  2295. if (entity.DispatchSort == 2)
  2296. {
  2297. ApiVo apiVo = new ApiVo();
  2298. apiVo.actionName = "closeDesign";
  2299. apiVo.orderNumber = entity.ctid;
  2300. designHelper.API_WorkCore(apiVo);//closeDesign
  2301. }
  2302. entity.DispatchSort = 0;
  2303. }
  2304. entity.DesignUserId = userid;
  2305. entity.WaitDesignTime = DateTime.Now;
  2306. entity.UpdateTime = DateTime.Now;
  2307. entity.Update();
  2308. string name = commonHelper.getUserNameById(userid);
  2309. commonHelper.UpdateRelationOrder(entity.ctid);
  2310. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2311. }
  2312. }
  2313. returnSuccessMsg("操作成功!");
  2314. return;
  2315. }
  2316. }
  2317. public string getTidByCtid(string ctid)
  2318. {
  2319. string tid = "";
  2320. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2321. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2322. if (dataTable != null && dataTable.Rows.Count > 0)
  2323. {
  2324. tid = dataTable.Rows[0]["tid"].ToString();
  2325. }
  2326. return tid;
  2327. }
  2328. public List<string> getTidByCtidMore(string ctid)
  2329. {
  2330. 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);
  2331. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2332. List<string> list = new List<string>();
  2333. if (dataTable != null && dataTable.Rows.Count > 0)
  2334. {
  2335. foreach (DataRow item in dataTable.Rows)
  2336. {
  2337. list.Add("'" + item["tid"].ToString() + "'");
  2338. }
  2339. }
  2340. return list;
  2341. }
  2342. public List<string> getTidByCtidLike(string ctid)
  2343. {
  2344. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2345. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2346. List<string> list = new List<string>();
  2347. if (dataTable != null && dataTable.Rows.Count > 0)
  2348. {
  2349. foreach (DataRow item in dataTable.Rows)
  2350. {
  2351. list.Add("'" + item["tid"].ToString() + "'");
  2352. }
  2353. }
  2354. return list;
  2355. }
  2356. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2357. {
  2358. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2359. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2360. List<string> list = new List<string>();
  2361. if (dataTable != null && dataTable.Rows.Count > 0)
  2362. {
  2363. foreach (DataRow item in dataTable.Rows)
  2364. {
  2365. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2366. {
  2367. continue;
  2368. }
  2369. list.Add("'" + item["receiverId"].ToString() + "'");
  2370. }
  2371. }
  2372. return list;
  2373. }
  2374. public void get_erp_myorderlist()
  2375. {
  2376. DataStruct dStruct = GetPostStruct();
  2377. List<string> lw = new List<string>();
  2378. string tid = GetPostString("ctid");
  2379. if (tid.Length > 0)
  2380. {
  2381. string select_tid = getTidByCtid(tid);
  2382. lw.Add(string.Format("tid='{0}'", select_tid));
  2383. }
  2384. else
  2385. {
  2386. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2387. }
  2388. //12-1 修改
  2389. string urgent = GetPostString("urgent");
  2390. string back = GetPostString("back");
  2391. string offlineSearch = GetPostString("offlineSearch");
  2392. if (!string.IsNullOrWhiteSpace(urgent))
  2393. {
  2394. if (urgent.Equals("true"))
  2395. {
  2396. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2397. }
  2398. }
  2399. if (!string.IsNullOrWhiteSpace(back))
  2400. {
  2401. if (back.Equals("true"))
  2402. {
  2403. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2404. }
  2405. }
  2406. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2407. {
  2408. if (offlineSearch.Equals("true"))
  2409. {
  2410. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2411. }
  2412. }
  2413. //end
  2414. string shopname = GetPostString("shopname");
  2415. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2416. string buyernick = GetPostString("buyer_nick");
  2417. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2418. string design = GetPostString("design");
  2419. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2420. string orderState = GetPostString("orderState");
  2421. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2422. string sellermemo = GetPostString("seller_memo");
  2423. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2424. string date1 = GetPostString("date1");
  2425. string date2 = GetPostString("date2");
  2426. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2427. if (dw.Length > 0) lw.Add(dw);
  2428. string price1 = GetPostString("price1");
  2429. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2430. string price2 = GetPostString("price2");
  2431. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2432. string urgency = GetPostString("urgency");
  2433. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2434. string after = GetPostString("after");
  2435. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2436. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2437. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2438. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2439. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2440. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2441. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2442. if (dt != null && dt.Rows.Count > 0)
  2443. {
  2444. foreach (DataRow dr in dt.Rows)
  2445. {
  2446. try
  2447. {
  2448. // 对象操作
  2449. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2450. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2451. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2452. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2453. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2454. if (dStruct.PageSize != 100000)
  2455. {
  2456. if (dr["DispatchSort"].ToString() == "2")
  2457. {
  2458. dr["gongchuang"] = 200;
  2459. }
  2460. else if ("外协".Equals(dr["ToType"].ToString()))
  2461. {
  2462. dr["gongchuang"] = 200;
  2463. }
  2464. else if ("内部".Equals(dr["ToType"].ToString()))
  2465. {
  2466. dr["gongchuang"] = -1;
  2467. }
  2468. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2469. {
  2470. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2471. dr["gongchuang"] = response.code;
  2472. }
  2473. }
  2474. }
  2475. catch (NullReferenceException ex)
  2476. {
  2477. }
  2478. }
  2479. }
  2480. writeGridDataTableJson(dStruct.TotalCount, dt);
  2481. }
  2482. public void get_erp_myreturnorderlist()
  2483. {
  2484. DataStruct dStruct = GetPostStruct();
  2485. List<string> lw = new List<string>();
  2486. string tid = GetPostString("ctid");
  2487. if (tid.Length > 0)
  2488. {
  2489. string select_tid = getTidByCtid(tid);
  2490. lw.Add(string.Format("tid='{0}'", select_tid));
  2491. }
  2492. else
  2493. {
  2494. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2495. }
  2496. string shopname = GetPostString("shopname");
  2497. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2498. string buyernick = GetPostString("buyer_nick");
  2499. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2500. string design = GetPostString("design");
  2501. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2502. string orderState = GetPostString("orderState");
  2503. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2504. string sellermemo = GetPostString("seller_memo");
  2505. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2506. string date1 = GetPostString("date1");
  2507. string date2 = GetPostString("date2");
  2508. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2509. if (dw.Length > 0) lw.Add(dw);
  2510. string price1 = GetPostString("price1");
  2511. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2512. string price2 = GetPostString("price2");
  2513. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2514. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2515. {
  2516. lw.Add(string.Format("CusOrgID = 94"));
  2517. }
  2518. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2519. {
  2520. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2521. }
  2522. else
  2523. {
  2524. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2525. }
  2526. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2527. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2528. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2529. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2530. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2531. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2532. if (dt != null && dt.Rows.Count > 0)
  2533. {
  2534. foreach (DataRow dr in dt.Rows)
  2535. {
  2536. try
  2537. {
  2538. // 对象操作
  2539. if (dStruct.PageSize != 100000)
  2540. {
  2541. if (dr["DispatchSort"].ToString() == "2")
  2542. {
  2543. dr["gongchuang"] = 200;
  2544. }
  2545. else if ("外协".Equals(dr["ToType"].ToString()))
  2546. {
  2547. dr["gongchuang"] = 200;
  2548. }
  2549. else if ("内部".Equals(dr["ToType"].ToString()))
  2550. {
  2551. dr["gongchuang"] = -1;
  2552. }
  2553. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2554. {
  2555. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2556. dr["gongchuang"] = response.code;
  2557. }
  2558. }
  2559. }
  2560. catch (NullReferenceException ex)
  2561. {
  2562. // 处理空引用异常
  2563. }
  2564. }
  2565. }
  2566. writeGridDataTableJson(dStruct.TotalCount, dt);
  2567. }
  2568. public void get_erp_myorderlist_pregather()
  2569. {
  2570. string date1 = GetPostString("date1");
  2571. string date2 = GetPostString("date2");
  2572. int userId = CurrentUser.UserID; //客服id
  2573. string orderWhere = "";
  2574. List<string> lw = new List<string>();
  2575. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2576. if (dw.Length > 0) lw.Add(dw);
  2577. lw.Add(string.Format("CustomerUserId={0}", userId));
  2578. lw.Add(string.Format("OrderState<9"));
  2579. orderWhere = string.Join(" and ", lw.ToArray());
  2580. string orderWhere2 = "";
  2581. List<string> lw2 = new List<string>();
  2582. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2583. if (dw2.Length > 0) lw2.Add(dw2);
  2584. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2585. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2586. string sql = string.Format("select *" +
  2587. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2588. "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 " +
  2589. "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 " +
  2590. "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");
  2591. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2592. //writeGridDataTableJson(dt.Rows.Count, dt);
  2593. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2594. }
  2595. public void upd_erp_publishorder()
  2596. {
  2597. if (UrlPostParmsCheck("ctid"))
  2598. {
  2599. string eid = GetPostString("ctid");
  2600. CeErpTradeCell entity = null;
  2601. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2602. if (entity != null)
  2603. {
  2604. entity.OrderState = 0; //发布后,变为待抢单
  2605. entity.Update();
  2606. commonHelper.UpdateRelationOrder(entity.ctid);
  2607. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2608. returnSuccessMsg("发布成功!");
  2609. return;
  2610. }
  2611. returnErrorMsg("找不到记录");
  2612. }
  2613. }
  2614. public void get_erp_my_tiporder()
  2615. {
  2616. StringBuilder sql = new StringBuilder();
  2617. int userId = 0;
  2618. if (CurrentUser != null) userId = CurrentUser.UserID;
  2619. string posCode = CurrentUser.UserPost.Post.Code;
  2620. string isTipedAfterSaleVerify = GetPostString("af");
  2621. DataTable dt = new DataTable();
  2622. if (posCode != "Supplier")
  2623. {
  2624. if (posCode == "CustomerService" || posCode == "Director")
  2625. {
  2626. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2627. }
  2628. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2629. {
  2630. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2631. }
  2632. else
  2633. {
  2634. string teamIds = CurrentUser.User.TeamIds;
  2635. if (teamIds == "")
  2636. {
  2637. teamIds = "0";
  2638. }
  2639. 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);
  2640. }
  2641. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2642. }
  2643. if (dt.Rows.Count <= 0)
  2644. {
  2645. string key = "aftersale_order_" + userId;
  2646. if (RedisHelper.HasKey(key))
  2647. {
  2648. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2649. dt.Columns.Add("ctid", typeof(string));
  2650. dt.Columns.Add("IsReadTag", typeof(int));
  2651. foreach (var i in list)
  2652. {
  2653. DataRow data = dt.NewRow();
  2654. data["ctid"] = i;
  2655. data["IsReadTag"] = 4;
  2656. dt.Rows.Add(data);
  2657. }
  2658. RedisHelper.StringDelete(key);
  2659. }
  2660. }
  2661. if (dt.Rows.Count <= 0)
  2662. {
  2663. sql = new StringBuilder();
  2664. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2665. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2666. }
  2667. if (posCode == "Supplier")
  2668. {
  2669. string ids = CurrentUser.User.pemVend;
  2670. if (ids != null && ids.Length > 0)
  2671. {
  2672. string[] ids_list = ids.Split(',');
  2673. foreach (var item in ids_list)
  2674. {
  2675. string key = "return_order_" + item;
  2676. if (RedisHelper.HasKey(key))
  2677. {
  2678. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2679. dt.Columns.Add("ctid", typeof(string));
  2680. dt.Columns.Add("IsReadTag", typeof(int));
  2681. foreach (var i in list)
  2682. {
  2683. DataRow data = dt.NewRow();
  2684. data["ctid"] = i;
  2685. data["IsReadTag"] = 1;
  2686. dt.Rows.Add(data);
  2687. }
  2688. RedisHelper.StringDelete(key);
  2689. }
  2690. }
  2691. }
  2692. if (dt.Rows.Count <= 0)
  2693. {
  2694. sql = new StringBuilder();
  2695. 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);
  2696. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2697. }
  2698. }
  2699. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2700. }
  2701. public void reset_erp_tiporder()
  2702. {
  2703. string ids = GetPostString("ids");
  2704. string[] ctidList = ids.Split(',');
  2705. foreach (string ctid in ctidList)
  2706. {
  2707. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2708. if (enty != null)
  2709. {
  2710. enty.IsReadTag = 0;
  2711. enty.Update();
  2712. }
  2713. }
  2714. returnSuccessMsg("成功!");
  2715. return;
  2716. }
  2717. public void get_erp_designlist()
  2718. {
  2719. DataStruct dStruct = GetPostStruct();
  2720. List<string> lw = new List<string>();
  2721. string tid = GetPostString("ctid");
  2722. if (tid.Length > 0)
  2723. {
  2724. string select_tid = getTidByCtid(tid);
  2725. lw.Add(string.Format("tid='{0}'", select_tid));
  2726. }
  2727. string shopname = GetPostString("shopname");
  2728. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2729. string buyernick = GetPostString("buyer_nick");
  2730. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2731. string customer = GetPostString("customer");
  2732. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2733. string design = GetPostString("design");
  2734. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2735. string orderState = GetPostString("orderState");
  2736. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2737. lw.Add(string.Format("OrderState<6"));
  2738. string address = GetPostString("address");
  2739. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2740. string sellermemo = GetPostString("seller_memo");
  2741. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2742. string date1 = GetPostString("date1");
  2743. string date2 = GetPostString("date2");
  2744. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2745. if (dw.Length > 0) lw.Add(dw);
  2746. string apdate1 = GetPostString("apdate1");
  2747. string apdate2 = GetPostString("apdate2");
  2748. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2749. if (dwap.Length > 0) lw.Add(dwap);
  2750. string price1 = GetPostString("price1");
  2751. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2752. string price2 = GetPostString("price2");
  2753. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2754. string designTime = GetPostString("designtime");
  2755. if (designTime.Length > 0)
  2756. {
  2757. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2758. }
  2759. string usershop = CurrentUser.User.pemShop;
  2760. if (usershop.Length > 0)
  2761. {
  2762. lw.Add(string.Format("shopId in ({0})", usershop));
  2763. }
  2764. int myOrgid = CurrentUser.UserPost.OrgID;
  2765. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2766. if (myOrgCode.IndexOf("Designer") != -1)
  2767. {
  2768. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2769. {
  2770. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2771. }
  2772. else
  2773. {
  2774. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2775. }
  2776. }
  2777. else
  2778. {
  2779. string orgId = GetPostString("designerhd");
  2780. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2781. }
  2782. if (tid.Length > 0 || buyernick.Length > 0)
  2783. {
  2784. lw.Add(string.Format("OrderState >= 3"));
  2785. }
  2786. else
  2787. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2788. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2789. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2790. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2791. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2792. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2793. if (dt != null && dt.Rows.Count > 0)
  2794. {
  2795. foreach (DataRow dr in dt.Rows)
  2796. {
  2797. try
  2798. {
  2799. // 对象操作
  2800. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2801. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2802. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2803. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2804. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2805. if (dStruct.PageSize != 100000)
  2806. {
  2807. if (dr["DispatchSort"].ToString() == "2")
  2808. {
  2809. dr["gongchuang"] = 200;
  2810. }
  2811. else if ("外协".Equals(dr["ToType"].ToString()))
  2812. {
  2813. dr["gongchuang"] = 200;
  2814. }
  2815. else if ("内部".Equals(dr["ToType"].ToString()))
  2816. {
  2817. dr["gongchuang"] = -1;
  2818. }
  2819. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2820. {
  2821. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2822. dr["gongchuang"] = response.code;
  2823. }
  2824. }
  2825. }
  2826. catch (NullReferenceException ex)
  2827. {
  2828. }
  2829. }
  2830. }
  2831. writeGridDataTableJson(dStruct.TotalCount, dt);
  2832. }
  2833. public void get_erp_mydesignlist()
  2834. {
  2835. DataStruct dStruct = GetPostStruct();
  2836. List<string> lw = new List<string>();
  2837. string tid = GetPostString("ctid");
  2838. if (tid.Length > 0)
  2839. {
  2840. string select_tid = getTidByCtid(tid);
  2841. lw.Add(string.Format("tid='{0}'", select_tid));
  2842. }
  2843. string shopname = GetPostString("shopname");
  2844. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2845. string buyernick = GetPostString("buyer_nick");
  2846. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2847. string customer = GetPostString("customer");
  2848. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2849. string orderState = GetPostString("orderState");
  2850. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2851. //lw.Add(string.Format("OrderState<6"));
  2852. string date1 = GetPostString("date1");
  2853. string date2 = GetPostString("date2");
  2854. string dw = GetDateWhere("pay_time", date1, date2);
  2855. if (dw.Length > 0) lw.Add(dw);
  2856. string apdate1 = GetPostString("apdate1");
  2857. string apdate2 = GetPostString("apdate2");
  2858. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2859. if (dwap.Length > 0) lw.Add(dwap);
  2860. string price1 = GetPostString("price1");
  2861. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2862. string price2 = GetPostString("price2");
  2863. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2864. string olddownload = GetPostString("olddown");
  2865. if (olddownload == "1")
  2866. {
  2867. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2868. }
  2869. else if (olddownload == "2")
  2870. {
  2871. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2872. }
  2873. string sellermemo = GetPostString("seller_memo");
  2874. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2875. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2876. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2877. {
  2878. if (CurrentUser.User.TeamIds.Length > 0)
  2879. {
  2880. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2881. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2882. else
  2883. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2884. }
  2885. else
  2886. {
  2887. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2888. }
  2889. }
  2890. if (tid.Length <= 0)
  2891. {
  2892. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2893. }
  2894. lw.Add(string.Format("IsReturn!=3"));
  2895. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2896. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2897. string teamids = CurrentUser.User.TeamIds.ToString();
  2898. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2899. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2900. if (dt != null && dt.Rows.Count > 0)
  2901. {
  2902. foreach (DataRow dr in dt.Rows)
  2903. {
  2904. try
  2905. {
  2906. // 对象操作
  2907. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2908. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2909. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2910. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2911. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2912. if (dStruct.PageSize != 100000)
  2913. {
  2914. if (dr["DispatchSort"].ToString() == "2")
  2915. {
  2916. dr["gongchuang"] = 200;
  2917. }
  2918. else if ("外协".Equals(dr["ToType"].ToString()))
  2919. {
  2920. dr["gongchuang"] = 200;
  2921. }
  2922. else if ("内部".Equals(dr["ToType"].ToString()))
  2923. {
  2924. dr["gongchuang"] = -1;
  2925. }
  2926. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2927. {
  2928. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2929. dr["gongchuang"] = response.code;
  2930. }
  2931. }
  2932. }
  2933. catch (NullReferenceException ex)
  2934. {
  2935. }
  2936. }
  2937. }
  2938. writeGridDataTableJson(dStruct.TotalCount, dt);
  2939. }
  2940. public void set_erp_startdesign()
  2941. {
  2942. if (UrlPostParmsCheck("ctid"))
  2943. {
  2944. string eid = GetPostString("ctid");
  2945. CeErpTradeCell entity = null;
  2946. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2947. if (entity != null)
  2948. {
  2949. if (entity.OrderState != 3)
  2950. {
  2951. returnErrorMsg("请刷新,订单已经设计了");
  2952. return;
  2953. }
  2954. entity.StartDesignTime = DateTime.Now;
  2955. entity.OrderState = 4;
  2956. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2957. {
  2958. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2959. entity.SupplierId = suid;
  2960. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2961. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2962. }
  2963. entity.UpdateTime = DateTime.Now;
  2964. //entity.MakeSupplier = suname;
  2965. entity.Update();
  2966. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2967. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2968. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2969. commonHelper.getCytPrice(entity);
  2970. returnSuccessMsg("操作成功!");
  2971. return;
  2972. }
  2973. returnErrorMsg("找不到记录");
  2974. }
  2975. }
  2976. public void ins_erp_designselfmemo()
  2977. {
  2978. if (UrlPostParmsCheck("ctid"))
  2979. {
  2980. string eid = GetPostString("ctid");
  2981. string con = GetPostString("con");
  2982. CeErpTradeCell entity = null;
  2983. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2984. if (entity != null)
  2985. {
  2986. entity.DesignSelfMemo = con;
  2987. entity.Update();
  2988. returnSuccessMsg("操作成功!");
  2989. return;
  2990. }
  2991. returnErrorMsg("找不到记录");
  2992. }
  2993. }
  2994. public void ins_erp_designprice()
  2995. {
  2996. if (UrlPostParmsCheck("ctid"))
  2997. {
  2998. string eid = GetPostString("ctid");
  2999. int uid = CurrentUser.UserID;
  3000. string userName = CurrentUser.UserName;
  3001. CeErpTradeCell entity = null;
  3002. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3003. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3004. if (entitys == null)
  3005. {
  3006. entitys = new CeErpDesignerBill();
  3007. }
  3008. if (entity != null)
  3009. {
  3010. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3011. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3012. entity.StartDesignTime = DateTime.Now;
  3013. entity.OrderState = 4;
  3014. string suname = "";
  3015. if (entity.SupplierId == 0)
  3016. {
  3017. int sid = commonHelper.autoDistributeToSupplier(entity);
  3018. entity.SupplierId = sid;
  3019. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3020. }
  3021. entity.Update();
  3022. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3023. if (ceErpUserPost != null)
  3024. {
  3025. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3026. if (ceErpPost != null)
  3027. {
  3028. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3029. {
  3030. entitys.tid = entity.ctid;
  3031. entitys.oid = entity.tid;
  3032. entitys.uid = uid;
  3033. entitys.userName = userName;
  3034. entitys.designerType = 1;
  3035. entitys.designerTypeText = "内部设计师";
  3036. entitys.price = Convert.ToDouble(GetPostString("price"));
  3037. entitys.designNum = GetPostInt("designNum");
  3038. entitys.modifyNum = GetPostInt("modifyNum");
  3039. entitys.designSize = GetPostString("designSize");
  3040. entitys.modifySize = GetPostString("modifySize");
  3041. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3042. {
  3043. entitys.create_time = DateTime.Now;
  3044. entitys.create_u_id = uid;
  3045. entitys.create_u_name = userName;
  3046. entitys.Save();
  3047. }
  3048. else
  3049. {
  3050. entitys.update_time = DateTime.Now;
  3051. entitys.update_u_id = uid;
  3052. entitys.update_u_name = userName;
  3053. entitys.Update();
  3054. }
  3055. }
  3056. }
  3057. }
  3058. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3059. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3060. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3061. if (suname != "")
  3062. {
  3063. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3064. }
  3065. commonHelper.getCytPrice(entity);
  3066. returnSuccessMsg("操作成功!");
  3067. return;
  3068. }
  3069. returnErrorMsg("找不到记录");
  3070. }
  3071. }
  3072. public void upload_erp_filecomplete()
  3073. {
  3074. if (UrlPostParmsCheck("ctid"))
  3075. {
  3076. string eid = GetPostString("ctid");
  3077. CeErpTradeCell entity = null;
  3078. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3079. if (entity != null)
  3080. {
  3081. entity.OrderState = 5; //设计完成
  3082. entity.Update();
  3083. returnSuccessMsg(eid + "上传成功,设计完成!");
  3084. return;
  3085. }
  3086. returnErrorMsg("找不到订单记录");
  3087. }
  3088. }
  3089. public void get_erp_designovertimelist()
  3090. {
  3091. DataStruct dStruct = GetPostStruct();
  3092. List<string> lw = new List<string>();
  3093. string tid = GetPostString("ctid");
  3094. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3095. string shopname = GetPostString("shopname");
  3096. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3097. string buyernick = GetPostString("buyer_nick");
  3098. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3099. string ResponsibleMan = GetPostString("responsible");
  3100. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3101. string date1 = GetPostString("date1");
  3102. string date2 = GetPostString("date2");
  3103. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3104. if (dw.Length > 0) lw.Add(dw);
  3105. string price1 = GetPostString("price1");
  3106. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3107. string price2 = GetPostString("price2");
  3108. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3109. string orderState = GetPostString("orderState");
  3110. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3111. string sellermemo = GetPostString("seller_memo");
  3112. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3113. lw.Add(string.Format("UnusualTag=3"));
  3114. lw.Add(string.Format("IsRefund<={0}", 1));
  3115. dStruct.Order = "WaitDesignTime desc";
  3116. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3117. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3118. writeGridDataTableJson(dStruct.TotalCount, dt);
  3119. }
  3120. //设计管理 获取抢单大厅列表
  3121. public void get_erp_grabinglist()
  3122. {
  3123. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3124. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3125. bool oldOrder = false;
  3126. if (org != null)
  3127. {
  3128. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3129. }
  3130. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3131. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3132. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3133. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3134. //先处理订单数据
  3135. if (dt.Rows.Count > 0)
  3136. {
  3137. Dictionary<string, int> design = null;
  3138. int count = 0;
  3139. foreach (DataRow row in dt.Rows)
  3140. {
  3141. if (map.ContainsKey(row["ShopId"].ToString()))
  3142. {
  3143. map.TryGetValue(row["ShopId"].ToString(), out design);
  3144. }
  3145. else
  3146. {
  3147. design = new Dictionary<string, int>();
  3148. }
  3149. if (design.ContainsKey(row["ProductId"].ToString()))
  3150. {
  3151. design.TryGetValue(row["ProductId"].ToString(), out count);
  3152. }
  3153. count++;
  3154. design[row["ProductId"].ToString()] = count;
  3155. map[row["ShopId"].ToString()] = design;
  3156. }
  3157. }
  3158. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3159. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3160. //把店铺排序和技能排序分类
  3161. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3162. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3163. if (design_dt.Rows.Count > 0)
  3164. {
  3165. Dictionary<string, string> design = null;
  3166. List<string> shopIds = null;
  3167. foreach (DataRow row in design_dt.Rows)
  3168. {
  3169. if ("0".Equals(row["designId"].ToString()))
  3170. {
  3171. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3172. {
  3173. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3174. }
  3175. else
  3176. {
  3177. shopIds = new List<string>();
  3178. }
  3179. shopIds.Add(row["shopId"].ToString());
  3180. shop_orders[row["orders"].ToString()] = shopIds;
  3181. }
  3182. else
  3183. {
  3184. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3185. {
  3186. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3187. }
  3188. else
  3189. {
  3190. design = new Dictionary<string, string>();
  3191. }
  3192. design[row["orders"].ToString()] = row["designId"].ToString();
  3193. design_orders[row["shopId"].ToString()] = design;
  3194. }
  3195. }
  3196. //处理成key value后根据key排序
  3197. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3198. foreach (List<string> val in shop_orders.Values)
  3199. {
  3200. if (val != null)
  3201. {
  3202. foreach (string key in val)
  3203. {
  3204. if (design_orders.ContainsKey(key.ToString()))
  3205. {
  3206. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3207. }
  3208. }
  3209. }
  3210. }
  3211. }
  3212. //校验哪个优先级有订单
  3213. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3214. foreach (string key in shop_orders.Keys)
  3215. {
  3216. List<string> ids = null;
  3217. shop_orders.TryGetValue(key, out ids);
  3218. //id为shopid
  3219. foreach (string id in ids)
  3220. {
  3221. Dictionary<string, int> list = null;
  3222. Dictionary<string, string> desing = null;
  3223. map.TryGetValue(id, out list);
  3224. design_orders.TryGetValue(id, out desing);
  3225. if (list != null && desing != null)
  3226. {
  3227. foreach (var item in desing)
  3228. {
  3229. int count = 0;
  3230. if (list.ContainsKey(item.Value))
  3231. {
  3232. list.TryGetValue(item.Value, out count);
  3233. if (count > 0)
  3234. {
  3235. designIds[id] = item.Value;
  3236. break;
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. if (designIds.Count > 0)
  3243. {
  3244. break;
  3245. }
  3246. }
  3247. DataTable table = new DataTable();
  3248. table.Columns.Add("tid", typeof(string));
  3249. table.Columns.Add("ctid", typeof(string));
  3250. table.Columns.Add("seller_nick", typeof(string));
  3251. table.Columns.Add("productName", typeof(string));
  3252. table.Columns.Add("pay_time", typeof(string));
  3253. table.Columns.Add("seller_memo", typeof(string));
  3254. if (designIds.Count > 0)
  3255. {
  3256. string shopId = "";
  3257. string productId = "";
  3258. foreach (var designInfo in designIds)
  3259. {
  3260. shopId = designInfo.Key;
  3261. productId = designInfo.Value;
  3262. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3263. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3264. if (dt.Rows.Count > 0)
  3265. {
  3266. foreach (DataRow row in dt.Rows)
  3267. {
  3268. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3269. {
  3270. DataRow data = table.NewRow();
  3271. data["ctid"] = row["ctid"].ToString();
  3272. data["tid"] = row["tid"].ToString();
  3273. data["seller_nick"] = ceErpShop.ShopName;
  3274. data["pay_time"] = row["pay_time"].ToString();
  3275. data["seller_memo"] = row["seller_memo"].ToString();
  3276. data["productName"] = ceErpProduct.PType;
  3277. table.Rows.Add(data);
  3278. }
  3279. }
  3280. }
  3281. }
  3282. }
  3283. writeGridDataTableJson(table.Rows.Count, table);
  3284. }
  3285. private object rushLockObject = new object();
  3286. public void set_erp_grabingorder()
  3287. {
  3288. if (UrlPostParmsCheck("ctid"))
  3289. {
  3290. int total = CurrentUser.User.Person.Total;
  3291. int userId = CurrentUser.User.ID;
  3292. int noFinish = CurrentUser.User.Person.NoFinish;
  3293. int finalization = CurrentUser.User.Person.Finalization;
  3294. string eids = GetPostString("ctid");
  3295. string key = "RushKey_" + userId;
  3296. int count = 0;
  3297. if (erpRedis.RedisHelper.KeyExists(key))
  3298. {
  3299. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3300. if (redisCount != null)
  3301. {
  3302. count = Convert.ToInt32(redisCount);
  3303. }
  3304. }
  3305. if (count >= total)
  3306. {
  3307. returnErrorMsg("半小时内已经抢" + total + "单");
  3308. return;
  3309. }
  3310. string[] ctidlist = eids.Split(',');
  3311. if (count + ctidlist.Length > total)
  3312. {
  3313. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3314. return;
  3315. }
  3316. int itag = 0;
  3317. lock (rushLockObject)
  3318. {
  3319. if (ctidlist.Length > 0)
  3320. {
  3321. string[] dtList = new string[ctidlist.Length];
  3322. for (int i = 0; i < ctidlist.Length; i++)
  3323. {
  3324. dtList[i] = "'" + ctidlist[i] + "'";
  3325. }
  3326. 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"));
  3327. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3328. if (dt_user.Rows.Count > 0)
  3329. {
  3330. int doing = 0;//未定稿
  3331. int finish = 0;//已完成
  3332. foreach (DataRow dr in dt_user.Rows)
  3333. {
  3334. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3335. {
  3336. doing++;
  3337. }
  3338. else
  3339. {
  3340. finish++;
  3341. }
  3342. }
  3343. if (doing >= noFinish)
  3344. {
  3345. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3346. return;
  3347. }
  3348. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3349. {
  3350. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3351. return;
  3352. }
  3353. }
  3354. //校验选择单子状态
  3355. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3356. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3357. if (dt.Rows.Count > 0)
  3358. {
  3359. List<string> list = new List<string>();
  3360. foreach (DataRow dr in dt.Rows)
  3361. {
  3362. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3363. {
  3364. list.Add(dr["ctid"].ToString());
  3365. }
  3366. }
  3367. if (list.Count > 0)
  3368. {
  3369. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3370. return;
  3371. }
  3372. }
  3373. foreach (string ctid in ctidlist)
  3374. {
  3375. CeErpTradeCell entity = null;
  3376. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3377. if (entity != null)
  3378. {
  3379. entity.OrderState = 3;
  3380. entity.DesignUserId = CurrentUser.UserID;
  3381. entity.WaitDesignTime = DateTime.Now;
  3382. entity.StartDesignTime = DateTime.Now;
  3383. entity.Update();
  3384. commonHelper.UpdateRelationOrder(entity.ctid);
  3385. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3386. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3387. itag++;
  3388. }
  3389. }
  3390. }
  3391. }
  3392. count += ctidlist.Length;
  3393. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3394. if (itag == 0)
  3395. returnErrorMsg("没有找到相关订单");
  3396. else
  3397. returnSuccessMsg("抢单成功!");
  3398. return;
  3399. }
  3400. }
  3401. public void get_erp_waitorderlist()
  3402. {
  3403. DataStruct dStruct = GetPostStruct();
  3404. List<string> lw = new List<string>();
  3405. string tid = GetPostString("ctid");
  3406. if (tid.Length > 0)
  3407. {
  3408. string select_tid = getTidByCtid(tid);
  3409. lw.Add(string.Format("tid='{0}'", select_tid));
  3410. }
  3411. string shopname = GetPostString("shopname");
  3412. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3413. string buyernick = GetPostString("buyer_nick");
  3414. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3415. string customer = GetPostString("customer");
  3416. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3417. string design = GetPostString("design");
  3418. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3419. string orderState = GetPostString("orderState");
  3420. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3421. string supplier = GetPostString("supplier");
  3422. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3423. string sellermemo = GetPostString("seller_memo");
  3424. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3425. string otherMemo = GetPostString("otherMemo");
  3426. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3427. string address = GetPostString("address");
  3428. 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));
  3429. string date1 = GetPostString("date1");
  3430. string date2 = GetPostString("date2");
  3431. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3432. if (dw.Length > 0) lw.Add(dw);
  3433. string price1 = GetPostString("price1");
  3434. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3435. string price2 = GetPostString("price2");
  3436. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3437. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3438. lw.Add(string.Format("IsSample != 2 "));
  3439. lw.Add(string.Format("OrderState = 5 "));
  3440. lw.Add(string.Format("IsRefund<={0}", 1));
  3441. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3442. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3443. string pagesize = GetPostString("pagesize");
  3444. if (pagesize != null)
  3445. {
  3446. dStruct.PageSize = 200;
  3447. }
  3448. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3449. List<string> tids = new List<string>();
  3450. if (dt != null)
  3451. {
  3452. dt.Columns.Add("compenPrice", typeof(double));
  3453. foreach (DataRow dr in dt.Rows)
  3454. {
  3455. if (Convert.IsDBNull(dr["compenPrice"]))
  3456. {
  3457. dr["compenPrice"] = 0;
  3458. }
  3459. tids.Add("'" + dr["tid"].ToString() + "'");
  3460. 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();
  3461. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3462. {
  3463. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3464. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3465. entity.SupplierId = suid;
  3466. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3467. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3468. entity.Update();
  3469. }
  3470. }
  3471. }
  3472. if (tids.Count > 0)
  3473. {
  3474. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3475. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3476. if (dt_price != null && dt_price.Rows.Count > 0)
  3477. {
  3478. foreach (DataRow dr in dt_price.Rows)
  3479. {
  3480. foreach (DataRow row in dt.Rows)
  3481. {
  3482. if (row["tid"].Equals(dr["ptid"]))
  3483. {
  3484. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3485. break;
  3486. }
  3487. }
  3488. }
  3489. }
  3490. }
  3491. writeGridDataTableJson(dStruct.TotalCount, dt);
  3492. }
  3493. public void get_erp_supplierwaitorderlist()
  3494. {
  3495. DataStruct dStruct = GetPostStruct();
  3496. List<string> lw = new List<string>();
  3497. string tid = GetPostString("ctid");
  3498. if (tid.Length > 0)
  3499. {
  3500. string select_tid = getTidByCtid(tid);
  3501. lw.Add(string.Format("tid='{0}'", select_tid));
  3502. }
  3503. string shopname = GetPostString("shopname");
  3504. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3505. string sellermemo = GetPostString("seller_memo");
  3506. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3507. string date1 = GetPostString("date1");
  3508. string date2 = GetPostString("date2");
  3509. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3510. if (dw.Length > 0) lw.Add(dw);
  3511. lw.Add(string.Format("OrderState = 5 "));
  3512. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3513. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3514. {
  3515. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3516. }
  3517. string supplier = GetPostString("supplier");
  3518. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3519. {
  3520. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3521. }
  3522. lw.Add(string.Format("IsRefund<={0}", 1));
  3523. dStruct.Order = "FinishDesignTime desc";
  3524. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3525. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3526. if (dt != null)
  3527. {
  3528. foreach (DataRow dr in dt.Rows)
  3529. {
  3530. 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();
  3531. }
  3532. }
  3533. writeGridDataTableJson(dStruct.TotalCount, dt);
  3534. }
  3535. public void upd_erp_verifytosupplier()
  3536. {
  3537. if (UrlPostParmsCheck("ctid"))
  3538. {
  3539. string eids = GetPostString("ctid");
  3540. CeErpTradeCell entity = null;
  3541. string[] eidsList = eids.Split(',');
  3542. if (eidsList.Length <= 0)
  3543. {
  3544. returnErrorMsg("订单号不能空");
  3545. return;
  3546. }
  3547. List<string> tLst = new List<string>();
  3548. foreach (string ctidstr in eidsList)
  3549. {
  3550. tLst.Add("'" + ctidstr + "'");
  3551. CeErpDataSendOrderInfo.createObject(ctidstr);
  3552. }
  3553. string needtids = string.Join(",", tLst.ToArray());
  3554. StringBuilder sql = new StringBuilder();
  3555. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3556. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3557. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3558. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3559. returnSuccessMsg("操作成功!");
  3560. return;
  3561. /**foreach (string ctidstr in eidsList)
  3562. {
  3563. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3564. if (entity != null)
  3565. {
  3566. if (entity.SupplierId == 0)
  3567. {
  3568. continue;
  3569. }
  3570. entity.IsVerifyToSupplier = true;
  3571. if (entity.IsReturn == 1) //1是供应商打回
  3572. {
  3573. entity.IsReturn = 0;
  3574. }
  3575. entity.FinishPlaceTime = DateTime.Now;
  3576. entity.PlaceUserId = CurrentUser.UserID;
  3577. entity.Update();
  3578. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3579. }
  3580. }
  3581. returnSuccessMsg("操作成功!");
  3582. return;**/
  3583. }
  3584. }
  3585. public void upd_erp_supplierback()
  3586. {
  3587. if (UrlPostParmsCheck("ctid"))
  3588. {
  3589. string eid = GetPostString("ctid");
  3590. string reason = GetPostString("returnreason");
  3591. CeErpTradeCell entity = null;
  3592. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3593. if (entity != null)
  3594. {
  3595. string message = "操作成功!";
  3596. string isDown = "";
  3597. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3598. {
  3599. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3600. isDown = "被点击下载";
  3601. }
  3602. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3603. {
  3604. string key = "return_order_" + entity.SupplierId;
  3605. List<string> list = new List<string>();
  3606. if (RedisHelper.HasKey(key))
  3607. {
  3608. object data = RedisHelper.StringGet(key);
  3609. list = Convert.ToString(data).Split(',').ToList();
  3610. }
  3611. list.Add(eid);
  3612. RedisHelper.StringSet(key, string.Join(",", list));
  3613. }
  3614. entity.IsVerifyToSupplier = false;
  3615. entity.IsReturn = 1;
  3616. entity.IsHaveNewOrder = 0;
  3617. entity.ReturnTime = DateTime.Now;
  3618. entity.ReturnReason = reason;
  3619. if (entity.OrderState == 6)
  3620. {
  3621. entity.OrderState = 5;
  3622. }
  3623. entity.Update();
  3624. CeErpSukuraData.createInfo(entity.ctid, 5);
  3625. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3626. returnSuccessMsg(message);
  3627. return;
  3628. }
  3629. returnErrorMsg("找不到订单记录");
  3630. }
  3631. }
  3632. public void upd_erp_toaftersaleorder()
  3633. {
  3634. if (UrlPostParmsCheck("ctid"))
  3635. {
  3636. string eid = GetPostString("ctid");
  3637. string reason = GetPostString("returnreason");
  3638. CeErpTradeCell entity = null;
  3639. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3640. if (entity != null)
  3641. {
  3642. if (entity.isAfterSaleOrder != 1)
  3643. {
  3644. returnErrorMsg("带S的售后单才能打回给售后");
  3645. return;
  3646. }
  3647. if (entity.OrderState >= 5)
  3648. {
  3649. returnErrorMsg("已经设计完成了不能打回给售后");
  3650. return;
  3651. }
  3652. entity.OrderState = 0;
  3653. entity.IsReturn = 3;
  3654. entity.ReturnTime = DateTime.Now;
  3655. entity.UpdateTime = DateTime.Now;
  3656. entity.ReturnReason = reason;
  3657. entity.Update();
  3658. CeErpSukuraData.createInfo(entity.ctid, 5);
  3659. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3660. returnSuccessMsg("操作成功!");
  3661. return;
  3662. }
  3663. returnErrorMsg("找不到订单记录");
  3664. }
  3665. }
  3666. public void upd_erp_aftersaletodesign()
  3667. {
  3668. if (UrlPostParmsCheck("ctid"))
  3669. {
  3670. string eid = GetPostString("ctid");
  3671. CeErpTradeCell entity = null;
  3672. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3673. if (entity != null)
  3674. {
  3675. entity.OrderState = 3;
  3676. entity.IsReturn = 0;
  3677. entity.UpdateTime = DateTime.Now;
  3678. entity.Update();
  3679. CeErpSukuraData.createInfo(entity.ctid, 5);
  3680. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3681. returnSuccessMsg("操作成功!");
  3682. return;
  3683. }
  3684. returnErrorMsg("找不到订单记录");
  3685. }
  3686. }
  3687. public void assign_erp_supplier()
  3688. {
  3689. if (UrlPostParmsCheck("ctid"))
  3690. {
  3691. string eids = GetPostString("ctid");
  3692. int sid = GetPostInt("SupplierName");
  3693. string fromTag = GetPostString("tag");
  3694. string[] eidList = eids.Split(',');
  3695. if (eidList.Length <= 0)
  3696. {
  3697. returnErrorMsg("指派不能为空");
  3698. return;
  3699. }
  3700. string errMsg = "";
  3701. string suname = commonHelper.getSupplierNameById(sid);
  3702. foreach (string ctid in eidList)
  3703. {
  3704. CeErpTradeCell entity = null;
  3705. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3706. if (entity != null)
  3707. {
  3708. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3709. {
  3710. errMsg += (ctid + "指派失败!!!");
  3711. continue;
  3712. }
  3713. entity.SupplierId = sid;
  3714. entity.Update();
  3715. commonHelper.UpdateRelationOrder(entity.ctid);
  3716. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3717. if (entity.OrderState >= 6)
  3718. {
  3719. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3720. //{
  3721. // string msl = entity.MakeSupplier;
  3722. // string[] mslist = msl.Split(',');
  3723. // 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);
  3724. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3725. //}
  3726. //else
  3727. //{
  3728. StringBuilder sql = new StringBuilder();
  3729. 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);
  3730. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3731. //}
  3732. }
  3733. }
  3734. else
  3735. {
  3736. continue;
  3737. }
  3738. }
  3739. if (errMsg.Length > 0)
  3740. {
  3741. returnErrorMsg(errMsg);
  3742. return;
  3743. }
  3744. returnSuccessMsg("操作成功!");
  3745. return;
  3746. }
  3747. }
  3748. public void assign_erp_makesupplier()
  3749. {
  3750. if (UrlPostParmsCheck("ctid"))
  3751. {
  3752. string eids = GetPostString("ctid");
  3753. string sname = GetPostString("SupplierName");
  3754. string[] eidList = eids.Split(',');
  3755. if (eidList.Length <= 0)
  3756. {
  3757. returnErrorMsg("指派不能为空");
  3758. return;
  3759. }
  3760. List<string> tLst = new List<string>();
  3761. foreach (string ctid in eidList)
  3762. {
  3763. CeErpTradeCell entity = null;
  3764. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3765. if (entity != null)
  3766. {
  3767. entity.MakeSupplier = sname;
  3768. entity.Update();
  3769. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3770. tLst.Add("'" + ctid + "'");
  3771. }
  3772. else
  3773. {
  3774. continue;
  3775. }
  3776. }
  3777. string ctids = string.Join(",", tLst.ToArray());
  3778. StringBuilder sql2 = new StringBuilder();
  3779. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3780. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3781. returnSuccessMsg("操作成功!");
  3782. return;
  3783. }
  3784. }
  3785. public void ins_erp_returnreason()
  3786. {
  3787. if (UrlPostParmsCheck("ctid"))
  3788. {
  3789. string eid = GetPostString("ctid");
  3790. CeErpTradeCell entity = null;
  3791. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3792. string userpost = CurrentUser.UserPost.Post.Code;
  3793. if (entity != null)
  3794. {
  3795. bool isPlace = false;
  3796. if (entity.OrderState > 6)
  3797. {
  3798. returnErrorMsg("已发货无法打回!");
  3799. return;
  3800. }
  3801. if (entity.OrderState == 6)
  3802. {
  3803. isPlace = true;
  3804. }
  3805. bool isNeedUpdateCell2 = false;
  3806. if (entity.OrderState >= 6)
  3807. {
  3808. isNeedUpdateCell2 = true;
  3809. }
  3810. int returnTag = 2;
  3811. if (userpost == "Supplier")
  3812. {
  3813. returnTag = 1;
  3814. }
  3815. int toType = GetPostInt("totype");
  3816. string fromType = "3";
  3817. if (entity.OrderState < 5)
  3818. {
  3819. fromType = "3";
  3820. }
  3821. else
  3822. {
  3823. fromType = "4";
  3824. }
  3825. if (entity.IsXianHuo == 0)
  3826. {
  3827. if (returnTag == 2)
  3828. {
  3829. if (toType == 1)
  3830. {
  3831. entity.OrderState = 0;
  3832. entity.ReturnUserType = 1;
  3833. string clearman = GetPostString("clearman");
  3834. if (!string.IsNullOrEmpty(clearman))
  3835. {
  3836. entity.DesignUserId = 0;
  3837. }
  3838. }
  3839. else
  3840. {
  3841. entity.OrderState = 3;
  3842. entity.ReturnUserType = 2;
  3843. }
  3844. entity.IsReadTag = 1;
  3845. }
  3846. else if (returnTag == 1)
  3847. {
  3848. entity.OrderState = 5;
  3849. }
  3850. entity.IsVerifyToSupplier = false;
  3851. }
  3852. if (entity.IsXianHuo == 1)
  3853. {
  3854. entity.OrderState = 5;
  3855. }
  3856. entity.UnusualTag = 0;
  3857. entity.UnusualTime = null;
  3858. entity.UnusualCon = "";
  3859. entity.IsReturn = returnTag;
  3860. entity.ReturnTime = DateTime.Now;
  3861. entity.UpdateTime = DateTime.Now;
  3862. entity.ReturnReason = GetPostString("returnreason");
  3863. entity.Update();
  3864. if (entity.OrderState == 3)
  3865. {
  3866. ApiVo apiVo = new ApiVo();
  3867. apiVo.orderNumber = entity.ctid;
  3868. apiVo.actionName = "rebutDesign";
  3869. apiVo.orderRemarks = entity.ReturnReason;
  3870. designHelper.API_WorkCore(apiVo);//rebutDesign
  3871. }
  3872. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3873. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3874. {
  3875. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3876. }
  3877. CeErpSukuraData.createInfo(entity.ctid, 5);
  3878. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3879. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3880. if (isPlace)
  3881. {
  3882. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3883. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3884. if (dth != null && dth.Rows.Count > 0)
  3885. {
  3886. dataSendOrderBean dataSendOrderBean = null;
  3887. foreach (DataRow item in dth.Rows)
  3888. {
  3889. try
  3890. {
  3891. dataSendOrderBean = new dataSendOrderBean();
  3892. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3893. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3894. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3895. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3896. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3897. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3898. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3899. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3900. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3901. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3902. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3903. dataSendOrderBean.Radio1723534706288 = "打回";
  3904. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3905. if (result != null)
  3906. {
  3907. if ("0".Equals(result.errcode))
  3908. {
  3909. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3910. }
  3911. else
  3912. {
  3913. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3914. }
  3915. }
  3916. }
  3917. catch (Exception ex)
  3918. {
  3919. }
  3920. }
  3921. }
  3922. }
  3923. if (isNeedUpdateCell2)
  3924. {
  3925. if (entity.MakeSupplier.IndexOf(",") != -1)
  3926. {
  3927. StringBuilder sql2 = new StringBuilder();
  3928. 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);
  3929. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3930. }
  3931. else
  3932. {
  3933. StringBuilder sql2 = new StringBuilder();
  3934. 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);
  3935. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3936. }
  3937. }
  3938. returnSuccessMsg("操作成功!");
  3939. return;
  3940. }
  3941. returnErrorMsg("找不到订单记录");
  3942. }
  3943. }
  3944. public void cyt_erp_returnreason()
  3945. {
  3946. if (UrlPostParmsCheck("ctid"))
  3947. {
  3948. string eid = GetPostString("ctid");
  3949. CeErpTradeCell entity = null;
  3950. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3951. string userpost = CurrentUser.UserPost.Post.Code;
  3952. if (entity != null)
  3953. {
  3954. if (entity.OrderState > 6)
  3955. {
  3956. returnErrorMsg("已发货无法打回!");
  3957. return;
  3958. }
  3959. JObject jsonObject = new JObject
  3960. {
  3961. { "Userid", "77886" },
  3962. { "Pwd", "lt666888" },
  3963. { "LTOrderId",eid }
  3964. };
  3965. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3966. JObject jsonObjects = JObject.Parse(response);
  3967. string msg = (string)jsonObjects["msg"];
  3968. if (msg != "取消成功")
  3969. {
  3970. returnErrorMsg(msg);
  3971. return;
  3972. }
  3973. bool isNeedUpdateCell2 = false;
  3974. if (entity.OrderState >= 6)
  3975. {
  3976. isNeedUpdateCell2 = true;
  3977. }
  3978. int returnTag = 2;
  3979. if (userpost == "Supplier")
  3980. {
  3981. returnTag = 1;
  3982. }
  3983. if (entity.IsXianHuo == 0)
  3984. {
  3985. if (returnTag == 2)
  3986. {
  3987. int toType = GetPostInt("totype");
  3988. if (toType == 1)
  3989. {
  3990. entity.OrderState = 0;
  3991. entity.ReturnUserType = 1;
  3992. }
  3993. else
  3994. {
  3995. entity.OrderState = 4;
  3996. entity.ReturnUserType = 2;
  3997. }
  3998. entity.IsReadTag = 1;
  3999. }
  4000. else if (returnTag == 1)
  4001. {
  4002. entity.OrderState = 5;
  4003. }
  4004. entity.IsVerifyToSupplier = false;
  4005. }
  4006. entity.UnusualTag = 0;
  4007. entity.UnusualTime = null;
  4008. entity.UnusualCon = "";
  4009. entity.IsReturn = returnTag;
  4010. entity.ReturnTime = DateTime.Now;
  4011. entity.ReturnReason = GetPostString("returnreason");
  4012. entity.Update();
  4013. if (entity.OrderState == 4)
  4014. {
  4015. ApiVo apiVo = new ApiVo();
  4016. apiVo.orderNumber = entity.ctid;
  4017. apiVo.actionName = "rebutDesign";
  4018. apiVo.orderRemarks = entity.ReturnReason;
  4019. designHelper.API_WorkCore(apiVo);//rebutDesign
  4020. }
  4021. CeErpSukuraData.createInfo(entity.ctid, 5);
  4022. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4023. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4024. if (isNeedUpdateCell2)
  4025. {
  4026. if (entity.MakeSupplier.IndexOf(",") != -1)
  4027. {
  4028. StringBuilder sql2 = new StringBuilder();
  4029. 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);
  4030. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4031. }
  4032. else
  4033. {
  4034. StringBuilder sql2 = new StringBuilder();
  4035. 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);
  4036. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4037. }
  4038. }
  4039. returnSuccessMsg("操作成功!");
  4040. return;
  4041. }
  4042. returnErrorMsg("找不到订单记录");
  4043. }
  4044. }
  4045. public void upd_erp_xianhuoreturntag()
  4046. {
  4047. if (UrlPostParmsCheck("ctid"))
  4048. {
  4049. string eids = GetPostString("ctid");
  4050. string[] ctids = eids.Split(',');
  4051. foreach (string ctid in ctids)
  4052. {
  4053. CeErpTradeCell entity = null;
  4054. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4055. if (entity != null)
  4056. {
  4057. entity.IsReturn = 0;
  4058. entity.Update();
  4059. CeErpSukuraData.createInfo(entity.ctid, 5);
  4060. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4061. }
  4062. }
  4063. returnSuccessMsg("操作成功!");
  4064. return;
  4065. }
  4066. }
  4067. public void get_erp_waitdeliverylist()
  4068. {
  4069. DataStruct dStruct = GetPostStruct();
  4070. List<string> lw = new List<string>();
  4071. string tid = GetPostString("ctid");
  4072. if (tid.Length > 0)
  4073. {
  4074. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4075. if (tid.Length > 5)
  4076. {
  4077. List<string> tids = getTidByCtidLike(tid);
  4078. if (tids.Count > 0 && tids.Count < 10)
  4079. {
  4080. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4081. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4082. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4083. {
  4084. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4085. }*/
  4086. }
  4087. }
  4088. lw.Add(tid_sql);
  4089. }
  4090. string shopname = GetPostString("shopname");
  4091. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4092. string buyernick = GetPostString("buyer_nick");
  4093. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4094. //if (tid.Length == 0 && buyernick.Length == 0)
  4095. //{
  4096. // lw.Add(string.Format("IsRefund<={0}", 1));
  4097. //}
  4098. string customer = GetPostString("customer");
  4099. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4100. string design = GetPostString("design");
  4101. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4102. string orderState = GetPostString("orderState");
  4103. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4104. string address = GetPostString("address");
  4105. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4106. string sellermemo = GetPostString("seller_memo");
  4107. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4108. string supplier = GetPostString("supplier");
  4109. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4110. string OrderArea = GetPostString("order_area");
  4111. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4112. string placedate1 = GetPostString("placedate1");
  4113. string placedate2 = GetPostString("placedate2");
  4114. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4115. if (fdw.Length > 0) lw.Add(fdw);
  4116. string price1 = GetPostString("price1");
  4117. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4118. string price2 = GetPostString("price2");
  4119. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4120. string unusualCon = GetPostString("unusualcon");
  4121. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4122. string otherMemo = GetPostString("otherMemo");
  4123. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4124. string posTag = CurrentUser.UserPost.Post.Code;
  4125. if (posTag == "Supplier")
  4126. {
  4127. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4128. }
  4129. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4130. lw.Add(string.Format("type != 'PDD' "));
  4131. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4132. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4133. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4134. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4135. writeGridDataTableJson(dStruct.TotalCount, dt);
  4136. }
  4137. public void get_erp_changedeliverylist()
  4138. {
  4139. DataStruct dStruct = GetPostStruct();
  4140. List<string> lw = new List<string>();
  4141. string tid = GetPostString("ctid");
  4142. if (tid.Length > 0)
  4143. {
  4144. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4145. if (tid.Length > 5)
  4146. {
  4147. List<string> tids = getTidByCtidLike(tid);
  4148. if (tids.Count > 0 && tids.Count < 10)
  4149. {
  4150. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4151. }
  4152. }
  4153. lw.Add(tid_sql);
  4154. }
  4155. string shopname = GetPostString("shopname");
  4156. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4157. string buyernick = GetPostString("buyer_nick");
  4158. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4159. //if (tid.Length == 0 && buyernick.Length == 0)
  4160. //{
  4161. // lw.Add(string.Format("IsRefund<={0}", 1));
  4162. //}
  4163. string customer = GetPostString("customer");
  4164. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4165. string design = GetPostString("design");
  4166. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4167. string orderState = GetPostString("orderState");
  4168. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4169. string address = GetPostString("address");
  4170. 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));
  4171. string sellermemo = GetPostString("seller_memo");
  4172. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4173. string supplier = GetPostString("supplier");
  4174. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4175. string OrderArea = GetPostString("order_area");
  4176. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4177. string placedate1 = GetPostString("placedate1");
  4178. string placedate2 = GetPostString("placedate2");
  4179. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4180. if (fdw.Length > 0) lw.Add(fdw);
  4181. string price1 = GetPostString("price1");
  4182. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4183. string price2 = GetPostString("price2");
  4184. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4185. string unusualCon = GetPostString("unusualcon");
  4186. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4187. string otherMemo = GetPostString("otherMemo");
  4188. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4189. string posTag = CurrentUser.UserPost.Post.Code;
  4190. if (posTag == "Supplier")
  4191. {
  4192. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4193. }
  4194. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4195. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4196. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4197. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4198. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4199. /*if (tid.Length > 0)
  4200. {
  4201. List<string> tids = new List<string>();
  4202. if (dt != null && dt.Rows.Count > 0)
  4203. {
  4204. foreach (DataRow item in dt.Rows)
  4205. {
  4206. tids.Add("'" + item["tid"] + "'");
  4207. }
  4208. }
  4209. if (tids.Count > 0)
  4210. {
  4211. lw.RemoveAt(0);
  4212. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4213. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4214. dt = WebCache.GetData("view_erptradecell", dStruct);
  4215. }
  4216. }*/
  4217. writeGridDataTableJson(dStruct.TotalCount, dt);
  4218. }
  4219. public void get_erp_pddderiving()
  4220. {
  4221. DataStruct dStruct = GetPostStruct();
  4222. List<string> lw = new List<string>();
  4223. string tid = GetPostString("ctid");
  4224. if (tid.Length > 0)
  4225. {
  4226. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4227. if (tid.Length > 5)
  4228. {
  4229. List<string> tids = getTidByCtidLike(tid);
  4230. if (tids.Count > 0 && tids.Count < 10)
  4231. {
  4232. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4233. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4234. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4235. {
  4236. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4237. }*/
  4238. }
  4239. }
  4240. lw.Add(tid_sql);
  4241. }
  4242. string shopname = GetPostString("shopname");
  4243. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4244. string buyernick = GetPostString("buyer_nick");
  4245. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4246. //if (tid.Length == 0 && buyernick.Length == 0)
  4247. //{
  4248. // lw.Add(string.Format("IsRefund<={0}", 1));
  4249. //}
  4250. string customer = GetPostString("customer");
  4251. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4252. string design = GetPostString("design");
  4253. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4254. string orderState = GetPostString("orderState");
  4255. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4256. string address = GetPostString("address");
  4257. 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));
  4258. string sellermemo = GetPostString("seller_memo");
  4259. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4260. string supplier = GetPostString("supplier");
  4261. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4262. string OrderArea = GetPostString("order_area");
  4263. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4264. string placedate1 = GetPostString("placedate1");
  4265. string placedate2 = GetPostString("placedate2");
  4266. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4267. if (fdw.Length > 0) lw.Add(fdw);
  4268. string price1 = GetPostString("price1");
  4269. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4270. string price2 = GetPostString("price2");
  4271. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4272. string unusualCon = GetPostString("unusualcon");
  4273. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4274. string posTag = CurrentUser.UserPost.Post.Code;
  4275. if (posTag == "Supplier")
  4276. {
  4277. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4278. }
  4279. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4280. lw.Add(string.Format("type = 'PDD' "));
  4281. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4282. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4283. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4284. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4285. /*if (tid.Length > 0)
  4286. {
  4287. List<string> tids = new List<string>();
  4288. if (dt != null && dt.Rows.Count > 0)
  4289. {
  4290. foreach (DataRow item in dt.Rows)
  4291. {
  4292. tids.Add("'" + item["tid"] + "'");
  4293. }
  4294. }
  4295. if (tids.Count > 0)
  4296. {
  4297. lw.RemoveAt(0);
  4298. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4299. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4300. dt = WebCache.GetData("view_erptradecell", dStruct);
  4301. }
  4302. }*/
  4303. writeGridDataTableJson(dStruct.TotalCount, dt);
  4304. }
  4305. public void get_erp_jdderiving()
  4306. {
  4307. DataStruct dStruct = GetPostStruct();
  4308. List<string> lw = new List<string>();
  4309. string tid = GetPostString("ctid");
  4310. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4311. string shopname = GetPostString("shopname");
  4312. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4313. string buyernick = GetPostString("buyer_nick");
  4314. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4315. //if (tid.Length == 0 && buyernick.Length == 0)
  4316. //{
  4317. // lw.Add(string.Format("IsRefund<={0}", 1));
  4318. //}
  4319. string customer = GetPostString("customer");
  4320. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4321. string design = GetPostString("design");
  4322. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4323. string orderState = GetPostString("orderState");
  4324. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4325. string address = GetPostString("address");
  4326. 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));
  4327. string sellermemo = GetPostString("seller_memo");
  4328. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4329. string supplier = GetPostString("supplier");
  4330. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4331. string OrderArea = GetPostString("order_area");
  4332. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4333. string placedate1 = GetPostString("placedate1");
  4334. string placedate2 = GetPostString("placedate2");
  4335. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4336. if (fdw.Length > 0) lw.Add(fdw);
  4337. string price1 = GetPostString("price1");
  4338. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4339. string price2 = GetPostString("price2");
  4340. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4341. string unusualCon = GetPostString("unusualcon");
  4342. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4343. string posTag = CurrentUser.UserPost.Post.Code;
  4344. if (posTag == "Supplier")
  4345. {
  4346. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4347. }
  4348. lw.Add(string.Format("OrderState = 6 "));
  4349. lw.Add(string.Format("type = 'JD' "));
  4350. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4351. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4352. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4353. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4354. writeGridDataTableJson(dStruct.TotalCount, dt);
  4355. }
  4356. public void get_erp_demoorderlist()
  4357. {
  4358. DataStruct dStruct = GetPostStruct();
  4359. List<string> lw = new List<string>();
  4360. string tid = GetPostString("ctid");
  4361. if (tid.Length > 0)
  4362. {
  4363. string select_tid = getTidByCtid(tid);
  4364. lw.Add(string.Format("tid='{0}'", select_tid));
  4365. }
  4366. string shopname = GetPostString("shopname");
  4367. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4368. string buyernick = GetPostString("buyer_nick");
  4369. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4370. string customer = GetPostString("customer");
  4371. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4372. string design = GetPostString("design");
  4373. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4374. string orderState = GetPostString("orderState");
  4375. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4376. string address = GetPostString("address");
  4377. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4378. string sellermemo = GetPostString("seller_memo");
  4379. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4380. string supplier = GetPostString("supplier");
  4381. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4382. string OrderArea = GetPostString("order_area");
  4383. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4384. string date1 = GetPostString("date1");
  4385. string date2 = GetPostString("date2");
  4386. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4387. if (dw.Length > 0) lw.Add(dw);
  4388. string price1 = GetPostString("price1");
  4389. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4390. string price2 = GetPostString("price2");
  4391. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4392. string posTag = CurrentUser.UserPost.Post.Code;
  4393. if (posTag == "Supplier")
  4394. {
  4395. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4396. }
  4397. //lw.Add(string.Format("OrderState = 6 "));
  4398. lw.Add(string.Format("IsSample={0}", 3));
  4399. lw.Add(string.Format("IsRefund<={0}", 1));
  4400. dStruct.Order = "pay_time desc";
  4401. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4402. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4403. writeGridDataTableJson(dStruct.TotalCount, dt);
  4404. }
  4405. public void save_erp_checkmemo()
  4406. {
  4407. if (UrlPostParmsCheck("ctid"))
  4408. {
  4409. string ctid = GetPostString("ctid");
  4410. CeErpTradeCell entity = null;
  4411. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4412. if (entity != null)
  4413. {
  4414. entity.CheckMemo = GetPostString("CheckMemo");
  4415. entity.Update();
  4416. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4417. if (trade != null)
  4418. {
  4419. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4420. }
  4421. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4422. returnSuccessMsg("保存成功!");
  4423. return;
  4424. }
  4425. returnErrorMsg("找不到记录");
  4426. }
  4427. }
  4428. public void get_erp_returnlist()
  4429. {
  4430. DataStruct dStruct = GetPostStruct();
  4431. List<string> lw = new List<string>();
  4432. string tid = GetPostString("ctid");
  4433. if (tid.Length > 0)
  4434. {
  4435. string select_tid = getTidByCtid(tid);
  4436. lw.Add(string.Format("tid='{0}'", select_tid));
  4437. }
  4438. string shopname = GetPostString("shopname");
  4439. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4440. string buyernick = GetPostString("buyer_nick");
  4441. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4442. string customer = GetPostString("customer");
  4443. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4444. string design = GetPostString("design");
  4445. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4446. string orderState = GetPostString("orderState");
  4447. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4448. string address = GetPostString("address");
  4449. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4450. string sellermemo = GetPostString("seller_memo");
  4451. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4452. string supplier = GetPostString("supplier");
  4453. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4454. string date1 = GetPostString("date1");
  4455. string date2 = GetPostString("date2");
  4456. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4457. if (dw.Length > 0) lw.Add(dw);
  4458. string bdate1 = GetPostString("backdate1");
  4459. string bdate2 = GetPostString("backdate2");
  4460. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4461. if (dw_back.Length > 0) lw.Add(dw_back);
  4462. string price1 = GetPostString("price1");
  4463. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4464. string price2 = GetPostString("price2");
  4465. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4466. lw.Add(string.Format("IsReturn>0"));
  4467. lw.Add(string.Format("IsXianHuo=0"));
  4468. lw.Add(string.Format("IsReturn!=3"));
  4469. string backtype = GetPostString("backtype");
  4470. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4471. dStruct.Order = "FinishDesignTime desc";
  4472. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4473. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4474. writeGridDataTableJson(dStruct.TotalCount, dt);
  4475. }
  4476. public void get_erp_today_sumreturn()
  4477. {
  4478. DataStruct dStruct = GetPostStruct();
  4479. List<string> lw = new List<string>();
  4480. string bdate1 = GetPostString("returnTimeS");
  4481. string bdate2 = GetPostString("returnTimeE");
  4482. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4483. if (dw_back.Length > 0) lw.Add(dw_back);
  4484. lw.Add(string.Format("IsReturn=0"));
  4485. lw.Add(string.Format("IsXianHuo=0"));
  4486. string mainWhere = string.Join(" and ", lw.ToArray());
  4487. string sql = "";
  4488. if (dw_back.Length > 0)
  4489. {
  4490. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4491. }
  4492. else
  4493. {
  4494. 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 + "'";
  4495. }
  4496. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4497. decimal total = 0, today_finish = 0;
  4498. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4499. {
  4500. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4501. }
  4502. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4503. {
  4504. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4505. }
  4506. var res = new
  4507. {
  4508. data = total,
  4509. data1 = today_finish,
  4510. };
  4511. string ro_jsond = JsonConvert.SerializeObject(res);
  4512. returnSuccess(ro_jsond);
  4513. return;
  4514. }
  4515. public void get_erp_allreturnlist()
  4516. {
  4517. DataStruct dStruct = GetPostStruct();
  4518. List<string> lw = new List<string>();
  4519. string tid = GetPostString("ctid");
  4520. if (tid.Length > 0)
  4521. {
  4522. string select_tid = getTidByCtid(tid);
  4523. lw.Add(string.Format("tid='{0}'", select_tid));
  4524. }
  4525. string shopname = GetPostString("shopname");
  4526. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4527. string buyernick = GetPostString("buyer_nick");
  4528. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4529. string customer = GetPostString("customer");
  4530. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4531. string design = GetPostString("design");
  4532. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4533. string orderState = GetPostString("orderState");
  4534. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4535. string address = GetPostString("address");
  4536. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4537. string sellermemo = GetPostString("seller_memo");
  4538. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4539. string supplier = GetPostString("supplier");
  4540. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4541. string date1 = GetPostString("date1");
  4542. string date2 = GetPostString("date2");
  4543. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4544. if (dw.Length > 0) lw.Add(dw);
  4545. string bdate1 = GetPostString("backdate1");
  4546. string bdate2 = GetPostString("backdate2");
  4547. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4548. if (dw_back.Length > 0) lw.Add(dw_back);
  4549. string price1 = GetPostString("price1");
  4550. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4551. string price2 = GetPostString("price2");
  4552. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4553. string backreason = GetPostString("backreason");
  4554. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4555. lw.Add(string.Format("IsXianHuo=0"));
  4556. lw.Add(string.Format("ReturnTime != ''"));
  4557. string backtype = GetPostString("backtype");
  4558. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4559. dStruct.Order = "FinishDesignTime desc";
  4560. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4561. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4562. writeGridDataTableJson(dStruct.TotalCount, dt);
  4563. }
  4564. public void get_erp_aftersalereturnlist()
  4565. {
  4566. DataStruct dStruct = GetPostStruct();
  4567. List<string> lw = new List<string>();
  4568. string tid = GetPostString("ctid");
  4569. if (tid.Length > 0)
  4570. {
  4571. string select_tid = getTidByCtid(tid);
  4572. lw.Add(string.Format("tid='{0}'", select_tid));
  4573. }
  4574. string shopname = GetPostString("shopname");
  4575. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4576. string buyernick = GetPostString("buyer_nick");
  4577. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4578. string customer = GetPostString("customer");
  4579. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4580. string design = GetPostString("design");
  4581. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4582. string orderState = GetPostString("orderState");
  4583. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4584. string address = GetPostString("address");
  4585. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4586. string sellermemo = GetPostString("seller_memo");
  4587. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4588. string supplier = GetPostString("supplier");
  4589. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4590. string date1 = GetPostString("date1");
  4591. string date2 = GetPostString("date2");
  4592. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4593. if (dw.Length > 0) lw.Add(dw);
  4594. string bdate1 = GetPostString("backdate1");
  4595. string bdate2 = GetPostString("backdate2");
  4596. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4597. if (dw_back.Length > 0) lw.Add(dw_back);
  4598. string price1 = GetPostString("price1");
  4599. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4600. string price2 = GetPostString("price2");
  4601. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4602. lw.Add(string.Format("IsReturn=3"));
  4603. string backtype = GetPostString("backtype");
  4604. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4605. string backreason = GetPostString("backreason");
  4606. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4607. dStruct.Order = "ReturnTime desc";
  4608. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4609. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4610. writeGridDataTableJson(dStruct.TotalCount, dt);
  4611. }
  4612. public void get_erp_xianhuoreturnlist()
  4613. {
  4614. DataStruct dStruct = GetPostStruct();
  4615. List<string> lw = new List<string>();
  4616. string tid = GetPostString("ctid");
  4617. if (tid.Length > 0)
  4618. {
  4619. string select_tid = getTidByCtid(tid);
  4620. lw.Add(string.Format("tid='{0}'", select_tid));
  4621. }
  4622. string shopname = GetPostString("shopname");
  4623. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4624. string buyernick = GetPostString("buyer_nick");
  4625. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4626. string customer = GetPostString("customer");
  4627. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4628. string design = GetPostString("design");
  4629. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4630. string orderState = GetPostString("orderState");
  4631. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4632. string address = GetPostString("address");
  4633. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4634. string sellermemo = GetPostString("seller_memo");
  4635. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4636. string supplier = GetPostString("supplier");
  4637. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4638. string OrderArea = GetPostString("order_area");
  4639. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4640. string date1 = GetPostString("date1");
  4641. string date2 = GetPostString("date2");
  4642. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4643. if (dw.Length > 0) lw.Add(dw);
  4644. string price1 = GetPostString("price1");
  4645. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4646. string price2 = GetPostString("price2");
  4647. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4648. string posTag = CurrentUser.UserPost.Post.Code;
  4649. if (posTag == "Supplier")
  4650. {
  4651. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4652. }
  4653. lw.Add(string.Format("OrderState=6 "));
  4654. lw.Add(string.Format("IsXianHuo=1 "));
  4655. lw.Add(string.Format("IsReturn>0 "));
  4656. lw.Add(string.Format("IsReturn!=3"));
  4657. lw.Add(string.Format("IsRefund<={0}", 1));
  4658. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4659. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4660. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4661. writeGridDataTableJson(dStruct.TotalCount, dt);
  4662. }
  4663. public void set_erp_orderdelivery()
  4664. {
  4665. if (UrlPostParmsCheck("ctid"))
  4666. {
  4667. string eid = GetPostString("ctid");
  4668. CeErpTradeCell entity = null;
  4669. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4670. if (entity != null)
  4671. {
  4672. if (entity.OrderState >= 7)
  4673. {
  4674. returnErrorMsg("此单已发货,无需重复发货");
  4675. return;
  4676. }
  4677. if (entity.OrderState != 6)
  4678. {
  4679. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4680. return;
  4681. }
  4682. string shop = GetPostString("seller_nick");
  4683. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4684. string comName = GetPostString("comName");
  4685. string comCode = GetPostString("comCode");
  4686. string outSid = GetPostString("outSid");
  4687. string deliveryType = GetPostString("deliveryType");
  4688. string deliveryMemo = GetPostString("deliveryMemo");
  4689. outSid = outSid.Trim();
  4690. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4691. if (mainEn == null)
  4692. {
  4693. returnErrorMsg("找不到原始订单记录");
  4694. return;
  4695. }
  4696. bool isInitOrderDeliv = false;
  4697. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4698. {
  4699. isInitOrderDeliv = true;
  4700. }
  4701. string apires = "";
  4702. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4703. 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)
  4704. {
  4705. apires = "发货成功true";
  4706. }
  4707. else
  4708. {
  4709. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4710. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4711. }
  4712. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4713. {
  4714. entity.OrderState = 7;//发货后订单已发货
  4715. entity.OutSid = outSid;
  4716. entity.MemoOpt = 0;
  4717. entity.UpdateTime = DateTime.Now;
  4718. entity.FinishDeliveryTime = DateTime.Now;
  4719. entity.Update();
  4720. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4721. commonHelper.UpdateRelationOrder(entity.ctid);
  4722. //还要插入快递信息到 快递信息表
  4723. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4724. exinfo.tid = eid;
  4725. exinfo.out_sid = outSid;
  4726. exinfo.company_code = comCode;
  4727. exinfo.company_name = comName;
  4728. exinfo.delivery_memo = deliveryMemo;
  4729. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4730. exinfo.deliveryType = deliveryType;
  4731. exinfo.Create();
  4732. returnSuccessMsg("发货操作成功!");
  4733. commonHelper.UpdateRelationOrder(entity.ctid);
  4734. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4735. CeErpSukuraData.createInfo(entity.ctid, 4);
  4736. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  4737. {
  4738. commonHelper.sendCytExpress(exinfo);
  4739. }
  4740. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4741. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4742. }
  4743. else
  4744. {
  4745. string errmsg = commonHelper.KeepChinese(apires);
  4746. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4747. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4748. }
  4749. return;
  4750. }
  4751. returnErrorMsg("找不到订单记录");
  4752. }
  4753. }
  4754. public void set_erp_multidelivery()
  4755. {
  4756. string eids = GetPostString("tids");
  4757. string[] eidList = eids.Split(',');
  4758. if (eidList.Length <= 0)
  4759. {
  4760. returnErrorMsg("发货不能为空");
  4761. return;
  4762. }
  4763. foreach (string ctid in eidList)
  4764. {
  4765. if (ctid.Length <= 0) continue;
  4766. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4767. if (expInfo != null)
  4768. {
  4769. StringBuilder sql = new StringBuilder();
  4770. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4771. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4772. if (dt.Rows.Count > 0)
  4773. {
  4774. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4775. {
  4776. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4777. expInfo.state = "异常";
  4778. expInfo.isMultiDelivery = 1;
  4779. expInfo.Update();
  4780. continue;
  4781. }
  4782. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4783. {
  4784. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4785. expInfo.state = "异常";
  4786. expInfo.Update();
  4787. continue;
  4788. }
  4789. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4790. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4791. bool isInitOrderDeliv = false;
  4792. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4793. {
  4794. isInitOrderDeliv = true;
  4795. expInfo.isMultiDelivery = 1;
  4796. }
  4797. if (ctid.IndexOf("N") != -1)
  4798. {
  4799. StringBuilder sqlbucha = new StringBuilder();
  4800. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4801. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4802. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4803. commonHelper.UpdateRelationOrder(ctid);
  4804. expInfo.delivery_memo = "发货成功";
  4805. expInfo.state = "发货成功";
  4806. expInfo.isMultiDelivery = 1;
  4807. expInfo.Update();
  4808. }
  4809. else
  4810. {
  4811. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4812. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4813. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4814. {
  4815. expInfo.delivery_memo = "发货成功";
  4816. expInfo.state = "发货成功";
  4817. expInfo.isMultiDelivery = 1;
  4818. expInfo.Update();
  4819. commonHelper.UpdateRelationOrder(ctid);
  4820. CeErpSukuraData.createInfo(ctid, 4);
  4821. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4822. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4823. }
  4824. else
  4825. {
  4826. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4827. expInfo.state = "异常";
  4828. expInfo.Update();
  4829. }
  4830. }
  4831. }
  4832. }
  4833. }
  4834. returnSuccessMsg("操作完成");
  4835. }
  4836. public void reset_erp_memoopt()
  4837. {
  4838. if (UrlPostParmsCheck("ctid"))
  4839. {
  4840. string eid = GetPostString("ctid");
  4841. CeErpTradeCell entity = null;
  4842. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4843. if (entity != null)
  4844. {
  4845. string stropt = "";
  4846. if (entity.MemoOpt == 1)
  4847. {
  4848. stropt = "“改稿”";
  4849. }
  4850. else if (entity.MemoOpt == 2)
  4851. {
  4852. stropt = "“定稿”";
  4853. }
  4854. else if (entity.MemoOpt == 3)
  4855. {
  4856. stropt = "“完成查货”";
  4857. CeErpSukuraData.createInfo(entity.ctid, 6);
  4858. }
  4859. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4860. entity.UpdateTime = DateTime.Now;
  4861. entity.MemoOpt = 0;
  4862. entity.Update();
  4863. returnSuccessMsg("操作成功!");
  4864. return;
  4865. }
  4866. returnErrorMsg("找不到记录");
  4867. }
  4868. }
  4869. public void get_erp_deliveryunusual()
  4870. {
  4871. DataStruct dStruct = GetPostStruct();
  4872. List<string> lw = new List<string>();
  4873. string tid = GetPostString("ctid");
  4874. if (tid.Length > 0)
  4875. {
  4876. string select_tid = getTidByCtid(tid);
  4877. lw.Add(string.Format("tid='{0}'", select_tid));
  4878. }
  4879. string shopname = GetPostString("shopname");
  4880. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4881. string buyernick = GetPostString("buyer_nick");
  4882. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4883. string customer = GetPostString("customer");
  4884. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4885. string design = GetPostString("design");
  4886. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4887. string sellermemo = GetPostString("seller_memo");
  4888. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4889. string supplier = GetPostString("supplier");
  4890. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4891. string date1 = GetPostString("date1");
  4892. string date2 = GetPostString("date2");
  4893. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4894. if (dw.Length > 0) lw.Add(dw);
  4895. string placedate1 = GetPostString("placedate1");
  4896. string placedate2 = GetPostString("placedate2");
  4897. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4898. if (dw_place.Length > 0) lw.Add(dw_place);
  4899. string price1 = GetPostString("price1");
  4900. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4901. string price2 = GetPostString("price2");
  4902. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4903. string unusualCon = GetPostString("unusualcon");
  4904. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4905. string posTag = CurrentUser.UserPost.Post.Code;
  4906. if (posTag == "Supplier")
  4907. {
  4908. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4909. }
  4910. lw.Add(string.Format("OrderState = 6"));
  4911. lw.Add(string.Format("UnusualTag = 5"));
  4912. lw.Add(string.Format("IsRefund<={0}", 1));
  4913. dStruct.Order = "FinishPlaceTime desc";
  4914. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4915. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4916. writeGridDataTableJson(dStruct.TotalCount, dt);
  4917. }
  4918. public void get_erp_deliveryedlist()
  4919. {
  4920. DataStruct dStruct = GetPostStruct();
  4921. List<string> lw = new List<string>();
  4922. string tid = GetPostString("ctid");
  4923. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4924. string shopname = GetPostString("shopname");
  4925. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4926. string buyernick = GetPostString("buyer_nick");
  4927. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4928. string customer = GetPostString("customer");
  4929. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4930. string design = GetPostString("design");
  4931. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4932. string sellermemo = GetPostString("seller_memo");
  4933. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4934. string logistics = GetPostString("logistics");
  4935. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4936. string date1 = GetPostString("date1");
  4937. string date2 = GetPostString("date2");
  4938. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4939. //if (dw.Length > 0) lw.Add(dw);
  4940. string placedate1 = GetPostString("placedate1");
  4941. string placedate2 = GetPostString("placedate2");
  4942. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4943. if (fdw.Length > 0) lw.Add(fdw);
  4944. string devdate1 = GetPostString("deliverydate1");
  4945. string devdate2 = GetPostString("deliverydate2");
  4946. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4947. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4948. string price1 = GetPostString("price1");
  4949. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4950. string price2 = GetPostString("price2");
  4951. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4952. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4953. {
  4954. if (tid.Length > 0)
  4955. {
  4956. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4957. if (tid.Length > 5)
  4958. {
  4959. List<string> tids = getTidByCtidLike(tid);
  4960. if (tids.Count > 0 && tids.Count < 10)
  4961. {
  4962. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4963. }
  4964. }
  4965. lw.Add(tid_sql);
  4966. }
  4967. if (buyernick.Length > 0)
  4968. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4969. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4970. if (dw.Length > 0) lw.Add(dw);
  4971. }
  4972. else
  4973. {
  4974. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  4975. }
  4976. string posTag = CurrentUser.UserPost.Post.Code;
  4977. if (posTag == "Supplier")
  4978. {
  4979. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4980. }
  4981. else
  4982. {
  4983. string supplier = GetPostString("supplier");
  4984. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4985. }
  4986. lw.Add(string.Format(" OrderState IN (7, 8)"));
  4987. lw.Add(string.Format("type != 'PDD' "));
  4988. lw.Add(string.Format("IsRefund!={0}", 2));
  4989. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4990. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4991. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4992. /*if (tid.Length > 0)
  4993. {
  4994. List<string> tids = new List<string>();
  4995. if (dt != null && dt.Rows.Count > 0)
  4996. {
  4997. foreach (DataRow item in dt.Rows)
  4998. {
  4999. tids.Add("'" + item["tid"] + "'");
  5000. }
  5001. }
  5002. if (tids.Count > 0)
  5003. {
  5004. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5005. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5006. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5007. dt = WebCache.GetData("view_erptradecell", dStruct);
  5008. }
  5009. }*/
  5010. if (dt != null)
  5011. {
  5012. foreach (DataRow dr in dt.Rows)
  5013. {
  5014. 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();
  5015. }
  5016. }
  5017. writeGridDataTableJson(dStruct.TotalCount, dt);
  5018. }
  5019. public void get_erp_pdddeliveryed()
  5020. {
  5021. DataStruct dStruct = GetPostStruct();
  5022. List<string> lw = new List<string>();
  5023. string tid = GetPostString("ctid");
  5024. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5025. string shopname = GetPostString("shopname");
  5026. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5027. string buyernick = GetPostString("buyer_nick");
  5028. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5029. string customer = GetPostString("customer");
  5030. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5031. string design = GetPostString("design");
  5032. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5033. string sellermemo = GetPostString("seller_memo");
  5034. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5035. string logistics = GetPostString("logistics");
  5036. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5037. string date1 = GetPostString("date1");
  5038. string date2 = GetPostString("date2");
  5039. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5040. //if (dw.Length > 0) lw.Add(dw);
  5041. string placedate1 = GetPostString("placedate1");
  5042. string placedate2 = GetPostString("placedate2");
  5043. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5044. if (fdw.Length > 0) lw.Add(fdw);
  5045. string devdate1 = GetPostString("deliverydate1");
  5046. string devdate2 = GetPostString("deliverydate2");
  5047. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5048. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5049. string price1 = GetPostString("price1");
  5050. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5051. string price2 = GetPostString("price2");
  5052. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5053. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5054. {
  5055. if (tid.Length > 0)
  5056. {
  5057. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5058. if (tid.Length > 5)
  5059. {
  5060. List<string> tids = getTidByCtidLike(tid);
  5061. if (tids.Count > 0 && tids.Count < 10)
  5062. {
  5063. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5064. }
  5065. }
  5066. lw.Add(tid_sql);
  5067. }
  5068. if (buyernick.Length > 0)
  5069. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5070. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5071. if (dw.Length > 0) lw.Add(dw);
  5072. }
  5073. else
  5074. {
  5075. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5076. }
  5077. string posTag = CurrentUser.UserPost.Post.Code;
  5078. if (posTag == "Supplier")
  5079. {
  5080. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5081. }
  5082. else
  5083. {
  5084. string supplier = GetPostString("supplier");
  5085. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5086. }
  5087. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5088. lw.Add(string.Format("type = 'PDD' "));
  5089. lw.Add(string.Format("IsRefund!={0}", 2));
  5090. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5091. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5092. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5093. /* if (tid.Length > 0)
  5094. {
  5095. List<string> tids = new List<string>();
  5096. if (dt != null && dt.Rows.Count > 0)
  5097. {
  5098. foreach (DataRow item in dt.Rows)
  5099. {
  5100. tids.Add("'" + item["tid"] + "'");
  5101. }
  5102. }
  5103. if (tids.Count > 0)
  5104. {
  5105. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5106. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5107. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5108. dt = WebCache.GetData("view_erptradecell", dStruct);
  5109. }
  5110. }*/
  5111. foreach (DataRow dr in dt.Rows)
  5112. {
  5113. 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();
  5114. }
  5115. writeGridDataTableJson(dStruct.TotalCount, dt);
  5116. }
  5117. public void get_erp_jddeliveryed()
  5118. {
  5119. DataStruct dStruct = GetPostStruct();
  5120. List<string> lw = new List<string>();
  5121. string tid = GetPostString("ctid");
  5122. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5123. string shopname = GetPostString("shopname");
  5124. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5125. string buyernick = GetPostString("buyer_nick");
  5126. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5127. string customer = GetPostString("customer");
  5128. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5129. string design = GetPostString("design");
  5130. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5131. string sellermemo = GetPostString("seller_memo");
  5132. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5133. string date1 = GetPostString("date1");
  5134. string date2 = GetPostString("date2");
  5135. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5136. //if (dw.Length > 0) lw.Add(dw);
  5137. string placedate1 = GetPostString("placedate1");
  5138. string placedate2 = GetPostString("placedate2");
  5139. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5140. if (fdw.Length > 0) lw.Add(fdw);
  5141. string devdate1 = GetPostString("deliverydate1");
  5142. string devdate2 = GetPostString("deliverydate2");
  5143. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5144. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5145. string price1 = GetPostString("price1");
  5146. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5147. string price2 = GetPostString("price2");
  5148. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5149. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5150. {
  5151. if (tid.Length > 0)
  5152. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5153. if (buyernick.Length > 0)
  5154. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5155. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5156. if (dw.Length > 0) lw.Add(dw);
  5157. }
  5158. else
  5159. {
  5160. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5161. }
  5162. string posTag = CurrentUser.UserPost.Post.Code;
  5163. if (posTag == "Supplier")
  5164. {
  5165. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5166. }
  5167. else
  5168. {
  5169. string supplier = GetPostString("supplier");
  5170. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5171. }
  5172. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5173. lw.Add(string.Format("type = 'JD' "));
  5174. lw.Add(string.Format("IsRefund!={0}", 2));
  5175. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5176. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5177. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5178. foreach (DataRow dr in dt.Rows)
  5179. {
  5180. 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();
  5181. }
  5182. writeGridDataTableJson(dStruct.TotalCount, dt);
  5183. }
  5184. public void get_erp_allplacelist()
  5185. {
  5186. DataStruct dStruct = GetPostStruct();
  5187. List<string> lw = new List<string>();
  5188. string tid = GetPostString("ctid");
  5189. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5190. string shopname = GetPostString("shopname");
  5191. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5192. string buyernick = GetPostString("buyer_nick");
  5193. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5194. string customer = GetPostString("customer");
  5195. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5196. string design = GetPostString("design");
  5197. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5198. string sellermemo = GetPostString("seller_memo");
  5199. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5200. string supplier = GetPostString("supplier");
  5201. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5202. string date1 = GetPostString("date1");
  5203. string date2 = GetPostString("date2");
  5204. string pldate1 = GetPostString("placedate1");
  5205. string pldate2 = GetPostString("placedate2");
  5206. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5207. //if (dw.Length > 0) lw.Add(dw);
  5208. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5209. {
  5210. if (tid.Length > 0)
  5211. {
  5212. string select_tid = getTidByCtid(tid);
  5213. lw.Add(string.Format("tid='{0}'", select_tid));
  5214. }
  5215. if (buyernick.Length > 0)
  5216. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5217. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5218. if (dw.Length > 0) lw.Add(dw);
  5219. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5220. if (dw_place.Length > 0) lw.Add(dw_place);
  5221. }
  5222. else
  5223. {
  5224. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5225. {
  5226. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5227. }
  5228. }
  5229. string price1 = GetPostString("price1");
  5230. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5231. string price2 = GetPostString("price2");
  5232. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5233. string posTag = CurrentUser.UserPost.Post.Code;
  5234. if (posTag == "Supplier")
  5235. {
  5236. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5237. }
  5238. lw.Add(string.Format("OrderState >= 6"));
  5239. lw.Add(string.Format("IsSample != 2 "));
  5240. //lw.Add(string.Format("isDianziOrder = 0 "));
  5241. lw.Add(string.Format("SupplierId > 0 "));
  5242. //lw.Add(string.Format("IsRefund<={0}", 1));
  5243. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5244. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5245. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5246. foreach (DataRow dr in dt.Rows)
  5247. {
  5248. 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();
  5249. }
  5250. writeGridDataTableJson(dStruct.TotalCount, dt);
  5251. }
  5252. public void get_erp_financeallplacelist()
  5253. {
  5254. DataStruct dStruct = GetPostStruct();
  5255. List<string> lw = new List<string>();
  5256. string tid = GetPostString("ctid");
  5257. string shopname = GetPostString("shopname");
  5258. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5259. string buyernick = GetPostString("buyer_nick");
  5260. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5261. string customer = GetPostString("customer");
  5262. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5263. string design = GetPostString("design");
  5264. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5265. string sellermemo = GetPostString("seller_memo");
  5266. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5267. string supplier = GetPostString("supplier");
  5268. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5269. string date1 = GetPostString("date1");
  5270. string date2 = GetPostString("date2");
  5271. string pldate1 = GetPostString("placedate1");
  5272. string pldate2 = GetPostString("placedate2");
  5273. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5274. {
  5275. if (tid.Length > 0)
  5276. {
  5277. string select_tid = getTidByCtid(tid);
  5278. lw.Add(string.Format("tid='{0}'", select_tid));
  5279. }
  5280. if (buyernick.Length > 0)
  5281. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5282. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5283. if (dw.Length > 0) lw.Add(dw);
  5284. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5285. if (dw_place.Length > 0) lw.Add(dw_place);
  5286. }
  5287. else
  5288. {
  5289. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5290. {
  5291. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5292. }
  5293. }
  5294. string price1 = GetPostString("price1");
  5295. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5296. string price2 = GetPostString("price2");
  5297. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5298. string posTag = CurrentUser.UserPost.Post.Code;
  5299. if (posTag == "Supplier")
  5300. {
  5301. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5302. }
  5303. //lw.Add(string.Format("OrderState >= 6"));
  5304. lw.Add(string.Format("IsSample != 2 "));
  5305. lw.Add(string.Format("isDianziOrder = 0 "));
  5306. //lw.Add(string.Format("IsRefund<={0}", 1));
  5307. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5308. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5309. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5310. foreach (DataRow dr in dt.Rows)
  5311. {
  5312. 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();
  5313. }
  5314. writeGridDataTableJson(dStruct.TotalCount, dt);
  5315. }
  5316. public void get_erp_expresslist()
  5317. {
  5318. int listtype = GetInt("ltype");
  5319. DataStruct dStruct = GetPostStruct();
  5320. List<string> lw = new List<string>();
  5321. string tid = GetPostString("tid");
  5322. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5323. string outsid = GetPostString("out_sid");
  5324. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5325. string importer = GetPostString("ImportUserName");
  5326. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5327. string file = GetPostString("import_file");
  5328. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5329. string printman = GetPostString("printman");
  5330. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5331. string date1 = GetPostString("date1");
  5332. string date2 = GetPostString("date2");
  5333. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5334. if (dw.Length > 0) lw.Add(dw);
  5335. string fdate1 = GetPostString("finishdate1");
  5336. string fdate2 = GetPostString("finishdate2");
  5337. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5338. if (fdw.Length > 0) lw.Add(fdw);
  5339. string supplierId = GetPostString("supplierId");
  5340. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5341. if (listtype == 1)
  5342. {
  5343. lw.Add(string.Format("importUserId !=0"));
  5344. }
  5345. string posTag = CurrentUser.UserPost.Post.Code;
  5346. if (posTag == "Supplier")
  5347. {
  5348. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5349. }
  5350. if (dStruct.PageSize != 100000)
  5351. {
  5352. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5353. }
  5354. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5355. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5356. writeGridDataTableJson(dStruct.TotalCount, dt);
  5357. }
  5358. public void set_erp_buchaorderdelivery()
  5359. {
  5360. if (UrlPostParmsCheck("ctid"))
  5361. {
  5362. string eid = GetPostString("ctid");
  5363. CeErpTradeCell entity = null;
  5364. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5365. if (entity != null)
  5366. {
  5367. if (entity.IsSample != 2)
  5368. {
  5369. returnErrorMsg("补差价单才能标记为已发货");
  5370. return;
  5371. }
  5372. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5373. entity.OrderState = 7;
  5374. entity.Update();
  5375. returnSuccessMsg("操作成功!");
  5376. return;
  5377. }
  5378. returnErrorMsg("找不到记录");
  5379. }
  5380. }
  5381. public void get_stdtemplates()
  5382. {
  5383. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5384. //string res = taobaoHelper.test();
  5385. string res = apiHelper.API_PrintTemplate();
  5386. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5387. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5388. {
  5389. int sidx = res.IndexOf("error_code");
  5390. int eidx = res.IndexOf("success");
  5391. string msg = res.Substring(sidx, eidx - sidx);
  5392. returnErrorMsg(msg);
  5393. return;
  5394. }
  5395. if (res.Length <= 0)
  5396. {
  5397. returnErrorMsg("模板数据为空!");
  5398. return;
  5399. }
  5400. ReturnSuccess(res);
  5401. }
  5402. public void cancel_print_order()
  5403. {
  5404. if (UrlPostParmsCheck("ctid"))
  5405. {
  5406. string ctid = GetPostString("ctid");
  5407. CeErpTradeCell entity = null;
  5408. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5409. if (entity != null)
  5410. {
  5411. string res = "";
  5412. string code = entity.LastBillWaybillCode;
  5413. if (code == "")
  5414. {
  5415. code = entity.OutSid;
  5416. }
  5417. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5418. XLog.SaveLog(0, "取消面单" + res);
  5419. }
  5420. }
  5421. }
  5422. public void set_erp_printwaybill()
  5423. {
  5424. if (UrlPostParmsCheck("ctid"))
  5425. {
  5426. string ctid = GetPostString("ctid");
  5427. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5428. string cpName = GetPostString("cpname");
  5429. string isTogether = GetPostString("together");
  5430. string printType = GetPostString("printType");
  5431. //var res_obj = new
  5432. //{
  5433. // restype = 1,
  5434. // 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\"}"
  5435. //};
  5436. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5437. //ReturnSuccess(ro_json);
  5438. //return;
  5439. bool isUseLastWayBillCode = false;
  5440. CeErpTradeCell entity = null;
  5441. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5442. if (entity != null)
  5443. {
  5444. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5445. {
  5446. isUseLastWayBillCode = true;
  5447. }
  5448. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5449. {
  5450. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5451. return;
  5452. }
  5453. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5454. {
  5455. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5456. return;
  5457. }
  5458. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5459. {
  5460. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5461. return;
  5462. }
  5463. }
  5464. string res = "";
  5465. Api_waybill_code_response_Obj fullObj = null;
  5466. string pData_str = "";
  5467. string curUseWayBillCode = "";
  5468. if (isUseLastWayBillCode == false)
  5469. {
  5470. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5471. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5472. if (res.IndexOf("failure") != -1)
  5473. {
  5474. //int idx = res.IndexOf("sub_message");
  5475. //int idx2 = res.IndexOf("flag");
  5476. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5477. string errMsgNeed = commonHelper.KeepChinese(res);
  5478. var res_objd = new
  5479. {
  5480. restype = 0,
  5481. data = "获取面单失败" + errMsgNeed
  5482. };
  5483. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5484. returnSuccess(ro_jsond);
  5485. if (res.IndexOf("停发") != -1)
  5486. {
  5487. entity.UnusualCon = "物流停发";
  5488. entity.Update();
  5489. }
  5490. //returnErrorMsg("获取面单失败,"+emsg);
  5491. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5492. return;
  5493. }
  5494. else if (res.IndexOf("errorMsg") != -1)
  5495. {
  5496. //int idx = res.IndexOf("errorMsg");
  5497. //int idx2 = res.IndexOf("}]}");
  5498. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5499. string errMsgNeed = commonHelper.KeepChinese(res);
  5500. var res_objf = new
  5501. {
  5502. restype = 0,
  5503. data = "获取面单失败2" + errMsgNeed
  5504. };
  5505. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5506. if (res.IndexOf("停发") != -1)
  5507. {
  5508. entity.UnusualCon = "物流停发";
  5509. entity.Update();
  5510. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5511. if (trade != null)
  5512. {
  5513. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5514. }
  5515. }
  5516. returnSuccess(ro_jsonf);
  5517. //returnErrorMsg("获取面单失败," + emsg);
  5518. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5519. return;
  5520. }
  5521. try
  5522. {
  5523. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5524. //res = res.Replace(" ", "");
  5525. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5526. }
  5527. catch (Exception ex)
  5528. {
  5529. XLog.SaveLog(0, "生成fullObj" + res);
  5530. var res_objf = new
  5531. {
  5532. restype = 0,
  5533. data = "生成fullObj发生错误" + ex.Message
  5534. };
  5535. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5536. returnSuccess(ro_jsonf);
  5537. return;
  5538. }
  5539. if (fullObj.response.data.content.Count > 0)
  5540. {
  5541. ContentItem codeObj = fullObj.response.data.content[0];
  5542. if (cpCode.IndexOf("SFFQ-") != -1)
  5543. {
  5544. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5545. }
  5546. else
  5547. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5548. curUseWayBillCode = codeObj.waybillCode;
  5549. }
  5550. else
  5551. {
  5552. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5553. var res_objf = new
  5554. {
  5555. restype = 0,
  5556. data = "生成fullObj找不到快递单号waybillCode"
  5557. };
  5558. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5559. returnSuccess(ro_jsonf);
  5560. return;
  5561. }
  5562. }
  5563. else
  5564. {
  5565. //使用上次打印的快递单号
  5566. if (cpCode == "SFFQ-LY")
  5567. {
  5568. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5569. }
  5570. else
  5571. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5572. curUseWayBillCode = entity.LastBillWaybillCode;
  5573. }
  5574. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5575. {
  5576. var res_obje = new
  5577. {
  5578. restype = 0,
  5579. data = "获取加密打印数据失败"
  5580. };
  5581. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5582. returnSuccess(ro_jsone);
  5583. entity.LastBillCpCode = cpCode;
  5584. entity.LastBillWaybillCode = curUseWayBillCode;
  5585. entity.Update();
  5586. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5587. //returnErrorMsg("获取加密打印数据失败");
  5588. return;
  5589. }
  5590. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5591. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5592. string btnType = "";
  5593. string errorMsg = "";
  5594. if (entity != null)
  5595. {
  5596. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5597. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5598. //cpcode是 YTO-CAINIAO
  5599. //string comCode = cpCode.Split('-')[0].ToString();
  5600. string apires = "";
  5601. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5602. //isTogether=2是新的合包弹窗
  5603. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5604. {
  5605. if (ctid.IndexOf("N") != -1)
  5606. {
  5607. apires = "发货成功";
  5608. }
  5609. else
  5610. {
  5611. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5612. }
  5613. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5614. //打单后发货
  5615. StringBuilder sql = new StringBuilder();
  5616. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5617. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5618. {
  5619. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5620. }
  5621. else
  5622. {
  5623. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5624. }
  5625. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5626. foreach (DataRow row in dt.Rows)
  5627. {
  5628. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5629. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5630. {
  5631. try
  5632. {
  5633. btnType = "待发货";
  5634. entity.OutSid = curUseWayBillCode;
  5635. entity.OrderState = 7;
  5636. entity.IsUrgency = false;
  5637. entity.LastBillCpCode = "";
  5638. entity.LastBillWaybillCode = "";
  5639. entity.FinishDeliveryTime = DateTime.Now;
  5640. entity.IsReturn = 0;
  5641. entity.MemoOpt = 0;
  5642. entity.UpdateTime = DateTime.Now;
  5643. entity.Update();
  5644. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5645. //还要插入快递信息到 快递信息表
  5646. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5647. exinfo.tid = entity.ctid;
  5648. exinfo.out_sid = curUseWayBillCode;
  5649. exinfo.company_code = cpCode;
  5650. exinfo.company_name = cpName;
  5651. exinfo.supplierUserName = supplierName;
  5652. exinfo.deliveryType = "发货成功";
  5653. exinfo.print_time = DateTime.Now;
  5654. exinfo.printUser = CurrentUser.UserName;
  5655. exinfo.postData = pData_str;
  5656. exinfo.Create();
  5657. commonHelper.UpdateRelationOrder(entity.ctid);
  5658. CeErpSukuraData.createInfo(ctid, 4);
  5659. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5660. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5661. {
  5662. commonHelper.sendCytExpress(exinfo);
  5663. }
  5664. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5665. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5666. }
  5667. catch (Exception ex)
  5668. {
  5669. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5670. }
  5671. }
  5672. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5673. {
  5674. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5675. if (entity.OrderState == 6)
  5676. {
  5677. entity.OrderState = 7;
  5678. }
  5679. entity.UpdateTime = DateTime.Now;
  5680. entity.FinishDeliveryTime = DateTime.Now;
  5681. btnType = "已发货";
  5682. entity.Update();
  5683. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5684. exinfo.tid = entity.ctid;
  5685. exinfo.out_sid = curUseWayBillCode;
  5686. exinfo.company_code = cpCode;
  5687. exinfo.company_name = cpName;
  5688. exinfo.supplierUserName = supplierName;
  5689. exinfo.deliveryType = "发货成功";
  5690. exinfo.print_time = DateTime.Now;
  5691. exinfo.printUser = CurrentUser.UserName;
  5692. exinfo.postData = pData_str;
  5693. exinfo.Create();
  5694. commonHelper.UpdateRelationOrder(entity.ctid);
  5695. CeErpSukuraData.createInfo(entity.ctid, 4);
  5696. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5697. {
  5698. commonHelper.sendCytExpress(exinfo);
  5699. }
  5700. //不处理
  5701. }
  5702. else
  5703. {
  5704. entity.UpdateTime = DateTime.Now;
  5705. entity.LastBillCpCode = cpCode;
  5706. entity.LastBillWaybillCode = curUseWayBillCode;
  5707. entity.Update();
  5708. string errmsg = commonHelper.KeepChinese(apires);
  5709. var res_objz = new
  5710. {
  5711. restype = 0,
  5712. data = "打单后发货失败"
  5713. };
  5714. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5715. returnSuccess(ro_jsonz);
  5716. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5717. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5718. return;
  5719. }
  5720. }
  5721. }
  5722. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5723. {
  5724. string ctids = GetPostString("ctids");
  5725. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5726. List<string> list = new List<string>();
  5727. List<string> send_list = new List<string>();
  5728. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5729. CeErpTrade ceErpTrade = new CeErpTrade();
  5730. //可合包的合并一起发货
  5731. if (dt == null && string.IsNullOrEmpty(ctids))
  5732. {
  5733. var res_objz = new
  5734. {
  5735. restype = 0,
  5736. data = "打单后发货失败"
  5737. };
  5738. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5739. returnSuccess(ro_jsonz);
  5740. return;
  5741. }
  5742. if (!string.IsNullOrEmpty(ctids))
  5743. {
  5744. StringBuilder sql = new StringBuilder();
  5745. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5746. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5747. }
  5748. foreach (DataRow row in dt.Rows)
  5749. {
  5750. list.Add("'" + row["ctid"] + "'");
  5751. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5752. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5753. if (ctid.IndexOf("N") != -1)
  5754. {
  5755. apires = "发货成功";
  5756. }
  5757. else
  5758. {
  5759. if (!send_list.Contains(ceErpTrade.tid))
  5760. {
  5761. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5762. }
  5763. else
  5764. {
  5765. apires = "发货成功";
  5766. }
  5767. }
  5768. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5769. {
  5770. send_list.Add(ceErpTrade.tid);
  5771. try
  5772. {
  5773. btnType = "待发货";
  5774. ceErpTradeCell.OutSid = curUseWayBillCode;
  5775. ceErpTradeCell.OrderState = 7;
  5776. ceErpTradeCell.IsUrgency = false;
  5777. ceErpTradeCell.LastBillCpCode = "";
  5778. ceErpTradeCell.LastBillWaybillCode = "";
  5779. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5780. ceErpTradeCell.IsReturn = 0;
  5781. ceErpTradeCell.MemoOpt = 0;
  5782. ceErpTradeCell.UpdateTime = DateTime.Now;
  5783. ceErpTradeCell.Update();
  5784. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5785. //还要插入快递信息到 快递信息表
  5786. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5787. exinfo.tid = ceErpTradeCell.ctid;
  5788. exinfo.out_sid = curUseWayBillCode;
  5789. exinfo.company_code = cpCode;
  5790. exinfo.company_name = cpName;
  5791. exinfo.supplierUserName = supplierName;
  5792. exinfo.deliveryType = "发货成功";
  5793. exinfo.print_time = DateTime.Now;
  5794. exinfo.printUser = CurrentUser.UserName;
  5795. exinfo.postData = pData_str;
  5796. exinfo.Create();
  5797. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5798. CeErpSukuraData.createInfo(ctid, 4);
  5799. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5800. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80)
  5801. {
  5802. commonHelper.sendCytExpress(exinfo);
  5803. }
  5804. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5805. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5806. }
  5807. catch (Exception ex)
  5808. {
  5809. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5810. }
  5811. }
  5812. else
  5813. {
  5814. ceErpTradeCell.UpdateTime = DateTime.Now;
  5815. ceErpTradeCell.LastBillCpCode = cpCode;
  5816. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5817. ceErpTradeCell.Update();
  5818. string errmsg = commonHelper.KeepChinese(apires);
  5819. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5820. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5821. }
  5822. }
  5823. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5824. }
  5825. }
  5826. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5827. var res_obj = new
  5828. {
  5829. restype = 1,
  5830. data = pData_str,
  5831. errorMsg
  5832. };
  5833. string ro_json = JsonConvert.SerializeObject(res_obj);
  5834. ReturnSuccess(ro_json);
  5835. return;
  5836. }
  5837. }
  5838. private string GetUTF8String(byte[] vs)
  5839. {
  5840. throw new NotImplementedException();
  5841. }
  5842. public void set_erp_printwaybill_cn()
  5843. {
  5844. if (UrlPostParmsCheck("ctid"))
  5845. {
  5846. string ctid = GetPostString("ctid");
  5847. string cpCode = GetPostString("cpcode");
  5848. string cpName = GetPostString("cpname");
  5849. string tempUrl = GetPostString("tempurl");
  5850. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5851. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5852. //string res = taobaoHelper.test();
  5853. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5854. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5855. {
  5856. int sidx = res.IndexOf("errorMsg");
  5857. int eidx = res.IndexOf("}");
  5858. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5859. var res_objzxx = new
  5860. {
  5861. restype = 0,
  5862. data = msg
  5863. };
  5864. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5865. returnSuccess(ro_jsonzxx);
  5866. //returnErrorMsg(msg);
  5867. return;
  5868. }
  5869. int idx = res.IndexOf("waybillCode");
  5870. int idx2 = res.IndexOf("printData");
  5871. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5872. string eid = GetPostString("ctid");
  5873. CeErpTradeCell entity = null;
  5874. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5875. if (entity != null)
  5876. {
  5877. string osid = entity.OutSid;
  5878. entity.OutSid = osid + "," + outsid;
  5879. entity.FinishDeliveryTime = DateTime.Now;
  5880. entity.OrderState = 7;
  5881. entity.UpdateTime = DateTime.Now;
  5882. entity.IsReturn = 0;
  5883. entity.Update();
  5884. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5885. exinfo.tid = entity.ctid;
  5886. exinfo.out_sid = outsid;
  5887. exinfo.company_code = cpCode;
  5888. exinfo.company_name = cpName;
  5889. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5890. exinfo.deliveryType = "发货成功";
  5891. exinfo.print_time = DateTime.Now;
  5892. exinfo.printUser = CurrentUser.UserName;
  5893. exinfo.Create();
  5894. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5895. {
  5896. commonHelper.sendCytExpress(exinfo);
  5897. }
  5898. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5899. }
  5900. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5901. var res_objz = new
  5902. {
  5903. restype = 1,
  5904. data = res
  5905. };
  5906. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5907. returnSuccess(ro_jsonz);
  5908. //ReturnSuccess(res);
  5909. }
  5910. }
  5911. ////打单,打印面单 获取面单号
  5912. //public void set_erp_printwaybill()
  5913. //{
  5914. // if (UrlPostParmsCheck("ctid"))
  5915. // {
  5916. // string ctid = GetPostString("ctid");
  5917. // string cpCode = GetPostString("cpcode");
  5918. // string tempUrl = GetPostString("tempurl");
  5919. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5920. // //string res = taobaoHelper.test();
  5921. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5922. // if (res.IndexOf("error_response") != -1)
  5923. // {
  5924. // int sidx = res.IndexOf("sub_msg");
  5925. // int eidx = res.IndexOf("request_id");
  5926. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5927. // returnErrorMsg(msg);
  5928. // return;
  5929. // }
  5930. // int idx = res.IndexOf("waybill_code");
  5931. // int idx2 = res.IndexOf("}]}");
  5932. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5933. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5934. // ReturnSuccess(res);
  5935. // }
  5936. //}
  5937. public void cancel_erp_aftersale()
  5938. {
  5939. if (UrlPostParmsCheck("ctid"))
  5940. {
  5941. string eid = GetPostString("ctid");
  5942. CeErpTradeCell entity = null;
  5943. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5944. if (entity != null)
  5945. {
  5946. //有过处理的售后,取消也不能删除 售 字,保留
  5947. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5948. {
  5949. entity.AfterSaleState = 4;
  5950. }
  5951. else
  5952. entity.AfterSaleState = 0;
  5953. entity.UpdateTime = DateTime.Now;
  5954. entity.Update();
  5955. returnSuccessMsg("操作成功!");
  5956. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5957. return;
  5958. }
  5959. returnErrorMsg("找不到订单记录");
  5960. }
  5961. }
  5962. public void get_erp_aftersalelist()
  5963. {
  5964. DataStruct dStruct = GetPostStruct();
  5965. List<string> lw = new List<string>();
  5966. int st = GetInt("st");
  5967. string tid = GetPostString("ctid");
  5968. if (st == 3)
  5969. {
  5970. if (tid.Length > 0)
  5971. {
  5972. string select_tid = getTidByCtid(tid);
  5973. lw.Add(string.Format("tid='{0}'", select_tid));
  5974. }
  5975. }
  5976. else
  5977. {
  5978. if (tid.Length > 0)
  5979. {
  5980. string select_tid = getTidByCtid(tid);
  5981. lw.Add(string.Format("tid='{0}'", select_tid));
  5982. }
  5983. }
  5984. string shopname = GetPostString("shopname");
  5985. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5986. string buyernick = GetPostString("buyer_nick");
  5987. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5988. string sellermemo = GetPostString("seller_memo");
  5989. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5990. string orderState = GetPostString("orderState");
  5991. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5992. string afterState = GetPostString("afterstate");
  5993. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5994. string date1 = GetPostString("date1");
  5995. string date2 = GetPostString("date2");
  5996. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5997. if (dw.Length > 0) lw.Add(dw);
  5998. string price1 = GetPostString("price1");
  5999. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6000. string price2 = GetPostString("price2");
  6001. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6002. //lw.Add(string.Format("IsRefund!={0}", 1));
  6003. string reason = GetPostString("reason");
  6004. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6005. string method = GetPostString("method");
  6006. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6007. string handler = GetPostString("handler");
  6008. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6009. string handledate1 = GetPostString("handledate1");
  6010. string handledate2 = GetPostString("handledate2");
  6011. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6012. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6013. string finish1 = GetPostString("finishdate1");
  6014. string finish2 = GetPostString("finishdate2");
  6015. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6016. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6017. string afterdate1 = GetPostString("afterdate1");
  6018. string afterdate2 = GetPostString("afterdate2");
  6019. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6020. if (afterDate.Length > 0) lw.Add(afterDate);
  6021. string supplier = GetPostString("supplier");
  6022. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6023. string responsible = GetPostString("responsibleman");
  6024. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6025. string customer = GetPostString("customer");
  6026. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6027. string design = GetPostString("design");
  6028. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6029. string afterMemoType = GetPostString("aftermemotype");
  6030. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6031. string posCode = CurrentUser.UserPost.Post.Code;
  6032. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6033. //{
  6034. // string vstate = GetPostString("vstate");
  6035. // if (vstate.Length > 0)
  6036. // {
  6037. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6038. // }
  6039. // if (posCode == "Supplier")
  6040. // {
  6041. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6042. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6043. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6044. // }
  6045. // else
  6046. // {
  6047. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6048. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6049. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6050. // {
  6051. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6052. // }
  6053. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6054. // {
  6055. // int orgid = CurrentUser.UserPost.OrgID;
  6056. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6057. // }
  6058. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6059. // {
  6060. // string shopid = CurrentUser.User.pemShop;
  6061. // lw.Add(string.Format("shopId in ({0})", shopid));
  6062. // }
  6063. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6064. // //{
  6065. // // int org_id = CurrentUser.UserPost.OrgID;
  6066. // // lw.Add(string.Format("OrgID={0}", org_id));
  6067. // //}
  6068. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6069. // }
  6070. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6071. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6072. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6073. //}
  6074. if (st == 5)
  6075. {
  6076. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6077. {
  6078. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6079. {
  6080. string shopid = CurrentUser.User.pemShop;
  6081. lw.Add(string.Format("shopId in ({0})", shopid));
  6082. }
  6083. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6084. {
  6085. int mrOrgid = CurrentUser.UserPost.OrgID;
  6086. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6087. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6088. }
  6089. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6090. //{
  6091. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6092. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6093. //}
  6094. else
  6095. {
  6096. string userIdStr = "";
  6097. if (posCode == "CustomerService")
  6098. {
  6099. userIdStr = CurrentUser.UserID + "_k";
  6100. }
  6101. else if (posCode == "Designer" || posCode == "wxDesigner")
  6102. {
  6103. userIdStr = CurrentUser.UserID + "_s";
  6104. }
  6105. else if (posCode == "Place")
  6106. {
  6107. userIdStr = CurrentUser.UserID + "_x";
  6108. }
  6109. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6110. }
  6111. }
  6112. string placedate1 = GetPostString("placedate1");
  6113. string placedate2 = GetPostString("placedate2");
  6114. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6115. if (dwplace.Length > 0) lw.Add(dwplace);
  6116. string supState = GetPostString("supState");
  6117. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6118. string searchType = GetPostString("searchType");
  6119. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6120. {
  6121. lw.Add(string.Format("BackNum>1"));
  6122. }
  6123. lw.Add(string.Format("AfterSaleState>0"));
  6124. if (ex_psize > 0)
  6125. {
  6126. if (CurrentUser.UserPost.Post.Code == "Finance")
  6127. dStruct.Order = "pay_time desc";
  6128. else
  6129. dStruct.Order = "HandleTime desc";
  6130. }
  6131. else
  6132. dStruct.Order = "HandleTime desc";
  6133. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6134. DataTable dt = WebCache.GetData("view_test", dStruct);
  6135. writeGridDataTableJson(dStruct.TotalCount, dt);
  6136. }
  6137. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6138. //{
  6139. // lw.Add(string.Format("AfterSaleState=4"));
  6140. // string code = CurrentUser.UserPost.Post.Code;
  6141. // if (code == "CustomerService")
  6142. // {
  6143. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6144. // }
  6145. // else if (code == "Designer" || code == "DesignerMr")
  6146. // {
  6147. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6148. // }
  6149. // else if (code == "Place" || code == "PlaceMr")
  6150. // {
  6151. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6152. // }
  6153. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6154. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6155. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6156. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6157. //}
  6158. //else //处理中的售后,待处理和处理中合并
  6159. //{
  6160. // if (afterState.Length <= 0)
  6161. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6162. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6163. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6164. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6165. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6166. //}
  6167. }
  6168. public void get_erp_disagreeftersalelist()
  6169. {
  6170. DataStruct dStruct = GetPostStruct();
  6171. List<string> lw = new List<string>();
  6172. int st = 2;
  6173. string tid = GetPostString("ctid");
  6174. if (tid.Length > 0)
  6175. {
  6176. string select_tid = getTidByCtid(tid);
  6177. lw.Add(string.Format("tid='{0}'", select_tid));
  6178. }
  6179. string shopname = GetPostString("shopname");
  6180. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6181. string buyernick = GetPostString("buyer_nick");
  6182. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6183. string sellermemo = GetPostString("seller_memo");
  6184. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6185. string orderState = GetPostString("orderState");
  6186. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6187. string afterState = GetPostString("afterstate");
  6188. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6189. string date1 = GetPostString("date1");
  6190. string date2 = GetPostString("date2");
  6191. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6192. if (dw.Length > 0) lw.Add(dw);
  6193. string price1 = GetPostString("price1");
  6194. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6195. string price2 = GetPostString("price2");
  6196. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6197. //lw.Add(string.Format("IsRefund!={0}", 1));
  6198. string reason = GetPostString("reason");
  6199. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6200. string method = GetPostString("method");
  6201. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6202. string handler = GetPostString("handler");
  6203. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6204. string handledate1 = GetPostString("handledate1");
  6205. string handledate2 = GetPostString("handledate2");
  6206. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6207. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6208. string afterdate1 = GetPostString("afterdate1");
  6209. string afterdate2 = GetPostString("afterdate2");
  6210. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6211. if (afterDate.Length > 0) lw.Add(afterDate);
  6212. string backdate1 = GetPostString("backdate1");
  6213. string backdate2 = GetPostString("backdate2");
  6214. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6215. if (backDate.Length > 0) lw.Add(backDate);
  6216. string supplier = GetPostString("supplier");
  6217. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6218. string responsible = GetPostString("responsibleman");
  6219. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6220. string customer = GetPostString("customer");
  6221. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6222. string design = GetPostString("design");
  6223. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6224. string afterSaleMemo = GetPostString("afterSaleMemo");
  6225. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6226. string afterMemoType = GetPostString("aftermemotype");
  6227. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6228. string aftersakereason = GetPostString("aftersakereason");
  6229. if (aftersakereason.Length > 0)
  6230. {
  6231. if (aftersakereason == "1")
  6232. {
  6233. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6234. }
  6235. if (aftersakereason == "2")
  6236. {
  6237. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6238. }
  6239. }
  6240. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6241. string poscode = CurrentUser.UserPost.Post.Code;
  6242. if (poscode != "SysAdmin")
  6243. {
  6244. string shopid = CurrentUser.User.pemShop;
  6245. lw.Add(string.Format("shopId in ({0})", shopid));
  6246. }
  6247. string searchType = GetPostString("searchType");
  6248. if (searchType == "wait")
  6249. {
  6250. lw.Add(string.Format("HandleTime is null"));
  6251. }
  6252. if (searchType == "handling")
  6253. {
  6254. lw.Add(string.Format("HandleTime is not null "));
  6255. }
  6256. if (searchType == "back" || searchType == "puBack")
  6257. {
  6258. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6259. }
  6260. if (searchType == "reBack")
  6261. {
  6262. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6263. }
  6264. if (searchType == "moreBack")
  6265. {
  6266. lw.Add(string.Format("backNum > 1"));
  6267. }
  6268. lw.Add(string.Format("(AfterSaleState=5)"));
  6269. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6270. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6271. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6272. writeGridDataTableJson(dStruct.TotalCount, dt);
  6273. }
  6274. public void get_erp_handlingaftersalelist()
  6275. {
  6276. DataStruct dStruct = GetPostStruct();
  6277. List<string> lw = new List<string>();
  6278. int st = 2;
  6279. string tid = GetPostString("ctid");
  6280. if (tid.Length > 0)
  6281. {
  6282. string select_tid = getTidByCtid(tid);
  6283. lw.Add(string.Format("tid='{0}'", select_tid));
  6284. }
  6285. string shopname = GetPostString("shopname");
  6286. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6287. string buyernick = GetPostString("buyer_nick");
  6288. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6289. string sellermemo = GetPostString("seller_memo");
  6290. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6291. string orderState = GetPostString("orderState");
  6292. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6293. string afterState = GetPostString("afterstate");
  6294. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6295. string date1 = GetPostString("date1");
  6296. string date2 = GetPostString("date2");
  6297. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6298. if (dw.Length > 0) lw.Add(dw);
  6299. string price1 = GetPostString("price1");
  6300. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6301. string price2 = GetPostString("price2");
  6302. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6303. //lw.Add(string.Format("IsRefund!={0}", 1));
  6304. string reason = GetPostString("reason");
  6305. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6306. string method = GetPostString("method");
  6307. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6308. string handler = GetPostString("handler");
  6309. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6310. string handledate1 = GetPostString("handledate1");
  6311. string handledate2 = GetPostString("handledate2");
  6312. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6313. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6314. string afterdate1 = GetPostString("afterdate1");
  6315. string afterdate2 = GetPostString("afterdate2");
  6316. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6317. if (afterDate.Length > 0) lw.Add(afterDate);
  6318. string supplier = GetPostString("supplier");
  6319. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6320. string responsible = GetPostString("responsibleman");
  6321. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6322. string customer = GetPostString("customer");
  6323. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6324. string design = GetPostString("design");
  6325. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6326. string afterSaleMemo = GetPostString("afterSaleMemo");
  6327. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6328. string afterMemoType = GetPostString("aftermemotype");
  6329. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6330. string afterresult = GetPostString("afterresult");
  6331. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6332. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6333. string poscode = CurrentUser.UserPost.Post.Code;
  6334. if (poscode != "SysAdmin")
  6335. {
  6336. string shopid = CurrentUser.User.pemShop;
  6337. lw.Add(string.Format("shopId in ({0})", shopid));
  6338. }
  6339. string searchType = GetPostString("searchType");
  6340. if (searchType == "wait")
  6341. {
  6342. lw.Add(string.Format("HandleTime is null"));
  6343. }
  6344. if (searchType == "documentary")
  6345. {
  6346. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6347. }
  6348. if (searchType == "handling")
  6349. {
  6350. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6351. }
  6352. if (searchType == "back" || searchType == "puBack")
  6353. {
  6354. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6355. }
  6356. if (searchType == "reBack")
  6357. {
  6358. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6359. }
  6360. if (afterState.Length <= 0)
  6361. {
  6362. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6363. }
  6364. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6365. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6366. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6367. writeGridDataTableJson(dStruct.TotalCount, dt);
  6368. }
  6369. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6370. //public void get_erp_back_handlingaftersalelist()
  6371. //{
  6372. // DataStruct dStruct = GetPostStruct();
  6373. // List<string> lw = new List<string>();
  6374. // string tid = GetPostString("ctid");
  6375. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6376. // string shopname = GetPostString("shopname");
  6377. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6378. // string buyernick = GetPostString("buyer_nick");
  6379. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6380. // string sellermemo = GetPostString("seller_memo");
  6381. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6382. // string orderState = GetPostString("orderState");
  6383. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6384. // string afterState = GetPostString("afterstate");
  6385. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6386. // string date1 = GetPostString("date1");
  6387. // string date2 = GetPostString("date2");
  6388. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6389. // if (dw.Length > 0) lw.Add(dw);
  6390. // string price1 = GetPostString("price1");
  6391. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6392. // string price2 = GetPostString("price2");
  6393. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6394. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6395. // string reason = GetPostString("reason");
  6396. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6397. // string method = GetPostString("method");
  6398. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6399. // string handler = GetPostString("handler");
  6400. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6401. // string handledate1 = GetPostString("handledate1");
  6402. // string handledate2 = GetPostString("handledate2");
  6403. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6404. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6405. // string afterdate1 = GetPostString("afterdate1");
  6406. // string afterdate2 = GetPostString("afterdate2");
  6407. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6408. // if (afterDate.Length > 0) lw.Add(afterDate);
  6409. // string supplier = GetPostString("supplier");
  6410. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6411. // string responsible = GetPostString("responsibleman");
  6412. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6413. // string customer = GetPostString("customer");
  6414. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6415. // string design = GetPostString("design");
  6416. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6417. // string afterMemoType = GetPostString("aftermemotype");
  6418. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6419. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6420. // if (afterState.Length <= 0)
  6421. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6422. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6423. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6424. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6425. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6426. //}
  6427. public void get_erp_aftersaleverifylist()
  6428. {
  6429. DataStruct dStruct = GetPostStruct();
  6430. List<string> lw = new List<string>();
  6431. string tid = GetPostString("ctid");
  6432. if (tid.Length > 0)
  6433. {
  6434. string select_tid = getTidByCtid(tid);
  6435. lw.Add(string.Format("otid='{0}'", select_tid));
  6436. }
  6437. string shopname = GetPostString("shopname");
  6438. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6439. string buyernick = GetPostString("buyer_nick");
  6440. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6441. string sellermemo = GetPostString("seller_memo");
  6442. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6443. string orderState = GetPostString("orderState");
  6444. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6445. //lw.Add(string.Format("IsRefund!={0}", 1));
  6446. string reason = GetPostString("reason");
  6447. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6448. string method = GetPostString("method");
  6449. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6450. string handler = GetPostString("handler");
  6451. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6452. string handledate1 = GetPostString("handledate1");
  6453. string handledate2 = GetPostString("handledate2");
  6454. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6455. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6456. string finish1 = GetPostString("finishdate1");
  6457. string finish2 = GetPostString("finishdate2");
  6458. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6459. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6460. string supplier = GetPostString("supplier");
  6461. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6462. string responsible = GetPostString("responsibleman");
  6463. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6464. string posCode = CurrentUser.UserPost.Post.Code;
  6465. string vstate = GetPostString("vstate");
  6466. if (vstate.Length > 0)
  6467. {
  6468. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6469. }
  6470. if (posCode == "Supplier")
  6471. {
  6472. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6473. lw.Add(string.Format("VerifyState = 0"));
  6474. lw.Add("type = 1");
  6475. lw.Add(string.Format("AfterSaleState={0}", 3));
  6476. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6477. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6478. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6479. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6480. writeGridDataTableJson(dStruct.TotalCount, dt);
  6481. }
  6482. else if (posCode == "logistics")
  6483. {
  6484. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6485. lw.Add(string.Format("VerifyState = 0"));
  6486. lw.Add("type = 2");
  6487. lw.Add(string.Format("AfterSaleState={0}", 3));
  6488. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6489. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6490. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6491. writeGridDataTableJson(dStruct.TotalCount, dt);
  6492. }
  6493. else
  6494. {
  6495. lw.Add(string.Format("(AfterSaleState = 3)"));
  6496. string reasonState = GetPostString("reasonState");
  6497. lw.Add("type = 0");
  6498. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6499. || posCode == "Summarize" || posCode == "Finance")
  6500. {
  6501. if (reasonState == "2")
  6502. {
  6503. lw.Add("VerifyState = 3");
  6504. }
  6505. else if (reasonState == "1")
  6506. {
  6507. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6508. }
  6509. else
  6510. {
  6511. lw.Add("VerifyState in (0,3)");
  6512. }
  6513. //不加条件,可以看全部
  6514. }
  6515. 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")
  6516. {
  6517. int orgid = CurrentUser.UserPost.OrgID;
  6518. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6519. if (string.IsNullOrEmpty(manageOrgId))
  6520. {
  6521. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6522. }
  6523. else
  6524. {
  6525. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6526. }
  6527. if (reasonState == "1")
  6528. {
  6529. lw.Add("VerifyState = 3");
  6530. }
  6531. else if (reasonState == "2")
  6532. {
  6533. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6534. }
  6535. else
  6536. {
  6537. }
  6538. }
  6539. else
  6540. {
  6541. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6542. }
  6543. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6544. //{
  6545. // int org_id = CurrentUser.UserPost.OrgID;
  6546. // lw.Add(string.Format("OrgID={0}", org_id));
  6547. //}
  6548. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6549. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6550. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6551. writeGridDataTableJson(dStruct.TotalCount, dt);
  6552. }
  6553. }
  6554. public void get_erp_finishaftersalelist()
  6555. {
  6556. DataStruct dStruct = GetPostStruct();
  6557. List<string> lw = new List<string>();
  6558. int st = 4;
  6559. string tid = GetPostString("ctid");
  6560. if (tid.Length > 0)
  6561. {
  6562. string select_tid = getTidByCtid(tid);
  6563. lw.Add(string.Format("otid='{0}'", select_tid));
  6564. }
  6565. string shopname = GetPostString("shopname");
  6566. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6567. //lw.Add(string.Format("IsRefund!={0}", 1));
  6568. string reason = GetPostString("reason");
  6569. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6570. string method = GetPostString("method");
  6571. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6572. string buyernick = GetPostString("buyer_nick");
  6573. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6574. string handler = GetPostString("handler");
  6575. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6576. string handledate1 = GetPostString("handledate1");
  6577. string handledate2 = GetPostString("handledate2");
  6578. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6579. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6580. string finish1 = GetPostString("finishdate1");
  6581. string finish2 = GetPostString("finishdate2");
  6582. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6583. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6584. string supplier = GetPostString("supplier");
  6585. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6586. string responsible = GetPostString("responsibleman");
  6587. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6588. string vstate = GetPostString("vstate");
  6589. if (vstate.Length > 0)
  6590. {
  6591. if ("3".Equals(vstate))
  6592. {
  6593. lw.Add(string.Format("IsTem=1"));
  6594. }
  6595. else
  6596. {
  6597. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6598. }
  6599. }
  6600. lw.Add(string.Format("AfterSaleState=4"));
  6601. string code = CurrentUser.UserPost.Post.Code;
  6602. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6603. {
  6604. //不加条件,可以看全部
  6605. }
  6606. else if (code == "Supplier")
  6607. {
  6608. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6609. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6610. lw.Add("type = 1");
  6611. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6612. }
  6613. else if (code == "logistics")
  6614. {
  6615. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6616. lw.Add("type = 2");
  6617. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6618. }
  6619. 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")
  6620. {
  6621. lw.Add("type = 0");
  6622. int orgid = CurrentUser.UserPost.OrgID;
  6623. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6624. if (string.IsNullOrEmpty(manageOrgIds))
  6625. {
  6626. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6627. }
  6628. else
  6629. {
  6630. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6631. }
  6632. }
  6633. else
  6634. {
  6635. lw.Add("type = 0");
  6636. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6637. }
  6638. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6639. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6640. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6641. writeGridDataTableJson(dStruct.TotalCount, dt);
  6642. }
  6643. public void handle_erp_aftersale()
  6644. {
  6645. if (UrlPostParmsCheck("ctid"))
  6646. {
  6647. string eid = GetPostString("ctid");
  6648. string responStr = GetPostString("AfterSaleResponsible");
  6649. if (responStr.Length <= 0)
  6650. {
  6651. returnErrorMsg("售后责任人不能为空");
  6652. return;
  6653. }
  6654. bool isDesign = false;
  6655. double designFree = 0.00;
  6656. int responsibleId = 0;
  6657. CeErpTradeCell entity = null;
  6658. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6659. if (entity != null)
  6660. {
  6661. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6662. string afterMethod = GetPostString("AfterSaleMethod");
  6663. if (isNeedNewOrder == 1)
  6664. {
  6665. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6666. bool ishav = true;
  6667. if (newentity == null)
  6668. {
  6669. newentity = entity.Clone() as CeErpTradeCell;
  6670. ishav = false;
  6671. newentity.ctid = "S_" + entity.ctid;
  6672. newentity.OrderState = 0;
  6673. //唯一标识
  6674. newentity.OrderSn = newentity.ctid;
  6675. string orderSn = dataHelper.getSaleOrderSn();
  6676. if (orderSn != "")
  6677. {
  6678. newentity.OrderSn = orderSn;
  6679. }
  6680. }
  6681. newentity.UpdateTime = DateTime.Now;
  6682. newentity.AfterSaleState = 0;
  6683. newentity.AfterSaleMethod = afterMethod;
  6684. if (!ishav)
  6685. {
  6686. string memo_str = newentity.seller_memo;
  6687. memo_str = memo_str.Replace("(", "(");
  6688. memo_str = memo_str.Replace(")", ")");
  6689. int sIndex = memo_str.IndexOf("(");
  6690. int eIndex = memo_str.IndexOf(")");
  6691. if (sIndex == -1 || eIndex == -1)
  6692. {
  6693. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6694. return;
  6695. }
  6696. string first = memo_str.Substring(0, sIndex + 1);
  6697. string memoCtid = newentity.OrderSn;
  6698. //if (memoCtid.IndexOf("C") != -1)
  6699. //{
  6700. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6701. //if (CIdx.IndexOf("+") != -1)
  6702. //{
  6703. //CIdx = "C" + CIdx.Split('+')[1];
  6704. //}
  6705. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6706. //}
  6707. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6708. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6709. string newMemo = first + memoCtid + last;
  6710. newentity.seller_memo = newMemo;
  6711. newentity.FinishPlaceTime = null;
  6712. newentity.UnusualTag = 0;
  6713. newentity.UnusualCon = "";
  6714. newentity.UnusualTime = null;
  6715. newentity.AfterSaleMemo = "";
  6716. newentity.AfterSaleMethod = afterMethod;
  6717. newentity.AfterSalePreTime = null;
  6718. newentity.AfterSaleReason = "";
  6719. newentity.AfterSaleResponsible = "";
  6720. newentity.AfterSaleState = 0;
  6721. newentity.AfterSaleTime = null;
  6722. newentity.AfterSaleUserId = 0;
  6723. newentity.AfterSaleSupplierState = 0;
  6724. newentity.LastBillWaybillCode = "";
  6725. newentity.LastBillCpCode = "";
  6726. newentity.FinishAfterSaleTime = null;
  6727. newentity.HandleTime = null;
  6728. newentity.IsSF = 0;
  6729. newentity.IsOldCustomer = 0;
  6730. newentity.UrgencyTime = null;
  6731. newentity.ResponsibleUserId = "";
  6732. newentity.IsVerifyToSupplier = false;
  6733. newentity.payment = 0;
  6734. newentity.CheckMemo = "";
  6735. newentity.OutSid = "";
  6736. newentity.CheckOrderTime = null;
  6737. newentity.MemoOpt = 0;
  6738. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6739. }
  6740. newentity.isAfterSaleOrder = 1;
  6741. newentity.IsRefund = 0;
  6742. string receiveMobile = GetPostString("receiver_mobile");
  6743. if (receiveMobile.Length > 0)
  6744. {
  6745. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6746. if (trade != null)
  6747. {
  6748. trade.receiver_name = GetPostString("receiver_name");
  6749. trade.receiver_mobile = receiveMobile;
  6750. trade.receiver_state = GetPostString("receiver_state");
  6751. trade.receiver_city = GetPostString("receiver_city");
  6752. trade.receiver_district = GetPostString("receiver_district");
  6753. trade.receiver_address = GetPostString("receiver_address");
  6754. newentity.IsOffLineOrder = 1;
  6755. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6756. }
  6757. }
  6758. string st = GetPostString("ToState");
  6759. if (st.Length > 0)
  6760. {
  6761. if (newentity.OrderState <= 3)
  6762. {
  6763. newentity.WaitDesignTime = DateTime.Now;
  6764. newentity.StartDesignTime = null;
  6765. newentity.FinishDesignTime = null;
  6766. newentity.OrderState = 3;
  6767. if (st == "下单员")
  6768. {
  6769. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6770. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6771. {
  6772. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6773. }
  6774. }
  6775. else
  6776. {
  6777. newentity.WaitDesignTime = DateTime.Now;
  6778. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6779. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6780. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6781. {
  6782. DataRow user = dt1.Rows[0];
  6783. //找主管
  6784. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6785. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6786. if (dt != null && dt.Rows.Count > 0)
  6787. {
  6788. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6789. newentity.DesignUserId = designMr;
  6790. string key = "aftersale_order_" + designMr;
  6791. if (RedisHelper.HasKey(key))
  6792. {
  6793. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6794. list.Add(newentity.ctid);
  6795. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6796. }
  6797. }
  6798. //账号正常
  6799. if (user["State"].ToString() == "0")
  6800. {
  6801. newentity.DesignUserId = entity.DesignUserId;
  6802. string key = "aftersale_order_" + entity.DesignUserId;
  6803. if (RedisHelper.HasKey(key))
  6804. {
  6805. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6806. list.Add(newentity.ctid);
  6807. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6808. }
  6809. }
  6810. }
  6811. }
  6812. }
  6813. if (entity.IsXianHuo == 1)
  6814. {
  6815. newentity.OrderState = 6;
  6816. entity.FinishPlaceTime = DateTime.Now;
  6817. }
  6818. }
  6819. if (ishav)
  6820. {
  6821. newentity.Update();
  6822. }
  6823. else
  6824. {
  6825. newentity.Create();
  6826. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6827. newCellExtend.ctid = newentity.ctid;
  6828. newCellExtend.orderFrom = 20;
  6829. newCellExtend.orderType = 30;
  6830. if (st == "下单员")
  6831. {
  6832. }
  6833. else
  6834. {
  6835. newCellExtend.ReprintTime = DateTime.Now;
  6836. }
  6837. newCellExtend.Create();
  6838. }
  6839. if (st != "下单员")
  6840. {
  6841. if (entity.DispatchSort == 2)
  6842. {
  6843. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6844. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6845. }
  6846. }
  6847. }
  6848. //处理售后扩展
  6849. string resIdStr = GetPostString("ResponsibleUserId");
  6850. string refundFees = GetPostString("refundFrees");
  6851. int IsComplain = GetPostInt("isComplain");
  6852. int IsBad = GetPostInt("isBad");
  6853. string IsOriginal = GetPostString("isOriginal");
  6854. double diffResultPrice = GetPostDouble("diffResultPrice");
  6855. string textResult = GetPostString("textResult");
  6856. string supplierResponsible = GetPostString("supplierResponsible");
  6857. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6858. if (ceErpTradeAfterSaleExtend == null)
  6859. {
  6860. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6861. ceErpTradeAfterSaleExtend.tid = eid;
  6862. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6863. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6864. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6865. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6866. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6867. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6868. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6869. ceErpTradeAfterSaleExtend.Create();
  6870. }
  6871. else
  6872. {
  6873. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6874. {
  6875. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6876. }
  6877. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6878. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6879. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6880. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6881. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6882. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6883. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6884. ceErpTradeAfterSaleExtend.Update();
  6885. }
  6886. int gysid = GetPostInt("ResponsibleSupId");
  6887. if (entity.AfterSaleUserId == 0)
  6888. {
  6889. entity.AfterSaleUserId = CurrentUser.UserID;
  6890. }
  6891. entity.ResponsibleUserId = resIdStr;
  6892. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6893. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6894. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6895. {
  6896. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6897. int backNum = 0;
  6898. if (number != null)
  6899. {
  6900. backNum = number.BackNum;
  6901. }
  6902. char[] separator = { ',' };
  6903. string[] sArray = resIdStr.Split(separator);
  6904. string[] refundFreeList = { };
  6905. if (refundFees.Length > 0)
  6906. {
  6907. refundFreeList = refundFees.Split(separator);
  6908. }
  6909. int index = -1;
  6910. List<int> responsibleIds = new List<int>();
  6911. foreach (string i in sArray)
  6912. {
  6913. index++;
  6914. if (i.Length <= 0) continue;
  6915. char[] separator2 = { '_' };
  6916. string idstr = i.Split(separator2)[0];
  6917. string idtype = i.Split(separator2)[1];
  6918. double refudFree = 0;
  6919. if (refundFreeList.Length > 0)
  6920. {
  6921. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6922. }
  6923. if (idtype == "s")
  6924. {
  6925. isDesign = true;
  6926. designFree = refudFree;
  6927. }
  6928. int userId = Convert.ToInt32(idstr);
  6929. int type = 0;
  6930. if (idtype == "g")
  6931. {
  6932. type = 1;
  6933. }
  6934. if (idtype == "w")
  6935. {
  6936. type = 2;
  6937. }
  6938. if (idtype == "t")
  6939. {
  6940. type = 3;
  6941. }
  6942. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6943. if (ceErpTradeResponsible == null)
  6944. {
  6945. ceErpTradeResponsible = new CeErpTradeResponsible();
  6946. ceErpTradeResponsible.tid = eid;
  6947. ceErpTradeResponsible.UserId = userId;
  6948. ceErpTradeResponsible.createdTime = DateTime.Now;
  6949. ceErpTradeResponsible.type = type;
  6950. if (type == 1)
  6951. {
  6952. ceErpTradeResponsible.IsSup = 1;
  6953. }
  6954. if (type == 2)
  6955. {
  6956. ceErpTradeResponsible.IsFlow = 1;
  6957. }
  6958. }
  6959. int state = 0;
  6960. //已认可的不需要再次认可
  6961. if (ceErpTradeResponsible.VerifyState == 1)
  6962. {
  6963. state = 1;
  6964. }
  6965. ceErpTradeResponsible.RefundFee = refudFree;
  6966. ceErpTradeResponsible.VerifyState = state;
  6967. if (userId == 2125 || idtype == "w")
  6968. {
  6969. ceErpTradeResponsible.VerifyState = 1;
  6970. }
  6971. if (idtype == "w" && userId == 101)
  6972. {
  6973. ceErpTradeResponsible.VerifyState = state;
  6974. }
  6975. if (ceErpTradeResponsible.ID > 0)
  6976. {
  6977. ceErpTradeResponsible.Update();
  6978. }
  6979. else
  6980. {
  6981. ceErpTradeResponsible.Create();
  6982. }
  6983. if (isDesign)
  6984. {
  6985. responsibleId = ceErpTradeResponsible.ID;
  6986. }
  6987. responsibleIds.Add(responsibleId);
  6988. }
  6989. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  6990. CeErpTradeResponsible.NumByTid(backNum, eid);
  6991. }
  6992. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6993. if (ceErpTradeCellExtend != null)
  6994. {
  6995. ceErpTradeCellExtend.returnVisit = 0;
  6996. ceErpTradeCellExtend.Update();
  6997. }
  6998. if (entity.HandleTime != null)
  6999. {
  7000. if (entity.AfterSaleState == 1)
  7001. {
  7002. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7003. }
  7004. else
  7005. {
  7006. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7007. }
  7008. }
  7009. else
  7010. {
  7011. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7012. entity.HandleTime = DateTime.Now;
  7013. }
  7014. bool isCompale = false;
  7015. if (entity.AfterSaleState == 5)
  7016. {
  7017. isCompale = true;
  7018. entity.AfterSaleState = 3;
  7019. }
  7020. entity.AfterSaleSupplierState = 0;
  7021. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7022. {
  7023. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7024. }
  7025. string sImgs = GetPostString("img");
  7026. entity.AfterSaleSupplierImg = sImgs;
  7027. entity.supRefundType = GetPostString("supRefundType");
  7028. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7029. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7030. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7031. entity.AfterSaleMemoType = GetPostString("MemoType");
  7032. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7033. {
  7034. //entity.AfterSaleSupplierState = 2;
  7035. }
  7036. string df = GetPostString("DeductFee");
  7037. if (df == "")
  7038. {
  7039. df = "0";
  7040. }
  7041. string rf = GetPostString("RefundFee");
  7042. if (rf == "")
  7043. {
  7044. rf = "0";
  7045. }
  7046. string pm = GetPostString("AfterSalePayment");
  7047. if (pm == "")
  7048. {
  7049. pm = "0";
  7050. }
  7051. entity.AfterSalePayment = Convert.ToDouble(pm);
  7052. entity.DeductFee = Convert.ToDouble(df);
  7053. entity.RefundFee = Convert.ToDouble(rf);
  7054. entity.UpdateTime = DateTime.Now;
  7055. entity.Update();
  7056. string toState = GetPostString("ToState");
  7057. string original = GetPostString("isOriginal");
  7058. ApiVo apiVo = new ApiVo();
  7059. apiVo.orderNumber = entity.ctid;
  7060. apiVo.actionName = "afterDesign";
  7061. apiVo.orderRemarks = entity.AfterSaleMethod;
  7062. apiVo.reasonRemarks = entity.AfterSaleReason;
  7063. apiVo.isDesign = isDesign;
  7064. apiVo.designFree = designFree;
  7065. apiVo.responsibleId = responsibleId;
  7066. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7067. if (toState == "设计师")
  7068. {
  7069. apiVo.isOriginal = Convert.ToBoolean(original);
  7070. }
  7071. designHelper.API_WorkCore(apiVo);//afterDesign
  7072. CeErpMethod methodSql = new CeErpMethod();
  7073. methodSql.con = entity.AfterSaleMethod;
  7074. methodSql.addTime = DateTime.Now;
  7075. methodSql.Create();
  7076. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7077. CeErpMethod.ExecuteNonQuery(delsql);
  7078. if (isCompale)
  7079. {
  7080. aftersale_data_change(entity.ctid);
  7081. }
  7082. returnSuccessMsg("操作成功!");
  7083. return;
  7084. }
  7085. returnErrorMsg("找不到订单记录");
  7086. }
  7087. }
  7088. public void ins_erp_toresponsible()
  7089. {
  7090. if (UrlPostParmsCheck("ctid"))
  7091. {
  7092. string eid = GetPostString("ctid");
  7093. CeErpTradeCell entity = null;
  7094. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7095. if (entity != null)
  7096. {
  7097. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7098. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7099. {
  7100. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7101. return;
  7102. }
  7103. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7104. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7105. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7106. if (entity.AfterSalePreTime == null)
  7107. {
  7108. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7109. {
  7110. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7111. }
  7112. }
  7113. entity.AfterSalePreTime = DateTime.Now;
  7114. //预完成给售后主管审核客户问题直接完成
  7115. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7116. {
  7117. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7118. {
  7119. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7120. }
  7121. }
  7122. ceErpTradeAfterSaleExtend.Update();
  7123. entity.AfterSaleState = 2;
  7124. entity.UpdateTime = DateTime.Now;
  7125. entity.Update();
  7126. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7127. aftersale_data_change(entity.ctid);
  7128. returnSuccessMsg("操作成功!");
  7129. return;
  7130. }
  7131. returnErrorMsg("找不到订单记录");
  7132. }
  7133. }
  7134. public void cancel_erp_aftersaleanddelnew()
  7135. {
  7136. if (UrlPostParmsCheck("ctid"))
  7137. {
  7138. string eid = GetPostString("ctid");
  7139. CeErpTradeCell entity = null;
  7140. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7141. if (entity != null)
  7142. {
  7143. entity.AfterSaleState = 0;
  7144. entity.AfterSaleReason = "";
  7145. entity.AfterSaleMethod = "";
  7146. entity.AfterSaleMemo = "";
  7147. entity.AfterSaleResponsible = "";
  7148. entity.ResponsibleUserId = "";
  7149. entity.DeductFee = 0;
  7150. entity.RefundFee = 0;
  7151. entity.IsArbitrate = 0;
  7152. CeErpTradeResponsible.DelByTid(eid, -1);
  7153. entity.Update();
  7154. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7155. if (after != null)
  7156. {
  7157. if (after.OrderState < 5)
  7158. CeErpTradeCell.DelByCtid("S_" + eid);
  7159. }
  7160. returnSuccessMsg("操作成功!");
  7161. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7162. return;
  7163. }
  7164. returnErrorMsg("找不到订单记录");
  7165. }
  7166. }
  7167. public void get_erp_aftersale_pregather()
  7168. {
  7169. List<string> lw = new List<string>();
  7170. int st = GetInt("st");
  7171. string tid = GetPostString("ctid");
  7172. if (tid.Length > 0)
  7173. {
  7174. string select_tid = getTidByCtid(tid);
  7175. lw.Add(string.Format("tid='{0}'", select_tid));
  7176. }
  7177. string shopname = GetPostString("shopname");
  7178. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7179. string buyernick = GetPostString("buyer_nick");
  7180. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7181. string sellermemo = GetPostString("seller_memo");
  7182. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7183. string orderState = GetPostString("orderState");
  7184. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7185. string reason = GetPostString("reason");
  7186. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7187. string method = GetPostString("method");
  7188. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7189. string handler = GetPostString("handler");
  7190. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7191. string handledate1 = GetPostString("handledate1");
  7192. string handledate2 = GetPostString("handledate2");
  7193. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7194. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7195. string supplier = GetPostString("supplier");
  7196. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7197. string responsible = GetPostString("responsibleman");
  7198. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7199. string customer = GetPostString("customer");
  7200. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7201. string design = GetPostString("design");
  7202. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7203. string afterMemoType = GetPostString("aftermemotype");
  7204. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7205. string afterSaleMemo = GetPostString("afterSaleMemo");
  7206. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7207. string afterresult = GetPostString("afterresult");
  7208. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7209. string poscode = CurrentUser.UserPost.Post.Code;
  7210. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7211. {
  7212. string shopid = CurrentUser.User.pemShop;
  7213. lw.Add(string.Format("shopId in ({0})", shopid));
  7214. }
  7215. var mainwhere = string.Join(" and ", lw.ToArray());
  7216. string ro_json = "";
  7217. string type = GetPostString("gather_type");
  7218. int number = 0;
  7219. if (poscode == "AfterSale")
  7220. {
  7221. //处理中
  7222. if (type == "Handling")
  7223. {
  7224. 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) : ""));
  7225. DataTable dt = null;
  7226. try
  7227. {
  7228. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7229. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7230. }
  7231. catch (Exception e)
  7232. {
  7233. dt = new DataTable();
  7234. }
  7235. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7236. return;
  7237. }
  7238. if (type == "Wait")
  7239. {
  7240. //待处理
  7241. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7242. DataTable dt1 = null;
  7243. try
  7244. {
  7245. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7246. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7247. }
  7248. catch (Exception e)
  7249. {
  7250. dt1 = new DataTable();
  7251. }
  7252. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7253. return;
  7254. }
  7255. if (type == "back")
  7256. {
  7257. //打回
  7258. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7259. DataTable dt2 = null;
  7260. try
  7261. {
  7262. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7263. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7264. }
  7265. catch (Exception e)
  7266. {
  7267. dt2 = new DataTable();
  7268. }
  7269. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7270. return;
  7271. }
  7272. if (type == "preCompletion")
  7273. {
  7274. //预完成
  7275. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7276. DataTable dt3 = null;
  7277. try
  7278. {
  7279. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7280. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7281. }
  7282. catch (Exception e)
  7283. {
  7284. dt3 = new DataTable();
  7285. }
  7286. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7287. return;
  7288. }
  7289. if (type == "documentary")
  7290. {
  7291. //跟单中
  7292. 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) : ""));
  7293. DataTable dt4 = null;
  7294. try
  7295. {
  7296. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7297. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7298. }
  7299. catch (Exception e)
  7300. {
  7301. dt4 = new DataTable();
  7302. }
  7303. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7304. return;
  7305. }
  7306. if (type == "reBack")
  7307. {
  7308. //被打回
  7309. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7310. DataTable dt1 = null;
  7311. try
  7312. {
  7313. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7314. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7315. }
  7316. catch (Exception e)
  7317. {
  7318. dt1 = new DataTable();
  7319. }
  7320. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7321. return;
  7322. }
  7323. }
  7324. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7325. {
  7326. if (type == "puBack")
  7327. {
  7328. //退回
  7329. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7330. DataTable dt = null;
  7331. try
  7332. {
  7333. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7334. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7335. }
  7336. catch (Exception e)
  7337. {
  7338. dt = new DataTable();
  7339. }
  7340. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7341. return;
  7342. }
  7343. if (type == "reBack")
  7344. {
  7345. //打回
  7346. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7347. DataTable dt1 = null;
  7348. try
  7349. {
  7350. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7351. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7352. }
  7353. catch (Exception e)
  7354. {
  7355. dt1 = new DataTable();
  7356. }
  7357. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7358. return;
  7359. }
  7360. if (type == "examEd")
  7361. {
  7362. //已审核
  7363. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7364. DataTable dt2 = null;
  7365. try
  7366. {
  7367. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7368. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7369. }
  7370. catch (Exception e)
  7371. {
  7372. dt2 = new DataTable();
  7373. }
  7374. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7375. return;
  7376. }
  7377. if (type == "waitExam")
  7378. {
  7379. //待审核
  7380. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7381. DataTable dt3 = null;
  7382. try
  7383. {
  7384. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7385. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7386. }
  7387. catch (Exception e)
  7388. {
  7389. dt3 = new DataTable();
  7390. }
  7391. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7392. return;
  7393. }
  7394. if (type == "Handling")
  7395. {
  7396. //处理中
  7397. 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) : ""));
  7398. DataTable dt4 = null;
  7399. try
  7400. {
  7401. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7402. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7403. }
  7404. catch (Exception e)
  7405. {
  7406. dt4 = new DataTable();
  7407. }
  7408. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7409. return;
  7410. }
  7411. if (type == "Wait")
  7412. {
  7413. //待处理
  7414. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7415. DataTable dt5 = null;
  7416. try
  7417. {
  7418. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7419. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7420. }
  7421. catch (Exception e)
  7422. {
  7423. dt5 = new DataTable();
  7424. }
  7425. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7426. return;
  7427. }
  7428. if (type == "documentary")
  7429. {
  7430. //跟单中
  7431. 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) : ""));
  7432. DataTable dt6 = null;
  7433. try
  7434. {
  7435. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7436. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7437. }
  7438. catch (Exception e)
  7439. {
  7440. dt6 = new DataTable();
  7441. }
  7442. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7443. return;
  7444. }
  7445. }
  7446. returnSuccess(ro_json);
  7447. }
  7448. public void end_erp_aftersale()
  7449. {
  7450. if (UrlPostParmsCheck("ctid"))
  7451. {
  7452. string eid = GetPostString("ctid");
  7453. CeErpTradeCell entity = null;
  7454. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7455. if (entity != null)
  7456. {
  7457. string stype = GetPostString("stype");
  7458. string typeStr = stype;
  7459. entity.AfterSaleState = 4;
  7460. entity.FinishAfterSaleTime = DateTime.Now;
  7461. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7462. entity.Update();
  7463. ApiVo apiVo = new ApiVo();
  7464. apiVo.orderNumber = entity.ctid;
  7465. apiVo.actionName = "afterOver";
  7466. designHelper.API_WorkCore(apiVo); //afterOver
  7467. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7468. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7469. CeErpSukuraData.createInfo(entity.ctid, 8);
  7470. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7471. returnSuccessMsg("操作成功!");
  7472. return;
  7473. }
  7474. returnErrorMsg("找不到订单记录");
  7475. }
  7476. }
  7477. public void ins_erp_finishaftersale()
  7478. {
  7479. if (UrlPostParmsCheck("id"))
  7480. {
  7481. string eid = GetPostString("id");
  7482. CeErpTradeResponsible entity = null;
  7483. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7484. if (entity != null)
  7485. {
  7486. entity.VerifyState = 1;
  7487. entity.VerifyTime = DateTime.Now;
  7488. entity.Update();
  7489. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7490. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7491. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7492. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7493. if (dt.Rows.Count <= 0)
  7494. {
  7495. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7496. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7497. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7498. CeErpSukuraData.createInfo(entity.tid, 8);
  7499. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7500. {
  7501. CeErpDesignerBill.Del(entity.tid);
  7502. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7503. }
  7504. }
  7505. returnSuccessMsg("操作成功!");
  7506. return;
  7507. }
  7508. returnErrorMsg("找不到订单记录");
  7509. }
  7510. }
  7511. public void upd_erp_arbitrateaftersale()
  7512. {
  7513. if (UrlPostParmsCheck("id"))
  7514. {
  7515. string eid = GetPostString("id");
  7516. CeErpTradeResponsible entity = null;
  7517. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7518. if (entity != null)
  7519. {
  7520. entity.IsArbitrate = 1;
  7521. entity.ArbitradeMemo = GetPostString("reason");
  7522. entity.VerifyState = 2;
  7523. entity.Update();
  7524. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7525. if (tradecell != null)
  7526. {
  7527. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7528. tradecell.IsArbitrate = 1;
  7529. tradecell.Update();
  7530. }
  7531. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7532. returnSuccessMsg("操作成功!");
  7533. return;
  7534. }
  7535. returnErrorMsg("找不到订单记录");
  7536. }
  7537. }
  7538. public void upd_erp_backaftersale()
  7539. {
  7540. if (UrlPostParmsCheck("tid"))
  7541. {
  7542. string eid = GetPostString("tid");
  7543. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7544. int backNum = 0;
  7545. if (number != null)
  7546. {
  7547. backNum = number.BackNum;
  7548. }
  7549. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7550. CeErpTradeCell entity = null;
  7551. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7552. if (entity != null)
  7553. {
  7554. entity.AfterSaleBackReason = GetPostString("backreason");
  7555. entity.AfterSaleState = 1;
  7556. entity.AfterSaleSupplierState = 0;
  7557. entity.UpdateTime = DateTime.Now;
  7558. entity.Update();
  7559. returnSuccessMsg("操作成功!");
  7560. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7561. return;
  7562. }
  7563. returnErrorMsg("找不到订单记录");
  7564. }
  7565. }
  7566. public void get_erp_supplieraftersalelist()
  7567. {
  7568. DataStruct dStruct = GetPostStruct();
  7569. List<string> lw = new List<string>();
  7570. string tid = GetPostString("ctid");
  7571. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7572. string shopname = GetPostString("shopname");
  7573. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7574. string buyernick = GetPostString("buyer_nick");
  7575. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7576. string sellermemo = GetPostString("seller_memo");
  7577. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7578. string orderState = GetPostString("orderState");
  7579. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7580. string afterState = GetPostString("afterstate");
  7581. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7582. string date1 = GetPostString("date1");
  7583. string date2 = GetPostString("date2");
  7584. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7585. if (dw.Length > 0) lw.Add(dw);
  7586. string price1 = GetPostString("price1");
  7587. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7588. string price2 = GetPostString("price2");
  7589. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7590. string reason = GetPostString("reason");
  7591. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7592. string method = GetPostString("method");
  7593. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7594. string handledate1 = GetPostString("handledate1");
  7595. string handledate2 = GetPostString("handledate2");
  7596. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7597. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7598. string handler = GetPostString("handler");
  7599. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7600. string afterdate1 = GetPostString("afterdate1");
  7601. string afterdate2 = GetPostString("afterdate2");
  7602. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7603. if (afterDate.Length > 0) lw.Add(afterDate);
  7604. string customer = GetPostString("customer");
  7605. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7606. string design = GetPostString("design");
  7607. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7608. string afterMemoType = GetPostString("aftermemotype");
  7609. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7610. string vstate = GetPostString("vstate");
  7611. if (vstate.Length > 0)
  7612. {
  7613. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7614. }
  7615. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7616. string supplier = GetPostString("supplier");
  7617. int supid = commonHelper.getSupplierIDByName(supplier);
  7618. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7619. string posCode = CurrentUser.UserPost.Post.Code;
  7620. if (posCode == "Supplier")
  7621. {
  7622. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7623. }
  7624. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7625. {
  7626. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7627. }
  7628. else
  7629. {
  7630. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7631. }
  7632. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7633. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7634. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7635. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7636. writeGridDataTableJson(dStruct.TotalCount, dt);
  7637. }
  7638. public void upd_erp_supverifyaftersale()
  7639. {
  7640. if (UrlPostParmsCheck("id"))
  7641. {
  7642. string id = GetPostString("id");
  7643. int st = GetPostInt("afterstate");
  7644. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7645. CeErpTradeCell entity = null;
  7646. if (ceErpTradeResponsible != null)
  7647. {
  7648. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7649. }
  7650. string afmemo = GetPostString("supmemo");
  7651. string image = GetPostString("image");
  7652. if (entity != null)
  7653. {
  7654. entity.AfterSaleSupplierState = st;
  7655. entity.AfterSaleSupplierMemo = afmemo;
  7656. if (st == 1)
  7657. {
  7658. ceErpTradeResponsible.VerifyState = 1;
  7659. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7660. ceErpTradeResponsible.Update();
  7661. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7662. if (isAll)
  7663. {
  7664. entity.AfterSaleState = 4;
  7665. entity.FinishAfterSaleTime = DateTime.Now;
  7666. }
  7667. }
  7668. else
  7669. {
  7670. CeErpTradeResponsible.dateByTid(entity.ctid);
  7671. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7672. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7673. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7674. if (num <= 1)
  7675. {
  7676. entity.AfterSaleState = 1;
  7677. }
  7678. else
  7679. {
  7680. entity.AfterSaleState = 5;
  7681. }
  7682. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7683. if (ceErpTradeAfterSaleExtend != null)
  7684. {
  7685. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7686. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7687. ceErpTradeAfterSaleExtend.Update();
  7688. }
  7689. else
  7690. {
  7691. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7692. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7693. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7694. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7695. ceErpTradeAfterSaleExtend.Create();
  7696. }
  7697. }
  7698. if (entity.AfterSaleState == 4)
  7699. {
  7700. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7701. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7702. {
  7703. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7704. }
  7705. ApiVo apiVo = new ApiVo();
  7706. apiVo.orderNumber = entity.ctid;
  7707. apiVo.actionName = "afterOver";
  7708. designHelper.API_WorkCore(apiVo); //afterOver
  7709. }
  7710. entity.UpdateTime = DateTime.Now;
  7711. entity.Update();
  7712. returnSuccessMsg("操作成功!");
  7713. CeErpSukuraData.createInfo(entity.ctid, 8);
  7714. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7715. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7716. return;
  7717. }
  7718. returnErrorMsg("找不到订单记录");
  7719. }
  7720. }
  7721. public void upd_erp_masteraftersale()
  7722. {
  7723. if (UrlPostParmsCheck("id"))
  7724. {
  7725. string id = GetPostString("id");
  7726. int st = GetPostInt("afterstate");
  7727. string afmemo = GetPostString("supmemo");
  7728. string image = GetPostString("image");
  7729. string textResult = GetPostString("textResult");
  7730. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7731. if (ceErpTradeResponsible != null)
  7732. {
  7733. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7734. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7735. ceErpTradeResponsible.Update();
  7736. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7737. if (entity != null)
  7738. {
  7739. entity.AfterSaleSupplierState = st;
  7740. entity.AfterSaleSupplierMemo = afmemo;
  7741. if (st == 1)
  7742. {
  7743. }
  7744. else
  7745. {
  7746. CeErpTradeResponsible.dateByTid(entity.ctid);
  7747. //退回到售后
  7748. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7749. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7750. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7751. if (num <= 1)
  7752. {
  7753. entity.AfterSaleState = 1;
  7754. }
  7755. else
  7756. {
  7757. entity.AfterSaleState = 5;
  7758. }
  7759. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7760. if (ceErpTradeAfterSaleExtend != null)
  7761. {
  7762. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7763. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7764. ceErpTradeAfterSaleExtend.Update();
  7765. }
  7766. else
  7767. {
  7768. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7769. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7770. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7771. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7772. ceErpTradeAfterSaleExtend.Create();
  7773. }
  7774. }
  7775. entity.UpdateTime = DateTime.Now;
  7776. entity.Update();
  7777. returnSuccessMsg("操作成功!");
  7778. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7779. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7780. return;
  7781. }
  7782. }
  7783. returnErrorMsg("找不到订单记录");
  7784. }
  7785. }
  7786. public void upd_erp_personaftersale()
  7787. {
  7788. if (UrlPostParmsCheck("id"))
  7789. {
  7790. //林小连
  7791. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7792. {
  7793. upd_erp_masteraftersale();
  7794. return;
  7795. }
  7796. string id = GetPostString("id");
  7797. int st = GetPostInt("afterstate");
  7798. string afmemo = GetPostString("supmemo");
  7799. string image = GetPostString("image");
  7800. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7801. if (ceErpTradeResponsible != null)
  7802. {
  7803. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7804. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7805. ceErpTradeResponsible.Update();
  7806. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7807. if (entity != null)
  7808. {
  7809. entity.AfterSaleSupplierMemo = afmemo;
  7810. entity.AfterSaleSupplierState = st;
  7811. if (st == 1)
  7812. {
  7813. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7814. if (isAll)
  7815. {
  7816. entity.AfterSaleState = 4;
  7817. entity.FinishAfterSaleTime = DateTime.Now;
  7818. }
  7819. }
  7820. else
  7821. {
  7822. CeErpTradeResponsible.dateByTid(entity.ctid);
  7823. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7824. if (ceErpTradeAfterSaleExtend != null)
  7825. {
  7826. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7827. ceErpTradeAfterSaleExtend.Update();
  7828. }
  7829. else
  7830. {
  7831. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7832. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7833. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7834. ceErpTradeAfterSaleExtend.Create();
  7835. }
  7836. //退回到主管
  7837. //entity.AfterSaleState = 2;
  7838. }
  7839. if (entity.AfterSaleState == 4)
  7840. {
  7841. ApiVo apiVo = new ApiVo();
  7842. apiVo.orderNumber = entity.ctid;
  7843. apiVo.actionName = "afterOver";
  7844. designHelper.API_WorkCore(apiVo); //afterOver
  7845. }
  7846. entity.UpdateTime = DateTime.Now;
  7847. entity.Update();
  7848. returnSuccessMsg("操作成功!");
  7849. CeErpSukuraData.createInfo(entity.ctid, 8);
  7850. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7851. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7852. return;
  7853. }
  7854. }
  7855. returnErrorMsg("找不到订单记录");
  7856. }
  7857. }
  7858. public void set_erp_supplierrefundtag()
  7859. {
  7860. if (UrlPostParmsCheck("ctid"))
  7861. {
  7862. string eid = GetPostString("ctid");
  7863. CeErpTradeCell entity = null;
  7864. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7865. if (entity != null)
  7866. {
  7867. entity.IsSupplierRefund = GetPostInt("tag");
  7868. entity.Update();
  7869. returnSuccessMsg("操作成功!");
  7870. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7871. return;
  7872. }
  7873. returnErrorMsg("找不到订单记录");
  7874. }
  7875. }
  7876. public void get_erp_refundlist()
  7877. {
  7878. DataStruct dStruct = GetPostStruct();
  7879. List<string> lw = new List<string>();
  7880. string tid = GetPostString("tid");
  7881. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7882. //string rid = GetPostString("refund_id");
  7883. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7884. string shopname = GetPostString("shopname");
  7885. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7886. string buyernick = GetPostString("buyer_nick");
  7887. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7888. string customer = GetPostString("customer");
  7889. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7890. string design = GetPostString("design");
  7891. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7892. string sellermemo = GetPostString("seller_memo");
  7893. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7894. //string date1 = GetPostString("date1");
  7895. //string date2 = GetPostString("date2");
  7896. //string dateType = GetPostString("dateType");
  7897. //if (dateType.Length > 0)
  7898. //{
  7899. // if (dateType == "1001") dateType = "0";
  7900. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7901. // if (searchDT.Count == 2)
  7902. // {
  7903. // date1 = searchDT[0].ToString();
  7904. // date2 = searchDT[1].ToString();
  7905. // }
  7906. //}
  7907. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7908. //if (dw.Length > 0) lw.Add(dw);
  7909. string redate1 = GetPostString("refunddate1");
  7910. string redate2 = GetPostString("refunddate2");
  7911. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7912. if (dwdate.Length > 0) lw.Add(dwdate);
  7913. string price1 = GetPostString("price1");
  7914. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7915. string price2 = GetPostString("price2");
  7916. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7917. string ispartrefund = GetPostString("ispartrefund");
  7918. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7919. string refundState = GetPostString("refundvstate");
  7920. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7921. int st = GetInt("st");
  7922. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7923. {
  7924. string responsible = GetPostString("responsibleman");
  7925. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7926. lw.Add(string.Format("RefundState>={0}", st));
  7927. string code = CurrentUser.UserPost.Post.Code;
  7928. if (code == "CustomerService")
  7929. {
  7930. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7931. }
  7932. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7933. {
  7934. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7935. }
  7936. else if (code == "Place" || code == "PlaceMr")
  7937. {
  7938. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7939. }
  7940. dStruct.Order = "RefundState asc,created desc";
  7941. }
  7942. else if (st == 10)
  7943. {
  7944. string responsible = GetPostString("responsibleman");
  7945. if (responsible == "空白")
  7946. {
  7947. lw.Add(string.Format("ResponsibleUserName = ''"));
  7948. }
  7949. else if (responsible.Length > 0)
  7950. {
  7951. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7952. }
  7953. lw.Add(string.Format("RefundState>=0"));
  7954. dStruct.Order = "created desc";
  7955. }
  7956. else
  7957. {
  7958. string responsible = GetPostString("responsibleman");
  7959. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7960. lw.Add(string.Format("RefundState={0}", st));
  7961. dStruct.Order = "created desc";
  7962. }
  7963. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7964. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7965. dt.Columns.Add("refund_fees");
  7966. foreach (DataRow dr in dt.Rows)
  7967. {
  7968. String status = dr["status"].ToString();
  7969. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7970. {
  7971. dr["refund_fees"] = dr["refund_fee"];
  7972. }
  7973. else
  7974. {
  7975. dr["refund_fees"] = "0.0";
  7976. }
  7977. }
  7978. writeGridDataTableJson(dStruct.TotalCount, dt);
  7979. }
  7980. public void get_erp_refunddesignlist()
  7981. {
  7982. DataStruct dStruct = GetPostStruct();
  7983. List<string> lw = new List<string>();
  7984. string tid = GetPostString("tid");
  7985. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7986. string shopname = GetPostString("shopname");
  7987. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7988. string buyernick = GetPostString("buyer_nick");
  7989. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7990. string customer = GetPostString("customer");
  7991. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7992. string design = GetPostString("design");
  7993. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7994. string sellermemo = GetPostString("seller_memo");
  7995. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7996. string redate1 = GetPostString("refunddate1");
  7997. string redate2 = GetPostString("refunddate2");
  7998. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7999. if (dwdate.Length > 0) lw.Add(dwdate);
  8000. string price1 = GetPostString("price1");
  8001. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8002. string price2 = GetPostString("price2");
  8003. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8004. string ispartrefund = GetPostString("ispartrefund");
  8005. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8006. string designerorg = GetPostString("designerorg");
  8007. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8008. string refundState = GetPostString("refundState");
  8009. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8010. int myOrgid = CurrentUser.UserPost.OrgID;
  8011. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8012. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8013. {
  8014. if (CurrentUser.User.TeamIds.Length > 0)
  8015. {
  8016. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8017. }
  8018. else
  8019. {
  8020. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8021. }
  8022. }
  8023. else if ("SysAdmin".Equals(myOrgCode))
  8024. {
  8025. }
  8026. else
  8027. {
  8028. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8029. {
  8030. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8031. }
  8032. else
  8033. {
  8034. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8035. }
  8036. }
  8037. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8038. dStruct.Order = "created desc";
  8039. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8040. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8041. dt.Columns.Add("refund_fees");
  8042. foreach (DataRow dr in dt.Rows)
  8043. {
  8044. String status = dr["status"].ToString();
  8045. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8046. {
  8047. dr["refund_fees"] = dr["refund_fee"];
  8048. }
  8049. else
  8050. {
  8051. dr["refund_fees"] = "0.0";
  8052. }
  8053. }
  8054. writeGridDataTableJson(dStruct.TotalCount, dt);
  8055. }
  8056. public void handle_erp_refundtag()
  8057. {
  8058. if (UrlPostParmsCheck("refund_id"))
  8059. {
  8060. string eid = GetPostString("refund_id");
  8061. string respMan = GetPostString("ResponsibleName");
  8062. if (respMan.Length <= 0)
  8063. {
  8064. returnErrorMsg("责任人不能为空");
  8065. return;
  8066. }
  8067. CeErpTradeRefund entity = null;
  8068. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8069. if (entity != null)
  8070. {
  8071. entity.ResponsibleUserName = respMan;
  8072. string userid = GetPostString("ResponsibleUserId");
  8073. if (userid.Length > 0)
  8074. {
  8075. entity.ResponsibleUserId = userid;
  8076. }
  8077. entity.Memo = GetPostString("Memo");
  8078. if (respMan.IndexOf("客服") != -1 ||
  8079. respMan.IndexOf("设计师") != -1 ||
  8080. respMan.IndexOf("下单员") != -1)
  8081. {
  8082. entity.RefundState = 2;
  8083. }
  8084. else
  8085. {
  8086. entity.RefundState = 3;
  8087. }
  8088. entity.modified = DateTime.Now;
  8089. entity.Update();
  8090. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8091. returnSuccessMsg("操作成功!");
  8092. return;
  8093. }
  8094. returnErrorMsg("找不到订单记录");
  8095. }
  8096. }
  8097. public void handle_erp_designrefundtag()
  8098. {
  8099. if (UrlPostParmsCheck("refund_id"))
  8100. {
  8101. string eid = GetPostString("refund_id");
  8102. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8103. if (ceErpTradeCellExtend == null)
  8104. {
  8105. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8106. ceErpTradeCellExtend.ctid = eid;
  8107. }
  8108. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8109. if (ceErpTradeCellExtend.ID > 0)
  8110. {
  8111. ceErpTradeCellExtend.Update();
  8112. }
  8113. else
  8114. {
  8115. ceErpTradeCellExtend.Create();
  8116. }
  8117. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8118. returnSuccessMsg("操作成功!");
  8119. return;
  8120. }
  8121. returnErrorMsg("找不到订单记录");
  8122. }
  8123. public void upd_erp_refundverify()
  8124. {
  8125. if (UrlPostParmsCheck("refund_id"))
  8126. {
  8127. string eid = GetPostString("refund_id");
  8128. CeErpTradeRefund entity = null;
  8129. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8130. if (entity != null)
  8131. {
  8132. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8133. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8134. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8135. {
  8136. entity.RefundState = 2;
  8137. }
  8138. else
  8139. {
  8140. entity.RefundState = 3;
  8141. }
  8142. entity.Update();
  8143. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8144. returnSuccessMsg("操作成功!");
  8145. return;
  8146. }
  8147. returnErrorMsg("找不到订单记录");
  8148. }
  8149. }
  8150. public void upd_erp_refundapprove()
  8151. {
  8152. if (UrlPostParmsCheck("refund_id"))
  8153. {
  8154. string eid = GetPostString("refund_id");
  8155. CeErpTradeRefund entity = null;
  8156. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8157. if (entity != null)
  8158. {
  8159. int apr = GetPostInt("approve");
  8160. if (apr == 0)
  8161. {
  8162. entity.RefundState = 1;
  8163. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8164. }
  8165. else if (apr == 1)
  8166. {
  8167. entity.RefundState = 3;
  8168. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8169. }
  8170. entity.modified = DateTime.Now;
  8171. entity.Update();
  8172. returnSuccessMsg("操作成功!");
  8173. return;
  8174. }
  8175. returnErrorMsg("找不到订单记录");
  8176. }
  8177. }
  8178. public void get_erp_billlist()
  8179. {
  8180. DataStruct dStruct = GetPostStruct();
  8181. List<string> lw = new List<string>();
  8182. string title = GetPostString("title");
  8183. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8184. string tid = GetPostString("tid");
  8185. string tids = GetPostString("tids");
  8186. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8187. if (tids.Length > 0)
  8188. {
  8189. tids = "'" + tids + "'";
  8190. tids = tids.Replace(",", "','");
  8191. lw.Add(string.Format("tid in ({0})", tids));
  8192. }
  8193. string shopname = GetPostString("shopname");
  8194. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8195. string buyernick = GetPostString("buyer_nick");
  8196. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8197. string customer = GetPostString("customer");
  8198. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8199. string date1 = GetPostString("date1");
  8200. string date2 = GetPostString("date2");
  8201. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8202. if (dw.Length > 0) lw.Add(dw);
  8203. string price1 = GetPostString("price1");
  8204. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8205. string price2 = GetPostString("price2");
  8206. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8207. string returndate1 = GetPostString("returndate1");
  8208. string returndate2 = GetPostString("returndate2");
  8209. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8210. if (dw1.Length > 0) lw.Add(dw1);
  8211. string billtype = GetPostString("billtype");
  8212. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8213. string billstate = GetPostString("billstate");
  8214. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8215. string usershop = CurrentUser.User.pemShop;
  8216. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8217. dStruct.Order = "createTime desc";
  8218. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8219. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8220. //foreach (DataRow dr in dt.Rows)
  8221. //{
  8222. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8223. //}
  8224. writeGridDataTableJson(dStruct.TotalCount, dt);
  8225. }
  8226. public void modify_erp_billinfo()
  8227. {
  8228. if (UrlPostParmsCheck("ID"))
  8229. {
  8230. string eid = GetPostString("ID");
  8231. CeErpBill bill_entity = null;
  8232. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8233. if (bill_entity != null)
  8234. {
  8235. bill_entity.tid = GetPostString("tid");
  8236. bill_entity.title = GetPostString("title");
  8237. bill_entity.tax = GetPostString("tax");
  8238. bill_entity.bank = GetPostString("bank");
  8239. bill_entity.bankac = GetPostString("bankac");
  8240. bill_entity.address = GetPostString("address");
  8241. bill_entity.phone = GetPostString("phone");
  8242. bill_entity.price = GetPostString("price");
  8243. bill_entity.productId = GetPostInt("ProductName");
  8244. bill_entity.num = GetPostInt("num");
  8245. bill_entity.unit = GetPostString("unit");
  8246. bill_entity.type = GetPostString("type");
  8247. bill_entity.sendType = GetPostString("SendType");
  8248. bill_entity.email = GetPostString("email");
  8249. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8250. bill_entity.shopName = GetPostString("ShopName");
  8251. bill_entity.applymemo = GetPostString("applymemo");
  8252. bill_entity.modifyTime = DateTime.Now;
  8253. bill_entity.createTime = DateTime.Now;
  8254. bill_entity.state = 0;
  8255. bill_entity.Update();
  8256. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8257. returnSuccessMsg("发票修改成功!");
  8258. return;
  8259. }
  8260. returnErrorMsg("找不到对应记录");
  8261. }
  8262. }
  8263. public void set_erp_invoicing()
  8264. {
  8265. if (UrlPostParmsCheck("id"))
  8266. {
  8267. try
  8268. {
  8269. string eid = GetPostString("id");
  8270. CeErpBill bill_entity = null;
  8271. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8272. if (bill_entity != null)
  8273. {
  8274. int ComId = GetPostInt("ComId");
  8275. //string memo = GetPostString("Memo");
  8276. int allInfo = GetPostInt("allinfo");
  8277. string clert = CurrentUser.User.Name;
  8278. //string detailValue = GetPostString("detailvalue");
  8279. string billId = bill_entity.billOrderId;
  8280. string[] billIdList = billId.Split(',');
  8281. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8282. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8283. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8284. {
  8285. billCount += 1;
  8286. }
  8287. if (billId.Length <= 0 || billIdList.Length != billCount)
  8288. {
  8289. bill_entity.billOrderId = "";
  8290. string prebill = "ltb";
  8291. for (int idx = 1; idx <= billCount; idx++)
  8292. {
  8293. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8294. string billoid = prebill + idx + dtstr;
  8295. bill_entity.billOrderId += billoid;
  8296. if (idx < billCount)
  8297. {
  8298. bill_entity.billOrderId += ",";
  8299. }
  8300. }
  8301. }
  8302. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8303. if (bill_entity.state == 5)
  8304. {
  8305. string errMsg = bill_entity.failerror;
  8306. string[] errlist = errMsg.Split('|');
  8307. string[] errTags = new string[errlist.Length];
  8308. for (int itag = 0; itag < errlist.Length; itag++)
  8309. {
  8310. if (errlist[itag].Length <= 0) continue;
  8311. errTags[itag] = errlist[itag].Split('&')[0];
  8312. }
  8313. for (int iii = 0; iii < errTags.Length; iii++)
  8314. {
  8315. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8316. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8317. if (billOrderList.Length >= erroBillOrderTag)
  8318. {
  8319. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8320. if (needModifyBillId.Length <= 19)
  8321. {
  8322. needModifyBillId = needModifyBillId + "1";
  8323. }
  8324. else
  8325. {
  8326. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8327. last = last + 1;
  8328. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8329. }
  8330. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8331. }
  8332. }
  8333. }
  8334. bool isHaveBillSucces = false;
  8335. string totalRes = "";
  8336. bill_entity.failerror = "";
  8337. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8338. {
  8339. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8340. totalRes += res;
  8341. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8342. {
  8343. isHaveBillSucces = true;
  8344. bill_entity.comId = ComId;
  8345. bill_entity.state = 1;
  8346. bill_entity.executeTime = DateTime.Now;
  8347. bill_entity.executeUser = clert;
  8348. }
  8349. else
  8350. {
  8351. bill_entity.state = 5;
  8352. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8353. }
  8354. }
  8355. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8356. bill_entity.Update();
  8357. if (isHaveBillSucces)
  8358. {
  8359. StringBuilder sql = new StringBuilder();
  8360. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8361. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8362. }
  8363. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8364. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8365. {
  8366. returnErrorMsg("开票失败");
  8367. }
  8368. else
  8369. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8370. return;
  8371. }
  8372. returnErrorMsg("找不到对应记录");
  8373. }
  8374. catch (Exception ex)
  8375. {
  8376. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8377. returnErrorMsg("操作失败");
  8378. }
  8379. }
  8380. }
  8381. public void get_erp_invoicing_back()
  8382. {
  8383. if (UrlPostParmsCheck("id"))
  8384. {
  8385. try
  8386. {
  8387. string id = GetPostString("id");
  8388. CeErpBill entiy = CeErpBill.Get(id);
  8389. if (entiy != null)
  8390. {
  8391. if (entiy.state == 0)
  8392. {
  8393. returnErrorMsg("发票还未开具");
  8394. return;
  8395. }
  8396. string[] billOrderList = entiy.billOrderId.Split(',');
  8397. int iTag = 0;
  8398. entiy.fplsh = "";
  8399. entiy.fpdm = "";
  8400. entiy.fphm = "";
  8401. foreach (string billOrderId in billOrderList)
  8402. {
  8403. iTag++;
  8404. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8405. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8406. {
  8407. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8408. try
  8409. {
  8410. Invoicing_get_response_Obj iObj = null;
  8411. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8412. if (iObj != null)
  8413. {
  8414. entiy.state = 2;
  8415. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8416. entiy.fpdm += iObj.list[0].c_fpdm;
  8417. entiy.fphm += iObj.list[0].c_fphm;
  8418. if (iTag < billOrderList.Length)
  8419. {
  8420. entiy.fplsh += ",";
  8421. entiy.fpdm += ",";
  8422. entiy.fphm += ",";
  8423. }
  8424. entiy.Update();
  8425. }
  8426. StringBuilder sql = new StringBuilder();
  8427. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8428. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8429. returnSuccessMsg("开票成功");
  8430. }
  8431. catch (Exception ex)
  8432. {
  8433. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8434. }
  8435. return;
  8436. }
  8437. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8438. {
  8439. var res_obj = new
  8440. {
  8441. data = "开票中"
  8442. };
  8443. string ro_json = JsonConvert.SerializeObject(res_obj);
  8444. returnSuccess(ro_json);
  8445. return;
  8446. }
  8447. else
  8448. {
  8449. int eidx = res.IndexOf("c_resultmsg");
  8450. int lidx = res.IndexOf("c_status");
  8451. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8452. entiy.state = 5;
  8453. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8454. entiy.Update();
  8455. returnErrorMsg("开票失败");
  8456. return;
  8457. }
  8458. }
  8459. }
  8460. }
  8461. catch (Exception ex)
  8462. {
  8463. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8464. }
  8465. return;
  8466. }
  8467. }
  8468. public void get_erp_invoicing()
  8469. {
  8470. if (UrlPostParmsCheck("id"))
  8471. {
  8472. try
  8473. {
  8474. string id = GetPostString("id");
  8475. CeErpBill entiy = CeErpBill.Get(id);
  8476. if (entiy != null)
  8477. {
  8478. if (entiy.state == 0)
  8479. {
  8480. returnErrorMsg("发票还未开具");
  8481. return;
  8482. }
  8483. if (entiy.sendType == "纸质发票")
  8484. {
  8485. if (entiy.img.Length <= 0)
  8486. {
  8487. returnErrorMsg("查无纸质发票");
  8488. return;
  8489. }
  8490. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8491. returnSuccess(returnres);
  8492. return;
  8493. }
  8494. string[] billOrderList = entiy.billOrderId.Split(',');
  8495. int iTag = 0;
  8496. string fpUrl = "";
  8497. entiy.fplsh = "";
  8498. entiy.fpdm = "";
  8499. entiy.fphm = "";
  8500. foreach (string billOrderId in billOrderList)
  8501. {
  8502. iTag++;
  8503. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8504. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8505. {
  8506. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8507. Invoicing_get_response_Obj iObj = null;
  8508. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8509. if (iObj != null)
  8510. {
  8511. //entiy.state = 2;
  8512. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8513. entiy.fpdm += iObj.list[0].c_fpdm;
  8514. entiy.fphm += iObj.list[0].c_fphm;
  8515. if (iTag < billOrderList.Length)
  8516. {
  8517. entiy.fplsh += ",";
  8518. entiy.fpdm += ",";
  8519. entiy.fphm += ",";
  8520. }
  8521. entiy.Update();
  8522. fpUrl += iObj.list[0].c_url + ",";
  8523. }
  8524. //returnSuccess(res);
  8525. StringBuilder sql = new StringBuilder();
  8526. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8527. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8528. }
  8529. else
  8530. {
  8531. int eidx = res.IndexOf("c_resultmsg");
  8532. //int lidx = res.IndexOf("c_status");
  8533. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8534. //开票失败
  8535. entiy.state = 5;
  8536. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8537. entiy.Update();
  8538. returnErrorMsg("开票失败");
  8539. return;
  8540. }
  8541. }
  8542. var returnObj = new
  8543. {
  8544. data = fpUrl
  8545. };
  8546. string ro_json = JsonConvert.SerializeObject(returnObj);
  8547. returnSuccess(ro_json);
  8548. }
  8549. }
  8550. catch (Exception ex)
  8551. {
  8552. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8553. }
  8554. return;
  8555. }
  8556. }
  8557. public void save_erp_billimg()
  8558. {
  8559. if (UrlPostParmsCheck("id"))
  8560. {
  8561. string eid = GetPostString("id");
  8562. CeErpBill bill_entity = null;
  8563. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8564. if (bill_entity != null)
  8565. {
  8566. bill_entity.img = GetPostString("img");
  8567. bill_entity.executeTime = DateTime.Now;
  8568. bill_entity.state = 2;
  8569. bill_entity.Update();
  8570. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8571. returnSuccessMsg("保存成功");
  8572. }
  8573. return;
  8574. }
  8575. }
  8576. public void upd_erp_billreturnback()
  8577. {
  8578. if (UrlPostParmsCheck("id"))
  8579. {
  8580. int eid = GetPostInt("id");
  8581. CeErpBill bill_entity = null;
  8582. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8583. if (bill_entity != null)
  8584. {
  8585. bill_entity.state = 3;
  8586. bill_entity.returnReason = GetPostString("reason");
  8587. bill_entity.Update();
  8588. returnSuccessMsg("驳回成功!");
  8589. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8590. }
  8591. return;
  8592. }
  8593. }
  8594. public void cancel_erp_bill()
  8595. {
  8596. if (UrlPostParmsCheck("id"))
  8597. {
  8598. int eid = GetPostInt("id");
  8599. int detailValue = GetPostInt("detailvalue");
  8600. CeErpBill bill_entity = null;
  8601. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8602. string cres = "";
  8603. string gres = "";
  8604. if (bill_entity != null)
  8605. {
  8606. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8607. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8608. {
  8609. int iTag = 0;
  8610. bill_entity.fplsh = "";
  8611. bill_entity.fpdm = "";
  8612. bill_entity.fphm = "";
  8613. foreach (string billOrderId in billOrderList)
  8614. {
  8615. iTag++;
  8616. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8617. if (gres.IndexOf("success") != -1)
  8618. {
  8619. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8620. Invoicing_get_response_Obj iObj = null;
  8621. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8622. if (iObj != null)
  8623. {
  8624. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8625. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8626. bill_entity.fphm += iObj.list[0].c_fphm;
  8627. if (iTag < billOrderList.Length)
  8628. {
  8629. bill_entity.fplsh += ",";
  8630. bill_entity.fpdm += ",";
  8631. bill_entity.fphm += ",";
  8632. }
  8633. bill_entity.Update();
  8634. }
  8635. }
  8636. else
  8637. {
  8638. returnErrorMsg(gres);
  8639. return;
  8640. }
  8641. }
  8642. }
  8643. if (bill_entity.sendType == "纸质发票")
  8644. {
  8645. //作废
  8646. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8647. //if (DateTime.Now.Month == extime.Month)
  8648. //{
  8649. //cres = taobaoHelper.cancel_invoicing(eid);
  8650. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8651. //{
  8652. bill_entity.state = 4;//已作废
  8653. bill_entity.Update();
  8654. returnSuccessMsg("发票已作废");
  8655. return;
  8656. //}
  8657. //else
  8658. //{
  8659. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8660. // bill_entity.Update();
  8661. // returnErrorMsg(cres);
  8662. // return;
  8663. //}
  8664. //}
  8665. //else
  8666. //{
  8667. // returnErrorMsg("纸质发票只能作废本月的发票");
  8668. // return;
  8669. //}
  8670. }
  8671. //红冲
  8672. int redTag = 0;
  8673. string[] fpdmList = bill_entity.fpdm.Split(',');
  8674. string[] fphmList = bill_entity.fphm.Split(',');
  8675. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8676. {
  8677. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8678. return;
  8679. }
  8680. foreach (string billOrderId in billOrderList)
  8681. {
  8682. redTag++;
  8683. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8684. cres += onecres;
  8685. cres += ",";
  8686. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8687. {
  8688. bill_entity.state = 4;//已作废
  8689. //bill_entity.Update();
  8690. //returnSuccessMsg("发票已红冲");
  8691. }
  8692. else if (onecres.IndexOf("重复冲红") != -1)
  8693. {
  8694. bill_entity.state = 4;//已作废
  8695. //bill_entity.Update();
  8696. //returnSuccessMsg("发票已红冲");
  8697. }
  8698. else
  8699. {
  8700. string errmsg = commonHelper.KeepChinese(onecres);
  8701. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8702. }
  8703. }
  8704. bill_entity.Update();
  8705. if (cres.IndexOf("失败") != -1)
  8706. returnErrorMsg("红冲失败");
  8707. else
  8708. returnSuccessMsg("发票已红冲");
  8709. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8710. return;
  8711. }
  8712. return;
  8713. }
  8714. }
  8715. public void del_erp_billorder()
  8716. {
  8717. if (UrlPostParmsCheck("id"))
  8718. {
  8719. string eid = GetPostString("id");
  8720. CeErpBill.Del(eid);
  8721. CeErpBill bill = CeErpBill.Get(eid);
  8722. if (bill != null)
  8723. {
  8724. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8725. }
  8726. returnSuccessMsg("删除成功");
  8727. }
  8728. }
  8729. public void finish_erp_bill()
  8730. {
  8731. if (UrlPostParmsCheck("ids"))
  8732. {
  8733. string eids = GetPostString("ids");
  8734. string[] list = eids.Split(',');
  8735. foreach (string eid in list)
  8736. {
  8737. CeErpBill bill = CeErpBill.Get(eid);
  8738. if (bill != null)
  8739. {
  8740. bill.state = 2;
  8741. bill.Update();
  8742. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8743. }
  8744. }
  8745. returnSuccessMsg("操作成功");
  8746. }
  8747. }
  8748. public void get_erp_returncash()
  8749. {
  8750. DataStruct dStruct = GetPostStruct();
  8751. List<string> lw = new List<string>();
  8752. string tid = GetPostString("tid");
  8753. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8754. string shopname = GetPostString("shopname");
  8755. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8756. string buyernick = GetPostString("buyer_nick");
  8757. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8758. string customer = GetPostString("customer");
  8759. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8760. string returndate1 = GetPostString("returndate1");
  8761. string returndate2 = GetPostString("returndate2");
  8762. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8763. if (dw.Length > 0) lw.Add(dw);
  8764. string finishDate1 = GetPostString("finishdate1");
  8765. string finishDate2 = GetPostString("finishdate2");
  8766. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8767. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8768. string returntype = GetPostString("returntype");
  8769. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8770. string returnvstate = GetPostString("returnvstate");
  8771. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8772. dStruct.Order = "created desc";
  8773. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8774. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8775. writeGridDataTableJson(dStruct.TotalCount, dt);
  8776. }
  8777. public void get_erp_staygoods()
  8778. {
  8779. DataStruct dStruct = GetPostStruct();
  8780. List<string> lw = new List<string>();
  8781. string tid = GetPostString("tid");
  8782. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8783. string shopname = GetPostString("shopname");
  8784. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8785. string wangwang = GetPostString("wangwang");
  8786. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8787. string customer = GetPostString("customer");
  8788. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8789. string returndate1 = GetPostString("returndate1");
  8790. string returndate2 = GetPostString("returndate2");
  8791. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8792. if (dw.Length > 0) lw.Add(dw);
  8793. string finishDate1 = GetPostString("finishdate1");
  8794. string finishDate2 = GetPostString("finishdate2");
  8795. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8796. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8797. string returnvstate = GetPostString("returnvstate");
  8798. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8799. string persuadetype = GetPostString("persuadetype");
  8800. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8801. string customerOrg = GetPostString("customerOrg");
  8802. if (customerOrg.Length > 0)
  8803. {
  8804. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8805. }
  8806. dStruct.Order = "creata_time desc";
  8807. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8808. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8809. writeGridDataTableJson(dStruct.TotalCount, dt);
  8810. }
  8811. public void upd_erp_staygoods()
  8812. {
  8813. if (UrlPostParmsCheck("id"))
  8814. {
  8815. int eid = GetPostInt("id");
  8816. CeErpStayGoods entity = null;
  8817. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8818. if (entity != null)
  8819. {
  8820. entity.audit_type = 1;
  8821. entity.audit_time = DateTime.Now;
  8822. entity.audit_u_id = CurrentUser.UserID;
  8823. entity.audit_u_name = CurrentUser.UserName;
  8824. entity.Update();
  8825. returnSuccessMsg("审核成功!");
  8826. return;
  8827. }
  8828. returnErrorMsg("找不到订单记录");
  8829. }
  8830. }
  8831. public void upd_erp_stayGoodsback()
  8832. {
  8833. if (UrlPostParmsCheck("id"))
  8834. {
  8835. int eid = GetPostInt("id");
  8836. CeErpStayGoods entity = null;
  8837. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8838. if (entity != null)
  8839. {
  8840. entity.audit_text = GetPostString("reason");
  8841. entity.audit_type = 2;
  8842. entity.audit_time = DateTime.Now;
  8843. entity.audit_u_id = CurrentUser.UserID;
  8844. entity.audit_u_name = CurrentUser.UserName;
  8845. entity.Update();
  8846. returnSuccessMsg("退回成功!");
  8847. return;
  8848. }
  8849. returnErrorMsg("找不到订单记录");
  8850. }
  8851. }
  8852. public void upd_erp_returncashverify()
  8853. {
  8854. if (UrlPostParmsCheck("ID"))
  8855. {
  8856. int eid = GetPostInt("ID");
  8857. CeErpReturnCash entity = null;
  8858. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8859. if (entity != null)
  8860. {
  8861. entity.cashstate = 1;
  8862. entity.verifytime = DateTime.Now;
  8863. entity.verifyuserid = CurrentUser.UserID;
  8864. entity.Update();
  8865. returnSuccessMsg("审核成功!");
  8866. return;
  8867. }
  8868. returnErrorMsg("找不到订单记录");
  8869. }
  8870. }
  8871. public void upd_all_erp_returncashverify()
  8872. {
  8873. if (UrlPostParmsCheck("ID"))
  8874. {
  8875. String[] list = GetPostString("ID").Split(',');
  8876. CeErpReturnCash entity = null;
  8877. for (int i = 0; i < list.Length; i++)
  8878. {
  8879. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8880. if (entity != null)
  8881. {
  8882. if (entity.cashstate == 1)
  8883. {
  8884. returnErrorMsg("已审核过的订单不需要在审核!");
  8885. return;
  8886. }
  8887. entity.cashstate = 1;
  8888. entity.verifytime = DateTime.Now;
  8889. entity.verifyuserid = CurrentUser.UserID;
  8890. entity.Update();
  8891. }
  8892. }
  8893. returnSuccessMsg("审核成功!");
  8894. return;
  8895. }
  8896. }
  8897. public void upd_erp_returncashback()
  8898. {
  8899. if (UrlPostParmsCheck("ID"))
  8900. {
  8901. int eid = GetPostInt("ID");
  8902. CeErpReturnCash entity = null;
  8903. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8904. if (entity != null)
  8905. {
  8906. entity.backreason = GetPostString("reason");
  8907. entity.cashstate = 2;
  8908. entity.verifytime = DateTime.Now;
  8909. entity.verifyuserid = CurrentUser.UserID;
  8910. entity.Update();
  8911. returnSuccessMsg("退回成功!");
  8912. return;
  8913. }
  8914. returnErrorMsg("找不到订单记录");
  8915. }
  8916. }
  8917. public void upd_erp_returnprice()
  8918. {
  8919. if (UrlPostParmsCheck("ID"))
  8920. {
  8921. int eid = GetPostInt("ID");
  8922. CeErpReturnCash entity = null;
  8923. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8924. if (entity != null)
  8925. {
  8926. if (entity.cashstate == 1)
  8927. {
  8928. returnErrorMsg("审核通过了不能改");
  8929. return;
  8930. }
  8931. entity.returnprice = GetPostDouble("returnprice");
  8932. entity.Update();
  8933. returnSuccessMsg("修改成功!");
  8934. return;
  8935. }
  8936. returnErrorMsg("找不到订单记录");
  8937. }
  8938. }
  8939. public void del_erp_returncash()
  8940. {
  8941. if (UrlPostParmsCheck("ID"))
  8942. {
  8943. int eid = GetPostInt("ID");
  8944. CeErpReturnCash.Del(eid);
  8945. returnSuccessMsg("操作成功");
  8946. return;
  8947. }
  8948. }
  8949. public void test_for_do_sql()
  8950. {
  8951. string sql = GetPostString("sqlstr");
  8952. if (sql.Length > 0)
  8953. {
  8954. try
  8955. {
  8956. DbHelper.DbConn.ExecuteNonQuery(sql);
  8957. var res_obj = new
  8958. {
  8959. data = "成功",
  8960. };
  8961. string ro_json = JsonConvert.SerializeObject(res_obj);
  8962. returnSuccess(ro_json);
  8963. }
  8964. catch (Exception ex)
  8965. {
  8966. var res_obj = new
  8967. {
  8968. data = ex.Message,
  8969. };
  8970. string ro_json = JsonConvert.SerializeObject(res_obj);
  8971. returnSuccess(ro_json);
  8972. }
  8973. }
  8974. }
  8975. public void get_user_info()
  8976. {
  8977. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8978. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8979. }
  8980. public void get_total_data()
  8981. {
  8982. int userId = CurrentUser.UserID;
  8983. string sql = "";
  8984. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8985. {
  8986. 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);
  8987. }
  8988. else
  8989. {
  8990. 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 " +
  8991. "(select ID from CE_ErpUser where ID = {0}) d " +
  8992. "left join " +
  8993. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8994. ") a on d.ID = a.id left join " +
  8995. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8996. ") b on a.id = b.id1 left join" +
  8997. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8998. ") c on a.id = c.id2;", userId);
  8999. }
  9000. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9001. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9002. }
  9003. public void get_date_area_total_data2()
  9004. {
  9005. int userId = CurrentUser.UserID;
  9006. string date_type = GetPostString("timetype");
  9007. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9008. string sql = "";
  9009. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9010. {
  9011. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9012. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9013. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9014. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9015. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9016. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9017. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9018. ") a on e.ID = a.id left join " +
  9019. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9020. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9021. ") b on a.id = b.id1 " +
  9022. "left join " +
  9023. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9024. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9025. ") c on a.id = c.id2 " +
  9026. "left join " +
  9027. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9028. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9029. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9030. }
  9031. else
  9032. {
  9033. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9034. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9035. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9036. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9037. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9038. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9039. ") a on e.ID = a.id left join " +
  9040. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9041. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9042. ") c on a.id = c.id2 " +
  9043. "left join " +
  9044. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9045. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9046. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9047. }
  9048. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9049. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9050. }
  9051. public void get_date_area_total_data()
  9052. {
  9053. int userId = CurrentUser.UserID;
  9054. string date_type = GetPostString("timetype");
  9055. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9056. string date1 = searchDT[0].ToString();
  9057. string date2 = searchDT[1].ToString();
  9058. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9059. {
  9060. SqlParameter[] sqlParameter ={
  9061. new SqlParameter("@userId", SqlDbType.Int,4),
  9062. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9063. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9064. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9065. };
  9066. sqlParameter[0].Value = userId;
  9067. sqlParameter[1].Value = date1;
  9068. sqlParameter[2].Value = date2;
  9069. sqlParameter[3].Direction = ParameterDirection.Output;
  9070. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9071. string res = sqlParameter[3].Value.ToString();
  9072. var res_obj = new
  9073. {
  9074. data = res
  9075. };
  9076. string ro_json = JsonConvert.SerializeObject(res_obj);
  9077. returnSuccess(ro_json);
  9078. }
  9079. else
  9080. {
  9081. SqlParameter[] sqlParameter ={
  9082. new SqlParameter("@userId", SqlDbType.Int,4),
  9083. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9084. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9085. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9086. };
  9087. sqlParameter[0].Value = userId;
  9088. sqlParameter[1].Value = date1;
  9089. sqlParameter[2].Value = date2;
  9090. sqlParameter[3].Direction = ParameterDirection.Output;
  9091. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9092. string res = sqlParameter[3].Value.ToString();
  9093. var res_obj = new
  9094. {
  9095. data = res
  9096. };
  9097. string ro_json = JsonConvert.SerializeObject(res_obj);
  9098. returnSuccess(ro_json);
  9099. }
  9100. //writeGridDataViewJson(dt.Rows.Count, dv);
  9101. }
  9102. public void get_order_list()
  9103. {
  9104. string strFields = GetPostString("paraFields");
  9105. string strOrder = GetPostString("paraOrder");
  9106. string strWhere = GetPostString("paraWhere");
  9107. string strPageSize = GetPostString("paraPageSize");
  9108. DataStruct dStruct = GetPostStruct();
  9109. dStruct.PageSize = int.Parse(strPageSize);
  9110. dStruct.Fileds = strFields;
  9111. dStruct.Order = strOrder;
  9112. dStruct.MainWhere = strWhere;
  9113. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9114. writeGridDataTableJson(dStruct.TotalCount, dt);
  9115. }
  9116. ////获取待开始订单列表
  9117. //public void get_wait_design_order_list()
  9118. //{
  9119. // string date_type = GetPostString("date_type");
  9120. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9121. // DataStruct dStruct = GetPostStruct();
  9122. // dStruct.PageSize = 1000;
  9123. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9124. // List<string> lw = new List<string>();
  9125. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9126. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9127. // dStruct.Order = "WaitDesignTime asc";
  9128. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9129. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9130. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9131. //}
  9132. //获取完成单量排名
  9133. public void get_finish_order_count_ranking()
  9134. {
  9135. /* string date_type = GetPostString("date_type");
  9136. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9137. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9138. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9139. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9140. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9141. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9142. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9143. writeGridDataTableJson(0, new DataTable());
  9144. }
  9145. public void get_finish_order_amount_ranking()
  9146. {
  9147. /*string date_type = GetPostString("date_type");
  9148. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9149. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9150. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9151. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9152. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9153. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9154. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9155. writeGridDataTableJson(0, new DataTable());
  9156. }
  9157. public void get_finish_refund_count_ranking()
  9158. {
  9159. string date_type = GetPostString("date_type");
  9160. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9161. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9162. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9163. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9164. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9165. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9166. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9167. writeGridDataTableJson(dt.Rows.Count, dt);
  9168. }
  9169. public void get_finish_refund_amount_ranking()
  9170. {
  9171. string date_type = GetPostString("date_type");
  9172. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9173. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9174. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9175. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9176. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9177. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9178. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9179. writeGridDataTableJson(dt.Rows.Count, dt);
  9180. }
  9181. public void set_erp_finishorder_director()
  9182. {
  9183. if (UrlPostParmsCheck("ctid"))
  9184. {
  9185. string eid = GetPostString("ctid");
  9186. CeErpTradeCell entity = null;
  9187. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9188. if (entity != null)
  9189. {
  9190. entity.OrderState = 8;
  9191. entity.Update();
  9192. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9193. returnSuccessMsg("操作成功!");
  9194. return;
  9195. }
  9196. returnErrorMsg("找不到记录");
  9197. }
  9198. }
  9199. public void get_erp_placeregistlist()
  9200. {
  9201. DataStruct dStruct = GetPostStruct();
  9202. List<string> lw = new List<string>();
  9203. string outsid = GetPostString("outsid");
  9204. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9205. string memo = GetPostString("memo");
  9206. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9207. string filename = GetPostString("filename");
  9208. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9209. string islate = GetPostString("islate");
  9210. if (islate.Length > 0)
  9211. {
  9212. if (islate == "1")
  9213. lw.Add(string.Format("OutLate>0"));
  9214. else
  9215. lw.Add(string.Format("OutLate=0"));
  9216. }
  9217. string placedate1 = GetPostString("placedate1");
  9218. string placedate2 = GetPostString("placedate2");
  9219. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9220. if (dw.Length > 0) lw.Add(dw);
  9221. string deliveryDate1 = GetPostString("deliverydate1");
  9222. string deliveryDate2 = GetPostString("deliverydate2");
  9223. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9224. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9225. dStruct.Order = "ID desc";
  9226. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9227. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9228. writeGridDataTableJson(dStruct.TotalCount, dt);
  9229. }
  9230. public void ins_erp_placeregist()
  9231. {
  9232. if (UrlPostParmsCheck("id"))
  9233. {
  9234. string eid = GetPostString("id");
  9235. CeErpPlaceRegister entity = null;
  9236. if (eid == "0")//新增
  9237. {
  9238. entity = new CeErpPlaceRegister();
  9239. string xdTime = GetPostString("placeTime");
  9240. if (xdTime.Length > 0)
  9241. {
  9242. entity.PlactTime = Convert.ToDateTime(xdTime);
  9243. }
  9244. string fhTime = GetPostString("deliveryTime");
  9245. if (fhTime.Length > 0)
  9246. {
  9247. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9248. }
  9249. string preTime = GetPostString("preOutTime");
  9250. if (preTime.Length > 0)
  9251. {
  9252. entity.PreOutTime = Convert.ToDateTime(preTime);
  9253. }
  9254. entity.DeliveryCount = GetPostInt("deliveryCount");
  9255. entity.ReceiveCount = GetPostInt("receiveCount");
  9256. entity.OutSid = GetPostString("outSid");
  9257. entity.FileName = GetPostString("fileName");
  9258. entity.Memo = GetPostString("memo");
  9259. entity.AddUserId = CurrentUser.UserID;
  9260. entity.CreateTime = DateTime.Now;
  9261. entity.Img = GetPostString("img");
  9262. entity.Supplier = GetPostInt("supplier");
  9263. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9264. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9265. {
  9266. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9267. DateTime dt2 = (DateTime)entity.PreOutTime;
  9268. TimeSpan span = dt1.Subtract(dt2);
  9269. if (span.Days > 0)
  9270. {
  9271. entity.OutLate = span.Days;
  9272. }
  9273. }
  9274. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9275. entity.Create();
  9276. returnSuccessMsg("添加成功!");
  9277. return;
  9278. }
  9279. else //修改
  9280. {
  9281. entity = CeErpPlaceRegister.Get(eid);
  9282. if (entity != null)
  9283. {
  9284. string xdTime = GetPostString("placeTime");
  9285. if (xdTime.Length > 0)
  9286. {
  9287. entity.PlactTime = Convert.ToDateTime(xdTime);
  9288. }
  9289. string fhTime = GetPostString("deliveryTime");
  9290. if (fhTime.Length > 0)
  9291. {
  9292. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9293. }
  9294. string preTime = GetPostString("preOutTime");
  9295. if (preTime.Length > 0)
  9296. {
  9297. entity.PreOutTime = Convert.ToDateTime(preTime);
  9298. }
  9299. entity.DeliveryCount = GetPostInt("deliveryCount");
  9300. entity.ReceiveCount = GetPostInt("receiveCount");
  9301. if (entity.DeliveryCount == entity.ReceiveCount)
  9302. {
  9303. entity.CurState = "已完成";
  9304. }
  9305. else
  9306. {
  9307. entity.CurState = "未完成";
  9308. }
  9309. entity.OutSid = GetPostString("outSid");
  9310. entity.FileName = GetPostString("fileName");
  9311. entity.Memo = GetPostString("memo");
  9312. entity.Img = GetPostString("img");
  9313. entity.Supplier = GetPostInt("supplier");
  9314. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9315. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9316. {
  9317. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9318. DateTime dt2 = (DateTime)entity.PreOutTime;
  9319. TimeSpan span = dt1.Subtract(dt2);
  9320. if (span.Days > 0)
  9321. {
  9322. entity.OutLate = span.Days;
  9323. }
  9324. }
  9325. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9326. entity.Update();
  9327. returnSuccessMsg("修改成功");
  9328. return;
  9329. }
  9330. returnErrorMsg("找不到对应的记录");
  9331. return;
  9332. }
  9333. }
  9334. returnErrorMsg("缺少必要参数");
  9335. }
  9336. public void del_erp_placeregist()
  9337. {
  9338. string eid = GetPostString("id");
  9339. CeErpPlaceRegister.Del(eid);
  9340. returnSuccessMsg("删除成功!");
  9341. return;
  9342. }
  9343. public void ins_erp_placeregistbyorder()
  9344. {
  9345. string ctid = GetPostString("ctid");
  9346. if (ctid.Length > 0)
  9347. {
  9348. StringBuilder sql = new StringBuilder();
  9349. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9350. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9351. if (dt.Rows.Count > 0)
  9352. {
  9353. foreach (DataRow dr in dt.Rows)
  9354. {
  9355. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9356. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9357. entity.AddUserId = CurrentUser.UserID;
  9358. entity.tid = dr["tid"].ToString();
  9359. entity.Did = Convert.ToString(dr["ctid"]);
  9360. entity.splitTag = dr["SplitTag"].ToString();
  9361. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9362. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9363. if (pre_ctid.Length > 0)
  9364. {
  9365. sellmemo = sellmemo.Replace(pre_ctid, "");
  9366. }
  9367. sellmemo = sellmemo.Replace("[", "");
  9368. sellmemo = sellmemo.Replace("]", "");
  9369. entity.FileName = sellmemo;
  9370. string count = dr["ProductCount"].ToString();
  9371. int usecount = commonHelper.getIntCountFromString(count);
  9372. entity.DeliveryCount = usecount;
  9373. entity.CurState = "未完成";
  9374. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9375. {
  9376. entity.Supplier = 24;//dl手提袋定制
  9377. }
  9378. else
  9379. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9380. entity.CreateTime = DateTime.Now;
  9381. entity.Create();
  9382. }
  9383. returnSuccessMsg("操作成功");
  9384. return;
  9385. }
  9386. returnErrorMsg("没有找到对应订单");
  9387. return;
  9388. }
  9389. returnErrorMsg("缺少订单编号");
  9390. return;
  9391. }
  9392. public void get_erp_persuadelist()
  9393. {
  9394. DataStruct dStruct = GetPostStruct();
  9395. List<string> lw = new List<string>();
  9396. string ctid = GetPostString("ctid");
  9397. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9398. string shopname = GetPostString("shopname");
  9399. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9400. string buyernick = GetPostString("buyer_nick");
  9401. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9402. string customer = GetPostString("customer");
  9403. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9404. string returndate1 = GetPostString("returndate1");
  9405. string returndate2 = GetPostString("returndate2");
  9406. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9407. if (dw.Length > 0) lw.Add(dw);
  9408. string finishDate1 = GetPostString("finishdate1");
  9409. string finishDate2 = GetPostString("finishdate2");
  9410. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9411. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9412. string persuadetype = GetPostString("persuadetype");
  9413. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9414. string returnvstate = GetPostString("returnvstate");
  9415. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9416. dStruct.Order = "created desc";
  9417. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9418. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9419. writeGridDataTableJson(dStruct.TotalCount, dt);
  9420. }
  9421. public void upd_erp_returnpersuadeback()
  9422. {
  9423. if (UrlPostParmsCheck("ID"))
  9424. {
  9425. int eid = GetPostInt("ID");
  9426. CeErpPersuade entity = null;
  9427. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9428. if (entity != null)
  9429. {
  9430. entity.backreason = GetPostString("reason");
  9431. entity.pstate = 2;
  9432. entity.verifytime = DateTime.Now;
  9433. entity.verifyuserid = CurrentUser.UserID;
  9434. entity.Update();
  9435. returnSuccessMsg("退回成功!");
  9436. return;
  9437. }
  9438. returnErrorMsg("找不到订单记录");
  9439. }
  9440. }
  9441. public void upd_erp_returnpersuadeverify()
  9442. {
  9443. if (UrlPostParmsCheck("ID"))
  9444. {
  9445. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9446. {
  9447. returnErrorMsg("暂无权限审核");
  9448. return;
  9449. }
  9450. int eid = GetPostInt("ID");
  9451. CeErpPersuade entity = null;
  9452. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9453. if (entity != null)
  9454. {
  9455. entity.pstate = 1;
  9456. entity.verifytime = DateTime.Now;
  9457. entity.verifyuserid = CurrentUser.UserID;
  9458. entity.Update();
  9459. returnSuccessMsg("审核成功!");
  9460. return;
  9461. }
  9462. returnErrorMsg("找不到订单记录");
  9463. }
  9464. }
  9465. public void del_erp_persuade()
  9466. {
  9467. if (UrlPostParmsCheck("ID"))
  9468. {
  9469. int eid = GetPostInt("ID");
  9470. CeErpPersuade.Del(eid);
  9471. returnSuccessMsg("操作成功");
  9472. return;
  9473. }
  9474. }
  9475. public void get_erp_oldcustoupload()
  9476. {
  9477. DataStruct dStruct = GetPostStruct();
  9478. List<string> lw = new List<string>();
  9479. string buyernick = GetPostString("buyer_nick");
  9480. if (buyernick.Length > 0)
  9481. {
  9482. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9483. }
  9484. else
  9485. return;
  9486. dStruct.Order = "pay_time desc";
  9487. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9488. DataTable dt = null;
  9489. dt = WebCache.GetData("view_erptradecell", dStruct);
  9490. writeGridDataTableJson(dStruct.TotalCount, dt);
  9491. }
  9492. public void get_erp_checkorderlist()
  9493. {
  9494. DataStruct dStruct = GetPostStruct();
  9495. List<string> lw = new List<string>();
  9496. string tid = GetPostString("ctid");
  9497. if (tid.Length > 0)
  9498. {
  9499. string select_tid = getTidByCtid(tid);
  9500. lw.Add(string.Format("tid='{0}'", select_tid));
  9501. }
  9502. string shopname = GetPostString("shopname");
  9503. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9504. string buyernick = GetPostString("buyer_nick");
  9505. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9506. string customer = GetPostString("customer");
  9507. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9508. string design = GetPostString("design");
  9509. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9510. string orderState = GetPostString("orderState");
  9511. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9512. string address = GetPostString("address");
  9513. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9514. string sellermemo = GetPostString("seller_memo");
  9515. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9516. string supplier = GetPostString("supplier");
  9517. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9518. {
  9519. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9520. }
  9521. else
  9522. {
  9523. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9524. }
  9525. string date1 = GetPostString("date1");
  9526. string date2 = GetPostString("date2");
  9527. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9528. if (dw.Length > 0) lw.Add(dw);
  9529. string placedate1 = GetPostString("placedate1");
  9530. string placedate2 = GetPostString("placedate2");
  9531. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9532. if (fdw.Length > 0) lw.Add(fdw);
  9533. string price1 = GetPostString("price1");
  9534. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9535. string price2 = GetPostString("price2");
  9536. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9537. string checkst = GetPostString("checkstate");
  9538. if (checkst.Length > 0 && "10".Equals(checkst))
  9539. {
  9540. lw.Add(string.Format("CheckOut>0"));
  9541. }
  9542. else
  9543. {
  9544. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9545. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9546. }
  9547. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9548. {
  9549. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9550. }
  9551. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9552. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9553. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9554. writeGridDataTableJson(dStruct.TotalCount, dt);
  9555. }
  9556. public void ins_erp_startCheck()
  9557. {
  9558. if (UrlPostParmsCheck("ctid"))
  9559. {
  9560. string eid = GetPostString("ctid");
  9561. CeErpTradeCell entity = null;
  9562. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9563. if (entity != null)
  9564. {
  9565. entity.MemoOpt = 4;
  9566. entity.UpdateTime = DateTime.Now;
  9567. entity.Update();
  9568. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9569. CeErpSukuraData.createInfo(entity.ctid, 6);
  9570. returnSuccessMsg("操作成功!");
  9571. return;
  9572. }
  9573. returnErrorMsg("找不到记录");
  9574. }
  9575. }
  9576. public void upd_erp_sendXlw()
  9577. {
  9578. if (UrlPostParmsCheck("ctid"))
  9579. {
  9580. string eid = GetPostString("ctid");
  9581. CeErpTradeCell entity = null;
  9582. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9583. if (entity != null)
  9584. {
  9585. if (entity.IsSendGift == 1)
  9586. {
  9587. returnErrorMsg("请勿重复标记");
  9588. return;
  9589. }
  9590. entity.IsSendGift = 1;
  9591. entity.Update();
  9592. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9593. returnSuccessMsg("操作成功!");
  9594. return;
  9595. }
  9596. returnErrorMsg("找不到记录");
  9597. }
  9598. }
  9599. public void cancel_sendXlw()
  9600. {
  9601. if (UrlPostParmsCheck("ctid"))
  9602. {
  9603. string eid = GetPostString("ctid");
  9604. CeErpTradeCell entity = null;
  9605. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9606. if (entity != null)
  9607. {
  9608. if (entity.IsSendGift == 0)
  9609. {
  9610. returnErrorMsg("未标记小礼物");
  9611. return;
  9612. }
  9613. entity.IsSendGift = 0;
  9614. entity.Update();
  9615. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9616. returnSuccessMsg("操作成功!");
  9617. return;
  9618. }
  9619. returnErrorMsg("找不到记录");
  9620. }
  9621. }
  9622. public void get_erp_designbill()
  9623. {
  9624. DataStruct dStruct = GetPostStruct();
  9625. List<string> lw = new List<string>();
  9626. int isMy = GetInt("my");
  9627. if (isMy == 1)
  9628. {
  9629. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9630. }
  9631. string tid = GetPostString("tid");
  9632. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9633. string userName = GetPostString("design");
  9634. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9635. string price1 = GetPostString("price1");
  9636. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9637. string price2 = GetPostString("price2");
  9638. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9639. string rePrice1 = GetPostString("rePrice1");
  9640. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9641. string rePrice2 = GetPostString("rePrice2");
  9642. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9643. string designerType = GetPostString("designerType");
  9644. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9645. string orderState = GetPostString("orderState");
  9646. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9647. string endTime1 = GetPostString("endTime1");
  9648. string endTime2 = GetPostString("endTime2");
  9649. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9650. if (dw.Length > 0) lw.Add(dw);
  9651. string isDk = GetPostString("isDk");
  9652. if (isDk == "1")
  9653. {
  9654. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9655. }
  9656. else if (isDk == "0")
  9657. {
  9658. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9659. }
  9660. dStruct.Order = "oid, create_time desc";
  9661. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9662. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9663. writeGridDataTableJson(dStruct.TotalCount, dt);
  9664. }
  9665. public void upd_erp_designerbill()
  9666. {
  9667. if (UrlPostParmsCheck("ID"))
  9668. {
  9669. string eid = GetPostString("ID");
  9670. CeErpDesignerBill entity = null;
  9671. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9672. if (entity != null)
  9673. {
  9674. if (GetPostDouble("designerpirce") > 0)
  9675. {
  9676. entity.realPrice = GetPostDouble("designerpirce");
  9677. entity.update_time = DateTime.Now;
  9678. entity.update_u_id = CurrentUser.UserID;
  9679. entity.update_u_name = CurrentUser.UserName;
  9680. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9681. entity.Update();
  9682. returnSuccessMsg("操作成功!");
  9683. return;
  9684. }
  9685. else
  9686. {
  9687. entity.price = GetPostDouble("price");
  9688. entity.update_time = DateTime.Now;
  9689. entity.update_u_id = CurrentUser.UserID;
  9690. entity.update_u_name = CurrentUser.UserName;
  9691. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9692. entity.Update();
  9693. returnSuccessMsg("操作成功!");
  9694. return;
  9695. }
  9696. }
  9697. returnErrorMsg("找不到记录");
  9698. }
  9699. }
  9700. public void audit_erp_designerbill()
  9701. {
  9702. if (UrlPostParmsCheck("ID"))
  9703. {
  9704. string eid = GetPostString("ID");
  9705. CeErpDesignerBill entity = null;
  9706. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9707. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9708. if (entity != null)
  9709. {
  9710. entity.realPrice = GetPostDouble("designerpirce");
  9711. entity.update_time = DateTime.Now;
  9712. entity.update_u_id = CurrentUser.UserID;
  9713. entity.update_u_name = CurrentUser.UserName;
  9714. entity.isAudit = 1;
  9715. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9716. entity.Update();
  9717. if (orderEntity != null)
  9718. {
  9719. orderEntity.IsReadTag = 3;
  9720. orderEntity.Update();
  9721. }
  9722. returnSuccessMsg("操作成功!");
  9723. return;
  9724. }
  9725. returnErrorMsg("找不到记录");
  9726. }
  9727. }
  9728. public void all_audit_erp_designerbill()
  9729. {
  9730. if (UrlPostParmsCheck("idList"))
  9731. {
  9732. string[] list = GetPostString("idList").Split(',');
  9733. CeErpDesignerBill entity = null;
  9734. for (int i = 0; i < list.Length; i++)
  9735. {
  9736. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9737. if (entity == null) return;
  9738. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9739. if (orderEntity == null) return;
  9740. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9741. entity.update_time = DateTime.Now;
  9742. entity.update_u_id = CurrentUser.UserID;
  9743. entity.update_u_name = CurrentUser.UserName;
  9744. entity.isAudit = 1;
  9745. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9746. entity.Update();
  9747. orderEntity.IsReadTag = 3;
  9748. orderEntity.Update();
  9749. }
  9750. returnSuccessMsg("操作成功!");
  9751. return;
  9752. }
  9753. }
  9754. public void get_erp_sameorders()
  9755. {
  9756. if (UrlPostParmsCheck("ctid"))
  9757. {
  9758. string eid = GetPostString("ctid");
  9759. CeErpTradeCell entity = null;
  9760. entity = CeErpTradeCell.GetByCtid(eid);
  9761. if (entity != null)
  9762. {
  9763. StringBuilder sql = new StringBuilder();
  9764. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9765. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9766. var res = new
  9767. {
  9768. data = dt.Rows.Count
  9769. };
  9770. string ro_jsond = JsonConvert.SerializeObject(res);
  9771. returnSuccess(ro_jsond);
  9772. return;
  9773. }
  9774. returnErrorMsg("未找到订单");
  9775. return;
  9776. }
  9777. returnErrorMsg("缺少必要的参数");
  9778. }
  9779. public void get_erp_islasthavesameorder()
  9780. {
  9781. if (UrlPostParmsCheck("ctid"))
  9782. {
  9783. string eid = GetPostString("ctid");
  9784. string[] ctidList = eid.Split(',');
  9785. StringBuilder sql = new StringBuilder();
  9786. string tisCtid = "";
  9787. foreach (string ctid in ctidList)
  9788. {
  9789. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9790. if (entity != null)
  9791. {
  9792. sql = new StringBuilder();
  9793. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9794. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9795. if (dth.Rows.Count > 0)
  9796. {
  9797. tisCtid += entity.ctid;
  9798. tisCtid += ",";
  9799. }
  9800. }
  9801. }
  9802. if (tisCtid.Length > 0)
  9803. {
  9804. var res = new
  9805. {
  9806. data = tisCtid
  9807. };
  9808. string ro_jsond = JsonConvert.SerializeObject(res);
  9809. returnSuccess(ro_jsond);
  9810. }
  9811. else
  9812. {
  9813. var res = new
  9814. {
  9815. data = ""
  9816. };
  9817. string ro_jsond = JsonConvert.SerializeObject(res);
  9818. returnSuccess(ro_jsond);
  9819. }
  9820. return;
  9821. }
  9822. returnErrorMsg("缺少必要的参数");
  9823. }
  9824. public void file_client_down_url()
  9825. {
  9826. if (!UrlPostParmsCheck("userId"))
  9827. {
  9828. returnErrorMsg("缺少必要的参数");
  9829. }
  9830. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9831. }
  9832. public void checkout_form_data()
  9833. {
  9834. if (!UrlPostParmsCheck("tid"))
  9835. {
  9836. returnErrorMsg("缺少必要的参数");
  9837. }
  9838. string tid = GetPostString("tid");
  9839. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9840. if (ceErpOrderFormData != null)
  9841. {
  9842. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9843. returnSuccess(ro_jsond);
  9844. return;
  9845. }
  9846. returnErrorMsg("尚未有文件!");
  9847. }
  9848. public void back_supplier_audit()
  9849. {
  9850. int userId = CurrentUser.UserID;
  9851. StringBuilder sql = new StringBuilder();
  9852. 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);
  9853. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9854. if (dt.Rows.Count > 0)
  9855. {
  9856. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9857. }
  9858. else
  9859. {
  9860. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9861. }
  9862. }
  9863. public void back_supplier_query()
  9864. {
  9865. string eid = GetPostString("ctid");
  9866. if (eid != "")
  9867. {
  9868. StringBuilder sql = new StringBuilder();
  9869. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9870. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9871. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9872. }
  9873. else
  9874. {
  9875. returnErrorMsg("找不到订单记录");
  9876. return;
  9877. }
  9878. }
  9879. public void verified_to_order()
  9880. {
  9881. int userId = CurrentUser.UserID;
  9882. StringBuilder sql = new StringBuilder();
  9883. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9884. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9885. if (dt.Rows.Count > 0)
  9886. {
  9887. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9888. }
  9889. else
  9890. {
  9891. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9892. }
  9893. }
  9894. public void upd_supplier_audit()
  9895. {
  9896. if (UrlPostParmsCheck("ctid"))
  9897. {
  9898. string eid = GetPostString("ctid");
  9899. string reason = GetPostString("returnreason");
  9900. CeErpTradeCell entity = null;
  9901. CeWithdraw withdraw = null;
  9902. withdraw = CeWithdraw.GetByTid(eid);
  9903. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9904. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9905. {
  9906. if (withdraw != null)
  9907. {
  9908. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9909. {
  9910. returnSuccessMsg("您没有权限操作!");
  9911. return;
  9912. }
  9913. else
  9914. {
  9915. if (reason.Equals("1"))
  9916. {
  9917. if (entity.OrderState == -1)
  9918. {
  9919. if (entity.FinishPlaceTime == null)
  9920. {
  9921. entity.OrderState = 2;
  9922. }
  9923. else
  9924. {
  9925. entity.OrderState = 6;
  9926. }
  9927. }
  9928. entity.Update();
  9929. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9930. if (withdraw != null)
  9931. {
  9932. withdraw.status = int.Parse(reason);
  9933. withdraw.Update();
  9934. }
  9935. returnSuccessMsg("操作成功!");
  9936. return;
  9937. }
  9938. else
  9939. {
  9940. withdraw.status = int.Parse(reason);
  9941. withdraw.acknowledgingtime = DateTime.Now;
  9942. withdraw.Update();
  9943. returnSuccessMsg("查看详细请点击线下订单查询");
  9944. return;
  9945. }
  9946. }
  9947. }
  9948. // 第一个字符是 'N'
  9949. }
  9950. if (eid[0] != 'N')
  9951. {
  9952. }
  9953. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9954. {
  9955. entity.IsVerifyToSupplier = false;
  9956. entity.IsReturn = 1;
  9957. entity.ReturnTime = DateTime.Now;
  9958. entity.ReturnReason = reason;
  9959. if (entity.OrderState == 6)
  9960. {
  9961. entity.OrderState = 5;
  9962. }
  9963. entity.Update();
  9964. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9965. if (withdraw != null)
  9966. {
  9967. withdraw.status = int.Parse(reason);
  9968. withdraw.Update();
  9969. }
  9970. returnSuccessMsg("操作成功!");
  9971. return;
  9972. }
  9973. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9974. {
  9975. ;
  9976. if (withdraw != null)
  9977. {
  9978. withdraw.status = int.Parse(reason);
  9979. withdraw.acknowledgingtime = DateTime.Now;
  9980. withdraw.Update();
  9981. returnSuccessMsg("供应商取消撤回!");
  9982. return;
  9983. }
  9984. }
  9985. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9986. {
  9987. if (entity.OrderState == -1)
  9988. {
  9989. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  9990. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9991. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  9992. {
  9993. returnErrorMsg("台湾客户需填写身份证!");
  9994. return;
  9995. }
  9996. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9997. {
  9998. returnErrorMsg("订单spu没有确认无法通过审核!");
  9999. return;
  10000. }
  10001. if (entity.FinishPlaceTime == null)
  10002. {
  10003. entity.OrderState = 2;
  10004. }
  10005. else
  10006. {
  10007. entity.OrderState = 3;
  10008. }
  10009. commonHelper.getCytPrice(entity);
  10010. }
  10011. entity.Update();
  10012. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10013. if (withdraw != null)
  10014. {
  10015. withdraw.status = int.Parse(reason);
  10016. withdraw.Update();
  10017. }
  10018. returnSuccessMsg("操作成功!");
  10019. return;
  10020. }
  10021. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10022. {
  10023. if (withdraw == null)
  10024. {
  10025. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10026. return;
  10027. }
  10028. }
  10029. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10030. {
  10031. if (withdraw != null)
  10032. {
  10033. withdraw.status = int.Parse(reason);
  10034. withdraw.acknowledgingtime = DateTime.Now;
  10035. withdraw.Update();
  10036. returnSuccessMsg("查看详细请点击线下订单查询");
  10037. return;
  10038. }
  10039. }
  10040. return;
  10041. }
  10042. }
  10043. //校验报价
  10044. public void refund_order_tip()
  10045. {
  10046. int userid = CurrentUser.UserID;
  10047. int sectionId = CurrentUser.UserPost.OrgID;
  10048. StringBuilder sql = new StringBuilder();
  10049. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10050. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10051. List<string> ids = new List<string>();
  10052. if (dth.Rows.Count > 0)
  10053. {
  10054. foreach (DataRow dr in dth.Rows)
  10055. {
  10056. ids.Add(dr["ID"].ToString());
  10057. }
  10058. try
  10059. {
  10060. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10061. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10062. }
  10063. catch (Exception ex)
  10064. {
  10065. }
  10066. }
  10067. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10068. }
  10069. public void refund_order_Design()
  10070. {
  10071. int userid = CurrentUser.UserID;
  10072. int sectionId = CurrentUser.UserPost.OrgID;
  10073. StringBuilder sql = new StringBuilder();
  10074. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10075. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10076. List<string> ids = new List<string>();
  10077. if (dth.Rows.Count > 0)
  10078. {
  10079. foreach (DataRow dr in dth.Rows)
  10080. {
  10081. ids.Add(dr["ID"].ToString());
  10082. }
  10083. try
  10084. {
  10085. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10086. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10087. }
  10088. catch (Exception ex)
  10089. {
  10090. }
  10091. }
  10092. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10093. }
  10094. public void change_order_info()
  10095. {
  10096. int userid = CurrentUser.UserID;
  10097. StringBuilder sql = new StringBuilder();
  10098. 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);
  10099. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10100. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10101. }
  10102. public void change_win_mome()
  10103. {
  10104. if (UrlPostParmsCheck("id,ctid"))
  10105. {
  10106. string id = GetPostString("id");
  10107. string ctid = GetPostString("ctid");
  10108. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10109. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10110. if (ce == null || ceErpMessageTip == null)
  10111. {
  10112. returnSuccessMsg("未找到对应的订单!");
  10113. return;
  10114. }
  10115. if (ce.OrderState >= 5)
  10116. {
  10117. ceErpMessageTip.isVisit = true;
  10118. ceErpMessageTip.Update();
  10119. returnSuccessMsg("已上传文件无法修改!");
  10120. return;
  10121. }
  10122. int type = GetPostInt("type");
  10123. string content = GetPostString("content");
  10124. if (type == 0)
  10125. {
  10126. content = content.Replace("(", "(");
  10127. content = content.Replace(")", ")");
  10128. string check = MidStrEx(content, "(", ")").Trim();
  10129. if (string.IsNullOrEmpty(check))
  10130. {
  10131. returnSuccessMsg("文件名格式不正确");
  10132. return;
  10133. }
  10134. }
  10135. ce.seller_memo = content;
  10136. ce.Update();
  10137. ceErpMessageTip.isVisit = true;
  10138. ceErpMessageTip.Update();
  10139. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10140. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10141. ApiVo apiVo = new ApiVo();
  10142. apiVo.orderNumber = ce.ctid;
  10143. apiVo.actionName = "demandDesign";
  10144. apiVo.orderRemarks = content;
  10145. apiVo.demandExamine = type + 1;
  10146. designHelper.API_WorkCore(apiVo);//demandDesign
  10147. returnSuccessMsg("修改成功!");
  10148. }
  10149. }
  10150. public static string MidStrEx(string sourse, string startstr, string endstr)
  10151. {
  10152. string result = string.Empty;
  10153. int startindex, endindex;
  10154. try
  10155. {
  10156. startindex = sourse.IndexOf(startstr);
  10157. if (startindex == -1)
  10158. return result;
  10159. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10160. endindex = tmpstr.IndexOf(endstr);
  10161. if (endindex == -1)
  10162. return result;
  10163. result = tmpstr.Remove(endindex);
  10164. }
  10165. catch (Exception ex)
  10166. {
  10167. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10168. }
  10169. return result;
  10170. }
  10171. public void refund_order_list()
  10172. {
  10173. int userid = CurrentUser.UserID;
  10174. int sectionId = CurrentUser.UserPost.OrgID;
  10175. StringBuilder sql = new StringBuilder();
  10176. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10177. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10178. DataStruct dStruct = GetPostStruct();
  10179. DataTable dt = null;
  10180. List<string> ids = new List<string>();
  10181. List<string> tids = new List<string>();
  10182. if (dth.Rows.Count > 0)
  10183. {
  10184. foreach (DataRow dr in dth.Rows)
  10185. {
  10186. tids.Add("'" + dr["tid"].ToString() + "'");
  10187. ids.Add(dr["id"].ToString());
  10188. }
  10189. try
  10190. {
  10191. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10192. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10193. List<string> lw = new List<string>();
  10194. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10195. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10196. dt = WebCache.GetData("view_orderlist", dStruct);
  10197. }
  10198. catch (Exception ex)
  10199. {
  10200. }
  10201. }
  10202. writeGridDataTableJson(dStruct.TotalCount, dt);
  10203. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10204. }
  10205. //新增
  10206. public void order_batch_downloads()
  10207. {
  10208. string ceid = GetPostString("tid");
  10209. String[] tid = ceid.Split(',');
  10210. order_batch_caiyingtong(tid);
  10211. /* (string success, string errors) = UploadFiles(tid);
  10212. returnSuccessMsg(success + errors);*/
  10213. return;
  10214. }
  10215. //报价接口
  10216. public void Get_To_Quote()
  10217. {
  10218. string ceid = GetPostString("ctid");
  10219. if (ceid != null)
  10220. {
  10221. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10222. if (entity != null)
  10223. {
  10224. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10225. {
  10226. return;
  10227. }
  10228. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10229. double price = 0;
  10230. if (cp == null)
  10231. {
  10232. JObject jsonObject12 = new JObject
  10233. {
  10234. { "UserId", "77886" },
  10235. { "Pwd", "lt666888" },
  10236. { "Filename", entity.seller_memo }
  10237. };
  10238. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10239. JObject jsonObjects1 = JObject.Parse(response1);
  10240. string ms1g = (string)jsonObjects1["msg"];
  10241. if (ms1g == "报价成功")
  10242. {
  10243. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10244. string data = (string)jsonObject1["price"];
  10245. 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 + "');";
  10246. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10247. returnSuccessMsg("获取报价成功:" + data);
  10248. price = Convert.ToDouble(data);
  10249. }
  10250. else
  10251. {
  10252. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10253. return;
  10254. }
  10255. }
  10256. String[] beizhu = entity.seller_memo.Split('-');
  10257. String chanp = "";
  10258. if (beizhu.Length > 0)
  10259. {
  10260. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10261. }
  10262. else
  10263. {
  10264. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10265. }
  10266. JObject jsonObject = new JObject
  10267. {
  10268. { "UserId", "77886" },
  10269. { "Pwd", "lt666888" },
  10270. { "Filename", chanp }
  10271. };
  10272. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10273. JObject jsonObjects = JObject.Parse(response);
  10274. string msg = (string)jsonObjects["msg"];
  10275. if (msg == "报价成功")
  10276. {
  10277. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10278. string data = (string)jsonObject1["price"];
  10279. 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 + "');";
  10280. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10281. returnSuccessMsg("获取报价成功:" + data);
  10282. price = Convert.ToDouble(data);
  10283. }
  10284. else
  10285. {
  10286. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10287. return;
  10288. }
  10289. if (price > 0)
  10290. {
  10291. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10292. if (ceErpTradeCellExtend == null)
  10293. {
  10294. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10295. ceErpTradeCellExtend.ctid = entity.ctid;
  10296. ceErpTradeCellExtend.payment_cyt = price;
  10297. ceErpTradeCellExtend.Create();
  10298. }
  10299. else
  10300. {
  10301. ceErpTradeCellExtend.payment_cyt = price;
  10302. ceErpTradeCellExtend.Update();
  10303. }
  10304. }
  10305. return;
  10306. }
  10307. }
  10308. else
  10309. {
  10310. returnErrorMsg("请至少选择一条数据");
  10311. return;
  10312. }
  10313. }
  10314. //新增
  10315. public void order_To_Supplier()
  10316. {
  10317. string ceid = GetPostString("tid");
  10318. String[] tid = ceid.Split(',');
  10319. if (tid.Length > 0)
  10320. {
  10321. try
  10322. {
  10323. for (int i = 0; i < tid.Length; i++)
  10324. {
  10325. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10326. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10327. entity.SupplierId = suid;
  10328. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10329. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10330. entity.Update();
  10331. }
  10332. }
  10333. catch (Exception ex)
  10334. {
  10335. returnErrorMsg("自动匹配供应商失败");
  10336. return;
  10337. }
  10338. }
  10339. else
  10340. {
  10341. returnErrorMsg("请至少选择一条数据");
  10342. return;
  10343. }
  10344. returnSuccessMsg("自动匹配供应商成功");
  10345. return;
  10346. }
  10347. public (string, string) UploadFiles(string[] urls)
  10348. {
  10349. string success = "";
  10350. string errors = "";
  10351. int userid = CurrentUser.UserID;
  10352. foreach (string url in urls)
  10353. {
  10354. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10355. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10356. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10357. {
  10358. JObject jsonObject = new JObject
  10359. {
  10360. { "Userid", "77886" },
  10361. { "pwd", "cyt86435015" },
  10362. { "content", base64FileContent },
  10363. { "ext", Path.GetExtension(fileName) }
  10364. };
  10365. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10366. JObject jsonObjects = JObject.Parse(response);
  10367. string msg = (string)jsonObjects["msg"];
  10368. if (msg.Equals("上传成功"))
  10369. {
  10370. success += url + " 上传成功";
  10371. }
  10372. else
  10373. {
  10374. errors += url + " 上传失败";
  10375. }
  10376. }
  10377. else
  10378. {
  10379. errors += url + " 格式出现问题";
  10380. }
  10381. }
  10382. if (urls.Length == 0)
  10383. {
  10384. return (success, errors);
  10385. }
  10386. return (success, errors);
  10387. }
  10388. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10389. {
  10390. return true; //总是接受
  10391. }
  10392. public static string HttpPost(string url, string param = null)
  10393. {
  10394. HttpWebRequest request;
  10395. //如果是发送HTTPS请求
  10396. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10397. {
  10398. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10399. request = WebRequest.Create(url) as HttpWebRequest;
  10400. request.ProtocolVersion = HttpVersion.Version10;
  10401. }
  10402. else
  10403. {
  10404. request = WebRequest.Create(url) as HttpWebRequest;
  10405. }
  10406. request.Method = "POST";
  10407. request.ContentType = "application/json";
  10408. request.Accept = "*/*";
  10409. request.Timeout = 120000;
  10410. request.AllowAutoRedirect = false;
  10411. StreamWriter requestStream = null;
  10412. WebResponse response = null;
  10413. string responseStr = null;
  10414. try
  10415. {
  10416. requestStream = new StreamWriter(request.GetRequestStream());
  10417. requestStream.Write(param);
  10418. requestStream.Close();
  10419. response = request.GetResponse();
  10420. if (response != null)
  10421. {
  10422. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10423. responseStr = reader.ReadToEnd();
  10424. reader.Close();
  10425. }
  10426. }
  10427. catch (Exception ex)
  10428. {
  10429. return ex.Message;
  10430. }
  10431. finally
  10432. {
  10433. request = null;
  10434. requestStream = null;
  10435. response = null;
  10436. }
  10437. return responseStr;
  10438. }
  10439. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10440. {
  10441. string base64FileContent;
  10442. string fileName;
  10443. using (WebClient webClient = new WebClient())
  10444. {
  10445. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10446. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10447. {
  10448. using (Stream stream = response.GetResponseStream())
  10449. {
  10450. using (MemoryStream memoryStream = new MemoryStream())
  10451. {
  10452. stream.CopyTo(memoryStream);
  10453. byte[] fileBytes = memoryStream.ToArray();
  10454. base64FileContent = Convert.ToBase64String(fileBytes);
  10455. fileName = response.Headers["Content-Disposition"];
  10456. if (!string.IsNullOrEmpty(fileName))
  10457. {
  10458. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10459. if (index >= 0)
  10460. {
  10461. fileName = fileName.Substring(index + 9).Trim('\"');
  10462. }
  10463. }
  10464. else
  10465. {
  10466. fileName = Path.GetFileName(downloadUrl);
  10467. }
  10468. }
  10469. }
  10470. }
  10471. }
  10472. return (fileName, base64FileContent);
  10473. }
  10474. //新增
  10475. public void order_batch_caiyingtong(string[] downloadUrls)
  10476. {
  10477. try
  10478. {
  10479. //遍历文件
  10480. DataStruct dStruct = GetPostStruct();
  10481. DataTable dt = null;
  10482. int userid = CurrentUser.UserID;
  10483. List<string> ids = new List<string>();//失败组
  10484. List<string> tids = new List<string>();
  10485. using (WebClient webClient = new WebClient())
  10486. {
  10487. foreach (var url in downloadUrls)
  10488. {
  10489. try
  10490. {
  10491. tids.Add("'" + url + "'");
  10492. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10493. if (entity != null)
  10494. {
  10495. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10496. if (cp == null)
  10497. {
  10498. JObject jsonObject = new JObject
  10499. {
  10500. { "Userid", "77886" },
  10501. { "pwd", "lt666888" },
  10502. { "Filename",entity.seller_memo }
  10503. };
  10504. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10505. JObject jsonObjects = JObject.Parse(response);
  10506. string msg = (string)jsonObjects["msg"];
  10507. if (msg == "报价成功")
  10508. {
  10509. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10510. DownloadAndConvertToBase64(url1);
  10511. }
  10512. else
  10513. {
  10514. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10515. }
  10516. }
  10517. else
  10518. {
  10519. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10520. JObject jsonObject = new JObject
  10521. {
  10522. { "Userid", "77886" },
  10523. { "pwd", "lt666888" },
  10524. { "Filename",chanp }
  10525. };
  10526. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10527. JObject jsonObjects = JObject.Parse(response);
  10528. string msg = (string)jsonObjects["msg"];
  10529. if (msg == "报价成功")
  10530. {
  10531. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10532. DownloadAndConvertToBase64(url1);
  10533. }
  10534. else
  10535. {
  10536. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10537. }
  10538. }
  10539. }
  10540. // 上传文件到FTP
  10541. }
  10542. catch (Exception ex)
  10543. {
  10544. Console.WriteLine($"An error occurred: {ex.Message}");
  10545. }
  10546. }
  10547. List<string> lw = new List<string>();
  10548. lw.Add(string.Format("( OrderState < 6 )"));
  10549. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10550. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10551. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10552. if (dt.Rows.Count > 0)
  10553. {
  10554. foreach (DataRow dr in dt.Rows)
  10555. {
  10556. ids.Add(dr["ctid"].ToString());
  10557. }
  10558. }
  10559. String ErrorMsgs = "";
  10560. foreach (String id in ids)
  10561. {
  10562. ErrorMsgs += id + ",";
  10563. }
  10564. if (ErrorMsgs.Length > 1)
  10565. {
  10566. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10567. }
  10568. if (ErrorMsgs.Length < 1)
  10569. {
  10570. ErrorMsgs = "上传成功";
  10571. returnSuccessMsg(ErrorMsgs);
  10572. }
  10573. else
  10574. {
  10575. returnErrorMsg("以下订单" + ErrorMsgs);
  10576. }
  10577. }
  10578. // 删除文件夹及其内容
  10579. /* Directory.Delete(localDirectory, true);*/
  10580. }
  10581. catch { }
  10582. }
  10583. public void get_center_data()
  10584. {
  10585. int userId = CurrentUser.UserID;
  10586. string postCode = CurrentUser.UserPost.Post.Code;
  10587. List<string> lw = new List<string>();
  10588. List<string> ww = new List<string>();
  10589. DateTime currentTime = DateTime.Now;
  10590. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10591. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10592. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10593. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10594. string sql = " SELECT ";
  10595. string startTime = "2023-10-01 11:22:31";
  10596. //设计
  10597. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10598. {
  10599. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10600. 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));
  10601. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10602. 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));
  10603. }
  10604. //客服
  10605. else if (postCode == "CustomerService" || postCode == "Director")
  10606. {
  10607. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10608. 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));
  10609. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10610. 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));
  10611. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10612. 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));
  10613. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10614. 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));
  10615. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10616. 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));
  10617. }
  10618. //售后
  10619. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10620. {
  10621. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10622. 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));
  10623. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10624. 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));
  10625. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10626. 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));
  10627. }
  10628. //下单部
  10629. else if (postCode == "Place" || postCode == "PlaceMr")
  10630. {
  10631. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10632. 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));
  10633. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10634. 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));
  10635. }
  10636. //车间
  10637. else if (postCode == "Supplier")
  10638. {
  10639. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10640. 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));
  10641. }
  10642. DataTable dt = new DataTable();
  10643. if (lw.Count > 0)
  10644. {
  10645. sql += string.Join(" , ", lw);
  10646. sql += " FROM ";
  10647. sql += string.Join(" , ", ww);
  10648. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10649. }
  10650. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10651. }
  10652. public void get_center_data_list()
  10653. {
  10654. int userId = CurrentUser.UserID;
  10655. string postCode = CurrentUser.UserPost.Post.Code;
  10656. string shopIds = CurrentUser.User.pemShop;
  10657. DataStruct dStruct = GetPostStruct();
  10658. List<string> lw = new List<string>();
  10659. DateTime currentTime = DateTime.Now;
  10660. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10661. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10662. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10663. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10664. string startTime = "2023-10-01 11:22:31";
  10665. int order_type = GetPostInt("order_type");
  10666. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10667. {
  10668. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10669. if (order_type == 0)
  10670. {
  10671. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10672. }
  10673. else if (order_type == 3)
  10674. {
  10675. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10676. }
  10677. else
  10678. {
  10679. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10680. }
  10681. }
  10682. //客服
  10683. if (postCode == "CustomerService" || postCode == "Director")
  10684. {
  10685. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10686. if (order_type == 0)
  10687. {
  10688. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10689. }
  10690. else if (order_type == 1)
  10691. {
  10692. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10693. }
  10694. else if (order_type == 2)
  10695. {
  10696. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10697. }
  10698. else if (order_type == 3)
  10699. {
  10700. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10701. }
  10702. else if (order_type == 4)
  10703. {
  10704. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10705. }
  10706. else
  10707. {
  10708. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10709. }
  10710. }
  10711. //售后
  10712. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10713. {
  10714. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10715. if (shopIds != "")
  10716. {
  10717. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10718. }
  10719. if (order_type == 2)
  10720. {
  10721. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10722. }
  10723. else if (order_type == 4)
  10724. {
  10725. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10726. }
  10727. else if (order_type == 5)
  10728. {
  10729. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10730. }
  10731. else
  10732. {
  10733. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10734. }
  10735. }
  10736. //下单部
  10737. if (postCode == "Place" || postCode == "PlaceMr")
  10738. {
  10739. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10740. if (shopIds != "")
  10741. {
  10742. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10743. }
  10744. else if (order_type == 1)
  10745. {
  10746. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10747. }
  10748. else if (order_type == 2)
  10749. {
  10750. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10751. }
  10752. else
  10753. {
  10754. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10755. }
  10756. }
  10757. //车间
  10758. if (postCode == "Supplier")
  10759. {
  10760. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10761. if (order_type == 5)
  10762. {
  10763. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10764. }
  10765. else
  10766. {
  10767. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10768. }
  10769. }
  10770. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10771. dStruct.Fileds = "tid,ctid";
  10772. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10773. writeGridDataTableJson(dStruct.TotalCount, dt);
  10774. }
  10775. public void aftersale_audit_master()
  10776. {
  10777. if (UrlPostParmsCheck("ctid"))
  10778. {
  10779. string ctid = GetPostString("ctid");
  10780. if (ctid.Length > 0)
  10781. {
  10782. bool result = aftersale_data_change(ctid);
  10783. if (result)
  10784. {
  10785. returnSuccessMsg("修改成功!");
  10786. return;
  10787. }
  10788. }
  10789. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10790. }
  10791. }
  10792. public void aftersale_batch_audit_master()
  10793. {
  10794. if (UrlPostParmsCheck("ctids"))
  10795. {
  10796. string ctids = GetPostString("ctids");
  10797. if (ctids.Length > 0)
  10798. {
  10799. List<string> list = new List<string>();
  10800. string[] ctid_list = ctids.Split(',');
  10801. foreach (var item in ctid_list)
  10802. {
  10803. bool result = aftersale_data_change(item);
  10804. if (!result)
  10805. {
  10806. list.Add(item);
  10807. }
  10808. }
  10809. if (list.Count > 0)
  10810. {
  10811. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10812. return;
  10813. }
  10814. returnSuccessMsg("修改成功!");
  10815. return;
  10816. }
  10817. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10818. }
  10819. }
  10820. public bool aftersale_data_change(string ctid)
  10821. {
  10822. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10823. if (ceErpTradeCell != null)
  10824. {
  10825. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10826. ceErpTradeCell.AfterSaleSupplierState = 0;
  10827. StringBuilder sql = new StringBuilder();
  10828. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10829. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10830. CeErpTradeResponsible.DelByTid(ctid, 0);
  10831. 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 == "不理赔")
  10832. {
  10833. CeErpTradeResponsible.DelByTid(ctid, 1);
  10834. ceErpTradeCell.AfterSaleSupplierState = 1;
  10835. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10836. ceErpTradeCell.AfterSaleState = 4;
  10837. }
  10838. else
  10839. {
  10840. ceErpTradeCell.AfterSaleState = 3;
  10841. }
  10842. bool needCyt = false;
  10843. if (dt != null)
  10844. {
  10845. if (dt.Rows.Count == 1)
  10846. {
  10847. bool isEnd = false;
  10848. foreach (DataRow dr in dt.Rows)
  10849. {
  10850. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10851. {
  10852. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10853. isEnd = true;
  10854. }
  10855. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10856. {
  10857. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10858. isEnd = true;
  10859. }
  10860. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10861. {
  10862. needCyt = true;
  10863. }
  10864. }
  10865. if (isEnd)
  10866. {
  10867. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10868. ceErpTradeCell.AfterSaleState = 4;
  10869. ceErpTradeCell.AfterSaleSupplierState = 1;
  10870. }
  10871. }
  10872. else
  10873. {
  10874. bool isAll = true;
  10875. foreach (DataRow dr in dt.Rows)
  10876. {
  10877. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10878. {
  10879. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10880. continue;
  10881. }
  10882. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10883. {
  10884. string path = "";
  10885. int OrgID = 0;
  10886. if (!Convert.IsDBNull(dr["OrgPath"]))
  10887. {
  10888. path = dr["OrgPath"].ToString();
  10889. }
  10890. if (!Convert.IsDBNull(dr["OrgID"]))
  10891. {
  10892. OrgID = Convert.ToInt32(dr["OrgID"]);
  10893. }
  10894. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10895. {
  10896. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10897. continue;
  10898. }
  10899. }
  10900. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10901. {
  10902. needCyt = true;
  10903. }
  10904. isAll = false;
  10905. }
  10906. if (isAll)
  10907. {
  10908. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10909. ceErpTradeCell.AfterSaleState = 4;
  10910. ceErpTradeCell.AfterSaleSupplierState = 1;
  10911. }
  10912. }
  10913. }
  10914. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10915. {
  10916. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10917. }
  10918. if (ceErpTradeCell.AfterSaleState == 4)
  10919. {
  10920. ApiVo apiVo = new ApiVo();
  10921. apiVo.orderNumber = ceErpTradeCell.ctid;
  10922. apiVo.actionName = "afterOver";
  10923. designHelper.API_WorkCore(apiVo); //afterOver
  10924. }
  10925. ceErpTradeCell.Update();
  10926. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10927. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10928. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10929. return true;
  10930. }
  10931. return false;
  10932. }
  10933. public void get_erp_wechatorder()
  10934. {
  10935. DataStruct dStruct = GetPostStruct();
  10936. List<string> lw = new List<string>();
  10937. string tid = GetPostString("tid");
  10938. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10939. string shopname = GetPostString("shopname");
  10940. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10941. string buyernick = GetPostString("buyer_nick");
  10942. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10943. string customer = GetPostString("customer");
  10944. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10945. string returndate1 = GetPostString("returndate1");
  10946. string returndate2 = GetPostString("returndate2");
  10947. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10948. if (dw.Length > 0) lw.Add(dw);
  10949. string finishDate1 = GetPostString("finishdate1");
  10950. string finishDate2 = GetPostString("finishdate2");
  10951. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10952. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10953. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10954. dStruct.Order = "created desc";
  10955. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10956. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10957. writeGridDataTableJson(dStruct.TotalCount, dt);
  10958. }
  10959. public void get_erp_wechatlist_sumprice()
  10960. {
  10961. DataStruct dStruct = GetPostStruct();
  10962. List<string> lw = new List<string>();
  10963. string tid = GetPostString("tid");
  10964. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10965. string shopname = GetPostString("shopname");
  10966. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10967. string buyernick = GetPostString("buyer_nick");
  10968. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10969. string customer = GetPostString("customer");
  10970. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10971. string returndate1 = GetPostString("returndate1");
  10972. string returndate2 = GetPostString("returndate2");
  10973. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10974. if (dw.Length > 0) lw.Add(dw);
  10975. string finishDate1 = GetPostString("finishdate1");
  10976. string finishDate2 = GetPostString("finishdate2");
  10977. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10978. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10979. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10980. string mainWhere = string.Join(" and ", lw.ToArray());
  10981. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10982. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10983. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10984. decimal total = 0;
  10985. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10986. {
  10987. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10988. }
  10989. var res = new
  10990. {
  10991. data = total
  10992. };
  10993. string ro_jsond = JsonConvert.SerializeObject(res);
  10994. returnSuccess(ro_jsond);
  10995. return;
  10996. }
  10997. public void get_erp_qr_waitdeliverylist()
  10998. {
  10999. DataStruct dStruct = GetPostStruct();
  11000. List<string> lw = new List<string>();
  11001. string tid = GetPostString("ctid");
  11002. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11003. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11004. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11005. var res_objz = new
  11006. {
  11007. restype = 1,
  11008. data = dt
  11009. };
  11010. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11011. returnSuccess(ro_jsonz);
  11012. }
  11013. public void get_erp_yield_list()
  11014. {
  11015. DataStruct dStruct = GetPostStruct();
  11016. List<string> lw = new List<string>();
  11017. string tid = GetPostString("ctid");
  11018. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11019. string shopname = GetPostString("shopname");
  11020. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11021. string buyernick = GetPostString("buyer_nick");
  11022. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11023. //if (tid.Length == 0 && buyernick.Length == 0)
  11024. //{
  11025. // lw.Add(string.Format("IsRefund<={0}", 1));
  11026. //}
  11027. string customer = GetPostString("customer");
  11028. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11029. string design = GetPostString("design");
  11030. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11031. string orderState = GetPostString("orderState");
  11032. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11033. string address = GetPostString("address");
  11034. 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));
  11035. string sellermemo = GetPostString("seller_memo");
  11036. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11037. string supplier = GetPostString("supplier");
  11038. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11039. string OrderArea = GetPostString("order_area");
  11040. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11041. string placedate1 = GetPostString("placedate1");
  11042. string placedate2 = GetPostString("placedate2");
  11043. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11044. if (fdw.Length > 0) lw.Add(fdw);
  11045. string price1 = GetPostString("price1");
  11046. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11047. string price2 = GetPostString("price2");
  11048. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11049. string unusualCon = GetPostString("unusualcon");
  11050. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11051. string posTag = CurrentUser.UserPost.Post.Code;
  11052. if (posTag == "Supplier")
  11053. {
  11054. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11055. }
  11056. lw.Add(string.Format("OrderState = 6 "));
  11057. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11058. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11059. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11060. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11061. writeGridDataTableJson(dStruct.TotalCount, dt);
  11062. }
  11063. public void change_erp_sup_state()
  11064. {
  11065. if (UrlPostParmsCheck("ctid"))
  11066. {
  11067. string ctid = GetPostString("ctid");
  11068. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11069. if (ceErpTradeCell != null)
  11070. {
  11071. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11072. if (ceErpTradeCellExtend == null)
  11073. {
  11074. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11075. ceErpTradeCellExtend.ctid = ctid;
  11076. ceErpTradeCellExtend.SupState = 1;
  11077. ceErpTradeCellExtend.Create();
  11078. }
  11079. else
  11080. {
  11081. ceErpTradeCellExtend.SupState = 1;
  11082. ceErpTradeCellExtend.Update();
  11083. }
  11084. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11085. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11086. return;
  11087. }
  11088. returnErrorMsg("找不到订单");
  11089. }
  11090. }
  11091. public void supplier_all_downs()
  11092. {
  11093. if (UrlPostParmsCheck("tids"))
  11094. {
  11095. string tids = GetPostString("tids");
  11096. if (tids != null && tids.Length > 0)
  11097. {
  11098. StringBuilder sql = new StringBuilder();
  11099. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11100. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11101. sql = new StringBuilder();
  11102. 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, "下载设计文件");
  11103. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11104. string[] list = tids.Split(',');
  11105. foreach (string ctid in list)
  11106. {
  11107. CeErpSukuraData.createInfo(ctid, 3);
  11108. }
  11109. designHelper.api_approveDesign(tids); //approveDesign
  11110. returnSuccessMsg("下载成功!");
  11111. return;
  11112. }
  11113. returnErrorMsg("下载订单更新失败");
  11114. }
  11115. }
  11116. public void uploaderFileSuccess()
  11117. {
  11118. if (UrlPostParmsCheck("fileName"))
  11119. {
  11120. string fileName = GetPostString("fileName");
  11121. ApiVo apiVo = new ApiVo();
  11122. apiVo.orderNumber = fileName;
  11123. apiVo.actionName = "finishDesign";
  11124. designHelper.API_WorkCore(apiVo);//finishDesign
  11125. returnSuccessMsg("");
  11126. }
  11127. }
  11128. public void get_sample2_order()
  11129. {
  11130. if (UrlPostParmsCheck("ctid"))
  11131. {
  11132. string ctid = GetPostString("ctid");
  11133. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11134. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11135. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11136. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11137. double total = 0.0;
  11138. double order_price = 0.0;
  11139. if (dt_bu.Rows.Count > 0)
  11140. {
  11141. foreach (DataRow dr in dt_bu.Rows)
  11142. {
  11143. total += Convert.ToDouble(dr["payment"]);
  11144. }
  11145. }
  11146. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11147. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11148. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11149. string tid = ctid.Replace("S_", "");
  11150. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11151. double paymant = 0.0;
  11152. if (entity != null)
  11153. {
  11154. paymant = entity.payment;
  11155. }
  11156. string return_reason = "";
  11157. if (dt_after != null && dt_after.Rows.Count > 0)
  11158. {
  11159. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11160. }
  11161. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11162. }
  11163. }
  11164. public void get_erp_design_status()
  11165. {
  11166. string designName = GetPostString("designName");
  11167. DataStruct dStruct = GetPostStruct();
  11168. if (designName.Length > 0)
  11169. {
  11170. 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";
  11171. sql_user += " and Name like '%" + designName + "%'";
  11172. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11173. List<string> ids_list = new List<string>();
  11174. if (user_table.Rows.Count > 0)
  11175. {
  11176. foreach (DataRow item in user_table.Rows)
  11177. {
  11178. ids_list.Add(item["id"].ToString());
  11179. string ids_s = item["TeamIds"].ToString();
  11180. if (ids_s.Length > 0)
  11181. {
  11182. ids_list.AddRange(ids_s.Split(','));
  11183. }
  11184. }
  11185. }
  11186. HashSet<string> set = new HashSet<string>(ids_list);
  11187. ids_list = set.ToList();
  11188. if (ids_list.Count > 0)
  11189. {
  11190. 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));
  11191. dStruct.MainWhere = sql;
  11192. DataTable dt = null;
  11193. dt = WebCache.GetData("view_ErpUser", dStruct);
  11194. writeGridDataTableJson(dStruct.TotalCount, dt);
  11195. }
  11196. }
  11197. }
  11198. public void change_erp_order_price()
  11199. {
  11200. string ctid = GetPostString("ctid");
  11201. double price = GetPostDouble("price");
  11202. if (ctid.Length > 0)
  11203. {
  11204. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11205. if (ceErpTradeCellExtend == null)
  11206. {
  11207. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11208. ceErpTradeCellExtend.ctid = ctid;
  11209. ceErpTradeCellExtend.payment_cyt = price;
  11210. ceErpTradeCellExtend.Create();
  11211. }
  11212. else
  11213. {
  11214. ceErpTradeCellExtend.payment_cyt = price;
  11215. ceErpTradeCellExtend.Update();
  11216. }
  11217. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11218. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11219. {
  11220. ceErpDataSendOrderInfo.isSync = false;
  11221. ceErpDataSendOrderInfo.Update();
  11222. }
  11223. if (ceErpDataSendOrderInfo == null)
  11224. {
  11225. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11226. ceErpDataSendOrderInfo.isSync = false;
  11227. ceErpDataSendOrderInfo.ctid = ctid;
  11228. ceErpDataSendOrderInfo.Create();
  11229. }
  11230. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11231. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11232. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11233. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11234. {
  11235. dataSendOrderBean dataSendOrderBean = null;
  11236. foreach (DataRow item in dth.Rows)
  11237. {
  11238. try
  11239. {
  11240. dataSendOrderBean = new dataSendOrderBean();
  11241. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11242. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11243. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11244. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11245. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11246. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11247. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11248. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11249. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11250. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11251. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11252. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11253. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11254. if (result != null)
  11255. {
  11256. if ("0".Equals(result.errcode))
  11257. {
  11258. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11259. }
  11260. else
  11261. {
  11262. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11263. }
  11264. }
  11265. }
  11266. catch (Exception ex)
  11267. {
  11268. }
  11269. }
  11270. }
  11271. returnSuccessMsg("修改成功!");
  11272. return;
  11273. }
  11274. returnErrorMsg("找不到订单");
  11275. }
  11276. public void find_he_together()
  11277. {
  11278. string ctid = GetPostString("ctid");
  11279. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11280. List<string> list = new List<string>();
  11281. if (ceErpTradeCell != null)
  11282. {
  11283. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11284. {
  11285. 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);
  11286. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11287. if (table != null && table.Rows.Count > 0)
  11288. {
  11289. foreach (TableRow row in table.Rows)
  11290. {
  11291. }
  11292. }
  11293. }
  11294. }
  11295. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11296. }
  11297. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11298. {
  11299. //chy----19
  11300. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11301. //GD-CYT-----64
  11302. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11303. //ZHX----3
  11304. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11305. //JK----97
  11306. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11307. //ZT----70
  11308. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11309. //LHCY-----98
  11310. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11311. //XD-----90
  11312. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11313. //CYCY-----14
  11314. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11315. };
  11316. //其他改名
  11317. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11318. {
  11319. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11320. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11321. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11322. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11323. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11324. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11325. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11326. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11327. };
  11328. //不统计
  11329. List<int> no_suppliers = new List<int>()
  11330. {
  11331. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11332. };
  11333. //配件单
  11334. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11335. {
  11336. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11337. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11338. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11339. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11340. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11341. {"旗杆",new List<string>(){ "班旗" } },
  11342. {"牙签",new List<string>(){ "不干胶" } }
  11343. };
  11344. public void get_place_order_data()
  11345. {
  11346. string date1 = GetPostString("date1");
  11347. string date2 = GetPostString("date2");
  11348. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11349. DateTime start = DateTime.Parse(starttime);
  11350. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11351. DateTime end = DateTime.Parse(endtime);
  11352. if (date1 != null && date1.Length > 0)
  11353. {
  11354. DateTime dateTime = DateTime.Parse(date1);
  11355. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11356. start = DateTime.Parse(starttime);
  11357. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11358. end = DateTime.Parse(endtime);
  11359. }
  11360. if (date2 != null && date2.Length > 0)
  11361. {
  11362. DateTime dateTime = DateTime.Parse(date2);
  11363. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11364. end = DateTime.Parse(endtime);
  11365. }
  11366. 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);
  11367. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11368. //不干胶-----1,卡片-----29
  11369. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11370. foreach (DataRow row in data.Rows)
  11371. {
  11372. int productId = Convert.ToInt32(row["ProductId"]);
  11373. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11374. if (no_suppliers.Contains(supplierId))
  11375. {
  11376. continue;
  11377. }
  11378. string seller_memo = row["seller_memo"].ToString();
  11379. bool ispj = false;//是否配件单
  11380. bool isfirst = true;//第一个配
  11381. maps.Keys.ForEach(key =>
  11382. {
  11383. //备注包含配件
  11384. if (seller_memo.Contains(key) && isfirst)
  11385. {
  11386. List<string> list = maps[key];
  11387. ispj = true;
  11388. isfirst = false;
  11389. for (int i = 0; i < list.Count; i++)
  11390. {
  11391. if (seller_memo.Contains(list[i]))
  11392. {
  11393. ispj = false;
  11394. break;
  11395. }
  11396. }
  11397. }
  11398. });
  11399. if (ispj)
  11400. {
  11401. continue;
  11402. }
  11403. seller_memo = seller_memo.Replace("UV", "uv");
  11404. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11405. //吊牌归到卡片
  11406. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11407. seller_memo = seller_memo.Replace("卡套", "卡片");
  11408. seller_memo = seller_memo.Replace("封套", "卡片");
  11409. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11410. seller_memo = seller_memo.Replace("腰封", "卡片");
  11411. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11412. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11413. seller_memo = seller_memo.Replace("横幅", "条幅");
  11414. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11415. string map_key = "";
  11416. string type = "";
  11417. if (supplierMap.ContainsKey(supplierId))
  11418. {
  11419. foreach (var kvp in supplierMap[supplierId])
  11420. {
  11421. if (seller_memo.Contains(kvp.Key))
  11422. {
  11423. map_key = kvp.Value;
  11424. type = kvp.Value;
  11425. break;
  11426. }
  11427. }
  11428. }
  11429. if (map_key == "")
  11430. {
  11431. type = "其他";
  11432. map_key = "其他";
  11433. }
  11434. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11435. {
  11436. map_key = suppliers[supplierId];
  11437. }
  11438. if (supplierId == 70)
  11439. {
  11440. supplierId = 70;
  11441. }
  11442. map_key += "_" + row["SupplierName"].ToString();
  11443. Dictionary<string, int> map = null;
  11444. if (other_map.ContainsKey(map_key))
  11445. {
  11446. other_map.TryGetValue(map_key, out map);
  11447. }
  11448. else
  11449. {
  11450. map = new Dictionary<string, int>();
  11451. map.Add("dayDev", 0);//当天出货
  11452. map.Add("dayTotal", 0);//下单总数
  11453. map.Add("payTotal", 0);//500以上
  11454. map.Add("today", 0);//当天出货数量
  11455. map.Add("unusua", 0);//异常数
  11456. other_map.Add(map_key, map);
  11457. other_map.TryGetValue(map_key, out map);
  11458. }
  11459. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11460. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11461. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11462. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11463. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11464. {
  11465. map["dayTotal"]++;
  11466. if (supplierId == 97)
  11467. {
  11468. supplierId = 97;
  11469. }
  11470. }
  11471. if (Convert.ToDecimal(row["payment"]) >= 500)
  11472. {
  11473. map["payTotal"]++;
  11474. }
  11475. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11476. {
  11477. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11478. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11479. {
  11480. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11481. {
  11482. map["today"]++;
  11483. }
  11484. }
  11485. else
  11486. {
  11487. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11488. {
  11489. map["today"]++;
  11490. }
  11491. else
  11492. {
  11493. if (supplierId == 119)
  11494. {
  11495. Debug.WriteLine(row["seller_memo"].ToString());
  11496. }
  11497. }
  11498. }
  11499. }
  11500. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11501. {
  11502. map["unusua"]++;
  11503. }
  11504. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11505. //GD-CYT-----64
  11506. DateTime two = palceTimeStart.AddHours(14);
  11507. DateTime three = palceTimeStart.AddHours(15);
  11508. DateTime four = palceTimeStart.AddHours(16);
  11509. DateTime six = palceTimeStart.AddHours(18);
  11510. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11511. {
  11512. //下午四点前 500-1000
  11513. string count = row["ProductCount"].ToString();
  11514. if (count != null && count.Length > 0)
  11515. {
  11516. int productCount = commonHelper.getPlaceProductCount(count);
  11517. if (productCount >= 500 && productCount <= 1000)
  11518. {
  11519. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11520. {
  11521. map["dayDev"]++;
  11522. }
  11523. }
  11524. }
  11525. }
  11526. //UV
  11527. else if ("uv".Equals(type))
  11528. {
  11529. //ZT----70
  11530. //ZHX----3
  11531. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11532. {
  11533. map["dayDev"]++;
  11534. }
  11535. //JK----97
  11536. //HZX----105
  11537. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11538. {
  11539. map["dayDev"]++;
  11540. }
  11541. }
  11542. //帆布---52|条幅---27
  11543. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11544. {
  11545. //LHCY-----98
  11546. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11547. {
  11548. map["dayDev"]++;
  11549. }
  11550. }
  11551. //条幅
  11552. else if ("条幅".Equals(type))
  11553. {
  11554. //XD-----90
  11555. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11556. {
  11557. map["dayDev"]++;
  11558. }
  11559. }
  11560. //桌布
  11561. else if ("桌布".Equals(type))
  11562. {
  11563. //XD-----90
  11564. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11565. {
  11566. map["dayDev"]++;
  11567. }
  11568. }
  11569. //DL---10
  11570. //AYTW---119
  11571. //FS-CYT-DY ----80
  11572. //JK----97
  11573. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11574. {
  11575. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11576. {
  11577. map["dayDev"]++;
  11578. }
  11579. }
  11580. // QC---121
  11581. else if (supplierId == 121)
  11582. {
  11583. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11584. {
  11585. map["dayDev"]++;
  11586. }
  11587. }
  11588. }
  11589. DataTable dt = new DataTable();
  11590. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11591. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11592. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11593. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11594. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11595. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11596. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11597. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11598. other_map.Keys.ForEach(key =>
  11599. {
  11600. DataRow dr = dt.NewRow();
  11601. Dictionary<string, int> map = other_map[key];
  11602. string[] key_list = key.Split('_');
  11603. dr[0] = key_list[0];
  11604. dr[1] = key_list[1];
  11605. if (key_list.Length > 2)
  11606. {
  11607. dr[1] += "(" + key_list[2] + ")";
  11608. }
  11609. dr[2] = map["dayTotal"];
  11610. dr[3] = map["payTotal"];
  11611. dr[4] = map["today"];
  11612. dr[5] = map["unusua"];
  11613. dr[6] = map["dayDev"];
  11614. double rate = 0.00;
  11615. if (map["dayDev"] > 0)
  11616. {
  11617. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11618. }
  11619. dr[7] = rate.ToString();
  11620. dt.Rows.Add(dr);
  11621. });
  11622. DataView dv = new DataView(dt);
  11623. dv.Sort = "SupplierName";
  11624. //dv.Sort = "AllOrder desc";
  11625. DataTable dtNew = dv.ToTable();
  11626. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11627. }
  11628. public void check_order_desing_info()
  11629. {
  11630. string ctid = GetPostString("ctid");
  11631. if (!string.IsNullOrEmpty(ctid))
  11632. {
  11633. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11634. if (ceErpTradeCell != null)
  11635. {
  11636. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11637. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11638. return;
  11639. }
  11640. returnErrorMsg("找不到订单");
  11641. return;
  11642. }
  11643. returnErrorMsg("找不到订单");
  11644. }
  11645. public void get_timeout_detail()
  11646. {
  11647. string poscode = CurrentUser.UserPost.Post.Code;
  11648. DataStruct dStruct = GetPostStruct();
  11649. List<string> lw = new List<string>();
  11650. string id = GetPostString("id");
  11651. string pay_date1 = GetPostString("pay_date1");
  11652. string pay_date2 = GetPostString("pay_date2");
  11653. int type = GetPostInt("type");
  11654. if (type == 0)
  11655. {
  11656. if (pay_date1.Length > 0)
  11657. {
  11658. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11659. }
  11660. if (pay_date2.Length > 0)
  11661. {
  11662. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11663. }
  11664. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11665. }
  11666. if (type == 1)
  11667. {
  11668. if (pay_date1.Length > 0)
  11669. {
  11670. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11671. }
  11672. if (pay_date2.Length > 0)
  11673. {
  11674. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11675. }
  11676. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11677. }
  11678. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11679. DataTable dt = null;
  11680. dt = WebCache.GetData("view_orderlist", dStruct);
  11681. writeGridDataTableJson(dStruct.TotalCount, dt);
  11682. }
  11683. public void saveUrgentChargePrice()
  11684. {
  11685. string ctid = GetPostString("ctid");
  11686. if (!string.IsNullOrEmpty(ctid))
  11687. {
  11688. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11689. if (ceErpTradeCell != null)
  11690. {
  11691. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11692. if (prices <= 100)
  11693. {
  11694. returnErrorMsg("此订单金额不足100元,无法加急。");
  11695. return;
  11696. }
  11697. double price = GetPostDouble("price");
  11698. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11699. if (ceErpTradeCellExtend == null)
  11700. {
  11701. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11702. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11703. }
  11704. ceErpTradeCellExtend.urgentCharge = price;
  11705. if (ceErpTradeCellExtend.ID > 0)
  11706. {
  11707. ceErpTradeCellExtend.Update();
  11708. }
  11709. else
  11710. {
  11711. ceErpTradeCellExtend.Save();
  11712. }
  11713. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11714. returnSuccessMsg("修改成功!");
  11715. return;
  11716. }
  11717. returnErrorMsg("找不到订单");
  11718. return;
  11719. }
  11720. returnErrorMsg("找不到订单");
  11721. }
  11722. public void finish_erp_order()
  11723. {
  11724. string ctid = GetPostString("ctid");
  11725. if (!string.IsNullOrEmpty(ctid))
  11726. {
  11727. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11728. {
  11729. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11730. if (ceErpTradeCell != null)
  11731. {
  11732. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11733. ceErpTradeCell.Update();
  11734. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11735. returnSuccessMsg("修改成功!");
  11736. return;
  11737. }
  11738. }
  11739. }
  11740. returnErrorMsg("找不到订单");
  11741. }
  11742. public void get_trade_order_list()
  11743. {
  11744. string tid = GetPostString("tid");
  11745. if (!string.IsNullOrEmpty(tid))
  11746. {
  11747. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11748. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11749. writeGridDataTableJson(data.Rows.Count, data);
  11750. return;
  11751. }
  11752. returnErrorMsg("找不到订单");
  11753. }
  11754. public void save_cell_spu()
  11755. {
  11756. string ctid = GetPostString("ctid");
  11757. string spu_id = GetPostString("spu_id");
  11758. if (!string.IsNullOrEmpty(ctid))
  11759. {
  11760. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11761. if (ceErpTradeCellExtend == null)
  11762. {
  11763. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11764. ceErpTradeCellExtend.ctid = ctid;
  11765. }
  11766. ceErpTradeCellExtend.spu_id = spu_id;
  11767. if (!string.IsNullOrEmpty(spu_id))
  11768. {
  11769. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11770. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11771. }
  11772. if (ceErpTradeCellExtend.ID == 0)
  11773. {
  11774. ceErpTradeCellExtend.Create();
  11775. }
  11776. else
  11777. {
  11778. ceErpTradeCellExtend.Update();
  11779. }
  11780. returnSuccessMsg("修改成功!");
  11781. return;
  11782. }
  11783. returnErrorMsg("找不到订单");
  11784. }
  11785. public void change_express_info()
  11786. {
  11787. string ctid = GetPostString("ctid");
  11788. string transNo = GetPostString("transNo");
  11789. string transCom = GetPostString("transCom");
  11790. if (!string.IsNullOrEmpty(ctid))
  11791. {
  11792. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11793. if (ceErpTradeCellExtend == null)
  11794. {
  11795. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11796. ceErpTradeCellExtend.ctid = ctid;
  11797. }
  11798. ceErpTradeCellExtend.modExpressNo = transNo;
  11799. ceErpTradeCellExtend.modExpressCom = transCom;
  11800. ceErpTradeCellExtend.readMod = 2;
  11801. if (ceErpTradeCellExtend.ID == 0)
  11802. {
  11803. ceErpTradeCellExtend.Create();
  11804. }
  11805. else
  11806. {
  11807. ceErpTradeCellExtend.Update();
  11808. }
  11809. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11810. returnSuccessMsg("修改成功!");
  11811. return;
  11812. }
  11813. returnErrorMsg("找不到订单");
  11814. }
  11815. public void get_change_express_list()
  11816. {
  11817. DataStruct dStruct = GetPostStruct();
  11818. List<string> lw = new List<string>();
  11819. int st = 2;
  11820. string tid = GetPostString("ctid");
  11821. if (tid.Length > 0)
  11822. {
  11823. string select_tid = getTidByCtid(tid);
  11824. lw.Add(string.Format("tid='{0}'", select_tid));
  11825. }
  11826. string shopname = GetPostString("shopname");
  11827. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11828. string buyernick = GetPostString("buyer_nick");
  11829. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11830. string sellermemo = GetPostString("seller_memo");
  11831. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11832. string supplier = GetPostString("supplier");
  11833. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11834. string customer = GetPostString("customer");
  11835. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11836. string design = GetPostString("design");
  11837. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11838. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11839. string poscode = CurrentUser.UserPost.Post.Code;
  11840. if (poscode != "SysAdmin")
  11841. {
  11842. string shopid = CurrentUser.User.pemShop;
  11843. lw.Add(string.Format("shopId in ({0})", shopid));
  11844. }
  11845. lw.Add("readMod = 2");
  11846. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11847. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11848. writeGridDataTableJson(dStruct.TotalCount, dt);
  11849. }
  11850. public void deal_express_complete()
  11851. {
  11852. string ctid = GetPostString("ctid");
  11853. if (!string.IsNullOrEmpty(ctid))
  11854. {
  11855. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11856. if (ceErpTradeCellExtend == null)
  11857. {
  11858. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11859. ceErpTradeCellExtend.ctid = ctid;
  11860. }
  11861. ceErpTradeCellExtend.readMod = 1;
  11862. if (ceErpTradeCellExtend.ID == 0)
  11863. {
  11864. ceErpTradeCellExtend.Create();
  11865. }
  11866. else
  11867. {
  11868. ceErpTradeCellExtend.Update();
  11869. }
  11870. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11871. returnSuccessMsg("修改成功!");
  11872. return;
  11873. }
  11874. returnErrorMsg("找不到订单");
  11875. }
  11876. public void aftersale_return_visit()
  11877. {
  11878. string ctid = GetPostString("ctid");
  11879. if (!string.IsNullOrEmpty(ctid))
  11880. {
  11881. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11882. if (ceErpTradeCellExtend == null)
  11883. {
  11884. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11885. ceErpTradeCellExtend.ctid = ctid;
  11886. }
  11887. ceErpTradeCellExtend.returnVisit = 1;
  11888. if (ceErpTradeCellExtend.ID == 0)
  11889. {
  11890. ceErpTradeCellExtend.Create();
  11891. }
  11892. else
  11893. {
  11894. ceErpTradeCellExtend.Update();
  11895. }
  11896. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11897. if (ceErpTradeAfterSaleExtend != null)
  11898. {
  11899. ceErpTradeAfterSaleExtend.TextResult = "";
  11900. ceErpTradeAfterSaleExtend.Update();
  11901. }
  11902. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11903. returnSuccessMsg("修改成功!");
  11904. return;
  11905. }
  11906. returnErrorMsg("找不到订单");
  11907. }
  11908. public void orderPlaceInfo()
  11909. {
  11910. string ctids = GetPostString("ctids");
  11911. string[] list = ctids.Split(',');
  11912. foreach (string ctid in list)
  11913. {
  11914. CeErpSukuraData.createInfo(ctid, 3);
  11915. }
  11916. StringBuilder sql = new StringBuilder();
  11917. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11918. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11919. designHelper.api_approveDesign(ctids); //approveDesign
  11920. returnSuccessMsg("");
  11921. }
  11922. public void get_issue_list()
  11923. {
  11924. DataStruct dStruct = GetPostStruct();
  11925. List<string> lw = new List<string>();
  11926. int st = 2;
  11927. string tid = GetPostString("ctid");
  11928. if (tid.Length > 0)
  11929. {
  11930. string select_tid = getTidByCtid(tid);
  11931. lw.Add(string.Format("tid='{0}'", select_tid));
  11932. }
  11933. string shopname = GetPostString("shopname");
  11934. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11935. string buyernick = GetPostString("buyer_nick");
  11936. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11937. string sellermemo = GetPostString("seller_memo");
  11938. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11939. string supplier = GetPostString("supplier");
  11940. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11941. string customer = GetPostString("customer");
  11942. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11943. string design = GetPostString("design");
  11944. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11945. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11946. string poscode = CurrentUser.UserPost.Post.Code;
  11947. if (poscode != "SysAdmin")
  11948. {
  11949. string shopid = CurrentUser.User.pemShop;
  11950. lw.Add(string.Format("shopId in ({0})", shopid));
  11951. }
  11952. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11953. {
  11954. lw.Add("IssueState = 1");
  11955. }
  11956. else
  11957. {
  11958. string iisstate = GetPostString("iisstate");
  11959. if ("1".Equals(iisstate))
  11960. {
  11961. lw.Add("IssueState =1");
  11962. }
  11963. else if ("2".Equals(iisstate))
  11964. {
  11965. lw.Add("IssueState = 2");
  11966. }
  11967. else
  11968. {
  11969. lw.Add("IssueState > 0");
  11970. }
  11971. }
  11972. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11973. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11974. writeGridDataTableJson(dStruct.TotalCount, dt);
  11975. }
  11976. public void saveIssueContent()
  11977. {
  11978. string ctid = GetPostString("ctid");
  11979. if (!string.IsNullOrEmpty(ctid))
  11980. {
  11981. string content = GetPostString("content");
  11982. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11983. if (ceErpTradeAfterSaleExtend == null)
  11984. {
  11985. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11986. ceErpTradeAfterSaleExtend.tid = ctid;
  11987. }
  11988. ceErpTradeAfterSaleExtend.IssueContent = content;
  11989. ceErpTradeAfterSaleExtend.IssueState = 1;
  11990. if (ceErpTradeAfterSaleExtend.ID > 0)
  11991. {
  11992. ceErpTradeAfterSaleExtend.Update();
  11993. }
  11994. else
  11995. {
  11996. ceErpTradeAfterSaleExtend.Create();
  11997. }
  11998. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11999. returnSuccessMsg("添加成功!");
  12000. return;
  12001. }
  12002. returnErrorMsg("找不到订单");
  12003. }
  12004. public void dealIssueContent()
  12005. {
  12006. string ctid = GetPostString("ctid");
  12007. if (!string.IsNullOrEmpty(ctid))
  12008. {
  12009. string content = GetPostString("content");
  12010. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12011. if (ceErpTradeAfterSaleExtend != null)
  12012. {
  12013. ceErpTradeAfterSaleExtend.IssueState = 2;
  12014. ceErpTradeAfterSaleExtend.Update();
  12015. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12016. returnSuccessMsg("修改完成!");
  12017. return;
  12018. }
  12019. }
  12020. returnErrorMsg("找不到订单");
  12021. }
  12022. public void set_tid_attachments()
  12023. {
  12024. string tid = GetPostString("tid");
  12025. string atta = GetPostString("atta");
  12026. if (!string.IsNullOrEmpty(tid))
  12027. {
  12028. if (string.IsNullOrEmpty(atta))
  12029. {
  12030. returnErrorMsg("文件地址为空");
  12031. return;
  12032. }
  12033. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12034. if (ceErpTradeCell != null)
  12035. {
  12036. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12037. if (ceErpTrade == null)
  12038. {
  12039. returnErrorMsg("找不到订单");
  12040. return;
  12041. }
  12042. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12043. bool isSend = false;
  12044. if (dt != null && dt.Rows.Count > 0)
  12045. {
  12046. foreach (DataRow row in dt.Rows)
  12047. {
  12048. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12049. {
  12050. isSend = true;
  12051. }
  12052. }
  12053. if (isSend)
  12054. {
  12055. returnErrorMsg("已发货无法修改");
  12056. return;
  12057. }
  12058. ceErpTrade.Attachments = atta;
  12059. ceErpTrade.Update();
  12060. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12061. returnSuccessMsg("上传成功!");
  12062. return;
  12063. }
  12064. }
  12065. }
  12066. returnErrorMsg("找不到订单");
  12067. }
  12068. public void get_tid_attachments()
  12069. {
  12070. string tid = GetPostString("tid");
  12071. if (!string.IsNullOrEmpty(tid))
  12072. {
  12073. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12074. if (ceErpTradeCell != null)
  12075. {
  12076. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12077. if (ceErpTrade == null)
  12078. {
  12079. returnErrorMsg("找不到订单");
  12080. return;
  12081. }
  12082. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12083. return;
  12084. }
  12085. }
  12086. returnErrorMsg("找不到订单");
  12087. }
  12088. public void check_erp_sameorders()
  12089. {
  12090. if (UrlPostParmsCheck("ctid"))
  12091. {
  12092. string eid = GetPostString("ctid");
  12093. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12094. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12095. if (entity != null && ceErpTrade != null)
  12096. {
  12097. if (entity.OrderState > 6)
  12098. {
  12099. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12100. return;
  12101. }
  12102. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12103. List<string> ids = new List<string>();
  12104. if (dt != null && dt.Rows.Count > 1)
  12105. {
  12106. bool needhe = true;
  12107. foreach (DataRow dr in dt.Rows)
  12108. {
  12109. ids.Add("'" + dr["ctid"] + "'");
  12110. /* //备注有合包
  12111. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12112. {
  12113. needhe = true;
  12114. }
  12115. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12116. {
  12117. needhe = true;
  12118. }
  12119. //顺丰快递
  12120. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12121. {
  12122. needhe = true;
  12123. }*/
  12124. }
  12125. if (!needhe)
  12126. {
  12127. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12128. return;
  12129. }
  12130. StringBuilder sql = new StringBuilder();
  12131. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12132. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12133. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12134. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12135. foreach (DataRow dr in dt.Rows)
  12136. {
  12137. dr["dstate"] = 0;
  12138. dr["dnumber"] = 0;
  12139. foreach (DataRow row in dt1.Rows)
  12140. {
  12141. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12142. {
  12143. dr["dstate"] = 2;
  12144. dr["default"] = 1;
  12145. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12146. }
  12147. }
  12148. if (eid.Equals(dr["ctid"].ToString()))
  12149. {
  12150. dr["dstate"] = 1;
  12151. dr["default"] = 1;
  12152. }
  12153. }
  12154. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12155. return;
  12156. }
  12157. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12158. return;
  12159. }
  12160. returnErrorMsg("未找到订单");
  12161. return;
  12162. }
  12163. returnErrorMsg("缺少必要的参数");
  12164. }
  12165. public void get_mark_number()
  12166. {
  12167. string eid = GetPostString("ctid");
  12168. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12169. if (entity != null)
  12170. {
  12171. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12172. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12173. int current = 1;
  12174. if (ceErpDeliverMark == null)
  12175. {
  12176. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12177. List<string> ids = new List<string>();
  12178. if (dt != null && dt.Rows.Count > 1)
  12179. {
  12180. foreach (DataRow dr in dt.Rows)
  12181. {
  12182. ids.Add("'" + dr["ctid"] + "'");
  12183. }
  12184. //查询已有的编号
  12185. StringBuilder sql = new StringBuilder();
  12186. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12187. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12188. if (dt1 == null || dt1.Rows.Count == 0)
  12189. {
  12190. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12191. List<int> list_number = new List<int>();
  12192. foreach (DataRow row in numbers.Rows)
  12193. {
  12194. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12195. }
  12196. //查询空余编号
  12197. for (int i = 0; i < list_number.Count + 2; i++)
  12198. {
  12199. if (!list_number.Contains(current))
  12200. {
  12201. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12202. //防止查询过程中有新数据生成
  12203. if (ceErpDeliverMark1 == null)
  12204. {
  12205. break;
  12206. }
  12207. }
  12208. current++;
  12209. }
  12210. }
  12211. else
  12212. {
  12213. foreach (DataRow row in dt1.Rows)
  12214. {
  12215. current = Convert.ToInt32(row["markNumber"]);
  12216. }
  12217. }
  12218. ceErpDeliverMark = new CeErpDeliverMark();
  12219. ceErpDeliverMark.ctid = eid;
  12220. ceErpDeliverMark.createtime = DateTime.Now;
  12221. if (ceErpTrade != null)
  12222. {
  12223. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12224. }
  12225. ceErpDeliverMark.markNumber = current;
  12226. ceErpDeliverMark.Create();
  12227. }
  12228. }
  12229. else
  12230. {
  12231. current = ceErpDeliverMark.markNumber;
  12232. }
  12233. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12234. return;
  12235. }
  12236. }
  12237. public void aftersaleCytSend()
  12238. {
  12239. string ctid = GetPostString("ctid");
  12240. if (!string.IsNullOrEmpty(ctid))
  12241. {
  12242. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12243. if (ceErpTradeCell != null)
  12244. {
  12245. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12246. }
  12247. returnSuccessMsg("推送成功");
  12248. return;
  12249. }
  12250. returnErrorMsg("缺少必要的参数");
  12251. }
  12252. public void packOrderInfo()
  12253. {
  12254. string ctids = GetPostString("ctids");
  12255. if (!string.IsNullOrEmpty(ctids))
  12256. {
  12257. string[] ctid_list = ctids.Split(',');
  12258. if (ctid_list.Length > 20)
  12259. {
  12260. returnErrorMsg("单次下载次数不能超过20个");
  12261. return;
  12262. }
  12263. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12264. StringBuilder sql = new StringBuilder();
  12265. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12266. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12267. int supplierId = 0;
  12268. StringBuilder insterSql = new StringBuilder();
  12269. for (int i = 0; i < dt.Rows.Count; i++)
  12270. {
  12271. DataRow row = dt.Rows[i];
  12272. if (i == 0)
  12273. {
  12274. supplierId = Convert.ToInt32(row["SupplierId"]);
  12275. }
  12276. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12277. {
  12278. returnErrorMsg("同车间的订单才能一起打包");
  12279. return;
  12280. }
  12281. int orderState = Convert.ToInt32(row["OrderState"]);
  12282. if (orderState != 5)
  12283. {
  12284. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12285. return;
  12286. }
  12287. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12288. }
  12289. CeErpPackData ceErpPackData = new CeErpPackData();
  12290. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12291. ceErpPackData.supplierId = supplierId;
  12292. ceErpPackData.createtime = DateTime.Now;
  12293. ceErpPackData.createBy = CurrentUser.UserID;
  12294. ceErpPackData.createName = CurrentUser.UserName;
  12295. ceErpPackData.Create();
  12296. if (ceErpPackData.ID > 0)
  12297. {
  12298. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12299. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12300. }
  12301. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12302. returnSuccessMsg("打包成功");
  12303. return;
  12304. }
  12305. returnErrorMsg("缺少必要的参数");
  12306. }
  12307. public void rePackOrderInfo()
  12308. {
  12309. string id = GetPostString("id");
  12310. if (!string.IsNullOrEmpty(id))
  12311. {
  12312. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12313. if (ceErpPackData == null)
  12314. {
  12315. returnSuccessMsg("查无数据");
  12316. return;
  12317. }
  12318. ceErpPackData.upStatus = 0;
  12319. ceErpPackData.message = "";
  12320. ceErpPackData.Update();
  12321. returnSuccessMsg("打包成功");
  12322. return;
  12323. }
  12324. returnErrorMsg("缺少必要的参数");
  12325. }
  12326. public void backPackOrderInfo()
  12327. {
  12328. string id = GetPostString("id");
  12329. if (!string.IsNullOrEmpty(id))
  12330. {
  12331. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12332. if (ceErpPackData == null)
  12333. {
  12334. returnSuccessMsg("查无数据");
  12335. return;
  12336. }
  12337. ceErpPackData.upStatus = 4;
  12338. ceErpPackData.Update();
  12339. List<string> list = new List<string>();
  12340. StringBuilder sql = new StringBuilder();
  12341. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12342. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12343. for (int i = 0; i < dt.Rows.Count; i++)
  12344. {
  12345. DataRow row = dt.Rows[i];
  12346. list.Add("'" + row["ctid"].ToString() + "'");
  12347. }
  12348. string textCtids = string.Join(",", list);
  12349. 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));
  12350. 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, "无法打包退回"));
  12351. returnSuccessMsg("退回成功");
  12352. return;
  12353. }
  12354. returnErrorMsg("缺少必要的参数");
  12355. }
  12356. public void addPackDownNum()
  12357. {
  12358. string id = GetPostString("id");
  12359. if (!string.IsNullOrEmpty(id))
  12360. {
  12361. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12362. returnSuccessMsg("下载成功");
  12363. return;
  12364. }
  12365. returnErrorMsg("缺少必要的参数");
  12366. }
  12367. public void get_pack_list()
  12368. {
  12369. DataStruct dStruct = GetPostStruct();
  12370. List<string> lw = new List<string>();
  12371. string supplier = GetPostString("supplier");
  12372. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12373. string posTag = CurrentUser.UserPost.Post.Code;
  12374. if (posTag == "Supplier")
  12375. {
  12376. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12377. }
  12378. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12379. dStruct.Order = "createtime desc";
  12380. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12381. writeGridDataTableJson(dStruct.TotalCount, dt);
  12382. }
  12383. public void get_pack_order_list()
  12384. {
  12385. string packId = GetPostString("packId");
  12386. if (string.IsNullOrEmpty(packId))
  12387. {
  12388. returnErrorMsg("缺少必要的参数");
  12389. return;
  12390. }
  12391. StringBuilder sql = new StringBuilder();
  12392. 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);
  12393. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12394. if (dt == null || dt.Rows.Count == 0)
  12395. {
  12396. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12397. return;
  12398. }
  12399. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12400. return;
  12401. }
  12402. public void get_supplier_product_time_list()
  12403. {
  12404. DataStruct dStruct = GetPostStruct();
  12405. List<string> lw = new List<string>();
  12406. string supplier = GetPostString("supplier");
  12407. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12408. string posTag = CurrentUser.UserPost.Post.Code;
  12409. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12410. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12411. writeGridDataTableJson(dStruct.TotalCount, dt);
  12412. }
  12413. public void saveSupplierProductTime()
  12414. {
  12415. string productId = GetPostString("productId");
  12416. if (string.IsNullOrEmpty(productId))
  12417. {
  12418. returnErrorMsg("缺少必要的参数");
  12419. return;
  12420. }
  12421. string productName = GetPostString("productName");
  12422. int supplierId = GetPostInt("supplierId");
  12423. if (supplierId == 0)
  12424. {
  12425. returnErrorMsg("缺少必要的参数");
  12426. return;
  12427. }
  12428. int quantity = GetPostInt("quantity");
  12429. int sendDay = GetPostInt("sendTime");
  12430. string supplierName = GetPostString("supplierName");
  12431. string craft = GetPostString("craft");
  12432. string deadLine = GetPostString("deadLine");
  12433. string dayDeadLine = GetPostString("dayDeadLine");
  12434. try
  12435. {
  12436. int eid = GetPostInt("eid");
  12437. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12438. if (ceErpSupplierProductTime == null)
  12439. {
  12440. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12441. }
  12442. ceErpSupplierProductTime.productId = productId;
  12443. ceErpSupplierProductTime.productName = productName;
  12444. ceErpSupplierProductTime.supplierId = supplierId;
  12445. ceErpSupplierProductTime.supplierName = supplierName;
  12446. ceErpSupplierProductTime.craft = craft;
  12447. ceErpSupplierProductTime.sendDay = sendDay;
  12448. ceErpSupplierProductTime.quantity = quantity;
  12449. if (!string.IsNullOrEmpty(deadLine))
  12450. {
  12451. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12452. }
  12453. if (!string.IsNullOrEmpty(dayDeadLine))
  12454. {
  12455. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12456. }
  12457. if (ceErpSupplierProductTime.ID == 0)
  12458. {
  12459. ceErpSupplierProductTime.Save();
  12460. }
  12461. else
  12462. {
  12463. ceErpSupplierProductTime.Update();
  12464. }
  12465. }
  12466. catch (Exception e)
  12467. {
  12468. }
  12469. returnSuccessMsg("保存成功");
  12470. return;
  12471. }
  12472. public void delSupplierProductTime()
  12473. {
  12474. int eid = GetPostInt("eid");
  12475. if (eid > 0)
  12476. {
  12477. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12478. if (ceErpSupplierProductTime == null)
  12479. {
  12480. returnErrorMsg("查无数据");
  12481. return;
  12482. }
  12483. ceErpSupplierProductTime.Delete();
  12484. returnSuccessMsg("保存成功");
  12485. return;
  12486. }
  12487. returnErrorMsg("缺少必要的参数");
  12488. }
  12489. public void getExpressInfo()
  12490. {
  12491. string ctid = GetPostString("ctid");
  12492. if (!string.IsNullOrEmpty(ctid))
  12493. {
  12494. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12495. if (ceErpTradeCell != null)
  12496. {
  12497. string outSid = ceErpTradeCell.OutSid;
  12498. if (outSid.Length > 0)
  12499. {
  12500. 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);
  12501. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12502. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12503. return;
  12504. }
  12505. }
  12506. returnErrorMsg("查无记录");
  12507. return;
  12508. }
  12509. returnErrorMsg("缺少必要的参数");
  12510. }
  12511. public void getExpressPostData()
  12512. {
  12513. string express = GetPostString("express");
  12514. if (!string.IsNullOrEmpty(express))
  12515. {
  12516. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12517. if (ceErpExpressInfo != null)
  12518. {
  12519. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12520. return;
  12521. }
  12522. }
  12523. returnErrorMsg("缺少必要的参数");
  12524. }
  12525. public void checkSupplierOrder()
  12526. {
  12527. string ctids = GetPostString("ctids");
  12528. if (ctids != null)
  12529. {
  12530. List<string> list = new List<string>();
  12531. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12532. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12533. for (int i = 0; i < dt.Rows.Count; i++)
  12534. {
  12535. DataRow row = dt.Rows[i];
  12536. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12537. {
  12538. continue;
  12539. }
  12540. list.Add(row["seller_memo"].ToString());
  12541. }
  12542. if (list.Count > 0)
  12543. {
  12544. 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, "点击下载按钮"));
  12545. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12546. return;
  12547. }
  12548. }
  12549. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12550. return;
  12551. }
  12552. public void addPersonId()
  12553. {
  12554. string tid = GetPostString("tid");
  12555. string personId = GetPostString("personId");
  12556. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12557. if (ceErpTrade != null)
  12558. {
  12559. ceErpTrade.receiver_zip = personId;
  12560. ceErpTrade.Update();
  12561. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12562. returnSuccessMsg("保存成功");
  12563. return;
  12564. }
  12565. returnErrorMsg("缺少必要的参数");
  12566. }
  12567. }
  12568. }