sync.order.cs 640 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862
  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. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\uv特殊工艺价格(1).xls");
  59. //apiHelper.Api_SyncOrderByTime("598825");
  60. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  61. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  62. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  63. //banniuApiHelper.sendLogisticsInfo(null);
  64. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  65. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  66. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  67. //int sid = commonHelper.autoDistributeToSupplier(entity);
  68. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  69. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1750324509000,\"deliveryType\":\"OFFLINE\",\"discountFee\":60.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1750867200000,\"lines\":[{\"latestDeliveryTime\":1750867200000,\"mark2\":[],\"num\":12,\"outerId\":\"XCCBTFB\",\"payment\":300.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/490100363/O1CN01QY84g81EYIfY4eEq2_!!490100363.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"2618419802494137080\",\"refSkuId\":\"0\",\"refSpuId\":\"703805468317\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":25.0,\"singleFee\":25.0,\"spuOuterId\":\"XCCBTFB\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"摆摊广告布定制推车贴纸三轮小吃车展示招牌喷绘夜市地摊帆布海报\",\"totalFee\":300.0,\"totalPrice\":360.0,\"totalSellPrice\":300.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1750397934000,\"openBuyerId\":\"AAHnRHraABkUZRHgSx2jBZ8l\",\"openBuyerNick\":\"t**\",\"openSellerNick\":\"琳19890725\",\"orderSource\":\"SYNC\",\"orderTime\":1750324223000,\"payTime\":1750324505000,\"payment\":300.0,\"platServiceFee\":0.0,\"posCode\":\"guliang\",\"posId\":598696,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"三亚市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"吉阳区\",\"receiverId\":\"d882d22254b88b1ed1b3d6d4645179dd$\",\"receiverState\":\"海南省\",\"receiverTown\":\"河东区街道\",\"refOid\":\"2618419802494137080\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"422x35cm-1张-帆布-摆摊布米白-打孔模切-tb908253750- 拾柒-100-送10米麻绳,200x35cm-1张-帆布-摆摊布米白-打孔模切-tb908253750- 拾柒-100-送10米麻绳,400x73cm-1张-帆布-摆摊布米白-打孔模切-tb908253750- 拾柒-100-送10米麻绳\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":300.0,\"totalPrice\":360.0,\"totalSellPrice\":300.0,\"type\":\"SALE\"}}");
  70. //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}}");
  71. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  72. //commonHelper.loginGetOrder(2152);
  73. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  74. List<string> lw = new List<string>();
  75. string tid = GetPostString("ctid");
  76. string date1 = GetPostString("date1");
  77. //12-1 修改
  78. string urgent = GetPostString("urgent");
  79. string back = GetPostString("back");
  80. string offlineSearch = GetPostString("offlineSearch");
  81. int paramsCount = 0;
  82. if (!string.IsNullOrWhiteSpace(urgent))
  83. {
  84. if (urgent.Equals("true"))
  85. {
  86. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  87. }
  88. }
  89. if (!string.IsNullOrWhiteSpace(back))
  90. {
  91. if (back.Equals("true"))
  92. {
  93. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  94. }
  95. }
  96. if (!string.IsNullOrWhiteSpace(offlineSearch))
  97. {
  98. if (offlineSearch.Equals("true"))
  99. {
  100. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  101. }
  102. }
  103. //end
  104. string date2 = GetPostString("date2");
  105. string buyernick = GetPostString("buyer_nick");
  106. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  107. {
  108. if (tid.Length <= 0 && buyernick.Length <= 0)
  109. {
  110. return;
  111. }
  112. }
  113. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  114. {
  115. if (tid.Length > 0)
  116. {
  117. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  118. if (ceErpTradeCell != null)
  119. {
  120. tid = ceErpTradeCell.tid;
  121. }
  122. List<string> select_tid = getTidByCtidMore(tid);
  123. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  124. }
  125. if (buyernick.Length > 0)
  126. {
  127. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  128. }
  129. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  130. if (dw.Length > 0)
  131. {
  132. lw.Add(dw);
  133. }
  134. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  135. {
  136. string usershop = CurrentUser.User.pemShop;
  137. lw.Add(string.Format("ShopId in ({0})", usershop));
  138. }
  139. }
  140. else
  141. {
  142. if (ex_psize == 0)
  143. {
  144. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  145. }
  146. if (PKey != "admin" && poscode != "SysAdmin")
  147. {
  148. string usershop = CurrentUser.User.pemShop;
  149. lw.Add(string.Format("ShopId in ({0})", usershop));
  150. paramsCount++;
  151. }
  152. }
  153. string uploaddate1 = GetPostString("uploaddate1");
  154. string uploaddate2 = GetPostString("uploaddate2");
  155. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  156. if (update.Length > 0) lw.Add(update);
  157. string deliverydate1 = GetPostString("deliverydate1");
  158. string deliverydate2 = GetPostString("deliverydate2");
  159. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  160. if (deliverydate.Length > 0)
  161. {
  162. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  163. };
  164. string shopname = GetPostString("shopname");
  165. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  166. string addwechat = GetPostString("addwechat");
  167. if (addwechat.Length > 0)
  168. {
  169. int addWt = Convert.ToInt32(addwechat);
  170. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  171. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  172. }
  173. string customer = GetPostString("customer");
  174. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  175. string design = GetPostString("design");
  176. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  177. string orderState = GetPostString("orderState");
  178. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  179. string address = GetPostString("address");
  180. 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));
  181. string sellermemo = GetPostString("seller_memo");
  182. if (sellermemo.Length > 0)
  183. {
  184. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  185. }
  186. string backReason = GetPostString("backReason");
  187. if (backReason.Length > 0)
  188. {
  189. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  190. }
  191. string apdate1 = GetPostString("apdate1");
  192. string apdate2 = GetPostString("apdate2");
  193. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  194. if (dwap.Length > 0) lw.Add(dwap);
  195. string price1 = GetPostString("price1");
  196. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  197. string price2 = GetPostString("price2");
  198. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  199. string isoldcustomer = GetPostString("isoldcus");
  200. string spudata = GetPostString("spudata");
  201. if ("0".Equals(spudata))
  202. {
  203. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  204. }
  205. if ("1".Equals(spudata))
  206. {
  207. lw.Add(string.Format("spu_id <> ''"));
  208. }
  209. string finishdate1 = GetPostString("finishdate1");
  210. string finishdate2 = GetPostString("finishdate2");
  211. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  212. bool isFinish = false;
  213. if (finishdate.Length > 0)
  214. {
  215. lw.Add(finishdate);
  216. isFinish = true;
  217. paramsCount++;
  218. }
  219. if (isoldcustomer.Length > 0)
  220. {
  221. if ("2".Equals(isoldcustomer))
  222. {
  223. lw.Add(string.Format("VipCustomer=1"));
  224. }
  225. else
  226. {
  227. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  228. }
  229. }
  230. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  231. if (ex_psize > 0)
  232. {
  233. int UserID = CurrentUser.UserID;
  234. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  235. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  236. {
  237. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  238. }
  239. dStruct.Order = "pay_time desc";
  240. }
  241. string isNew = GetPostString("isNew");
  242. if (isNew == "true")
  243. {
  244. lw.Add(string.Format("IsNew = {0}", 1));
  245. }
  246. string overtime = GetPostString("overtime");
  247. if (overtime == "1")
  248. {
  249. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  250. }
  251. String usePost = CurrentUser.UserPost.Post.Code;
  252. if (usePost.Equals("Operation") == true)
  253. {
  254. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  255. }
  256. else
  257. {
  258. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  259. }
  260. //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";
  261. if (dStruct.PageSize == 100000)
  262. {
  263. dStruct.Order = "";
  264. }
  265. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  266. DataTable dt = null;
  267. string tablename = "view_orderlist";
  268. if (isFinish)
  269. {
  270. tablename = "view_orderlist_end";
  271. }
  272. dt = WebCache.GetData(tablename, dStruct);
  273. if (dt != null && dt.Rows.Count > 0)
  274. {
  275. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  276. foreach (DataRow dr in dt.Rows)
  277. {
  278. try
  279. {
  280. if (dr["refund_fees"] != null)
  281. {
  282. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  283. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  284. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  285. if (payment == refund_fees)
  286. {
  287. dr["refund_fees"] = Math.Round(refund_fees, 2);
  288. }
  289. else if (refund_fees == total_fee)
  290. {
  291. dr["refund_fees"] = payment;
  292. }
  293. else
  294. {
  295. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  296. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  297. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  298. }
  299. }
  300. // 对象操作
  301. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  302. ceErpTradeCell.ctid = dr["ctid"].ToString();
  303. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  304. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  305. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  306. if (dStruct.PageSize != 100000)
  307. {
  308. if (dr["DispatchSort"].ToString() == "2")
  309. {
  310. dr["gongchuang"] = 200;
  311. }
  312. else if ("外协".Equals(dr["ToType"].ToString()))
  313. {
  314. dr["gongchuang"] = 200;
  315. }
  316. else if ("内部".Equals(dr["ToType"].ToString()))
  317. {
  318. dr["gongchuang"] = -1;
  319. }
  320. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  321. {
  322. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  323. dr["gongchuang"] = response.code;
  324. }
  325. }
  326. }
  327. catch (NullReferenceException ex)
  328. {
  329. // 处理空引用异常
  330. dr["refund_fees"] = "0.00";
  331. }
  332. }
  333. }
  334. writeGridDataTableJson(dStruct.TotalCount, dt);
  335. }
  336. public void get_erp_orderlist_sumprice()
  337. {
  338. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  339. return;
  340. List<string> lw = new List<string>();
  341. string tid = GetPostString("ctid");
  342. string date1 = GetPostString("date1");
  343. string date2 = GetPostString("date2");
  344. if (tid.Length > 0 || date1.Length > 0)
  345. {
  346. lw.Add(string.Format("ctid like '%{0}%'", tid));
  347. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  348. if (dw.Length > 0) lw.Add(dw);
  349. }
  350. else
  351. {
  352. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  353. }
  354. string shopname = GetPostString("shopname");
  355. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  356. string buyernick = GetPostString("buyer_nick");
  357. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  358. string customer = GetPostString("customer");
  359. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  360. string design = GetPostString("design");
  361. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  362. string orderState = GetPostString("orderState");
  363. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  364. string address = GetPostString("address");
  365. 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));
  366. string sellermemo = GetPostString("seller_memo");
  367. if (sellermemo.Length > 0)
  368. {
  369. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  370. }
  371. string apdate1 = GetPostString("apdate1");
  372. string apdate2 = GetPostString("apdate2");
  373. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  374. if (dwap.Length > 0) lw.Add(dwap);
  375. string price1 = GetPostString("price1");
  376. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  377. string price2 = GetPostString("price2");
  378. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  379. string isoldcustomer = GetPostString("isoldcus");
  380. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  381. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  382. if (PKey != "admin")
  383. {
  384. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  385. lw.Add(string.Format("shopId in ({0})", usershop));
  386. }
  387. //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";
  388. string mainWhere = string.Join(" and ", lw.ToArray());
  389. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  390. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  391. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  392. decimal total = 0;
  393. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  394. {
  395. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  396. }
  397. var res = new
  398. {
  399. data = total
  400. };
  401. string ro_jsond = JsonConvert.SerializeObject(res);
  402. returnSuccess(ro_jsond);
  403. return;
  404. }
  405. public void get_erp_CustomerServiceGather()
  406. {
  407. string userWhere = "", orderWhere = "";
  408. List<string> lw = new List<string>();
  409. string customer = GetPostString("customer");
  410. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  411. string shopname = GetPostString("shopname");
  412. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  413. string date1 = GetPostString("date1");
  414. string date2 = GetPostString("date2");
  415. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  416. if (dw.Length > 0) lw.Add(dw);
  417. orderWhere = string.Join(" and ", lw.ToArray());
  418. 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 " +
  419. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  420. "left join " +
  421. "( " +
  422. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  423. ") as b on a.ID = b.CustomerUserId " +
  424. "left join " +
  425. "( " +
  426. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  427. ") as d on a.ID = d.CustomerUserId " +
  428. "left join " +
  429. "( " +
  430. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  431. ") as e on a.ID = e.CustomerUserId " +
  432. "left join " +
  433. "( " +
  434. " select CustomerUserId, RefundCount, RefundSum from " +
  435. " ( " +
  436. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  437. " from CE_ErpTradeRefund a " +
  438. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  439. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  440. " group by CustomerUserId " +
  441. " ) as a " +
  442. ") as f on a.ID = f.CustomerUserId " +
  443. "where a.PostCode = 'CustomerService'",
  444. userWhere, orderWhere);
  445. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  446. writeGridDataTableJson(dt.Rows.Count, dt);
  447. //writeGridDataTableJson(dt.Rows.Count, dt);
  448. }
  449. //设计汇总
  450. public void get_erp_DesignerGather()
  451. {
  452. string userWhere = "", orderWhere = "";
  453. List<string> lw = new List<string>();
  454. string Designer = GetPostString("designer");
  455. int org = GetPostInt("org");
  456. if (Designer.Length > 0)
  457. {
  458. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  459. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  460. }
  461. else if (org > 0)
  462. {
  463. userWhere = string.Format(" where OrgID ={0}", org);
  464. }
  465. string shopname = GetPostString("shopname");
  466. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  467. string state = GetPostString("state");
  468. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  469. string OrderArea = GetPostString("order_area");
  470. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  471. string date1 = GetPostString("date1");
  472. string date2 = GetPostString("date2");
  473. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  474. if (dw.Length > 0) lw.Add(dw);
  475. string UpDate1 = GetPostString("UpDate1");
  476. string UpDate2 = GetPostString("UpDate2");
  477. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  478. if (dw.Length > 0) lw.Add(dw);
  479. orderWhere = string.Join(" and ", lw.ToArray());
  480. 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 (" +
  481. "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 " +
  482. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  483. "left join " +
  484. "( " +
  485. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  486. ") as b on a.ID = b.DesignUserId " +
  487. "left join " +
  488. "( " +
  489. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  490. ") as d on a.ID = d.DesignUserId " +
  491. "left join " +
  492. "( " +
  493. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  494. ") as e on a.ID = e.DesignUserId " +
  495. "left join " +
  496. "( " +
  497. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  498. ") as g on a.ID = g.DesignUserId " +
  499. "left join " +
  500. "( " +
  501. " select CustomerUserId, RefundCount, RefundSum from " +
  502. " ( " +
  503. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  504. " from CE_ErpTradeRefund a " +
  505. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  506. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  507. " group by CustomerUserId " +
  508. " ) as a " +
  509. ") as f on a.ID = f.CustomerUserId " +
  510. "where a.PostCode = 'Designer') as z",
  511. userWhere, orderWhere);
  512. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  513. writeGridDataTableJson(dt.Rows.Count, dt);
  514. }
  515. //删除tradecell的订单
  516. public void del_erp_cellorder()
  517. {
  518. if (UrlPostParmsCheck("ctid"))
  519. {
  520. string eid = GetPostString("ctid");
  521. CeErpTradeCell.DelByCtid(eid);
  522. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  523. returnSuccessMsg("删除成功");
  524. }
  525. }
  526. public void clear_erp_refundstate()
  527. {
  528. if (UrlPostParmsCheck("ids"))
  529. {
  530. string eids = GetPostString("ids");
  531. string[] ctidList = eids.Split(',');
  532. foreach (string ctid in ctidList)
  533. {
  534. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  535. if (entity != null)
  536. {
  537. entity.IsRefund = 0;
  538. entity.Update();
  539. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  540. }
  541. else
  542. continue;
  543. }
  544. returnSuccessMsg("操作成功");
  545. return;
  546. }
  547. returnErrorMsg("缺少必要参数");
  548. }
  549. public void set_erp_urgency()
  550. {
  551. if (UrlPostParmsCheck("ctid"))
  552. {
  553. string eid = GetPostString("ctid");
  554. CeErpTradeCell entity = null;
  555. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  556. if (entity != null)
  557. {
  558. double prices = commonHelper.calculationPrice(entity);
  559. if (prices <= 100)
  560. {
  561. returnErrorMsg("此订单金额不足100元,无法加急。");
  562. return;
  563. }
  564. string utime = GetPostString("urgencytime");
  565. if (utime.Length > 0)
  566. {
  567. entity.UrgencyTime = Convert.ToDateTime(utime);
  568. }
  569. else
  570. {
  571. returnErrorMsg("请选择加急时间");
  572. return;
  573. }
  574. if (entity.OrderState <= 4)
  575. {
  576. //entity.seller_memo = entity.seller_memo + "-加急";
  577. string smemo = entity.seller_memo;
  578. int kindex = smemo.IndexOf(")");
  579. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  580. if (lastoneStr != "-")
  581. {
  582. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  583. }
  584. string prememo = smemo.Substring(0, kindex + 2);
  585. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  586. int lastkindex = lastmemo.IndexOf("(");
  587. DateTime urgtime = Convert.ToDateTime(utime);
  588. string newlastmemo = "";
  589. if (lastkindex == 0)
  590. {
  591. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  592. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  593. }
  594. else
  595. {
  596. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  597. }
  598. entity.seller_memo = prememo + newlastmemo;
  599. }
  600. entity.IsUrgency = true;
  601. entity.UpdateTime = DateTime.Now;
  602. entity.Update();
  603. ApiVo apiVo = new ApiVo();
  604. apiVo.orderNumber = entity.ctid;
  605. apiVo.actionName = "changeDesign";
  606. apiVo.orderRemarks = entity.seller_memo;
  607. apiVo.remarkSign = 3;
  608. designHelper.API_WorkCore(apiVo); //changeDesign
  609. CeErpSukuraData.createInfo(entity.ctid, 7);
  610. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  611. returnSuccessMsg("设置成功!");
  612. return;
  613. }
  614. returnErrorMsg("找不到记录");
  615. }
  616. }
  617. public void set_erp_reset()
  618. {
  619. if (UrlPostParmsCheck("ctid"))
  620. {
  621. string eid = GetPostString("ctid");
  622. CeErpTradeCell entity = null;
  623. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  624. if (entity != null)
  625. {
  626. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  627. {
  628. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  629. {
  630. returnErrorMsg("财务要求已下单已发货无法重置");
  631. return;
  632. }
  633. }
  634. entity.IsUrgency = false;
  635. entity.seller_memo = "";
  636. entity.OtherMemo = "";
  637. entity.OrderState = 0;
  638. entity.IsReturn = 0;
  639. //entity.IsRefund = 0;
  640. entity.MemoOpt = 0;
  641. entity.AfterSaleState = 0;
  642. entity.AfterSaleResponsible = "";
  643. entity.AfterSaleUserId = 0;
  644. entity.IsNeedBill = 0;
  645. entity.CustomerUserId = 0;
  646. entity.DesignUserId = 0;
  647. entity.SupplierId = 0;
  648. entity.PlaceUserId = 0;
  649. entity.ptid = "";
  650. entity.IsSample = 0;
  651. entity.IsXianHuo = 0;
  652. entity.isDianziOrder = 0;
  653. entity.DispatchSort = 0;
  654. entity.FinishPlaceTime = null;
  655. entity.Update();
  656. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  657. if (trade != null)
  658. {
  659. trade.seller_memo = "";
  660. trade.Update();
  661. }
  662. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  663. returnSuccessMsg("重置成功!");
  664. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  665. if (desginBill != null)
  666. {
  667. desginBill.isDel = 1;
  668. desginBill.Update();
  669. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  670. }
  671. ApiVo apiVo = new ApiVo();
  672. apiVo.orderNumber = entity.ctid;
  673. apiVo.actionName = "resetDesign";
  674. designHelper.API_WorkCore(apiVo);//resetDesign
  675. return;
  676. }
  677. returnErrorMsg("找不到记录");
  678. }
  679. }
  680. public void save_erp_sellermemo()
  681. {
  682. if (UrlPostParmsCheck("ctid"))
  683. {
  684. string ctid = GetPostString("ctid");
  685. CeErpTradeCell entity = null;
  686. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  687. if (entity != null)
  688. {
  689. string memo = GetPostString("seller_memo");
  690. memo = memo.Replace(" ", "");
  691. if (memo.Contains("补差"))
  692. {
  693. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  694. return;
  695. }
  696. List<string> bitList = new List<string>
  697. {
  698. "\\","/",":","*","?", "\"","<" ,">","|"
  699. };
  700. bool isIn = false;
  701. foreach (string bit in bitList)
  702. {
  703. if (memo.Contains(bit))
  704. {
  705. isIn = true;
  706. }
  707. }
  708. if (isIn)
  709. {
  710. returnErrorMsg("不能使用 一些符合作为文件名");
  711. return;
  712. }
  713. if (entity.seller_memo != memo)
  714. {
  715. if (entity.IsSample == 2)
  716. {
  717. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  718. return;
  719. }
  720. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  721. {
  722. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  723. {
  724. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  725. return;
  726. }
  727. /*if (CurrentUser.UserPost.Post.Code != "Place")
  728. {
  729. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  730. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  731. {
  732. returnErrorMsg("售前系统订单无法再此修改!");
  733. return;
  734. }
  735. }*/
  736. }
  737. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  738. }
  739. commonHelper.getCytPrice(entity);
  740. int memoopt = GetPostInt("MemoOpt");
  741. Boolean ismemoopt = false;
  742. if (memoopt > 0)
  743. {
  744. string stropt = "";
  745. if (memoopt == 1)
  746. {
  747. stropt = "“改稿”";
  748. ismemoopt = true;
  749. }
  750. else if (memoopt == 2)
  751. {
  752. stropt = "“定稿”";
  753. }
  754. else if (memoopt == 3)
  755. {
  756. stropt = "“查货”";
  757. CeErpSukuraData.createInfo(entity.ctid, 6);
  758. }
  759. entity.MemoOpt = Convert.ToInt32(memoopt);
  760. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  761. }
  762. if (entity.OrderState < 5)
  763. {
  764. memo = memo.Replace("(", "(");
  765. memo = memo.Replace(")", ")");
  766. }
  767. if (entity.OrderState < 3)
  768. {
  769. entity.DispatchSort = 0;
  770. }
  771. entity.seller_memo = memo;
  772. entity.UpdateTime = DateTime.Now;
  773. entity.Update();
  774. ApiVo apiVo = new ApiVo();
  775. apiVo.orderNumber = entity.ctid;
  776. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  777. apiVo.orderRemarks = memo;
  778. apiVo.remarkSign = memoopt;
  779. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  780. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  781. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  782. {
  783. dataHelper.api_orderBack(entity.ctid, "0", "");
  784. }
  785. if (entity.seller_memo.Contains("改稿"))
  786. {
  787. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  788. }
  789. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  790. returnSuccessMsg("保存成功!");
  791. return;
  792. }
  793. returnErrorMsg("找不到记录");
  794. }
  795. }
  796. public void ins_erp_checkorder()
  797. {
  798. if (UrlPostParmsCheck("ctid"))
  799. {
  800. string ctid = GetPostString("ctid");
  801. CeErpTradeCell entity = null;
  802. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  803. if (entity != null)
  804. {
  805. if (entity.OrderState < 6)
  806. {
  807. returnErrorMsg("下单完成后才可查货");
  808. return;
  809. }
  810. /*if (entity.OrderState > 6)
  811. {
  812. returnErrorMsg("订单已发货");
  813. return;
  814. }*/
  815. if (entity.FinishPlaceTime != null)
  816. {
  817. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  818. {
  819. returnErrorMsg("下单时间不足,无法查货");
  820. return;
  821. }
  822. }
  823. entity.MemoOpt = 3;
  824. entity.CheckOrderTime = DateTime.Now;
  825. entity.UpdateTime = DateTime.Now;
  826. entity.Update();
  827. CeErpSukuraData.createInfo(entity.ctid, 6);
  828. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  829. returnSuccessMsg("操作成功!");
  830. return;
  831. }
  832. returnErrorMsg("找不到记录");
  833. }
  834. }
  835. public void save_erp_othermemo()
  836. {
  837. if (UrlPostParmsCheck("ctid"))
  838. {
  839. string ctid = GetPostString("ctid");
  840. CeErpTradeCell entity = null;
  841. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  842. if (entity != null)
  843. {
  844. entity.OtherMemo = GetPostString("otherMemo");
  845. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  846. {
  847. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  848. StringBuilder sql = new StringBuilder();
  849. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  850. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  851. if (dt != null && dt.Rows.Count > 0)
  852. {
  853. foreach (DataRow dr in dt.Rows)
  854. {
  855. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  856. {
  857. //品类一直
  858. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  859. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  860. if (ceErpSampleCustomer == null)
  861. {
  862. ceErpSampleCustomer = new CeErpSampleCustomer();
  863. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  864. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  865. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  866. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  867. ceErpSampleCustomer.shopId = entity.ShopId;
  868. }
  869. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  870. ceErpSampleCustomer.lastTid = entity.tid;
  871. if (ceErpSampleCustomer.ID > 0)
  872. {
  873. ceErpSampleCustomer.Update();
  874. }
  875. else
  876. {
  877. ceErpSampleCustomer.Create();
  878. }
  879. }
  880. }
  881. }
  882. }
  883. //if (entity.IsOldCustomer == 1)
  884. //{
  885. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  886. //{
  887. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  888. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  889. //}
  890. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  891. //{
  892. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  893. // {
  894. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  895. // {
  896. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  897. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  898. // }
  899. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  900. // {
  901. // entity.OrderState = 2;
  902. // entity.DesignUserId = 0;
  903. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  904. // }
  905. // else
  906. // {
  907. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  908. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  909. // }
  910. // }
  911. //}
  912. //}
  913. entity.UpdateTime = DateTime.Now;
  914. entity.Update();
  915. returnSuccessMsg("保存成功!");
  916. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  917. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  918. if (entity.OtherMemo.Contains("改稿"))
  919. {
  920. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  921. }
  922. return;
  923. }
  924. returnErrorMsg("找不到记录");
  925. }
  926. }
  927. public void save_erp_customermemo()
  928. {
  929. if (UrlPostParmsCheck("ctid"))
  930. {
  931. string ctid = GetPostString("ctid");
  932. CeErpTradeCell entity = null;
  933. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  934. if (entity != null)
  935. {
  936. entity.UpdateTime = DateTime.Now;
  937. entity.CustomerMemo = GetPostString("CustomerMemo");
  938. entity.Update();
  939. ApiVo apiVo = new ApiVo();
  940. apiVo.orderNumber = entity.ctid;
  941. apiVo.actionName = "followRemarks";
  942. apiVo.orderRemarks = entity.CustomerMemo;
  943. designHelper.API_WorkCore(apiVo);//followRemarks
  944. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  945. returnSuccessMsg("保存成功!");
  946. return;
  947. }
  948. returnErrorMsg("找不到记录");
  949. }
  950. }
  951. public void upd_erp_addmemotag()
  952. {
  953. if (UrlPostParmsCheck("ctid"))
  954. {
  955. ;
  956. string eid = GetPostString("ctid");
  957. string sfTagstr = GetPostString("memotag");
  958. CeErpTradeCell entity = null;
  959. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  960. if (entity != null)
  961. {
  962. ApiVo apiVo = new ApiVo();
  963. if (entity.OrderState == 0)
  964. {
  965. returnErrorMsg("请先领单");
  966. return;
  967. }
  968. //撤销顺丰
  969. if (sfTagstr == "撤销顺丰")
  970. {
  971. entity.IsSF = 0;
  972. string reMsg = "";
  973. string oldmemo = entity.seller_memo;
  974. if (entity.OrderState < 5)
  975. {
  976. oldmemo = oldmemo.Replace("顺丰到付", "");
  977. oldmemo = oldmemo.Replace("顺丰寄付", "");
  978. entity.seller_memo = oldmemo;
  979. }
  980. else
  981. {
  982. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  983. {
  984. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  985. }
  986. }
  987. entity.Update();
  988. apiVo.orderNumber = entity.ctid;
  989. apiVo.actionName = "orderRemarks";
  990. apiVo.orderRemarks = entity.seller_memo;
  991. apiVo.isSf = entity.IsSF.ToString();
  992. designHelper.API_WorkCore(apiVo);//orderRemarks
  993. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  994. returnSuccessMsg("撤销成功!" + reMsg);
  995. return;
  996. }
  997. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  998. {
  999. //string oldmemo = entity.seller_memo;
  1000. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1001. string sfStr = GetPostString("memotag");
  1002. string smemo = entity.seller_memo;
  1003. int kindex = smemo.IndexOf(")");
  1004. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1005. if (lastoneStr != "-")
  1006. {
  1007. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1008. }
  1009. string prememo = smemo.Substring(0, kindex + 2);
  1010. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1011. int lastkindex = lastmemo.IndexOf("(");
  1012. string newlastmemo = "";
  1013. if (lastkindex == 0)
  1014. {
  1015. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1016. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1017. }
  1018. else
  1019. {
  1020. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1021. }
  1022. entity.seller_memo = prememo + newlastmemo;
  1023. }
  1024. string sfTagMSg = "";
  1025. if (sfTagstr == "顺丰寄付")
  1026. {
  1027. entity.IsSF = 1;
  1028. sfTagMSg = "顺丰寄付";
  1029. }
  1030. else if (sfTagstr == "顺丰到付")
  1031. {
  1032. entity.IsSF = 2;
  1033. sfTagMSg = "顺丰到付";
  1034. }
  1035. entity.Update();
  1036. apiVo = new ApiVo();
  1037. apiVo.orderNumber = entity.ctid;
  1038. apiVo.actionName = "orderRemarks";
  1039. apiVo.orderRemarks = entity.seller_memo;
  1040. apiVo.isSf = entity.IsSF.ToString();
  1041. designHelper.API_WorkCore(apiVo);//orderRemarks
  1042. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1043. returnSuccessMsg("标记成功!");
  1044. return;
  1045. }
  1046. returnErrorMsg("找不到记录");
  1047. }
  1048. }
  1049. public void upd_erp_ordertag()
  1050. {
  1051. if (UrlPostParmsCheck("ctid"))
  1052. {
  1053. string eid = GetPostString("ctid");
  1054. CeErpTradeCell entity = null;
  1055. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1056. if (entity != null)
  1057. {
  1058. int tag = GetPostInt("wechattag");
  1059. //if(tag==4 && entity.IsSample == 2)
  1060. //{
  1061. // returnErrorMsg("补差价单不能标记微信单");
  1062. // return;
  1063. //}
  1064. entity.wechatTag = tag;
  1065. entity.Update();
  1066. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1067. if (tag == 1)
  1068. {
  1069. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1070. if (cash == null)
  1071. {
  1072. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1073. cash = new CeErpReturnCash();
  1074. cash.tid = entity.tid;
  1075. cash.seller_nick = main.seller_nick;
  1076. cash.payment = trade.payment;
  1077. cash.buyer_nick = main.buyer_nick;
  1078. cash.cashstate = 0;
  1079. cash.rtype = "微信返现";
  1080. cash.returnprice = 0;
  1081. cash.created = DateTime.Now;
  1082. cash.con = "订单标记微信单";
  1083. cash.img = "";
  1084. cash.applyuserid = CurrentUser.UserID;
  1085. cash.Create();
  1086. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1087. }
  1088. else
  1089. {
  1090. cash.cashstate = 0;
  1091. cash.Update();
  1092. }
  1093. CeErpSukuraData.createInfo(entity.ctid, 9);
  1094. }
  1095. else if (tag == 2)
  1096. {
  1097. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1098. if (cash == null)
  1099. {
  1100. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1101. cash = new CeErpReturnCash();
  1102. cash.tid = entity.tid;
  1103. cash.seller_nick = main.seller_nick;
  1104. cash.payment = trade.payment;
  1105. cash.buyer_nick = main.buyer_nick;
  1106. cash.cashstate = 0;
  1107. cash.rtype = "推购返现";
  1108. cash.returnprice = 5;
  1109. cash.created = DateTime.Now;
  1110. cash.con = "订单标记推购单";
  1111. cash.img = "";
  1112. cash.applyuserid = CurrentUser.UserID;
  1113. cash.Create();
  1114. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1115. }
  1116. else
  1117. {
  1118. cash.cashstate = 0;
  1119. cash.Update();
  1120. }
  1121. CeErpSukuraData.createInfo(entity.ctid, 9);
  1122. }
  1123. else if (tag == 3)
  1124. {
  1125. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1126. if (pers == null)
  1127. {
  1128. pers = new CeErpPersuade();
  1129. pers.ctid = entity.ctid;
  1130. pers.pstate = 0;
  1131. pers.created = DateTime.Now;
  1132. pers.applyuserid = CurrentUser.UserID;
  1133. pers.Create();
  1134. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1135. }
  1136. else
  1137. {
  1138. pers.pstate = 0;
  1139. pers.Update();
  1140. }
  1141. }
  1142. else if (tag == 4 || tag == 5)
  1143. {
  1144. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1145. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1146. if (pers == null)
  1147. {
  1148. pers = CeErpStayGoods.GetByTid(entity.tid);
  1149. }
  1150. if (pers == null)
  1151. {
  1152. pers = new CeErpStayGoods();
  1153. pers.t_id = entity.tid;
  1154. pers.ctid = entity.ctid;
  1155. pers.status = "待审核";
  1156. pers.audit_type = 0;
  1157. if (tag == 4)
  1158. {
  1159. pers.stay_type = "微信推购";
  1160. }
  1161. else
  1162. {
  1163. pers.stay_type = "旺旺推购";
  1164. }
  1165. if (entity.IsXianHuo == 0)
  1166. {
  1167. pers.product_id = entity.ProductId;
  1168. }
  1169. pers.wangwang = main.buyer_nick;
  1170. pers.shop_name = main.seller_nick;
  1171. pers.creata_time = DateTime.Now;
  1172. pers.create_u_id = CurrentUser.UserID;
  1173. pers.create_u_name = CurrentUser.UserName;
  1174. pers.Create();
  1175. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1176. }
  1177. else
  1178. {
  1179. pers.ctid = entity.ctid;
  1180. pers.audit_type = 0;
  1181. pers.Update();
  1182. }
  1183. CeErpSukuraData.createInfo(entity.ctid, 10);
  1184. }
  1185. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1186. returnSuccessMsg("标记成功!");
  1187. return;
  1188. }
  1189. returnErrorMsg("找不到记录");
  1190. }
  1191. }
  1192. public void upd_erp_ordertag_cancel()
  1193. {
  1194. if (UrlPostParmsCheck("ctid"))
  1195. {
  1196. string eid = GetPostString("ctid");
  1197. CeErpTradeCell entity = null;
  1198. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1199. if (entity != null)
  1200. {
  1201. entity.wechatTag = 0;
  1202. entity.Update();
  1203. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1204. if (pers != null)
  1205. {
  1206. pers.status = "取消推购";
  1207. pers.audit_type = 3;
  1208. pers.Update();
  1209. }
  1210. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1211. returnSuccessMsg("标记成功!");
  1212. return;
  1213. }
  1214. returnErrorMsg("找不到记录");
  1215. }
  1216. }
  1217. public void upd_erp_addweichattag()
  1218. {
  1219. if (UrlPostParmsCheck("ctid"))
  1220. {
  1221. ;
  1222. string eid = GetPostString("ctid");
  1223. CeErpTradeCell entity = null;
  1224. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1225. if (entity != null)
  1226. {
  1227. if (entity.IsAddWechat > 0)
  1228. {
  1229. returnErrorMsg("此单已经标记过了");
  1230. return;
  1231. }
  1232. 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);
  1233. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1234. if (dt.Rows.Count > 0)
  1235. {
  1236. entity.IsAddWechat = 2;
  1237. }
  1238. else
  1239. {
  1240. entity.IsAddWechat = 1;
  1241. }
  1242. entity.Update();
  1243. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1244. returnSuccessMsg("标记成功!");
  1245. return;
  1246. }
  1247. returnErrorMsg("找不到记录");
  1248. }
  1249. }
  1250. public void upd_erp_getmyorder()
  1251. {
  1252. if (UrlPostParmsCheck("ctid"))
  1253. {
  1254. ;
  1255. string eid = GetPostString("ctid");
  1256. CeErpTradeCell entity = null;
  1257. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1258. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1259. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1260. {
  1261. returnErrorMsg("台湾客户需填写身份证号!");
  1262. return;
  1263. }
  1264. if (entity != null)
  1265. {
  1266. if (entity.ctid.IndexOf("C") != -1)
  1267. {
  1268. StringBuilder sql = new StringBuilder();
  1269. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1270. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1271. if (dt.Rows.Count > 0)
  1272. {
  1273. decimal total = 0;
  1274. foreach (DataRow dr in dt.Rows)
  1275. {
  1276. total += Convert.ToDecimal(dr["payment"]);
  1277. }
  1278. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1279. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1280. {
  1281. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1282. return;
  1283. }
  1284. }
  1285. }
  1286. if (entity.OrderState == -1)
  1287. {
  1288. returnErrorMsg("待审核订单无法领取!");
  1289. return;
  1290. }
  1291. entity.CustomerUserId = CurrentUser.UserID;
  1292. if (entity.OrderState < 2)
  1293. {
  1294. entity.OrderState = 2;
  1295. if (entity.ShopId != 0)
  1296. {
  1297. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1298. }
  1299. }
  1300. entity.UpdateTime = DateTime.Now;
  1301. entity.Update();
  1302. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1303. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1304. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1305. {
  1306. dataHelper.api_orderBack(entity.ctid, "0", "");
  1307. }
  1308. returnSuccessMsg("领单成功!");
  1309. return;
  1310. }
  1311. returnErrorMsg("找不到记录");
  1312. }
  1313. }
  1314. public void getmyorder_from_init()
  1315. {
  1316. if (UrlPostParmsCheck("ctid"))
  1317. {
  1318. string eid = GetPostString("ctid");
  1319. CeErpTradeCell entity = null;
  1320. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1321. if (entity != null)
  1322. {
  1323. string sellerMemo = GetPostString("sellerMemo");
  1324. if (sellerMemo.Length > 0)
  1325. {
  1326. entity.seller_memo = sellerMemo;
  1327. }
  1328. string oterhMemo = GetPostString("otherMemo");
  1329. if (oterhMemo.Length > 0)
  1330. {
  1331. entity.OtherMemo = oterhMemo;
  1332. }
  1333. int urg = GetPostInt("urgency");
  1334. entity.IsUrgency = (urg == 1 ? true : false);
  1335. int wechat = GetPostInt("wechat");
  1336. int command = GetPostInt("command");
  1337. if (wechat == 1)
  1338. {
  1339. entity.wechatTag = 1;
  1340. }
  1341. if (command == 1)
  1342. {
  1343. entity.wechatTag = 2;
  1344. }
  1345. string pPro = GetPostString("pprofession");
  1346. if (pPro.Length > 0)
  1347. {
  1348. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1349. string spro = GetPostString("profession");
  1350. if (spro.Length > 0)
  1351. {
  1352. entity.ProfessionId = Convert.ToInt32(spro);
  1353. }
  1354. }
  1355. string proId = GetPostString("productId");
  1356. if (proId.Length > 0)
  1357. {
  1358. entity.ProductId = Convert.ToInt32(proId);
  1359. }
  1360. entity.Material = GetPostString("material");
  1361. entity.Craft = GetPostString("craft");
  1362. entity.CustomerUserId = CurrentUser.UserID;
  1363. if (entity.OrderState < 2)
  1364. {
  1365. entity.OrderState = 2;
  1366. if (entity.ShopId != 0)
  1367. {
  1368. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1369. }
  1370. }
  1371. entity.Update();
  1372. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1373. returnSuccessMsg("领单成功!");
  1374. return;
  1375. }
  1376. returnErrorMsg("找不到记录");
  1377. }
  1378. }
  1379. public void upd_erp_setrelationorder()
  1380. {
  1381. if (UrlPostParmsCheck("ctid"))
  1382. {
  1383. ;
  1384. string eid = GetPostString("ctid");
  1385. string ftid = GetPostString("ftid");
  1386. CeErpTradeCell entity = null;
  1387. CeErpTradeCell fentity = null;
  1388. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1389. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1390. if (fentity == null)
  1391. {
  1392. returnErrorMsg("找不到关联的主订单");
  1393. return;
  1394. }
  1395. if (entity != null)
  1396. {
  1397. if (entity.OrderState >= 5)
  1398. {
  1399. returnErrorMsg("本单已经设计完成无法关联");
  1400. return;
  1401. }
  1402. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1403. {
  1404. returnErrorMsg("线下单续审核后才能关联!");
  1405. return;
  1406. }
  1407. entity.ptid = ftid;
  1408. entity.OrderState = fentity.OrderState;
  1409. //entity.status = fentity.status;
  1410. entity.CustomerUserId = fentity.CustomerUserId;
  1411. entity.DesignUserId = fentity.DesignUserId;
  1412. entity.seller_memo = "补差价单:" + ftid;
  1413. entity.IsSample = 2;
  1414. entity.Update();
  1415. ApiVo apiVo = new ApiVo();
  1416. apiVo.orderNumber = ftid;
  1417. apiVo.payment = entity.payment;
  1418. apiVo.actionName = "repairDesign";
  1419. designHelper.API_WorkCore(apiVo);//repairDesign
  1420. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1421. returnSuccessMsg("关联成功!");
  1422. return;
  1423. }
  1424. else
  1425. returnErrorMsg("找不到记录");
  1426. }
  1427. }
  1428. public void download_erp_neworder()
  1429. {
  1430. string seller = GetPostString("seller_nick");
  1431. string tid = GetPostString("tid");
  1432. if (seller.Length <= 0 || tid.Length <= 0)
  1433. {
  1434. returnErrorMsg("数据错误");
  1435. }
  1436. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1437. //{
  1438. // returnErrorMsg("找不到店铺Sessionkey");
  1439. //}
  1440. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1441. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1442. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1443. if (res.IndexOf("refOid") == -1)
  1444. {
  1445. returnErrorMsg("下载订单数据失败");
  1446. return;
  1447. }
  1448. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1449. returnSuccessMsg("下载完成");
  1450. //tmcHelper.createNewOrder(res);
  1451. //CeErpTrade entr = null;
  1452. //entr = CeErpTrade.Get(tid);
  1453. //if (entr != null)
  1454. //{
  1455. // returnSuccess("下载成功");
  1456. // //下载成功之后,Cell表生成对应的订单;
  1457. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1458. //}
  1459. //else
  1460. //{
  1461. // returnErrorMsg("下载失败或者创建订单失败");
  1462. //}
  1463. }
  1464. public void set_erp_atersale()
  1465. {
  1466. if (UrlPostParmsCheck("ctid"))
  1467. {
  1468. string eid = GetPostString("ctid");
  1469. string reason = GetPostString("AfterSaleReason");
  1470. CeErpTradeCell entity = null;
  1471. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1472. if (entity != null)
  1473. {
  1474. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1475. {
  1476. returnErrorMsg("此订单已经在售后");
  1477. return;
  1478. }
  1479. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1480. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1481. entity.AfterSaleTime = DateTime.Now;
  1482. entity.Update();
  1483. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1484. returnSuccessMsg("转售后成功!");
  1485. return;
  1486. }
  1487. returnErrorMsg("找不到记录");
  1488. }
  1489. }
  1490. public void set_erp_withdraw()
  1491. {
  1492. if (UrlPostParmsCheck("ctid"))
  1493. {
  1494. try
  1495. {
  1496. string eid = GetPostString("ctid");//商品id
  1497. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1498. CeWithdraw ceWithdrawSelect = null;
  1499. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1500. if (ceWithdrawSelect != null)
  1501. {
  1502. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1503. {
  1504. ceWithdrawSelect.status = -1;
  1505. ceWithdrawSelect.Update();
  1506. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1507. returnSuccessMsg("重新发起审核成功");
  1508. return;
  1509. }
  1510. else
  1511. {
  1512. returnSuccessMsg("请勿重复申请!");
  1513. return;
  1514. }
  1515. }
  1516. else
  1517. {
  1518. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1519. if (string.IsNullOrEmpty(CustomerUserId))
  1520. {
  1521. CustomerUserId = "-1";
  1522. }
  1523. int Userid = CurrentUser.UserID;//用户id
  1524. CeWithdraw ceWithdraw = new CeWithdraw();
  1525. ceWithdraw.tid = eid;
  1526. ceWithdraw.userid = Userid;
  1527. ceWithdraw.providerid = CustomerUserId;
  1528. ceWithdraw.status = 3;
  1529. ceWithdraw.creationtime = DateTime.Now;
  1530. ceWithdraw.Create();
  1531. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1532. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1533. return;
  1534. }
  1535. }
  1536. catch
  1537. {
  1538. returnErrorMsg("申请撤回订单失败");
  1539. return;
  1540. }
  1541. }
  1542. }
  1543. public void ins_erp_billinfo()
  1544. {
  1545. if (UrlPostParmsCheck("ctid"))
  1546. {
  1547. string eid = GetPostString("ctid");
  1548. CeErpTradeCell entity = null;
  1549. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1550. if (entity != null)
  1551. {
  1552. CeErpBill bill = CeErpBill.GetByTid(eid);
  1553. bool isHave = false;
  1554. if (bill != null)
  1555. {
  1556. isHave = true;
  1557. if (bill.state != 4)
  1558. {
  1559. returnErrorMsg("此单已经申请过发票了");
  1560. return;
  1561. }
  1562. }
  1563. if (entity.IsNeedBill == 0)
  1564. {
  1565. entity.IsNeedBill = 1;
  1566. }
  1567. entity.Update();
  1568. string errjson = "";
  1569. try
  1570. {
  1571. CeErpBill bill_entity = new CeErpBill();
  1572. bill_entity.tid = entity.tid;
  1573. bill_entity.title = GetPostString("title");
  1574. string taxstr = GetPostString("tax");
  1575. taxstr = taxstr.Replace(" ", "");
  1576. bill_entity.tax = taxstr;
  1577. bill_entity.bank = GetPostString("bank");
  1578. string bankacstr = GetPostString("bankac");
  1579. bankacstr = bankacstr.Replace(" ", "");
  1580. bill_entity.bankac = bankacstr;
  1581. bill_entity.address = GetPostString("address");
  1582. bill_entity.phone = GetPostString("phone");
  1583. bill_entity.price = GetPostString("price");
  1584. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1585. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1586. {
  1587. billCount += 1;
  1588. }
  1589. string prebill = "ltb";
  1590. for (int idx = 1; idx <= billCount; idx++)
  1591. {
  1592. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1593. string billoid = prebill + idx + dtstr;
  1594. bill_entity.billOrderId += billoid;
  1595. if (idx < billCount)
  1596. {
  1597. bill_entity.billOrderId += ",";
  1598. }
  1599. }
  1600. bill_entity.productId = GetPostInt("ProductName");
  1601. bill_entity.num = GetPostInt("num");
  1602. bill_entity.unit = GetPostString("unit");
  1603. bill_entity.type = GetPostString("type");
  1604. bill_entity.sendType = GetPostString("SendType");
  1605. bill_entity.email = GetPostString("email");
  1606. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1607. bill_entity.shopName = GetPostString("ShopName");
  1608. bill_entity.applymemo = GetPostString("applyMemo");
  1609. bill_entity.createTime = DateTime.Now;
  1610. bill_entity.state = 0;
  1611. bill_entity.userId = CurrentUser.UserID;
  1612. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1613. bill_entity.Create();
  1614. }
  1615. catch (Exception ex)
  1616. {
  1617. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1618. returnErrorMsg("创建发票出错!");
  1619. return;
  1620. }
  1621. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1622. returnSuccessMsg("发票申请成功!");
  1623. return;
  1624. }
  1625. returnErrorMsg("找不到记录");
  1626. }
  1627. }
  1628. public void ins_erp_neworder()
  1629. {
  1630. if (UrlPostParmsCheck("receiver_name"))
  1631. {
  1632. CeErpTrade entity = new CeErpTrade();
  1633. string plat_form = GetPostString("platform");
  1634. string preStr = "N_";
  1635. if (plat_form == "拼多多")
  1636. {
  1637. preStr = "P_";
  1638. }
  1639. else if (plat_form == "阿里巴巴")
  1640. {
  1641. preStr = "A_";
  1642. }
  1643. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1644. entity.seller_nick = GetPostString("seller_nick");
  1645. entity.buyer_nick = GetPostString("buyer_nick");
  1646. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1647. entity.total_fee = entity.payment;
  1648. entity.pay_time = DateTime.Now;
  1649. entity.status = "NOT_SHIPPED";
  1650. entity.receiver_name = GetPostString("receiver_name");
  1651. entity.receiver_mobile = GetPostString("receiver_mobile");
  1652. entity.receiver_state = GetPostString("receiver_state");
  1653. entity.receiver_city = GetPostString("receiver_city");
  1654. entity.receiver_district = GetPostString("receiver_district");
  1655. entity.receiver_address = GetPostString("receiver_address");
  1656. if (entity.receiver_state == "" || entity.receiver_city == "")
  1657. {
  1658. returnErrorMsg("收件地址不能为空");
  1659. return;
  1660. }
  1661. int shopId = 0;
  1662. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1663. if (nShop != null)
  1664. {
  1665. shopId = nShop.ID;
  1666. }
  1667. if (shopId != 34 && entity.payment == 0)
  1668. {
  1669. returnErrorMsg("公司自用的单金额才能为0");
  1670. return;
  1671. }
  1672. entity.Create();
  1673. CeErpTradeCell entitycell = new CeErpTradeCell();
  1674. entitycell.ctid = entity.tid;
  1675. entitycell.tid = entity.tid;
  1676. entitycell.ShopId = shopId;
  1677. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1678. entitycell.OrderState = 0;
  1679. entitycell.pay_time = entity.pay_time;
  1680. entitycell.IsOffLineOrder = 1;
  1681. entitycell.Create();
  1682. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1683. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1684. return;
  1685. }
  1686. }
  1687. public void ins_erp_neworder2()
  1688. {
  1689. if (UrlPostParmsCheck("receiver_name"))
  1690. {
  1691. //string plat_form = GetPostString("platform");
  1692. string preStr = "X_";
  1693. string memo = GetPostString("memo");
  1694. string productId = GetPostString("productId");
  1695. string primg = GetPostString("proofimg");
  1696. string sellerNick = GetPostString("seller_nick");
  1697. string addFrom = GetPostString("addfrom");
  1698. if (addFrom == "1")
  1699. {
  1700. preStr = "N_";
  1701. }
  1702. int shopId = 0;
  1703. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1704. if (nShop != null)
  1705. {
  1706. shopId = nShop.ID;
  1707. }
  1708. else
  1709. {
  1710. returnErrorMsg("找不到对应店铺");
  1711. return;
  1712. }
  1713. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1714. {
  1715. returnErrorMsg("必须上传付款凭证");
  1716. return;
  1717. }
  1718. CeErpTrade entity = new CeErpTrade();
  1719. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1720. entity.seller_nick = sellerNick;
  1721. entity.buyer_nick = GetPostString("buyer_nick");
  1722. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1723. entity.total_fee = entity.payment;
  1724. entity.pay_time = DateTime.Now;
  1725. entity.status = "NOT_SHIPPED";
  1726. entity.receiver_name = GetPostString("receiver_name");
  1727. entity.receiver_mobile = GetPostString("receiver_mobile");
  1728. entity.receiver_state = GetPostString("receiver_state");
  1729. entity.receiver_city = GetPostString("receiver_city");
  1730. entity.receiver_district = GetPostString("receiver_district");
  1731. entity.receiver_address = GetPostString("receiver_address");
  1732. entity.seller_memo = memo;
  1733. entity.orderFrom = 20;
  1734. entity.orderType = 15;
  1735. if (entity.receiver_state == "" || entity.receiver_city == "")
  1736. {
  1737. returnErrorMsg("收件地址不能为空");
  1738. return;
  1739. }
  1740. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1741. {
  1742. returnErrorMsg("公司自用的单金额才能为0");
  1743. return;
  1744. }
  1745. entity.Create();
  1746. string toWhere = GetPostString("towhere");
  1747. CeErpTradeCell entitycell = new CeErpTradeCell();
  1748. entitycell.ctid = entity.tid;
  1749. //唯一标识
  1750. entitycell.OrderSn = entity.tid;
  1751. string orderSn = dataHelper.getSaleOrderSn();
  1752. if (orderSn != "")
  1753. {
  1754. entitycell.OrderSn = orderSn;
  1755. }
  1756. entitycell.tid = entity.tid;
  1757. //if (preStr == "X_")
  1758. //{
  1759. entitycell.IsOffLineOrder = 1;
  1760. //}
  1761. entitycell.CustomerUserId = CurrentUser.UserID;
  1762. entitycell.PayProofImg = primg;
  1763. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1764. entitycell.ProductId = Convert.ToInt32(productId);
  1765. entitycell.ShopId = shopId;
  1766. entitycell.UpdateTime = DateTime.Now;
  1767. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1768. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1769. {
  1770. entitycell.IsXianHuo = 1;
  1771. }
  1772. entitycell.pay_time = entity.pay_time;
  1773. if (toWhere == "1")
  1774. {
  1775. entitycell.OrderState = 2;
  1776. }
  1777. else
  1778. {
  1779. entitycell.OrderState = 6;
  1780. entitycell.FinishPlaceTime = entitycell.pay_time;
  1781. }
  1782. if (shopId == 94)
  1783. {
  1784. entitycell.OrderState = 4;
  1785. entitycell.WaitDesignTime = entitycell.pay_time;
  1786. entitycell.StartDesignTime = entitycell.pay_time;
  1787. entitycell.DesignUserId = 218;
  1788. }
  1789. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1790. {
  1791. entitycell.OrderState = -1;//修改12-5
  1792. CeWithdraw ceWithdraw = new CeWithdraw();
  1793. ceWithdraw.tid = entity.tid;
  1794. ceWithdraw.providerid = "-1";
  1795. ceWithdraw.status = -1;
  1796. ceWithdraw.creationtime = DateTime.Now;
  1797. ceWithdraw.userid = 1337;
  1798. ceWithdraw.Create();
  1799. }
  1800. entitycell.Create();
  1801. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1802. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1803. {
  1804. addPlaceRegist(entitycell, CurrentUser.UserID);
  1805. }
  1806. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1807. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1808. return;
  1809. }
  1810. }
  1811. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1812. {
  1813. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1814. entity.PlactTime = tradecell.pay_time;
  1815. entity.AddUserId = userid;
  1816. entity.FileName = tradecell.seller_memo;
  1817. entity.Supplier = 24;
  1818. entity.CreateTime = DateTime.Now;
  1819. entity.Did = tradecell.ctid;
  1820. entity.tid = tradecell.tid;
  1821. entity.splitTag = tradecell.SplitTag;
  1822. entity.CurState = "未完成";
  1823. entity.Create();
  1824. }
  1825. public void get_erp_offlinelist()
  1826. {
  1827. DataStruct dStruct = GetPostStruct();
  1828. List<string> lw = new List<string>();
  1829. string tid = GetPostString("ctid");
  1830. string date1 = GetPostString("date1");
  1831. string date2 = GetPostString("date2");
  1832. if (tid.Length > 0 || date1.Length > 0)
  1833. {
  1834. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1835. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1836. if (dw.Length > 0) lw.Add(dw);
  1837. }
  1838. else
  1839. {
  1840. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1841. }
  1842. string shopname = GetPostString("shopname");
  1843. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1844. string buyernick = GetPostString("buyer_nick");
  1845. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1846. string customer = GetPostString("customer");
  1847. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1848. string design = GetPostString("design");
  1849. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1850. string orderState = GetPostString("orderState");
  1851. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1852. string address = GetPostString("address");
  1853. 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));
  1854. string sellermemo = GetPostString("seller_memo");
  1855. if (sellermemo.Length > 0)
  1856. {
  1857. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1858. }
  1859. string price1 = GetPostString("price1");
  1860. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1861. string price2 = GetPostString("price2");
  1862. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1863. //if (PKey != "admin")
  1864. //{
  1865. // string usershop = CurrentUser.User.pemShop;
  1866. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1867. //}
  1868. //if (ex_psize > 0)
  1869. //{
  1870. dStruct.Order = "pay_time desc";
  1871. //}
  1872. //else
  1873. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1874. lw.Add(string.Format("IsOffLineOrder=1"));
  1875. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1876. DataTable dt = null;
  1877. dt = WebCache.GetData("view_erptradecell", dStruct);
  1878. writeGridDataTableJson(dStruct.TotalCount, dt);
  1879. }
  1880. public void get_erp_returncashrecord()
  1881. {
  1882. DataStruct dStruct = GetPostStruct();
  1883. List<string> lw = new List<string>();
  1884. string tid = GetPostString("ctid");
  1885. if (tid.Length > 0)
  1886. {
  1887. lw.Add(string.Format("tid like '%{0}%'", tid));
  1888. dStruct.Order = "id desc";
  1889. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1890. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1891. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1892. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1893. return;
  1894. }
  1895. returnErrorMsg("id数据错误!");
  1896. }
  1897. public void ins_erp_returncashrecord()
  1898. {
  1899. if (UrlPostParmsCheck("tid"))
  1900. {
  1901. string tid = GetPostString("tid");
  1902. string retype = GetPostString("type");
  1903. StringBuilder sql = new StringBuilder();
  1904. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1905. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1906. if (dt.Rows.Count > 0)
  1907. {
  1908. returnErrorMsg("相同返现类型记录已存在");
  1909. return;
  1910. }
  1911. CeErpReturnCash entity = new CeErpReturnCash();
  1912. entity.tid = tid;
  1913. entity.seller_nick = GetPostString("seller_nick");
  1914. string pment = GetPostString("payment");
  1915. if (pment.Length > 0)
  1916. {
  1917. entity.payment = Convert.ToDouble(pment);
  1918. }
  1919. entity.buyer_nick = GetPostString("buyer_nick");
  1920. entity.cashstate = 0;
  1921. entity.rtype = retype;
  1922. string rPrice = GetPostString("returnprice");
  1923. if (rPrice.Length > 0)
  1924. {
  1925. entity.returnprice = Convert.ToDouble(rPrice);
  1926. }
  1927. entity.created = DateTime.Now;
  1928. entity.con = GetPostString("con");
  1929. entity.img = GetPostString("img");
  1930. entity.applyuserid = CurrentUser.UserID;
  1931. entity.Create();
  1932. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1933. returnSuccessMsg("操作成功!");
  1934. return;
  1935. }
  1936. }
  1937. public void set_erp_predelivery()
  1938. {
  1939. if (UrlPostParmsCheck("ctid"))
  1940. {
  1941. string eid = GetPostString("ctid");
  1942. CeErpTradeCell entity = null;
  1943. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1944. if (entity != null)
  1945. {
  1946. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1947. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1948. //{
  1949. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1950. // return;
  1951. //}
  1952. entity.IsPreDelivery = 1;
  1953. entity.Update();
  1954. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1955. returnSuccessMsg("预发货成功!");
  1956. return;
  1957. //string shop = GetPostString("seller_nick");
  1958. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1959. //string comName = GetPostString("comName");
  1960. //string comCode = GetPostString("comCode");
  1961. //string outSid = GetPostString("outSid");//运单号
  1962. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1963. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1964. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1965. //string apires = "";
  1966. //if (deliveryType == "虚拟发货")
  1967. //{
  1968. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1969. //}
  1970. //else
  1971. //{
  1972. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1973. //}
  1974. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1975. ////{
  1976. //if (apires.IndexOf("发货成功") != -1)
  1977. //{
  1978. // if (deliveryType != "虚拟发货")
  1979. // {
  1980. // //还要插入快递信息到 快递信息表
  1981. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1982. // exinfo.tid = eid;
  1983. // exinfo.out_sid = outSid;
  1984. // exinfo.company_code = comCode;
  1985. // exinfo.company_name = comName;
  1986. // exinfo.delivery_memo = deliveryMemo;
  1987. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1988. // exinfo.deliveryType = deliveryType;
  1989. // exinfo.Create();
  1990. // }
  1991. // returnSuccessMsg("发货成功!");
  1992. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1993. //}
  1994. //else
  1995. //{
  1996. // returnErrorMsg("淘宝发货失败!!");
  1997. //}
  1998. //return;
  1999. }
  2000. returnErrorMsg("找不到订单记录");
  2001. }
  2002. }
  2003. public void get_erp_unusuallist()
  2004. {
  2005. DataStruct dStruct = GetPostStruct();
  2006. List<string> lw = new List<string>();
  2007. string tid = GetPostString("ctid");
  2008. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2009. string shopname = GetPostString("shopname");
  2010. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2011. string buyernick = GetPostString("buyer_nick");
  2012. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2013. string ResponsibleMan = GetPostString("responsible");
  2014. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2015. string date1 = GetPostString("date1");
  2016. string date2 = GetPostString("date2");
  2017. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2018. if (dw.Length > 0) lw.Add(dw);
  2019. string price1 = GetPostString("price1");
  2020. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2021. string price2 = GetPostString("price2");
  2022. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2023. string orderState = GetPostString("orderState");
  2024. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2025. string sellermemo = GetPostString("seller_memo");
  2026. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2027. lw.Add(string.Format("UnusualTag > 0"));
  2028. lw.Add(string.Format("IsRefund<={0}", 1));
  2029. dStruct.Order = "pay_time desc";
  2030. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2031. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2032. writeGridDataTableJson(dStruct.TotalCount, dt);
  2033. }
  2034. public void set_erp_unusualtonomal()
  2035. {
  2036. if (UrlPostParmsCheck("ctid"))
  2037. {
  2038. string eid = GetPostString("ctid");
  2039. CeErpTradeCell entity = null;
  2040. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2041. if (entity != null)
  2042. {
  2043. entity.UnusualTag = -1;
  2044. entity.Update();
  2045. returnSuccessMsg("忽略成功!");
  2046. return;
  2047. }
  2048. returnErrorMsg("找不到记录");
  2049. }
  2050. }
  2051. public void ins_erp_unusualreason()
  2052. {
  2053. if (UrlPostParmsCheck("ctid"))
  2054. {
  2055. string eid = GetPostString("ctid");
  2056. CeErpTradeCell entity = null;
  2057. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2058. if (entity != null)
  2059. {
  2060. entity.MemoOpt = 4;
  2061. entity.UnusualCon = GetPostString("con");
  2062. entity.Update();
  2063. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2064. if (trade != null)
  2065. {
  2066. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2067. }
  2068. //查货是否超时
  2069. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2070. if (ceErpTradeCellExtend == null)
  2071. {
  2072. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2073. ceErpTradeCellExtend.ctid = entity.ctid;
  2074. }
  2075. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2076. {
  2077. ceErpTradeCellExtend.CheckOut += 1;
  2078. }
  2079. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2080. if (ceErpTradeCellExtend.ID > 0)
  2081. {
  2082. ceErpTradeCellExtend.Update();
  2083. }
  2084. else
  2085. {
  2086. ceErpTradeCellExtend.Create();
  2087. }
  2088. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2089. returnSuccessMsg("操作成功!");
  2090. return;
  2091. }
  2092. returnErrorMsg("找不到记录");
  2093. }
  2094. }
  2095. public void upd_erp_sampleorder()
  2096. {
  2097. if (UrlPostParmsCheck("ctid"))
  2098. {
  2099. string eid = GetPostString("ctid");
  2100. string[] eArr = eid.Split(',');
  2101. if (eArr.Length > 1)
  2102. {
  2103. List<string> eLst = new List<string>();
  2104. for (int i = 0; i < eArr.Length; i++)
  2105. {
  2106. eLst.Add("'" + eArr[i] + "'");
  2107. }
  2108. eid = string.Join(",", eLst.ToArray());
  2109. }
  2110. else
  2111. {
  2112. eid = "'" + eid + "'";
  2113. }
  2114. StringBuilder sql = new StringBuilder();
  2115. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2116. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2117. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2118. if (dt.Rows.Count > 0)
  2119. {
  2120. string errmsg = "";
  2121. foreach (DataRow dr in dt.Rows)
  2122. {
  2123. StringBuilder sqlsb = new StringBuilder();
  2124. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2125. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2126. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2127. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2128. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2129. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2130. {
  2131. continue;
  2132. }
  2133. else
  2134. {
  2135. string emsg = commonHelper.KeepChinese(apires);
  2136. errmsg += emsg;
  2137. }
  2138. }
  2139. if (errmsg.Length > 0)
  2140. {
  2141. returnErrorMsg(errmsg);
  2142. return;
  2143. }
  2144. returnSuccessMsg("操作成功");
  2145. return;
  2146. }
  2147. returnErrorMsg("找不到记录");
  2148. }
  2149. }
  2150. public void upd_erp_transcustomer()
  2151. {
  2152. if (UrlPostParmsCheck("ctid"))
  2153. {
  2154. string eid = GetPostString("ctid");
  2155. int userid = GetPostInt("CustomerUserId");
  2156. CeErpTradeCell entity = null;
  2157. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2158. if (entity != null)
  2159. {
  2160. //string[] mlist = entity.seller_memo.Split('-');
  2161. //string sql = "select * from view_erpuser where id=" + userid;
  2162. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2163. //if (dt != null && dt.Rows.Count > 0)
  2164. //{
  2165. // string nmemo = "";
  2166. // for(int i = 0; i < mlist.Length - 1; i++)
  2167. // {
  2168. // nmemo += mlist[i];
  2169. // nmemo += "-";
  2170. // }
  2171. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2172. // entity.seller_memo = nmemo;
  2173. //}
  2174. entity.CustomerUserId = userid;
  2175. entity.Update();
  2176. returnSuccessMsg("操作成功!");
  2177. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2178. return;
  2179. }
  2180. returnErrorMsg("找不到记录");
  2181. }
  2182. }
  2183. public void upd_erp_transdesigner()
  2184. {
  2185. if (UrlPostParmsCheck("ctid"))
  2186. {
  2187. string eids = GetPostString("ctid");
  2188. string[] ctidList = eids.Split(',');
  2189. int userid = GetPostInt("DesignUserId");
  2190. foreach (string ctid in ctidList)
  2191. {
  2192. CeErpTradeCell entity = null;
  2193. CeErpDesignerBill entitys = null;
  2194. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2195. entitys = CeErpDesignerBill.GetByTid(ctid);
  2196. if (entity != null)
  2197. {
  2198. if (entity.OrderState > 4)
  2199. {
  2200. continue;
  2201. }
  2202. //存在退款不能流转
  2203. if (entity.IsRefund > 0)
  2204. {
  2205. continue;
  2206. }
  2207. entity.DesignUserId = userid;
  2208. entity.WaitDesignTime = DateTime.Now;
  2209. entity.Update();
  2210. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2211. }
  2212. }
  2213. returnSuccessMsg("操作成功!");
  2214. }
  2215. }
  2216. public void upd_erp_distributedesigner()
  2217. {
  2218. if (UrlPostParmsCheck("ctid"))
  2219. {
  2220. string eid = GetPostString("ctid");
  2221. int userid = GetPostInt("DesignUserId");
  2222. string[] idlist = eid.Split(',');
  2223. if (idlist.Length <= 0)
  2224. {
  2225. returnErrorMsg("订单不能为空");
  2226. return;
  2227. }
  2228. foreach (string ctid in idlist)
  2229. {
  2230. CeErpTradeCell entity = null;
  2231. CeErpDesignerBill entitys = null;
  2232. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2233. else continue;
  2234. if (entity != null)
  2235. {
  2236. if (userid == 2125 || userid == 3542)
  2237. { }
  2238. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2239. {
  2240. returnErrorMsg("金额错误的订单无法指派");
  2241. return;
  2242. }
  2243. if (entity.OrderState >= 5)
  2244. {
  2245. returnErrorMsg("已经设计完成无法指派");
  2246. return;
  2247. }
  2248. if (entity.OrderState == -1)
  2249. {
  2250. returnErrorMsg("审核中的订单无法指派");
  2251. return;
  2252. }
  2253. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2254. {
  2255. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2256. return;
  2257. }
  2258. //157赖橙帆 159林晨 73 静之颖
  2259. 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)
  2260. {
  2261. returnErrorMsg("指派设计共创无法再次指派!");
  2262. return;
  2263. }
  2264. entity.OrderState = 3;
  2265. if (entity.SupplierId == 0)
  2266. {
  2267. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2268. entity.SupplierId = suid;
  2269. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2270. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2271. }
  2272. if (userid == 2125 && entity.seller_memo != "")
  2273. {
  2274. apiDesign.API_GetPrintData_CreateOrder(entity);
  2275. }
  2276. if (userid == 3542 && entity.seller_memo != "")
  2277. {
  2278. string userPost = CurrentUser.UserPost.Post.Code;
  2279. if (CurrentUser.UserID == 73)
  2280. {
  2281. userPost = "SysAdmin";
  2282. }
  2283. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2284. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2285. if (response.msg != "设计共创:成功")
  2286. {
  2287. returnErrorMsg(response.msg);
  2288. return;
  2289. }
  2290. entity.DispatchSort = 2;
  2291. }
  2292. else
  2293. {
  2294. if (entity.DispatchSort == 2)
  2295. {
  2296. ApiVo apiVo = new ApiVo();
  2297. apiVo.actionName = "closeDesign";
  2298. apiVo.orderNumber = entity.ctid;
  2299. designHelper.API_WorkCore(apiVo);//closeDesign
  2300. }
  2301. entity.DispatchSort = 0;
  2302. }
  2303. entity.DesignUserId = userid;
  2304. entity.WaitDesignTime = DateTime.Now;
  2305. entity.UpdateTime = DateTime.Now;
  2306. entity.Update();
  2307. string name = commonHelper.getUserNameById(userid);
  2308. commonHelper.UpdateRelationOrder(entity.ctid);
  2309. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2310. }
  2311. }
  2312. returnSuccessMsg("操作成功!");
  2313. return;
  2314. }
  2315. }
  2316. public string getTidByCtid(string ctid)
  2317. {
  2318. string tid = "";
  2319. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2320. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2321. if (dataTable != null && dataTable.Rows.Count > 0)
  2322. {
  2323. tid = dataTable.Rows[0]["tid"].ToString();
  2324. }
  2325. return tid;
  2326. }
  2327. public List<string> getTidByCtidMore(string ctid)
  2328. {
  2329. 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);
  2330. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2331. List<string> list = new List<string>();
  2332. if (dataTable != null && dataTable.Rows.Count > 0)
  2333. {
  2334. foreach (DataRow item in dataTable.Rows)
  2335. {
  2336. list.Add("'" + item["tid"].ToString() + "'");
  2337. }
  2338. }
  2339. return list;
  2340. }
  2341. public List<string> getTidByCtidLike(string ctid)
  2342. {
  2343. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2344. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2345. List<string> list = new List<string>();
  2346. if (dataTable != null && dataTable.Rows.Count > 0)
  2347. {
  2348. foreach (DataRow item in dataTable.Rows)
  2349. {
  2350. list.Add("'" + item["tid"].ToString() + "'");
  2351. }
  2352. }
  2353. return list;
  2354. }
  2355. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2356. {
  2357. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2358. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2359. List<string> list = new List<string>();
  2360. if (dataTable != null && dataTable.Rows.Count > 0)
  2361. {
  2362. foreach (DataRow item in dataTable.Rows)
  2363. {
  2364. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2365. {
  2366. continue;
  2367. }
  2368. list.Add("'" + item["receiverId"].ToString() + "'");
  2369. }
  2370. }
  2371. return list;
  2372. }
  2373. public void get_erp_myorderlist()
  2374. {
  2375. DataStruct dStruct = GetPostStruct();
  2376. List<string> lw = new List<string>();
  2377. string tid = GetPostString("ctid");
  2378. if (tid.Length > 0)
  2379. {
  2380. string select_tid = getTidByCtid(tid);
  2381. lw.Add(string.Format("tid='{0}'", select_tid));
  2382. }
  2383. else
  2384. {
  2385. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2386. }
  2387. //12-1 修改
  2388. string urgent = GetPostString("urgent");
  2389. string back = GetPostString("back");
  2390. string offlineSearch = GetPostString("offlineSearch");
  2391. if (!string.IsNullOrWhiteSpace(urgent))
  2392. {
  2393. if (urgent.Equals("true"))
  2394. {
  2395. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2396. }
  2397. }
  2398. if (!string.IsNullOrWhiteSpace(back))
  2399. {
  2400. if (back.Equals("true"))
  2401. {
  2402. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2403. }
  2404. }
  2405. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2406. {
  2407. if (offlineSearch.Equals("true"))
  2408. {
  2409. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2410. }
  2411. }
  2412. //end
  2413. string shopname = GetPostString("shopname");
  2414. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2415. string buyernick = GetPostString("buyer_nick");
  2416. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2417. string design = GetPostString("design");
  2418. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2419. string orderState = GetPostString("orderState");
  2420. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2421. string sellermemo = GetPostString("seller_memo");
  2422. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2423. string date1 = GetPostString("date1");
  2424. string date2 = GetPostString("date2");
  2425. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2426. if (dw.Length > 0) lw.Add(dw);
  2427. string price1 = GetPostString("price1");
  2428. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2429. string price2 = GetPostString("price2");
  2430. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2431. string urgency = GetPostString("urgency");
  2432. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2433. string after = GetPostString("after");
  2434. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2435. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2436. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2437. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2438. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2439. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2440. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2441. if (dt != null && dt.Rows.Count > 0)
  2442. {
  2443. foreach (DataRow dr in dt.Rows)
  2444. {
  2445. try
  2446. {
  2447. // 对象操作
  2448. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2449. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2450. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2451. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2452. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2453. if (dStruct.PageSize != 100000)
  2454. {
  2455. if (dr["DispatchSort"].ToString() == "2")
  2456. {
  2457. dr["gongchuang"] = 200;
  2458. }
  2459. else if ("外协".Equals(dr["ToType"].ToString()))
  2460. {
  2461. dr["gongchuang"] = 200;
  2462. }
  2463. else if ("内部".Equals(dr["ToType"].ToString()))
  2464. {
  2465. dr["gongchuang"] = -1;
  2466. }
  2467. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2468. {
  2469. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2470. dr["gongchuang"] = response.code;
  2471. }
  2472. }
  2473. }
  2474. catch (NullReferenceException ex)
  2475. {
  2476. }
  2477. }
  2478. }
  2479. writeGridDataTableJson(dStruct.TotalCount, dt);
  2480. }
  2481. public void get_erp_myreturnorderlist()
  2482. {
  2483. DataStruct dStruct = GetPostStruct();
  2484. List<string> lw = new List<string>();
  2485. string tid = GetPostString("ctid");
  2486. if (tid.Length > 0)
  2487. {
  2488. string select_tid = getTidByCtid(tid);
  2489. lw.Add(string.Format("tid='{0}'", select_tid));
  2490. }
  2491. else
  2492. {
  2493. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2494. }
  2495. string shopname = GetPostString("shopname");
  2496. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2497. string buyernick = GetPostString("buyer_nick");
  2498. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2499. string design = GetPostString("design");
  2500. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2501. string orderState = GetPostString("orderState");
  2502. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2503. string sellermemo = GetPostString("seller_memo");
  2504. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2505. string date1 = GetPostString("date1");
  2506. string date2 = GetPostString("date2");
  2507. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2508. if (dw.Length > 0) lw.Add(dw);
  2509. string price1 = GetPostString("price1");
  2510. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2511. string price2 = GetPostString("price2");
  2512. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2513. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2514. {
  2515. lw.Add(string.Format("CusOrgID = 94"));
  2516. }
  2517. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2518. {
  2519. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2520. }
  2521. else
  2522. {
  2523. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2524. }
  2525. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2526. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2527. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2528. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2529. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2530. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2531. if (dt != null && dt.Rows.Count > 0)
  2532. {
  2533. foreach (DataRow dr in dt.Rows)
  2534. {
  2535. try
  2536. {
  2537. // 对象操作
  2538. if (dStruct.PageSize != 100000)
  2539. {
  2540. if (dr["DispatchSort"].ToString() == "2")
  2541. {
  2542. dr["gongchuang"] = 200;
  2543. }
  2544. else if ("外协".Equals(dr["ToType"].ToString()))
  2545. {
  2546. dr["gongchuang"] = 200;
  2547. }
  2548. else if ("内部".Equals(dr["ToType"].ToString()))
  2549. {
  2550. dr["gongchuang"] = -1;
  2551. }
  2552. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2553. {
  2554. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2555. dr["gongchuang"] = response.code;
  2556. }
  2557. }
  2558. }
  2559. catch (NullReferenceException ex)
  2560. {
  2561. // 处理空引用异常
  2562. }
  2563. }
  2564. }
  2565. writeGridDataTableJson(dStruct.TotalCount, dt);
  2566. }
  2567. public void get_erp_myorderlist_pregather()
  2568. {
  2569. string date1 = GetPostString("date1");
  2570. string date2 = GetPostString("date2");
  2571. int userId = CurrentUser.UserID; //客服id
  2572. string orderWhere = "";
  2573. List<string> lw = new List<string>();
  2574. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2575. if (dw.Length > 0) lw.Add(dw);
  2576. lw.Add(string.Format("CustomerUserId={0}", userId));
  2577. lw.Add(string.Format("OrderState<9"));
  2578. orderWhere = string.Join(" and ", lw.ToArray());
  2579. string orderWhere2 = "";
  2580. List<string> lw2 = new List<string>();
  2581. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2582. if (dw2.Length > 0) lw2.Add(dw2);
  2583. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2584. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2585. string sql = string.Format("select *" +
  2586. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2587. "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 " +
  2588. "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 " +
  2589. "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");
  2590. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2591. //writeGridDataTableJson(dt.Rows.Count, dt);
  2592. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2593. }
  2594. public void upd_erp_publishorder()
  2595. {
  2596. if (UrlPostParmsCheck("ctid"))
  2597. {
  2598. string eid = GetPostString("ctid");
  2599. CeErpTradeCell entity = null;
  2600. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2601. if (entity != null)
  2602. {
  2603. entity.OrderState = 0; //发布后,变为待抢单
  2604. entity.Update();
  2605. commonHelper.UpdateRelationOrder(entity.ctid);
  2606. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2607. returnSuccessMsg("发布成功!");
  2608. return;
  2609. }
  2610. returnErrorMsg("找不到记录");
  2611. }
  2612. }
  2613. public void get_erp_my_tiporder()
  2614. {
  2615. StringBuilder sql = new StringBuilder();
  2616. int userId = 0;
  2617. if (CurrentUser != null) userId = CurrentUser.UserID;
  2618. string posCode = CurrentUser.UserPost.Post.Code;
  2619. string isTipedAfterSaleVerify = GetPostString("af");
  2620. DataTable dt = new DataTable();
  2621. if (posCode != "Supplier")
  2622. {
  2623. if (posCode == "CustomerService" || posCode == "Director")
  2624. {
  2625. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2626. }
  2627. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2628. {
  2629. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2630. }
  2631. else
  2632. {
  2633. string teamIds = CurrentUser.User.TeamIds;
  2634. if (teamIds == "")
  2635. {
  2636. teamIds = "0";
  2637. }
  2638. 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);
  2639. }
  2640. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2641. }
  2642. if (dt.Rows.Count <= 0)
  2643. {
  2644. string key = "aftersale_order_" + userId;
  2645. if (RedisHelper.HasKey(key))
  2646. {
  2647. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2648. dt.Columns.Add("ctid", typeof(string));
  2649. dt.Columns.Add("IsReadTag", typeof(int));
  2650. foreach (var i in list)
  2651. {
  2652. DataRow data = dt.NewRow();
  2653. data["ctid"] = i;
  2654. data["IsReadTag"] = 4;
  2655. dt.Rows.Add(data);
  2656. }
  2657. RedisHelper.StringDelete(key);
  2658. }
  2659. }
  2660. if (dt.Rows.Count <= 0)
  2661. {
  2662. sql = new StringBuilder();
  2663. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2664. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2665. }
  2666. if (posCode == "Supplier")
  2667. {
  2668. string ids = CurrentUser.User.pemVend;
  2669. if (ids != null && ids.Length > 0)
  2670. {
  2671. string[] ids_list = ids.Split(',');
  2672. foreach (var item in ids_list)
  2673. {
  2674. string key = "return_order_" + item;
  2675. if (RedisHelper.HasKey(key))
  2676. {
  2677. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2678. dt.Columns.Add("ctid", typeof(string));
  2679. dt.Columns.Add("IsReadTag", typeof(int));
  2680. foreach (var i in list)
  2681. {
  2682. DataRow data = dt.NewRow();
  2683. data["ctid"] = i;
  2684. data["IsReadTag"] = 1;
  2685. dt.Rows.Add(data);
  2686. }
  2687. RedisHelper.StringDelete(key);
  2688. }
  2689. }
  2690. }
  2691. if (dt.Rows.Count <= 0)
  2692. {
  2693. sql = new StringBuilder();
  2694. 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);
  2695. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2696. }
  2697. }
  2698. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2699. }
  2700. public void reset_erp_tiporder()
  2701. {
  2702. string ids = GetPostString("ids");
  2703. string[] ctidList = ids.Split(',');
  2704. foreach (string ctid in ctidList)
  2705. {
  2706. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2707. if (enty != null)
  2708. {
  2709. enty.IsReadTag = 0;
  2710. enty.Update();
  2711. }
  2712. }
  2713. returnSuccessMsg("成功!");
  2714. return;
  2715. }
  2716. public void get_erp_designlist()
  2717. {
  2718. DataStruct dStruct = GetPostStruct();
  2719. List<string> lw = new List<string>();
  2720. string tid = GetPostString("ctid");
  2721. if (tid.Length > 0)
  2722. {
  2723. string select_tid = getTidByCtid(tid);
  2724. lw.Add(string.Format("tid='{0}'", select_tid));
  2725. }
  2726. string shopname = GetPostString("shopname");
  2727. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2728. string buyernick = GetPostString("buyer_nick");
  2729. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2730. string customer = GetPostString("customer");
  2731. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2732. string design = GetPostString("design");
  2733. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2734. string orderState = GetPostString("orderState");
  2735. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2736. lw.Add(string.Format("OrderState<6"));
  2737. string address = GetPostString("address");
  2738. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2739. string sellermemo = GetPostString("seller_memo");
  2740. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2741. string date1 = GetPostString("date1");
  2742. string date2 = GetPostString("date2");
  2743. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2744. if (dw.Length > 0) lw.Add(dw);
  2745. string apdate1 = GetPostString("apdate1");
  2746. string apdate2 = GetPostString("apdate2");
  2747. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2748. if (dwap.Length > 0) lw.Add(dwap);
  2749. string price1 = GetPostString("price1");
  2750. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2751. string price2 = GetPostString("price2");
  2752. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2753. string designTime = GetPostString("designtime");
  2754. if (designTime.Length > 0)
  2755. {
  2756. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2757. }
  2758. string usershop = CurrentUser.User.pemShop;
  2759. if (usershop.Length > 0)
  2760. {
  2761. lw.Add(string.Format("shopId in ({0})", usershop));
  2762. }
  2763. int myOrgid = CurrentUser.UserPost.OrgID;
  2764. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2765. if (myOrgCode.IndexOf("Designer") != -1)
  2766. {
  2767. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2768. {
  2769. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2770. }
  2771. else
  2772. {
  2773. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2774. }
  2775. }
  2776. else
  2777. {
  2778. string orgId = GetPostString("designerhd");
  2779. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2780. }
  2781. if (tid.Length > 0 || buyernick.Length > 0)
  2782. {
  2783. lw.Add(string.Format("OrderState >= 3"));
  2784. }
  2785. else
  2786. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2787. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2788. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2789. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2790. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2791. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2792. if (dt != null && dt.Rows.Count > 0)
  2793. {
  2794. foreach (DataRow dr in dt.Rows)
  2795. {
  2796. try
  2797. {
  2798. // 对象操作
  2799. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2800. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2801. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2802. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2803. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2804. if (dStruct.PageSize != 100000)
  2805. {
  2806. if (dr["DispatchSort"].ToString() == "2")
  2807. {
  2808. dr["gongchuang"] = 200;
  2809. }
  2810. else if ("外协".Equals(dr["ToType"].ToString()))
  2811. {
  2812. dr["gongchuang"] = 200;
  2813. }
  2814. else if ("内部".Equals(dr["ToType"].ToString()))
  2815. {
  2816. dr["gongchuang"] = -1;
  2817. }
  2818. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2819. {
  2820. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2821. dr["gongchuang"] = response.code;
  2822. }
  2823. }
  2824. }
  2825. catch (NullReferenceException ex)
  2826. {
  2827. }
  2828. }
  2829. }
  2830. writeGridDataTableJson(dStruct.TotalCount, dt);
  2831. }
  2832. public void get_erp_mydesignlist()
  2833. {
  2834. DataStruct dStruct = GetPostStruct();
  2835. List<string> lw = new List<string>();
  2836. string tid = GetPostString("ctid");
  2837. if (tid.Length > 0)
  2838. {
  2839. string select_tid = getTidByCtid(tid);
  2840. lw.Add(string.Format("tid='{0}'", select_tid));
  2841. }
  2842. string shopname = GetPostString("shopname");
  2843. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2844. string buyernick = GetPostString("buyer_nick");
  2845. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2846. string customer = GetPostString("customer");
  2847. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2848. string orderState = GetPostString("orderState");
  2849. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2850. //lw.Add(string.Format("OrderState<6"));
  2851. string date1 = GetPostString("date1");
  2852. string date2 = GetPostString("date2");
  2853. string dw = GetDateWhere("pay_time", date1, date2);
  2854. if (dw.Length > 0) lw.Add(dw);
  2855. string apdate1 = GetPostString("apdate1");
  2856. string apdate2 = GetPostString("apdate2");
  2857. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2858. if (dwap.Length > 0) lw.Add(dwap);
  2859. string price1 = GetPostString("price1");
  2860. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2861. string price2 = GetPostString("price2");
  2862. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2863. string olddownload = GetPostString("olddown");
  2864. if (olddownload == "1")
  2865. {
  2866. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2867. }
  2868. else if (olddownload == "2")
  2869. {
  2870. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2871. }
  2872. string sellermemo = GetPostString("seller_memo");
  2873. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2874. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2875. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2876. {
  2877. if (CurrentUser.User.TeamIds.Length > 0)
  2878. {
  2879. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2880. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2881. else
  2882. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2883. }
  2884. else
  2885. {
  2886. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2887. }
  2888. }
  2889. if (tid.Length <= 0)
  2890. {
  2891. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2892. }
  2893. lw.Add(string.Format("IsReturn!=3"));
  2894. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2895. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2896. string teamids = CurrentUser.User.TeamIds.ToString();
  2897. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2898. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2899. if (dt != null && dt.Rows.Count > 0)
  2900. {
  2901. foreach (DataRow dr in dt.Rows)
  2902. {
  2903. try
  2904. {
  2905. // 对象操作
  2906. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2907. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2908. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2909. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2910. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2911. if (dStruct.PageSize != 100000)
  2912. {
  2913. if (dr["DispatchSort"].ToString() == "2")
  2914. {
  2915. dr["gongchuang"] = 200;
  2916. }
  2917. else if ("外协".Equals(dr["ToType"].ToString()))
  2918. {
  2919. dr["gongchuang"] = 200;
  2920. }
  2921. else if ("内部".Equals(dr["ToType"].ToString()))
  2922. {
  2923. dr["gongchuang"] = -1;
  2924. }
  2925. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2926. {
  2927. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2928. dr["gongchuang"] = response.code;
  2929. }
  2930. }
  2931. }
  2932. catch (NullReferenceException ex)
  2933. {
  2934. }
  2935. }
  2936. }
  2937. writeGridDataTableJson(dStruct.TotalCount, dt);
  2938. }
  2939. public void set_erp_startdesign()
  2940. {
  2941. if (UrlPostParmsCheck("ctid"))
  2942. {
  2943. string eid = GetPostString("ctid");
  2944. CeErpTradeCell entity = null;
  2945. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2946. if (entity != null)
  2947. {
  2948. if (entity.OrderState != 3)
  2949. {
  2950. returnErrorMsg("请刷新,订单已经设计了");
  2951. return;
  2952. }
  2953. entity.StartDesignTime = DateTime.Now;
  2954. entity.OrderState = 4;
  2955. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2956. {
  2957. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2958. entity.SupplierId = suid;
  2959. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2960. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2961. }
  2962. entity.UpdateTime = DateTime.Now;
  2963. //entity.MakeSupplier = suname;
  2964. entity.Update();
  2965. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2966. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2967. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2968. commonHelper.getCytPrice(entity);
  2969. returnSuccessMsg("操作成功!");
  2970. return;
  2971. }
  2972. returnErrorMsg("找不到记录");
  2973. }
  2974. }
  2975. public void ins_erp_designselfmemo()
  2976. {
  2977. if (UrlPostParmsCheck("ctid"))
  2978. {
  2979. string eid = GetPostString("ctid");
  2980. string con = GetPostString("con");
  2981. CeErpTradeCell entity = null;
  2982. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2983. if (entity != null)
  2984. {
  2985. entity.DesignSelfMemo = con;
  2986. entity.Update();
  2987. returnSuccessMsg("操作成功!");
  2988. return;
  2989. }
  2990. returnErrorMsg("找不到记录");
  2991. }
  2992. }
  2993. public void ins_erp_designprice()
  2994. {
  2995. if (UrlPostParmsCheck("ctid"))
  2996. {
  2997. string eid = GetPostString("ctid");
  2998. int uid = CurrentUser.UserID;
  2999. string userName = CurrentUser.UserName;
  3000. CeErpTradeCell entity = null;
  3001. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3002. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3003. if (entitys == null)
  3004. {
  3005. entitys = new CeErpDesignerBill();
  3006. }
  3007. if (entity != null)
  3008. {
  3009. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3010. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3011. entity.StartDesignTime = DateTime.Now;
  3012. entity.OrderState = 4;
  3013. string suname = "";
  3014. if (entity.SupplierId == 0)
  3015. {
  3016. int sid = commonHelper.autoDistributeToSupplier(entity);
  3017. entity.SupplierId = sid;
  3018. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3019. }
  3020. entity.Update();
  3021. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3022. if (ceErpUserPost != null)
  3023. {
  3024. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3025. if (ceErpPost != null)
  3026. {
  3027. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3028. {
  3029. entitys.tid = entity.ctid;
  3030. entitys.oid = entity.tid;
  3031. entitys.uid = uid;
  3032. entitys.userName = userName;
  3033. entitys.designerType = 1;
  3034. entitys.designerTypeText = "内部设计师";
  3035. entitys.price = Convert.ToDouble(GetPostString("price"));
  3036. entitys.designNum = GetPostInt("designNum");
  3037. entitys.modifyNum = GetPostInt("modifyNum");
  3038. entitys.designSize = GetPostString("designSize");
  3039. entitys.modifySize = GetPostString("modifySize");
  3040. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3041. {
  3042. entitys.create_time = DateTime.Now;
  3043. entitys.create_u_id = uid;
  3044. entitys.create_u_name = userName;
  3045. entitys.Save();
  3046. }
  3047. else
  3048. {
  3049. entitys.update_time = DateTime.Now;
  3050. entitys.update_u_id = uid;
  3051. entitys.update_u_name = userName;
  3052. entitys.Update();
  3053. }
  3054. }
  3055. }
  3056. }
  3057. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3058. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3059. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3060. if (suname != "")
  3061. {
  3062. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3063. }
  3064. commonHelper.getCytPrice(entity);
  3065. returnSuccessMsg("操作成功!");
  3066. return;
  3067. }
  3068. returnErrorMsg("找不到记录");
  3069. }
  3070. }
  3071. public void upload_erp_filecomplete()
  3072. {
  3073. if (UrlPostParmsCheck("ctid"))
  3074. {
  3075. string eid = GetPostString("ctid");
  3076. CeErpTradeCell entity = null;
  3077. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3078. if (entity != null)
  3079. {
  3080. entity.OrderState = 5; //设计完成
  3081. entity.Update();
  3082. returnSuccessMsg(eid + "上传成功,设计完成!");
  3083. return;
  3084. }
  3085. returnErrorMsg("找不到订单记录");
  3086. }
  3087. }
  3088. public void get_erp_designovertimelist()
  3089. {
  3090. DataStruct dStruct = GetPostStruct();
  3091. List<string> lw = new List<string>();
  3092. string tid = GetPostString("ctid");
  3093. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3094. string shopname = GetPostString("shopname");
  3095. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3096. string buyernick = GetPostString("buyer_nick");
  3097. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3098. string ResponsibleMan = GetPostString("responsible");
  3099. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3100. string date1 = GetPostString("date1");
  3101. string date2 = GetPostString("date2");
  3102. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3103. if (dw.Length > 0) lw.Add(dw);
  3104. string price1 = GetPostString("price1");
  3105. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3106. string price2 = GetPostString("price2");
  3107. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3108. string orderState = GetPostString("orderState");
  3109. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3110. string sellermemo = GetPostString("seller_memo");
  3111. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3112. lw.Add(string.Format("UnusualTag=3"));
  3113. lw.Add(string.Format("IsRefund<={0}", 1));
  3114. dStruct.Order = "WaitDesignTime desc";
  3115. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3116. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3117. writeGridDataTableJson(dStruct.TotalCount, dt);
  3118. }
  3119. //设计管理 获取抢单大厅列表
  3120. public void get_erp_grabinglist()
  3121. {
  3122. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3123. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3124. bool oldOrder = false;
  3125. if (org != null)
  3126. {
  3127. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3128. }
  3129. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3130. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3131. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3132. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3133. //先处理订单数据
  3134. if (dt.Rows.Count > 0)
  3135. {
  3136. Dictionary<string, int> design = null;
  3137. int count = 0;
  3138. foreach (DataRow row in dt.Rows)
  3139. {
  3140. if (map.ContainsKey(row["ShopId"].ToString()))
  3141. {
  3142. map.TryGetValue(row["ShopId"].ToString(), out design);
  3143. }
  3144. else
  3145. {
  3146. design = new Dictionary<string, int>();
  3147. }
  3148. if (design.ContainsKey(row["ProductId"].ToString()))
  3149. {
  3150. design.TryGetValue(row["ProductId"].ToString(), out count);
  3151. }
  3152. count++;
  3153. design[row["ProductId"].ToString()] = count;
  3154. map[row["ShopId"].ToString()] = design;
  3155. }
  3156. }
  3157. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3158. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3159. //把店铺排序和技能排序分类
  3160. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3161. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3162. if (design_dt.Rows.Count > 0)
  3163. {
  3164. Dictionary<string, string> design = null;
  3165. List<string> shopIds = null;
  3166. foreach (DataRow row in design_dt.Rows)
  3167. {
  3168. if ("0".Equals(row["designId"].ToString()))
  3169. {
  3170. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3171. {
  3172. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3173. }
  3174. else
  3175. {
  3176. shopIds = new List<string>();
  3177. }
  3178. shopIds.Add(row["shopId"].ToString());
  3179. shop_orders[row["orders"].ToString()] = shopIds;
  3180. }
  3181. else
  3182. {
  3183. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3184. {
  3185. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3186. }
  3187. else
  3188. {
  3189. design = new Dictionary<string, string>();
  3190. }
  3191. design[row["orders"].ToString()] = row["designId"].ToString();
  3192. design_orders[row["shopId"].ToString()] = design;
  3193. }
  3194. }
  3195. //处理成key value后根据key排序
  3196. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3197. foreach (List<string> val in shop_orders.Values)
  3198. {
  3199. if (val != null)
  3200. {
  3201. foreach (string key in val)
  3202. {
  3203. if (design_orders.ContainsKey(key.ToString()))
  3204. {
  3205. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3206. }
  3207. }
  3208. }
  3209. }
  3210. }
  3211. //校验哪个优先级有订单
  3212. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3213. foreach (string key in shop_orders.Keys)
  3214. {
  3215. List<string> ids = null;
  3216. shop_orders.TryGetValue(key, out ids);
  3217. //id为shopid
  3218. foreach (string id in ids)
  3219. {
  3220. Dictionary<string, int> list = null;
  3221. Dictionary<string, string> desing = null;
  3222. map.TryGetValue(id, out list);
  3223. design_orders.TryGetValue(id, out desing);
  3224. if (list != null && desing != null)
  3225. {
  3226. foreach (var item in desing)
  3227. {
  3228. int count = 0;
  3229. if (list.ContainsKey(item.Value))
  3230. {
  3231. list.TryGetValue(item.Value, out count);
  3232. if (count > 0)
  3233. {
  3234. designIds[id] = item.Value;
  3235. break;
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. if (designIds.Count > 0)
  3242. {
  3243. break;
  3244. }
  3245. }
  3246. DataTable table = new DataTable();
  3247. table.Columns.Add("tid", typeof(string));
  3248. table.Columns.Add("ctid", typeof(string));
  3249. table.Columns.Add("seller_nick", typeof(string));
  3250. table.Columns.Add("productName", typeof(string));
  3251. table.Columns.Add("pay_time", typeof(string));
  3252. table.Columns.Add("seller_memo", typeof(string));
  3253. if (designIds.Count > 0)
  3254. {
  3255. string shopId = "";
  3256. string productId = "";
  3257. foreach (var designInfo in designIds)
  3258. {
  3259. shopId = designInfo.Key;
  3260. productId = designInfo.Value;
  3261. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3262. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3263. if (dt.Rows.Count > 0)
  3264. {
  3265. foreach (DataRow row in dt.Rows)
  3266. {
  3267. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3268. {
  3269. DataRow data = table.NewRow();
  3270. data["ctid"] = row["ctid"].ToString();
  3271. data["tid"] = row["tid"].ToString();
  3272. data["seller_nick"] = ceErpShop.ShopName;
  3273. data["pay_time"] = row["pay_time"].ToString();
  3274. data["seller_memo"] = row["seller_memo"].ToString();
  3275. data["productName"] = ceErpProduct.PType;
  3276. table.Rows.Add(data);
  3277. }
  3278. }
  3279. }
  3280. }
  3281. }
  3282. writeGridDataTableJson(table.Rows.Count, table);
  3283. }
  3284. private object rushLockObject = new object();
  3285. public void set_erp_grabingorder()
  3286. {
  3287. if (UrlPostParmsCheck("ctid"))
  3288. {
  3289. int total = CurrentUser.User.Person.Total;
  3290. int userId = CurrentUser.User.ID;
  3291. int noFinish = CurrentUser.User.Person.NoFinish;
  3292. int finalization = CurrentUser.User.Person.Finalization;
  3293. string eids = GetPostString("ctid");
  3294. string key = "RushKey_" + userId;
  3295. int count = 0;
  3296. if (erpRedis.RedisHelper.KeyExists(key))
  3297. {
  3298. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3299. if (redisCount != null)
  3300. {
  3301. count = Convert.ToInt32(redisCount);
  3302. }
  3303. }
  3304. if (count >= total)
  3305. {
  3306. returnErrorMsg("半小时内已经抢" + total + "单");
  3307. return;
  3308. }
  3309. string[] ctidlist = eids.Split(',');
  3310. if (count + ctidlist.Length > total)
  3311. {
  3312. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3313. return;
  3314. }
  3315. int itag = 0;
  3316. lock (rushLockObject)
  3317. {
  3318. if (ctidlist.Length > 0)
  3319. {
  3320. string[] dtList = new string[ctidlist.Length];
  3321. for (int i = 0; i < ctidlist.Length; i++)
  3322. {
  3323. dtList[i] = "'" + ctidlist[i] + "'";
  3324. }
  3325. 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"));
  3326. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3327. if (dt_user.Rows.Count > 0)
  3328. {
  3329. int doing = 0;//未定稿
  3330. int finish = 0;//已完成
  3331. foreach (DataRow dr in dt_user.Rows)
  3332. {
  3333. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3334. {
  3335. doing++;
  3336. }
  3337. else
  3338. {
  3339. finish++;
  3340. }
  3341. }
  3342. if (doing >= noFinish)
  3343. {
  3344. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3345. return;
  3346. }
  3347. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3348. {
  3349. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3350. return;
  3351. }
  3352. }
  3353. //校验选择单子状态
  3354. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3355. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3356. if (dt.Rows.Count > 0)
  3357. {
  3358. List<string> list = new List<string>();
  3359. foreach (DataRow dr in dt.Rows)
  3360. {
  3361. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3362. {
  3363. list.Add(dr["ctid"].ToString());
  3364. }
  3365. }
  3366. if (list.Count > 0)
  3367. {
  3368. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3369. return;
  3370. }
  3371. }
  3372. foreach (string ctid in ctidlist)
  3373. {
  3374. CeErpTradeCell entity = null;
  3375. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3376. if (entity != null)
  3377. {
  3378. entity.OrderState = 3;
  3379. entity.DesignUserId = CurrentUser.UserID;
  3380. entity.WaitDesignTime = DateTime.Now;
  3381. entity.StartDesignTime = DateTime.Now;
  3382. entity.Update();
  3383. commonHelper.UpdateRelationOrder(entity.ctid);
  3384. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3385. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3386. itag++;
  3387. }
  3388. }
  3389. }
  3390. }
  3391. count += ctidlist.Length;
  3392. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3393. if (itag == 0)
  3394. returnErrorMsg("没有找到相关订单");
  3395. else
  3396. returnSuccessMsg("抢单成功!");
  3397. return;
  3398. }
  3399. }
  3400. public void get_erp_waitorderlist()
  3401. {
  3402. DataStruct dStruct = GetPostStruct();
  3403. List<string> lw = new List<string>();
  3404. string tid = GetPostString("ctid");
  3405. if (tid.Length > 0)
  3406. {
  3407. string select_tid = getTidByCtid(tid);
  3408. lw.Add(string.Format("tid='{0}'", select_tid));
  3409. }
  3410. string shopname = GetPostString("shopname");
  3411. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3412. string buyernick = GetPostString("buyer_nick");
  3413. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3414. string customer = GetPostString("customer");
  3415. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3416. string design = GetPostString("design");
  3417. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3418. string orderState = GetPostString("orderState");
  3419. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3420. string supplier = GetPostString("supplier");
  3421. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3422. string sellermemo = GetPostString("seller_memo");
  3423. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3424. string otherMemo = GetPostString("otherMemo");
  3425. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3426. string address = GetPostString("address");
  3427. 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));
  3428. string date1 = GetPostString("date1");
  3429. string date2 = GetPostString("date2");
  3430. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3431. if (dw.Length > 0) lw.Add(dw);
  3432. string price1 = GetPostString("price1");
  3433. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3434. string price2 = GetPostString("price2");
  3435. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3436. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3437. lw.Add(string.Format("IsSample != 2 "));
  3438. lw.Add(string.Format("OrderState = 5 "));
  3439. lw.Add(string.Format("IsRefund<={0}", 1));
  3440. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3441. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3442. string pagesize = GetPostString("pagesize");
  3443. if (pagesize != null)
  3444. {
  3445. dStruct.PageSize = 200;
  3446. }
  3447. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3448. List<string> tids = new List<string>();
  3449. if (dt != null)
  3450. {
  3451. dt.Columns.Add("compenPrice", typeof(double));
  3452. foreach (DataRow dr in dt.Rows)
  3453. {
  3454. if (Convert.IsDBNull(dr["compenPrice"]))
  3455. {
  3456. dr["compenPrice"] = 0;
  3457. }
  3458. tids.Add("'" + dr["tid"].ToString() + "'");
  3459. 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();
  3460. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3461. {
  3462. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3463. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3464. entity.SupplierId = suid;
  3465. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3466. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3467. entity.Update();
  3468. }
  3469. }
  3470. }
  3471. if (tids.Count > 0)
  3472. {
  3473. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3474. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3475. if (dt_price != null && dt_price.Rows.Count > 0)
  3476. {
  3477. foreach (DataRow dr in dt_price.Rows)
  3478. {
  3479. foreach (DataRow row in dt.Rows)
  3480. {
  3481. if (row["tid"].Equals(dr["ptid"]))
  3482. {
  3483. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3484. break;
  3485. }
  3486. }
  3487. }
  3488. }
  3489. }
  3490. writeGridDataTableJson(dStruct.TotalCount, dt);
  3491. }
  3492. public void get_erp_supplierwaitorderlist()
  3493. {
  3494. DataStruct dStruct = GetPostStruct();
  3495. List<string> lw = new List<string>();
  3496. string tid = GetPostString("ctid");
  3497. if (tid.Length > 0)
  3498. {
  3499. string select_tid = getTidByCtid(tid);
  3500. lw.Add(string.Format("tid='{0}'", select_tid));
  3501. }
  3502. string shopname = GetPostString("shopname");
  3503. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3504. string sellermemo = GetPostString("seller_memo");
  3505. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3506. string date1 = GetPostString("date1");
  3507. string date2 = GetPostString("date2");
  3508. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3509. if (dw.Length > 0) lw.Add(dw);
  3510. lw.Add(string.Format("OrderState = 5 "));
  3511. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3512. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3513. {
  3514. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3515. }
  3516. string supplier = GetPostString("supplier");
  3517. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3518. {
  3519. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3520. }
  3521. lw.Add(string.Format("IsRefund<={0}", 1));
  3522. dStruct.Order = "FinishDesignTime desc";
  3523. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3524. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3525. if (dt != null)
  3526. {
  3527. foreach (DataRow dr in dt.Rows)
  3528. {
  3529. 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();
  3530. }
  3531. }
  3532. writeGridDataTableJson(dStruct.TotalCount, dt);
  3533. }
  3534. public void upd_erp_verifytosupplier()
  3535. {
  3536. if (UrlPostParmsCheck("ctid"))
  3537. {
  3538. string eids = GetPostString("ctid");
  3539. CeErpTradeCell entity = null;
  3540. string[] eidsList = eids.Split(',');
  3541. if (eidsList.Length <= 0)
  3542. {
  3543. returnErrorMsg("订单号不能空");
  3544. return;
  3545. }
  3546. List<string> tLst = new List<string>();
  3547. foreach (string ctidstr in eidsList)
  3548. {
  3549. tLst.Add("'" + ctidstr + "'");
  3550. CeErpDataSendOrderInfo.createObject(ctidstr);
  3551. }
  3552. string needtids = string.Join(",", tLst.ToArray());
  3553. StringBuilder sql = new StringBuilder();
  3554. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3555. 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);
  3556. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3557. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3558. returnSuccessMsg("操作成功!");
  3559. return;
  3560. /**foreach (string ctidstr in eidsList)
  3561. {
  3562. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3563. if (entity != null)
  3564. {
  3565. if (entity.SupplierId == 0)
  3566. {
  3567. continue;
  3568. }
  3569. entity.IsVerifyToSupplier = true;
  3570. if (entity.IsReturn == 1) //1是供应商打回
  3571. {
  3572. entity.IsReturn = 0;
  3573. }
  3574. entity.FinishPlaceTime = DateTime.Now;
  3575. entity.PlaceUserId = CurrentUser.UserID;
  3576. entity.Update();
  3577. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3578. }
  3579. }
  3580. returnSuccessMsg("操作成功!");
  3581. return;**/
  3582. }
  3583. }
  3584. public void upd_erp_supplierback()
  3585. {
  3586. if (UrlPostParmsCheck("ctid"))
  3587. {
  3588. string eid = GetPostString("ctid");
  3589. string reason = GetPostString("returnreason");
  3590. CeErpTradeCell entity = null;
  3591. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3592. if (entity != null)
  3593. {
  3594. string message = "操作成功!";
  3595. string isDown = "";
  3596. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3597. {
  3598. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3599. isDown = "被点击下载";
  3600. }
  3601. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3602. {
  3603. string key = "return_order_" + entity.SupplierId;
  3604. List<string> list = new List<string>();
  3605. if (RedisHelper.HasKey(key))
  3606. {
  3607. object data = RedisHelper.StringGet(key);
  3608. list = Convert.ToString(data).Split(',').ToList();
  3609. }
  3610. list.Add(eid);
  3611. RedisHelper.StringSet(key, string.Join(",", list));
  3612. }
  3613. entity.IsVerifyToSupplier = false;
  3614. entity.IsReturn = 1;
  3615. entity.IsHaveNewOrder = 0;
  3616. entity.ReturnTime = DateTime.Now;
  3617. entity.ReturnReason = reason;
  3618. if (entity.OrderState == 6)
  3619. {
  3620. entity.OrderState = 5;
  3621. }
  3622. entity.Update();
  3623. CeErpSukuraData.createInfo(entity.ctid, 5);
  3624. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3625. returnSuccessMsg(message);
  3626. return;
  3627. }
  3628. returnErrorMsg("找不到订单记录");
  3629. }
  3630. }
  3631. public void upd_erp_toaftersaleorder()
  3632. {
  3633. if (UrlPostParmsCheck("ctid"))
  3634. {
  3635. string eid = GetPostString("ctid");
  3636. string reason = GetPostString("returnreason");
  3637. CeErpTradeCell entity = null;
  3638. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3639. if (entity != null)
  3640. {
  3641. if (entity.isAfterSaleOrder != 1)
  3642. {
  3643. returnErrorMsg("带S的售后单才能打回给售后");
  3644. return;
  3645. }
  3646. if (entity.OrderState >= 5)
  3647. {
  3648. returnErrorMsg("已经设计完成了不能打回给售后");
  3649. return;
  3650. }
  3651. entity.OrderState = 0;
  3652. entity.IsReturn = 3;
  3653. entity.ReturnTime = DateTime.Now;
  3654. entity.UpdateTime = DateTime.Now;
  3655. entity.ReturnReason = reason;
  3656. entity.Update();
  3657. CeErpSukuraData.createInfo(entity.ctid, 5);
  3658. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3659. returnSuccessMsg("操作成功!");
  3660. return;
  3661. }
  3662. returnErrorMsg("找不到订单记录");
  3663. }
  3664. }
  3665. public void upd_erp_aftersaletodesign()
  3666. {
  3667. if (UrlPostParmsCheck("ctid"))
  3668. {
  3669. string eid = GetPostString("ctid");
  3670. CeErpTradeCell entity = null;
  3671. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3672. if (entity != null)
  3673. {
  3674. entity.OrderState = 3;
  3675. entity.IsReturn = 0;
  3676. entity.UpdateTime = DateTime.Now;
  3677. entity.Update();
  3678. CeErpSukuraData.createInfo(entity.ctid, 5);
  3679. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3680. returnSuccessMsg("操作成功!");
  3681. return;
  3682. }
  3683. returnErrorMsg("找不到订单记录");
  3684. }
  3685. }
  3686. public void assign_erp_supplier()
  3687. {
  3688. if (UrlPostParmsCheck("ctid"))
  3689. {
  3690. string eids = GetPostString("ctid");
  3691. int sid = GetPostInt("SupplierName");
  3692. string fromTag = GetPostString("tag");
  3693. string[] eidList = eids.Split(',');
  3694. if (eidList.Length <= 0)
  3695. {
  3696. returnErrorMsg("指派不能为空");
  3697. return;
  3698. }
  3699. string errMsg = "";
  3700. string suname = commonHelper.getSupplierNameById(sid);
  3701. foreach (string ctid in eidList)
  3702. {
  3703. CeErpTradeCell entity = null;
  3704. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3705. if (entity != null)
  3706. {
  3707. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3708. {
  3709. errMsg += (ctid + "指派失败!!!");
  3710. continue;
  3711. }
  3712. entity.SupplierId = sid;
  3713. entity.Update();
  3714. commonHelper.UpdateRelationOrder(entity.ctid);
  3715. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3716. if (entity.OrderState >= 6)
  3717. {
  3718. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3719. //{
  3720. // string msl = entity.MakeSupplier;
  3721. // string[] mslist = msl.Split(',');
  3722. // 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);
  3723. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3724. //}
  3725. //else
  3726. //{
  3727. StringBuilder sql = new StringBuilder();
  3728. 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);
  3729. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3730. //}
  3731. }
  3732. }
  3733. else
  3734. {
  3735. continue;
  3736. }
  3737. }
  3738. if (errMsg.Length > 0)
  3739. {
  3740. returnErrorMsg(errMsg);
  3741. return;
  3742. }
  3743. returnSuccessMsg("操作成功!");
  3744. return;
  3745. }
  3746. }
  3747. public void assign_erp_makesupplier()
  3748. {
  3749. if (UrlPostParmsCheck("ctid"))
  3750. {
  3751. string eids = GetPostString("ctid");
  3752. string sname = GetPostString("SupplierName");
  3753. string[] eidList = eids.Split(',');
  3754. if (eidList.Length <= 0)
  3755. {
  3756. returnErrorMsg("指派不能为空");
  3757. return;
  3758. }
  3759. List<string> tLst = new List<string>();
  3760. foreach (string ctid in eidList)
  3761. {
  3762. CeErpTradeCell entity = null;
  3763. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3764. if (entity != null)
  3765. {
  3766. entity.MakeSupplier = sname;
  3767. entity.Update();
  3768. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3769. tLst.Add("'" + ctid + "'");
  3770. }
  3771. else
  3772. {
  3773. continue;
  3774. }
  3775. }
  3776. string ctids = string.Join(",", tLst.ToArray());
  3777. StringBuilder sql2 = new StringBuilder();
  3778. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3779. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3780. returnSuccessMsg("操作成功!");
  3781. return;
  3782. }
  3783. }
  3784. public void ins_erp_returnreason()
  3785. {
  3786. if (UrlPostParmsCheck("ctid"))
  3787. {
  3788. string eid = GetPostString("ctid");
  3789. CeErpTradeCell entity = null;
  3790. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3791. string userpost = CurrentUser.UserPost.Post.Code;
  3792. if (entity != null)
  3793. {
  3794. bool isPlace = false;
  3795. if (entity.OrderState > 6)
  3796. {
  3797. returnErrorMsg("已发货无法打回!");
  3798. return;
  3799. }
  3800. if (entity.OrderState == 6)
  3801. {
  3802. isPlace = true;
  3803. }
  3804. bool isNeedUpdateCell2 = false;
  3805. if (entity.OrderState >= 6)
  3806. {
  3807. isNeedUpdateCell2 = true;
  3808. }
  3809. int returnTag = 2;
  3810. if (userpost == "Supplier")
  3811. {
  3812. returnTag = 1;
  3813. }
  3814. int toType = GetPostInt("totype");
  3815. string fromType = "3";
  3816. if (entity.OrderState < 5)
  3817. {
  3818. fromType = "3";
  3819. }
  3820. else
  3821. {
  3822. fromType = "4";
  3823. }
  3824. if (entity.IsXianHuo == 0)
  3825. {
  3826. if (returnTag == 2)
  3827. {
  3828. if (toType == 1)
  3829. {
  3830. entity.OrderState = 0;
  3831. entity.ReturnUserType = 1;
  3832. string clearman = GetPostString("clearman");
  3833. if (!string.IsNullOrEmpty(clearman))
  3834. {
  3835. entity.DesignUserId = 0;
  3836. }
  3837. }
  3838. else
  3839. {
  3840. entity.OrderState = 3;
  3841. entity.ReturnUserType = 2;
  3842. }
  3843. entity.IsReadTag = 1;
  3844. }
  3845. else if (returnTag == 1)
  3846. {
  3847. entity.OrderState = 5;
  3848. }
  3849. entity.IsVerifyToSupplier = false;
  3850. }
  3851. if (entity.IsXianHuo == 1)
  3852. {
  3853. entity.OrderState = 5;
  3854. }
  3855. entity.UnusualTag = 0;
  3856. entity.UnusualTime = null;
  3857. entity.UnusualCon = "";
  3858. entity.IsReturn = returnTag;
  3859. entity.ReturnTime = DateTime.Now;
  3860. entity.UpdateTime = DateTime.Now;
  3861. entity.ReturnReason = GetPostString("returnreason");
  3862. entity.Update();
  3863. if (entity.OrderState == 3)
  3864. {
  3865. ApiVo apiVo = new ApiVo();
  3866. apiVo.orderNumber = entity.ctid;
  3867. apiVo.actionName = "rebutDesign";
  3868. apiVo.orderRemarks = entity.ReturnReason;
  3869. designHelper.API_WorkCore(apiVo);//rebutDesign
  3870. }
  3871. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3872. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3873. {
  3874. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3875. }
  3876. CeErpSukuraData.createInfo(entity.ctid, 5);
  3877. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3878. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3879. if (isPlace)
  3880. {
  3881. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3882. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3883. if (dth != null && dth.Rows.Count > 0)
  3884. {
  3885. dataSendOrderBean dataSendOrderBean = null;
  3886. foreach (DataRow item in dth.Rows)
  3887. {
  3888. try
  3889. {
  3890. dataSendOrderBean = new dataSendOrderBean();
  3891. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3892. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3893. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3894. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3895. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3896. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3897. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3898. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3899. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3900. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3901. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3902. dataSendOrderBean.Radio1723534706288 = "打回";
  3903. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3904. if (result != null)
  3905. {
  3906. if ("0".Equals(result.errcode))
  3907. {
  3908. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3909. }
  3910. else
  3911. {
  3912. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3913. }
  3914. }
  3915. }
  3916. catch (Exception ex)
  3917. {
  3918. }
  3919. }
  3920. }
  3921. }
  3922. if (isNeedUpdateCell2)
  3923. {
  3924. if (entity.MakeSupplier.IndexOf(",") != -1)
  3925. {
  3926. StringBuilder sql2 = new StringBuilder();
  3927. 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);
  3928. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3929. }
  3930. else
  3931. {
  3932. StringBuilder sql2 = new StringBuilder();
  3933. 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);
  3934. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3935. }
  3936. }
  3937. returnSuccessMsg("操作成功!");
  3938. return;
  3939. }
  3940. returnErrorMsg("找不到订单记录");
  3941. }
  3942. }
  3943. public void cyt_erp_returnreason()
  3944. {
  3945. if (UrlPostParmsCheck("ctid"))
  3946. {
  3947. string eid = GetPostString("ctid");
  3948. CeErpTradeCell entity = null;
  3949. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3950. string userpost = CurrentUser.UserPost.Post.Code;
  3951. if (entity != null)
  3952. {
  3953. if (entity.OrderState > 6)
  3954. {
  3955. returnErrorMsg("已发货无法打回!");
  3956. return;
  3957. }
  3958. JObject jsonObject = new JObject
  3959. {
  3960. { "Userid", "77886" },
  3961. { "Pwd", "lt666888" },
  3962. { "LTOrderId",eid }
  3963. };
  3964. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3965. JObject jsonObjects = JObject.Parse(response);
  3966. string msg = (string)jsonObjects["msg"];
  3967. if (msg != "取消成功")
  3968. {
  3969. returnErrorMsg(msg);
  3970. return;
  3971. }
  3972. bool isNeedUpdateCell2 = false;
  3973. if (entity.OrderState >= 6)
  3974. {
  3975. isNeedUpdateCell2 = true;
  3976. }
  3977. int returnTag = 2;
  3978. if (userpost == "Supplier")
  3979. {
  3980. returnTag = 1;
  3981. }
  3982. if (entity.IsXianHuo == 0)
  3983. {
  3984. if (returnTag == 2)
  3985. {
  3986. int toType = GetPostInt("totype");
  3987. if (toType == 1)
  3988. {
  3989. entity.OrderState = 0;
  3990. entity.ReturnUserType = 1;
  3991. }
  3992. else
  3993. {
  3994. entity.OrderState = 4;
  3995. entity.ReturnUserType = 2;
  3996. }
  3997. entity.IsReadTag = 1;
  3998. }
  3999. else if (returnTag == 1)
  4000. {
  4001. entity.OrderState = 5;
  4002. }
  4003. entity.IsVerifyToSupplier = false;
  4004. }
  4005. entity.UnusualTag = 0;
  4006. entity.UnusualTime = null;
  4007. entity.UnusualCon = "";
  4008. entity.IsReturn = returnTag;
  4009. entity.ReturnTime = DateTime.Now;
  4010. entity.ReturnReason = GetPostString("returnreason");
  4011. entity.Update();
  4012. if (entity.OrderState == 4)
  4013. {
  4014. ApiVo apiVo = new ApiVo();
  4015. apiVo.orderNumber = entity.ctid;
  4016. apiVo.actionName = "rebutDesign";
  4017. apiVo.orderRemarks = entity.ReturnReason;
  4018. designHelper.API_WorkCore(apiVo);//rebutDesign
  4019. }
  4020. CeErpSukuraData.createInfo(entity.ctid, 5);
  4021. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4022. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4023. if (isNeedUpdateCell2)
  4024. {
  4025. if (entity.MakeSupplier.IndexOf(",") != -1)
  4026. {
  4027. StringBuilder sql2 = new StringBuilder();
  4028. 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);
  4029. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4030. }
  4031. else
  4032. {
  4033. StringBuilder sql2 = new StringBuilder();
  4034. 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);
  4035. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4036. }
  4037. }
  4038. returnSuccessMsg("操作成功!");
  4039. return;
  4040. }
  4041. returnErrorMsg("找不到订单记录");
  4042. }
  4043. }
  4044. public void upd_erp_xianhuoreturntag()
  4045. {
  4046. if (UrlPostParmsCheck("ctid"))
  4047. {
  4048. string eids = GetPostString("ctid");
  4049. string[] ctids = eids.Split(',');
  4050. foreach (string ctid in ctids)
  4051. {
  4052. CeErpTradeCell entity = null;
  4053. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4054. if (entity != null)
  4055. {
  4056. entity.IsReturn = 0;
  4057. entity.Update();
  4058. CeErpSukuraData.createInfo(entity.ctid, 5);
  4059. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4060. }
  4061. }
  4062. returnSuccessMsg("操作成功!");
  4063. return;
  4064. }
  4065. }
  4066. public void get_erp_waitdeliverylist()
  4067. {
  4068. DataStruct dStruct = GetPostStruct();
  4069. List<string> lw = new List<string>();
  4070. string tid = GetPostString("ctid");
  4071. if (tid.Length > 0)
  4072. {
  4073. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4074. if (tid.Length > 5)
  4075. {
  4076. List<string> tids = getTidByCtidLike(tid);
  4077. if (tids.Count > 0 && tids.Count < 10)
  4078. {
  4079. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4080. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4081. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4082. {
  4083. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4084. }*/
  4085. }
  4086. }
  4087. lw.Add(tid_sql);
  4088. }
  4089. string shopname = GetPostString("shopname");
  4090. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4091. string buyernick = GetPostString("buyer_nick");
  4092. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4093. //if (tid.Length == 0 && buyernick.Length == 0)
  4094. //{
  4095. // lw.Add(string.Format("IsRefund<={0}", 1));
  4096. //}
  4097. string customer = GetPostString("customer");
  4098. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4099. string design = GetPostString("design");
  4100. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4101. string orderState = GetPostString("orderState");
  4102. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4103. string address = GetPostString("address");
  4104. 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));
  4105. string sellermemo = GetPostString("seller_memo");
  4106. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4107. string supplier = GetPostString("supplier");
  4108. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4109. string OrderArea = GetPostString("order_area");
  4110. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4111. string placedate1 = GetPostString("placedate1");
  4112. string placedate2 = GetPostString("placedate2");
  4113. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4114. if (fdw.Length > 0) lw.Add(fdw);
  4115. string price1 = GetPostString("price1");
  4116. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4117. string price2 = GetPostString("price2");
  4118. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4119. string unusualCon = GetPostString("unusualcon");
  4120. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4121. string otherMemo = GetPostString("otherMemo");
  4122. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4123. string posTag = CurrentUser.UserPost.Post.Code;
  4124. if (posTag == "Supplier")
  4125. {
  4126. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4127. }
  4128. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4129. lw.Add(string.Format("type != 'PDD' "));
  4130. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4131. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4132. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4133. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4134. writeGridDataTableJson(dStruct.TotalCount, dt);
  4135. }
  4136. public void get_erp_changedeliverylist()
  4137. {
  4138. DataStruct dStruct = GetPostStruct();
  4139. List<string> lw = new List<string>();
  4140. string tid = GetPostString("ctid");
  4141. if (tid.Length > 0)
  4142. {
  4143. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4144. if (tid.Length > 5)
  4145. {
  4146. List<string> tids = getTidByCtidLike(tid);
  4147. if (tids.Count > 0 && tids.Count < 10)
  4148. {
  4149. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4150. }
  4151. }
  4152. lw.Add(tid_sql);
  4153. }
  4154. string shopname = GetPostString("shopname");
  4155. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4156. string buyernick = GetPostString("buyer_nick");
  4157. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4158. //if (tid.Length == 0 && buyernick.Length == 0)
  4159. //{
  4160. // lw.Add(string.Format("IsRefund<={0}", 1));
  4161. //}
  4162. string customer = GetPostString("customer");
  4163. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4164. string design = GetPostString("design");
  4165. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4166. string orderState = GetPostString("orderState");
  4167. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4168. string address = GetPostString("address");
  4169. 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));
  4170. string sellermemo = GetPostString("seller_memo");
  4171. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4172. string supplier = GetPostString("supplier");
  4173. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4174. string OrderArea = GetPostString("order_area");
  4175. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4176. string placedate1 = GetPostString("placedate1");
  4177. string placedate2 = GetPostString("placedate2");
  4178. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4179. if (fdw.Length > 0) lw.Add(fdw);
  4180. string price1 = GetPostString("price1");
  4181. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4182. string price2 = GetPostString("price2");
  4183. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4184. string unusualCon = GetPostString("unusualcon");
  4185. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4186. string otherMemo = GetPostString("otherMemo");
  4187. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4188. string posTag = CurrentUser.UserPost.Post.Code;
  4189. if (posTag == "Supplier")
  4190. {
  4191. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4192. }
  4193. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4194. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4195. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4196. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4197. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4198. /*if (tid.Length > 0)
  4199. {
  4200. List<string> tids = new List<string>();
  4201. if (dt != null && dt.Rows.Count > 0)
  4202. {
  4203. foreach (DataRow item in dt.Rows)
  4204. {
  4205. tids.Add("'" + item["tid"] + "'");
  4206. }
  4207. }
  4208. if (tids.Count > 0)
  4209. {
  4210. lw.RemoveAt(0);
  4211. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4212. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4213. dt = WebCache.GetData("view_erptradecell", dStruct);
  4214. }
  4215. }*/
  4216. writeGridDataTableJson(dStruct.TotalCount, dt);
  4217. }
  4218. public void get_erp_pddderiving()
  4219. {
  4220. DataStruct dStruct = GetPostStruct();
  4221. List<string> lw = new List<string>();
  4222. string tid = GetPostString("ctid");
  4223. if (tid.Length > 0)
  4224. {
  4225. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4226. if (tid.Length > 5)
  4227. {
  4228. List<string> tids = getTidByCtidLike(tid);
  4229. if (tids.Count > 0 && tids.Count < 10)
  4230. {
  4231. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4232. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4233. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4234. {
  4235. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4236. }*/
  4237. }
  4238. }
  4239. lw.Add(tid_sql);
  4240. }
  4241. string shopname = GetPostString("shopname");
  4242. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4243. string buyernick = GetPostString("buyer_nick");
  4244. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4245. //if (tid.Length == 0 && buyernick.Length == 0)
  4246. //{
  4247. // lw.Add(string.Format("IsRefund<={0}", 1));
  4248. //}
  4249. string customer = GetPostString("customer");
  4250. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4251. string design = GetPostString("design");
  4252. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4253. string orderState = GetPostString("orderState");
  4254. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4255. string address = GetPostString("address");
  4256. 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));
  4257. string sellermemo = GetPostString("seller_memo");
  4258. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4259. string supplier = GetPostString("supplier");
  4260. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4261. string OrderArea = GetPostString("order_area");
  4262. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4263. string placedate1 = GetPostString("placedate1");
  4264. string placedate2 = GetPostString("placedate2");
  4265. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4266. if (fdw.Length > 0) lw.Add(fdw);
  4267. string price1 = GetPostString("price1");
  4268. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4269. string price2 = GetPostString("price2");
  4270. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4271. string unusualCon = GetPostString("unusualcon");
  4272. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4273. string posTag = CurrentUser.UserPost.Post.Code;
  4274. if (posTag == "Supplier")
  4275. {
  4276. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4277. }
  4278. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4279. lw.Add(string.Format("type = 'PDD' "));
  4280. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4281. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4282. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4283. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4284. /*if (tid.Length > 0)
  4285. {
  4286. List<string> tids = new List<string>();
  4287. if (dt != null && dt.Rows.Count > 0)
  4288. {
  4289. foreach (DataRow item in dt.Rows)
  4290. {
  4291. tids.Add("'" + item["tid"] + "'");
  4292. }
  4293. }
  4294. if (tids.Count > 0)
  4295. {
  4296. lw.RemoveAt(0);
  4297. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4298. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4299. dt = WebCache.GetData("view_erptradecell", dStruct);
  4300. }
  4301. }*/
  4302. writeGridDataTableJson(dStruct.TotalCount, dt);
  4303. }
  4304. public void get_erp_jdderiving()
  4305. {
  4306. DataStruct dStruct = GetPostStruct();
  4307. List<string> lw = new List<string>();
  4308. string tid = GetPostString("ctid");
  4309. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4310. string shopname = GetPostString("shopname");
  4311. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4312. string buyernick = GetPostString("buyer_nick");
  4313. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4314. //if (tid.Length == 0 && buyernick.Length == 0)
  4315. //{
  4316. // lw.Add(string.Format("IsRefund<={0}", 1));
  4317. //}
  4318. string customer = GetPostString("customer");
  4319. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4320. string design = GetPostString("design");
  4321. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4322. string orderState = GetPostString("orderState");
  4323. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4324. string address = GetPostString("address");
  4325. 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));
  4326. string sellermemo = GetPostString("seller_memo");
  4327. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4328. string supplier = GetPostString("supplier");
  4329. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4330. string OrderArea = GetPostString("order_area");
  4331. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4332. string placedate1 = GetPostString("placedate1");
  4333. string placedate2 = GetPostString("placedate2");
  4334. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4335. if (fdw.Length > 0) lw.Add(fdw);
  4336. string price1 = GetPostString("price1");
  4337. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4338. string price2 = GetPostString("price2");
  4339. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4340. string unusualCon = GetPostString("unusualcon");
  4341. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4342. string posTag = CurrentUser.UserPost.Post.Code;
  4343. if (posTag == "Supplier")
  4344. {
  4345. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4346. }
  4347. lw.Add(string.Format("OrderState = 6 "));
  4348. lw.Add(string.Format("type = 'JD' "));
  4349. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4350. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4351. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4352. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4353. writeGridDataTableJson(dStruct.TotalCount, dt);
  4354. }
  4355. public void get_erp_demoorderlist()
  4356. {
  4357. DataStruct dStruct = GetPostStruct();
  4358. List<string> lw = new List<string>();
  4359. string tid = GetPostString("ctid");
  4360. if (tid.Length > 0)
  4361. {
  4362. string select_tid = getTidByCtid(tid);
  4363. lw.Add(string.Format("tid='{0}'", select_tid));
  4364. }
  4365. string shopname = GetPostString("shopname");
  4366. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4367. string buyernick = GetPostString("buyer_nick");
  4368. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4369. string customer = GetPostString("customer");
  4370. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4371. string design = GetPostString("design");
  4372. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4373. string orderState = GetPostString("orderState");
  4374. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4375. string address = GetPostString("address");
  4376. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4377. string sellermemo = GetPostString("seller_memo");
  4378. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4379. string supplier = GetPostString("supplier");
  4380. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4381. string OrderArea = GetPostString("order_area");
  4382. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4383. string date1 = GetPostString("date1");
  4384. string date2 = GetPostString("date2");
  4385. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4386. if (dw.Length > 0) lw.Add(dw);
  4387. string price1 = GetPostString("price1");
  4388. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4389. string price2 = GetPostString("price2");
  4390. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4391. string posTag = CurrentUser.UserPost.Post.Code;
  4392. if (posTag == "Supplier")
  4393. {
  4394. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4395. }
  4396. //lw.Add(string.Format("OrderState = 6 "));
  4397. lw.Add(string.Format("IsSample={0}", 3));
  4398. lw.Add(string.Format("IsRefund<={0}", 1));
  4399. dStruct.Order = "pay_time desc";
  4400. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4401. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4402. writeGridDataTableJson(dStruct.TotalCount, dt);
  4403. }
  4404. public void save_erp_checkmemo()
  4405. {
  4406. if (UrlPostParmsCheck("ctid"))
  4407. {
  4408. string ctid = GetPostString("ctid");
  4409. CeErpTradeCell entity = null;
  4410. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4411. if (entity != null)
  4412. {
  4413. entity.CheckMemo = GetPostString("CheckMemo");
  4414. entity.Update();
  4415. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4416. if (trade != null)
  4417. {
  4418. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4419. }
  4420. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4421. returnSuccessMsg("保存成功!");
  4422. return;
  4423. }
  4424. returnErrorMsg("找不到记录");
  4425. }
  4426. }
  4427. public void get_erp_returnlist()
  4428. {
  4429. DataStruct dStruct = GetPostStruct();
  4430. List<string> lw = new List<string>();
  4431. string tid = GetPostString("ctid");
  4432. if (tid.Length > 0)
  4433. {
  4434. string select_tid = getTidByCtid(tid);
  4435. lw.Add(string.Format("tid='{0}'", select_tid));
  4436. }
  4437. string shopname = GetPostString("shopname");
  4438. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4439. string buyernick = GetPostString("buyer_nick");
  4440. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4441. string customer = GetPostString("customer");
  4442. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4443. string design = GetPostString("design");
  4444. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4445. string orderState = GetPostString("orderState");
  4446. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4447. string address = GetPostString("address");
  4448. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4449. string sellermemo = GetPostString("seller_memo");
  4450. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4451. string supplier = GetPostString("supplier");
  4452. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4453. string date1 = GetPostString("date1");
  4454. string date2 = GetPostString("date2");
  4455. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4456. if (dw.Length > 0) lw.Add(dw);
  4457. string bdate1 = GetPostString("backdate1");
  4458. string bdate2 = GetPostString("backdate2");
  4459. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4460. if (dw_back.Length > 0) lw.Add(dw_back);
  4461. string price1 = GetPostString("price1");
  4462. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4463. string price2 = GetPostString("price2");
  4464. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4465. lw.Add(string.Format("IsReturn>0"));
  4466. lw.Add(string.Format("IsXianHuo=0"));
  4467. lw.Add(string.Format("IsReturn!=3"));
  4468. string backtype = GetPostString("backtype");
  4469. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4470. dStruct.Order = "FinishDesignTime desc";
  4471. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4472. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4473. writeGridDataTableJson(dStruct.TotalCount, dt);
  4474. }
  4475. public void get_erp_today_sumreturn()
  4476. {
  4477. DataStruct dStruct = GetPostStruct();
  4478. List<string> lw = new List<string>();
  4479. string bdate1 = GetPostString("returnTimeS");
  4480. string bdate2 = GetPostString("returnTimeE");
  4481. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4482. if (dw_back.Length > 0) lw.Add(dw_back);
  4483. lw.Add(string.Format("IsReturn=0"));
  4484. lw.Add(string.Format("IsXianHuo=0"));
  4485. string mainWhere = string.Join(" and ", lw.ToArray());
  4486. string sql = "";
  4487. if (dw_back.Length > 0)
  4488. {
  4489. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4490. }
  4491. else
  4492. {
  4493. 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 + "'";
  4494. }
  4495. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4496. decimal total = 0, today_finish = 0;
  4497. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4498. {
  4499. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4500. }
  4501. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4502. {
  4503. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4504. }
  4505. var res = new
  4506. {
  4507. data = total,
  4508. data1 = today_finish,
  4509. };
  4510. string ro_jsond = JsonConvert.SerializeObject(res);
  4511. returnSuccess(ro_jsond);
  4512. return;
  4513. }
  4514. public void get_erp_allreturnlist()
  4515. {
  4516. DataStruct dStruct = GetPostStruct();
  4517. List<string> lw = new List<string>();
  4518. string tid = GetPostString("ctid");
  4519. if (tid.Length > 0)
  4520. {
  4521. string select_tid = getTidByCtid(tid);
  4522. lw.Add(string.Format("tid='{0}'", select_tid));
  4523. }
  4524. string shopname = GetPostString("shopname");
  4525. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4526. string buyernick = GetPostString("buyer_nick");
  4527. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4528. string customer = GetPostString("customer");
  4529. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4530. string design = GetPostString("design");
  4531. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4532. string orderState = GetPostString("orderState");
  4533. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4534. string address = GetPostString("address");
  4535. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4536. string sellermemo = GetPostString("seller_memo");
  4537. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4538. string supplier = GetPostString("supplier");
  4539. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4540. string date1 = GetPostString("date1");
  4541. string date2 = GetPostString("date2");
  4542. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4543. if (dw.Length > 0) lw.Add(dw);
  4544. string bdate1 = GetPostString("backdate1");
  4545. string bdate2 = GetPostString("backdate2");
  4546. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4547. if (dw_back.Length > 0) lw.Add(dw_back);
  4548. string price1 = GetPostString("price1");
  4549. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4550. string price2 = GetPostString("price2");
  4551. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4552. string backreason = GetPostString("backreason");
  4553. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4554. lw.Add(string.Format("IsXianHuo=0"));
  4555. lw.Add(string.Format("ReturnTime != ''"));
  4556. string backtype = GetPostString("backtype");
  4557. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4558. dStruct.Order = "FinishDesignTime desc";
  4559. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4560. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4561. writeGridDataTableJson(dStruct.TotalCount, dt);
  4562. }
  4563. public void get_erp_aftersalereturnlist()
  4564. {
  4565. DataStruct dStruct = GetPostStruct();
  4566. List<string> lw = new List<string>();
  4567. string tid = GetPostString("ctid");
  4568. if (tid.Length > 0)
  4569. {
  4570. string select_tid = getTidByCtid(tid);
  4571. lw.Add(string.Format("tid='{0}'", select_tid));
  4572. }
  4573. string shopname = GetPostString("shopname");
  4574. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4575. string buyernick = GetPostString("buyer_nick");
  4576. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4577. string customer = GetPostString("customer");
  4578. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4579. string design = GetPostString("design");
  4580. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4581. string orderState = GetPostString("orderState");
  4582. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4583. string address = GetPostString("address");
  4584. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4585. string sellermemo = GetPostString("seller_memo");
  4586. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4587. string supplier = GetPostString("supplier");
  4588. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4589. string date1 = GetPostString("date1");
  4590. string date2 = GetPostString("date2");
  4591. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4592. if (dw.Length > 0) lw.Add(dw);
  4593. string bdate1 = GetPostString("backdate1");
  4594. string bdate2 = GetPostString("backdate2");
  4595. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4596. if (dw_back.Length > 0) lw.Add(dw_back);
  4597. string price1 = GetPostString("price1");
  4598. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4599. string price2 = GetPostString("price2");
  4600. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4601. lw.Add(string.Format("IsReturn=3"));
  4602. string backtype = GetPostString("backtype");
  4603. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4604. string backreason = GetPostString("backreason");
  4605. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4606. dStruct.Order = "ReturnTime desc";
  4607. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4608. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4609. writeGridDataTableJson(dStruct.TotalCount, dt);
  4610. }
  4611. public void get_erp_xianhuoreturnlist()
  4612. {
  4613. DataStruct dStruct = GetPostStruct();
  4614. List<string> lw = new List<string>();
  4615. string tid = GetPostString("ctid");
  4616. if (tid.Length > 0)
  4617. {
  4618. string select_tid = getTidByCtid(tid);
  4619. lw.Add(string.Format("tid='{0}'", select_tid));
  4620. }
  4621. string shopname = GetPostString("shopname");
  4622. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4623. string buyernick = GetPostString("buyer_nick");
  4624. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4625. string customer = GetPostString("customer");
  4626. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4627. string design = GetPostString("design");
  4628. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4629. string orderState = GetPostString("orderState");
  4630. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4631. string address = GetPostString("address");
  4632. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4633. string sellermemo = GetPostString("seller_memo");
  4634. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4635. string supplier = GetPostString("supplier");
  4636. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4637. string OrderArea = GetPostString("order_area");
  4638. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4639. string date1 = GetPostString("date1");
  4640. string date2 = GetPostString("date2");
  4641. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4642. if (dw.Length > 0) lw.Add(dw);
  4643. string price1 = GetPostString("price1");
  4644. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4645. string price2 = GetPostString("price2");
  4646. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4647. string posTag = CurrentUser.UserPost.Post.Code;
  4648. if (posTag == "Supplier")
  4649. {
  4650. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4651. }
  4652. lw.Add(string.Format("OrderState=6 "));
  4653. lw.Add(string.Format("IsXianHuo=1 "));
  4654. lw.Add(string.Format("IsReturn>0 "));
  4655. lw.Add(string.Format("IsReturn!=3"));
  4656. lw.Add(string.Format("IsRefund<={0}", 1));
  4657. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4658. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4659. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4660. writeGridDataTableJson(dStruct.TotalCount, dt);
  4661. }
  4662. public void set_erp_orderdelivery()
  4663. {
  4664. if (UrlPostParmsCheck("ctid"))
  4665. {
  4666. string eid = GetPostString("ctid");
  4667. CeErpTradeCell entity = null;
  4668. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4669. if (entity != null)
  4670. {
  4671. if (entity.OrderState >= 7)
  4672. {
  4673. returnErrorMsg("此单已发货,无需重复发货");
  4674. return;
  4675. }
  4676. if (entity.OrderState != 6)
  4677. {
  4678. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4679. return;
  4680. }
  4681. string shop = GetPostString("seller_nick");
  4682. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4683. string comName = GetPostString("comName");
  4684. string comCode = GetPostString("comCode");
  4685. string outSid = GetPostString("outSid");
  4686. string deliveryType = GetPostString("deliveryType");
  4687. string deliveryMemo = GetPostString("deliveryMemo");
  4688. outSid = outSid.Trim();
  4689. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4690. if (mainEn == null)
  4691. {
  4692. returnErrorMsg("找不到原始订单记录");
  4693. return;
  4694. }
  4695. bool isInitOrderDeliv = false;
  4696. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4697. {
  4698. isInitOrderDeliv = true;
  4699. }
  4700. string apires = "";
  4701. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4702. 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)
  4703. {
  4704. apires = "发货成功true";
  4705. }
  4706. else
  4707. {
  4708. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4709. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4710. }
  4711. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4712. {
  4713. entity.OrderState = 7;//发货后订单已发货
  4714. entity.OutSid = outSid;
  4715. entity.MemoOpt = 0;
  4716. entity.UpdateTime = DateTime.Now;
  4717. entity.FinishDeliveryTime = DateTime.Now;
  4718. entity.Update();
  4719. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4720. commonHelper.UpdateRelationOrder(entity.ctid);
  4721. //还要插入快递信息到 快递信息表
  4722. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4723. exinfo.tid = eid;
  4724. exinfo.out_sid = outSid;
  4725. exinfo.company_code = comCode;
  4726. exinfo.company_name = comName;
  4727. exinfo.delivery_memo = deliveryMemo;
  4728. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4729. exinfo.deliveryType = deliveryType;
  4730. exinfo.Create();
  4731. returnSuccessMsg("发货操作成功!");
  4732. commonHelper.UpdateRelationOrder(entity.ctid);
  4733. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4734. CeErpSukuraData.createInfo(entity.ctid, 4);
  4735. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  4736. {
  4737. commonHelper.sendCytExpress(exinfo);
  4738. }
  4739. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4740. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4741. }
  4742. else
  4743. {
  4744. string errmsg = commonHelper.KeepChinese(apires);
  4745. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4746. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4747. }
  4748. return;
  4749. }
  4750. returnErrorMsg("找不到订单记录");
  4751. }
  4752. }
  4753. public void set_erp_multidelivery()
  4754. {
  4755. string eids = GetPostString("tids");
  4756. string[] eidList = eids.Split(',');
  4757. if (eidList.Length <= 0)
  4758. {
  4759. returnErrorMsg("发货不能为空");
  4760. return;
  4761. }
  4762. foreach (string ctid in eidList)
  4763. {
  4764. if (ctid.Length <= 0) continue;
  4765. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4766. if (expInfo != null)
  4767. {
  4768. StringBuilder sql = new StringBuilder();
  4769. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4770. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4771. if (dt.Rows.Count > 0)
  4772. {
  4773. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4774. {
  4775. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4776. expInfo.state = "异常";
  4777. expInfo.isMultiDelivery = 1;
  4778. expInfo.Update();
  4779. continue;
  4780. }
  4781. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4782. {
  4783. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4784. expInfo.state = "异常";
  4785. expInfo.Update();
  4786. continue;
  4787. }
  4788. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4789. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4790. bool isInitOrderDeliv = false;
  4791. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4792. {
  4793. isInitOrderDeliv = true;
  4794. expInfo.isMultiDelivery = 1;
  4795. }
  4796. if (ctid.IndexOf("N") != -1)
  4797. {
  4798. StringBuilder sqlbucha = new StringBuilder();
  4799. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4800. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4801. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4802. commonHelper.UpdateRelationOrder(ctid);
  4803. expInfo.delivery_memo = "发货成功";
  4804. expInfo.state = "发货成功";
  4805. expInfo.isMultiDelivery = 1;
  4806. expInfo.Update();
  4807. }
  4808. else
  4809. {
  4810. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4811. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4812. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4813. {
  4814. expInfo.delivery_memo = "发货成功";
  4815. expInfo.state = "发货成功";
  4816. expInfo.isMultiDelivery = 1;
  4817. expInfo.Update();
  4818. commonHelper.UpdateRelationOrder(ctid);
  4819. CeErpSukuraData.createInfo(ctid, 4);
  4820. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4821. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4822. }
  4823. else
  4824. {
  4825. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4826. expInfo.state = "异常";
  4827. expInfo.Update();
  4828. }
  4829. }
  4830. }
  4831. }
  4832. }
  4833. returnSuccessMsg("操作完成");
  4834. }
  4835. public void reset_erp_memoopt()
  4836. {
  4837. if (UrlPostParmsCheck("ctid"))
  4838. {
  4839. string eid = GetPostString("ctid");
  4840. CeErpTradeCell entity = null;
  4841. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4842. if (entity != null)
  4843. {
  4844. string stropt = "";
  4845. if (entity.MemoOpt == 1)
  4846. {
  4847. stropt = "“改稿”";
  4848. }
  4849. else if (entity.MemoOpt == 2)
  4850. {
  4851. stropt = "“定稿”";
  4852. }
  4853. else if (entity.MemoOpt == 3)
  4854. {
  4855. stropt = "“完成查货”";
  4856. CeErpSukuraData.createInfo(entity.ctid, 6);
  4857. }
  4858. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4859. entity.UpdateTime = DateTime.Now;
  4860. entity.MemoOpt = 0;
  4861. entity.Update();
  4862. returnSuccessMsg("操作成功!");
  4863. return;
  4864. }
  4865. returnErrorMsg("找不到记录");
  4866. }
  4867. }
  4868. public void get_erp_deliveryunusual()
  4869. {
  4870. DataStruct dStruct = GetPostStruct();
  4871. List<string> lw = new List<string>();
  4872. string tid = GetPostString("ctid");
  4873. if (tid.Length > 0)
  4874. {
  4875. string select_tid = getTidByCtid(tid);
  4876. lw.Add(string.Format("tid='{0}'", select_tid));
  4877. }
  4878. string shopname = GetPostString("shopname");
  4879. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4880. string buyernick = GetPostString("buyer_nick");
  4881. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4882. string customer = GetPostString("customer");
  4883. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4884. string design = GetPostString("design");
  4885. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4886. string sellermemo = GetPostString("seller_memo");
  4887. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4888. string supplier = GetPostString("supplier");
  4889. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4890. string date1 = GetPostString("date1");
  4891. string date2 = GetPostString("date2");
  4892. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4893. if (dw.Length > 0) lw.Add(dw);
  4894. string placedate1 = GetPostString("placedate1");
  4895. string placedate2 = GetPostString("placedate2");
  4896. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4897. if (dw_place.Length > 0) lw.Add(dw_place);
  4898. string price1 = GetPostString("price1");
  4899. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4900. string price2 = GetPostString("price2");
  4901. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4902. string unusualCon = GetPostString("unusualcon");
  4903. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4904. string posTag = CurrentUser.UserPost.Post.Code;
  4905. if (posTag == "Supplier")
  4906. {
  4907. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4908. }
  4909. lw.Add(string.Format("OrderState = 6"));
  4910. lw.Add(string.Format("UnusualTag = 5"));
  4911. lw.Add(string.Format("IsRefund<={0}", 1));
  4912. dStruct.Order = "FinishPlaceTime desc";
  4913. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4914. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4915. writeGridDataTableJson(dStruct.TotalCount, dt);
  4916. }
  4917. public void get_erp_deliveryedlist()
  4918. {
  4919. DataStruct dStruct = GetPostStruct();
  4920. List<string> lw = new List<string>();
  4921. string tid = GetPostString("ctid");
  4922. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4923. string shopname = GetPostString("shopname");
  4924. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4925. string buyernick = GetPostString("buyer_nick");
  4926. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4927. string customer = GetPostString("customer");
  4928. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4929. string design = GetPostString("design");
  4930. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4931. string sellermemo = GetPostString("seller_memo");
  4932. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4933. string logistics = GetPostString("logistics");
  4934. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4935. string date1 = GetPostString("date1");
  4936. string date2 = GetPostString("date2");
  4937. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4938. //if (dw.Length > 0) lw.Add(dw);
  4939. string placedate1 = GetPostString("placedate1");
  4940. string placedate2 = GetPostString("placedate2");
  4941. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4942. if (fdw.Length > 0) lw.Add(fdw);
  4943. string devdate1 = GetPostString("deliverydate1");
  4944. string devdate2 = GetPostString("deliverydate2");
  4945. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4946. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4947. string price1 = GetPostString("price1");
  4948. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4949. string price2 = GetPostString("price2");
  4950. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4951. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4952. {
  4953. if (tid.Length > 0)
  4954. {
  4955. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4956. if (tid.Length > 5)
  4957. {
  4958. List<string> tids = getTidByCtidLike(tid);
  4959. if (tids.Count > 0 && tids.Count < 10)
  4960. {
  4961. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4962. }
  4963. }
  4964. lw.Add(tid_sql);
  4965. }
  4966. if (buyernick.Length > 0)
  4967. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4968. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4969. if (dw.Length > 0) lw.Add(dw);
  4970. }
  4971. else
  4972. {
  4973. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  4974. }
  4975. string posTag = CurrentUser.UserPost.Post.Code;
  4976. if (posTag == "Supplier")
  4977. {
  4978. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4979. }
  4980. else
  4981. {
  4982. string supplier = GetPostString("supplier");
  4983. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4984. }
  4985. lw.Add(string.Format(" OrderState IN (7, 8)"));
  4986. lw.Add(string.Format("type != 'PDD' "));
  4987. lw.Add(string.Format("IsRefund!={0}", 2));
  4988. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4989. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4990. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4991. /*if (tid.Length > 0)
  4992. {
  4993. List<string> tids = new List<string>();
  4994. if (dt != null && dt.Rows.Count > 0)
  4995. {
  4996. foreach (DataRow item in dt.Rows)
  4997. {
  4998. tids.Add("'" + item["tid"] + "'");
  4999. }
  5000. }
  5001. if (tids.Count > 0)
  5002. {
  5003. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5004. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5005. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5006. dt = WebCache.GetData("view_erptradecell", dStruct);
  5007. }
  5008. }*/
  5009. if (dt != null)
  5010. {
  5011. foreach (DataRow dr in dt.Rows)
  5012. {
  5013. 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();
  5014. }
  5015. }
  5016. writeGridDataTableJson(dStruct.TotalCount, dt);
  5017. }
  5018. public void get_erp_pdddeliveryed()
  5019. {
  5020. DataStruct dStruct = GetPostStruct();
  5021. List<string> lw = new List<string>();
  5022. string tid = GetPostString("ctid");
  5023. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5024. string shopname = GetPostString("shopname");
  5025. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5026. string buyernick = GetPostString("buyer_nick");
  5027. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5028. string customer = GetPostString("customer");
  5029. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5030. string design = GetPostString("design");
  5031. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5032. string sellermemo = GetPostString("seller_memo");
  5033. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5034. string logistics = GetPostString("logistics");
  5035. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5036. string date1 = GetPostString("date1");
  5037. string date2 = GetPostString("date2");
  5038. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5039. //if (dw.Length > 0) lw.Add(dw);
  5040. string placedate1 = GetPostString("placedate1");
  5041. string placedate2 = GetPostString("placedate2");
  5042. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5043. if (fdw.Length > 0) lw.Add(fdw);
  5044. string devdate1 = GetPostString("deliverydate1");
  5045. string devdate2 = GetPostString("deliverydate2");
  5046. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5047. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5048. string price1 = GetPostString("price1");
  5049. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5050. string price2 = GetPostString("price2");
  5051. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5052. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5053. {
  5054. if (tid.Length > 0)
  5055. {
  5056. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5057. if (tid.Length > 5)
  5058. {
  5059. List<string> tids = getTidByCtidLike(tid);
  5060. if (tids.Count > 0 && tids.Count < 10)
  5061. {
  5062. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5063. }
  5064. }
  5065. lw.Add(tid_sql);
  5066. }
  5067. if (buyernick.Length > 0)
  5068. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5069. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5070. if (dw.Length > 0) lw.Add(dw);
  5071. }
  5072. else
  5073. {
  5074. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5075. }
  5076. string posTag = CurrentUser.UserPost.Post.Code;
  5077. if (posTag == "Supplier")
  5078. {
  5079. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5080. }
  5081. else
  5082. {
  5083. string supplier = GetPostString("supplier");
  5084. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5085. }
  5086. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5087. lw.Add(string.Format("type = 'PDD' "));
  5088. lw.Add(string.Format("IsRefund!={0}", 2));
  5089. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5090. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5091. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5092. /* if (tid.Length > 0)
  5093. {
  5094. List<string> tids = new List<string>();
  5095. if (dt != null && dt.Rows.Count > 0)
  5096. {
  5097. foreach (DataRow item in dt.Rows)
  5098. {
  5099. tids.Add("'" + item["tid"] + "'");
  5100. }
  5101. }
  5102. if (tids.Count > 0)
  5103. {
  5104. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5105. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5106. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5107. dt = WebCache.GetData("view_erptradecell", dStruct);
  5108. }
  5109. }*/
  5110. foreach (DataRow dr in dt.Rows)
  5111. {
  5112. 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();
  5113. }
  5114. writeGridDataTableJson(dStruct.TotalCount, dt);
  5115. }
  5116. public void get_erp_jddeliveryed()
  5117. {
  5118. DataStruct dStruct = GetPostStruct();
  5119. List<string> lw = new List<string>();
  5120. string tid = GetPostString("ctid");
  5121. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5122. string shopname = GetPostString("shopname");
  5123. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5124. string buyernick = GetPostString("buyer_nick");
  5125. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5126. string customer = GetPostString("customer");
  5127. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5128. string design = GetPostString("design");
  5129. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5130. string sellermemo = GetPostString("seller_memo");
  5131. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5132. string date1 = GetPostString("date1");
  5133. string date2 = GetPostString("date2");
  5134. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5135. //if (dw.Length > 0) lw.Add(dw);
  5136. string placedate1 = GetPostString("placedate1");
  5137. string placedate2 = GetPostString("placedate2");
  5138. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5139. if (fdw.Length > 0) lw.Add(fdw);
  5140. string devdate1 = GetPostString("deliverydate1");
  5141. string devdate2 = GetPostString("deliverydate2");
  5142. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5143. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5144. string price1 = GetPostString("price1");
  5145. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5146. string price2 = GetPostString("price2");
  5147. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5148. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5149. {
  5150. if (tid.Length > 0)
  5151. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5152. if (buyernick.Length > 0)
  5153. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5154. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5155. if (dw.Length > 0) lw.Add(dw);
  5156. }
  5157. else
  5158. {
  5159. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5160. }
  5161. string posTag = CurrentUser.UserPost.Post.Code;
  5162. if (posTag == "Supplier")
  5163. {
  5164. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5165. }
  5166. else
  5167. {
  5168. string supplier = GetPostString("supplier");
  5169. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5170. }
  5171. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5172. lw.Add(string.Format("type = 'JD' "));
  5173. lw.Add(string.Format("IsRefund!={0}", 2));
  5174. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5175. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5176. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5177. foreach (DataRow dr in dt.Rows)
  5178. {
  5179. 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();
  5180. }
  5181. writeGridDataTableJson(dStruct.TotalCount, dt);
  5182. }
  5183. public void get_erp_allplacelist()
  5184. {
  5185. DataStruct dStruct = GetPostStruct();
  5186. List<string> lw = new List<string>();
  5187. string tid = GetPostString("ctid");
  5188. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5189. string shopname = GetPostString("shopname");
  5190. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5191. string buyernick = GetPostString("buyer_nick");
  5192. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5193. string customer = GetPostString("customer");
  5194. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5195. string design = GetPostString("design");
  5196. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5197. string sellermemo = GetPostString("seller_memo");
  5198. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5199. string supplier = GetPostString("supplier");
  5200. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5201. string date1 = GetPostString("date1");
  5202. string date2 = GetPostString("date2");
  5203. string pldate1 = GetPostString("placedate1");
  5204. string pldate2 = GetPostString("placedate2");
  5205. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5206. //if (dw.Length > 0) lw.Add(dw);
  5207. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5208. {
  5209. if (tid.Length > 0)
  5210. {
  5211. string select_tid = getTidByCtid(tid);
  5212. lw.Add(string.Format("tid='{0}'", select_tid));
  5213. }
  5214. if (buyernick.Length > 0)
  5215. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5216. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5217. if (dw.Length > 0) lw.Add(dw);
  5218. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5219. if (dw_place.Length > 0) lw.Add(dw_place);
  5220. }
  5221. else
  5222. {
  5223. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5224. {
  5225. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5226. }
  5227. }
  5228. string price1 = GetPostString("price1");
  5229. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5230. string price2 = GetPostString("price2");
  5231. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5232. string posTag = CurrentUser.UserPost.Post.Code;
  5233. if (posTag == "Supplier")
  5234. {
  5235. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5236. }
  5237. lw.Add(string.Format("OrderState >= 6"));
  5238. lw.Add(string.Format("IsSample != 2 "));
  5239. //lw.Add(string.Format("isDianziOrder = 0 "));
  5240. lw.Add(string.Format("SupplierId > 0 "));
  5241. //lw.Add(string.Format("IsRefund<={0}", 1));
  5242. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5243. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5244. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5245. foreach (DataRow dr in dt.Rows)
  5246. {
  5247. 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();
  5248. }
  5249. writeGridDataTableJson(dStruct.TotalCount, dt);
  5250. }
  5251. public void get_erp_financeallplacelist()
  5252. {
  5253. DataStruct dStruct = GetPostStruct();
  5254. List<string> lw = new List<string>();
  5255. string tid = GetPostString("ctid");
  5256. string shopname = GetPostString("shopname");
  5257. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5258. string buyernick = GetPostString("buyer_nick");
  5259. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5260. string customer = GetPostString("customer");
  5261. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5262. string design = GetPostString("design");
  5263. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5264. string sellermemo = GetPostString("seller_memo");
  5265. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5266. string supplier = GetPostString("supplier");
  5267. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5268. string date1 = GetPostString("date1");
  5269. string date2 = GetPostString("date2");
  5270. string pldate1 = GetPostString("placedate1");
  5271. string pldate2 = GetPostString("placedate2");
  5272. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5273. {
  5274. if (tid.Length > 0)
  5275. {
  5276. string select_tid = getTidByCtid(tid);
  5277. lw.Add(string.Format("tid='{0}'", select_tid));
  5278. }
  5279. if (buyernick.Length > 0)
  5280. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5281. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5282. if (dw.Length > 0) lw.Add(dw);
  5283. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5284. if (dw_place.Length > 0) lw.Add(dw_place);
  5285. }
  5286. else
  5287. {
  5288. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5289. {
  5290. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5291. }
  5292. }
  5293. string price1 = GetPostString("price1");
  5294. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5295. string price2 = GetPostString("price2");
  5296. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5297. string posTag = CurrentUser.UserPost.Post.Code;
  5298. if (posTag == "Supplier")
  5299. {
  5300. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5301. }
  5302. //lw.Add(string.Format("OrderState >= 6"));
  5303. lw.Add(string.Format("IsSample != 2 "));
  5304. lw.Add(string.Format("isDianziOrder = 0 "));
  5305. //lw.Add(string.Format("IsRefund<={0}", 1));
  5306. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5307. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5308. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5309. foreach (DataRow dr in dt.Rows)
  5310. {
  5311. 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();
  5312. }
  5313. writeGridDataTableJson(dStruct.TotalCount, dt);
  5314. }
  5315. public void get_erp_expresslist()
  5316. {
  5317. int listtype = GetInt("ltype");
  5318. DataStruct dStruct = GetPostStruct();
  5319. List<string> lw = new List<string>();
  5320. string tid = GetPostString("tid");
  5321. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5322. string outsid = GetPostString("out_sid");
  5323. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5324. string importer = GetPostString("ImportUserName");
  5325. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5326. string file = GetPostString("import_file");
  5327. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5328. string printman = GetPostString("printman");
  5329. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5330. string date1 = GetPostString("date1");
  5331. string date2 = GetPostString("date2");
  5332. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5333. if (dw.Length > 0) lw.Add(dw);
  5334. string fdate1 = GetPostString("finishdate1");
  5335. string fdate2 = GetPostString("finishdate2");
  5336. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5337. if (fdw.Length > 0) lw.Add(fdw);
  5338. string supplierId = GetPostString("supplierId");
  5339. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5340. if (listtype == 1)
  5341. {
  5342. lw.Add(string.Format("importUserId !=0"));
  5343. }
  5344. string posTag = CurrentUser.UserPost.Post.Code;
  5345. if (posTag == "Supplier")
  5346. {
  5347. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5348. }
  5349. if (dStruct.PageSize != 100000)
  5350. {
  5351. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5352. }
  5353. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5354. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5355. writeGridDataTableJson(dStruct.TotalCount, dt);
  5356. }
  5357. public void set_erp_buchaorderdelivery()
  5358. {
  5359. if (UrlPostParmsCheck("ctid"))
  5360. {
  5361. string eid = GetPostString("ctid");
  5362. CeErpTradeCell entity = null;
  5363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5364. if (entity != null)
  5365. {
  5366. if (entity.IsSample != 2)
  5367. {
  5368. returnErrorMsg("补差价单才能标记为已发货");
  5369. return;
  5370. }
  5371. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5372. entity.OrderState = 7;
  5373. entity.Update();
  5374. returnSuccessMsg("操作成功!");
  5375. return;
  5376. }
  5377. returnErrorMsg("找不到记录");
  5378. }
  5379. }
  5380. public void get_stdtemplates()
  5381. {
  5382. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5383. //string res = taobaoHelper.test();
  5384. string res = apiHelper.API_PrintTemplate();
  5385. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5386. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5387. {
  5388. int sidx = res.IndexOf("error_code");
  5389. int eidx = res.IndexOf("success");
  5390. string msg = res.Substring(sidx, eidx - sidx);
  5391. returnErrorMsg(msg);
  5392. return;
  5393. }
  5394. if (res.Length <= 0)
  5395. {
  5396. returnErrorMsg("模板数据为空!");
  5397. return;
  5398. }
  5399. ReturnSuccess(res);
  5400. }
  5401. public void cancel_print_order()
  5402. {
  5403. if (UrlPostParmsCheck("ctid"))
  5404. {
  5405. string ctid = GetPostString("ctid");
  5406. CeErpTradeCell entity = null;
  5407. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5408. if (entity != null)
  5409. {
  5410. string res = "";
  5411. string code = entity.LastBillWaybillCode;
  5412. if (code == "")
  5413. {
  5414. code = entity.OutSid;
  5415. }
  5416. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5417. XLog.SaveLog(0, "取消面单" + res);
  5418. }
  5419. }
  5420. }
  5421. public void set_erp_printwaybill()
  5422. {
  5423. if (UrlPostParmsCheck("ctid"))
  5424. {
  5425. string ctid = GetPostString("ctid");
  5426. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5427. string cpName = GetPostString("cpname");
  5428. string isTogether = GetPostString("together");
  5429. string printType = GetPostString("printType");
  5430. //var res_obj = new
  5431. //{
  5432. // restype = 1,
  5433. // 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\"}"
  5434. //};
  5435. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5436. //ReturnSuccess(ro_json);
  5437. //return;
  5438. bool isUseLastWayBillCode = false;
  5439. CeErpTradeCell entity = null;
  5440. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5441. if (entity != null)
  5442. {
  5443. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5444. {
  5445. isUseLastWayBillCode = true;
  5446. }
  5447. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5448. {
  5449. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5450. return;
  5451. }
  5452. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5453. {
  5454. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5455. return;
  5456. }
  5457. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5458. {
  5459. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5460. return;
  5461. }
  5462. }
  5463. string res = "";
  5464. Api_waybill_code_response_Obj fullObj = null;
  5465. string pData_str = "";
  5466. string curUseWayBillCode = "";
  5467. if (isUseLastWayBillCode == false)
  5468. {
  5469. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5470. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5471. if (res.IndexOf("failure") != -1)
  5472. {
  5473. //int idx = res.IndexOf("sub_message");
  5474. //int idx2 = res.IndexOf("flag");
  5475. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5476. string errMsgNeed = commonHelper.KeepChinese(res);
  5477. var res_objd = new
  5478. {
  5479. restype = 0,
  5480. data = "获取面单失败" + errMsgNeed
  5481. };
  5482. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5483. returnSuccess(ro_jsond);
  5484. if (res.IndexOf("停发") != -1)
  5485. {
  5486. entity.UnusualCon = "物流停发";
  5487. entity.Update();
  5488. }
  5489. //returnErrorMsg("获取面单失败,"+emsg);
  5490. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5491. return;
  5492. }
  5493. else if (res.IndexOf("errorMsg") != -1)
  5494. {
  5495. //int idx = res.IndexOf("errorMsg");
  5496. //int idx2 = res.IndexOf("}]}");
  5497. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5498. string errMsgNeed = commonHelper.KeepChinese(res);
  5499. var res_objf = new
  5500. {
  5501. restype = 0,
  5502. data = "获取面单失败2" + errMsgNeed
  5503. };
  5504. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5505. if (res.IndexOf("停发") != -1)
  5506. {
  5507. entity.UnusualCon = "物流停发";
  5508. entity.Update();
  5509. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5510. if (trade != null)
  5511. {
  5512. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5513. }
  5514. }
  5515. returnSuccess(ro_jsonf);
  5516. //returnErrorMsg("获取面单失败," + emsg);
  5517. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5518. return;
  5519. }
  5520. try
  5521. {
  5522. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5523. //res = res.Replace(" ", "");
  5524. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5525. }
  5526. catch (Exception ex)
  5527. {
  5528. XLog.SaveLog(0, "生成fullObj" + res);
  5529. var res_objf = new
  5530. {
  5531. restype = 0,
  5532. data = "生成fullObj发生错误" + ex.Message
  5533. };
  5534. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5535. returnSuccess(ro_jsonf);
  5536. return;
  5537. }
  5538. if (fullObj.response.data.content.Count > 0)
  5539. {
  5540. ContentItem codeObj = fullObj.response.data.content[0];
  5541. if (cpCode.IndexOf("SFFQ-") != -1)
  5542. {
  5543. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5544. }
  5545. else
  5546. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5547. curUseWayBillCode = codeObj.waybillCode;
  5548. }
  5549. else
  5550. {
  5551. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5552. var res_objf = new
  5553. {
  5554. restype = 0,
  5555. data = "生成fullObj找不到快递单号waybillCode"
  5556. };
  5557. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5558. returnSuccess(ro_jsonf);
  5559. return;
  5560. }
  5561. }
  5562. else
  5563. {
  5564. //使用上次打印的快递单号
  5565. if (cpCode == "SFFQ-LY")
  5566. {
  5567. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5568. }
  5569. else
  5570. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5571. curUseWayBillCode = entity.LastBillWaybillCode;
  5572. }
  5573. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5574. {
  5575. var res_obje = new
  5576. {
  5577. restype = 0,
  5578. data = "获取加密打印数据失败"
  5579. };
  5580. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5581. returnSuccess(ro_jsone);
  5582. entity.LastBillCpCode = cpCode;
  5583. entity.LastBillWaybillCode = curUseWayBillCode;
  5584. entity.Update();
  5585. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5586. //returnErrorMsg("获取加密打印数据失败");
  5587. return;
  5588. }
  5589. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5590. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5591. string btnType = "";
  5592. string errorMsg = "";
  5593. if (entity != null)
  5594. {
  5595. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5596. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5597. //cpcode是 YTO-CAINIAO
  5598. //string comCode = cpCode.Split('-')[0].ToString();
  5599. string apires = "";
  5600. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5601. //isTogether=2是新的合包弹窗
  5602. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5603. {
  5604. if (ctid.IndexOf("N") != -1)
  5605. {
  5606. apires = "发货成功";
  5607. }
  5608. else
  5609. {
  5610. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5611. }
  5612. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5613. //打单后发货
  5614. StringBuilder sql = new StringBuilder();
  5615. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5616. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5617. {
  5618. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5619. }
  5620. else
  5621. {
  5622. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5623. }
  5624. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5625. foreach (DataRow row in dt.Rows)
  5626. {
  5627. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5628. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5629. {
  5630. try
  5631. {
  5632. btnType = "待发货";
  5633. entity.OutSid = curUseWayBillCode;
  5634. entity.OrderState = 7;
  5635. entity.IsUrgency = false;
  5636. entity.LastBillCpCode = "";
  5637. entity.LastBillWaybillCode = "";
  5638. entity.FinishDeliveryTime = DateTime.Now;
  5639. entity.IsReturn = 0;
  5640. entity.MemoOpt = 0;
  5641. entity.UpdateTime = DateTime.Now;
  5642. entity.Update();
  5643. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5644. //还要插入快递信息到 快递信息表
  5645. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5646. exinfo.tid = entity.ctid;
  5647. exinfo.out_sid = curUseWayBillCode;
  5648. exinfo.company_code = cpCode;
  5649. exinfo.company_name = cpName;
  5650. exinfo.supplierUserName = supplierName;
  5651. exinfo.deliveryType = "发货成功";
  5652. exinfo.print_time = DateTime.Now;
  5653. exinfo.printUser = CurrentUser.UserName;
  5654. exinfo.postData = pData_str;
  5655. exinfo.Create();
  5656. commonHelper.UpdateRelationOrder(entity.ctid);
  5657. CeErpSukuraData.createInfo(ctid, 4);
  5658. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5659. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5660. {
  5661. commonHelper.sendCytExpress(exinfo);
  5662. }
  5663. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5664. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5665. }
  5666. catch (Exception ex)
  5667. {
  5668. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5669. }
  5670. }
  5671. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5672. {
  5673. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5674. if (entity.OrderState == 6)
  5675. {
  5676. entity.OrderState = 7;
  5677. }
  5678. entity.UpdateTime = DateTime.Now;
  5679. entity.FinishDeliveryTime = DateTime.Now;
  5680. btnType = "已发货";
  5681. entity.Update();
  5682. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5683. exinfo.tid = entity.ctid;
  5684. exinfo.out_sid = curUseWayBillCode;
  5685. exinfo.company_code = cpCode;
  5686. exinfo.company_name = cpName;
  5687. exinfo.supplierUserName = supplierName;
  5688. exinfo.deliveryType = "发货成功";
  5689. exinfo.print_time = DateTime.Now;
  5690. exinfo.printUser = CurrentUser.UserName;
  5691. exinfo.postData = pData_str;
  5692. exinfo.Create();
  5693. commonHelper.UpdateRelationOrder(entity.ctid);
  5694. CeErpSukuraData.createInfo(entity.ctid, 4);
  5695. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5696. {
  5697. commonHelper.sendCytExpress(exinfo);
  5698. }
  5699. //不处理
  5700. }
  5701. else
  5702. {
  5703. entity.UpdateTime = DateTime.Now;
  5704. entity.LastBillCpCode = cpCode;
  5705. entity.LastBillWaybillCode = curUseWayBillCode;
  5706. entity.Update();
  5707. string errmsg = commonHelper.KeepChinese(apires);
  5708. var res_objz = new
  5709. {
  5710. restype = 0,
  5711. data = "打单后发货失败"
  5712. };
  5713. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5714. returnSuccess(ro_jsonz);
  5715. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5716. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5717. return;
  5718. }
  5719. }
  5720. }
  5721. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5722. {
  5723. string ctids = GetPostString("ctids");
  5724. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5725. List<string> list = new List<string>();
  5726. List<string> send_list = new List<string>();
  5727. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5728. CeErpTrade ceErpTrade = new CeErpTrade();
  5729. //可合包的合并一起发货
  5730. if (dt == null && string.IsNullOrEmpty(ctids))
  5731. {
  5732. var res_objz = new
  5733. {
  5734. restype = 0,
  5735. data = "打单后发货失败"
  5736. };
  5737. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5738. returnSuccess(ro_jsonz);
  5739. return;
  5740. }
  5741. if (!string.IsNullOrEmpty(ctids))
  5742. {
  5743. StringBuilder sql = new StringBuilder();
  5744. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5745. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5746. }
  5747. foreach (DataRow row in dt.Rows)
  5748. {
  5749. list.Add("'" + row["ctid"] + "'");
  5750. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5751. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5752. if (ctid.IndexOf("N") != -1)
  5753. {
  5754. apires = "发货成功";
  5755. }
  5756. else
  5757. {
  5758. if (!send_list.Contains(ceErpTrade.tid))
  5759. {
  5760. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5761. }
  5762. else
  5763. {
  5764. apires = "发货成功";
  5765. }
  5766. }
  5767. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5768. {
  5769. send_list.Add(ceErpTrade.tid);
  5770. try
  5771. {
  5772. btnType = "待发货";
  5773. ceErpTradeCell.OutSid = curUseWayBillCode;
  5774. ceErpTradeCell.OrderState = 7;
  5775. ceErpTradeCell.IsUrgency = false;
  5776. ceErpTradeCell.LastBillCpCode = "";
  5777. ceErpTradeCell.LastBillWaybillCode = "";
  5778. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5779. ceErpTradeCell.IsReturn = 0;
  5780. ceErpTradeCell.MemoOpt = 0;
  5781. ceErpTradeCell.UpdateTime = DateTime.Now;
  5782. ceErpTradeCell.Update();
  5783. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5784. //还要插入快递信息到 快递信息表
  5785. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5786. exinfo.tid = ceErpTradeCell.ctid;
  5787. exinfo.out_sid = curUseWayBillCode;
  5788. exinfo.company_code = cpCode;
  5789. exinfo.company_name = cpName;
  5790. exinfo.supplierUserName = supplierName;
  5791. exinfo.deliveryType = "发货成功";
  5792. exinfo.print_time = DateTime.Now;
  5793. exinfo.printUser = CurrentUser.UserName;
  5794. exinfo.postData = pData_str;
  5795. exinfo.Create();
  5796. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5797. CeErpSukuraData.createInfo(ctid, 4);
  5798. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5799. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80)
  5800. {
  5801. commonHelper.sendCytExpress(exinfo);
  5802. }
  5803. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5804. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5805. }
  5806. catch (Exception ex)
  5807. {
  5808. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5809. }
  5810. }
  5811. else
  5812. {
  5813. ceErpTradeCell.UpdateTime = DateTime.Now;
  5814. ceErpTradeCell.LastBillCpCode = cpCode;
  5815. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5816. ceErpTradeCell.Update();
  5817. string errmsg = commonHelper.KeepChinese(apires);
  5818. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5819. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5820. }
  5821. }
  5822. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5823. }
  5824. }
  5825. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5826. var res_obj = new
  5827. {
  5828. restype = 1,
  5829. data = pData_str,
  5830. errorMsg
  5831. };
  5832. string ro_json = JsonConvert.SerializeObject(res_obj);
  5833. ReturnSuccess(ro_json);
  5834. return;
  5835. }
  5836. }
  5837. private string GetUTF8String(byte[] vs)
  5838. {
  5839. throw new NotImplementedException();
  5840. }
  5841. public void set_erp_printwaybill_cn()
  5842. {
  5843. if (UrlPostParmsCheck("ctid"))
  5844. {
  5845. string ctid = GetPostString("ctid");
  5846. string cpCode = GetPostString("cpcode");
  5847. string cpName = GetPostString("cpname");
  5848. string tempUrl = GetPostString("tempurl");
  5849. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5850. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5851. //string res = taobaoHelper.test();
  5852. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5853. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5854. {
  5855. int sidx = res.IndexOf("errorMsg");
  5856. int eidx = res.IndexOf("}");
  5857. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5858. var res_objzxx = new
  5859. {
  5860. restype = 0,
  5861. data = msg
  5862. };
  5863. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5864. returnSuccess(ro_jsonzxx);
  5865. //returnErrorMsg(msg);
  5866. return;
  5867. }
  5868. int idx = res.IndexOf("waybillCode");
  5869. int idx2 = res.IndexOf("printData");
  5870. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5871. string eid = GetPostString("ctid");
  5872. CeErpTradeCell entity = null;
  5873. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5874. if (entity != null)
  5875. {
  5876. string osid = entity.OutSid;
  5877. entity.OutSid = osid + "," + outsid;
  5878. entity.FinishDeliveryTime = DateTime.Now;
  5879. entity.OrderState = 7;
  5880. entity.UpdateTime = DateTime.Now;
  5881. entity.IsReturn = 0;
  5882. entity.Update();
  5883. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5884. exinfo.tid = entity.ctid;
  5885. exinfo.out_sid = outsid;
  5886. exinfo.company_code = cpCode;
  5887. exinfo.company_name = cpName;
  5888. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5889. exinfo.deliveryType = "发货成功";
  5890. exinfo.print_time = DateTime.Now;
  5891. exinfo.printUser = CurrentUser.UserName;
  5892. exinfo.Create();
  5893. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5894. {
  5895. commonHelper.sendCytExpress(exinfo);
  5896. }
  5897. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5898. }
  5899. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5900. var res_objz = new
  5901. {
  5902. restype = 1,
  5903. data = res
  5904. };
  5905. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5906. returnSuccess(ro_jsonz);
  5907. //ReturnSuccess(res);
  5908. }
  5909. }
  5910. ////打单,打印面单 获取面单号
  5911. //public void set_erp_printwaybill()
  5912. //{
  5913. // if (UrlPostParmsCheck("ctid"))
  5914. // {
  5915. // string ctid = GetPostString("ctid");
  5916. // string cpCode = GetPostString("cpcode");
  5917. // string tempUrl = GetPostString("tempurl");
  5918. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5919. // //string res = taobaoHelper.test();
  5920. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5921. // if (res.IndexOf("error_response") != -1)
  5922. // {
  5923. // int sidx = res.IndexOf("sub_msg");
  5924. // int eidx = res.IndexOf("request_id");
  5925. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5926. // returnErrorMsg(msg);
  5927. // return;
  5928. // }
  5929. // int idx = res.IndexOf("waybill_code");
  5930. // int idx2 = res.IndexOf("}]}");
  5931. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5932. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5933. // ReturnSuccess(res);
  5934. // }
  5935. //}
  5936. public void cancel_erp_aftersale()
  5937. {
  5938. if (UrlPostParmsCheck("ctid"))
  5939. {
  5940. string eid = GetPostString("ctid");
  5941. CeErpTradeCell entity = null;
  5942. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5943. if (entity != null)
  5944. {
  5945. //有过处理的售后,取消也不能删除 售 字,保留
  5946. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5947. {
  5948. entity.AfterSaleState = 4;
  5949. }
  5950. else
  5951. entity.AfterSaleState = 0;
  5952. entity.UpdateTime = DateTime.Now;
  5953. entity.Update();
  5954. returnSuccessMsg("操作成功!");
  5955. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5956. return;
  5957. }
  5958. returnErrorMsg("找不到订单记录");
  5959. }
  5960. }
  5961. public void get_erp_aftersalelist()
  5962. {
  5963. DataStruct dStruct = GetPostStruct();
  5964. List<string> lw = new List<string>();
  5965. int st = GetInt("st");
  5966. string tid = GetPostString("ctid");
  5967. if (st == 3)
  5968. {
  5969. if (tid.Length > 0)
  5970. {
  5971. string select_tid = getTidByCtid(tid);
  5972. lw.Add(string.Format("tid='{0}'", select_tid));
  5973. }
  5974. }
  5975. else
  5976. {
  5977. if (tid.Length > 0)
  5978. {
  5979. string select_tid = getTidByCtid(tid);
  5980. lw.Add(string.Format("tid='{0}'", select_tid));
  5981. }
  5982. }
  5983. string shopname = GetPostString("shopname");
  5984. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5985. string buyernick = GetPostString("buyer_nick");
  5986. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5987. string sellermemo = GetPostString("seller_memo");
  5988. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5989. string orderState = GetPostString("orderState");
  5990. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5991. string afterState = GetPostString("afterstate");
  5992. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5993. string date1 = GetPostString("date1");
  5994. string date2 = GetPostString("date2");
  5995. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5996. if (dw.Length > 0) lw.Add(dw);
  5997. string price1 = GetPostString("price1");
  5998. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5999. string price2 = GetPostString("price2");
  6000. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6001. //lw.Add(string.Format("IsRefund!={0}", 1));
  6002. string reason = GetPostString("reason");
  6003. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6004. string method = GetPostString("method");
  6005. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6006. string handler = GetPostString("handler");
  6007. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6008. string handledate1 = GetPostString("handledate1");
  6009. string handledate2 = GetPostString("handledate2");
  6010. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6011. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6012. string finish1 = GetPostString("finishdate1");
  6013. string finish2 = GetPostString("finishdate2");
  6014. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6015. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6016. string afterdate1 = GetPostString("afterdate1");
  6017. string afterdate2 = GetPostString("afterdate2");
  6018. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6019. if (afterDate.Length > 0) lw.Add(afterDate);
  6020. string supplier = GetPostString("supplier");
  6021. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6022. string responsible = GetPostString("responsibleman");
  6023. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6024. string customer = GetPostString("customer");
  6025. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6026. string design = GetPostString("design");
  6027. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6028. string afterMemoType = GetPostString("aftermemotype");
  6029. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6030. string posCode = CurrentUser.UserPost.Post.Code;
  6031. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6032. //{
  6033. // string vstate = GetPostString("vstate");
  6034. // if (vstate.Length > 0)
  6035. // {
  6036. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6037. // }
  6038. // if (posCode == "Supplier")
  6039. // {
  6040. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6041. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6042. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6043. // }
  6044. // else
  6045. // {
  6046. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6047. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6048. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6049. // {
  6050. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6051. // }
  6052. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6053. // {
  6054. // int orgid = CurrentUser.UserPost.OrgID;
  6055. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6056. // }
  6057. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6058. // {
  6059. // string shopid = CurrentUser.User.pemShop;
  6060. // lw.Add(string.Format("shopId in ({0})", shopid));
  6061. // }
  6062. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6063. // //{
  6064. // // int org_id = CurrentUser.UserPost.OrgID;
  6065. // // lw.Add(string.Format("OrgID={0}", org_id));
  6066. // //}
  6067. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6068. // }
  6069. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6070. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6071. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6072. //}
  6073. if (st == 5)
  6074. {
  6075. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6076. {
  6077. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6078. {
  6079. string shopid = CurrentUser.User.pemShop;
  6080. lw.Add(string.Format("shopId in ({0})", shopid));
  6081. }
  6082. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6083. {
  6084. int mrOrgid = CurrentUser.UserPost.OrgID;
  6085. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6086. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6087. }
  6088. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6089. //{
  6090. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6091. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6092. //}
  6093. else
  6094. {
  6095. string userIdStr = "";
  6096. if (posCode == "CustomerService")
  6097. {
  6098. userIdStr = CurrentUser.UserID + "_k";
  6099. }
  6100. else if (posCode == "Designer" || posCode == "wxDesigner")
  6101. {
  6102. userIdStr = CurrentUser.UserID + "_s";
  6103. }
  6104. else if (posCode == "Place")
  6105. {
  6106. userIdStr = CurrentUser.UserID + "_x";
  6107. }
  6108. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6109. }
  6110. }
  6111. string placedate1 = GetPostString("placedate1");
  6112. string placedate2 = GetPostString("placedate2");
  6113. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6114. if (dwplace.Length > 0) lw.Add(dwplace);
  6115. string supState = GetPostString("supState");
  6116. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6117. string searchType = GetPostString("searchType");
  6118. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6119. {
  6120. lw.Add(string.Format("BackNum>1"));
  6121. }
  6122. lw.Add(string.Format("AfterSaleState>0"));
  6123. if (ex_psize > 0)
  6124. {
  6125. if (CurrentUser.UserPost.Post.Code == "Finance")
  6126. dStruct.Order = "pay_time desc";
  6127. else
  6128. dStruct.Order = "HandleTime desc";
  6129. }
  6130. else
  6131. dStruct.Order = "HandleTime desc";
  6132. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6133. DataTable dt = WebCache.GetData("view_test", dStruct);
  6134. writeGridDataTableJson(dStruct.TotalCount, dt);
  6135. }
  6136. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6137. //{
  6138. // lw.Add(string.Format("AfterSaleState=4"));
  6139. // string code = CurrentUser.UserPost.Post.Code;
  6140. // if (code == "CustomerService")
  6141. // {
  6142. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6143. // }
  6144. // else if (code == "Designer" || code == "DesignerMr")
  6145. // {
  6146. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6147. // }
  6148. // else if (code == "Place" || code == "PlaceMr")
  6149. // {
  6150. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6151. // }
  6152. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6153. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6154. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6155. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6156. //}
  6157. //else //处理中的售后,待处理和处理中合并
  6158. //{
  6159. // if (afterState.Length <= 0)
  6160. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6161. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6162. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6163. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6164. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6165. //}
  6166. }
  6167. public void get_erp_disagreeftersalelist()
  6168. {
  6169. DataStruct dStruct = GetPostStruct();
  6170. List<string> lw = new List<string>();
  6171. int st = 2;
  6172. string tid = GetPostString("ctid");
  6173. if (tid.Length > 0)
  6174. {
  6175. string select_tid = getTidByCtid(tid);
  6176. lw.Add(string.Format("tid='{0}'", select_tid));
  6177. }
  6178. string shopname = GetPostString("shopname");
  6179. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6180. string buyernick = GetPostString("buyer_nick");
  6181. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6182. string sellermemo = GetPostString("seller_memo");
  6183. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6184. string orderState = GetPostString("orderState");
  6185. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6186. string afterState = GetPostString("afterstate");
  6187. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6188. string date1 = GetPostString("date1");
  6189. string date2 = GetPostString("date2");
  6190. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6191. if (dw.Length > 0) lw.Add(dw);
  6192. string price1 = GetPostString("price1");
  6193. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6194. string price2 = GetPostString("price2");
  6195. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6196. //lw.Add(string.Format("IsRefund!={0}", 1));
  6197. string reason = GetPostString("reason");
  6198. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6199. string method = GetPostString("method");
  6200. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6201. string handler = GetPostString("handler");
  6202. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6203. string handledate1 = GetPostString("handledate1");
  6204. string handledate2 = GetPostString("handledate2");
  6205. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6206. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6207. string afterdate1 = GetPostString("afterdate1");
  6208. string afterdate2 = GetPostString("afterdate2");
  6209. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6210. if (afterDate.Length > 0) lw.Add(afterDate);
  6211. string backdate1 = GetPostString("backdate1");
  6212. string backdate2 = GetPostString("backdate2");
  6213. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6214. if (backDate.Length > 0) lw.Add(backDate);
  6215. string supplier = GetPostString("supplier");
  6216. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6217. string responsible = GetPostString("responsibleman");
  6218. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6219. string customer = GetPostString("customer");
  6220. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6221. string design = GetPostString("design");
  6222. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6223. string afterSaleMemo = GetPostString("afterSaleMemo");
  6224. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6225. string afterMemoType = GetPostString("aftermemotype");
  6226. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6227. string aftersakereason = GetPostString("aftersakereason");
  6228. if (aftersakereason.Length > 0)
  6229. {
  6230. if (aftersakereason == "1")
  6231. {
  6232. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6233. }
  6234. if (aftersakereason == "2")
  6235. {
  6236. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6237. }
  6238. }
  6239. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6240. string poscode = CurrentUser.UserPost.Post.Code;
  6241. if (poscode != "SysAdmin")
  6242. {
  6243. string shopid = CurrentUser.User.pemShop;
  6244. lw.Add(string.Format("shopId in ({0})", shopid));
  6245. }
  6246. string searchType = GetPostString("searchType");
  6247. if (searchType == "wait")
  6248. {
  6249. lw.Add(string.Format("HandleTime is null"));
  6250. }
  6251. if (searchType == "handling")
  6252. {
  6253. lw.Add(string.Format("HandleTime is not null "));
  6254. }
  6255. if (searchType == "back" || searchType == "puBack")
  6256. {
  6257. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6258. }
  6259. if (searchType == "reBack")
  6260. {
  6261. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6262. }
  6263. if (searchType == "moreBack")
  6264. {
  6265. lw.Add(string.Format("backNum > 1"));
  6266. }
  6267. lw.Add(string.Format("(AfterSaleState=5)"));
  6268. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6269. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6270. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6271. writeGridDataTableJson(dStruct.TotalCount, dt);
  6272. }
  6273. public void get_erp_handlingaftersalelist()
  6274. {
  6275. DataStruct dStruct = GetPostStruct();
  6276. List<string> lw = new List<string>();
  6277. int st = 2;
  6278. string tid = GetPostString("ctid");
  6279. if (tid.Length > 0)
  6280. {
  6281. string select_tid = getTidByCtid(tid);
  6282. lw.Add(string.Format("tid='{0}'", select_tid));
  6283. }
  6284. string shopname = GetPostString("shopname");
  6285. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6286. string buyernick = GetPostString("buyer_nick");
  6287. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6288. string sellermemo = GetPostString("seller_memo");
  6289. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6290. string orderState = GetPostString("orderState");
  6291. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6292. string afterState = GetPostString("afterstate");
  6293. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6294. string date1 = GetPostString("date1");
  6295. string date2 = GetPostString("date2");
  6296. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6297. if (dw.Length > 0) lw.Add(dw);
  6298. string price1 = GetPostString("price1");
  6299. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6300. string price2 = GetPostString("price2");
  6301. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6302. //lw.Add(string.Format("IsRefund!={0}", 1));
  6303. string reason = GetPostString("reason");
  6304. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6305. string method = GetPostString("method");
  6306. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6307. string handler = GetPostString("handler");
  6308. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6309. string handledate1 = GetPostString("handledate1");
  6310. string handledate2 = GetPostString("handledate2");
  6311. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6312. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6313. string afterdate1 = GetPostString("afterdate1");
  6314. string afterdate2 = GetPostString("afterdate2");
  6315. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6316. if (afterDate.Length > 0) lw.Add(afterDate);
  6317. string supplier = GetPostString("supplier");
  6318. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6319. string responsible = GetPostString("responsibleman");
  6320. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6321. string customer = GetPostString("customer");
  6322. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6323. string design = GetPostString("design");
  6324. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6325. string afterSaleMemo = GetPostString("afterSaleMemo");
  6326. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6327. string afterMemoType = GetPostString("aftermemotype");
  6328. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6329. string afterresult = GetPostString("afterresult");
  6330. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6331. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6332. string poscode = CurrentUser.UserPost.Post.Code;
  6333. if (poscode != "SysAdmin")
  6334. {
  6335. string shopid = CurrentUser.User.pemShop;
  6336. lw.Add(string.Format("shopId in ({0})", shopid));
  6337. }
  6338. string searchType = GetPostString("searchType");
  6339. if (searchType == "wait")
  6340. {
  6341. lw.Add(string.Format("HandleTime is null"));
  6342. }
  6343. if (searchType == "documentary")
  6344. {
  6345. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6346. }
  6347. if (searchType == "handling")
  6348. {
  6349. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6350. }
  6351. if (searchType == "back" || searchType == "puBack")
  6352. {
  6353. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6354. }
  6355. if (searchType == "reBack")
  6356. {
  6357. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6358. }
  6359. if (afterState.Length <= 0)
  6360. {
  6361. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6362. }
  6363. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6364. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6365. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6366. writeGridDataTableJson(dStruct.TotalCount, dt);
  6367. }
  6368. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6369. //public void get_erp_back_handlingaftersalelist()
  6370. //{
  6371. // DataStruct dStruct = GetPostStruct();
  6372. // List<string> lw = new List<string>();
  6373. // string tid = GetPostString("ctid");
  6374. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6375. // string shopname = GetPostString("shopname");
  6376. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6377. // string buyernick = GetPostString("buyer_nick");
  6378. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6379. // string sellermemo = GetPostString("seller_memo");
  6380. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6381. // string orderState = GetPostString("orderState");
  6382. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6383. // string afterState = GetPostString("afterstate");
  6384. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6385. // string date1 = GetPostString("date1");
  6386. // string date2 = GetPostString("date2");
  6387. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6388. // if (dw.Length > 0) lw.Add(dw);
  6389. // string price1 = GetPostString("price1");
  6390. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6391. // string price2 = GetPostString("price2");
  6392. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6393. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6394. // string reason = GetPostString("reason");
  6395. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6396. // string method = GetPostString("method");
  6397. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6398. // string handler = GetPostString("handler");
  6399. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6400. // string handledate1 = GetPostString("handledate1");
  6401. // string handledate2 = GetPostString("handledate2");
  6402. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6403. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6404. // string afterdate1 = GetPostString("afterdate1");
  6405. // string afterdate2 = GetPostString("afterdate2");
  6406. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6407. // if (afterDate.Length > 0) lw.Add(afterDate);
  6408. // string supplier = GetPostString("supplier");
  6409. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6410. // string responsible = GetPostString("responsibleman");
  6411. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6412. // string customer = GetPostString("customer");
  6413. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6414. // string design = GetPostString("design");
  6415. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6416. // string afterMemoType = GetPostString("aftermemotype");
  6417. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6418. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6419. // if (afterState.Length <= 0)
  6420. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6421. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6422. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6423. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6424. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6425. //}
  6426. public void get_erp_aftersaleverifylist()
  6427. {
  6428. DataStruct dStruct = GetPostStruct();
  6429. List<string> lw = new List<string>();
  6430. string tid = GetPostString("ctid");
  6431. if (tid.Length > 0)
  6432. {
  6433. string select_tid = getTidByCtid(tid);
  6434. lw.Add(string.Format("otid='{0}'", select_tid));
  6435. }
  6436. string shopname = GetPostString("shopname");
  6437. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6438. string buyernick = GetPostString("buyer_nick");
  6439. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6440. string sellermemo = GetPostString("seller_memo");
  6441. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6442. string orderState = GetPostString("orderState");
  6443. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6444. //lw.Add(string.Format("IsRefund!={0}", 1));
  6445. string reason = GetPostString("reason");
  6446. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6447. string method = GetPostString("method");
  6448. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6449. string handler = GetPostString("handler");
  6450. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6451. string handledate1 = GetPostString("handledate1");
  6452. string handledate2 = GetPostString("handledate2");
  6453. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6454. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6455. string finish1 = GetPostString("finishdate1");
  6456. string finish2 = GetPostString("finishdate2");
  6457. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6458. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6459. string supplier = GetPostString("supplier");
  6460. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6461. string responsible = GetPostString("responsibleman");
  6462. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6463. string posCode = CurrentUser.UserPost.Post.Code;
  6464. string vstate = GetPostString("vstate");
  6465. if (vstate.Length > 0)
  6466. {
  6467. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6468. }
  6469. if (posCode == "Supplier")
  6470. {
  6471. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6472. lw.Add(string.Format("VerifyState = 0"));
  6473. lw.Add("type = 1");
  6474. lw.Add(string.Format("AfterSaleState={0}", 3));
  6475. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6476. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6477. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6478. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6479. writeGridDataTableJson(dStruct.TotalCount, dt);
  6480. }
  6481. else if (posCode == "logistics")
  6482. {
  6483. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6484. lw.Add(string.Format("VerifyState = 0"));
  6485. lw.Add("type = 2");
  6486. lw.Add(string.Format("AfterSaleState={0}", 3));
  6487. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6488. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6489. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6490. writeGridDataTableJson(dStruct.TotalCount, dt);
  6491. }
  6492. else
  6493. {
  6494. lw.Add(string.Format("(AfterSaleState = 3)"));
  6495. string reasonState = GetPostString("reasonState");
  6496. lw.Add("type = 0");
  6497. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6498. || posCode == "Summarize" || posCode == "Finance")
  6499. {
  6500. if (reasonState == "2")
  6501. {
  6502. lw.Add("VerifyState = 3");
  6503. }
  6504. else if (reasonState == "1")
  6505. {
  6506. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6507. }
  6508. else
  6509. {
  6510. lw.Add("VerifyState in (0,3)");
  6511. }
  6512. //不加条件,可以看全部
  6513. }
  6514. 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")
  6515. {
  6516. int orgid = CurrentUser.UserPost.OrgID;
  6517. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6518. if (string.IsNullOrEmpty(manageOrgId))
  6519. {
  6520. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6521. }
  6522. else
  6523. {
  6524. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6525. }
  6526. if (reasonState == "1")
  6527. {
  6528. lw.Add("VerifyState = 3");
  6529. }
  6530. else if (reasonState == "2")
  6531. {
  6532. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6533. }
  6534. else
  6535. {
  6536. }
  6537. }
  6538. else
  6539. {
  6540. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6541. }
  6542. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6543. //{
  6544. // int org_id = CurrentUser.UserPost.OrgID;
  6545. // lw.Add(string.Format("OrgID={0}", org_id));
  6546. //}
  6547. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6548. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6549. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6550. writeGridDataTableJson(dStruct.TotalCount, dt);
  6551. }
  6552. }
  6553. public void get_erp_finishaftersalelist()
  6554. {
  6555. DataStruct dStruct = GetPostStruct();
  6556. List<string> lw = new List<string>();
  6557. int st = 4;
  6558. string tid = GetPostString("ctid");
  6559. if (tid.Length > 0)
  6560. {
  6561. string select_tid = getTidByCtid(tid);
  6562. lw.Add(string.Format("otid='{0}'", select_tid));
  6563. }
  6564. string shopname = GetPostString("shopname");
  6565. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6566. //lw.Add(string.Format("IsRefund!={0}", 1));
  6567. string reason = GetPostString("reason");
  6568. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6569. string method = GetPostString("method");
  6570. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6571. string buyernick = GetPostString("buyer_nick");
  6572. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6573. string handler = GetPostString("handler");
  6574. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6575. string handledate1 = GetPostString("handledate1");
  6576. string handledate2 = GetPostString("handledate2");
  6577. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6578. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6579. string finish1 = GetPostString("finishdate1");
  6580. string finish2 = GetPostString("finishdate2");
  6581. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6582. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6583. string supplier = GetPostString("supplier");
  6584. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6585. string responsible = GetPostString("responsibleman");
  6586. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6587. string vstate = GetPostString("vstate");
  6588. if (vstate.Length > 0)
  6589. {
  6590. if ("3".Equals(vstate))
  6591. {
  6592. lw.Add(string.Format("IsTem=1"));
  6593. }
  6594. else
  6595. {
  6596. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6597. }
  6598. }
  6599. lw.Add(string.Format("AfterSaleState=4"));
  6600. string code = CurrentUser.UserPost.Post.Code;
  6601. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6602. {
  6603. //不加条件,可以看全部
  6604. }
  6605. else if (code == "Supplier")
  6606. {
  6607. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6608. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6609. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6610. }
  6611. else if (code == "logistics")
  6612. {
  6613. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6614. lw.Add("type = 2");
  6615. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6616. }
  6617. 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")
  6618. {
  6619. int orgid = CurrentUser.UserPost.OrgID;
  6620. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6621. if (string.IsNullOrEmpty(manageOrgIds))
  6622. {
  6623. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6624. }
  6625. else
  6626. {
  6627. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6628. }
  6629. }
  6630. else
  6631. {
  6632. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6633. }
  6634. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6635. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6636. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6637. writeGridDataTableJson(dStruct.TotalCount, dt);
  6638. }
  6639. public void handle_erp_aftersale()
  6640. {
  6641. if (UrlPostParmsCheck("ctid"))
  6642. {
  6643. string eid = GetPostString("ctid");
  6644. string responStr = GetPostString("AfterSaleResponsible");
  6645. if (responStr.Length <= 0)
  6646. {
  6647. returnErrorMsg("售后责任人不能为空");
  6648. return;
  6649. }
  6650. bool isDesign = false;
  6651. double designFree = 0.00;
  6652. int responsibleId = 0;
  6653. CeErpTradeCell entity = null;
  6654. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6655. if (entity != null)
  6656. {
  6657. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6658. string afterMethod = GetPostString("AfterSaleMethod");
  6659. if (isNeedNewOrder == 1)
  6660. {
  6661. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6662. bool ishav = true;
  6663. if (newentity == null)
  6664. {
  6665. newentity = entity.Clone() as CeErpTradeCell;
  6666. ishav = false;
  6667. newentity.ctid = "S_" + entity.ctid;
  6668. newentity.OrderState = 0;
  6669. //唯一标识
  6670. newentity.OrderSn = newentity.ctid;
  6671. string orderSn = dataHelper.getSaleOrderSn();
  6672. if (orderSn != "")
  6673. {
  6674. newentity.OrderSn = orderSn;
  6675. }
  6676. }
  6677. newentity.UpdateTime = DateTime.Now;
  6678. newentity.AfterSaleState = 0;
  6679. newentity.AfterSaleMethod = afterMethod;
  6680. if (!ishav)
  6681. {
  6682. string memo_str = newentity.seller_memo;
  6683. memo_str = memo_str.Replace("(", "(");
  6684. memo_str = memo_str.Replace(")", ")");
  6685. int sIndex = memo_str.IndexOf("(");
  6686. int eIndex = memo_str.IndexOf(")");
  6687. if (sIndex == -1 || eIndex == -1)
  6688. {
  6689. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6690. return;
  6691. }
  6692. string first = memo_str.Substring(0, sIndex + 1);
  6693. string memoCtid = newentity.OrderSn;
  6694. //if (memoCtid.IndexOf("C") != -1)
  6695. //{
  6696. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6697. //if (CIdx.IndexOf("+") != -1)
  6698. //{
  6699. //CIdx = "C" + CIdx.Split('+')[1];
  6700. //}
  6701. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6702. //}
  6703. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6704. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6705. string newMemo = first + memoCtid + last;
  6706. newentity.seller_memo = newMemo;
  6707. newentity.FinishPlaceTime = null;
  6708. newentity.UnusualTag = 0;
  6709. newentity.UnusualCon = "";
  6710. newentity.UnusualTime = null;
  6711. newentity.AfterSaleMemo = "";
  6712. newentity.AfterSaleMethod = afterMethod;
  6713. newentity.AfterSalePreTime = null;
  6714. newentity.AfterSaleReason = "";
  6715. newentity.AfterSaleResponsible = "";
  6716. newentity.AfterSaleState = 0;
  6717. newentity.AfterSaleTime = null;
  6718. newentity.AfterSaleUserId = 0;
  6719. newentity.AfterSaleSupplierState = 0;
  6720. newentity.LastBillWaybillCode = "";
  6721. newentity.LastBillCpCode = "";
  6722. newentity.FinishAfterSaleTime = null;
  6723. newentity.HandleTime = null;
  6724. newentity.IsSF = 0;
  6725. newentity.IsOldCustomer = 0;
  6726. newentity.UrgencyTime = null;
  6727. newentity.ResponsibleUserId = "";
  6728. newentity.IsVerifyToSupplier = false;
  6729. newentity.payment = 0;
  6730. newentity.CheckMemo = "";
  6731. newentity.OutSid = "";
  6732. newentity.CheckOrderTime = null;
  6733. newentity.MemoOpt = 0;
  6734. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6735. }
  6736. newentity.isAfterSaleOrder = 1;
  6737. newentity.IsRefund = 0;
  6738. string receiveMobile = GetPostString("receiver_mobile");
  6739. if (receiveMobile.Length > 0)
  6740. {
  6741. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6742. if (trade != null)
  6743. {
  6744. trade.receiver_name = GetPostString("receiver_name");
  6745. trade.receiver_mobile = receiveMobile;
  6746. trade.receiver_state = GetPostString("receiver_state");
  6747. trade.receiver_city = GetPostString("receiver_city");
  6748. trade.receiver_district = GetPostString("receiver_district");
  6749. trade.receiver_address = GetPostString("receiver_address");
  6750. newentity.IsOffLineOrder = 1;
  6751. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6752. }
  6753. }
  6754. string st = GetPostString("ToState");
  6755. if (st.Length > 0)
  6756. {
  6757. if (newentity.OrderState <= 3)
  6758. {
  6759. newentity.WaitDesignTime = DateTime.Now;
  6760. newentity.StartDesignTime = null;
  6761. newentity.FinishDesignTime = null;
  6762. newentity.OrderState = 3;
  6763. if (st == "下单员")
  6764. {
  6765. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6766. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6767. {
  6768. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6769. }
  6770. }
  6771. else
  6772. {
  6773. newentity.WaitDesignTime = DateTime.Now;
  6774. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6775. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6776. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6777. {
  6778. DataRow user = dt1.Rows[0];
  6779. //找主管
  6780. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6781. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6782. if (dt != null && dt.Rows.Count > 0)
  6783. {
  6784. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6785. newentity.DesignUserId = designMr;
  6786. string key = "aftersale_order_" + designMr;
  6787. if (RedisHelper.HasKey(key))
  6788. {
  6789. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6790. list.Add(newentity.ctid);
  6791. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6792. }
  6793. }
  6794. //账号正常
  6795. if (user["State"].ToString() == "0")
  6796. {
  6797. newentity.DesignUserId = entity.DesignUserId;
  6798. string key = "aftersale_order_" + entity.DesignUserId;
  6799. if (RedisHelper.HasKey(key))
  6800. {
  6801. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6802. list.Add(newentity.ctid);
  6803. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6804. }
  6805. }
  6806. }
  6807. }
  6808. }
  6809. if (entity.IsXianHuo == 1)
  6810. {
  6811. newentity.OrderState = 6;
  6812. entity.FinishPlaceTime = DateTime.Now;
  6813. }
  6814. }
  6815. if (ishav)
  6816. {
  6817. newentity.Update();
  6818. }
  6819. else
  6820. {
  6821. newentity.Create();
  6822. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6823. newCellExtend.ctid = newentity.ctid;
  6824. newCellExtend.orderFrom = 20;
  6825. newCellExtend.orderType = 30;
  6826. if (st == "下单员")
  6827. {
  6828. }
  6829. else
  6830. {
  6831. newCellExtend.ReprintTime = DateTime.Now;
  6832. }
  6833. newCellExtend.Create();
  6834. }
  6835. if (st != "下单员")
  6836. {
  6837. if (entity.DispatchSort == 2)
  6838. {
  6839. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6840. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6841. }
  6842. }
  6843. }
  6844. //处理售后扩展
  6845. string resIdStr = GetPostString("ResponsibleUserId");
  6846. string refundFees = GetPostString("refundFrees");
  6847. int IsComplain = GetPostInt("isComplain");
  6848. int IsBad = GetPostInt("isBad");
  6849. string IsOriginal = GetPostString("isOriginal");
  6850. double diffResultPrice = GetPostDouble("diffResultPrice");
  6851. string textResult = GetPostString("textResult");
  6852. string supplierResponsible = GetPostString("supplierResponsible");
  6853. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6854. if (ceErpTradeAfterSaleExtend == null)
  6855. {
  6856. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6857. ceErpTradeAfterSaleExtend.tid = eid;
  6858. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6859. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6860. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6861. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6862. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6863. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6864. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6865. ceErpTradeAfterSaleExtend.Create();
  6866. }
  6867. else
  6868. {
  6869. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6870. {
  6871. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6872. }
  6873. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6874. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6875. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6876. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6877. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6878. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6879. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6880. ceErpTradeAfterSaleExtend.Update();
  6881. }
  6882. int gysid = GetPostInt("ResponsibleSupId");
  6883. if (entity.AfterSaleUserId == 0)
  6884. {
  6885. entity.AfterSaleUserId = CurrentUser.UserID;
  6886. }
  6887. entity.ResponsibleUserId = resIdStr;
  6888. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6889. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6890. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6891. {
  6892. CeErpTradeResponsible.DelByTid(eid, -1);
  6893. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6894. int backNum = 0;
  6895. if (number != null)
  6896. {
  6897. backNum = number.BackNum;
  6898. }
  6899. char[] separator = { ',' };
  6900. string[] sArray = resIdStr.Split(separator);
  6901. string[] refundFreeList = { };
  6902. if (refundFees.Length > 0)
  6903. {
  6904. refundFreeList = refundFees.Split(separator);
  6905. }
  6906. int index = -1;
  6907. foreach (string i in sArray)
  6908. {
  6909. index++;
  6910. if (i.Length <= 0) continue;
  6911. char[] separator2 = { '_' };
  6912. string idstr = i.Split(separator2)[0];
  6913. string idtype = i.Split(separator2)[1];
  6914. double refudFree = 0;
  6915. if (refundFreeList.Length > 0)
  6916. {
  6917. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6918. }
  6919. if (idtype == "s")
  6920. {
  6921. isDesign = true;
  6922. designFree = refudFree;
  6923. }
  6924. int userId = Convert.ToInt32(idstr);
  6925. int type = 0;
  6926. if (idtype == "g")
  6927. {
  6928. type = 1;
  6929. }
  6930. if (idtype == "w")
  6931. {
  6932. type = 2;
  6933. }
  6934. if (idtype == "t")
  6935. {
  6936. type = 3;
  6937. }
  6938. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6939. if (ceErpTradeResponsible == null)
  6940. {
  6941. ceErpTradeResponsible = new CeErpTradeResponsible();
  6942. ceErpTradeResponsible.tid = eid;
  6943. ceErpTradeResponsible.UserId = userId;
  6944. ceErpTradeResponsible.createdTime = DateTime.Now;
  6945. ceErpTradeResponsible.type = type;
  6946. if (type == 1)
  6947. {
  6948. ceErpTradeResponsible.IsSup = 1;
  6949. }
  6950. if (type == 2)
  6951. {
  6952. ceErpTradeResponsible.IsFlow = 1;
  6953. }
  6954. }
  6955. ceErpTradeResponsible.RefundFee = refudFree;
  6956. ceErpTradeResponsible.VerifyState = 0;
  6957. if (userId == 2125 || idtype == "w")
  6958. {
  6959. ceErpTradeResponsible.VerifyState = 1;
  6960. }
  6961. if (idtype == "w" && userId == 101)
  6962. {
  6963. ceErpTradeResponsible.VerifyState = 0;
  6964. }
  6965. if (ceErpTradeResponsible.ID > 0)
  6966. {
  6967. ceErpTradeResponsible.Update();
  6968. }
  6969. else
  6970. {
  6971. ceErpTradeResponsible.Create();
  6972. }
  6973. if (isDesign)
  6974. {
  6975. responsibleId = ceErpTradeResponsible.ID;
  6976. }
  6977. }
  6978. CeErpTradeResponsible.NumByTid(backNum, eid);
  6979. }
  6980. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6981. if (ceErpTradeCellExtend != null)
  6982. {
  6983. ceErpTradeCellExtend.returnVisit = 0;
  6984. ceErpTradeCellExtend.Update();
  6985. }
  6986. if (entity.HandleTime != null)
  6987. {
  6988. if (entity.AfterSaleState == 1)
  6989. {
  6990. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6991. }
  6992. else
  6993. {
  6994. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6995. }
  6996. }
  6997. else
  6998. {
  6999. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7000. entity.HandleTime = DateTime.Now;
  7001. }
  7002. bool isCompale = false;
  7003. if (entity.AfterSaleState == 5)
  7004. {
  7005. isCompale = true;
  7006. entity.AfterSaleState = 3;
  7007. }
  7008. entity.AfterSaleSupplierState = 0;
  7009. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7010. {
  7011. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7012. }
  7013. string sImgs = GetPostString("img");
  7014. entity.AfterSaleSupplierImg = sImgs;
  7015. entity.supRefundType = GetPostString("supRefundType");
  7016. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7017. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7018. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7019. entity.AfterSaleMemoType = GetPostString("MemoType");
  7020. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7021. {
  7022. //entity.AfterSaleSupplierState = 2;
  7023. }
  7024. string df = GetPostString("DeductFee");
  7025. if (df == "")
  7026. {
  7027. df = "0";
  7028. }
  7029. string rf = GetPostString("RefundFee");
  7030. if (rf == "")
  7031. {
  7032. rf = "0";
  7033. }
  7034. string pm = GetPostString("AfterSalePayment");
  7035. if (pm == "")
  7036. {
  7037. pm = "0";
  7038. }
  7039. entity.AfterSalePayment = Convert.ToDouble(pm);
  7040. entity.DeductFee = Convert.ToDouble(df);
  7041. entity.RefundFee = Convert.ToDouble(rf);
  7042. entity.UpdateTime = DateTime.Now;
  7043. entity.Update();
  7044. string toState = GetPostString("ToState");
  7045. string original = GetPostString("isOriginal");
  7046. ApiVo apiVo = new ApiVo();
  7047. apiVo.orderNumber = entity.ctid;
  7048. apiVo.actionName = "afterDesign";
  7049. apiVo.orderRemarks = entity.AfterSaleMethod;
  7050. apiVo.reasonRemarks = entity.AfterSaleReason;
  7051. apiVo.isDesign = isDesign;
  7052. apiVo.designFree = designFree;
  7053. apiVo.responsibleId = responsibleId;
  7054. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7055. if (toState == "设计师")
  7056. {
  7057. apiVo.isOriginal = Convert.ToBoolean(original);
  7058. }
  7059. designHelper.API_WorkCore(apiVo);//afterDesign
  7060. CeErpMethod methodSql = new CeErpMethod();
  7061. methodSql.con = entity.AfterSaleMethod;
  7062. methodSql.addTime = DateTime.Now;
  7063. methodSql.Create();
  7064. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7065. CeErpMethod.ExecuteNonQuery(delsql);
  7066. if (isCompale)
  7067. {
  7068. aftersale_data_change(entity.ctid);
  7069. }
  7070. returnSuccessMsg("操作成功!");
  7071. return;
  7072. }
  7073. returnErrorMsg("找不到订单记录");
  7074. }
  7075. }
  7076. public void ins_erp_toresponsible()
  7077. {
  7078. if (UrlPostParmsCheck("ctid"))
  7079. {
  7080. string eid = GetPostString("ctid");
  7081. CeErpTradeCell entity = null;
  7082. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7083. if (entity != null)
  7084. {
  7085. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7086. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7087. {
  7088. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7089. return;
  7090. }
  7091. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7092. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7093. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7094. if (entity.AfterSalePreTime == null)
  7095. {
  7096. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7097. {
  7098. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7099. }
  7100. }
  7101. entity.AfterSalePreTime = DateTime.Now;
  7102. //预完成给售后主管审核客户问题直接完成
  7103. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7104. {
  7105. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7106. {
  7107. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7108. }
  7109. }
  7110. ceErpTradeAfterSaleExtend.Update();
  7111. entity.AfterSaleState = 2;
  7112. entity.UpdateTime = DateTime.Now;
  7113. entity.Update();
  7114. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7115. aftersale_data_change(entity.ctid);
  7116. returnSuccessMsg("操作成功!");
  7117. return;
  7118. }
  7119. returnErrorMsg("找不到订单记录");
  7120. }
  7121. }
  7122. public void cancel_erp_aftersaleanddelnew()
  7123. {
  7124. if (UrlPostParmsCheck("ctid"))
  7125. {
  7126. string eid = GetPostString("ctid");
  7127. CeErpTradeCell entity = null;
  7128. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7129. if (entity != null)
  7130. {
  7131. entity.AfterSaleState = 0;
  7132. entity.AfterSaleReason = "";
  7133. entity.AfterSaleMethod = "";
  7134. entity.AfterSaleMemo = "";
  7135. entity.AfterSaleResponsible = "";
  7136. entity.ResponsibleUserId = "";
  7137. entity.DeductFee = 0;
  7138. entity.RefundFee = 0;
  7139. entity.IsArbitrate = 0;
  7140. CeErpTradeResponsible.DelByTid(eid, -1);
  7141. entity.Update();
  7142. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7143. if (after != null)
  7144. {
  7145. if (after.OrderState < 5)
  7146. CeErpTradeCell.DelByCtid("S_" + eid);
  7147. }
  7148. returnSuccessMsg("操作成功!");
  7149. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7150. return;
  7151. }
  7152. returnErrorMsg("找不到订单记录");
  7153. }
  7154. }
  7155. public void get_erp_aftersale_pregather()
  7156. {
  7157. List<string> lw = new List<string>();
  7158. int st = GetInt("st");
  7159. string tid = GetPostString("ctid");
  7160. if (tid.Length > 0)
  7161. {
  7162. string select_tid = getTidByCtid(tid);
  7163. lw.Add(string.Format("tid='{0}'", select_tid));
  7164. }
  7165. string shopname = GetPostString("shopname");
  7166. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7167. string buyernick = GetPostString("buyer_nick");
  7168. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7169. string sellermemo = GetPostString("seller_memo");
  7170. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7171. string orderState = GetPostString("orderState");
  7172. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7173. string reason = GetPostString("reason");
  7174. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7175. string method = GetPostString("method");
  7176. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7177. string handler = GetPostString("handler");
  7178. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7179. string handledate1 = GetPostString("handledate1");
  7180. string handledate2 = GetPostString("handledate2");
  7181. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7182. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7183. string supplier = GetPostString("supplier");
  7184. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7185. string responsible = GetPostString("responsibleman");
  7186. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7187. string customer = GetPostString("customer");
  7188. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7189. string design = GetPostString("design");
  7190. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7191. string afterMemoType = GetPostString("aftermemotype");
  7192. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7193. string afterSaleMemo = GetPostString("afterSaleMemo");
  7194. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7195. string afterresult = GetPostString("afterresult");
  7196. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7197. string poscode = CurrentUser.UserPost.Post.Code;
  7198. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7199. {
  7200. string shopid = CurrentUser.User.pemShop;
  7201. lw.Add(string.Format("shopId in ({0})", shopid));
  7202. }
  7203. var mainwhere = string.Join(" and ", lw.ToArray());
  7204. string ro_json = "";
  7205. string type = GetPostString("gather_type");
  7206. int number = 0;
  7207. if (poscode == "AfterSale")
  7208. {
  7209. //处理中
  7210. if (type == "Handling")
  7211. {
  7212. 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) : ""));
  7213. DataTable dt = null;
  7214. try
  7215. {
  7216. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7217. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7218. }
  7219. catch (Exception e)
  7220. {
  7221. dt = new DataTable();
  7222. }
  7223. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7224. return;
  7225. }
  7226. if (type == "Wait")
  7227. {
  7228. //待处理
  7229. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7230. DataTable dt1 = null;
  7231. try
  7232. {
  7233. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7234. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7235. }
  7236. catch (Exception e)
  7237. {
  7238. dt1 = new DataTable();
  7239. }
  7240. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7241. return;
  7242. }
  7243. if (type == "back")
  7244. {
  7245. //打回
  7246. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7247. DataTable dt2 = null;
  7248. try
  7249. {
  7250. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7251. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7252. }
  7253. catch (Exception e)
  7254. {
  7255. dt2 = new DataTable();
  7256. }
  7257. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7258. return;
  7259. }
  7260. if (type == "preCompletion")
  7261. {
  7262. //预完成
  7263. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7264. DataTable dt3 = null;
  7265. try
  7266. {
  7267. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7268. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7269. }
  7270. catch (Exception e)
  7271. {
  7272. dt3 = new DataTable();
  7273. }
  7274. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7275. return;
  7276. }
  7277. if (type == "documentary")
  7278. {
  7279. //跟单中
  7280. 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) : ""));
  7281. DataTable dt4 = null;
  7282. try
  7283. {
  7284. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7285. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7286. }
  7287. catch (Exception e)
  7288. {
  7289. dt4 = new DataTable();
  7290. }
  7291. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7292. return;
  7293. }
  7294. if (type == "reBack")
  7295. {
  7296. //被打回
  7297. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7298. DataTable dt1 = null;
  7299. try
  7300. {
  7301. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7302. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7303. }
  7304. catch (Exception e)
  7305. {
  7306. dt1 = new DataTable();
  7307. }
  7308. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7309. return;
  7310. }
  7311. }
  7312. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7313. {
  7314. if (type == "puBack")
  7315. {
  7316. //退回
  7317. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7318. DataTable dt = null;
  7319. try
  7320. {
  7321. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7322. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7323. }
  7324. catch (Exception e)
  7325. {
  7326. dt = new DataTable();
  7327. }
  7328. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7329. return;
  7330. }
  7331. if (type == "reBack")
  7332. {
  7333. //打回
  7334. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7335. DataTable dt1 = null;
  7336. try
  7337. {
  7338. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7339. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7340. }
  7341. catch (Exception e)
  7342. {
  7343. dt1 = new DataTable();
  7344. }
  7345. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7346. return;
  7347. }
  7348. if (type == "examEd")
  7349. {
  7350. //已审核
  7351. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7352. DataTable dt2 = null;
  7353. try
  7354. {
  7355. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7356. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7357. }
  7358. catch (Exception e)
  7359. {
  7360. dt2 = new DataTable();
  7361. }
  7362. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7363. return;
  7364. }
  7365. if (type == "waitExam")
  7366. {
  7367. //待审核
  7368. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7369. DataTable dt3 = null;
  7370. try
  7371. {
  7372. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7373. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7374. }
  7375. catch (Exception e)
  7376. {
  7377. dt3 = new DataTable();
  7378. }
  7379. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7380. return;
  7381. }
  7382. if (type == "Handling")
  7383. {
  7384. //处理中
  7385. 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) : ""));
  7386. DataTable dt4 = null;
  7387. try
  7388. {
  7389. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7390. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7391. }
  7392. catch (Exception e)
  7393. {
  7394. dt4 = new DataTable();
  7395. }
  7396. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7397. return;
  7398. }
  7399. if (type == "Wait")
  7400. {
  7401. //待处理
  7402. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7403. DataTable dt5 = null;
  7404. try
  7405. {
  7406. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7407. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7408. }
  7409. catch (Exception e)
  7410. {
  7411. dt5 = new DataTable();
  7412. }
  7413. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7414. return;
  7415. }
  7416. if (type == "documentary")
  7417. {
  7418. //跟单中
  7419. 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) : ""));
  7420. DataTable dt6 = null;
  7421. try
  7422. {
  7423. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7424. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7425. }
  7426. catch (Exception e)
  7427. {
  7428. dt6 = new DataTable();
  7429. }
  7430. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7431. return;
  7432. }
  7433. }
  7434. returnSuccess(ro_json);
  7435. }
  7436. public void end_erp_aftersale()
  7437. {
  7438. if (UrlPostParmsCheck("ctid"))
  7439. {
  7440. string eid = GetPostString("ctid");
  7441. CeErpTradeCell entity = null;
  7442. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7443. if (entity != null)
  7444. {
  7445. string stype = GetPostString("stype");
  7446. string typeStr = stype;
  7447. entity.AfterSaleState = 4;
  7448. entity.FinishAfterSaleTime = DateTime.Now;
  7449. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7450. entity.Update();
  7451. ApiVo apiVo = new ApiVo();
  7452. apiVo.orderNumber = entity.ctid;
  7453. apiVo.actionName = "afterOver";
  7454. designHelper.API_WorkCore(apiVo); //afterOver
  7455. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7456. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7457. CeErpSukuraData.createInfo(entity.ctid, 8);
  7458. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7459. returnSuccessMsg("操作成功!");
  7460. return;
  7461. }
  7462. returnErrorMsg("找不到订单记录");
  7463. }
  7464. }
  7465. public void ins_erp_finishaftersale()
  7466. {
  7467. if (UrlPostParmsCheck("id"))
  7468. {
  7469. string eid = GetPostString("id");
  7470. CeErpTradeResponsible entity = null;
  7471. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7472. if (entity != null)
  7473. {
  7474. entity.VerifyState = 1;
  7475. entity.VerifyTime = DateTime.Now;
  7476. entity.Update();
  7477. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7478. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7479. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7480. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7481. if (dt.Rows.Count <= 0)
  7482. {
  7483. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7484. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7485. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7486. CeErpSukuraData.createInfo(entity.tid, 8);
  7487. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7488. {
  7489. CeErpDesignerBill.Del(entity.tid);
  7490. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7491. }
  7492. }
  7493. returnSuccessMsg("操作成功!");
  7494. return;
  7495. }
  7496. returnErrorMsg("找不到订单记录");
  7497. }
  7498. }
  7499. public void upd_erp_arbitrateaftersale()
  7500. {
  7501. if (UrlPostParmsCheck("id"))
  7502. {
  7503. string eid = GetPostString("id");
  7504. CeErpTradeResponsible entity = null;
  7505. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7506. if (entity != null)
  7507. {
  7508. entity.IsArbitrate = 1;
  7509. entity.ArbitradeMemo = GetPostString("reason");
  7510. entity.VerifyState = 2;
  7511. entity.Update();
  7512. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7513. if (tradecell != null)
  7514. {
  7515. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7516. tradecell.IsArbitrate = 1;
  7517. tradecell.Update();
  7518. }
  7519. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7520. returnSuccessMsg("操作成功!");
  7521. return;
  7522. }
  7523. returnErrorMsg("找不到订单记录");
  7524. }
  7525. }
  7526. public void upd_erp_backaftersale()
  7527. {
  7528. if (UrlPostParmsCheck("tid"))
  7529. {
  7530. string eid = GetPostString("tid");
  7531. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7532. int backNum = 0;
  7533. if (number != null)
  7534. {
  7535. backNum = number.BackNum;
  7536. }
  7537. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7538. CeErpTradeCell entity = null;
  7539. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7540. if (entity != null)
  7541. {
  7542. entity.AfterSaleBackReason = GetPostString("backreason");
  7543. entity.AfterSaleState = 1;
  7544. entity.AfterSaleSupplierState = 0;
  7545. entity.UpdateTime = DateTime.Now;
  7546. entity.Update();
  7547. returnSuccessMsg("操作成功!");
  7548. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7549. return;
  7550. }
  7551. returnErrorMsg("找不到订单记录");
  7552. }
  7553. }
  7554. public void get_erp_supplieraftersalelist()
  7555. {
  7556. DataStruct dStruct = GetPostStruct();
  7557. List<string> lw = new List<string>();
  7558. string tid = GetPostString("ctid");
  7559. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7560. string shopname = GetPostString("shopname");
  7561. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7562. string buyernick = GetPostString("buyer_nick");
  7563. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7564. string sellermemo = GetPostString("seller_memo");
  7565. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7566. string orderState = GetPostString("orderState");
  7567. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7568. string afterState = GetPostString("afterstate");
  7569. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7570. string date1 = GetPostString("date1");
  7571. string date2 = GetPostString("date2");
  7572. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7573. if (dw.Length > 0) lw.Add(dw);
  7574. string price1 = GetPostString("price1");
  7575. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7576. string price2 = GetPostString("price2");
  7577. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7578. string reason = GetPostString("reason");
  7579. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7580. string method = GetPostString("method");
  7581. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7582. string handledate1 = GetPostString("handledate1");
  7583. string handledate2 = GetPostString("handledate2");
  7584. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7585. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7586. string handler = GetPostString("handler");
  7587. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7588. string afterdate1 = GetPostString("afterdate1");
  7589. string afterdate2 = GetPostString("afterdate2");
  7590. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7591. if (afterDate.Length > 0) lw.Add(afterDate);
  7592. string customer = GetPostString("customer");
  7593. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7594. string design = GetPostString("design");
  7595. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7596. string afterMemoType = GetPostString("aftermemotype");
  7597. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7598. string vstate = GetPostString("vstate");
  7599. if (vstate.Length > 0)
  7600. {
  7601. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7602. }
  7603. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7604. string supplier = GetPostString("supplier");
  7605. int supid = commonHelper.getSupplierIDByName(supplier);
  7606. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7607. string posCode = CurrentUser.UserPost.Post.Code;
  7608. if (posCode == "Supplier")
  7609. {
  7610. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7611. }
  7612. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7613. {
  7614. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7615. }
  7616. else
  7617. {
  7618. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7619. }
  7620. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7621. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7622. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7623. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7624. writeGridDataTableJson(dStruct.TotalCount, dt);
  7625. }
  7626. public void upd_erp_supverifyaftersale()
  7627. {
  7628. if (UrlPostParmsCheck("id"))
  7629. {
  7630. string id = GetPostString("id");
  7631. int st = GetPostInt("afterstate");
  7632. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7633. CeErpTradeCell entity = null;
  7634. if (ceErpTradeResponsible != null)
  7635. {
  7636. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7637. }
  7638. string afmemo = GetPostString("supmemo");
  7639. string image = GetPostString("image");
  7640. if (entity != null)
  7641. {
  7642. entity.AfterSaleSupplierState = st;
  7643. entity.AfterSaleSupplierMemo = afmemo;
  7644. if (st == 1)
  7645. {
  7646. ceErpTradeResponsible.VerifyState = 1;
  7647. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7648. ceErpTradeResponsible.Update();
  7649. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7650. if (isAll)
  7651. {
  7652. entity.AfterSaleState = 4;
  7653. entity.FinishAfterSaleTime = DateTime.Now;
  7654. }
  7655. }
  7656. else
  7657. {
  7658. CeErpTradeResponsible.dateByTid(entity.ctid);
  7659. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7660. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7661. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7662. if (num <= 1)
  7663. {
  7664. entity.AfterSaleState = 1;
  7665. }
  7666. else
  7667. {
  7668. entity.AfterSaleState = 5;
  7669. }
  7670. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7671. if (ceErpTradeAfterSaleExtend != null)
  7672. {
  7673. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7674. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7675. ceErpTradeAfterSaleExtend.Update();
  7676. }
  7677. else
  7678. {
  7679. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7680. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7681. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7682. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7683. ceErpTradeAfterSaleExtend.Create();
  7684. }
  7685. }
  7686. if (entity.AfterSaleState == 4)
  7687. {
  7688. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7689. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7690. {
  7691. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7692. }
  7693. ApiVo apiVo = new ApiVo();
  7694. apiVo.orderNumber = entity.ctid;
  7695. apiVo.actionName = "afterOver";
  7696. designHelper.API_WorkCore(apiVo); //afterOver
  7697. }
  7698. entity.UpdateTime = DateTime.Now;
  7699. entity.Update();
  7700. returnSuccessMsg("操作成功!");
  7701. CeErpSukuraData.createInfo(entity.ctid, 8);
  7702. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7703. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7704. return;
  7705. }
  7706. returnErrorMsg("找不到订单记录");
  7707. }
  7708. }
  7709. public void upd_erp_masteraftersale()
  7710. {
  7711. if (UrlPostParmsCheck("id"))
  7712. {
  7713. string id = GetPostString("id");
  7714. int st = GetPostInt("afterstate");
  7715. string afmemo = GetPostString("supmemo");
  7716. string image = GetPostString("image");
  7717. string textResult = GetPostString("textResult");
  7718. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7719. if (ceErpTradeResponsible != null)
  7720. {
  7721. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7722. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7723. ceErpTradeResponsible.Update();
  7724. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7725. if (entity != null)
  7726. {
  7727. entity.AfterSaleSupplierState = st;
  7728. entity.AfterSaleSupplierMemo = afmemo;
  7729. if (st == 1)
  7730. {
  7731. }
  7732. else
  7733. {
  7734. CeErpTradeResponsible.dateByTid(entity.ctid);
  7735. //退回到售后
  7736. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7737. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7738. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7739. if (num <= 1)
  7740. {
  7741. entity.AfterSaleState = 1;
  7742. }
  7743. else
  7744. {
  7745. entity.AfterSaleState = 5;
  7746. }
  7747. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7748. if (ceErpTradeAfterSaleExtend != null)
  7749. {
  7750. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7751. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7752. ceErpTradeAfterSaleExtend.Update();
  7753. }
  7754. else
  7755. {
  7756. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7757. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7758. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7759. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7760. ceErpTradeAfterSaleExtend.Create();
  7761. }
  7762. }
  7763. entity.UpdateTime = DateTime.Now;
  7764. entity.Update();
  7765. returnSuccessMsg("操作成功!");
  7766. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7767. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7768. return;
  7769. }
  7770. }
  7771. returnErrorMsg("找不到订单记录");
  7772. }
  7773. }
  7774. public void upd_erp_personaftersale()
  7775. {
  7776. if (UrlPostParmsCheck("id"))
  7777. {
  7778. //林小连
  7779. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7780. {
  7781. upd_erp_masteraftersale();
  7782. return;
  7783. }
  7784. string id = GetPostString("id");
  7785. int st = GetPostInt("afterstate");
  7786. string afmemo = GetPostString("supmemo");
  7787. string image = GetPostString("image");
  7788. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7789. if (ceErpTradeResponsible != null)
  7790. {
  7791. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7792. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7793. ceErpTradeResponsible.Update();
  7794. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7795. if (entity != null)
  7796. {
  7797. entity.AfterSaleSupplierMemo = afmemo;
  7798. entity.AfterSaleSupplierState = st;
  7799. if (st == 1)
  7800. {
  7801. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7802. if (isAll)
  7803. {
  7804. entity.AfterSaleState = 4;
  7805. entity.FinishAfterSaleTime = DateTime.Now;
  7806. }
  7807. }
  7808. else
  7809. {
  7810. CeErpTradeResponsible.dateByTid(entity.ctid);
  7811. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7812. if (ceErpTradeAfterSaleExtend != null)
  7813. {
  7814. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7815. ceErpTradeAfterSaleExtend.Update();
  7816. }
  7817. else
  7818. {
  7819. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7820. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7821. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7822. ceErpTradeAfterSaleExtend.Create();
  7823. }
  7824. //退回到主管
  7825. //entity.AfterSaleState = 2;
  7826. }
  7827. if (entity.AfterSaleState == 4)
  7828. {
  7829. ApiVo apiVo = new ApiVo();
  7830. apiVo.orderNumber = entity.ctid;
  7831. apiVo.actionName = "afterOver";
  7832. designHelper.API_WorkCore(apiVo); //afterOver
  7833. }
  7834. entity.UpdateTime = DateTime.Now;
  7835. entity.Update();
  7836. returnSuccessMsg("操作成功!");
  7837. CeErpSukuraData.createInfo(entity.ctid, 8);
  7838. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7839. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7840. return;
  7841. }
  7842. }
  7843. returnErrorMsg("找不到订单记录");
  7844. }
  7845. }
  7846. public void set_erp_supplierrefundtag()
  7847. {
  7848. if (UrlPostParmsCheck("ctid"))
  7849. {
  7850. string eid = GetPostString("ctid");
  7851. CeErpTradeCell entity = null;
  7852. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7853. if (entity != null)
  7854. {
  7855. entity.IsSupplierRefund = GetPostInt("tag");
  7856. entity.Update();
  7857. returnSuccessMsg("操作成功!");
  7858. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7859. return;
  7860. }
  7861. returnErrorMsg("找不到订单记录");
  7862. }
  7863. }
  7864. public void get_erp_refundlist()
  7865. {
  7866. DataStruct dStruct = GetPostStruct();
  7867. List<string> lw = new List<string>();
  7868. string tid = GetPostString("tid");
  7869. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7870. //string rid = GetPostString("refund_id");
  7871. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7872. string shopname = GetPostString("shopname");
  7873. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7874. string buyernick = GetPostString("buyer_nick");
  7875. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7876. string customer = GetPostString("customer");
  7877. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7878. string design = GetPostString("design");
  7879. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7880. string sellermemo = GetPostString("seller_memo");
  7881. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7882. //string date1 = GetPostString("date1");
  7883. //string date2 = GetPostString("date2");
  7884. //string dateType = GetPostString("dateType");
  7885. //if (dateType.Length > 0)
  7886. //{
  7887. // if (dateType == "1001") dateType = "0";
  7888. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7889. // if (searchDT.Count == 2)
  7890. // {
  7891. // date1 = searchDT[0].ToString();
  7892. // date2 = searchDT[1].ToString();
  7893. // }
  7894. //}
  7895. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7896. //if (dw.Length > 0) lw.Add(dw);
  7897. string redate1 = GetPostString("refunddate1");
  7898. string redate2 = GetPostString("refunddate2");
  7899. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7900. if (dwdate.Length > 0) lw.Add(dwdate);
  7901. string price1 = GetPostString("price1");
  7902. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7903. string price2 = GetPostString("price2");
  7904. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7905. string ispartrefund = GetPostString("ispartrefund");
  7906. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7907. string refundState = GetPostString("refundvstate");
  7908. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7909. int st = GetInt("st");
  7910. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7911. {
  7912. string responsible = GetPostString("responsibleman");
  7913. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7914. lw.Add(string.Format("RefundState>={0}", st));
  7915. string code = CurrentUser.UserPost.Post.Code;
  7916. if (code == "CustomerService")
  7917. {
  7918. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7919. }
  7920. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7921. {
  7922. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7923. }
  7924. else if (code == "Place" || code == "PlaceMr")
  7925. {
  7926. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7927. }
  7928. dStruct.Order = "RefundState asc,created desc";
  7929. }
  7930. else if (st == 10)
  7931. {
  7932. string responsible = GetPostString("responsibleman");
  7933. if (responsible == "空白")
  7934. {
  7935. lw.Add(string.Format("ResponsibleUserName = ''"));
  7936. }
  7937. else if (responsible.Length > 0)
  7938. {
  7939. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7940. }
  7941. lw.Add(string.Format("RefundState>=0"));
  7942. dStruct.Order = "created desc";
  7943. }
  7944. else
  7945. {
  7946. string responsible = GetPostString("responsibleman");
  7947. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7948. lw.Add(string.Format("RefundState={0}", st));
  7949. dStruct.Order = "created desc";
  7950. }
  7951. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7952. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7953. dt.Columns.Add("refund_fees");
  7954. foreach (DataRow dr in dt.Rows)
  7955. {
  7956. String status = dr["status"].ToString();
  7957. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7958. {
  7959. dr["refund_fees"] = dr["refund_fee"];
  7960. }
  7961. else
  7962. {
  7963. dr["refund_fees"] = "0.0";
  7964. }
  7965. }
  7966. writeGridDataTableJson(dStruct.TotalCount, dt);
  7967. }
  7968. public void get_erp_refunddesignlist()
  7969. {
  7970. DataStruct dStruct = GetPostStruct();
  7971. List<string> lw = new List<string>();
  7972. string tid = GetPostString("tid");
  7973. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7974. string shopname = GetPostString("shopname");
  7975. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7976. string buyernick = GetPostString("buyer_nick");
  7977. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7978. string customer = GetPostString("customer");
  7979. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7980. string design = GetPostString("design");
  7981. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7982. string sellermemo = GetPostString("seller_memo");
  7983. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7984. string redate1 = GetPostString("refunddate1");
  7985. string redate2 = GetPostString("refunddate2");
  7986. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7987. if (dwdate.Length > 0) lw.Add(dwdate);
  7988. string price1 = GetPostString("price1");
  7989. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7990. string price2 = GetPostString("price2");
  7991. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7992. string ispartrefund = GetPostString("ispartrefund");
  7993. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7994. string designerorg = GetPostString("designerorg");
  7995. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7996. string refundState = GetPostString("refundState");
  7997. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7998. int myOrgid = CurrentUser.UserPost.OrgID;
  7999. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8000. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8001. {
  8002. if (CurrentUser.User.TeamIds.Length > 0)
  8003. {
  8004. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8005. }
  8006. else
  8007. {
  8008. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8009. }
  8010. }
  8011. else if ("SysAdmin".Equals(myOrgCode))
  8012. {
  8013. }
  8014. else
  8015. {
  8016. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8017. {
  8018. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8019. }
  8020. else
  8021. {
  8022. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8023. }
  8024. }
  8025. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8026. dStruct.Order = "created desc";
  8027. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8028. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8029. dt.Columns.Add("refund_fees");
  8030. foreach (DataRow dr in dt.Rows)
  8031. {
  8032. String status = dr["status"].ToString();
  8033. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8034. {
  8035. dr["refund_fees"] = dr["refund_fee"];
  8036. }
  8037. else
  8038. {
  8039. dr["refund_fees"] = "0.0";
  8040. }
  8041. }
  8042. writeGridDataTableJson(dStruct.TotalCount, dt);
  8043. }
  8044. public void handle_erp_refundtag()
  8045. {
  8046. if (UrlPostParmsCheck("refund_id"))
  8047. {
  8048. string eid = GetPostString("refund_id");
  8049. string respMan = GetPostString("ResponsibleName");
  8050. if (respMan.Length <= 0)
  8051. {
  8052. returnErrorMsg("责任人不能为空");
  8053. return;
  8054. }
  8055. CeErpTradeRefund entity = null;
  8056. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8057. if (entity != null)
  8058. {
  8059. entity.ResponsibleUserName = respMan;
  8060. string userid = GetPostString("ResponsibleUserId");
  8061. if (userid.Length > 0)
  8062. {
  8063. entity.ResponsibleUserId = userid;
  8064. }
  8065. entity.Memo = GetPostString("Memo");
  8066. if (respMan.IndexOf("客服") != -1 ||
  8067. respMan.IndexOf("设计师") != -1 ||
  8068. respMan.IndexOf("下单员") != -1)
  8069. {
  8070. entity.RefundState = 2;
  8071. }
  8072. else
  8073. {
  8074. entity.RefundState = 3;
  8075. }
  8076. entity.modified = DateTime.Now;
  8077. entity.Update();
  8078. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8079. returnSuccessMsg("操作成功!");
  8080. return;
  8081. }
  8082. returnErrorMsg("找不到订单记录");
  8083. }
  8084. }
  8085. public void handle_erp_designrefundtag()
  8086. {
  8087. if (UrlPostParmsCheck("refund_id"))
  8088. {
  8089. string eid = GetPostString("refund_id");
  8090. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8091. if (ceErpTradeCellExtend == null)
  8092. {
  8093. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8094. ceErpTradeCellExtend.ctid = eid;
  8095. }
  8096. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8097. if (ceErpTradeCellExtend.ID > 0)
  8098. {
  8099. ceErpTradeCellExtend.Update();
  8100. }
  8101. else
  8102. {
  8103. ceErpTradeCellExtend.Create();
  8104. }
  8105. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8106. returnSuccessMsg("操作成功!");
  8107. return;
  8108. }
  8109. returnErrorMsg("找不到订单记录");
  8110. }
  8111. public void upd_erp_refundverify()
  8112. {
  8113. if (UrlPostParmsCheck("refund_id"))
  8114. {
  8115. string eid = GetPostString("refund_id");
  8116. CeErpTradeRefund entity = null;
  8117. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8118. if (entity != null)
  8119. {
  8120. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8121. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8122. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8123. {
  8124. entity.RefundState = 2;
  8125. }
  8126. else
  8127. {
  8128. entity.RefundState = 3;
  8129. }
  8130. entity.Update();
  8131. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8132. returnSuccessMsg("操作成功!");
  8133. return;
  8134. }
  8135. returnErrorMsg("找不到订单记录");
  8136. }
  8137. }
  8138. public void upd_erp_refundapprove()
  8139. {
  8140. if (UrlPostParmsCheck("refund_id"))
  8141. {
  8142. string eid = GetPostString("refund_id");
  8143. CeErpTradeRefund entity = null;
  8144. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8145. if (entity != null)
  8146. {
  8147. int apr = GetPostInt("approve");
  8148. if (apr == 0)
  8149. {
  8150. entity.RefundState = 1;
  8151. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8152. }
  8153. else if (apr == 1)
  8154. {
  8155. entity.RefundState = 3;
  8156. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8157. }
  8158. entity.modified = DateTime.Now;
  8159. entity.Update();
  8160. returnSuccessMsg("操作成功!");
  8161. return;
  8162. }
  8163. returnErrorMsg("找不到订单记录");
  8164. }
  8165. }
  8166. public void get_erp_billlist()
  8167. {
  8168. DataStruct dStruct = GetPostStruct();
  8169. List<string> lw = new List<string>();
  8170. string title = GetPostString("title");
  8171. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8172. string tid = GetPostString("tid");
  8173. string tids = GetPostString("tids");
  8174. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8175. if (tids.Length > 0)
  8176. {
  8177. tids = "'" + tids + "'";
  8178. tids = tids.Replace(",", "','");
  8179. lw.Add(string.Format("tid in ({0})", tids));
  8180. }
  8181. string shopname = GetPostString("shopname");
  8182. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8183. string buyernick = GetPostString("buyer_nick");
  8184. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8185. string customer = GetPostString("customer");
  8186. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8187. string date1 = GetPostString("date1");
  8188. string date2 = GetPostString("date2");
  8189. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8190. if (dw.Length > 0) lw.Add(dw);
  8191. string price1 = GetPostString("price1");
  8192. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8193. string price2 = GetPostString("price2");
  8194. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8195. string returndate1 = GetPostString("returndate1");
  8196. string returndate2 = GetPostString("returndate2");
  8197. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8198. if (dw1.Length > 0) lw.Add(dw1);
  8199. string billtype = GetPostString("billtype");
  8200. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8201. string billstate = GetPostString("billstate");
  8202. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8203. string usershop = CurrentUser.User.pemShop;
  8204. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8205. dStruct.Order = "createTime desc";
  8206. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8207. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8208. //foreach (DataRow dr in dt.Rows)
  8209. //{
  8210. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8211. //}
  8212. writeGridDataTableJson(dStruct.TotalCount, dt);
  8213. }
  8214. public void modify_erp_billinfo()
  8215. {
  8216. if (UrlPostParmsCheck("ID"))
  8217. {
  8218. string eid = GetPostString("ID");
  8219. CeErpBill bill_entity = null;
  8220. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8221. if (bill_entity != null)
  8222. {
  8223. bill_entity.tid = GetPostString("tid");
  8224. bill_entity.title = GetPostString("title");
  8225. bill_entity.tax = GetPostString("tax");
  8226. bill_entity.bank = GetPostString("bank");
  8227. bill_entity.bankac = GetPostString("bankac");
  8228. bill_entity.address = GetPostString("address");
  8229. bill_entity.phone = GetPostString("phone");
  8230. bill_entity.price = GetPostString("price");
  8231. bill_entity.productId = GetPostInt("ProductName");
  8232. bill_entity.num = GetPostInt("num");
  8233. bill_entity.unit = GetPostString("unit");
  8234. bill_entity.type = GetPostString("type");
  8235. bill_entity.sendType = GetPostString("SendType");
  8236. bill_entity.email = GetPostString("email");
  8237. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8238. bill_entity.shopName = GetPostString("ShopName");
  8239. bill_entity.applymemo = GetPostString("applymemo");
  8240. bill_entity.modifyTime = DateTime.Now;
  8241. bill_entity.createTime = DateTime.Now;
  8242. bill_entity.state = 0;
  8243. bill_entity.Update();
  8244. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8245. returnSuccessMsg("发票修改成功!");
  8246. return;
  8247. }
  8248. returnErrorMsg("找不到对应记录");
  8249. }
  8250. }
  8251. public void set_erp_invoicing()
  8252. {
  8253. if (UrlPostParmsCheck("id"))
  8254. {
  8255. try
  8256. {
  8257. string eid = GetPostString("id");
  8258. CeErpBill bill_entity = null;
  8259. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8260. if (bill_entity != null)
  8261. {
  8262. int ComId = GetPostInt("ComId");
  8263. //string memo = GetPostString("Memo");
  8264. int allInfo = GetPostInt("allinfo");
  8265. string clert = CurrentUser.User.Name;
  8266. //string detailValue = GetPostString("detailvalue");
  8267. string billId = bill_entity.billOrderId;
  8268. string[] billIdList = billId.Split(',');
  8269. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8270. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8271. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8272. {
  8273. billCount += 1;
  8274. }
  8275. if (billId.Length <= 0 || billIdList.Length != billCount)
  8276. {
  8277. bill_entity.billOrderId = "";
  8278. string prebill = "ltb";
  8279. for (int idx = 1; idx <= billCount; idx++)
  8280. {
  8281. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8282. string billoid = prebill + idx + dtstr;
  8283. bill_entity.billOrderId += billoid;
  8284. if (idx < billCount)
  8285. {
  8286. bill_entity.billOrderId += ",";
  8287. }
  8288. }
  8289. }
  8290. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8291. if (bill_entity.state == 5)
  8292. {
  8293. string errMsg = bill_entity.failerror;
  8294. string[] errlist = errMsg.Split('|');
  8295. string[] errTags = new string[errlist.Length];
  8296. for (int itag = 0; itag < errlist.Length; itag++)
  8297. {
  8298. if (errlist[itag].Length <= 0) continue;
  8299. errTags[itag] = errlist[itag].Split('&')[0];
  8300. }
  8301. for (int iii = 0; iii < errTags.Length; iii++)
  8302. {
  8303. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8304. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8305. if (billOrderList.Length >= erroBillOrderTag)
  8306. {
  8307. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8308. if (needModifyBillId.Length <= 19)
  8309. {
  8310. needModifyBillId = needModifyBillId + "1";
  8311. }
  8312. else
  8313. {
  8314. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8315. last = last + 1;
  8316. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8317. }
  8318. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8319. }
  8320. }
  8321. }
  8322. bool isHaveBillSucces = false;
  8323. string totalRes = "";
  8324. bill_entity.failerror = "";
  8325. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8326. {
  8327. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8328. totalRes += res;
  8329. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8330. {
  8331. isHaveBillSucces = true;
  8332. bill_entity.comId = ComId;
  8333. bill_entity.state = 1;
  8334. bill_entity.executeTime = DateTime.Now;
  8335. bill_entity.executeUser = clert;
  8336. }
  8337. else
  8338. {
  8339. bill_entity.state = 5;
  8340. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8341. }
  8342. }
  8343. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8344. bill_entity.Update();
  8345. if (isHaveBillSucces)
  8346. {
  8347. StringBuilder sql = new StringBuilder();
  8348. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8349. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8350. }
  8351. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8352. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8353. {
  8354. returnErrorMsg("开票失败");
  8355. }
  8356. else
  8357. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8358. return;
  8359. }
  8360. returnErrorMsg("找不到对应记录");
  8361. }
  8362. catch (Exception ex)
  8363. {
  8364. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8365. returnErrorMsg("操作失败");
  8366. }
  8367. }
  8368. }
  8369. public void get_erp_invoicing_back()
  8370. {
  8371. if (UrlPostParmsCheck("id"))
  8372. {
  8373. try
  8374. {
  8375. string id = GetPostString("id");
  8376. CeErpBill entiy = CeErpBill.Get(id);
  8377. if (entiy != null)
  8378. {
  8379. if (entiy.state == 0)
  8380. {
  8381. returnErrorMsg("发票还未开具");
  8382. return;
  8383. }
  8384. string[] billOrderList = entiy.billOrderId.Split(',');
  8385. int iTag = 0;
  8386. entiy.fplsh = "";
  8387. entiy.fpdm = "";
  8388. entiy.fphm = "";
  8389. foreach (string billOrderId in billOrderList)
  8390. {
  8391. iTag++;
  8392. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8393. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8394. {
  8395. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8396. try
  8397. {
  8398. Invoicing_get_response_Obj iObj = null;
  8399. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8400. if (iObj != null)
  8401. {
  8402. entiy.state = 2;
  8403. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8404. entiy.fpdm += iObj.list[0].c_fpdm;
  8405. entiy.fphm += iObj.list[0].c_fphm;
  8406. if (iTag < billOrderList.Length)
  8407. {
  8408. entiy.fplsh += ",";
  8409. entiy.fpdm += ",";
  8410. entiy.fphm += ",";
  8411. }
  8412. entiy.Update();
  8413. }
  8414. StringBuilder sql = new StringBuilder();
  8415. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8416. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8417. returnSuccessMsg("开票成功");
  8418. }
  8419. catch (Exception ex)
  8420. {
  8421. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8422. }
  8423. return;
  8424. }
  8425. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8426. {
  8427. var res_obj = new
  8428. {
  8429. data = "开票中"
  8430. };
  8431. string ro_json = JsonConvert.SerializeObject(res_obj);
  8432. returnSuccess(ro_json);
  8433. return;
  8434. }
  8435. else
  8436. {
  8437. int eidx = res.IndexOf("c_resultmsg");
  8438. int lidx = res.IndexOf("c_status");
  8439. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8440. entiy.state = 5;
  8441. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8442. entiy.Update();
  8443. returnErrorMsg("开票失败");
  8444. return;
  8445. }
  8446. }
  8447. }
  8448. }
  8449. catch (Exception ex)
  8450. {
  8451. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8452. }
  8453. return;
  8454. }
  8455. }
  8456. public void get_erp_invoicing()
  8457. {
  8458. if (UrlPostParmsCheck("id"))
  8459. {
  8460. try
  8461. {
  8462. string id = GetPostString("id");
  8463. CeErpBill entiy = CeErpBill.Get(id);
  8464. if (entiy != null)
  8465. {
  8466. if (entiy.state == 0)
  8467. {
  8468. returnErrorMsg("发票还未开具");
  8469. return;
  8470. }
  8471. if (entiy.sendType == "纸质发票")
  8472. {
  8473. if (entiy.img.Length <= 0)
  8474. {
  8475. returnErrorMsg("查无纸质发票");
  8476. return;
  8477. }
  8478. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8479. returnSuccess(returnres);
  8480. return;
  8481. }
  8482. string[] billOrderList = entiy.billOrderId.Split(',');
  8483. int iTag = 0;
  8484. string fpUrl = "";
  8485. entiy.fplsh = "";
  8486. entiy.fpdm = "";
  8487. entiy.fphm = "";
  8488. foreach (string billOrderId in billOrderList)
  8489. {
  8490. iTag++;
  8491. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8492. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8493. {
  8494. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8495. Invoicing_get_response_Obj iObj = null;
  8496. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8497. if (iObj != null)
  8498. {
  8499. //entiy.state = 2;
  8500. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8501. entiy.fpdm += iObj.list[0].c_fpdm;
  8502. entiy.fphm += iObj.list[0].c_fphm;
  8503. if (iTag < billOrderList.Length)
  8504. {
  8505. entiy.fplsh += ",";
  8506. entiy.fpdm += ",";
  8507. entiy.fphm += ",";
  8508. }
  8509. entiy.Update();
  8510. fpUrl += iObj.list[0].c_url + ",";
  8511. }
  8512. //returnSuccess(res);
  8513. StringBuilder sql = new StringBuilder();
  8514. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8515. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8516. }
  8517. else
  8518. {
  8519. int eidx = res.IndexOf("c_resultmsg");
  8520. //int lidx = res.IndexOf("c_status");
  8521. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8522. //开票失败
  8523. entiy.state = 5;
  8524. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8525. entiy.Update();
  8526. returnErrorMsg("开票失败");
  8527. return;
  8528. }
  8529. }
  8530. var returnObj = new
  8531. {
  8532. data = fpUrl
  8533. };
  8534. string ro_json = JsonConvert.SerializeObject(returnObj);
  8535. returnSuccess(ro_json);
  8536. }
  8537. }
  8538. catch (Exception ex)
  8539. {
  8540. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8541. }
  8542. return;
  8543. }
  8544. }
  8545. public void save_erp_billimg()
  8546. {
  8547. if (UrlPostParmsCheck("id"))
  8548. {
  8549. string eid = GetPostString("id");
  8550. CeErpBill bill_entity = null;
  8551. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8552. if (bill_entity != null)
  8553. {
  8554. bill_entity.img = GetPostString("img");
  8555. bill_entity.executeTime = DateTime.Now;
  8556. bill_entity.state = 2;
  8557. bill_entity.Update();
  8558. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8559. returnSuccessMsg("保存成功");
  8560. }
  8561. return;
  8562. }
  8563. }
  8564. public void upd_erp_billreturnback()
  8565. {
  8566. if (UrlPostParmsCheck("id"))
  8567. {
  8568. int eid = GetPostInt("id");
  8569. CeErpBill bill_entity = null;
  8570. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8571. if (bill_entity != null)
  8572. {
  8573. bill_entity.state = 3;
  8574. bill_entity.returnReason = GetPostString("reason");
  8575. bill_entity.Update();
  8576. returnSuccessMsg("驳回成功!");
  8577. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8578. }
  8579. return;
  8580. }
  8581. }
  8582. public void cancel_erp_bill()
  8583. {
  8584. if (UrlPostParmsCheck("id"))
  8585. {
  8586. int eid = GetPostInt("id");
  8587. int detailValue = GetPostInt("detailvalue");
  8588. CeErpBill bill_entity = null;
  8589. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8590. string cres = "";
  8591. string gres = "";
  8592. if (bill_entity != null)
  8593. {
  8594. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8595. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8596. {
  8597. int iTag = 0;
  8598. bill_entity.fplsh = "";
  8599. bill_entity.fpdm = "";
  8600. bill_entity.fphm = "";
  8601. foreach (string billOrderId in billOrderList)
  8602. {
  8603. iTag++;
  8604. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8605. if (gres.IndexOf("success") != -1)
  8606. {
  8607. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8608. Invoicing_get_response_Obj iObj = null;
  8609. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8610. if (iObj != null)
  8611. {
  8612. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8613. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8614. bill_entity.fphm += iObj.list[0].c_fphm;
  8615. if (iTag < billOrderList.Length)
  8616. {
  8617. bill_entity.fplsh += ",";
  8618. bill_entity.fpdm += ",";
  8619. bill_entity.fphm += ",";
  8620. }
  8621. bill_entity.Update();
  8622. }
  8623. }
  8624. else
  8625. {
  8626. returnErrorMsg(gres);
  8627. return;
  8628. }
  8629. }
  8630. }
  8631. if (bill_entity.sendType == "纸质发票")
  8632. {
  8633. //作废
  8634. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8635. //if (DateTime.Now.Month == extime.Month)
  8636. //{
  8637. //cres = taobaoHelper.cancel_invoicing(eid);
  8638. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8639. //{
  8640. bill_entity.state = 4;//已作废
  8641. bill_entity.Update();
  8642. returnSuccessMsg("发票已作废");
  8643. return;
  8644. //}
  8645. //else
  8646. //{
  8647. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8648. // bill_entity.Update();
  8649. // returnErrorMsg(cres);
  8650. // return;
  8651. //}
  8652. //}
  8653. //else
  8654. //{
  8655. // returnErrorMsg("纸质发票只能作废本月的发票");
  8656. // return;
  8657. //}
  8658. }
  8659. //红冲
  8660. int redTag = 0;
  8661. string[] fpdmList = bill_entity.fpdm.Split(',');
  8662. string[] fphmList = bill_entity.fphm.Split(',');
  8663. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8664. {
  8665. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8666. return;
  8667. }
  8668. foreach (string billOrderId in billOrderList)
  8669. {
  8670. redTag++;
  8671. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8672. cres += onecres;
  8673. cres += ",";
  8674. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8675. {
  8676. bill_entity.state = 4;//已作废
  8677. //bill_entity.Update();
  8678. //returnSuccessMsg("发票已红冲");
  8679. }
  8680. else if (onecres.IndexOf("重复冲红") != -1)
  8681. {
  8682. bill_entity.state = 4;//已作废
  8683. //bill_entity.Update();
  8684. //returnSuccessMsg("发票已红冲");
  8685. }
  8686. else
  8687. {
  8688. string errmsg = commonHelper.KeepChinese(onecres);
  8689. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8690. }
  8691. }
  8692. bill_entity.Update();
  8693. if (cres.IndexOf("失败") != -1)
  8694. returnErrorMsg("红冲失败");
  8695. else
  8696. returnSuccessMsg("发票已红冲");
  8697. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8698. return;
  8699. }
  8700. return;
  8701. }
  8702. }
  8703. public void del_erp_billorder()
  8704. {
  8705. if (UrlPostParmsCheck("id"))
  8706. {
  8707. string eid = GetPostString("id");
  8708. CeErpBill.Del(eid);
  8709. CeErpBill bill = CeErpBill.Get(eid);
  8710. if (bill != null)
  8711. {
  8712. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8713. }
  8714. returnSuccessMsg("删除成功");
  8715. }
  8716. }
  8717. public void finish_erp_bill()
  8718. {
  8719. if (UrlPostParmsCheck("ids"))
  8720. {
  8721. string eids = GetPostString("ids");
  8722. string[] list = eids.Split(',');
  8723. foreach (string eid in list)
  8724. {
  8725. CeErpBill bill = CeErpBill.Get(eid);
  8726. if (bill != null)
  8727. {
  8728. bill.state = 2;
  8729. bill.Update();
  8730. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8731. }
  8732. }
  8733. returnSuccessMsg("操作成功");
  8734. }
  8735. }
  8736. public void get_erp_returncash()
  8737. {
  8738. DataStruct dStruct = GetPostStruct();
  8739. List<string> lw = new List<string>();
  8740. string tid = GetPostString("tid");
  8741. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8742. string shopname = GetPostString("shopname");
  8743. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8744. string buyernick = GetPostString("buyer_nick");
  8745. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8746. string customer = GetPostString("customer");
  8747. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8748. string returndate1 = GetPostString("returndate1");
  8749. string returndate2 = GetPostString("returndate2");
  8750. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8751. if (dw.Length > 0) lw.Add(dw);
  8752. string finishDate1 = GetPostString("finishdate1");
  8753. string finishDate2 = GetPostString("finishdate2");
  8754. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8755. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8756. string returntype = GetPostString("returntype");
  8757. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8758. string returnvstate = GetPostString("returnvstate");
  8759. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8760. dStruct.Order = "created desc";
  8761. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8762. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8763. writeGridDataTableJson(dStruct.TotalCount, dt);
  8764. }
  8765. public void get_erp_staygoods()
  8766. {
  8767. DataStruct dStruct = GetPostStruct();
  8768. List<string> lw = new List<string>();
  8769. string tid = GetPostString("tid");
  8770. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8771. string shopname = GetPostString("shopname");
  8772. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8773. string wangwang = GetPostString("wangwang");
  8774. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8775. string customer = GetPostString("customer");
  8776. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8777. string returndate1 = GetPostString("returndate1");
  8778. string returndate2 = GetPostString("returndate2");
  8779. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8780. if (dw.Length > 0) lw.Add(dw);
  8781. string finishDate1 = GetPostString("finishdate1");
  8782. string finishDate2 = GetPostString("finishdate2");
  8783. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8784. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8785. string returnvstate = GetPostString("returnvstate");
  8786. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8787. string persuadetype = GetPostString("persuadetype");
  8788. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8789. string customerOrg = GetPostString("customerOrg");
  8790. if (customerOrg.Length > 0)
  8791. {
  8792. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8793. }
  8794. dStruct.Order = "creata_time desc";
  8795. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8796. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8797. writeGridDataTableJson(dStruct.TotalCount, dt);
  8798. }
  8799. public void upd_erp_staygoods()
  8800. {
  8801. if (UrlPostParmsCheck("id"))
  8802. {
  8803. int eid = GetPostInt("id");
  8804. CeErpStayGoods entity = null;
  8805. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8806. if (entity != null)
  8807. {
  8808. entity.audit_type = 1;
  8809. entity.audit_time = DateTime.Now;
  8810. entity.audit_u_id = CurrentUser.UserID;
  8811. entity.audit_u_name = CurrentUser.UserName;
  8812. entity.Update();
  8813. returnSuccessMsg("审核成功!");
  8814. return;
  8815. }
  8816. returnErrorMsg("找不到订单记录");
  8817. }
  8818. }
  8819. public void upd_erp_stayGoodsback()
  8820. {
  8821. if (UrlPostParmsCheck("id"))
  8822. {
  8823. int eid = GetPostInt("id");
  8824. CeErpStayGoods entity = null;
  8825. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8826. if (entity != null)
  8827. {
  8828. entity.audit_text = GetPostString("reason");
  8829. entity.audit_type = 2;
  8830. entity.audit_time = DateTime.Now;
  8831. entity.audit_u_id = CurrentUser.UserID;
  8832. entity.audit_u_name = CurrentUser.UserName;
  8833. entity.Update();
  8834. returnSuccessMsg("退回成功!");
  8835. return;
  8836. }
  8837. returnErrorMsg("找不到订单记录");
  8838. }
  8839. }
  8840. public void upd_erp_returncashverify()
  8841. {
  8842. if (UrlPostParmsCheck("ID"))
  8843. {
  8844. int eid = GetPostInt("ID");
  8845. CeErpReturnCash entity = null;
  8846. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8847. if (entity != null)
  8848. {
  8849. entity.cashstate = 1;
  8850. entity.verifytime = DateTime.Now;
  8851. entity.verifyuserid = CurrentUser.UserID;
  8852. entity.Update();
  8853. returnSuccessMsg("审核成功!");
  8854. return;
  8855. }
  8856. returnErrorMsg("找不到订单记录");
  8857. }
  8858. }
  8859. public void upd_all_erp_returncashverify()
  8860. {
  8861. if (UrlPostParmsCheck("ID"))
  8862. {
  8863. String[] list = GetPostString("ID").Split(',');
  8864. CeErpReturnCash entity = null;
  8865. for (int i = 0; i < list.Length; i++)
  8866. {
  8867. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8868. if (entity != null)
  8869. {
  8870. if (entity.cashstate == 1)
  8871. {
  8872. returnErrorMsg("已审核过的订单不需要在审核!");
  8873. return;
  8874. }
  8875. entity.cashstate = 1;
  8876. entity.verifytime = DateTime.Now;
  8877. entity.verifyuserid = CurrentUser.UserID;
  8878. entity.Update();
  8879. }
  8880. }
  8881. returnSuccessMsg("审核成功!");
  8882. return;
  8883. }
  8884. }
  8885. public void upd_erp_returncashback()
  8886. {
  8887. if (UrlPostParmsCheck("ID"))
  8888. {
  8889. int eid = GetPostInt("ID");
  8890. CeErpReturnCash entity = null;
  8891. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8892. if (entity != null)
  8893. {
  8894. entity.backreason = GetPostString("reason");
  8895. entity.cashstate = 2;
  8896. entity.verifytime = DateTime.Now;
  8897. entity.verifyuserid = CurrentUser.UserID;
  8898. entity.Update();
  8899. returnSuccessMsg("退回成功!");
  8900. return;
  8901. }
  8902. returnErrorMsg("找不到订单记录");
  8903. }
  8904. }
  8905. public void upd_erp_returnprice()
  8906. {
  8907. if (UrlPostParmsCheck("ID"))
  8908. {
  8909. int eid = GetPostInt("ID");
  8910. CeErpReturnCash entity = null;
  8911. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8912. if (entity != null)
  8913. {
  8914. if (entity.cashstate == 1)
  8915. {
  8916. returnErrorMsg("审核通过了不能改");
  8917. return;
  8918. }
  8919. entity.returnprice = GetPostDouble("returnprice");
  8920. entity.Update();
  8921. returnSuccessMsg("修改成功!");
  8922. return;
  8923. }
  8924. returnErrorMsg("找不到订单记录");
  8925. }
  8926. }
  8927. public void del_erp_returncash()
  8928. {
  8929. if (UrlPostParmsCheck("ID"))
  8930. {
  8931. int eid = GetPostInt("ID");
  8932. CeErpReturnCash.Del(eid);
  8933. returnSuccessMsg("操作成功");
  8934. return;
  8935. }
  8936. }
  8937. public void test_for_do_sql()
  8938. {
  8939. string sql = GetPostString("sqlstr");
  8940. if (sql.Length > 0)
  8941. {
  8942. try
  8943. {
  8944. DbHelper.DbConn.ExecuteNonQuery(sql);
  8945. var res_obj = new
  8946. {
  8947. data = "成功",
  8948. };
  8949. string ro_json = JsonConvert.SerializeObject(res_obj);
  8950. returnSuccess(ro_json);
  8951. }
  8952. catch (Exception ex)
  8953. {
  8954. var res_obj = new
  8955. {
  8956. data = ex.Message,
  8957. };
  8958. string ro_json = JsonConvert.SerializeObject(res_obj);
  8959. returnSuccess(ro_json);
  8960. }
  8961. }
  8962. }
  8963. public void get_user_info()
  8964. {
  8965. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8966. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8967. }
  8968. public void get_total_data()
  8969. {
  8970. int userId = CurrentUser.UserID;
  8971. string sql = "";
  8972. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8973. {
  8974. 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);
  8975. }
  8976. else
  8977. {
  8978. 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 " +
  8979. "(select ID from CE_ErpUser where ID = {0}) d " +
  8980. "left join " +
  8981. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8982. ") a on d.ID = a.id left join " +
  8983. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8984. ") b on a.id = b.id1 left join" +
  8985. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8986. ") c on a.id = c.id2;", userId);
  8987. }
  8988. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8989. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8990. }
  8991. public void get_date_area_total_data2()
  8992. {
  8993. int userId = CurrentUser.UserID;
  8994. string date_type = GetPostString("timetype");
  8995. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8996. string sql = "";
  8997. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8998. {
  8999. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9000. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9001. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9002. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9003. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9004. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9005. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9006. ") a on e.ID = a.id left join " +
  9007. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9008. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9009. ") b on a.id = b.id1 " +
  9010. "left join " +
  9011. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9012. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9013. ") c on a.id = c.id2 " +
  9014. "left join " +
  9015. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9016. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9017. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9018. }
  9019. else
  9020. {
  9021. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9022. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9023. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9024. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9025. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9026. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9027. ") a on e.ID = a.id left join " +
  9028. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9029. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9030. ") c on a.id = c.id2 " +
  9031. "left join " +
  9032. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9033. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9034. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9035. }
  9036. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9037. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9038. }
  9039. public void get_date_area_total_data()
  9040. {
  9041. int userId = CurrentUser.UserID;
  9042. string date_type = GetPostString("timetype");
  9043. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9044. string date1 = searchDT[0].ToString();
  9045. string date2 = searchDT[1].ToString();
  9046. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9047. {
  9048. SqlParameter[] sqlParameter ={
  9049. new SqlParameter("@userId", SqlDbType.Int,4),
  9050. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9051. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9052. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9053. };
  9054. sqlParameter[0].Value = userId;
  9055. sqlParameter[1].Value = date1;
  9056. sqlParameter[2].Value = date2;
  9057. sqlParameter[3].Direction = ParameterDirection.Output;
  9058. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9059. string res = sqlParameter[3].Value.ToString();
  9060. var res_obj = new
  9061. {
  9062. data = res
  9063. };
  9064. string ro_json = JsonConvert.SerializeObject(res_obj);
  9065. returnSuccess(ro_json);
  9066. }
  9067. else
  9068. {
  9069. SqlParameter[] sqlParameter ={
  9070. new SqlParameter("@userId", SqlDbType.Int,4),
  9071. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9072. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9073. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9074. };
  9075. sqlParameter[0].Value = userId;
  9076. sqlParameter[1].Value = date1;
  9077. sqlParameter[2].Value = date2;
  9078. sqlParameter[3].Direction = ParameterDirection.Output;
  9079. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9080. string res = sqlParameter[3].Value.ToString();
  9081. var res_obj = new
  9082. {
  9083. data = res
  9084. };
  9085. string ro_json = JsonConvert.SerializeObject(res_obj);
  9086. returnSuccess(ro_json);
  9087. }
  9088. //writeGridDataViewJson(dt.Rows.Count, dv);
  9089. }
  9090. public void get_order_list()
  9091. {
  9092. string strFields = GetPostString("paraFields");
  9093. string strOrder = GetPostString("paraOrder");
  9094. string strWhere = GetPostString("paraWhere");
  9095. string strPageSize = GetPostString("paraPageSize");
  9096. DataStruct dStruct = GetPostStruct();
  9097. dStruct.PageSize = int.Parse(strPageSize);
  9098. dStruct.Fileds = strFields;
  9099. dStruct.Order = strOrder;
  9100. dStruct.MainWhere = strWhere;
  9101. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9102. writeGridDataTableJson(dStruct.TotalCount, dt);
  9103. }
  9104. ////获取待开始订单列表
  9105. //public void get_wait_design_order_list()
  9106. //{
  9107. // string date_type = GetPostString("date_type");
  9108. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9109. // DataStruct dStruct = GetPostStruct();
  9110. // dStruct.PageSize = 1000;
  9111. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9112. // List<string> lw = new List<string>();
  9113. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9114. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9115. // dStruct.Order = "WaitDesignTime asc";
  9116. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9117. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9118. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9119. //}
  9120. //获取完成单量排名
  9121. public void get_finish_order_count_ranking()
  9122. {
  9123. /* string date_type = GetPostString("date_type");
  9124. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9125. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9126. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9127. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9128. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9129. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9130. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9131. writeGridDataTableJson(0, new DataTable());
  9132. }
  9133. public void get_finish_order_amount_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.orderAmount, 0) as orderAmount " +
  9138. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9139. "left join(select DesignUserId, SUM(payment) as orderAmount 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 orderAmount 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_refund_count_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.orderCount, 0) as orderCount " +
  9150. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9151. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9152. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9153. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9154. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9155. writeGridDataTableJson(dt.Rows.Count, dt);
  9156. }
  9157. public void get_finish_refund_amount_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.orderAmount, 0) as orderAmount " +
  9162. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9163. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount 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 orderAmount 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 set_erp_finishorder_director()
  9170. {
  9171. if (UrlPostParmsCheck("ctid"))
  9172. {
  9173. string eid = GetPostString("ctid");
  9174. CeErpTradeCell entity = null;
  9175. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9176. if (entity != null)
  9177. {
  9178. entity.OrderState = 8;
  9179. entity.Update();
  9180. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9181. returnSuccessMsg("操作成功!");
  9182. return;
  9183. }
  9184. returnErrorMsg("找不到记录");
  9185. }
  9186. }
  9187. public void get_erp_placeregistlist()
  9188. {
  9189. DataStruct dStruct = GetPostStruct();
  9190. List<string> lw = new List<string>();
  9191. string outsid = GetPostString("outsid");
  9192. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9193. string memo = GetPostString("memo");
  9194. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9195. string filename = GetPostString("filename");
  9196. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9197. string islate = GetPostString("islate");
  9198. if (islate.Length > 0)
  9199. {
  9200. if (islate == "1")
  9201. lw.Add(string.Format("OutLate>0"));
  9202. else
  9203. lw.Add(string.Format("OutLate=0"));
  9204. }
  9205. string placedate1 = GetPostString("placedate1");
  9206. string placedate2 = GetPostString("placedate2");
  9207. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9208. if (dw.Length > 0) lw.Add(dw);
  9209. string deliveryDate1 = GetPostString("deliverydate1");
  9210. string deliveryDate2 = GetPostString("deliverydate2");
  9211. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9212. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9213. dStruct.Order = "ID desc";
  9214. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9215. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9216. writeGridDataTableJson(dStruct.TotalCount, dt);
  9217. }
  9218. public void ins_erp_placeregist()
  9219. {
  9220. if (UrlPostParmsCheck("id"))
  9221. {
  9222. string eid = GetPostString("id");
  9223. CeErpPlaceRegister entity = null;
  9224. if (eid == "0")//新增
  9225. {
  9226. entity = new CeErpPlaceRegister();
  9227. string xdTime = GetPostString("placeTime");
  9228. if (xdTime.Length > 0)
  9229. {
  9230. entity.PlactTime = Convert.ToDateTime(xdTime);
  9231. }
  9232. string fhTime = GetPostString("deliveryTime");
  9233. if (fhTime.Length > 0)
  9234. {
  9235. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9236. }
  9237. string preTime = GetPostString("preOutTime");
  9238. if (preTime.Length > 0)
  9239. {
  9240. entity.PreOutTime = Convert.ToDateTime(preTime);
  9241. }
  9242. entity.DeliveryCount = GetPostInt("deliveryCount");
  9243. entity.ReceiveCount = GetPostInt("receiveCount");
  9244. entity.OutSid = GetPostString("outSid");
  9245. entity.FileName = GetPostString("fileName");
  9246. entity.Memo = GetPostString("memo");
  9247. entity.AddUserId = CurrentUser.UserID;
  9248. entity.CreateTime = DateTime.Now;
  9249. entity.Img = GetPostString("img");
  9250. entity.Supplier = GetPostInt("supplier");
  9251. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9252. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9253. {
  9254. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9255. DateTime dt2 = (DateTime)entity.PreOutTime;
  9256. TimeSpan span = dt1.Subtract(dt2);
  9257. if (span.Days > 0)
  9258. {
  9259. entity.OutLate = span.Days;
  9260. }
  9261. }
  9262. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9263. entity.Create();
  9264. returnSuccessMsg("添加成功!");
  9265. return;
  9266. }
  9267. else //修改
  9268. {
  9269. entity = CeErpPlaceRegister.Get(eid);
  9270. if (entity != null)
  9271. {
  9272. string xdTime = GetPostString("placeTime");
  9273. if (xdTime.Length > 0)
  9274. {
  9275. entity.PlactTime = Convert.ToDateTime(xdTime);
  9276. }
  9277. string fhTime = GetPostString("deliveryTime");
  9278. if (fhTime.Length > 0)
  9279. {
  9280. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9281. }
  9282. string preTime = GetPostString("preOutTime");
  9283. if (preTime.Length > 0)
  9284. {
  9285. entity.PreOutTime = Convert.ToDateTime(preTime);
  9286. }
  9287. entity.DeliveryCount = GetPostInt("deliveryCount");
  9288. entity.ReceiveCount = GetPostInt("receiveCount");
  9289. if (entity.DeliveryCount == entity.ReceiveCount)
  9290. {
  9291. entity.CurState = "已完成";
  9292. }
  9293. else
  9294. {
  9295. entity.CurState = "未完成";
  9296. }
  9297. entity.OutSid = GetPostString("outSid");
  9298. entity.FileName = GetPostString("fileName");
  9299. entity.Memo = GetPostString("memo");
  9300. entity.Img = GetPostString("img");
  9301. entity.Supplier = GetPostInt("supplier");
  9302. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9303. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9304. {
  9305. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9306. DateTime dt2 = (DateTime)entity.PreOutTime;
  9307. TimeSpan span = dt1.Subtract(dt2);
  9308. if (span.Days > 0)
  9309. {
  9310. entity.OutLate = span.Days;
  9311. }
  9312. }
  9313. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9314. entity.Update();
  9315. returnSuccessMsg("修改成功");
  9316. return;
  9317. }
  9318. returnErrorMsg("找不到对应的记录");
  9319. return;
  9320. }
  9321. }
  9322. returnErrorMsg("缺少必要参数");
  9323. }
  9324. public void del_erp_placeregist()
  9325. {
  9326. string eid = GetPostString("id");
  9327. CeErpPlaceRegister.Del(eid);
  9328. returnSuccessMsg("删除成功!");
  9329. return;
  9330. }
  9331. public void ins_erp_placeregistbyorder()
  9332. {
  9333. string ctid = GetPostString("ctid");
  9334. if (ctid.Length > 0)
  9335. {
  9336. StringBuilder sql = new StringBuilder();
  9337. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9338. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9339. if (dt.Rows.Count > 0)
  9340. {
  9341. foreach (DataRow dr in dt.Rows)
  9342. {
  9343. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9344. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9345. entity.AddUserId = CurrentUser.UserID;
  9346. entity.tid = dr["tid"].ToString();
  9347. entity.Did = Convert.ToString(dr["ctid"]);
  9348. entity.splitTag = dr["SplitTag"].ToString();
  9349. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9350. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9351. if (pre_ctid.Length > 0)
  9352. {
  9353. sellmemo = sellmemo.Replace(pre_ctid, "");
  9354. }
  9355. sellmemo = sellmemo.Replace("[", "");
  9356. sellmemo = sellmemo.Replace("]", "");
  9357. entity.FileName = sellmemo;
  9358. string count = dr["ProductCount"].ToString();
  9359. int usecount = commonHelper.getIntCountFromString(count);
  9360. entity.DeliveryCount = usecount;
  9361. entity.CurState = "未完成";
  9362. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9363. {
  9364. entity.Supplier = 24;//dl手提袋定制
  9365. }
  9366. else
  9367. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9368. entity.CreateTime = DateTime.Now;
  9369. entity.Create();
  9370. }
  9371. returnSuccessMsg("操作成功");
  9372. return;
  9373. }
  9374. returnErrorMsg("没有找到对应订单");
  9375. return;
  9376. }
  9377. returnErrorMsg("缺少订单编号");
  9378. return;
  9379. }
  9380. public void get_erp_persuadelist()
  9381. {
  9382. DataStruct dStruct = GetPostStruct();
  9383. List<string> lw = new List<string>();
  9384. string ctid = GetPostString("ctid");
  9385. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9386. string shopname = GetPostString("shopname");
  9387. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9388. string buyernick = GetPostString("buyer_nick");
  9389. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9390. string customer = GetPostString("customer");
  9391. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9392. string returndate1 = GetPostString("returndate1");
  9393. string returndate2 = GetPostString("returndate2");
  9394. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9395. if (dw.Length > 0) lw.Add(dw);
  9396. string finishDate1 = GetPostString("finishdate1");
  9397. string finishDate2 = GetPostString("finishdate2");
  9398. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9399. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9400. string persuadetype = GetPostString("persuadetype");
  9401. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9402. string returnvstate = GetPostString("returnvstate");
  9403. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9404. dStruct.Order = "created desc";
  9405. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9406. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9407. writeGridDataTableJson(dStruct.TotalCount, dt);
  9408. }
  9409. public void upd_erp_returnpersuadeback()
  9410. {
  9411. if (UrlPostParmsCheck("ID"))
  9412. {
  9413. int eid = GetPostInt("ID");
  9414. CeErpPersuade entity = null;
  9415. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9416. if (entity != null)
  9417. {
  9418. entity.backreason = GetPostString("reason");
  9419. entity.pstate = 2;
  9420. entity.verifytime = DateTime.Now;
  9421. entity.verifyuserid = CurrentUser.UserID;
  9422. entity.Update();
  9423. returnSuccessMsg("退回成功!");
  9424. return;
  9425. }
  9426. returnErrorMsg("找不到订单记录");
  9427. }
  9428. }
  9429. public void upd_erp_returnpersuadeverify()
  9430. {
  9431. if (UrlPostParmsCheck("ID"))
  9432. {
  9433. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9434. {
  9435. returnErrorMsg("暂无权限审核");
  9436. return;
  9437. }
  9438. int eid = GetPostInt("ID");
  9439. CeErpPersuade entity = null;
  9440. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9441. if (entity != null)
  9442. {
  9443. entity.pstate = 1;
  9444. entity.verifytime = DateTime.Now;
  9445. entity.verifyuserid = CurrentUser.UserID;
  9446. entity.Update();
  9447. returnSuccessMsg("审核成功!");
  9448. return;
  9449. }
  9450. returnErrorMsg("找不到订单记录");
  9451. }
  9452. }
  9453. public void del_erp_persuade()
  9454. {
  9455. if (UrlPostParmsCheck("ID"))
  9456. {
  9457. int eid = GetPostInt("ID");
  9458. CeErpPersuade.Del(eid);
  9459. returnSuccessMsg("操作成功");
  9460. return;
  9461. }
  9462. }
  9463. public void get_erp_oldcustoupload()
  9464. {
  9465. DataStruct dStruct = GetPostStruct();
  9466. List<string> lw = new List<string>();
  9467. string buyernick = GetPostString("buyer_nick");
  9468. if (buyernick.Length > 0)
  9469. {
  9470. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9471. }
  9472. else
  9473. return;
  9474. dStruct.Order = "pay_time desc";
  9475. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9476. DataTable dt = null;
  9477. dt = WebCache.GetData("view_erptradecell", dStruct);
  9478. writeGridDataTableJson(dStruct.TotalCount, dt);
  9479. }
  9480. public void get_erp_checkorderlist()
  9481. {
  9482. DataStruct dStruct = GetPostStruct();
  9483. List<string> lw = new List<string>();
  9484. string tid = GetPostString("ctid");
  9485. if (tid.Length > 0)
  9486. {
  9487. string select_tid = getTidByCtid(tid);
  9488. lw.Add(string.Format("tid='{0}'", select_tid));
  9489. }
  9490. string shopname = GetPostString("shopname");
  9491. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9492. string buyernick = GetPostString("buyer_nick");
  9493. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9494. string customer = GetPostString("customer");
  9495. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9496. string design = GetPostString("design");
  9497. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9498. string orderState = GetPostString("orderState");
  9499. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9500. string address = GetPostString("address");
  9501. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9502. string sellermemo = GetPostString("seller_memo");
  9503. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9504. string supplier = GetPostString("supplier");
  9505. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9506. {
  9507. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9508. }
  9509. else
  9510. {
  9511. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9512. }
  9513. string date1 = GetPostString("date1");
  9514. string date2 = GetPostString("date2");
  9515. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9516. if (dw.Length > 0) lw.Add(dw);
  9517. string placedate1 = GetPostString("placedate1");
  9518. string placedate2 = GetPostString("placedate2");
  9519. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9520. if (fdw.Length > 0) lw.Add(fdw);
  9521. string price1 = GetPostString("price1");
  9522. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9523. string price2 = GetPostString("price2");
  9524. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9525. string checkst = GetPostString("checkstate");
  9526. if (checkst.Length > 0 && "10".Equals(checkst))
  9527. {
  9528. lw.Add(string.Format("CheckOut>0"));
  9529. }
  9530. else
  9531. {
  9532. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9533. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9534. }
  9535. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9536. {
  9537. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9538. }
  9539. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9540. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9541. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9542. writeGridDataTableJson(dStruct.TotalCount, dt);
  9543. }
  9544. public void ins_erp_startCheck()
  9545. {
  9546. if (UrlPostParmsCheck("ctid"))
  9547. {
  9548. string eid = GetPostString("ctid");
  9549. CeErpTradeCell entity = null;
  9550. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9551. if (entity != null)
  9552. {
  9553. entity.MemoOpt = 4;
  9554. entity.UpdateTime = DateTime.Now;
  9555. entity.Update();
  9556. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9557. CeErpSukuraData.createInfo(entity.ctid, 6);
  9558. returnSuccessMsg("操作成功!");
  9559. return;
  9560. }
  9561. returnErrorMsg("找不到记录");
  9562. }
  9563. }
  9564. public void upd_erp_sendXlw()
  9565. {
  9566. if (UrlPostParmsCheck("ctid"))
  9567. {
  9568. string eid = GetPostString("ctid");
  9569. CeErpTradeCell entity = null;
  9570. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9571. if (entity != null)
  9572. {
  9573. if (entity.IsSendGift == 1)
  9574. {
  9575. returnErrorMsg("请勿重复标记");
  9576. return;
  9577. }
  9578. entity.IsSendGift = 1;
  9579. entity.Update();
  9580. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9581. returnSuccessMsg("操作成功!");
  9582. return;
  9583. }
  9584. returnErrorMsg("找不到记录");
  9585. }
  9586. }
  9587. public void cancel_sendXlw()
  9588. {
  9589. if (UrlPostParmsCheck("ctid"))
  9590. {
  9591. string eid = GetPostString("ctid");
  9592. CeErpTradeCell entity = null;
  9593. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9594. if (entity != null)
  9595. {
  9596. if (entity.IsSendGift == 0)
  9597. {
  9598. returnErrorMsg("未标记小礼物");
  9599. return;
  9600. }
  9601. entity.IsSendGift = 0;
  9602. entity.Update();
  9603. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9604. returnSuccessMsg("操作成功!");
  9605. return;
  9606. }
  9607. returnErrorMsg("找不到记录");
  9608. }
  9609. }
  9610. public void get_erp_designbill()
  9611. {
  9612. DataStruct dStruct = GetPostStruct();
  9613. List<string> lw = new List<string>();
  9614. int isMy = GetInt("my");
  9615. if (isMy == 1)
  9616. {
  9617. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9618. }
  9619. string tid = GetPostString("tid");
  9620. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9621. string userName = GetPostString("design");
  9622. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9623. string price1 = GetPostString("price1");
  9624. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9625. string price2 = GetPostString("price2");
  9626. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9627. string rePrice1 = GetPostString("rePrice1");
  9628. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9629. string rePrice2 = GetPostString("rePrice2");
  9630. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9631. string designerType = GetPostString("designerType");
  9632. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9633. string orderState = GetPostString("orderState");
  9634. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9635. string endTime1 = GetPostString("endTime1");
  9636. string endTime2 = GetPostString("endTime2");
  9637. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9638. if (dw.Length > 0) lw.Add(dw);
  9639. string isDk = GetPostString("isDk");
  9640. if (isDk == "1")
  9641. {
  9642. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9643. }
  9644. else if (isDk == "0")
  9645. {
  9646. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9647. }
  9648. dStruct.Order = "oid, create_time desc";
  9649. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9650. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9651. writeGridDataTableJson(dStruct.TotalCount, dt);
  9652. }
  9653. public void upd_erp_designerbill()
  9654. {
  9655. if (UrlPostParmsCheck("ID"))
  9656. {
  9657. string eid = GetPostString("ID");
  9658. CeErpDesignerBill entity = null;
  9659. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9660. if (entity != null)
  9661. {
  9662. if (GetPostDouble("designerpirce") > 0)
  9663. {
  9664. entity.realPrice = GetPostDouble("designerpirce");
  9665. entity.update_time = DateTime.Now;
  9666. entity.update_u_id = CurrentUser.UserID;
  9667. entity.update_u_name = CurrentUser.UserName;
  9668. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9669. entity.Update();
  9670. returnSuccessMsg("操作成功!");
  9671. return;
  9672. }
  9673. else
  9674. {
  9675. entity.price = GetPostDouble("price");
  9676. entity.update_time = DateTime.Now;
  9677. entity.update_u_id = CurrentUser.UserID;
  9678. entity.update_u_name = CurrentUser.UserName;
  9679. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9680. entity.Update();
  9681. returnSuccessMsg("操作成功!");
  9682. return;
  9683. }
  9684. }
  9685. returnErrorMsg("找不到记录");
  9686. }
  9687. }
  9688. public void audit_erp_designerbill()
  9689. {
  9690. if (UrlPostParmsCheck("ID"))
  9691. {
  9692. string eid = GetPostString("ID");
  9693. CeErpDesignerBill entity = null;
  9694. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9695. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9696. if (entity != null)
  9697. {
  9698. entity.realPrice = GetPostDouble("designerpirce");
  9699. entity.update_time = DateTime.Now;
  9700. entity.update_u_id = CurrentUser.UserID;
  9701. entity.update_u_name = CurrentUser.UserName;
  9702. entity.isAudit = 1;
  9703. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9704. entity.Update();
  9705. if (orderEntity != null)
  9706. {
  9707. orderEntity.IsReadTag = 3;
  9708. orderEntity.Update();
  9709. }
  9710. returnSuccessMsg("操作成功!");
  9711. return;
  9712. }
  9713. returnErrorMsg("找不到记录");
  9714. }
  9715. }
  9716. public void all_audit_erp_designerbill()
  9717. {
  9718. if (UrlPostParmsCheck("idList"))
  9719. {
  9720. string[] list = GetPostString("idList").Split(',');
  9721. CeErpDesignerBill entity = null;
  9722. for (int i = 0; i < list.Length; i++)
  9723. {
  9724. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9725. if (entity == null) return;
  9726. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9727. if (orderEntity == null) return;
  9728. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9729. entity.update_time = DateTime.Now;
  9730. entity.update_u_id = CurrentUser.UserID;
  9731. entity.update_u_name = CurrentUser.UserName;
  9732. entity.isAudit = 1;
  9733. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9734. entity.Update();
  9735. orderEntity.IsReadTag = 3;
  9736. orderEntity.Update();
  9737. }
  9738. returnSuccessMsg("操作成功!");
  9739. return;
  9740. }
  9741. }
  9742. public void get_erp_sameorders()
  9743. {
  9744. if (UrlPostParmsCheck("ctid"))
  9745. {
  9746. string eid = GetPostString("ctid");
  9747. CeErpTradeCell entity = null;
  9748. entity = CeErpTradeCell.GetByCtid(eid);
  9749. if (entity != null)
  9750. {
  9751. StringBuilder sql = new StringBuilder();
  9752. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9753. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9754. var res = new
  9755. {
  9756. data = dt.Rows.Count
  9757. };
  9758. string ro_jsond = JsonConvert.SerializeObject(res);
  9759. returnSuccess(ro_jsond);
  9760. return;
  9761. }
  9762. returnErrorMsg("未找到订单");
  9763. return;
  9764. }
  9765. returnErrorMsg("缺少必要的参数");
  9766. }
  9767. public void get_erp_islasthavesameorder()
  9768. {
  9769. if (UrlPostParmsCheck("ctid"))
  9770. {
  9771. string eid = GetPostString("ctid");
  9772. string[] ctidList = eid.Split(',');
  9773. StringBuilder sql = new StringBuilder();
  9774. string tisCtid = "";
  9775. foreach (string ctid in ctidList)
  9776. {
  9777. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9778. if (entity != null)
  9779. {
  9780. sql = new StringBuilder();
  9781. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9782. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9783. if (dth.Rows.Count > 0)
  9784. {
  9785. tisCtid += entity.ctid;
  9786. tisCtid += ",";
  9787. }
  9788. }
  9789. }
  9790. if (tisCtid.Length > 0)
  9791. {
  9792. var res = new
  9793. {
  9794. data = tisCtid
  9795. };
  9796. string ro_jsond = JsonConvert.SerializeObject(res);
  9797. returnSuccess(ro_jsond);
  9798. }
  9799. else
  9800. {
  9801. var res = new
  9802. {
  9803. data = ""
  9804. };
  9805. string ro_jsond = JsonConvert.SerializeObject(res);
  9806. returnSuccess(ro_jsond);
  9807. }
  9808. return;
  9809. }
  9810. returnErrorMsg("缺少必要的参数");
  9811. }
  9812. public void file_client_down_url()
  9813. {
  9814. if (!UrlPostParmsCheck("userId"))
  9815. {
  9816. returnErrorMsg("缺少必要的参数");
  9817. }
  9818. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9819. }
  9820. public void checkout_form_data()
  9821. {
  9822. if (!UrlPostParmsCheck("tid"))
  9823. {
  9824. returnErrorMsg("缺少必要的参数");
  9825. }
  9826. string tid = GetPostString("tid");
  9827. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9828. if (ceErpOrderFormData != null)
  9829. {
  9830. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9831. returnSuccess(ro_jsond);
  9832. return;
  9833. }
  9834. returnErrorMsg("尚未有文件!");
  9835. }
  9836. public void back_supplier_audit()
  9837. {
  9838. int userId = CurrentUser.UserID;
  9839. StringBuilder sql = new StringBuilder();
  9840. 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);
  9841. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9842. if (dt.Rows.Count > 0)
  9843. {
  9844. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9845. }
  9846. else
  9847. {
  9848. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9849. }
  9850. }
  9851. public void back_supplier_query()
  9852. {
  9853. string eid = GetPostString("ctid");
  9854. if (eid != "")
  9855. {
  9856. StringBuilder sql = new StringBuilder();
  9857. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9858. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9859. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9860. }
  9861. else
  9862. {
  9863. returnErrorMsg("找不到订单记录");
  9864. return;
  9865. }
  9866. }
  9867. public void verified_to_order()
  9868. {
  9869. int userId = CurrentUser.UserID;
  9870. StringBuilder sql = new StringBuilder();
  9871. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9872. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9873. if (dt.Rows.Count > 0)
  9874. {
  9875. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9876. }
  9877. else
  9878. {
  9879. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9880. }
  9881. }
  9882. public void upd_supplier_audit()
  9883. {
  9884. if (UrlPostParmsCheck("ctid"))
  9885. {
  9886. string eid = GetPostString("ctid");
  9887. string reason = GetPostString("returnreason");
  9888. CeErpTradeCell entity = null;
  9889. CeWithdraw withdraw = null;
  9890. withdraw = CeWithdraw.GetByTid(eid);
  9891. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9892. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9893. {
  9894. if (withdraw != null)
  9895. {
  9896. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9897. {
  9898. returnSuccessMsg("您没有权限操作!");
  9899. return;
  9900. }
  9901. else
  9902. {
  9903. if (reason.Equals("1"))
  9904. {
  9905. if (entity.OrderState == -1)
  9906. {
  9907. if (entity.FinishPlaceTime == null)
  9908. {
  9909. entity.OrderState = 2;
  9910. }
  9911. else
  9912. {
  9913. entity.OrderState = 6;
  9914. }
  9915. }
  9916. entity.Update();
  9917. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9918. if (withdraw != null)
  9919. {
  9920. withdraw.status = int.Parse(reason);
  9921. withdraw.Update();
  9922. }
  9923. returnSuccessMsg("操作成功!");
  9924. return;
  9925. }
  9926. else
  9927. {
  9928. withdraw.status = int.Parse(reason);
  9929. withdraw.acknowledgingtime = DateTime.Now;
  9930. withdraw.Update();
  9931. returnSuccessMsg("查看详细请点击线下订单查询");
  9932. return;
  9933. }
  9934. }
  9935. }
  9936. // 第一个字符是 'N'
  9937. }
  9938. if (eid[0] != 'N')
  9939. {
  9940. }
  9941. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9942. {
  9943. entity.IsVerifyToSupplier = false;
  9944. entity.IsReturn = 1;
  9945. entity.ReturnTime = DateTime.Now;
  9946. entity.ReturnReason = reason;
  9947. if (entity.OrderState == 6)
  9948. {
  9949. entity.OrderState = 5;
  9950. }
  9951. entity.Update();
  9952. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9953. if (withdraw != null)
  9954. {
  9955. withdraw.status = int.Parse(reason);
  9956. withdraw.Update();
  9957. }
  9958. returnSuccessMsg("操作成功!");
  9959. return;
  9960. }
  9961. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9962. {
  9963. ;
  9964. if (withdraw != null)
  9965. {
  9966. withdraw.status = int.Parse(reason);
  9967. withdraw.acknowledgingtime = DateTime.Now;
  9968. withdraw.Update();
  9969. returnSuccessMsg("供应商取消撤回!");
  9970. return;
  9971. }
  9972. }
  9973. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9974. {
  9975. if (entity.OrderState == -1)
  9976. {
  9977. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  9978. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9979. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  9980. {
  9981. returnErrorMsg("台湾客户需填写身份证!");
  9982. return;
  9983. }
  9984. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9985. {
  9986. returnErrorMsg("订单spu没有确认无法通过审核!");
  9987. return;
  9988. }
  9989. if (entity.FinishPlaceTime == null)
  9990. {
  9991. entity.OrderState = 2;
  9992. }
  9993. else
  9994. {
  9995. entity.OrderState = 3;
  9996. }
  9997. commonHelper.getCytPrice(entity);
  9998. }
  9999. entity.Update();
  10000. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10001. if (withdraw != null)
  10002. {
  10003. withdraw.status = int.Parse(reason);
  10004. withdraw.Update();
  10005. }
  10006. returnSuccessMsg("操作成功!");
  10007. return;
  10008. }
  10009. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10010. {
  10011. if (withdraw == null)
  10012. {
  10013. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10014. return;
  10015. }
  10016. }
  10017. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10018. {
  10019. if (withdraw != null)
  10020. {
  10021. withdraw.status = int.Parse(reason);
  10022. withdraw.acknowledgingtime = DateTime.Now;
  10023. withdraw.Update();
  10024. returnSuccessMsg("查看详细请点击线下订单查询");
  10025. return;
  10026. }
  10027. }
  10028. return;
  10029. }
  10030. }
  10031. //校验报价
  10032. public void refund_order_tip()
  10033. {
  10034. int userid = CurrentUser.UserID;
  10035. int sectionId = CurrentUser.UserPost.OrgID;
  10036. StringBuilder sql = new StringBuilder();
  10037. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10038. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10039. List<string> ids = new List<string>();
  10040. if (dth.Rows.Count > 0)
  10041. {
  10042. foreach (DataRow dr in dth.Rows)
  10043. {
  10044. ids.Add(dr["ID"].ToString());
  10045. }
  10046. try
  10047. {
  10048. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10049. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10050. }
  10051. catch (Exception ex)
  10052. {
  10053. }
  10054. }
  10055. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10056. }
  10057. public void refund_order_Design()
  10058. {
  10059. int userid = CurrentUser.UserID;
  10060. int sectionId = CurrentUser.UserPost.OrgID;
  10061. StringBuilder sql = new StringBuilder();
  10062. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10063. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10064. List<string> ids = new List<string>();
  10065. if (dth.Rows.Count > 0)
  10066. {
  10067. foreach (DataRow dr in dth.Rows)
  10068. {
  10069. ids.Add(dr["ID"].ToString());
  10070. }
  10071. try
  10072. {
  10073. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10074. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10075. }
  10076. catch (Exception ex)
  10077. {
  10078. }
  10079. }
  10080. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10081. }
  10082. public void change_order_info()
  10083. {
  10084. int userid = CurrentUser.UserID;
  10085. StringBuilder sql = new StringBuilder();
  10086. 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);
  10087. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10088. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10089. }
  10090. public void change_win_mome()
  10091. {
  10092. if (UrlPostParmsCheck("id,ctid"))
  10093. {
  10094. string id = GetPostString("id");
  10095. string ctid = GetPostString("ctid");
  10096. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10097. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10098. if (ce == null || ceErpMessageTip == null)
  10099. {
  10100. returnSuccessMsg("未找到对应的订单!");
  10101. return;
  10102. }
  10103. if (ce.OrderState >= 5)
  10104. {
  10105. ceErpMessageTip.isVisit = true;
  10106. ceErpMessageTip.Update();
  10107. returnSuccessMsg("已上传文件无法修改!");
  10108. return;
  10109. }
  10110. int type = GetPostInt("type");
  10111. string content = GetPostString("content");
  10112. if (type == 0)
  10113. {
  10114. content = content.Replace("(", "(");
  10115. content = content.Replace(")", ")");
  10116. string check = MidStrEx(content, "(", ")").Trim();
  10117. if (string.IsNullOrEmpty(check))
  10118. {
  10119. returnSuccessMsg("文件名格式不正确");
  10120. return;
  10121. }
  10122. }
  10123. ce.seller_memo = content;
  10124. ce.Update();
  10125. ceErpMessageTip.isVisit = true;
  10126. ceErpMessageTip.Update();
  10127. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10128. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10129. ApiVo apiVo = new ApiVo();
  10130. apiVo.orderNumber = ce.ctid;
  10131. apiVo.actionName = "demandDesign";
  10132. apiVo.orderRemarks = content;
  10133. apiVo.demandExamine = type + 1;
  10134. designHelper.API_WorkCore(apiVo);//demandDesign
  10135. returnSuccessMsg("修改成功!");
  10136. }
  10137. }
  10138. public static string MidStrEx(string sourse, string startstr, string endstr)
  10139. {
  10140. string result = string.Empty;
  10141. int startindex, endindex;
  10142. try
  10143. {
  10144. startindex = sourse.IndexOf(startstr);
  10145. if (startindex == -1)
  10146. return result;
  10147. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10148. endindex = tmpstr.IndexOf(endstr);
  10149. if (endindex == -1)
  10150. return result;
  10151. result = tmpstr.Remove(endindex);
  10152. }
  10153. catch (Exception ex)
  10154. {
  10155. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10156. }
  10157. return result;
  10158. }
  10159. public void refund_order_list()
  10160. {
  10161. int userid = CurrentUser.UserID;
  10162. int sectionId = CurrentUser.UserPost.OrgID;
  10163. StringBuilder sql = new StringBuilder();
  10164. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10165. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10166. DataStruct dStruct = GetPostStruct();
  10167. DataTable dt = null;
  10168. List<string> ids = new List<string>();
  10169. List<string> tids = new List<string>();
  10170. if (dth.Rows.Count > 0)
  10171. {
  10172. foreach (DataRow dr in dth.Rows)
  10173. {
  10174. tids.Add("'" + dr["tid"].ToString() + "'");
  10175. ids.Add(dr["id"].ToString());
  10176. }
  10177. try
  10178. {
  10179. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10180. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10181. List<string> lw = new List<string>();
  10182. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10183. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10184. dt = WebCache.GetData("view_orderlist", dStruct);
  10185. }
  10186. catch (Exception ex)
  10187. {
  10188. }
  10189. }
  10190. writeGridDataTableJson(dStruct.TotalCount, dt);
  10191. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10192. }
  10193. //新增
  10194. public void order_batch_downloads()
  10195. {
  10196. string ceid = GetPostString("tid");
  10197. String[] tid = ceid.Split(',');
  10198. order_batch_caiyingtong(tid);
  10199. /* (string success, string errors) = UploadFiles(tid);
  10200. returnSuccessMsg(success + errors);*/
  10201. return;
  10202. }
  10203. //报价接口
  10204. public void Get_To_Quote()
  10205. {
  10206. string ceid = GetPostString("ctid");
  10207. if (ceid != null)
  10208. {
  10209. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10210. if (entity != null)
  10211. {
  10212. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10213. {
  10214. return;
  10215. }
  10216. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10217. double price = 0;
  10218. if (cp == null)
  10219. {
  10220. JObject jsonObject12 = new JObject
  10221. {
  10222. { "UserId", "77886" },
  10223. { "Pwd", "lt666888" },
  10224. { "Filename", entity.seller_memo }
  10225. };
  10226. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10227. JObject jsonObjects1 = JObject.Parse(response1);
  10228. string ms1g = (string)jsonObjects1["msg"];
  10229. if (ms1g == "报价成功")
  10230. {
  10231. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10232. string data = (string)jsonObject1["price"];
  10233. 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 + "');";
  10234. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10235. returnSuccessMsg("获取报价成功:" + data);
  10236. price = Convert.ToDouble(data);
  10237. }
  10238. else
  10239. {
  10240. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10241. return;
  10242. }
  10243. }
  10244. String[] beizhu = entity.seller_memo.Split('-');
  10245. String chanp = "";
  10246. if (beizhu.Length > 0)
  10247. {
  10248. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10249. }
  10250. else
  10251. {
  10252. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10253. }
  10254. JObject jsonObject = new JObject
  10255. {
  10256. { "UserId", "77886" },
  10257. { "Pwd", "lt666888" },
  10258. { "Filename", chanp }
  10259. };
  10260. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10261. JObject jsonObjects = JObject.Parse(response);
  10262. string msg = (string)jsonObjects["msg"];
  10263. if (msg == "报价成功")
  10264. {
  10265. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10266. string data = (string)jsonObject1["price"];
  10267. 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 + "');";
  10268. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10269. returnSuccessMsg("获取报价成功:" + data);
  10270. price = Convert.ToDouble(data);
  10271. }
  10272. else
  10273. {
  10274. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10275. return;
  10276. }
  10277. if (price > 0)
  10278. {
  10279. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10280. if (ceErpTradeCellExtend == null)
  10281. {
  10282. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10283. ceErpTradeCellExtend.ctid = entity.ctid;
  10284. ceErpTradeCellExtend.payment_cyt = price;
  10285. ceErpTradeCellExtend.Create();
  10286. }
  10287. else
  10288. {
  10289. ceErpTradeCellExtend.payment_cyt = price;
  10290. ceErpTradeCellExtend.Update();
  10291. }
  10292. }
  10293. return;
  10294. }
  10295. }
  10296. else
  10297. {
  10298. returnErrorMsg("请至少选择一条数据");
  10299. return;
  10300. }
  10301. }
  10302. //新增
  10303. public void order_To_Supplier()
  10304. {
  10305. string ceid = GetPostString("tid");
  10306. String[] tid = ceid.Split(',');
  10307. if (tid.Length > 0)
  10308. {
  10309. try
  10310. {
  10311. for (int i = 0; i < tid.Length; i++)
  10312. {
  10313. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10314. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10315. entity.SupplierId = suid;
  10316. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10317. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10318. entity.Update();
  10319. }
  10320. }
  10321. catch (Exception ex)
  10322. {
  10323. returnErrorMsg("自动匹配供应商失败");
  10324. return;
  10325. }
  10326. }
  10327. else
  10328. {
  10329. returnErrorMsg("请至少选择一条数据");
  10330. return;
  10331. }
  10332. returnSuccessMsg("自动匹配供应商成功");
  10333. return;
  10334. }
  10335. public (string, string) UploadFiles(string[] urls)
  10336. {
  10337. string success = "";
  10338. string errors = "";
  10339. int userid = CurrentUser.UserID;
  10340. foreach (string url in urls)
  10341. {
  10342. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10343. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10344. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10345. {
  10346. JObject jsonObject = new JObject
  10347. {
  10348. { "Userid", "77886" },
  10349. { "pwd", "cyt86435015" },
  10350. { "content", base64FileContent },
  10351. { "ext", Path.GetExtension(fileName) }
  10352. };
  10353. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10354. JObject jsonObjects = JObject.Parse(response);
  10355. string msg = (string)jsonObjects["msg"];
  10356. if (msg.Equals("上传成功"))
  10357. {
  10358. success += url + " 上传成功";
  10359. }
  10360. else
  10361. {
  10362. errors += url + " 上传失败";
  10363. }
  10364. }
  10365. else
  10366. {
  10367. errors += url + " 格式出现问题";
  10368. }
  10369. }
  10370. if (urls.Length == 0)
  10371. {
  10372. return (success, errors);
  10373. }
  10374. return (success, errors);
  10375. }
  10376. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10377. {
  10378. return true; //总是接受
  10379. }
  10380. public static string HttpPost(string url, string param = null)
  10381. {
  10382. HttpWebRequest request;
  10383. //如果是发送HTTPS请求
  10384. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10385. {
  10386. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10387. request = WebRequest.Create(url) as HttpWebRequest;
  10388. request.ProtocolVersion = HttpVersion.Version10;
  10389. }
  10390. else
  10391. {
  10392. request = WebRequest.Create(url) as HttpWebRequest;
  10393. }
  10394. request.Method = "POST";
  10395. request.ContentType = "application/json";
  10396. request.Accept = "*/*";
  10397. request.Timeout = 120000;
  10398. request.AllowAutoRedirect = false;
  10399. StreamWriter requestStream = null;
  10400. WebResponse response = null;
  10401. string responseStr = null;
  10402. try
  10403. {
  10404. requestStream = new StreamWriter(request.GetRequestStream());
  10405. requestStream.Write(param);
  10406. requestStream.Close();
  10407. response = request.GetResponse();
  10408. if (response != null)
  10409. {
  10410. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10411. responseStr = reader.ReadToEnd();
  10412. reader.Close();
  10413. }
  10414. }
  10415. catch (Exception ex)
  10416. {
  10417. return ex.Message;
  10418. }
  10419. finally
  10420. {
  10421. request = null;
  10422. requestStream = null;
  10423. response = null;
  10424. }
  10425. return responseStr;
  10426. }
  10427. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10428. {
  10429. string base64FileContent;
  10430. string fileName;
  10431. using (WebClient webClient = new WebClient())
  10432. {
  10433. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10434. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10435. {
  10436. using (Stream stream = response.GetResponseStream())
  10437. {
  10438. using (MemoryStream memoryStream = new MemoryStream())
  10439. {
  10440. stream.CopyTo(memoryStream);
  10441. byte[] fileBytes = memoryStream.ToArray();
  10442. base64FileContent = Convert.ToBase64String(fileBytes);
  10443. fileName = response.Headers["Content-Disposition"];
  10444. if (!string.IsNullOrEmpty(fileName))
  10445. {
  10446. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10447. if (index >= 0)
  10448. {
  10449. fileName = fileName.Substring(index + 9).Trim('\"');
  10450. }
  10451. }
  10452. else
  10453. {
  10454. fileName = Path.GetFileName(downloadUrl);
  10455. }
  10456. }
  10457. }
  10458. }
  10459. }
  10460. return (fileName, base64FileContent);
  10461. }
  10462. //新增
  10463. public void order_batch_caiyingtong(string[] downloadUrls)
  10464. {
  10465. try
  10466. {
  10467. //遍历文件
  10468. DataStruct dStruct = GetPostStruct();
  10469. DataTable dt = null;
  10470. int userid = CurrentUser.UserID;
  10471. List<string> ids = new List<string>();//失败组
  10472. List<string> tids = new List<string>();
  10473. using (WebClient webClient = new WebClient())
  10474. {
  10475. foreach (var url in downloadUrls)
  10476. {
  10477. try
  10478. {
  10479. tids.Add("'" + url + "'");
  10480. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10481. if (entity != null)
  10482. {
  10483. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10484. if (cp == null)
  10485. {
  10486. JObject jsonObject = new JObject
  10487. {
  10488. { "Userid", "77886" },
  10489. { "pwd", "lt666888" },
  10490. { "Filename",entity.seller_memo }
  10491. };
  10492. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10493. JObject jsonObjects = JObject.Parse(response);
  10494. string msg = (string)jsonObjects["msg"];
  10495. if (msg == "报价成功")
  10496. {
  10497. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10498. DownloadAndConvertToBase64(url1);
  10499. }
  10500. else
  10501. {
  10502. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10503. }
  10504. }
  10505. else
  10506. {
  10507. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10508. JObject jsonObject = new JObject
  10509. {
  10510. { "Userid", "77886" },
  10511. { "pwd", "lt666888" },
  10512. { "Filename",chanp }
  10513. };
  10514. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10515. JObject jsonObjects = JObject.Parse(response);
  10516. string msg = (string)jsonObjects["msg"];
  10517. if (msg == "报价成功")
  10518. {
  10519. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10520. DownloadAndConvertToBase64(url1);
  10521. }
  10522. else
  10523. {
  10524. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10525. }
  10526. }
  10527. }
  10528. // 上传文件到FTP
  10529. }
  10530. catch (Exception ex)
  10531. {
  10532. Console.WriteLine($"An error occurred: {ex.Message}");
  10533. }
  10534. }
  10535. List<string> lw = new List<string>();
  10536. lw.Add(string.Format("( OrderState < 6 )"));
  10537. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10538. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10539. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10540. if (dt.Rows.Count > 0)
  10541. {
  10542. foreach (DataRow dr in dt.Rows)
  10543. {
  10544. ids.Add(dr["ctid"].ToString());
  10545. }
  10546. }
  10547. String ErrorMsgs = "";
  10548. foreach (String id in ids)
  10549. {
  10550. ErrorMsgs += id + ",";
  10551. }
  10552. if (ErrorMsgs.Length > 1)
  10553. {
  10554. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10555. }
  10556. if (ErrorMsgs.Length < 1)
  10557. {
  10558. ErrorMsgs = "上传成功";
  10559. returnSuccessMsg(ErrorMsgs);
  10560. }
  10561. else
  10562. {
  10563. returnErrorMsg("以下订单" + ErrorMsgs);
  10564. }
  10565. }
  10566. // 删除文件夹及其内容
  10567. /* Directory.Delete(localDirectory, true);*/
  10568. }
  10569. catch { }
  10570. }
  10571. public void get_center_data()
  10572. {
  10573. int userId = CurrentUser.UserID;
  10574. string postCode = CurrentUser.UserPost.Post.Code;
  10575. List<string> lw = new List<string>();
  10576. List<string> ww = new List<string>();
  10577. DateTime currentTime = DateTime.Now;
  10578. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10579. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10580. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10581. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10582. string sql = " SELECT ";
  10583. string startTime = "2023-10-01 11:22:31";
  10584. //设计
  10585. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10586. {
  10587. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10588. 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));
  10589. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10590. 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));
  10591. }
  10592. //客服
  10593. else if (postCode == "CustomerService" || postCode == "Director")
  10594. {
  10595. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10596. 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));
  10597. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10598. 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));
  10599. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10600. 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));
  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 = 0 AND ReturnTime IS NOT NULL AND pay_time > '{0}' AND CustomerUserId = {1} ) AS bc", startTime, userId));
  10603. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10604. 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));
  10605. }
  10606. //售后
  10607. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10608. {
  10609. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10610. 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));
  10611. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10612. 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));
  10613. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10614. 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));
  10615. }
  10616. //下单部
  10617. else if (postCode == "Place" || postCode == "PlaceMr")
  10618. {
  10619. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10620. 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));
  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. }
  10624. //车间
  10625. else if (postCode == "Supplier")
  10626. {
  10627. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10628. 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));
  10629. }
  10630. DataTable dt = new DataTable();
  10631. if (lw.Count > 0)
  10632. {
  10633. sql += string.Join(" , ", lw);
  10634. sql += " FROM ";
  10635. sql += string.Join(" , ", ww);
  10636. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10637. }
  10638. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10639. }
  10640. public void get_center_data_list()
  10641. {
  10642. int userId = CurrentUser.UserID;
  10643. string postCode = CurrentUser.UserPost.Post.Code;
  10644. string shopIds = CurrentUser.User.pemShop;
  10645. DataStruct dStruct = GetPostStruct();
  10646. List<string> lw = new List<string>();
  10647. DateTime currentTime = DateTime.Now;
  10648. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10649. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10650. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10651. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10652. string startTime = "2023-10-01 11:22:31";
  10653. int order_type = GetPostInt("order_type");
  10654. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10655. {
  10656. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10657. if (order_type == 0)
  10658. {
  10659. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10660. }
  10661. else if (order_type == 3)
  10662. {
  10663. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10664. }
  10665. else
  10666. {
  10667. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10668. }
  10669. }
  10670. //客服
  10671. if (postCode == "CustomerService" || postCode == "Director")
  10672. {
  10673. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10674. if (order_type == 0)
  10675. {
  10676. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10677. }
  10678. else if (order_type == 1)
  10679. {
  10680. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10681. }
  10682. else if (order_type == 2)
  10683. {
  10684. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10685. }
  10686. else if (order_type == 3)
  10687. {
  10688. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10689. }
  10690. else if (order_type == 4)
  10691. {
  10692. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10693. }
  10694. else
  10695. {
  10696. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10697. }
  10698. }
  10699. //售后
  10700. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10701. {
  10702. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10703. if (shopIds != "")
  10704. {
  10705. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10706. }
  10707. if (order_type == 2)
  10708. {
  10709. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10710. }
  10711. else if (order_type == 4)
  10712. {
  10713. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10714. }
  10715. else if (order_type == 5)
  10716. {
  10717. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10718. }
  10719. else
  10720. {
  10721. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10722. }
  10723. }
  10724. //下单部
  10725. if (postCode == "Place" || postCode == "PlaceMr")
  10726. {
  10727. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10728. if (shopIds != "")
  10729. {
  10730. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10731. }
  10732. else if (order_type == 1)
  10733. {
  10734. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10735. }
  10736. else if (order_type == 2)
  10737. {
  10738. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10739. }
  10740. else
  10741. {
  10742. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10743. }
  10744. }
  10745. //车间
  10746. if (postCode == "Supplier")
  10747. {
  10748. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10749. if (order_type == 5)
  10750. {
  10751. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10752. }
  10753. else
  10754. {
  10755. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10756. }
  10757. }
  10758. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10759. dStruct.Fileds = "tid,ctid";
  10760. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10761. writeGridDataTableJson(dStruct.TotalCount, dt);
  10762. }
  10763. public void aftersale_audit_master()
  10764. {
  10765. if (UrlPostParmsCheck("ctid"))
  10766. {
  10767. string ctid = GetPostString("ctid");
  10768. if (ctid.Length > 0)
  10769. {
  10770. bool result = aftersale_data_change(ctid);
  10771. if (result)
  10772. {
  10773. returnSuccessMsg("修改成功!");
  10774. return;
  10775. }
  10776. }
  10777. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10778. }
  10779. }
  10780. public void aftersale_batch_audit_master()
  10781. {
  10782. if (UrlPostParmsCheck("ctids"))
  10783. {
  10784. string ctids = GetPostString("ctids");
  10785. if (ctids.Length > 0)
  10786. {
  10787. List<string> list = new List<string>();
  10788. string[] ctid_list = ctids.Split(',');
  10789. foreach (var item in ctid_list)
  10790. {
  10791. bool result = aftersale_data_change(item);
  10792. if (!result)
  10793. {
  10794. list.Add(item);
  10795. }
  10796. }
  10797. if (list.Count > 0)
  10798. {
  10799. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10800. return;
  10801. }
  10802. returnSuccessMsg("修改成功!");
  10803. return;
  10804. }
  10805. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10806. }
  10807. }
  10808. public bool aftersale_data_change(string ctid)
  10809. {
  10810. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10811. if (ceErpTradeCell != null)
  10812. {
  10813. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10814. ceErpTradeCell.AfterSaleSupplierState = 0;
  10815. StringBuilder sql = new StringBuilder();
  10816. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10817. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10818. CeErpTradeResponsible.DelByTid(ctid, 0);
  10819. 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 == "不理赔")
  10820. {
  10821. CeErpTradeResponsible.DelByTid(ctid, 1);
  10822. ceErpTradeCell.AfterSaleSupplierState = 1;
  10823. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10824. ceErpTradeCell.AfterSaleState = 4;
  10825. }
  10826. else
  10827. {
  10828. ceErpTradeCell.AfterSaleState = 3;
  10829. }
  10830. bool needCyt = false;
  10831. if (dt != null)
  10832. {
  10833. if (dt.Rows.Count == 1)
  10834. {
  10835. bool isEnd = false;
  10836. foreach (DataRow dr in dt.Rows)
  10837. {
  10838. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10839. {
  10840. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10841. isEnd = true;
  10842. }
  10843. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10844. {
  10845. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10846. isEnd = true;
  10847. }
  10848. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10849. {
  10850. needCyt = true;
  10851. }
  10852. }
  10853. if (isEnd)
  10854. {
  10855. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10856. ceErpTradeCell.AfterSaleState = 4;
  10857. ceErpTradeCell.AfterSaleSupplierState = 1;
  10858. }
  10859. }
  10860. else
  10861. {
  10862. bool isAll = true;
  10863. foreach (DataRow dr in dt.Rows)
  10864. {
  10865. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10866. {
  10867. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10868. continue;
  10869. }
  10870. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10871. {
  10872. string path = "";
  10873. int OrgID = 0;
  10874. if (!Convert.IsDBNull(dr["OrgPath"]))
  10875. {
  10876. path = dr["OrgPath"].ToString();
  10877. }
  10878. if (!Convert.IsDBNull(dr["OrgID"]))
  10879. {
  10880. OrgID = Convert.ToInt32(dr["OrgID"]);
  10881. }
  10882. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10883. {
  10884. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10885. continue;
  10886. }
  10887. }
  10888. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10889. {
  10890. needCyt = true;
  10891. }
  10892. isAll = false;
  10893. }
  10894. if (isAll)
  10895. {
  10896. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10897. ceErpTradeCell.AfterSaleState = 4;
  10898. ceErpTradeCell.AfterSaleSupplierState = 1;
  10899. }
  10900. }
  10901. }
  10902. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10903. {
  10904. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10905. }
  10906. if (ceErpTradeCell.AfterSaleState == 4)
  10907. {
  10908. ApiVo apiVo = new ApiVo();
  10909. apiVo.orderNumber = ceErpTradeCell.ctid;
  10910. apiVo.actionName = "afterOver";
  10911. designHelper.API_WorkCore(apiVo); //afterOver
  10912. }
  10913. ceErpTradeCell.Update();
  10914. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10915. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10916. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10917. return true;
  10918. }
  10919. return false;
  10920. }
  10921. public void get_erp_wechatorder()
  10922. {
  10923. DataStruct dStruct = GetPostStruct();
  10924. List<string> lw = new List<string>();
  10925. string tid = GetPostString("tid");
  10926. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10927. string shopname = GetPostString("shopname");
  10928. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10929. string buyernick = GetPostString("buyer_nick");
  10930. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10931. string customer = GetPostString("customer");
  10932. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10933. string returndate1 = GetPostString("returndate1");
  10934. string returndate2 = GetPostString("returndate2");
  10935. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10936. if (dw.Length > 0) lw.Add(dw);
  10937. string finishDate1 = GetPostString("finishdate1");
  10938. string finishDate2 = GetPostString("finishdate2");
  10939. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10940. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10941. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10942. dStruct.Order = "created desc";
  10943. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10944. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10945. writeGridDataTableJson(dStruct.TotalCount, dt);
  10946. }
  10947. public void get_erp_wechatlist_sumprice()
  10948. {
  10949. DataStruct dStruct = GetPostStruct();
  10950. List<string> lw = new List<string>();
  10951. string tid = GetPostString("tid");
  10952. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10953. string shopname = GetPostString("shopname");
  10954. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10955. string buyernick = GetPostString("buyer_nick");
  10956. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10957. string customer = GetPostString("customer");
  10958. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10959. string returndate1 = GetPostString("returndate1");
  10960. string returndate2 = GetPostString("returndate2");
  10961. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10962. if (dw.Length > 0) lw.Add(dw);
  10963. string finishDate1 = GetPostString("finishdate1");
  10964. string finishDate2 = GetPostString("finishdate2");
  10965. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10966. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10967. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10968. string mainWhere = string.Join(" and ", lw.ToArray());
  10969. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10970. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10971. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10972. decimal total = 0;
  10973. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10974. {
  10975. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10976. }
  10977. var res = new
  10978. {
  10979. data = total
  10980. };
  10981. string ro_jsond = JsonConvert.SerializeObject(res);
  10982. returnSuccess(ro_jsond);
  10983. return;
  10984. }
  10985. public void get_erp_qr_waitdeliverylist()
  10986. {
  10987. DataStruct dStruct = GetPostStruct();
  10988. List<string> lw = new List<string>();
  10989. string tid = GetPostString("ctid");
  10990. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10991. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10992. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10993. var res_objz = new
  10994. {
  10995. restype = 1,
  10996. data = dt
  10997. };
  10998. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10999. returnSuccess(ro_jsonz);
  11000. }
  11001. public void get_erp_yield_list()
  11002. {
  11003. DataStruct dStruct = GetPostStruct();
  11004. List<string> lw = new List<string>();
  11005. string tid = GetPostString("ctid");
  11006. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11007. string shopname = GetPostString("shopname");
  11008. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11009. string buyernick = GetPostString("buyer_nick");
  11010. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11011. //if (tid.Length == 0 && buyernick.Length == 0)
  11012. //{
  11013. // lw.Add(string.Format("IsRefund<={0}", 1));
  11014. //}
  11015. string customer = GetPostString("customer");
  11016. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11017. string design = GetPostString("design");
  11018. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11019. string orderState = GetPostString("orderState");
  11020. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11021. string address = GetPostString("address");
  11022. 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));
  11023. string sellermemo = GetPostString("seller_memo");
  11024. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11025. string supplier = GetPostString("supplier");
  11026. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11027. string OrderArea = GetPostString("order_area");
  11028. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11029. string placedate1 = GetPostString("placedate1");
  11030. string placedate2 = GetPostString("placedate2");
  11031. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11032. if (fdw.Length > 0) lw.Add(fdw);
  11033. string price1 = GetPostString("price1");
  11034. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11035. string price2 = GetPostString("price2");
  11036. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11037. string unusualCon = GetPostString("unusualcon");
  11038. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11039. string posTag = CurrentUser.UserPost.Post.Code;
  11040. if (posTag == "Supplier")
  11041. {
  11042. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11043. }
  11044. lw.Add(string.Format("OrderState = 6 "));
  11045. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11046. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11047. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11048. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11049. writeGridDataTableJson(dStruct.TotalCount, dt);
  11050. }
  11051. public void change_erp_sup_state()
  11052. {
  11053. if (UrlPostParmsCheck("ctid"))
  11054. {
  11055. string ctid = GetPostString("ctid");
  11056. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11057. if (ceErpTradeCell != null)
  11058. {
  11059. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11060. if (ceErpTradeCellExtend == null)
  11061. {
  11062. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11063. ceErpTradeCellExtend.ctid = ctid;
  11064. ceErpTradeCellExtend.SupState = 1;
  11065. ceErpTradeCellExtend.Create();
  11066. }
  11067. else
  11068. {
  11069. ceErpTradeCellExtend.SupState = 1;
  11070. ceErpTradeCellExtend.Update();
  11071. }
  11072. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11073. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11074. return;
  11075. }
  11076. returnErrorMsg("找不到订单");
  11077. }
  11078. }
  11079. public void supplier_all_downs()
  11080. {
  11081. if (UrlPostParmsCheck("tids"))
  11082. {
  11083. string tids = GetPostString("tids");
  11084. if (tids != null && tids.Length > 0)
  11085. {
  11086. StringBuilder sql = new StringBuilder();
  11087. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11088. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11089. sql = new StringBuilder();
  11090. 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, "下载设计文件");
  11091. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11092. string[] list = tids.Split(',');
  11093. foreach (string ctid in list)
  11094. {
  11095. CeErpSukuraData.createInfo(ctid, 3);
  11096. }
  11097. designHelper.api_approveDesign(tids); //approveDesign
  11098. returnSuccessMsg("下载成功!");
  11099. return;
  11100. }
  11101. returnErrorMsg("下载订单更新失败");
  11102. }
  11103. }
  11104. public void uploaderFileSuccess()
  11105. {
  11106. if (UrlPostParmsCheck("fileName"))
  11107. {
  11108. string fileName = GetPostString("fileName");
  11109. ApiVo apiVo = new ApiVo();
  11110. apiVo.orderNumber = fileName;
  11111. apiVo.actionName = "finishDesign";
  11112. designHelper.API_WorkCore(apiVo);//finishDesign
  11113. returnSuccessMsg("");
  11114. }
  11115. }
  11116. public void get_sample2_order()
  11117. {
  11118. if (UrlPostParmsCheck("ctid"))
  11119. {
  11120. string ctid = GetPostString("ctid");
  11121. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11122. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11123. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11124. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11125. double total = 0.0;
  11126. double order_price = 0.0;
  11127. if (dt_bu.Rows.Count > 0)
  11128. {
  11129. foreach (DataRow dr in dt_bu.Rows)
  11130. {
  11131. total += Convert.ToDouble(dr["payment"]);
  11132. }
  11133. }
  11134. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11135. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11136. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11137. string tid = ctid.Replace("S_", "");
  11138. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11139. double paymant = 0.0;
  11140. if (entity != null)
  11141. {
  11142. paymant = entity.payment;
  11143. }
  11144. string return_reason = "";
  11145. if (dt_after != null && dt_after.Rows.Count > 0)
  11146. {
  11147. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11148. }
  11149. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11150. }
  11151. }
  11152. public void get_erp_design_status()
  11153. {
  11154. string designName = GetPostString("designName");
  11155. DataStruct dStruct = GetPostStruct();
  11156. if (designName.Length > 0)
  11157. {
  11158. 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";
  11159. sql_user += " and Name like '%" + designName + "%'";
  11160. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11161. List<string> ids_list = new List<string>();
  11162. if (user_table.Rows.Count > 0)
  11163. {
  11164. foreach (DataRow item in user_table.Rows)
  11165. {
  11166. ids_list.Add(item["id"].ToString());
  11167. string ids_s = item["TeamIds"].ToString();
  11168. if (ids_s.Length > 0)
  11169. {
  11170. ids_list.AddRange(ids_s.Split(','));
  11171. }
  11172. }
  11173. }
  11174. HashSet<string> set = new HashSet<string>(ids_list);
  11175. ids_list = set.ToList();
  11176. if (ids_list.Count > 0)
  11177. {
  11178. 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));
  11179. dStruct.MainWhere = sql;
  11180. DataTable dt = null;
  11181. dt = WebCache.GetData("view_ErpUser", dStruct);
  11182. writeGridDataTableJson(dStruct.TotalCount, dt);
  11183. }
  11184. }
  11185. }
  11186. public void change_erp_order_price()
  11187. {
  11188. string ctid = GetPostString("ctid");
  11189. double price = GetPostDouble("price");
  11190. if (ctid.Length > 0)
  11191. {
  11192. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11193. if (ceErpTradeCellExtend == null)
  11194. {
  11195. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11196. ceErpTradeCellExtend.ctid = ctid;
  11197. ceErpTradeCellExtend.payment_cyt = price;
  11198. ceErpTradeCellExtend.Create();
  11199. }
  11200. else
  11201. {
  11202. ceErpTradeCellExtend.payment_cyt = price;
  11203. ceErpTradeCellExtend.Update();
  11204. }
  11205. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11206. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11207. {
  11208. ceErpDataSendOrderInfo.isSync = false;
  11209. ceErpDataSendOrderInfo.Update();
  11210. }
  11211. if (ceErpDataSendOrderInfo == null)
  11212. {
  11213. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11214. ceErpDataSendOrderInfo.isSync = false;
  11215. ceErpDataSendOrderInfo.ctid = ctid;
  11216. ceErpDataSendOrderInfo.Create();
  11217. }
  11218. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11219. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11220. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11221. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11222. {
  11223. dataSendOrderBean dataSendOrderBean = null;
  11224. foreach (DataRow item in dth.Rows)
  11225. {
  11226. try
  11227. {
  11228. dataSendOrderBean = new dataSendOrderBean();
  11229. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11230. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11231. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11232. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11233. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11234. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11235. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11236. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11237. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11238. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11239. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11240. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11241. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11242. if (result != null)
  11243. {
  11244. if ("0".Equals(result.errcode))
  11245. {
  11246. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11247. }
  11248. else
  11249. {
  11250. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11251. }
  11252. }
  11253. }
  11254. catch (Exception ex)
  11255. {
  11256. }
  11257. }
  11258. }
  11259. returnSuccessMsg("修改成功!");
  11260. return;
  11261. }
  11262. returnErrorMsg("找不到订单");
  11263. }
  11264. public void find_he_together()
  11265. {
  11266. string ctid = GetPostString("ctid");
  11267. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11268. List<string> list = new List<string>();
  11269. if (ceErpTradeCell != null)
  11270. {
  11271. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11272. {
  11273. 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);
  11274. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11275. if (table != null && table.Rows.Count > 0)
  11276. {
  11277. foreach (TableRow row in table.Rows)
  11278. {
  11279. }
  11280. }
  11281. }
  11282. }
  11283. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11284. }
  11285. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11286. {
  11287. //chy----19
  11288. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11289. //GD-CYT-----64
  11290. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11291. //ZHX----3
  11292. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11293. //JK----97
  11294. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11295. //ZT----70
  11296. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11297. //LHCY-----98
  11298. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11299. //XD-----90
  11300. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11301. //CYCY-----14
  11302. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11303. };
  11304. //其他改名
  11305. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11306. {
  11307. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11308. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11309. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11310. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11311. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11312. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11313. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11314. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11315. };
  11316. //不统计
  11317. List<int> no_suppliers = new List<int>()
  11318. {
  11319. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11320. };
  11321. //配件单
  11322. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11323. {
  11324. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11325. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11326. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11327. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11328. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11329. {"旗杆",new List<string>(){ "班旗" } },
  11330. {"牙签",new List<string>(){ "不干胶" } }
  11331. };
  11332. public void get_place_order_data()
  11333. {
  11334. string date1 = GetPostString("date1");
  11335. string date2 = GetPostString("date2");
  11336. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11337. DateTime start = DateTime.Parse(starttime);
  11338. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11339. DateTime end = DateTime.Parse(endtime);
  11340. if (date1 != null && date1.Length > 0)
  11341. {
  11342. DateTime dateTime = DateTime.Parse(date1);
  11343. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11344. start = DateTime.Parse(starttime);
  11345. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11346. end = DateTime.Parse(endtime);
  11347. }
  11348. if (date2 != null && date2.Length > 0)
  11349. {
  11350. DateTime dateTime = DateTime.Parse(date2);
  11351. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11352. end = DateTime.Parse(endtime);
  11353. }
  11354. 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);
  11355. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11356. //不干胶-----1,卡片-----29
  11357. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11358. foreach (DataRow row in data.Rows)
  11359. {
  11360. int productId = Convert.ToInt32(row["ProductId"]);
  11361. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11362. if (no_suppliers.Contains(supplierId))
  11363. {
  11364. continue;
  11365. }
  11366. string seller_memo = row["seller_memo"].ToString();
  11367. bool ispj = false;//是否配件单
  11368. bool isfirst = true;//第一个配
  11369. maps.Keys.ForEach(key =>
  11370. {
  11371. //备注包含配件
  11372. if (seller_memo.Contains(key) && isfirst)
  11373. {
  11374. List<string> list = maps[key];
  11375. ispj = true;
  11376. isfirst = false;
  11377. for (int i = 0; i < list.Count; i++)
  11378. {
  11379. if (seller_memo.Contains(list[i]))
  11380. {
  11381. ispj = false;
  11382. break;
  11383. }
  11384. }
  11385. }
  11386. });
  11387. if (ispj)
  11388. {
  11389. continue;
  11390. }
  11391. seller_memo = seller_memo.Replace("UV", "uv");
  11392. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11393. //吊牌归到卡片
  11394. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11395. seller_memo = seller_memo.Replace("卡套", "卡片");
  11396. seller_memo = seller_memo.Replace("封套", "卡片");
  11397. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11398. seller_memo = seller_memo.Replace("腰封", "卡片");
  11399. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11400. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11401. seller_memo = seller_memo.Replace("横幅", "条幅");
  11402. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11403. string map_key = "";
  11404. string type = "";
  11405. if (supplierMap.ContainsKey(supplierId))
  11406. {
  11407. foreach (var kvp in supplierMap[supplierId])
  11408. {
  11409. if (seller_memo.Contains(kvp.Key))
  11410. {
  11411. map_key = kvp.Value;
  11412. type = kvp.Value;
  11413. break;
  11414. }
  11415. }
  11416. }
  11417. if (map_key == "")
  11418. {
  11419. type = "其他";
  11420. map_key = "其他";
  11421. }
  11422. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11423. {
  11424. map_key = suppliers[supplierId];
  11425. }
  11426. if (supplierId == 70)
  11427. {
  11428. supplierId = 70;
  11429. }
  11430. map_key += "_" + row["SupplierName"].ToString();
  11431. Dictionary<string, int> map = null;
  11432. if (other_map.ContainsKey(map_key))
  11433. {
  11434. other_map.TryGetValue(map_key, out map);
  11435. }
  11436. else
  11437. {
  11438. map = new Dictionary<string, int>();
  11439. map.Add("dayDev", 0);//当天出货
  11440. map.Add("dayTotal", 0);//下单总数
  11441. map.Add("payTotal", 0);//500以上
  11442. map.Add("today", 0);//当天出货数量
  11443. map.Add("unusua", 0);//异常数
  11444. other_map.Add(map_key, map);
  11445. other_map.TryGetValue(map_key, out map);
  11446. }
  11447. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11448. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11449. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11450. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11451. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11452. {
  11453. map["dayTotal"]++;
  11454. if (supplierId == 97)
  11455. {
  11456. supplierId = 97;
  11457. }
  11458. }
  11459. if (Convert.ToDecimal(row["payment"]) >= 500)
  11460. {
  11461. map["payTotal"]++;
  11462. }
  11463. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11464. {
  11465. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11466. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11467. {
  11468. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11469. {
  11470. map["today"]++;
  11471. }
  11472. }
  11473. else
  11474. {
  11475. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11476. {
  11477. map["today"]++;
  11478. }
  11479. else
  11480. {
  11481. if (supplierId == 119)
  11482. {
  11483. Debug.WriteLine(row["seller_memo"].ToString());
  11484. }
  11485. }
  11486. }
  11487. }
  11488. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11489. {
  11490. map["unusua"]++;
  11491. }
  11492. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11493. //GD-CYT-----64
  11494. DateTime two = palceTimeStart.AddHours(14);
  11495. DateTime three = palceTimeStart.AddHours(15);
  11496. DateTime four = palceTimeStart.AddHours(16);
  11497. DateTime six = palceTimeStart.AddHours(18);
  11498. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11499. {
  11500. //下午四点前 500-1000
  11501. string count = row["ProductCount"].ToString();
  11502. if (count != null && count.Length > 0)
  11503. {
  11504. int productCount = commonHelper.getPlaceProductCount(count);
  11505. if (productCount >= 500 && productCount <= 1000)
  11506. {
  11507. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11508. {
  11509. map["dayDev"]++;
  11510. }
  11511. }
  11512. }
  11513. }
  11514. //UV
  11515. else if ("uv".Equals(type))
  11516. {
  11517. //ZT----70
  11518. //ZHX----3
  11519. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11520. {
  11521. map["dayDev"]++;
  11522. }
  11523. //JK----97
  11524. //HZX----105
  11525. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11526. {
  11527. map["dayDev"]++;
  11528. }
  11529. }
  11530. //帆布---52|条幅---27
  11531. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11532. {
  11533. //LHCY-----98
  11534. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11535. {
  11536. map["dayDev"]++;
  11537. }
  11538. }
  11539. //条幅
  11540. else if ("条幅".Equals(type))
  11541. {
  11542. //XD-----90
  11543. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11544. {
  11545. map["dayDev"]++;
  11546. }
  11547. }
  11548. //桌布
  11549. else if ("桌布".Equals(type))
  11550. {
  11551. //XD-----90
  11552. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11553. {
  11554. map["dayDev"]++;
  11555. }
  11556. }
  11557. //DL---10
  11558. //AYTW---119
  11559. //FS-CYT-DY ----80
  11560. //JK----97
  11561. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11562. {
  11563. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11564. {
  11565. map["dayDev"]++;
  11566. }
  11567. }
  11568. // QC---121
  11569. else if (supplierId == 121)
  11570. {
  11571. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11572. {
  11573. map["dayDev"]++;
  11574. }
  11575. }
  11576. }
  11577. DataTable dt = new DataTable();
  11578. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11579. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11580. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11581. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11582. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11583. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11584. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11585. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11586. other_map.Keys.ForEach(key =>
  11587. {
  11588. DataRow dr = dt.NewRow();
  11589. Dictionary<string, int> map = other_map[key];
  11590. string[] key_list = key.Split('_');
  11591. dr[0] = key_list[0];
  11592. dr[1] = key_list[1];
  11593. if (key_list.Length > 2)
  11594. {
  11595. dr[1] += "(" + key_list[2] + ")";
  11596. }
  11597. dr[2] = map["dayTotal"];
  11598. dr[3] = map["payTotal"];
  11599. dr[4] = map["today"];
  11600. dr[5] = map["unusua"];
  11601. dr[6] = map["dayDev"];
  11602. double rate = 0.00;
  11603. if (map["dayDev"] > 0)
  11604. {
  11605. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11606. }
  11607. dr[7] = rate.ToString();
  11608. dt.Rows.Add(dr);
  11609. });
  11610. DataView dv = new DataView(dt);
  11611. dv.Sort = "SupplierName";
  11612. //dv.Sort = "AllOrder desc";
  11613. DataTable dtNew = dv.ToTable();
  11614. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11615. }
  11616. public void check_order_desing_info()
  11617. {
  11618. string ctid = GetPostString("ctid");
  11619. if (!string.IsNullOrEmpty(ctid))
  11620. {
  11621. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11622. if (ceErpTradeCell != null)
  11623. {
  11624. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11625. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11626. return;
  11627. }
  11628. returnErrorMsg("找不到订单");
  11629. return;
  11630. }
  11631. returnErrorMsg("找不到订单");
  11632. }
  11633. public void get_timeout_detail()
  11634. {
  11635. string poscode = CurrentUser.UserPost.Post.Code;
  11636. DataStruct dStruct = GetPostStruct();
  11637. List<string> lw = new List<string>();
  11638. string id = GetPostString("id");
  11639. string pay_date1 = GetPostString("pay_date1");
  11640. string pay_date2 = GetPostString("pay_date2");
  11641. int type = GetPostInt("type");
  11642. if (type == 0)
  11643. {
  11644. if (pay_date1.Length > 0)
  11645. {
  11646. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11647. }
  11648. if (pay_date2.Length > 0)
  11649. {
  11650. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11651. }
  11652. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11653. }
  11654. if (type == 1)
  11655. {
  11656. if (pay_date1.Length > 0)
  11657. {
  11658. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11659. }
  11660. if (pay_date2.Length > 0)
  11661. {
  11662. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11663. }
  11664. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11665. }
  11666. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11667. DataTable dt = null;
  11668. dt = WebCache.GetData("view_orderlist", dStruct);
  11669. writeGridDataTableJson(dStruct.TotalCount, dt);
  11670. }
  11671. public void saveUrgentChargePrice()
  11672. {
  11673. string ctid = GetPostString("ctid");
  11674. if (!string.IsNullOrEmpty(ctid))
  11675. {
  11676. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11677. if (ceErpTradeCell != null)
  11678. {
  11679. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11680. if (prices <= 100)
  11681. {
  11682. returnErrorMsg("此订单金额不足100元,无法加急。");
  11683. return;
  11684. }
  11685. double price = GetPostDouble("price");
  11686. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11687. if (ceErpTradeCellExtend == null)
  11688. {
  11689. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11690. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11691. }
  11692. ceErpTradeCellExtend.urgentCharge = price;
  11693. if (ceErpTradeCellExtend.ID > 0)
  11694. {
  11695. ceErpTradeCellExtend.Update();
  11696. }
  11697. else
  11698. {
  11699. ceErpTradeCellExtend.Save();
  11700. }
  11701. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11702. returnSuccessMsg("修改成功!");
  11703. return;
  11704. }
  11705. returnErrorMsg("找不到订单");
  11706. return;
  11707. }
  11708. returnErrorMsg("找不到订单");
  11709. }
  11710. public void finish_erp_order()
  11711. {
  11712. string ctid = GetPostString("ctid");
  11713. if (!string.IsNullOrEmpty(ctid))
  11714. {
  11715. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11716. {
  11717. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11718. if (ceErpTradeCell != null)
  11719. {
  11720. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11721. ceErpTradeCell.Update();
  11722. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11723. returnSuccessMsg("修改成功!");
  11724. return;
  11725. }
  11726. }
  11727. }
  11728. returnErrorMsg("找不到订单");
  11729. }
  11730. public void get_trade_order_list()
  11731. {
  11732. string tid = GetPostString("tid");
  11733. if (!string.IsNullOrEmpty(tid))
  11734. {
  11735. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11736. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11737. writeGridDataTableJson(data.Rows.Count, data);
  11738. return;
  11739. }
  11740. returnErrorMsg("找不到订单");
  11741. }
  11742. public void save_cell_spu()
  11743. {
  11744. string ctid = GetPostString("ctid");
  11745. string spu_id = GetPostString("spu_id");
  11746. if (!string.IsNullOrEmpty(ctid))
  11747. {
  11748. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11749. if (ceErpTradeCellExtend == null)
  11750. {
  11751. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11752. ceErpTradeCellExtend.ctid = ctid;
  11753. }
  11754. ceErpTradeCellExtend.spu_id = spu_id;
  11755. if (!string.IsNullOrEmpty(spu_id))
  11756. {
  11757. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11758. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11759. }
  11760. if (ceErpTradeCellExtend.ID == 0)
  11761. {
  11762. ceErpTradeCellExtend.Create();
  11763. }
  11764. else
  11765. {
  11766. ceErpTradeCellExtend.Update();
  11767. }
  11768. returnSuccessMsg("修改成功!");
  11769. return;
  11770. }
  11771. returnErrorMsg("找不到订单");
  11772. }
  11773. public void change_express_info()
  11774. {
  11775. string ctid = GetPostString("ctid");
  11776. string transNo = GetPostString("transNo");
  11777. string transCom = GetPostString("transCom");
  11778. if (!string.IsNullOrEmpty(ctid))
  11779. {
  11780. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11781. if (ceErpTradeCellExtend == null)
  11782. {
  11783. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11784. ceErpTradeCellExtend.ctid = ctid;
  11785. }
  11786. ceErpTradeCellExtend.modExpressNo = transNo;
  11787. ceErpTradeCellExtend.modExpressCom = transCom;
  11788. ceErpTradeCellExtend.readMod = 2;
  11789. if (ceErpTradeCellExtend.ID == 0)
  11790. {
  11791. ceErpTradeCellExtend.Create();
  11792. }
  11793. else
  11794. {
  11795. ceErpTradeCellExtend.Update();
  11796. }
  11797. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11798. returnSuccessMsg("修改成功!");
  11799. return;
  11800. }
  11801. returnErrorMsg("找不到订单");
  11802. }
  11803. public void get_change_express_list()
  11804. {
  11805. DataStruct dStruct = GetPostStruct();
  11806. List<string> lw = new List<string>();
  11807. int st = 2;
  11808. string tid = GetPostString("ctid");
  11809. if (tid.Length > 0)
  11810. {
  11811. string select_tid = getTidByCtid(tid);
  11812. lw.Add(string.Format("tid='{0}'", select_tid));
  11813. }
  11814. string shopname = GetPostString("shopname");
  11815. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11816. string buyernick = GetPostString("buyer_nick");
  11817. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11818. string sellermemo = GetPostString("seller_memo");
  11819. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11820. string supplier = GetPostString("supplier");
  11821. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11822. string customer = GetPostString("customer");
  11823. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11824. string design = GetPostString("design");
  11825. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11826. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11827. string poscode = CurrentUser.UserPost.Post.Code;
  11828. if (poscode != "SysAdmin")
  11829. {
  11830. string shopid = CurrentUser.User.pemShop;
  11831. lw.Add(string.Format("shopId in ({0})", shopid));
  11832. }
  11833. lw.Add("readMod = 2");
  11834. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11835. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11836. writeGridDataTableJson(dStruct.TotalCount, dt);
  11837. }
  11838. public void deal_express_complete()
  11839. {
  11840. string ctid = GetPostString("ctid");
  11841. if (!string.IsNullOrEmpty(ctid))
  11842. {
  11843. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11844. if (ceErpTradeCellExtend == null)
  11845. {
  11846. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11847. ceErpTradeCellExtend.ctid = ctid;
  11848. }
  11849. ceErpTradeCellExtend.readMod = 1;
  11850. if (ceErpTradeCellExtend.ID == 0)
  11851. {
  11852. ceErpTradeCellExtend.Create();
  11853. }
  11854. else
  11855. {
  11856. ceErpTradeCellExtend.Update();
  11857. }
  11858. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11859. returnSuccessMsg("修改成功!");
  11860. return;
  11861. }
  11862. returnErrorMsg("找不到订单");
  11863. }
  11864. public void aftersale_return_visit()
  11865. {
  11866. string ctid = GetPostString("ctid");
  11867. if (!string.IsNullOrEmpty(ctid))
  11868. {
  11869. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11870. if (ceErpTradeCellExtend == null)
  11871. {
  11872. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11873. ceErpTradeCellExtend.ctid = ctid;
  11874. }
  11875. ceErpTradeCellExtend.returnVisit = 1;
  11876. if (ceErpTradeCellExtend.ID == 0)
  11877. {
  11878. ceErpTradeCellExtend.Create();
  11879. }
  11880. else
  11881. {
  11882. ceErpTradeCellExtend.Update();
  11883. }
  11884. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11885. if (ceErpTradeAfterSaleExtend != null)
  11886. {
  11887. ceErpTradeAfterSaleExtend.TextResult = "";
  11888. ceErpTradeAfterSaleExtend.Update();
  11889. }
  11890. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11891. returnSuccessMsg("修改成功!");
  11892. return;
  11893. }
  11894. returnErrorMsg("找不到订单");
  11895. }
  11896. public void orderPlaceInfo()
  11897. {
  11898. string ctids = GetPostString("ctids");
  11899. string[] list = ctids.Split(',');
  11900. foreach (string ctid in list)
  11901. {
  11902. CeErpSukuraData.createInfo(ctid, 3);
  11903. }
  11904. StringBuilder sql = new StringBuilder();
  11905. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11906. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11907. designHelper.api_approveDesign(ctids); //approveDesign
  11908. returnSuccessMsg("");
  11909. }
  11910. public void get_issue_list()
  11911. {
  11912. DataStruct dStruct = GetPostStruct();
  11913. List<string> lw = new List<string>();
  11914. int st = 2;
  11915. string tid = GetPostString("ctid");
  11916. if (tid.Length > 0)
  11917. {
  11918. string select_tid = getTidByCtid(tid);
  11919. lw.Add(string.Format("tid='{0}'", select_tid));
  11920. }
  11921. string shopname = GetPostString("shopname");
  11922. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11923. string buyernick = GetPostString("buyer_nick");
  11924. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11925. string sellermemo = GetPostString("seller_memo");
  11926. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11927. string supplier = GetPostString("supplier");
  11928. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11929. string customer = GetPostString("customer");
  11930. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11931. string design = GetPostString("design");
  11932. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11933. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11934. string poscode = CurrentUser.UserPost.Post.Code;
  11935. if (poscode != "SysAdmin")
  11936. {
  11937. string shopid = CurrentUser.User.pemShop;
  11938. lw.Add(string.Format("shopId in ({0})", shopid));
  11939. }
  11940. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11941. {
  11942. lw.Add("IssueState = 1");
  11943. }
  11944. else
  11945. {
  11946. string iisstate = GetPostString("iisstate");
  11947. if ("1".Equals(iisstate))
  11948. {
  11949. lw.Add("IssueState =1");
  11950. }
  11951. else if ("2".Equals(iisstate))
  11952. {
  11953. lw.Add("IssueState = 2");
  11954. }
  11955. else
  11956. {
  11957. lw.Add("IssueState > 0");
  11958. }
  11959. }
  11960. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11961. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11962. writeGridDataTableJson(dStruct.TotalCount, dt);
  11963. }
  11964. public void saveIssueContent()
  11965. {
  11966. string ctid = GetPostString("ctid");
  11967. if (!string.IsNullOrEmpty(ctid))
  11968. {
  11969. string content = GetPostString("content");
  11970. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11971. if (ceErpTradeAfterSaleExtend == null)
  11972. {
  11973. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11974. ceErpTradeAfterSaleExtend.tid = ctid;
  11975. }
  11976. ceErpTradeAfterSaleExtend.IssueContent = content;
  11977. ceErpTradeAfterSaleExtend.IssueState = 1;
  11978. if (ceErpTradeAfterSaleExtend.ID > 0)
  11979. {
  11980. ceErpTradeAfterSaleExtend.Update();
  11981. }
  11982. else
  11983. {
  11984. ceErpTradeAfterSaleExtend.Create();
  11985. }
  11986. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11987. returnSuccessMsg("添加成功!");
  11988. return;
  11989. }
  11990. returnErrorMsg("找不到订单");
  11991. }
  11992. public void dealIssueContent()
  11993. {
  11994. string ctid = GetPostString("ctid");
  11995. if (!string.IsNullOrEmpty(ctid))
  11996. {
  11997. string content = GetPostString("content");
  11998. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11999. if (ceErpTradeAfterSaleExtend != null)
  12000. {
  12001. ceErpTradeAfterSaleExtend.IssueState = 2;
  12002. ceErpTradeAfterSaleExtend.Update();
  12003. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12004. returnSuccessMsg("修改完成!");
  12005. return;
  12006. }
  12007. }
  12008. returnErrorMsg("找不到订单");
  12009. }
  12010. public void set_tid_attachments()
  12011. {
  12012. string tid = GetPostString("tid");
  12013. string atta = GetPostString("atta");
  12014. if (!string.IsNullOrEmpty(tid))
  12015. {
  12016. if (string.IsNullOrEmpty(atta))
  12017. {
  12018. returnErrorMsg("文件地址为空");
  12019. return;
  12020. }
  12021. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12022. if (ceErpTradeCell != null)
  12023. {
  12024. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12025. if (ceErpTrade == null)
  12026. {
  12027. returnErrorMsg("找不到订单");
  12028. return;
  12029. }
  12030. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12031. bool isSend = false;
  12032. if (dt != null && dt.Rows.Count > 0)
  12033. {
  12034. foreach (DataRow row in dt.Rows)
  12035. {
  12036. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12037. {
  12038. isSend = true;
  12039. }
  12040. }
  12041. if (isSend)
  12042. {
  12043. returnErrorMsg("已发货无法修改");
  12044. return;
  12045. }
  12046. ceErpTrade.Attachments = atta;
  12047. ceErpTrade.Update();
  12048. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12049. returnSuccessMsg("上传成功!");
  12050. return;
  12051. }
  12052. }
  12053. }
  12054. returnErrorMsg("找不到订单");
  12055. }
  12056. public void get_tid_attachments()
  12057. {
  12058. string tid = GetPostString("tid");
  12059. if (!string.IsNullOrEmpty(tid))
  12060. {
  12061. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12062. if (ceErpTradeCell != null)
  12063. {
  12064. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12065. if (ceErpTrade == null)
  12066. {
  12067. returnErrorMsg("找不到订单");
  12068. return;
  12069. }
  12070. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12071. return;
  12072. }
  12073. }
  12074. returnErrorMsg("找不到订单");
  12075. }
  12076. public void check_erp_sameorders()
  12077. {
  12078. if (UrlPostParmsCheck("ctid"))
  12079. {
  12080. string eid = GetPostString("ctid");
  12081. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12082. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12083. if (entity != null && ceErpTrade != null)
  12084. {
  12085. if (entity.OrderState > 6)
  12086. {
  12087. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12088. return;
  12089. }
  12090. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12091. List<string> ids = new List<string>();
  12092. if (dt != null && dt.Rows.Count > 1)
  12093. {
  12094. bool needhe = true;
  12095. foreach (DataRow dr in dt.Rows)
  12096. {
  12097. ids.Add("'" + dr["ctid"] + "'");
  12098. /* //备注有合包
  12099. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12100. {
  12101. needhe = true;
  12102. }
  12103. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12104. {
  12105. needhe = true;
  12106. }
  12107. //顺丰快递
  12108. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12109. {
  12110. needhe = true;
  12111. }*/
  12112. }
  12113. if (!needhe)
  12114. {
  12115. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12116. return;
  12117. }
  12118. StringBuilder sql = new StringBuilder();
  12119. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12120. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12121. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12122. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12123. foreach (DataRow dr in dt.Rows)
  12124. {
  12125. dr["dstate"] = 0;
  12126. dr["dnumber"] = 0;
  12127. foreach (DataRow row in dt1.Rows)
  12128. {
  12129. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12130. {
  12131. dr["dstate"] = 2;
  12132. dr["default"] = 1;
  12133. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12134. }
  12135. }
  12136. if (eid.Equals(dr["ctid"].ToString()))
  12137. {
  12138. dr["dstate"] = 1;
  12139. dr["default"] = 1;
  12140. }
  12141. }
  12142. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12143. return;
  12144. }
  12145. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12146. return;
  12147. }
  12148. returnErrorMsg("未找到订单");
  12149. return;
  12150. }
  12151. returnErrorMsg("缺少必要的参数");
  12152. }
  12153. public void get_mark_number()
  12154. {
  12155. string eid = GetPostString("ctid");
  12156. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12157. if (entity != null)
  12158. {
  12159. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12160. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12161. int current = 1;
  12162. if (ceErpDeliverMark == null)
  12163. {
  12164. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12165. List<string> ids = new List<string>();
  12166. if (dt != null && dt.Rows.Count > 1)
  12167. {
  12168. foreach (DataRow dr in dt.Rows)
  12169. {
  12170. ids.Add("'" + dr["ctid"] + "'");
  12171. }
  12172. //查询已有的编号
  12173. StringBuilder sql = new StringBuilder();
  12174. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12175. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12176. if (dt1 == null || dt1.Rows.Count == 0)
  12177. {
  12178. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12179. List<int> list_number = new List<int>();
  12180. foreach (DataRow row in numbers.Rows)
  12181. {
  12182. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12183. }
  12184. //查询空余编号
  12185. for (int i = 0; i < list_number.Count + 2; i++)
  12186. {
  12187. if (!list_number.Contains(current))
  12188. {
  12189. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12190. //防止查询过程中有新数据生成
  12191. if (ceErpDeliverMark1 == null)
  12192. {
  12193. break;
  12194. }
  12195. }
  12196. current++;
  12197. }
  12198. }
  12199. else
  12200. {
  12201. foreach (DataRow row in dt1.Rows)
  12202. {
  12203. current = Convert.ToInt32(row["markNumber"]);
  12204. }
  12205. }
  12206. ceErpDeliverMark = new CeErpDeliverMark();
  12207. ceErpDeliverMark.ctid = eid;
  12208. ceErpDeliverMark.createtime = DateTime.Now;
  12209. if (ceErpTrade != null)
  12210. {
  12211. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12212. }
  12213. ceErpDeliverMark.markNumber = current;
  12214. ceErpDeliverMark.Create();
  12215. }
  12216. }
  12217. else
  12218. {
  12219. current = ceErpDeliverMark.markNumber;
  12220. }
  12221. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12222. return;
  12223. }
  12224. }
  12225. public void aftersaleCytSend()
  12226. {
  12227. string ctid = GetPostString("ctid");
  12228. if (!string.IsNullOrEmpty(ctid))
  12229. {
  12230. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12231. if (ceErpTradeCell != null)
  12232. {
  12233. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12234. }
  12235. returnSuccessMsg("推送成功");
  12236. return;
  12237. }
  12238. returnErrorMsg("缺少必要的参数");
  12239. }
  12240. public void packOrderInfo()
  12241. {
  12242. string ctids = GetPostString("ctids");
  12243. if (!string.IsNullOrEmpty(ctids))
  12244. {
  12245. string[] ctid_list = ctids.Split(',');
  12246. if (ctid_list.Length > 20)
  12247. {
  12248. returnErrorMsg("单次下载次数不能超过20个");
  12249. return;
  12250. }
  12251. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12252. StringBuilder sql = new StringBuilder();
  12253. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12254. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12255. int supplierId = 0;
  12256. StringBuilder insterSql = new StringBuilder();
  12257. for (int i = 0; i < dt.Rows.Count; i++)
  12258. {
  12259. DataRow row = dt.Rows[i];
  12260. if (i == 0)
  12261. {
  12262. supplierId = Convert.ToInt32(row["SupplierId"]);
  12263. }
  12264. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12265. {
  12266. returnErrorMsg("同车间的订单才能一起打包");
  12267. return;
  12268. }
  12269. int orderState = Convert.ToInt32(row["OrderState"]);
  12270. if (orderState != 5)
  12271. {
  12272. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12273. return;
  12274. }
  12275. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12276. }
  12277. CeErpPackData ceErpPackData = new CeErpPackData();
  12278. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12279. ceErpPackData.supplierId = supplierId;
  12280. ceErpPackData.createtime = DateTime.Now;
  12281. ceErpPackData.createBy = CurrentUser.UserID;
  12282. ceErpPackData.createName = CurrentUser.UserName;
  12283. ceErpPackData.Create();
  12284. if (ceErpPackData.ID > 0)
  12285. {
  12286. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12287. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12288. }
  12289. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12290. returnSuccessMsg("打包成功");
  12291. return;
  12292. }
  12293. returnErrorMsg("缺少必要的参数");
  12294. }
  12295. public void rePackOrderInfo()
  12296. {
  12297. string id = GetPostString("id");
  12298. if (!string.IsNullOrEmpty(id))
  12299. {
  12300. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12301. if (ceErpPackData == null)
  12302. {
  12303. returnSuccessMsg("查无数据");
  12304. return;
  12305. }
  12306. ceErpPackData.upStatus = 0;
  12307. ceErpPackData.message = "";
  12308. ceErpPackData.Update();
  12309. returnSuccessMsg("打包成功");
  12310. return;
  12311. }
  12312. returnErrorMsg("缺少必要的参数");
  12313. }
  12314. public void backPackOrderInfo()
  12315. {
  12316. string id = GetPostString("id");
  12317. if (!string.IsNullOrEmpty(id))
  12318. {
  12319. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12320. if (ceErpPackData == null)
  12321. {
  12322. returnSuccessMsg("查无数据");
  12323. return;
  12324. }
  12325. ceErpPackData.upStatus = 4;
  12326. ceErpPackData.Update();
  12327. List<string> list = new List<string>();
  12328. StringBuilder sql = new StringBuilder();
  12329. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12330. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12331. for (int i = 0; i < dt.Rows.Count; i++)
  12332. {
  12333. DataRow row = dt.Rows[i];
  12334. list.Add("'" + row["ctid"].ToString() + "'");
  12335. }
  12336. string textCtids = string.Join(",", list);
  12337. 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));
  12338. 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, "无法打包退回"));
  12339. returnSuccessMsg("退回成功");
  12340. return;
  12341. }
  12342. returnErrorMsg("缺少必要的参数");
  12343. }
  12344. public void addPackDownNum()
  12345. {
  12346. string id = GetPostString("id");
  12347. if (!string.IsNullOrEmpty(id))
  12348. {
  12349. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12350. returnSuccessMsg("下载成功");
  12351. return;
  12352. }
  12353. returnErrorMsg("缺少必要的参数");
  12354. }
  12355. public void get_pack_list()
  12356. {
  12357. DataStruct dStruct = GetPostStruct();
  12358. List<string> lw = new List<string>();
  12359. string supplier = GetPostString("supplier");
  12360. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12361. string posTag = CurrentUser.UserPost.Post.Code;
  12362. if (posTag == "Supplier")
  12363. {
  12364. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12365. }
  12366. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12367. dStruct.Order = "createtime desc";
  12368. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12369. writeGridDataTableJson(dStruct.TotalCount, dt);
  12370. }
  12371. public void get_pack_order_list()
  12372. {
  12373. string packId = GetPostString("packId");
  12374. if (string.IsNullOrEmpty(packId))
  12375. {
  12376. returnErrorMsg("缺少必要的参数");
  12377. return;
  12378. }
  12379. StringBuilder sql = new StringBuilder();
  12380. 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);
  12381. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12382. if (dt == null || dt.Rows.Count == 0)
  12383. {
  12384. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12385. return;
  12386. }
  12387. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12388. return;
  12389. }
  12390. public void get_supplier_product_time_list()
  12391. {
  12392. DataStruct dStruct = GetPostStruct();
  12393. List<string> lw = new List<string>();
  12394. string supplier = GetPostString("supplier");
  12395. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12396. string posTag = CurrentUser.UserPost.Post.Code;
  12397. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12398. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12399. writeGridDataTableJson(dStruct.TotalCount, dt);
  12400. }
  12401. public void saveSupplierProductTime()
  12402. {
  12403. string productId = GetPostString("productId");
  12404. if (string.IsNullOrEmpty(productId))
  12405. {
  12406. returnErrorMsg("缺少必要的参数");
  12407. return;
  12408. }
  12409. string productName = GetPostString("productName");
  12410. int supplierId = GetPostInt("supplierId");
  12411. if (supplierId == 0)
  12412. {
  12413. returnErrorMsg("缺少必要的参数");
  12414. return;
  12415. }
  12416. int quantity = GetPostInt("quantity");
  12417. int sendDay = GetPostInt("sendTime");
  12418. string supplierName = GetPostString("supplierName");
  12419. string craft = GetPostString("craft");
  12420. string deadLine = GetPostString("deadLine");
  12421. string dayDeadLine = GetPostString("dayDeadLine");
  12422. try
  12423. {
  12424. int eid = GetPostInt("eid");
  12425. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12426. if (ceErpSupplierProductTime == null)
  12427. {
  12428. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12429. }
  12430. ceErpSupplierProductTime.productId = productId;
  12431. ceErpSupplierProductTime.productName = productName;
  12432. ceErpSupplierProductTime.supplierId = supplierId;
  12433. ceErpSupplierProductTime.supplierName = supplierName;
  12434. ceErpSupplierProductTime.craft = craft;
  12435. ceErpSupplierProductTime.sendDay = sendDay;
  12436. ceErpSupplierProductTime.quantity = quantity;
  12437. if (!string.IsNullOrEmpty(deadLine))
  12438. {
  12439. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12440. }
  12441. if (!string.IsNullOrEmpty(dayDeadLine))
  12442. {
  12443. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12444. }
  12445. if (ceErpSupplierProductTime.ID == 0)
  12446. {
  12447. ceErpSupplierProductTime.Save();
  12448. }
  12449. else
  12450. {
  12451. ceErpSupplierProductTime.Update();
  12452. }
  12453. }
  12454. catch (Exception e)
  12455. {
  12456. }
  12457. returnSuccessMsg("保存成功");
  12458. return;
  12459. }
  12460. public void delSupplierProductTime()
  12461. {
  12462. int eid = GetPostInt("eid");
  12463. if (eid > 0)
  12464. {
  12465. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12466. if (ceErpSupplierProductTime == null)
  12467. {
  12468. returnErrorMsg("查无数据");
  12469. return;
  12470. }
  12471. ceErpSupplierProductTime.Delete();
  12472. returnSuccessMsg("保存成功");
  12473. return;
  12474. }
  12475. returnErrorMsg("缺少必要的参数");
  12476. }
  12477. public void getExpressInfo()
  12478. {
  12479. string ctid = GetPostString("ctid");
  12480. if (!string.IsNullOrEmpty(ctid))
  12481. {
  12482. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12483. if (ceErpTradeCell != null)
  12484. {
  12485. string outSid = ceErpTradeCell.OutSid;
  12486. if (outSid.Length > 0)
  12487. {
  12488. 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);
  12489. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12490. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12491. return;
  12492. }
  12493. }
  12494. returnErrorMsg("查无记录");
  12495. return;
  12496. }
  12497. returnErrorMsg("缺少必要的参数");
  12498. }
  12499. public void getExpressPostData()
  12500. {
  12501. string express = GetPostString("express");
  12502. if (!string.IsNullOrEmpty(express))
  12503. {
  12504. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12505. if (ceErpExpressInfo != null)
  12506. {
  12507. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12508. return;
  12509. }
  12510. }
  12511. returnErrorMsg("缺少必要的参数");
  12512. }
  12513. public void checkSupplierOrder()
  12514. {
  12515. string ctids = GetPostString("ctids");
  12516. if (ctids != null)
  12517. {
  12518. List<string> list = new List<string>();
  12519. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12520. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12521. for (int i = 0; i < dt.Rows.Count; i++)
  12522. {
  12523. DataRow row = dt.Rows[i];
  12524. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12525. {
  12526. continue;
  12527. }
  12528. list.Add(row["seller_memo"].ToString());
  12529. }
  12530. if (list.Count > 0)
  12531. {
  12532. 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, "点击下载按钮"));
  12533. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12534. return;
  12535. }
  12536. }
  12537. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12538. return;
  12539. }
  12540. public void addPersonId()
  12541. {
  12542. string tid = GetPostString("tid");
  12543. string personId = GetPostString("personId");
  12544. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12545. if (ceErpTrade != null)
  12546. {
  12547. ceErpTrade.receiver_zip = personId;
  12548. ceErpTrade.Update();
  12549. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12550. returnSuccessMsg("保存成功");
  12551. return;
  12552. }
  12553. returnErrorMsg("缺少必要的参数");
  12554. }
  12555. }
  12556. }