sync.order.cs 639 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838
  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. namespace SiteCore.Handler
  50. {
  51. public partial class sync
  52. {
  53. public void get_erp_orderlist()
  54. {
  55. string poscode = CurrentUser.UserPost.Post.Code;
  56. DataStruct dStruct = GetPostStruct();
  57. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\uv特殊工艺价格(1).xls");
  58. //apiHelper.Api_SyncOrderByTime("598825");
  59. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  60. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  61. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  62. //banniuApiHelper.sendLogisticsInfo(null);
  63. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  64. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  65. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  66. //int sid = commonHelper.autoDistributeToSupplier(entity);
  67. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  68. //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\"}}");
  69. //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}}");
  70. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  71. //commonHelper.loginGetOrder(2152);
  72. //string res = apiHelper.API_GetWaybill("SF-CAINIAO-LYZSJF", "C1_4386726036959480136");
  73. List<string> lw = new List<string>();
  74. string tid = GetPostString("ctid");
  75. string date1 = GetPostString("date1");
  76. //12-1 修改
  77. string urgent = GetPostString("urgent");
  78. string back = GetPostString("back");
  79. string offlineSearch = GetPostString("offlineSearch");
  80. int paramsCount = 0;
  81. if (!string.IsNullOrWhiteSpace(urgent))
  82. {
  83. if (urgent.Equals("true"))
  84. {
  85. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  86. }
  87. }
  88. if (!string.IsNullOrWhiteSpace(back))
  89. {
  90. if (back.Equals("true"))
  91. {
  92. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  93. }
  94. }
  95. if (!string.IsNullOrWhiteSpace(offlineSearch))
  96. {
  97. if (offlineSearch.Equals("true"))
  98. {
  99. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  100. }
  101. }
  102. //end
  103. string date2 = GetPostString("date2");
  104. string buyernick = GetPostString("buyer_nick");
  105. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  106. {
  107. if (tid.Length <= 0 && buyernick.Length <= 0)
  108. {
  109. return;
  110. }
  111. }
  112. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  113. {
  114. if (tid.Length > 0)
  115. {
  116. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  117. if (ceErpTradeCell != null)
  118. {
  119. tid = ceErpTradeCell.tid;
  120. }
  121. List<string> select_tid = getTidByCtidMore(tid);
  122. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  123. }
  124. if (buyernick.Length > 0)
  125. {
  126. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  127. }
  128. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  129. if (dw.Length > 0)
  130. {
  131. lw.Add(dw);
  132. }
  133. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  134. {
  135. string usershop = CurrentUser.User.pemShop;
  136. lw.Add(string.Format("ShopId in ({0})", usershop));
  137. }
  138. }
  139. else
  140. {
  141. if (ex_psize == 0)
  142. {
  143. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  144. }
  145. if (PKey != "admin")
  146. {
  147. string usershop = CurrentUser.User.pemShop;
  148. lw.Add(string.Format("ShopId in ({0})", usershop));
  149. paramsCount++;
  150. }
  151. }
  152. string uploaddate1 = GetPostString("uploaddate1");
  153. string uploaddate2 = GetPostString("uploaddate2");
  154. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  155. if (update.Length > 0) lw.Add(update);
  156. string deliverydate1 = GetPostString("deliverydate1");
  157. string deliverydate2 = GetPostString("deliverydate2");
  158. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  159. if (deliverydate.Length > 0)
  160. {
  161. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  162. };
  163. string shopname = GetPostString("shopname");
  164. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  165. string addwechat = GetPostString("addwechat");
  166. if (addwechat.Length > 0)
  167. {
  168. int addWt = Convert.ToInt32(addwechat);
  169. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  170. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  171. }
  172. string customer = GetPostString("customer");
  173. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  174. string design = GetPostString("design");
  175. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  176. string orderState = GetPostString("orderState");
  177. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  178. string address = GetPostString("address");
  179. 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));
  180. string sellermemo = GetPostString("seller_memo");
  181. if (sellermemo.Length > 0)
  182. {
  183. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  184. }
  185. string backReason = GetPostString("backReason");
  186. if (backReason.Length > 0)
  187. {
  188. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  189. }
  190. string apdate1 = GetPostString("apdate1");
  191. string apdate2 = GetPostString("apdate2");
  192. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  193. if (dwap.Length > 0) lw.Add(dwap);
  194. string price1 = GetPostString("price1");
  195. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  196. string price2 = GetPostString("price2");
  197. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  198. string isoldcustomer = GetPostString("isoldcus");
  199. string spudata = GetPostString("spudata");
  200. if ("0".Equals(spudata))
  201. {
  202. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  203. }
  204. if ("1".Equals(spudata))
  205. {
  206. lw.Add(string.Format("spu_id <> ''"));
  207. }
  208. string finishdate1 = GetPostString("finishdate1");
  209. string finishdate2 = GetPostString("finishdate2");
  210. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  211. bool isFinish = false;
  212. if (finishdate.Length > 0)
  213. {
  214. lw.Add(finishdate);
  215. isFinish = true;
  216. paramsCount++;
  217. }
  218. if (isoldcustomer.Length > 0)
  219. {
  220. if ("2".Equals(isoldcustomer))
  221. {
  222. lw.Add(string.Format("VipCustomer=1"));
  223. }
  224. else
  225. {
  226. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  227. }
  228. }
  229. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  230. if (ex_psize > 0)
  231. {
  232. int UserID = CurrentUser.UserID;
  233. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  234. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  235. {
  236. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  237. }
  238. dStruct.Order = "pay_time desc";
  239. }
  240. string isNew = GetPostString("isNew");
  241. if (isNew == "true")
  242. {
  243. lw.Add(string.Format("IsNew = {0}", 1));
  244. }
  245. string overtime = GetPostString("overtime");
  246. if (overtime == "1")
  247. {
  248. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  249. }
  250. String usePost = CurrentUser.UserPost.Post.Code;
  251. if (usePost.Equals("Operation") == true)
  252. {
  253. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  254. }
  255. else
  256. {
  257. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  258. }
  259. //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";
  260. if (dStruct.PageSize == 100000)
  261. {
  262. dStruct.Order = "";
  263. }
  264. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  265. DataTable dt = null;
  266. string tablename = "view_orderlist";
  267. if (isFinish)
  268. {
  269. tablename = "view_orderlist_end";
  270. }
  271. dt = WebCache.GetData(tablename, dStruct);
  272. if (dt != null && dt.Rows.Count > 0)
  273. {
  274. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  275. foreach (DataRow dr in dt.Rows)
  276. {
  277. try
  278. {
  279. if (dr["refund_fees"] != null)
  280. {
  281. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  282. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  283. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  284. if (payment == refund_fees)
  285. {
  286. dr["refund_fees"] = Math.Round(refund_fees, 2);
  287. }
  288. else if (refund_fees == total_fee)
  289. {
  290. dr["refund_fees"] = payment;
  291. }
  292. else
  293. {
  294. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  295. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  296. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  297. }
  298. }
  299. // 对象操作
  300. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  301. ceErpTradeCell.ctid = dr["ctid"].ToString();
  302. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  303. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  304. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  305. if (dStruct.PageSize != 100000)
  306. {
  307. if (dr["DispatchSort"].ToString() == "2")
  308. {
  309. dr["gongchuang"] = 200;
  310. }
  311. else if ("外协".Equals(dr["ToType"].ToString()))
  312. {
  313. dr["gongchuang"] = 200;
  314. }
  315. else if ("内部".Equals(dr["ToType"].ToString()))
  316. {
  317. dr["gongchuang"] = -1;
  318. }
  319. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  320. {
  321. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  322. dr["gongchuang"] = response.code;
  323. }
  324. }
  325. }
  326. catch (NullReferenceException ex)
  327. {
  328. // 处理空引用异常
  329. dr["refund_fees"] = "0.00";
  330. }
  331. }
  332. }
  333. writeGridDataTableJson(dStruct.TotalCount, dt);
  334. }
  335. public void get_erp_orderlist_sumprice()
  336. {
  337. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  338. return;
  339. List<string> lw = new List<string>();
  340. string tid = GetPostString("ctid");
  341. string date1 = GetPostString("date1");
  342. string date2 = GetPostString("date2");
  343. if (tid.Length > 0 || date1.Length > 0)
  344. {
  345. lw.Add(string.Format("ctid like '%{0}%'", tid));
  346. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  347. if (dw.Length > 0) lw.Add(dw);
  348. }
  349. else
  350. {
  351. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  352. }
  353. string shopname = GetPostString("shopname");
  354. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  355. string buyernick = GetPostString("buyer_nick");
  356. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  357. string customer = GetPostString("customer");
  358. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  359. string design = GetPostString("design");
  360. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  361. string orderState = GetPostString("orderState");
  362. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  363. string address = GetPostString("address");
  364. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  365. string sellermemo = GetPostString("seller_memo");
  366. if (sellermemo.Length > 0)
  367. {
  368. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  369. }
  370. string apdate1 = GetPostString("apdate1");
  371. string apdate2 = GetPostString("apdate2");
  372. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  373. if (dwap.Length > 0) lw.Add(dwap);
  374. string price1 = GetPostString("price1");
  375. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  376. string price2 = GetPostString("price2");
  377. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  378. string isoldcustomer = GetPostString("isoldcus");
  379. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  380. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  381. if (PKey != "admin")
  382. {
  383. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  384. lw.Add(string.Format("shopId in ({0})", usershop));
  385. }
  386. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  387. string mainWhere = string.Join(" and ", lw.ToArray());
  388. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  389. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  390. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  391. decimal total = 0;
  392. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  393. {
  394. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  395. }
  396. var res = new
  397. {
  398. data = total
  399. };
  400. string ro_jsond = JsonConvert.SerializeObject(res);
  401. returnSuccess(ro_jsond);
  402. return;
  403. }
  404. public void get_erp_CustomerServiceGather()
  405. {
  406. string userWhere = "", orderWhere = "";
  407. List<string> lw = new List<string>();
  408. string customer = GetPostString("customer");
  409. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  410. string shopname = GetPostString("shopname");
  411. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  412. string date1 = GetPostString("date1");
  413. string date2 = GetPostString("date2");
  414. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  415. if (dw.Length > 0) lw.Add(dw);
  416. orderWhere = string.Join(" and ", lw.ToArray());
  417. string sql = string.Format("select a.Name CusName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitRelease,0) WaitRelease, isnull(e.WaitRob,0) WaitRob, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  418. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  419. "left join " +
  420. "( " +
  421. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  422. ") as b on a.ID = b.CustomerUserId " +
  423. "left join " +
  424. "( " +
  425. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  426. ") as d on a.ID = d.CustomerUserId " +
  427. "left join " +
  428. "( " +
  429. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  430. ") as e on a.ID = e.CustomerUserId " +
  431. "left join " +
  432. "( " +
  433. " select CustomerUserId, RefundCount, RefundSum from " +
  434. " ( " +
  435. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  436. " from CE_ErpTradeRefund a " +
  437. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  438. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  439. " group by CustomerUserId " +
  440. " ) as a " +
  441. ") as f on a.ID = f.CustomerUserId " +
  442. "where a.PostCode = 'CustomerService'",
  443. userWhere, orderWhere);
  444. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  445. writeGridDataTableJson(dt.Rows.Count, dt);
  446. //writeGridDataTableJson(dt.Rows.Count, dt);
  447. }
  448. //设计汇总
  449. public void get_erp_DesignerGather()
  450. {
  451. string userWhere = "", orderWhere = "";
  452. List<string> lw = new List<string>();
  453. string Designer = GetPostString("designer");
  454. int org = GetPostInt("org");
  455. if (Designer.Length > 0)
  456. {
  457. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  458. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  459. }
  460. else if (org > 0)
  461. {
  462. userWhere = string.Format(" where OrgID ={0}", org);
  463. }
  464. string shopname = GetPostString("shopname");
  465. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  466. string state = GetPostString("state");
  467. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  468. string OrderArea = GetPostString("order_area");
  469. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  470. string date1 = GetPostString("date1");
  471. string date2 = GetPostString("date2");
  472. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  473. if (dw.Length > 0) lw.Add(dw);
  474. string UpDate1 = GetPostString("UpDate1");
  475. string UpDate2 = GetPostString("UpDate2");
  476. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  477. if (dw.Length > 0) lw.Add(dw);
  478. orderWhere = string.Join(" and ", lw.ToArray());
  479. string sql = string.Format("select *,cast(cast(z.DesignFinish as float) / (case z.AllOrder when 0 then 1 else z.AllOrder end) * 100 as numeric(18,2)) as FinalizationRate from (" +
  480. "select a.Name DesignerName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitDesign,0) WaitDesign, isnull(e.Designing,0) Designing, isnull(g.DesignFinish,0) DesignFinish, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  481. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  482. "left join " +
  483. "( " +
  484. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  485. ") as b on a.ID = b.DesignUserId " +
  486. "left join " +
  487. "( " +
  488. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  489. ") as d on a.ID = d.DesignUserId " +
  490. "left join " +
  491. "( " +
  492. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  493. ") as e on a.ID = e.DesignUserId " +
  494. "left join " +
  495. "( " +
  496. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  497. ") as g on a.ID = g.DesignUserId " +
  498. "left join " +
  499. "( " +
  500. " select CustomerUserId, RefundCount, RefundSum from " +
  501. " ( " +
  502. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  503. " from CE_ErpTradeRefund a " +
  504. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  505. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  506. " group by CustomerUserId " +
  507. " ) as a " +
  508. ") as f on a.ID = f.CustomerUserId " +
  509. "where a.PostCode = 'Designer') as z",
  510. userWhere, orderWhere);
  511. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  512. writeGridDataTableJson(dt.Rows.Count, dt);
  513. }
  514. //删除tradecell的订单
  515. public void del_erp_cellorder()
  516. {
  517. if (UrlPostParmsCheck("ctid"))
  518. {
  519. string eid = GetPostString("ctid");
  520. CeErpTradeCell.DelByCtid(eid);
  521. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  522. returnSuccessMsg("删除成功");
  523. }
  524. }
  525. public void clear_erp_refundstate()
  526. {
  527. if (UrlPostParmsCheck("ids"))
  528. {
  529. string eids = GetPostString("ids");
  530. string[] ctidList = eids.Split(',');
  531. foreach (string ctid in ctidList)
  532. {
  533. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  534. if (entity != null)
  535. {
  536. entity.IsRefund = 0;
  537. entity.Update();
  538. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  539. }
  540. else
  541. continue;
  542. }
  543. returnSuccessMsg("操作成功");
  544. return;
  545. }
  546. returnErrorMsg("缺少必要参数");
  547. }
  548. public void set_erp_urgency()
  549. {
  550. if (UrlPostParmsCheck("ctid"))
  551. {
  552. string eid = GetPostString("ctid");
  553. CeErpTradeCell entity = null;
  554. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  555. if (entity != null)
  556. {
  557. double prices = commonHelper.calculationPrice(entity);
  558. if (prices <= 100)
  559. {
  560. returnErrorMsg("此订单金额不足100元,无法加急。");
  561. return;
  562. }
  563. string utime = GetPostString("urgencytime");
  564. if (utime.Length > 0)
  565. {
  566. entity.UrgencyTime = Convert.ToDateTime(utime);
  567. }
  568. else
  569. {
  570. returnErrorMsg("请选择加急时间");
  571. return;
  572. }
  573. if (entity.OrderState <= 4)
  574. {
  575. //entity.seller_memo = entity.seller_memo + "-加急";
  576. string smemo = entity.seller_memo;
  577. int kindex = smemo.IndexOf(")");
  578. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  579. if (lastoneStr != "-")
  580. {
  581. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  582. }
  583. string prememo = smemo.Substring(0, kindex + 2);
  584. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  585. int lastkindex = lastmemo.IndexOf("(");
  586. DateTime urgtime = Convert.ToDateTime(utime);
  587. string newlastmemo = "";
  588. if (lastkindex == 0)
  589. {
  590. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  591. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  592. }
  593. else
  594. {
  595. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  596. }
  597. entity.seller_memo = prememo + newlastmemo;
  598. }
  599. entity.IsUrgency = true;
  600. entity.UpdateTime = DateTime.Now;
  601. entity.Update();
  602. ApiVo apiVo = new ApiVo();
  603. apiVo.orderNumber = entity.ctid;
  604. apiVo.actionName = "changeDesign";
  605. apiVo.orderRemarks = entity.seller_memo;
  606. apiVo.remarkSign = 3;
  607. designHelper.API_WorkCore(apiVo); //changeDesign
  608. CeErpSukuraData.createInfo(entity.ctid, 7);
  609. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  610. returnSuccessMsg("设置成功!");
  611. return;
  612. }
  613. returnErrorMsg("找不到记录");
  614. }
  615. }
  616. public void set_erp_reset()
  617. {
  618. if (UrlPostParmsCheck("ctid"))
  619. {
  620. string eid = GetPostString("ctid");
  621. CeErpTradeCell entity = null;
  622. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  623. if (entity != null)
  624. {
  625. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  626. {
  627. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  628. {
  629. returnErrorMsg("财务要求已下单已发货无法重置");
  630. return;
  631. }
  632. }
  633. entity.IsUrgency = false;
  634. entity.seller_memo = "";
  635. entity.OtherMemo = "";
  636. entity.OrderState = 0;
  637. entity.IsReturn = 0;
  638. //entity.IsRefund = 0;
  639. entity.MemoOpt = 0;
  640. entity.AfterSaleState = 0;
  641. entity.AfterSaleResponsible = "";
  642. entity.AfterSaleUserId = 0;
  643. entity.IsNeedBill = 0;
  644. entity.CustomerUserId = 0;
  645. entity.DesignUserId = 0;
  646. entity.SupplierId = 0;
  647. entity.PlaceUserId = 0;
  648. entity.ptid = "";
  649. entity.IsSample = 0;
  650. entity.IsXianHuo = 0;
  651. entity.isDianziOrder = 0;
  652. entity.DispatchSort = 0;
  653. entity.FinishPlaceTime = null;
  654. entity.Update();
  655. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  656. if (trade != null)
  657. {
  658. trade.seller_memo = "";
  659. trade.Update();
  660. }
  661. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  662. returnSuccessMsg("重置成功!");
  663. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  664. if (desginBill != null)
  665. {
  666. desginBill.isDel = 1;
  667. desginBill.Update();
  668. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  669. }
  670. ApiVo apiVo = new ApiVo();
  671. apiVo.orderNumber = entity.ctid;
  672. apiVo.actionName = "resetDesign";
  673. designHelper.API_WorkCore(apiVo);//resetDesign
  674. return;
  675. }
  676. returnErrorMsg("找不到记录");
  677. }
  678. }
  679. public void save_erp_sellermemo()
  680. {
  681. if (UrlPostParmsCheck("ctid"))
  682. {
  683. string ctid = GetPostString("ctid");
  684. CeErpTradeCell entity = null;
  685. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  686. if (entity != null)
  687. {
  688. string memo = GetPostString("seller_memo");
  689. memo = memo.Replace(" ", "");
  690. if (memo.Contains("补差"))
  691. {
  692. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  693. return;
  694. }
  695. List<string> bitList = new List<string>
  696. {
  697. "\\","/",":","*","?", "\"","<" ,">","|"
  698. };
  699. bool isIn = false;
  700. foreach (string bit in bitList)
  701. {
  702. if (memo.Contains(bit))
  703. {
  704. isIn = true;
  705. }
  706. }
  707. if (isIn)
  708. {
  709. returnErrorMsg("不能使用 一些符合作为文件名");
  710. return;
  711. }
  712. if (entity.seller_memo != memo)
  713. {
  714. if (entity.IsSample == 2)
  715. {
  716. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  717. return;
  718. }
  719. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  720. {
  721. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  722. {
  723. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  724. return;
  725. }
  726. /*if (CurrentUser.UserPost.Post.Code != "Place")
  727. {
  728. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  729. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  730. {
  731. returnErrorMsg("售前系统订单无法再此修改!");
  732. return;
  733. }
  734. }*/
  735. }
  736. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  737. }
  738. commonHelper.getCytPrice(entity);
  739. int memoopt = GetPostInt("MemoOpt");
  740. Boolean ismemoopt = false;
  741. if (memoopt > 0)
  742. {
  743. string stropt = "";
  744. if (memoopt == 1)
  745. {
  746. stropt = "“改稿”";
  747. ismemoopt = true;
  748. }
  749. else if (memoopt == 2)
  750. {
  751. stropt = "“定稿”";
  752. }
  753. else if (memoopt == 3)
  754. {
  755. stropt = "“查货”";
  756. CeErpSukuraData.createInfo(entity.ctid, 6);
  757. }
  758. entity.MemoOpt = Convert.ToInt32(memoopt);
  759. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  760. }
  761. if (entity.OrderState < 5)
  762. {
  763. memo = memo.Replace("(", "(");
  764. memo = memo.Replace(")", ")");
  765. }
  766. if (entity.OrderState < 3)
  767. {
  768. entity.DispatchSort = 0;
  769. }
  770. entity.seller_memo = memo;
  771. entity.UpdateTime = DateTime.Now;
  772. entity.Update();
  773. ApiVo apiVo = new ApiVo();
  774. apiVo.orderNumber = entity.ctid;
  775. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  776. apiVo.orderRemarks = memo;
  777. apiVo.remarkSign = memoopt;
  778. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  779. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  780. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  781. {
  782. dataHelper.api_orderBack(entity.ctid, "0", "");
  783. }
  784. if (entity.seller_memo.Contains("改稿"))
  785. {
  786. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  787. }
  788. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  789. returnSuccessMsg("保存成功!");
  790. return;
  791. }
  792. returnErrorMsg("找不到记录");
  793. }
  794. }
  795. public void ins_erp_checkorder()
  796. {
  797. if (UrlPostParmsCheck("ctid"))
  798. {
  799. string ctid = GetPostString("ctid");
  800. CeErpTradeCell entity = null;
  801. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  802. if (entity != null)
  803. {
  804. if (entity.OrderState < 6)
  805. {
  806. returnErrorMsg("下单完成后才可查货");
  807. return;
  808. }
  809. /*if (entity.OrderState > 6)
  810. {
  811. returnErrorMsg("订单已发货");
  812. return;
  813. }*/
  814. if (entity.FinishPlaceTime != null)
  815. {
  816. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  817. {
  818. returnErrorMsg("下单时间不足,无法查货");
  819. return;
  820. }
  821. }
  822. entity.MemoOpt = 3;
  823. entity.CheckOrderTime = DateTime.Now;
  824. entity.UpdateTime = DateTime.Now;
  825. entity.Update();
  826. CeErpSukuraData.createInfo(entity.ctid, 6);
  827. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  828. returnSuccessMsg("操作成功!");
  829. return;
  830. }
  831. returnErrorMsg("找不到记录");
  832. }
  833. }
  834. public void save_erp_othermemo()
  835. {
  836. if (UrlPostParmsCheck("ctid"))
  837. {
  838. string ctid = GetPostString("ctid");
  839. CeErpTradeCell entity = null;
  840. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  841. if (entity != null)
  842. {
  843. entity.OtherMemo = GetPostString("otherMemo");
  844. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  845. {
  846. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  847. StringBuilder sql = new StringBuilder();
  848. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  849. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  850. if (dt != null && dt.Rows.Count > 0)
  851. {
  852. foreach (DataRow dr in dt.Rows)
  853. {
  854. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  855. {
  856. //品类一直
  857. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  858. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  859. if (ceErpSampleCustomer == null)
  860. {
  861. ceErpSampleCustomer = new CeErpSampleCustomer();
  862. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  863. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  864. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  865. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  866. ceErpSampleCustomer.shopId = entity.ShopId;
  867. }
  868. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  869. ceErpSampleCustomer.lastTid = entity.tid;
  870. if (ceErpSampleCustomer.ID > 0)
  871. {
  872. ceErpSampleCustomer.Update();
  873. }
  874. else
  875. {
  876. ceErpSampleCustomer.Create();
  877. }
  878. }
  879. }
  880. }
  881. }
  882. //if (entity.IsOldCustomer == 1)
  883. //{
  884. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  885. //{
  886. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  887. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  888. //}
  889. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  890. //{
  891. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  892. // {
  893. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  894. // {
  895. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  896. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  897. // }
  898. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  899. // {
  900. // entity.OrderState = 2;
  901. // entity.DesignUserId = 0;
  902. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  903. // }
  904. // else
  905. // {
  906. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  907. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  908. // }
  909. // }
  910. //}
  911. //}
  912. entity.UpdateTime = DateTime.Now;
  913. entity.Update();
  914. returnSuccessMsg("保存成功!");
  915. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  916. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  917. if (entity.OtherMemo.Contains("改稿"))
  918. {
  919. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  920. }
  921. return;
  922. }
  923. returnErrorMsg("找不到记录");
  924. }
  925. }
  926. public void save_erp_customermemo()
  927. {
  928. if (UrlPostParmsCheck("ctid"))
  929. {
  930. string ctid = GetPostString("ctid");
  931. CeErpTradeCell entity = null;
  932. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  933. if (entity != null)
  934. {
  935. entity.UpdateTime = DateTime.Now;
  936. entity.CustomerMemo = GetPostString("CustomerMemo");
  937. entity.Update();
  938. ApiVo apiVo = new ApiVo();
  939. apiVo.orderNumber = entity.ctid;
  940. apiVo.actionName = "followRemarks";
  941. apiVo.orderRemarks = entity.CustomerMemo;
  942. designHelper.API_WorkCore(apiVo);//followRemarks
  943. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  944. returnSuccessMsg("保存成功!");
  945. return;
  946. }
  947. returnErrorMsg("找不到记录");
  948. }
  949. }
  950. public void upd_erp_addmemotag()
  951. {
  952. if (UrlPostParmsCheck("ctid"))
  953. {
  954. ;
  955. string eid = GetPostString("ctid");
  956. string sfTagstr = GetPostString("memotag");
  957. CeErpTradeCell entity = null;
  958. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  959. if (entity != null)
  960. {
  961. ApiVo apiVo = new ApiVo();
  962. if (entity.OrderState == 0)
  963. {
  964. returnErrorMsg("请先领单");
  965. return;
  966. }
  967. //撤销顺丰
  968. if (sfTagstr == "撤销顺丰")
  969. {
  970. entity.IsSF = 0;
  971. string reMsg = "";
  972. string oldmemo = entity.seller_memo;
  973. if (entity.OrderState < 5)
  974. {
  975. oldmemo = oldmemo.Replace("顺丰到付", "");
  976. oldmemo = oldmemo.Replace("顺丰寄付", "");
  977. entity.seller_memo = oldmemo;
  978. }
  979. else
  980. {
  981. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  982. {
  983. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  984. }
  985. }
  986. entity.Update();
  987. apiVo.orderNumber = entity.ctid;
  988. apiVo.actionName = "orderRemarks";
  989. apiVo.orderRemarks = entity.seller_memo;
  990. apiVo.isSf = entity.IsSF.ToString();
  991. designHelper.API_WorkCore(apiVo);//orderRemarks
  992. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  993. returnSuccessMsg("撤销成功!" + reMsg);
  994. return;
  995. }
  996. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  997. {
  998. //string oldmemo = entity.seller_memo;
  999. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1000. string sfStr = GetPostString("memotag");
  1001. string smemo = entity.seller_memo;
  1002. int kindex = smemo.IndexOf(")");
  1003. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1004. if (lastoneStr != "-")
  1005. {
  1006. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1007. }
  1008. string prememo = smemo.Substring(0, kindex + 2);
  1009. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1010. int lastkindex = lastmemo.IndexOf("(");
  1011. string newlastmemo = "";
  1012. if (lastkindex == 0)
  1013. {
  1014. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1015. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1016. }
  1017. else
  1018. {
  1019. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1020. }
  1021. entity.seller_memo = prememo + newlastmemo;
  1022. }
  1023. string sfTagMSg = "";
  1024. if (sfTagstr == "顺丰寄付")
  1025. {
  1026. entity.IsSF = 1;
  1027. sfTagMSg = "顺丰寄付";
  1028. }
  1029. else if (sfTagstr == "顺丰到付")
  1030. {
  1031. entity.IsSF = 2;
  1032. sfTagMSg = "顺丰到付";
  1033. }
  1034. entity.Update();
  1035. apiVo = new ApiVo();
  1036. apiVo.orderNumber = entity.ctid;
  1037. apiVo.actionName = "orderRemarks";
  1038. apiVo.orderRemarks = entity.seller_memo;
  1039. apiVo.isSf = entity.IsSF.ToString();
  1040. designHelper.API_WorkCore(apiVo);//orderRemarks
  1041. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1042. returnSuccessMsg("标记成功!");
  1043. return;
  1044. }
  1045. returnErrorMsg("找不到记录");
  1046. }
  1047. }
  1048. public void upd_erp_ordertag()
  1049. {
  1050. if (UrlPostParmsCheck("ctid"))
  1051. {
  1052. string eid = GetPostString("ctid");
  1053. CeErpTradeCell entity = null;
  1054. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1055. if (entity != null)
  1056. {
  1057. int tag = GetPostInt("wechattag");
  1058. //if(tag==4 && entity.IsSample == 2)
  1059. //{
  1060. // returnErrorMsg("补差价单不能标记微信单");
  1061. // return;
  1062. //}
  1063. entity.wechatTag = tag;
  1064. entity.Update();
  1065. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1066. if (tag == 1)
  1067. {
  1068. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1069. if (cash == null)
  1070. {
  1071. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1072. cash = new CeErpReturnCash();
  1073. cash.tid = entity.tid;
  1074. cash.seller_nick = main.seller_nick;
  1075. cash.payment = trade.payment;
  1076. cash.buyer_nick = main.buyer_nick;
  1077. cash.cashstate = 0;
  1078. cash.rtype = "微信返现";
  1079. cash.returnprice = 0;
  1080. cash.created = DateTime.Now;
  1081. cash.con = "订单标记微信单";
  1082. cash.img = "";
  1083. cash.applyuserid = CurrentUser.UserID;
  1084. cash.Create();
  1085. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1086. }
  1087. else
  1088. {
  1089. cash.cashstate = 0;
  1090. cash.Update();
  1091. }
  1092. CeErpSukuraData.createInfo(entity.ctid, 9);
  1093. }
  1094. else if (tag == 2)
  1095. {
  1096. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1097. if (cash == null)
  1098. {
  1099. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1100. cash = new CeErpReturnCash();
  1101. cash.tid = entity.tid;
  1102. cash.seller_nick = main.seller_nick;
  1103. cash.payment = trade.payment;
  1104. cash.buyer_nick = main.buyer_nick;
  1105. cash.cashstate = 0;
  1106. cash.rtype = "推购返现";
  1107. cash.returnprice = 5;
  1108. cash.created = DateTime.Now;
  1109. cash.con = "订单标记推购单";
  1110. cash.img = "";
  1111. cash.applyuserid = CurrentUser.UserID;
  1112. cash.Create();
  1113. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1114. }
  1115. else
  1116. {
  1117. cash.cashstate = 0;
  1118. cash.Update();
  1119. }
  1120. CeErpSukuraData.createInfo(entity.ctid, 9);
  1121. }
  1122. else if (tag == 3)
  1123. {
  1124. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1125. if (pers == null)
  1126. {
  1127. pers = new CeErpPersuade();
  1128. pers.ctid = entity.ctid;
  1129. pers.pstate = 0;
  1130. pers.created = DateTime.Now;
  1131. pers.applyuserid = CurrentUser.UserID;
  1132. pers.Create();
  1133. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1134. }
  1135. else
  1136. {
  1137. pers.pstate = 0;
  1138. pers.Update();
  1139. }
  1140. }
  1141. else if (tag == 4 || tag == 5)
  1142. {
  1143. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1144. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1145. if (pers == null)
  1146. {
  1147. pers = new CeErpStayGoods();
  1148. pers.t_id = entity.tid;
  1149. pers.status = "待审核";
  1150. pers.audit_type = 0;
  1151. if (tag == 4)
  1152. {
  1153. pers.stay_type = "微信推购";
  1154. }
  1155. else
  1156. {
  1157. pers.stay_type = "旺旺推购";
  1158. }
  1159. if (entity.IsXianHuo == 0)
  1160. {
  1161. pers.product_id = entity.ProductId;
  1162. }
  1163. pers.wangwang = main.buyer_nick;
  1164. pers.shop_name = main.seller_nick;
  1165. pers.creata_time = DateTime.Now;
  1166. pers.create_u_id = CurrentUser.UserID;
  1167. pers.create_u_name = CurrentUser.UserName;
  1168. pers.Create();
  1169. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1170. }
  1171. else
  1172. {
  1173. pers.audit_type = 0;
  1174. pers.Update();
  1175. }
  1176. CeErpSukuraData.createInfo(entity.ctid, 10);
  1177. }
  1178. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1179. returnSuccessMsg("标记成功!");
  1180. return;
  1181. }
  1182. returnErrorMsg("找不到记录");
  1183. }
  1184. }
  1185. public void upd_erp_ordertag_cancel()
  1186. {
  1187. if (UrlPostParmsCheck("ctid"))
  1188. {
  1189. string eid = GetPostString("ctid");
  1190. CeErpTradeCell entity = null;
  1191. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1192. if (entity != null)
  1193. {
  1194. entity.wechatTag = 0;
  1195. entity.Update();
  1196. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1197. if (pers != null)
  1198. {
  1199. pers.status = "取消推购";
  1200. pers.audit_type = 3;
  1201. pers.Update();
  1202. }
  1203. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1204. returnSuccessMsg("标记成功!");
  1205. return;
  1206. }
  1207. returnErrorMsg("找不到记录");
  1208. }
  1209. }
  1210. public void upd_erp_addweichattag()
  1211. {
  1212. if (UrlPostParmsCheck("ctid"))
  1213. {
  1214. ;
  1215. string eid = GetPostString("ctid");
  1216. CeErpTradeCell entity = null;
  1217. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1218. if (entity != null)
  1219. {
  1220. if (entity.IsAddWechat > 0)
  1221. {
  1222. returnErrorMsg("此单已经标记过了");
  1223. return;
  1224. }
  1225. 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);
  1226. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1227. if (dt.Rows.Count > 0)
  1228. {
  1229. entity.IsAddWechat = 2;
  1230. }
  1231. else
  1232. {
  1233. entity.IsAddWechat = 1;
  1234. }
  1235. entity.Update();
  1236. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1237. returnSuccessMsg("标记成功!");
  1238. return;
  1239. }
  1240. returnErrorMsg("找不到记录");
  1241. }
  1242. }
  1243. public void upd_erp_getmyorder()
  1244. {
  1245. if (UrlPostParmsCheck("ctid"))
  1246. {
  1247. ;
  1248. string eid = GetPostString("ctid");
  1249. CeErpTradeCell entity = null;
  1250. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1251. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1252. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1253. {
  1254. returnErrorMsg("台湾客户需填写身份证号!");
  1255. return;
  1256. }
  1257. if (entity != null)
  1258. {
  1259. if (entity.ctid.IndexOf("C") != -1)
  1260. {
  1261. StringBuilder sql = new StringBuilder();
  1262. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1263. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1264. if (dt.Rows.Count > 0)
  1265. {
  1266. decimal total = 0;
  1267. foreach (DataRow dr in dt.Rows)
  1268. {
  1269. total += Convert.ToDecimal(dr["payment"]);
  1270. }
  1271. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1272. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1273. {
  1274. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1275. return;
  1276. }
  1277. }
  1278. }
  1279. if (entity.OrderState == -1)
  1280. {
  1281. returnErrorMsg("待审核订单无法领取!");
  1282. return;
  1283. }
  1284. entity.CustomerUserId = CurrentUser.UserID;
  1285. if (entity.OrderState < 2)
  1286. {
  1287. entity.OrderState = 2;
  1288. if (entity.ShopId != 0)
  1289. {
  1290. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1291. }
  1292. }
  1293. entity.UpdateTime = DateTime.Now;
  1294. entity.Update();
  1295. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1296. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1297. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1298. {
  1299. dataHelper.api_orderBack(entity.ctid, "0", "");
  1300. }
  1301. returnSuccessMsg("领单成功!");
  1302. return;
  1303. }
  1304. returnErrorMsg("找不到记录");
  1305. }
  1306. }
  1307. public void getmyorder_from_init()
  1308. {
  1309. if (UrlPostParmsCheck("ctid"))
  1310. {
  1311. string eid = GetPostString("ctid");
  1312. CeErpTradeCell entity = null;
  1313. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1314. if (entity != null)
  1315. {
  1316. string sellerMemo = GetPostString("sellerMemo");
  1317. if (sellerMemo.Length > 0)
  1318. {
  1319. entity.seller_memo = sellerMemo;
  1320. }
  1321. string oterhMemo = GetPostString("otherMemo");
  1322. if (oterhMemo.Length > 0)
  1323. {
  1324. entity.OtherMemo = oterhMemo;
  1325. }
  1326. int urg = GetPostInt("urgency");
  1327. entity.IsUrgency = (urg == 1 ? true : false);
  1328. int wechat = GetPostInt("wechat");
  1329. int command = GetPostInt("command");
  1330. if (wechat == 1)
  1331. {
  1332. entity.wechatTag = 1;
  1333. }
  1334. if (command == 1)
  1335. {
  1336. entity.wechatTag = 2;
  1337. }
  1338. string pPro = GetPostString("pprofession");
  1339. if (pPro.Length > 0)
  1340. {
  1341. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1342. string spro = GetPostString("profession");
  1343. if (spro.Length > 0)
  1344. {
  1345. entity.ProfessionId = Convert.ToInt32(spro);
  1346. }
  1347. }
  1348. string proId = GetPostString("productId");
  1349. if (proId.Length > 0)
  1350. {
  1351. entity.ProductId = Convert.ToInt32(proId);
  1352. }
  1353. entity.Material = GetPostString("material");
  1354. entity.Craft = GetPostString("craft");
  1355. entity.CustomerUserId = CurrentUser.UserID;
  1356. if (entity.OrderState < 2)
  1357. {
  1358. entity.OrderState = 2;
  1359. if (entity.ShopId != 0)
  1360. {
  1361. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1362. }
  1363. }
  1364. entity.Update();
  1365. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1366. returnSuccessMsg("领单成功!");
  1367. return;
  1368. }
  1369. returnErrorMsg("找不到记录");
  1370. }
  1371. }
  1372. public void upd_erp_setrelationorder()
  1373. {
  1374. if (UrlPostParmsCheck("ctid"))
  1375. {
  1376. ;
  1377. string eid = GetPostString("ctid");
  1378. string ftid = GetPostString("ftid");
  1379. CeErpTradeCell entity = null;
  1380. CeErpTradeCell fentity = null;
  1381. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1382. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1383. if (fentity == null)
  1384. {
  1385. returnErrorMsg("找不到关联的主订单");
  1386. return;
  1387. }
  1388. if (entity != null)
  1389. {
  1390. if (entity.OrderState >= 5)
  1391. {
  1392. returnErrorMsg("本单已经设计完成无法关联");
  1393. return;
  1394. }
  1395. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1396. {
  1397. returnErrorMsg("线下单续审核后才能关联!");
  1398. return;
  1399. }
  1400. entity.ptid = ftid;
  1401. entity.OrderState = fentity.OrderState;
  1402. //entity.status = fentity.status;
  1403. entity.CustomerUserId = fentity.CustomerUserId;
  1404. entity.DesignUserId = fentity.DesignUserId;
  1405. entity.seller_memo = "补差价单:" + ftid;
  1406. entity.IsSample = 2;
  1407. entity.Update();
  1408. ApiVo apiVo = new ApiVo();
  1409. apiVo.orderNumber = ftid;
  1410. apiVo.payment = entity.payment;
  1411. apiVo.actionName = "repairDesign";
  1412. designHelper.API_WorkCore(apiVo);//repairDesign
  1413. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1414. returnSuccessMsg("关联成功!");
  1415. return;
  1416. }
  1417. else
  1418. returnErrorMsg("找不到记录");
  1419. }
  1420. }
  1421. public void download_erp_neworder()
  1422. {
  1423. string seller = GetPostString("seller_nick");
  1424. string tid = GetPostString("tid");
  1425. if (seller.Length <= 0 || tid.Length <= 0)
  1426. {
  1427. returnErrorMsg("数据错误");
  1428. }
  1429. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1430. //{
  1431. // returnErrorMsg("找不到店铺Sessionkey");
  1432. //}
  1433. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1434. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1435. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1436. if (res.IndexOf("refOid") == -1)
  1437. {
  1438. returnErrorMsg("下载订单数据失败");
  1439. return;
  1440. }
  1441. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1442. returnSuccessMsg("下载完成");
  1443. //tmcHelper.createNewOrder(res);
  1444. //CeErpTrade entr = null;
  1445. //entr = CeErpTrade.Get(tid);
  1446. //if (entr != null)
  1447. //{
  1448. // returnSuccess("下载成功");
  1449. // //下载成功之后,Cell表生成对应的订单;
  1450. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1451. //}
  1452. //else
  1453. //{
  1454. // returnErrorMsg("下载失败或者创建订单失败");
  1455. //}
  1456. }
  1457. public void set_erp_atersale()
  1458. {
  1459. if (UrlPostParmsCheck("ctid"))
  1460. {
  1461. string eid = GetPostString("ctid");
  1462. string reason = GetPostString("AfterSaleReason");
  1463. CeErpTradeCell entity = null;
  1464. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1465. if (entity != null)
  1466. {
  1467. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1468. {
  1469. returnErrorMsg("此订单已经在售后");
  1470. return;
  1471. }
  1472. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1473. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1474. entity.AfterSaleTime = DateTime.Now;
  1475. entity.Update();
  1476. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1477. returnSuccessMsg("转售后成功!");
  1478. return;
  1479. }
  1480. returnErrorMsg("找不到记录");
  1481. }
  1482. }
  1483. public void set_erp_withdraw()
  1484. {
  1485. if (UrlPostParmsCheck("ctid"))
  1486. {
  1487. try
  1488. {
  1489. string eid = GetPostString("ctid");//商品id
  1490. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1491. CeWithdraw ceWithdrawSelect = null;
  1492. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1493. if (ceWithdrawSelect != null)
  1494. {
  1495. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1496. {
  1497. ceWithdrawSelect.status = -1;
  1498. ceWithdrawSelect.Update();
  1499. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1500. returnSuccessMsg("重新发起审核成功");
  1501. return;
  1502. }
  1503. else
  1504. {
  1505. returnSuccessMsg("请勿重复申请!");
  1506. return;
  1507. }
  1508. }
  1509. else
  1510. {
  1511. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1512. if (string.IsNullOrEmpty(CustomerUserId))
  1513. {
  1514. CustomerUserId = "-1";
  1515. }
  1516. int Userid = CurrentUser.UserID;//用户id
  1517. CeWithdraw ceWithdraw = new CeWithdraw();
  1518. ceWithdraw.tid = eid;
  1519. ceWithdraw.userid = Userid;
  1520. ceWithdraw.providerid = CustomerUserId;
  1521. ceWithdraw.status = 3;
  1522. ceWithdraw.creationtime = DateTime.Now;
  1523. ceWithdraw.Create();
  1524. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1525. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1526. return;
  1527. }
  1528. }
  1529. catch
  1530. {
  1531. returnErrorMsg("申请撤回订单失败");
  1532. return;
  1533. }
  1534. }
  1535. }
  1536. public void ins_erp_billinfo()
  1537. {
  1538. if (UrlPostParmsCheck("ctid"))
  1539. {
  1540. string eid = GetPostString("ctid");
  1541. CeErpTradeCell entity = null;
  1542. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1543. if (entity != null)
  1544. {
  1545. CeErpBill bill = CeErpBill.GetByTid(eid);
  1546. bool isHave = false;
  1547. if (bill != null)
  1548. {
  1549. isHave = true;
  1550. if (bill.state != 4)
  1551. {
  1552. returnErrorMsg("此单已经申请过发票了");
  1553. return;
  1554. }
  1555. }
  1556. if (entity.IsNeedBill == 0)
  1557. {
  1558. entity.IsNeedBill = 1;
  1559. }
  1560. entity.Update();
  1561. string errjson = "";
  1562. try
  1563. {
  1564. CeErpBill bill_entity = new CeErpBill();
  1565. bill_entity.tid = entity.tid;
  1566. bill_entity.title = GetPostString("title");
  1567. string taxstr = GetPostString("tax");
  1568. taxstr = taxstr.Replace(" ", "");
  1569. bill_entity.tax = taxstr;
  1570. bill_entity.bank = GetPostString("bank");
  1571. string bankacstr = GetPostString("bankac");
  1572. bankacstr = bankacstr.Replace(" ", "");
  1573. bill_entity.bankac = bankacstr;
  1574. bill_entity.address = GetPostString("address");
  1575. bill_entity.phone = GetPostString("phone");
  1576. bill_entity.price = GetPostString("price");
  1577. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1578. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1579. {
  1580. billCount += 1;
  1581. }
  1582. string prebill = "ltb";
  1583. for (int idx = 1; idx <= billCount; idx++)
  1584. {
  1585. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1586. string billoid = prebill + idx + dtstr;
  1587. bill_entity.billOrderId += billoid;
  1588. if (idx < billCount)
  1589. {
  1590. bill_entity.billOrderId += ",";
  1591. }
  1592. }
  1593. bill_entity.productId = GetPostInt("ProductName");
  1594. bill_entity.num = GetPostInt("num");
  1595. bill_entity.unit = GetPostString("unit");
  1596. bill_entity.type = GetPostString("type");
  1597. bill_entity.sendType = GetPostString("SendType");
  1598. bill_entity.email = GetPostString("email");
  1599. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1600. bill_entity.shopName = GetPostString("ShopName");
  1601. bill_entity.applymemo = GetPostString("applyMemo");
  1602. bill_entity.createTime = DateTime.Now;
  1603. bill_entity.state = 0;
  1604. bill_entity.userId = CurrentUser.UserID;
  1605. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1606. bill_entity.Create();
  1607. }
  1608. catch (Exception ex)
  1609. {
  1610. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1611. returnErrorMsg("创建发票出错!");
  1612. return;
  1613. }
  1614. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1615. returnSuccessMsg("发票申请成功!");
  1616. return;
  1617. }
  1618. returnErrorMsg("找不到记录");
  1619. }
  1620. }
  1621. public void ins_erp_neworder()
  1622. {
  1623. if (UrlPostParmsCheck("receiver_name"))
  1624. {
  1625. CeErpTrade entity = new CeErpTrade();
  1626. string plat_form = GetPostString("platform");
  1627. string preStr = "N_";
  1628. if (plat_form == "拼多多")
  1629. {
  1630. preStr = "P_";
  1631. }
  1632. else if (plat_form == "阿里巴巴")
  1633. {
  1634. preStr = "A_";
  1635. }
  1636. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1637. entity.seller_nick = GetPostString("seller_nick");
  1638. entity.buyer_nick = GetPostString("buyer_nick");
  1639. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1640. entity.total_fee = entity.payment;
  1641. entity.pay_time = DateTime.Now;
  1642. entity.status = "NOT_SHIPPED";
  1643. entity.receiver_name = GetPostString("receiver_name");
  1644. entity.receiver_mobile = GetPostString("receiver_mobile");
  1645. entity.receiver_state = GetPostString("receiver_state");
  1646. entity.receiver_city = GetPostString("receiver_city");
  1647. entity.receiver_district = GetPostString("receiver_district");
  1648. entity.receiver_address = GetPostString("receiver_address");
  1649. if (entity.receiver_state == "" || entity.receiver_city == "")
  1650. {
  1651. returnErrorMsg("收件地址不能为空");
  1652. return;
  1653. }
  1654. int shopId = 0;
  1655. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1656. if (nShop != null)
  1657. {
  1658. shopId = nShop.ID;
  1659. }
  1660. if (shopId != 34 && entity.payment == 0)
  1661. {
  1662. returnErrorMsg("公司自用的单金额才能为0");
  1663. return;
  1664. }
  1665. entity.Create();
  1666. CeErpTradeCell entitycell = new CeErpTradeCell();
  1667. entitycell.ctid = entity.tid;
  1668. entitycell.tid = entity.tid;
  1669. entitycell.ShopId = shopId;
  1670. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1671. entitycell.OrderState = 0;
  1672. entitycell.pay_time = entity.pay_time;
  1673. entitycell.IsOffLineOrder = 1;
  1674. entitycell.Create();
  1675. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1676. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1677. return;
  1678. }
  1679. }
  1680. public void ins_erp_neworder2()
  1681. {
  1682. if (UrlPostParmsCheck("receiver_name"))
  1683. {
  1684. //string plat_form = GetPostString("platform");
  1685. string preStr = "X_";
  1686. string memo = GetPostString("memo");
  1687. string productId = GetPostString("productId");
  1688. string primg = GetPostString("proofimg");
  1689. string sellerNick = GetPostString("seller_nick");
  1690. string addFrom = GetPostString("addfrom");
  1691. if (addFrom == "1")
  1692. {
  1693. preStr = "N_";
  1694. }
  1695. int shopId = 0;
  1696. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1697. if (nShop != null)
  1698. {
  1699. shopId = nShop.ID;
  1700. }
  1701. else
  1702. {
  1703. returnErrorMsg("找不到对应店铺");
  1704. return;
  1705. }
  1706. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1707. {
  1708. returnErrorMsg("必须上传付款凭证");
  1709. return;
  1710. }
  1711. CeErpTrade entity = new CeErpTrade();
  1712. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1713. entity.seller_nick = sellerNick;
  1714. entity.buyer_nick = GetPostString("buyer_nick");
  1715. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1716. entity.total_fee = entity.payment;
  1717. entity.pay_time = DateTime.Now;
  1718. entity.status = "NOT_SHIPPED";
  1719. entity.receiver_name = GetPostString("receiver_name");
  1720. entity.receiver_mobile = GetPostString("receiver_mobile");
  1721. entity.receiver_state = GetPostString("receiver_state");
  1722. entity.receiver_city = GetPostString("receiver_city");
  1723. entity.receiver_district = GetPostString("receiver_district");
  1724. entity.receiver_address = GetPostString("receiver_address");
  1725. entity.seller_memo = memo;
  1726. entity.orderFrom = 20;
  1727. entity.orderType = 15;
  1728. if (entity.receiver_state == "" || entity.receiver_city == "")
  1729. {
  1730. returnErrorMsg("收件地址不能为空");
  1731. return;
  1732. }
  1733. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1734. {
  1735. returnErrorMsg("公司自用的单金额才能为0");
  1736. return;
  1737. }
  1738. entity.Create();
  1739. string toWhere = GetPostString("towhere");
  1740. CeErpTradeCell entitycell = new CeErpTradeCell();
  1741. entitycell.ctid = entity.tid;
  1742. //唯一标识
  1743. entitycell.OrderSn = entity.tid;
  1744. string orderSn = dataHelper.getSaleOrderSn();
  1745. if (orderSn != "")
  1746. {
  1747. entitycell.OrderSn = orderSn;
  1748. }
  1749. entitycell.tid = entity.tid;
  1750. //if (preStr == "X_")
  1751. //{
  1752. entitycell.IsOffLineOrder = 1;
  1753. //}
  1754. entitycell.CustomerUserId = CurrentUser.UserID;
  1755. entitycell.PayProofImg = primg;
  1756. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1757. entitycell.ProductId = Convert.ToInt32(productId);
  1758. entitycell.ShopId = shopId;
  1759. entitycell.UpdateTime = DateTime.Now;
  1760. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1761. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1762. {
  1763. entitycell.IsXianHuo = 1;
  1764. }
  1765. entitycell.pay_time = entity.pay_time;
  1766. if (toWhere == "1")
  1767. {
  1768. entitycell.OrderState = 2;
  1769. }
  1770. else
  1771. {
  1772. entitycell.OrderState = 6;
  1773. entitycell.FinishPlaceTime = entitycell.pay_time;
  1774. }
  1775. if (shopId == 94)
  1776. {
  1777. entitycell.OrderState = 4;
  1778. entitycell.WaitDesignTime = entitycell.pay_time;
  1779. entitycell.StartDesignTime = entitycell.pay_time;
  1780. entitycell.DesignUserId = 218;
  1781. }
  1782. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1783. {
  1784. entitycell.OrderState = -1;//修改12-5
  1785. CeWithdraw ceWithdraw = new CeWithdraw();
  1786. ceWithdraw.tid = entity.tid;
  1787. ceWithdraw.providerid = "-1";
  1788. ceWithdraw.status = -1;
  1789. ceWithdraw.creationtime = DateTime.Now;
  1790. ceWithdraw.userid = 1337;
  1791. ceWithdraw.Create();
  1792. }
  1793. entitycell.Create();
  1794. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1795. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1796. {
  1797. addPlaceRegist(entitycell, CurrentUser.UserID);
  1798. }
  1799. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1800. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1801. return;
  1802. }
  1803. }
  1804. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1805. {
  1806. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1807. entity.PlactTime = tradecell.pay_time;
  1808. entity.AddUserId = userid;
  1809. entity.FileName = tradecell.seller_memo;
  1810. entity.Supplier = 24;
  1811. entity.CreateTime = DateTime.Now;
  1812. entity.Did = tradecell.ctid;
  1813. entity.tid = tradecell.tid;
  1814. entity.splitTag = tradecell.SplitTag;
  1815. entity.CurState = "未完成";
  1816. entity.Create();
  1817. }
  1818. public void get_erp_offlinelist()
  1819. {
  1820. DataStruct dStruct = GetPostStruct();
  1821. List<string> lw = new List<string>();
  1822. string tid = GetPostString("ctid");
  1823. string date1 = GetPostString("date1");
  1824. string date2 = GetPostString("date2");
  1825. if (tid.Length > 0 || date1.Length > 0)
  1826. {
  1827. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1828. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1829. if (dw.Length > 0) lw.Add(dw);
  1830. }
  1831. else
  1832. {
  1833. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1834. }
  1835. string shopname = GetPostString("shopname");
  1836. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1837. string buyernick = GetPostString("buyer_nick");
  1838. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1839. string customer = GetPostString("customer");
  1840. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1841. string design = GetPostString("design");
  1842. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1843. string orderState = GetPostString("orderState");
  1844. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1845. string address = GetPostString("address");
  1846. 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));
  1847. string sellermemo = GetPostString("seller_memo");
  1848. if (sellermemo.Length > 0)
  1849. {
  1850. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1851. }
  1852. string price1 = GetPostString("price1");
  1853. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1854. string price2 = GetPostString("price2");
  1855. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1856. //if (PKey != "admin")
  1857. //{
  1858. // string usershop = CurrentUser.User.pemShop;
  1859. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1860. //}
  1861. //if (ex_psize > 0)
  1862. //{
  1863. dStruct.Order = "pay_time desc";
  1864. //}
  1865. //else
  1866. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1867. lw.Add(string.Format("IsOffLineOrder=1"));
  1868. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1869. DataTable dt = null;
  1870. dt = WebCache.GetData("view_erptradecell", dStruct);
  1871. writeGridDataTableJson(dStruct.TotalCount, dt);
  1872. }
  1873. public void get_erp_returncashrecord()
  1874. {
  1875. DataStruct dStruct = GetPostStruct();
  1876. List<string> lw = new List<string>();
  1877. string tid = GetPostString("ctid");
  1878. if (tid.Length > 0)
  1879. {
  1880. lw.Add(string.Format("tid like '%{0}%'", tid));
  1881. dStruct.Order = "id desc";
  1882. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1883. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1884. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1885. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1886. return;
  1887. }
  1888. returnErrorMsg("id数据错误!");
  1889. }
  1890. public void ins_erp_returncashrecord()
  1891. {
  1892. if (UrlPostParmsCheck("tid"))
  1893. {
  1894. string tid = GetPostString("tid");
  1895. string retype = GetPostString("type");
  1896. StringBuilder sql = new StringBuilder();
  1897. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1898. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1899. if (dt.Rows.Count > 0)
  1900. {
  1901. returnErrorMsg("相同返现类型记录已存在");
  1902. return;
  1903. }
  1904. CeErpReturnCash entity = new CeErpReturnCash();
  1905. entity.tid = tid;
  1906. entity.seller_nick = GetPostString("seller_nick");
  1907. string pment = GetPostString("payment");
  1908. if (pment.Length > 0)
  1909. {
  1910. entity.payment = Convert.ToDouble(pment);
  1911. }
  1912. entity.buyer_nick = GetPostString("buyer_nick");
  1913. entity.cashstate = 0;
  1914. entity.rtype = retype;
  1915. string rPrice = GetPostString("returnprice");
  1916. if (rPrice.Length > 0)
  1917. {
  1918. entity.returnprice = Convert.ToDouble(rPrice);
  1919. }
  1920. entity.created = DateTime.Now;
  1921. entity.con = GetPostString("con");
  1922. entity.img = GetPostString("img");
  1923. entity.applyuserid = CurrentUser.UserID;
  1924. entity.Create();
  1925. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1926. returnSuccessMsg("操作成功!");
  1927. return;
  1928. }
  1929. }
  1930. public void set_erp_predelivery()
  1931. {
  1932. if (UrlPostParmsCheck("ctid"))
  1933. {
  1934. string eid = GetPostString("ctid");
  1935. CeErpTradeCell entity = null;
  1936. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1937. if (entity != null)
  1938. {
  1939. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1940. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1941. //{
  1942. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1943. // return;
  1944. //}
  1945. entity.IsPreDelivery = 1;
  1946. entity.Update();
  1947. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1948. returnSuccessMsg("预发货成功!");
  1949. return;
  1950. //string shop = GetPostString("seller_nick");
  1951. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1952. //string comName = GetPostString("comName");
  1953. //string comCode = GetPostString("comCode");
  1954. //string outSid = GetPostString("outSid");//运单号
  1955. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1956. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1957. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1958. //string apires = "";
  1959. //if (deliveryType == "虚拟发货")
  1960. //{
  1961. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1962. //}
  1963. //else
  1964. //{
  1965. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1966. //}
  1967. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1968. ////{
  1969. //if (apires.IndexOf("发货成功") != -1)
  1970. //{
  1971. // if (deliveryType != "虚拟发货")
  1972. // {
  1973. // //还要插入快递信息到 快递信息表
  1974. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1975. // exinfo.tid = eid;
  1976. // exinfo.out_sid = outSid;
  1977. // exinfo.company_code = comCode;
  1978. // exinfo.company_name = comName;
  1979. // exinfo.delivery_memo = deliveryMemo;
  1980. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1981. // exinfo.deliveryType = deliveryType;
  1982. // exinfo.Create();
  1983. // }
  1984. // returnSuccessMsg("发货成功!");
  1985. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1986. //}
  1987. //else
  1988. //{
  1989. // returnErrorMsg("淘宝发货失败!!");
  1990. //}
  1991. //return;
  1992. }
  1993. returnErrorMsg("找不到订单记录");
  1994. }
  1995. }
  1996. public void get_erp_unusuallist()
  1997. {
  1998. DataStruct dStruct = GetPostStruct();
  1999. List<string> lw = new List<string>();
  2000. string tid = GetPostString("ctid");
  2001. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2002. string shopname = GetPostString("shopname");
  2003. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2004. string buyernick = GetPostString("buyer_nick");
  2005. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2006. string ResponsibleMan = GetPostString("responsible");
  2007. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2008. string date1 = GetPostString("date1");
  2009. string date2 = GetPostString("date2");
  2010. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2011. if (dw.Length > 0) lw.Add(dw);
  2012. string price1 = GetPostString("price1");
  2013. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2014. string price2 = GetPostString("price2");
  2015. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2016. string orderState = GetPostString("orderState");
  2017. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2018. string sellermemo = GetPostString("seller_memo");
  2019. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2020. lw.Add(string.Format("UnusualTag > 0"));
  2021. lw.Add(string.Format("IsRefund<={0}", 1));
  2022. dStruct.Order = "pay_time desc";
  2023. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2024. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2025. writeGridDataTableJson(dStruct.TotalCount, dt);
  2026. }
  2027. public void set_erp_unusualtonomal()
  2028. {
  2029. if (UrlPostParmsCheck("ctid"))
  2030. {
  2031. string eid = GetPostString("ctid");
  2032. CeErpTradeCell entity = null;
  2033. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2034. if (entity != null)
  2035. {
  2036. entity.UnusualTag = -1;
  2037. entity.Update();
  2038. returnSuccessMsg("忽略成功!");
  2039. return;
  2040. }
  2041. returnErrorMsg("找不到记录");
  2042. }
  2043. }
  2044. public void ins_erp_unusualreason()
  2045. {
  2046. if (UrlPostParmsCheck("ctid"))
  2047. {
  2048. string eid = GetPostString("ctid");
  2049. CeErpTradeCell entity = null;
  2050. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2051. if (entity != null)
  2052. {
  2053. entity.MemoOpt = 4;
  2054. entity.UnusualCon = GetPostString("con");
  2055. entity.Update();
  2056. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2057. if (trade != null)
  2058. {
  2059. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2060. }
  2061. //查货是否超时
  2062. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2063. if (ceErpTradeCellExtend == null)
  2064. {
  2065. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2066. ceErpTradeCellExtend.ctid = entity.ctid;
  2067. }
  2068. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2069. {
  2070. ceErpTradeCellExtend.CheckOut += 1;
  2071. }
  2072. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2073. if (ceErpTradeCellExtend.ID > 0)
  2074. {
  2075. ceErpTradeCellExtend.Update();
  2076. }
  2077. else
  2078. {
  2079. ceErpTradeCellExtend.Create();
  2080. }
  2081. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2082. returnSuccessMsg("操作成功!");
  2083. return;
  2084. }
  2085. returnErrorMsg("找不到记录");
  2086. }
  2087. }
  2088. public void upd_erp_sampleorder()
  2089. {
  2090. if (UrlPostParmsCheck("ctid"))
  2091. {
  2092. string eid = GetPostString("ctid");
  2093. string[] eArr = eid.Split(',');
  2094. if (eArr.Length > 1)
  2095. {
  2096. List<string> eLst = new List<string>();
  2097. for (int i = 0; i < eArr.Length; i++)
  2098. {
  2099. eLst.Add("'" + eArr[i] + "'");
  2100. }
  2101. eid = string.Join(",", eLst.ToArray());
  2102. }
  2103. else
  2104. {
  2105. eid = "'" + eid + "'";
  2106. }
  2107. StringBuilder sql = new StringBuilder();
  2108. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2109. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2110. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2111. if (dt.Rows.Count > 0)
  2112. {
  2113. string errmsg = "";
  2114. foreach (DataRow dr in dt.Rows)
  2115. {
  2116. StringBuilder sqlsb = new StringBuilder();
  2117. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2118. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2119. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2120. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2121. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2122. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2123. {
  2124. continue;
  2125. }
  2126. else
  2127. {
  2128. string emsg = commonHelper.KeepChinese(apires);
  2129. errmsg += emsg;
  2130. }
  2131. }
  2132. if (errmsg.Length > 0)
  2133. {
  2134. returnErrorMsg(errmsg);
  2135. return;
  2136. }
  2137. returnSuccessMsg("操作成功");
  2138. return;
  2139. }
  2140. returnErrorMsg("找不到记录");
  2141. }
  2142. }
  2143. public void upd_erp_transcustomer()
  2144. {
  2145. if (UrlPostParmsCheck("ctid"))
  2146. {
  2147. string eid = GetPostString("ctid");
  2148. int userid = GetPostInt("CustomerUserId");
  2149. CeErpTradeCell entity = null;
  2150. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2151. if (entity != null)
  2152. {
  2153. //string[] mlist = entity.seller_memo.Split('-');
  2154. //string sql = "select * from view_erpuser where id=" + userid;
  2155. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2156. //if (dt != null && dt.Rows.Count > 0)
  2157. //{
  2158. // string nmemo = "";
  2159. // for(int i = 0; i < mlist.Length - 1; i++)
  2160. // {
  2161. // nmemo += mlist[i];
  2162. // nmemo += "-";
  2163. // }
  2164. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2165. // entity.seller_memo = nmemo;
  2166. //}
  2167. entity.CustomerUserId = userid;
  2168. entity.Update();
  2169. returnSuccessMsg("操作成功!");
  2170. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2171. return;
  2172. }
  2173. returnErrorMsg("找不到记录");
  2174. }
  2175. }
  2176. public void upd_erp_transdesigner()
  2177. {
  2178. if (UrlPostParmsCheck("ctid"))
  2179. {
  2180. string eids = GetPostString("ctid");
  2181. string[] ctidList = eids.Split(',');
  2182. int userid = GetPostInt("DesignUserId");
  2183. foreach (string ctid in ctidList)
  2184. {
  2185. CeErpTradeCell entity = null;
  2186. CeErpDesignerBill entitys = null;
  2187. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2188. entitys = CeErpDesignerBill.GetByTid(ctid);
  2189. if (entity != null)
  2190. {
  2191. if (entity.OrderState > 4)
  2192. {
  2193. continue;
  2194. }
  2195. //存在退款不能流转
  2196. if (entity.IsRefund > 0)
  2197. {
  2198. continue;
  2199. }
  2200. entity.DesignUserId = userid;
  2201. entity.WaitDesignTime = DateTime.Now;
  2202. entity.Update();
  2203. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2204. }
  2205. }
  2206. returnSuccessMsg("操作成功!");
  2207. }
  2208. }
  2209. public void upd_erp_distributedesigner()
  2210. {
  2211. if (UrlPostParmsCheck("ctid"))
  2212. {
  2213. string eid = GetPostString("ctid");
  2214. int userid = GetPostInt("DesignUserId");
  2215. string[] idlist = eid.Split(',');
  2216. if (idlist.Length <= 0)
  2217. {
  2218. returnErrorMsg("订单不能为空");
  2219. return;
  2220. }
  2221. foreach (string ctid in idlist)
  2222. {
  2223. CeErpTradeCell entity = null;
  2224. CeErpDesignerBill entitys = null;
  2225. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2226. else continue;
  2227. if (entity != null)
  2228. {
  2229. if (userid == 2125 || userid == 3542)
  2230. { }
  2231. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2232. {
  2233. returnErrorMsg("金额错误的订单无法指派");
  2234. return;
  2235. }
  2236. if (entity.OrderState >= 5)
  2237. {
  2238. returnErrorMsg("已经设计完成无法指派");
  2239. return;
  2240. }
  2241. if (entity.OrderState == -1)
  2242. {
  2243. returnErrorMsg("审核中的订单无法指派");
  2244. return;
  2245. }
  2246. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2247. {
  2248. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2249. return;
  2250. }
  2251. //157赖橙帆 159林晨 73 静之颖
  2252. 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)
  2253. {
  2254. returnErrorMsg("指派设计共创无法再次指派!");
  2255. return;
  2256. }
  2257. entity.OrderState = 3;
  2258. if (entity.SupplierId == 0)
  2259. {
  2260. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2261. entity.SupplierId = suid;
  2262. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2263. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2264. }
  2265. if (userid == 2125 && entity.seller_memo != "")
  2266. {
  2267. apiDesign.API_GetPrintData_CreateOrder(entity);
  2268. }
  2269. if (userid == 3542 && entity.seller_memo != "")
  2270. {
  2271. string userPost = CurrentUser.UserPost.Post.Code;
  2272. if (CurrentUser.UserID == 73)
  2273. {
  2274. userPost = "SysAdmin";
  2275. }
  2276. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2277. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2278. if (response.msg != "设计共创:成功")
  2279. {
  2280. returnErrorMsg(response.msg);
  2281. return;
  2282. }
  2283. entity.DispatchSort = 2;
  2284. }
  2285. else
  2286. {
  2287. if (entity.DispatchSort == 2)
  2288. {
  2289. ApiVo apiVo = new ApiVo();
  2290. apiVo.actionName = "closeDesign";
  2291. apiVo.orderNumber = entity.ctid;
  2292. designHelper.API_WorkCore(apiVo);//closeDesign
  2293. }
  2294. entity.DispatchSort = 0;
  2295. }
  2296. entity.DesignUserId = userid;
  2297. entity.WaitDesignTime = DateTime.Now;
  2298. entity.UpdateTime = DateTime.Now;
  2299. entity.Update();
  2300. string name = commonHelper.getUserNameById(userid);
  2301. commonHelper.UpdateRelationOrder(entity.ctid);
  2302. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2303. }
  2304. }
  2305. returnSuccessMsg("操作成功!");
  2306. return;
  2307. }
  2308. }
  2309. public string getTidByCtid(string ctid)
  2310. {
  2311. string tid = "";
  2312. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2313. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2314. if (dataTable != null && dataTable.Rows.Count > 0)
  2315. {
  2316. tid = dataTable.Rows[0]["tid"].ToString();
  2317. }
  2318. return tid;
  2319. }
  2320. public List<string> getTidByCtidMore(string ctid)
  2321. {
  2322. 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);
  2323. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2324. List<string> list = new List<string>();
  2325. if (dataTable != null && dataTable.Rows.Count > 0)
  2326. {
  2327. foreach (DataRow item in dataTable.Rows)
  2328. {
  2329. list.Add("'" + item["tid"].ToString() + "'");
  2330. }
  2331. }
  2332. return list;
  2333. }
  2334. public List<string> getTidByCtidLike(string ctid)
  2335. {
  2336. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2337. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2338. List<string> list = new List<string>();
  2339. if (dataTable != null && dataTable.Rows.Count > 0)
  2340. {
  2341. foreach (DataRow item in dataTable.Rows)
  2342. {
  2343. list.Add("'" + item["tid"].ToString() + "'");
  2344. }
  2345. }
  2346. return list;
  2347. }
  2348. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2349. {
  2350. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2351. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2352. List<string> list = new List<string>();
  2353. if (dataTable != null && dataTable.Rows.Count > 0)
  2354. {
  2355. foreach (DataRow item in dataTable.Rows)
  2356. {
  2357. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2358. {
  2359. continue;
  2360. }
  2361. list.Add("'" + item["receiverId"].ToString() + "'");
  2362. }
  2363. }
  2364. return list;
  2365. }
  2366. public void get_erp_myorderlist()
  2367. {
  2368. DataStruct dStruct = GetPostStruct();
  2369. List<string> lw = new List<string>();
  2370. string tid = GetPostString("ctid");
  2371. if (tid.Length > 0)
  2372. {
  2373. string select_tid = getTidByCtid(tid);
  2374. lw.Add(string.Format("tid='{0}'", select_tid));
  2375. }
  2376. else
  2377. {
  2378. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2379. }
  2380. //12-1 修改
  2381. string urgent = GetPostString("urgent");
  2382. string back = GetPostString("back");
  2383. string offlineSearch = GetPostString("offlineSearch");
  2384. if (!string.IsNullOrWhiteSpace(urgent))
  2385. {
  2386. if (urgent.Equals("true"))
  2387. {
  2388. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2389. }
  2390. }
  2391. if (!string.IsNullOrWhiteSpace(back))
  2392. {
  2393. if (back.Equals("true"))
  2394. {
  2395. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2396. }
  2397. }
  2398. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2399. {
  2400. if (offlineSearch.Equals("true"))
  2401. {
  2402. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2403. }
  2404. }
  2405. //end
  2406. string shopname = GetPostString("shopname");
  2407. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2408. string buyernick = GetPostString("buyer_nick");
  2409. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2410. string design = GetPostString("design");
  2411. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2412. string orderState = GetPostString("orderState");
  2413. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2414. string sellermemo = GetPostString("seller_memo");
  2415. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2416. string date1 = GetPostString("date1");
  2417. string date2 = GetPostString("date2");
  2418. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2419. if (dw.Length > 0) lw.Add(dw);
  2420. string price1 = GetPostString("price1");
  2421. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2422. string price2 = GetPostString("price2");
  2423. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2424. string urgency = GetPostString("urgency");
  2425. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2426. string after = GetPostString("after");
  2427. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2428. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2429. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2430. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2431. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2432. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2433. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2434. if (dt != null && dt.Rows.Count > 0)
  2435. {
  2436. foreach (DataRow dr in dt.Rows)
  2437. {
  2438. try
  2439. {
  2440. // 对象操作
  2441. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2442. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2443. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2444. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2445. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2446. if (dStruct.PageSize != 100000)
  2447. {
  2448. if (dr["DispatchSort"].ToString() == "2")
  2449. {
  2450. dr["gongchuang"] = 200;
  2451. }
  2452. else if ("外协".Equals(dr["ToType"].ToString()))
  2453. {
  2454. dr["gongchuang"] = 200;
  2455. }
  2456. else if ("内部".Equals(dr["ToType"].ToString()))
  2457. {
  2458. dr["gongchuang"] = -1;
  2459. }
  2460. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2461. {
  2462. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2463. dr["gongchuang"] = response.code;
  2464. }
  2465. }
  2466. }
  2467. catch (NullReferenceException ex)
  2468. {
  2469. }
  2470. }
  2471. }
  2472. writeGridDataTableJson(dStruct.TotalCount, dt);
  2473. }
  2474. public void get_erp_myreturnorderlist()
  2475. {
  2476. DataStruct dStruct = GetPostStruct();
  2477. List<string> lw = new List<string>();
  2478. string tid = GetPostString("ctid");
  2479. if (tid.Length > 0)
  2480. {
  2481. string select_tid = getTidByCtid(tid);
  2482. lw.Add(string.Format("tid='{0}'", select_tid));
  2483. }
  2484. else
  2485. {
  2486. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2487. }
  2488. string shopname = GetPostString("shopname");
  2489. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2490. string buyernick = GetPostString("buyer_nick");
  2491. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2492. string design = GetPostString("design");
  2493. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2494. string orderState = GetPostString("orderState");
  2495. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2496. string sellermemo = GetPostString("seller_memo");
  2497. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2498. string date1 = GetPostString("date1");
  2499. string date2 = GetPostString("date2");
  2500. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2501. if (dw.Length > 0) lw.Add(dw);
  2502. string price1 = GetPostString("price1");
  2503. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2504. string price2 = GetPostString("price2");
  2505. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2506. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2507. {
  2508. lw.Add(string.Format("CusOrgID = 94"));
  2509. }
  2510. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2511. {
  2512. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2513. }
  2514. else
  2515. {
  2516. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2517. }
  2518. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2519. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2520. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2521. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2522. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2523. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2524. if (dt != null && dt.Rows.Count > 0)
  2525. {
  2526. foreach (DataRow dr in dt.Rows)
  2527. {
  2528. try
  2529. {
  2530. // 对象操作
  2531. if (dStruct.PageSize != 100000)
  2532. {
  2533. if (dr["DispatchSort"].ToString() == "2")
  2534. {
  2535. dr["gongchuang"] = 200;
  2536. }
  2537. else if ("外协".Equals(dr["ToType"].ToString()))
  2538. {
  2539. dr["gongchuang"] = 200;
  2540. }
  2541. else if ("内部".Equals(dr["ToType"].ToString()))
  2542. {
  2543. dr["gongchuang"] = -1;
  2544. }
  2545. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2546. {
  2547. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2548. dr["gongchuang"] = response.code;
  2549. }
  2550. }
  2551. }
  2552. catch (NullReferenceException ex)
  2553. {
  2554. // 处理空引用异常
  2555. }
  2556. }
  2557. }
  2558. writeGridDataTableJson(dStruct.TotalCount, dt);
  2559. }
  2560. public void get_erp_myorderlist_pregather()
  2561. {
  2562. string date1 = GetPostString("date1");
  2563. string date2 = GetPostString("date2");
  2564. int userId = CurrentUser.UserID; //客服id
  2565. string orderWhere = "";
  2566. List<string> lw = new List<string>();
  2567. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2568. if (dw.Length > 0) lw.Add(dw);
  2569. lw.Add(string.Format("CustomerUserId={0}", userId));
  2570. lw.Add(string.Format("OrderState<9"));
  2571. orderWhere = string.Join(" and ", lw.ToArray());
  2572. string orderWhere2 = "";
  2573. List<string> lw2 = new List<string>();
  2574. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2575. if (dw2.Length > 0) lw2.Add(dw2);
  2576. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2577. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2578. string sql = string.Format("select *" +
  2579. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2580. "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 " +
  2581. "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 " +
  2582. "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");
  2583. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2584. //writeGridDataTableJson(dt.Rows.Count, dt);
  2585. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2586. }
  2587. public void upd_erp_publishorder()
  2588. {
  2589. if (UrlPostParmsCheck("ctid"))
  2590. {
  2591. string eid = GetPostString("ctid");
  2592. CeErpTradeCell entity = null;
  2593. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2594. if (entity != null)
  2595. {
  2596. entity.OrderState = 0; //发布后,变为待抢单
  2597. entity.Update();
  2598. commonHelper.UpdateRelationOrder(entity.ctid);
  2599. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2600. returnSuccessMsg("发布成功!");
  2601. return;
  2602. }
  2603. returnErrorMsg("找不到记录");
  2604. }
  2605. }
  2606. public void get_erp_my_tiporder()
  2607. {
  2608. StringBuilder sql = new StringBuilder();
  2609. int userId = 0;
  2610. if (CurrentUser != null) userId = CurrentUser.UserID;
  2611. string posCode = CurrentUser.UserPost.Post.Code;
  2612. string isTipedAfterSaleVerify = GetPostString("af");
  2613. DataTable dt = new DataTable();
  2614. if (posCode != "Supplier")
  2615. {
  2616. if (posCode == "CustomerService" || posCode == "Director")
  2617. {
  2618. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2619. }
  2620. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2621. {
  2622. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2623. }
  2624. else
  2625. {
  2626. string teamIds = CurrentUser.User.TeamIds;
  2627. if (teamIds == "")
  2628. {
  2629. teamIds = "0";
  2630. }
  2631. 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);
  2632. }
  2633. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2634. }
  2635. if (dt.Rows.Count <= 0)
  2636. {
  2637. string key = "aftersale_order_" + userId;
  2638. if (RedisHelper.HasKey(key))
  2639. {
  2640. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2641. dt.Columns.Add("ctid", typeof(string));
  2642. dt.Columns.Add("IsReadTag", typeof(int));
  2643. foreach (var i in list)
  2644. {
  2645. DataRow data = dt.NewRow();
  2646. data["ctid"] = i;
  2647. data["IsReadTag"] = 4;
  2648. dt.Rows.Add(data);
  2649. }
  2650. RedisHelper.StringDelete(key);
  2651. }
  2652. }
  2653. if (dt.Rows.Count <= 0)
  2654. {
  2655. sql = new StringBuilder();
  2656. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2657. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2658. }
  2659. if (posCode == "Supplier")
  2660. {
  2661. string ids = CurrentUser.User.pemVend;
  2662. if (ids != null && ids.Length > 0)
  2663. {
  2664. string[] ids_list = ids.Split(',');
  2665. foreach (var item in ids_list)
  2666. {
  2667. string key = "return_order_" + item;
  2668. if (RedisHelper.HasKey(key))
  2669. {
  2670. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2671. dt.Columns.Add("ctid", typeof(string));
  2672. dt.Columns.Add("IsReadTag", typeof(int));
  2673. foreach (var i in list)
  2674. {
  2675. DataRow data = dt.NewRow();
  2676. data["ctid"] = i;
  2677. data["IsReadTag"] = 1;
  2678. dt.Rows.Add(data);
  2679. }
  2680. RedisHelper.StringDelete(key);
  2681. }
  2682. }
  2683. }
  2684. if (dt.Rows.Count <= 0)
  2685. {
  2686. sql = new StringBuilder();
  2687. 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);
  2688. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2689. }
  2690. }
  2691. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2692. }
  2693. public void reset_erp_tiporder()
  2694. {
  2695. string ids = GetPostString("ids");
  2696. string[] ctidList = ids.Split(',');
  2697. foreach (string ctid in ctidList)
  2698. {
  2699. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2700. if (enty != null)
  2701. {
  2702. enty.IsReadTag = 0;
  2703. enty.Update();
  2704. }
  2705. }
  2706. returnSuccessMsg("成功!");
  2707. return;
  2708. }
  2709. public void get_erp_designlist()
  2710. {
  2711. DataStruct dStruct = GetPostStruct();
  2712. List<string> lw = new List<string>();
  2713. string tid = GetPostString("ctid");
  2714. if (tid.Length > 0)
  2715. {
  2716. string select_tid = getTidByCtid(tid);
  2717. lw.Add(string.Format("tid='{0}'", select_tid));
  2718. }
  2719. string shopname = GetPostString("shopname");
  2720. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2721. string buyernick = GetPostString("buyer_nick");
  2722. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2723. string customer = GetPostString("customer");
  2724. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2725. string design = GetPostString("design");
  2726. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2727. string orderState = GetPostString("orderState");
  2728. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2729. lw.Add(string.Format("OrderState<6"));
  2730. string address = GetPostString("address");
  2731. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2732. string sellermemo = GetPostString("seller_memo");
  2733. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2734. string date1 = GetPostString("date1");
  2735. string date2 = GetPostString("date2");
  2736. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2737. if (dw.Length > 0) lw.Add(dw);
  2738. string apdate1 = GetPostString("apdate1");
  2739. string apdate2 = GetPostString("apdate2");
  2740. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2741. if (dwap.Length > 0) lw.Add(dwap);
  2742. string price1 = GetPostString("price1");
  2743. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2744. string price2 = GetPostString("price2");
  2745. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2746. string designTime = GetPostString("designtime");
  2747. if (designTime.Length > 0)
  2748. {
  2749. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2750. }
  2751. string usershop = CurrentUser.User.pemShop;
  2752. if (usershop.Length > 0)
  2753. {
  2754. lw.Add(string.Format("shopId in ({0})", usershop));
  2755. }
  2756. int myOrgid = CurrentUser.UserPost.OrgID;
  2757. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2758. if (myOrgCode.IndexOf("Designer") != -1)
  2759. {
  2760. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2761. {
  2762. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2763. }
  2764. else
  2765. {
  2766. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2767. }
  2768. }
  2769. else
  2770. {
  2771. string orgId = GetPostString("designerhd");
  2772. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2773. }
  2774. if (tid.Length > 0 || buyernick.Length > 0)
  2775. {
  2776. lw.Add(string.Format("OrderState >= 3"));
  2777. }
  2778. else
  2779. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2780. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2781. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2782. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2783. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2784. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2785. if (dt != null && dt.Rows.Count > 0)
  2786. {
  2787. foreach (DataRow dr in dt.Rows)
  2788. {
  2789. try
  2790. {
  2791. // 对象操作
  2792. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2793. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2794. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2795. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2796. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2797. if (dStruct.PageSize != 100000)
  2798. {
  2799. if (dr["DispatchSort"].ToString() == "2")
  2800. {
  2801. dr["gongchuang"] = 200;
  2802. }
  2803. else if ("外协".Equals(dr["ToType"].ToString()))
  2804. {
  2805. dr["gongchuang"] = 200;
  2806. }
  2807. else if ("内部".Equals(dr["ToType"].ToString()))
  2808. {
  2809. dr["gongchuang"] = -1;
  2810. }
  2811. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2812. {
  2813. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2814. dr["gongchuang"] = response.code;
  2815. }
  2816. }
  2817. }
  2818. catch (NullReferenceException ex)
  2819. {
  2820. }
  2821. }
  2822. }
  2823. writeGridDataTableJson(dStruct.TotalCount, dt);
  2824. }
  2825. public void get_erp_mydesignlist()
  2826. {
  2827. DataStruct dStruct = GetPostStruct();
  2828. List<string> lw = new List<string>();
  2829. string tid = GetPostString("ctid");
  2830. if (tid.Length > 0)
  2831. {
  2832. string select_tid = getTidByCtid(tid);
  2833. lw.Add(string.Format("tid='{0}'", select_tid));
  2834. }
  2835. string shopname = GetPostString("shopname");
  2836. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2837. string buyernick = GetPostString("buyer_nick");
  2838. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2839. string customer = GetPostString("customer");
  2840. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2841. string orderState = GetPostString("orderState");
  2842. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2843. //lw.Add(string.Format("OrderState<6"));
  2844. string date1 = GetPostString("date1");
  2845. string date2 = GetPostString("date2");
  2846. string dw = GetDateWhere("pay_time", date1, date2);
  2847. if (dw.Length > 0) lw.Add(dw);
  2848. string apdate1 = GetPostString("apdate1");
  2849. string apdate2 = GetPostString("apdate2");
  2850. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2851. if (dwap.Length > 0) lw.Add(dwap);
  2852. string price1 = GetPostString("price1");
  2853. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2854. string price2 = GetPostString("price2");
  2855. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2856. string olddownload = GetPostString("olddown");
  2857. if (olddownload == "1")
  2858. {
  2859. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2860. }
  2861. else if (olddownload == "2")
  2862. {
  2863. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2864. }
  2865. string sellermemo = GetPostString("seller_memo");
  2866. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2867. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2868. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2869. {
  2870. if (CurrentUser.User.TeamIds.Length > 0)
  2871. {
  2872. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2873. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2874. else
  2875. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2876. }
  2877. else
  2878. {
  2879. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2880. }
  2881. }
  2882. if (tid.Length <= 0)
  2883. {
  2884. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2885. }
  2886. lw.Add(string.Format("IsReturn!=3"));
  2887. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2888. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2889. string teamids = CurrentUser.User.TeamIds.ToString();
  2890. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2891. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2892. if (dt != null && dt.Rows.Count > 0)
  2893. {
  2894. foreach (DataRow dr in dt.Rows)
  2895. {
  2896. try
  2897. {
  2898. // 对象操作
  2899. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2900. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2901. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2902. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2903. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2904. if (dStruct.PageSize != 100000)
  2905. {
  2906. if (dr["DispatchSort"].ToString() == "2")
  2907. {
  2908. dr["gongchuang"] = 200;
  2909. }
  2910. else if ("外协".Equals(dr["ToType"].ToString()))
  2911. {
  2912. dr["gongchuang"] = 200;
  2913. }
  2914. else if ("内部".Equals(dr["ToType"].ToString()))
  2915. {
  2916. dr["gongchuang"] = -1;
  2917. }
  2918. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2919. {
  2920. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2921. dr["gongchuang"] = response.code;
  2922. }
  2923. }
  2924. }
  2925. catch (NullReferenceException ex)
  2926. {
  2927. }
  2928. }
  2929. }
  2930. writeGridDataTableJson(dStruct.TotalCount, dt);
  2931. }
  2932. public void set_erp_startdesign()
  2933. {
  2934. if (UrlPostParmsCheck("ctid"))
  2935. {
  2936. string eid = GetPostString("ctid");
  2937. CeErpTradeCell entity = null;
  2938. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2939. if (entity != null)
  2940. {
  2941. if (entity.OrderState != 3)
  2942. {
  2943. returnErrorMsg("请刷新,订单已经设计了");
  2944. return;
  2945. }
  2946. entity.StartDesignTime = DateTime.Now;
  2947. entity.OrderState = 4;
  2948. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2949. {
  2950. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2951. entity.SupplierId = suid;
  2952. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2953. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2954. }
  2955. entity.UpdateTime = DateTime.Now;
  2956. //entity.MakeSupplier = suname;
  2957. entity.Update();
  2958. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2959. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2960. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2961. commonHelper.getCytPrice(entity);
  2962. returnSuccessMsg("操作成功!");
  2963. return;
  2964. }
  2965. returnErrorMsg("找不到记录");
  2966. }
  2967. }
  2968. public void ins_erp_designselfmemo()
  2969. {
  2970. if (UrlPostParmsCheck("ctid"))
  2971. {
  2972. string eid = GetPostString("ctid");
  2973. string con = GetPostString("con");
  2974. CeErpTradeCell entity = null;
  2975. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2976. if (entity != null)
  2977. {
  2978. entity.DesignSelfMemo = con;
  2979. entity.Update();
  2980. returnSuccessMsg("操作成功!");
  2981. return;
  2982. }
  2983. returnErrorMsg("找不到记录");
  2984. }
  2985. }
  2986. public void ins_erp_designprice()
  2987. {
  2988. if (UrlPostParmsCheck("ctid"))
  2989. {
  2990. string eid = GetPostString("ctid");
  2991. int uid = CurrentUser.UserID;
  2992. string userName = CurrentUser.UserName;
  2993. CeErpTradeCell entity = null;
  2994. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2995. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2996. if (entitys == null)
  2997. {
  2998. entitys = new CeErpDesignerBill();
  2999. }
  3000. if (entity != null)
  3001. {
  3002. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3003. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3004. entity.StartDesignTime = DateTime.Now;
  3005. entity.OrderState = 4;
  3006. string suname = "";
  3007. if (entity.SupplierId == 0)
  3008. {
  3009. int sid = commonHelper.autoDistributeToSupplier(entity);
  3010. entity.SupplierId = sid;
  3011. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3012. }
  3013. entity.Update();
  3014. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3015. if (ceErpUserPost != null)
  3016. {
  3017. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3018. if (ceErpPost != null)
  3019. {
  3020. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3021. {
  3022. entitys.tid = entity.ctid;
  3023. entitys.oid = entity.tid;
  3024. entitys.uid = uid;
  3025. entitys.userName = userName;
  3026. entitys.designerType = 1;
  3027. entitys.designerTypeText = "内部设计师";
  3028. entitys.price = Convert.ToDouble(GetPostString("price"));
  3029. entitys.designNum = GetPostInt("designNum");
  3030. entitys.modifyNum = GetPostInt("modifyNum");
  3031. entitys.designSize = GetPostString("designSize");
  3032. entitys.modifySize = GetPostString("modifySize");
  3033. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3034. {
  3035. entitys.create_time = DateTime.Now;
  3036. entitys.create_u_id = uid;
  3037. entitys.create_u_name = userName;
  3038. entitys.Save();
  3039. }
  3040. else
  3041. {
  3042. entitys.update_time = DateTime.Now;
  3043. entitys.update_u_id = uid;
  3044. entitys.update_u_name = userName;
  3045. entitys.Update();
  3046. }
  3047. }
  3048. }
  3049. }
  3050. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3051. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3052. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3053. if (suname != "")
  3054. {
  3055. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3056. }
  3057. commonHelper.getCytPrice(entity);
  3058. returnSuccessMsg("操作成功!");
  3059. return;
  3060. }
  3061. returnErrorMsg("找不到记录");
  3062. }
  3063. }
  3064. public void upload_erp_filecomplete()
  3065. {
  3066. if (UrlPostParmsCheck("ctid"))
  3067. {
  3068. string eid = GetPostString("ctid");
  3069. CeErpTradeCell entity = null;
  3070. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3071. if (entity != null)
  3072. {
  3073. entity.OrderState = 5; //设计完成
  3074. entity.Update();
  3075. returnSuccessMsg(eid + "上传成功,设计完成!");
  3076. return;
  3077. }
  3078. returnErrorMsg("找不到订单记录");
  3079. }
  3080. }
  3081. public void get_erp_designovertimelist()
  3082. {
  3083. DataStruct dStruct = GetPostStruct();
  3084. List<string> lw = new List<string>();
  3085. string tid = GetPostString("ctid");
  3086. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3087. string shopname = GetPostString("shopname");
  3088. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3089. string buyernick = GetPostString("buyer_nick");
  3090. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3091. string ResponsibleMan = GetPostString("responsible");
  3092. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3093. string date1 = GetPostString("date1");
  3094. string date2 = GetPostString("date2");
  3095. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3096. if (dw.Length > 0) lw.Add(dw);
  3097. string price1 = GetPostString("price1");
  3098. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3099. string price2 = GetPostString("price2");
  3100. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3101. string orderState = GetPostString("orderState");
  3102. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3103. string sellermemo = GetPostString("seller_memo");
  3104. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3105. lw.Add(string.Format("UnusualTag=3"));
  3106. lw.Add(string.Format("IsRefund<={0}", 1));
  3107. dStruct.Order = "WaitDesignTime desc";
  3108. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3109. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3110. writeGridDataTableJson(dStruct.TotalCount, dt);
  3111. }
  3112. //设计管理 获取抢单大厅列表
  3113. public void get_erp_grabinglist()
  3114. {
  3115. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3116. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3117. bool oldOrder = false;
  3118. if (org != null)
  3119. {
  3120. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3121. }
  3122. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3123. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3124. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3125. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3126. //先处理订单数据
  3127. if (dt.Rows.Count > 0)
  3128. {
  3129. Dictionary<string, int> design = null;
  3130. int count = 0;
  3131. foreach (DataRow row in dt.Rows)
  3132. {
  3133. if (map.ContainsKey(row["ShopId"].ToString()))
  3134. {
  3135. map.TryGetValue(row["ShopId"].ToString(), out design);
  3136. }
  3137. else
  3138. {
  3139. design = new Dictionary<string, int>();
  3140. }
  3141. if (design.ContainsKey(row["ProductId"].ToString()))
  3142. {
  3143. design.TryGetValue(row["ProductId"].ToString(), out count);
  3144. }
  3145. count++;
  3146. design[row["ProductId"].ToString()] = count;
  3147. map[row["ShopId"].ToString()] = design;
  3148. }
  3149. }
  3150. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3151. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3152. //把店铺排序和技能排序分类
  3153. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3154. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3155. if (design_dt.Rows.Count > 0)
  3156. {
  3157. Dictionary<string, string> design = null;
  3158. List<string> shopIds = null;
  3159. foreach (DataRow row in design_dt.Rows)
  3160. {
  3161. if ("0".Equals(row["designId"].ToString()))
  3162. {
  3163. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3164. {
  3165. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3166. }
  3167. else
  3168. {
  3169. shopIds = new List<string>();
  3170. }
  3171. shopIds.Add(row["shopId"].ToString());
  3172. shop_orders[row["orders"].ToString()] = shopIds;
  3173. }
  3174. else
  3175. {
  3176. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3177. {
  3178. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3179. }
  3180. else
  3181. {
  3182. design = new Dictionary<string, string>();
  3183. }
  3184. design[row["orders"].ToString()] = row["designId"].ToString();
  3185. design_orders[row["shopId"].ToString()] = design;
  3186. }
  3187. }
  3188. //处理成key value后根据key排序
  3189. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3190. foreach (List<string> val in shop_orders.Values)
  3191. {
  3192. if (val != null)
  3193. {
  3194. foreach (string key in val)
  3195. {
  3196. if (design_orders.ContainsKey(key.ToString()))
  3197. {
  3198. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3199. }
  3200. }
  3201. }
  3202. }
  3203. }
  3204. //校验哪个优先级有订单
  3205. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3206. foreach (string key in shop_orders.Keys)
  3207. {
  3208. List<string> ids = null;
  3209. shop_orders.TryGetValue(key, out ids);
  3210. //id为shopid
  3211. foreach (string id in ids)
  3212. {
  3213. Dictionary<string, int> list = null;
  3214. Dictionary<string, string> desing = null;
  3215. map.TryGetValue(id, out list);
  3216. design_orders.TryGetValue(id, out desing);
  3217. if (list != null && desing != null)
  3218. {
  3219. foreach (var item in desing)
  3220. {
  3221. int count = 0;
  3222. if (list.ContainsKey(item.Value))
  3223. {
  3224. list.TryGetValue(item.Value, out count);
  3225. if (count > 0)
  3226. {
  3227. designIds[id] = item.Value;
  3228. break;
  3229. }
  3230. }
  3231. }
  3232. }
  3233. }
  3234. if (designIds.Count > 0)
  3235. {
  3236. break;
  3237. }
  3238. }
  3239. DataTable table = new DataTable();
  3240. table.Columns.Add("tid", typeof(string));
  3241. table.Columns.Add("ctid", typeof(string));
  3242. table.Columns.Add("seller_nick", typeof(string));
  3243. table.Columns.Add("productName", typeof(string));
  3244. table.Columns.Add("pay_time", typeof(string));
  3245. table.Columns.Add("seller_memo", typeof(string));
  3246. if (designIds.Count > 0)
  3247. {
  3248. string shopId = "";
  3249. string productId = "";
  3250. foreach (var designInfo in designIds)
  3251. {
  3252. shopId = designInfo.Key;
  3253. productId = designInfo.Value;
  3254. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3255. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3256. if (dt.Rows.Count > 0)
  3257. {
  3258. foreach (DataRow row in dt.Rows)
  3259. {
  3260. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3261. {
  3262. DataRow data = table.NewRow();
  3263. data["ctid"] = row["ctid"].ToString();
  3264. data["tid"] = row["tid"].ToString();
  3265. data["seller_nick"] = ceErpShop.ShopName;
  3266. data["pay_time"] = row["pay_time"].ToString();
  3267. data["seller_memo"] = row["seller_memo"].ToString();
  3268. data["productName"] = ceErpProduct.PType;
  3269. table.Rows.Add(data);
  3270. }
  3271. }
  3272. }
  3273. }
  3274. }
  3275. writeGridDataTableJson(table.Rows.Count, table);
  3276. }
  3277. private object rushLockObject = new object();
  3278. public void set_erp_grabingorder()
  3279. {
  3280. if (UrlPostParmsCheck("ctid"))
  3281. {
  3282. int total = CurrentUser.User.Person.Total;
  3283. int userId = CurrentUser.User.ID;
  3284. int noFinish = CurrentUser.User.Person.NoFinish;
  3285. int finalization = CurrentUser.User.Person.Finalization;
  3286. string eids = GetPostString("ctid");
  3287. string key = "RushKey_" + userId;
  3288. int count = 0;
  3289. if (erpRedis.RedisHelper.KeyExists(key))
  3290. {
  3291. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3292. if (redisCount != null)
  3293. {
  3294. count = Convert.ToInt32(redisCount);
  3295. }
  3296. }
  3297. if (count >= total)
  3298. {
  3299. returnErrorMsg("半小时内已经抢" + total + "单");
  3300. return;
  3301. }
  3302. string[] ctidlist = eids.Split(',');
  3303. if (count + ctidlist.Length > total)
  3304. {
  3305. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3306. return;
  3307. }
  3308. int itag = 0;
  3309. lock (rushLockObject)
  3310. {
  3311. if (ctidlist.Length > 0)
  3312. {
  3313. string[] dtList = new string[ctidlist.Length];
  3314. for (int i = 0; i < ctidlist.Length; i++)
  3315. {
  3316. dtList[i] = "'" + ctidlist[i] + "'";
  3317. }
  3318. 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"));
  3319. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3320. if (dt_user.Rows.Count > 0)
  3321. {
  3322. int doing = 0;//未定稿
  3323. int finish = 0;//已完成
  3324. foreach (DataRow dr in dt_user.Rows)
  3325. {
  3326. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3327. {
  3328. doing++;
  3329. }
  3330. else
  3331. {
  3332. finish++;
  3333. }
  3334. }
  3335. if (doing >= noFinish)
  3336. {
  3337. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3338. return;
  3339. }
  3340. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3341. {
  3342. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3343. return;
  3344. }
  3345. }
  3346. //校验选择单子状态
  3347. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3348. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3349. if (dt.Rows.Count > 0)
  3350. {
  3351. List<string> list = new List<string>();
  3352. foreach (DataRow dr in dt.Rows)
  3353. {
  3354. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3355. {
  3356. list.Add(dr["ctid"].ToString());
  3357. }
  3358. }
  3359. if (list.Count > 0)
  3360. {
  3361. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3362. return;
  3363. }
  3364. }
  3365. foreach (string ctid in ctidlist)
  3366. {
  3367. CeErpTradeCell entity = null;
  3368. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3369. if (entity != null)
  3370. {
  3371. entity.OrderState = 3;
  3372. entity.DesignUserId = CurrentUser.UserID;
  3373. entity.WaitDesignTime = DateTime.Now;
  3374. entity.StartDesignTime = DateTime.Now;
  3375. entity.Update();
  3376. commonHelper.UpdateRelationOrder(entity.ctid);
  3377. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3378. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3379. itag++;
  3380. }
  3381. }
  3382. }
  3383. }
  3384. count += ctidlist.Length;
  3385. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3386. if (itag == 0)
  3387. returnErrorMsg("没有找到相关订单");
  3388. else
  3389. returnSuccessMsg("抢单成功!");
  3390. return;
  3391. }
  3392. }
  3393. public void get_erp_waitorderlist()
  3394. {
  3395. DataStruct dStruct = GetPostStruct();
  3396. List<string> lw = new List<string>();
  3397. string tid = GetPostString("ctid");
  3398. if (tid.Length > 0)
  3399. {
  3400. string select_tid = getTidByCtid(tid);
  3401. lw.Add(string.Format("tid='{0}'", select_tid));
  3402. }
  3403. string shopname = GetPostString("shopname");
  3404. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3405. string buyernick = GetPostString("buyer_nick");
  3406. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3407. string customer = GetPostString("customer");
  3408. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3409. string design = GetPostString("design");
  3410. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3411. string orderState = GetPostString("orderState");
  3412. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3413. string supplier = GetPostString("supplier");
  3414. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3415. string sellermemo = GetPostString("seller_memo");
  3416. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3417. string otherMemo = GetPostString("otherMemo");
  3418. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3419. string address = GetPostString("address");
  3420. 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));
  3421. string date1 = GetPostString("date1");
  3422. string date2 = GetPostString("date2");
  3423. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3424. if (dw.Length > 0) lw.Add(dw);
  3425. string price1 = GetPostString("price1");
  3426. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3427. string price2 = GetPostString("price2");
  3428. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3429. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3430. lw.Add(string.Format("IsSample != 2 "));
  3431. lw.Add(string.Format("OrderState = 5 "));
  3432. lw.Add(string.Format("IsRefund<={0}", 1));
  3433. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3434. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3435. string pagesize = GetPostString("pagesize");
  3436. if (pagesize != null)
  3437. {
  3438. dStruct.PageSize = 200;
  3439. }
  3440. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3441. List<string> tids = new List<string>();
  3442. if (dt != null)
  3443. {
  3444. dt.Columns.Add("compenPrice", typeof(double));
  3445. foreach (DataRow dr in dt.Rows)
  3446. {
  3447. if (Convert.IsDBNull(dr["compenPrice"]))
  3448. {
  3449. dr["compenPrice"] = 0;
  3450. }
  3451. tids.Add("'" + dr["tid"].ToString() + "'");
  3452. 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();
  3453. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3454. {
  3455. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3456. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3457. entity.SupplierId = suid;
  3458. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3459. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3460. entity.Update();
  3461. }
  3462. }
  3463. }
  3464. if (tids.Count > 0)
  3465. {
  3466. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3467. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3468. if (dt_price != null && dt_price.Rows.Count > 0)
  3469. {
  3470. foreach (DataRow dr in dt_price.Rows)
  3471. {
  3472. foreach (DataRow row in dt.Rows)
  3473. {
  3474. if (row["tid"].Equals(dr["ptid"]))
  3475. {
  3476. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3477. break;
  3478. }
  3479. }
  3480. }
  3481. }
  3482. }
  3483. writeGridDataTableJson(dStruct.TotalCount, dt);
  3484. }
  3485. public void get_erp_supplierwaitorderlist()
  3486. {
  3487. DataStruct dStruct = GetPostStruct();
  3488. List<string> lw = new List<string>();
  3489. string tid = GetPostString("ctid");
  3490. if (tid.Length > 0)
  3491. {
  3492. string select_tid = getTidByCtid(tid);
  3493. lw.Add(string.Format("tid='{0}'", select_tid));
  3494. }
  3495. string shopname = GetPostString("shopname");
  3496. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3497. string sellermemo = GetPostString("seller_memo");
  3498. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3499. string date1 = GetPostString("date1");
  3500. string date2 = GetPostString("date2");
  3501. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3502. if (dw.Length > 0) lw.Add(dw);
  3503. lw.Add(string.Format("OrderState = 5 "));
  3504. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3505. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3506. {
  3507. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3508. }
  3509. string supplier = GetPostString("supplier");
  3510. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3511. {
  3512. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3513. }
  3514. lw.Add(string.Format("IsRefund<={0}", 1));
  3515. dStruct.Order = "FinishDesignTime desc";
  3516. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3517. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3518. if (dt != null)
  3519. {
  3520. foreach (DataRow dr in dt.Rows)
  3521. {
  3522. 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();
  3523. }
  3524. }
  3525. writeGridDataTableJson(dStruct.TotalCount, dt);
  3526. }
  3527. public void upd_erp_verifytosupplier()
  3528. {
  3529. if (UrlPostParmsCheck("ctid"))
  3530. {
  3531. string eids = GetPostString("ctid");
  3532. CeErpTradeCell entity = null;
  3533. string[] eidsList = eids.Split(',');
  3534. if (eidsList.Length <= 0)
  3535. {
  3536. returnErrorMsg("订单号不能空");
  3537. return;
  3538. }
  3539. List<string> tLst = new List<string>();
  3540. foreach (string ctidstr in eidsList)
  3541. {
  3542. tLst.Add("'" + ctidstr + "'");
  3543. CeErpDataSendOrderInfo.createObject(ctidstr);
  3544. }
  3545. string needtids = string.Join(",", tLst.ToArray());
  3546. StringBuilder sql = new StringBuilder();
  3547. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3548. 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);
  3549. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3550. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3551. returnSuccessMsg("操作成功!");
  3552. return;
  3553. /**foreach (string ctidstr in eidsList)
  3554. {
  3555. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3556. if (entity != null)
  3557. {
  3558. if (entity.SupplierId == 0)
  3559. {
  3560. continue;
  3561. }
  3562. entity.IsVerifyToSupplier = true;
  3563. if (entity.IsReturn == 1) //1是供应商打回
  3564. {
  3565. entity.IsReturn = 0;
  3566. }
  3567. entity.FinishPlaceTime = DateTime.Now;
  3568. entity.PlaceUserId = CurrentUser.UserID;
  3569. entity.Update();
  3570. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3571. }
  3572. }
  3573. returnSuccessMsg("操作成功!");
  3574. return;**/
  3575. }
  3576. }
  3577. public void upd_erp_supplierback()
  3578. {
  3579. if (UrlPostParmsCheck("ctid"))
  3580. {
  3581. string eid = GetPostString("ctid");
  3582. string reason = GetPostString("returnreason");
  3583. CeErpTradeCell entity = null;
  3584. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3585. if (entity != null)
  3586. {
  3587. string message = "操作成功!";
  3588. string isDown = "";
  3589. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3590. {
  3591. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3592. isDown = "被点击下载";
  3593. }
  3594. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3595. {
  3596. string key = "return_order_" + entity.SupplierId;
  3597. List<string> list = new List<string>();
  3598. if (RedisHelper.HasKey(key))
  3599. {
  3600. object data = RedisHelper.StringGet(key);
  3601. list = Convert.ToString(data).Split(',').ToList();
  3602. }
  3603. list.Add(eid);
  3604. RedisHelper.StringSet(key, string.Join(",", list));
  3605. }
  3606. entity.IsVerifyToSupplier = false;
  3607. entity.IsReturn = 1;
  3608. entity.IsHaveNewOrder = 0;
  3609. entity.ReturnTime = DateTime.Now;
  3610. entity.ReturnReason = reason;
  3611. if (entity.OrderState == 6)
  3612. {
  3613. entity.OrderState = 5;
  3614. }
  3615. entity.Update();
  3616. CeErpSukuraData.createInfo(entity.ctid, 5);
  3617. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3618. returnSuccessMsg(message);
  3619. return;
  3620. }
  3621. returnErrorMsg("找不到订单记录");
  3622. }
  3623. }
  3624. public void upd_erp_toaftersaleorder()
  3625. {
  3626. if (UrlPostParmsCheck("ctid"))
  3627. {
  3628. string eid = GetPostString("ctid");
  3629. string reason = GetPostString("returnreason");
  3630. CeErpTradeCell entity = null;
  3631. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3632. if (entity != null)
  3633. {
  3634. if (entity.isAfterSaleOrder != 1)
  3635. {
  3636. returnErrorMsg("带S的售后单才能打回给售后");
  3637. return;
  3638. }
  3639. if (entity.OrderState >= 5)
  3640. {
  3641. returnErrorMsg("已经设计完成了不能打回给售后");
  3642. return;
  3643. }
  3644. entity.OrderState = 0;
  3645. entity.IsReturn = 3;
  3646. entity.ReturnTime = DateTime.Now;
  3647. entity.UpdateTime = DateTime.Now;
  3648. entity.ReturnReason = reason;
  3649. entity.Update();
  3650. CeErpSukuraData.createInfo(entity.ctid, 5);
  3651. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3652. returnSuccessMsg("操作成功!");
  3653. return;
  3654. }
  3655. returnErrorMsg("找不到订单记录");
  3656. }
  3657. }
  3658. public void upd_erp_aftersaletodesign()
  3659. {
  3660. if (UrlPostParmsCheck("ctid"))
  3661. {
  3662. string eid = GetPostString("ctid");
  3663. CeErpTradeCell entity = null;
  3664. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3665. if (entity != null)
  3666. {
  3667. entity.OrderState = 3;
  3668. entity.IsReturn = 0;
  3669. entity.UpdateTime = DateTime.Now;
  3670. entity.Update();
  3671. CeErpSukuraData.createInfo(entity.ctid, 5);
  3672. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3673. returnSuccessMsg("操作成功!");
  3674. return;
  3675. }
  3676. returnErrorMsg("找不到订单记录");
  3677. }
  3678. }
  3679. public void assign_erp_supplier()
  3680. {
  3681. if (UrlPostParmsCheck("ctid"))
  3682. {
  3683. string eids = GetPostString("ctid");
  3684. int sid = GetPostInt("SupplierName");
  3685. string fromTag = GetPostString("tag");
  3686. string[] eidList = eids.Split(',');
  3687. if (eidList.Length <= 0)
  3688. {
  3689. returnErrorMsg("指派不能为空");
  3690. return;
  3691. }
  3692. string errMsg = "";
  3693. string suname = commonHelper.getSupplierNameById(sid);
  3694. foreach (string ctid in eidList)
  3695. {
  3696. CeErpTradeCell entity = null;
  3697. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3698. if (entity != null)
  3699. {
  3700. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3701. {
  3702. errMsg += (ctid + "指派失败!!!");
  3703. continue;
  3704. }
  3705. entity.SupplierId = sid;
  3706. entity.Update();
  3707. commonHelper.UpdateRelationOrder(entity.ctid);
  3708. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3709. if (entity.OrderState >= 6)
  3710. {
  3711. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3712. //{
  3713. // string msl = entity.MakeSupplier;
  3714. // string[] mslist = msl.Split(',');
  3715. // 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);
  3716. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3717. //}
  3718. //else
  3719. //{
  3720. StringBuilder sql = new StringBuilder();
  3721. 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);
  3722. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3723. //}
  3724. }
  3725. }
  3726. else
  3727. {
  3728. continue;
  3729. }
  3730. }
  3731. if (errMsg.Length > 0)
  3732. {
  3733. returnErrorMsg(errMsg);
  3734. return;
  3735. }
  3736. returnSuccessMsg("操作成功!");
  3737. return;
  3738. }
  3739. }
  3740. public void assign_erp_makesupplier()
  3741. {
  3742. if (UrlPostParmsCheck("ctid"))
  3743. {
  3744. string eids = GetPostString("ctid");
  3745. string sname = GetPostString("SupplierName");
  3746. string[] eidList = eids.Split(',');
  3747. if (eidList.Length <= 0)
  3748. {
  3749. returnErrorMsg("指派不能为空");
  3750. return;
  3751. }
  3752. List<string> tLst = new List<string>();
  3753. foreach (string ctid in eidList)
  3754. {
  3755. CeErpTradeCell entity = null;
  3756. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3757. if (entity != null)
  3758. {
  3759. entity.MakeSupplier = sname;
  3760. entity.Update();
  3761. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3762. tLst.Add("'" + ctid + "'");
  3763. }
  3764. else
  3765. {
  3766. continue;
  3767. }
  3768. }
  3769. string ctids = string.Join(",", tLst.ToArray());
  3770. StringBuilder sql2 = new StringBuilder();
  3771. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3772. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3773. returnSuccessMsg("操作成功!");
  3774. return;
  3775. }
  3776. }
  3777. public void ins_erp_returnreason()
  3778. {
  3779. if (UrlPostParmsCheck("ctid"))
  3780. {
  3781. string eid = GetPostString("ctid");
  3782. CeErpTradeCell entity = null;
  3783. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3784. string userpost = CurrentUser.UserPost.Post.Code;
  3785. if (entity != null)
  3786. {
  3787. bool isPlace = false;
  3788. if (entity.OrderState > 6)
  3789. {
  3790. returnErrorMsg("已发货无法打回!");
  3791. return;
  3792. }
  3793. if (entity.OrderState == 6)
  3794. {
  3795. isPlace = true;
  3796. }
  3797. bool isNeedUpdateCell2 = false;
  3798. if (entity.OrderState >= 6)
  3799. {
  3800. isNeedUpdateCell2 = true;
  3801. }
  3802. int returnTag = 2;
  3803. if (userpost == "Supplier")
  3804. {
  3805. returnTag = 1;
  3806. }
  3807. int toType = GetPostInt("totype");
  3808. string fromType = "3";
  3809. if (entity.OrderState < 5)
  3810. {
  3811. fromType = "3";
  3812. }
  3813. else
  3814. {
  3815. fromType = "4";
  3816. }
  3817. if (entity.IsXianHuo == 0)
  3818. {
  3819. if (returnTag == 2)
  3820. {
  3821. if (toType == 1)
  3822. {
  3823. entity.OrderState = 0;
  3824. entity.ReturnUserType = 1;
  3825. string clearman = GetPostString("clearman");
  3826. if (!string.IsNullOrEmpty(clearman))
  3827. {
  3828. entity.DesignUserId = 0;
  3829. }
  3830. }
  3831. else
  3832. {
  3833. entity.OrderState = 3;
  3834. entity.ReturnUserType = 2;
  3835. }
  3836. entity.IsReadTag = 1;
  3837. }
  3838. else if (returnTag == 1)
  3839. {
  3840. entity.OrderState = 5;
  3841. }
  3842. entity.IsVerifyToSupplier = false;
  3843. }
  3844. if (entity.IsXianHuo == 1)
  3845. {
  3846. entity.OrderState = 5;
  3847. }
  3848. entity.UnusualTag = 0;
  3849. entity.UnusualTime = null;
  3850. entity.UnusualCon = "";
  3851. entity.IsReturn = returnTag;
  3852. entity.ReturnTime = DateTime.Now;
  3853. entity.UpdateTime = DateTime.Now;
  3854. entity.ReturnReason = GetPostString("returnreason");
  3855. entity.Update();
  3856. if (entity.OrderState == 3)
  3857. {
  3858. ApiVo apiVo = new ApiVo();
  3859. apiVo.orderNumber = entity.ctid;
  3860. apiVo.actionName = "rebutDesign";
  3861. apiVo.orderRemarks = entity.ReturnReason;
  3862. designHelper.API_WorkCore(apiVo);//rebutDesign
  3863. }
  3864. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3865. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3866. {
  3867. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3868. }
  3869. CeErpSukuraData.createInfo(entity.ctid, 5);
  3870. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3871. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3872. if (isPlace)
  3873. {
  3874. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3875. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3876. if (dth != null && dth.Rows.Count > 0)
  3877. {
  3878. dataSendOrderBean dataSendOrderBean = null;
  3879. foreach (DataRow item in dth.Rows)
  3880. {
  3881. try
  3882. {
  3883. dataSendOrderBean = new dataSendOrderBean();
  3884. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3885. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3886. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3887. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3888. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3889. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3890. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3891. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3892. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3893. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3894. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3895. dataSendOrderBean.Radio1723534706288 = "打回";
  3896. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3897. if (result != null)
  3898. {
  3899. if ("0".Equals(result.errcode))
  3900. {
  3901. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3902. }
  3903. else
  3904. {
  3905. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3906. }
  3907. }
  3908. }
  3909. catch (Exception ex)
  3910. {
  3911. }
  3912. }
  3913. }
  3914. }
  3915. if (isNeedUpdateCell2)
  3916. {
  3917. if (entity.MakeSupplier.IndexOf(",") != -1)
  3918. {
  3919. StringBuilder sql2 = new StringBuilder();
  3920. 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);
  3921. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3922. }
  3923. else
  3924. {
  3925. StringBuilder sql2 = new StringBuilder();
  3926. 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);
  3927. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3928. }
  3929. }
  3930. returnSuccessMsg("操作成功!");
  3931. return;
  3932. }
  3933. returnErrorMsg("找不到订单记录");
  3934. }
  3935. }
  3936. public void cyt_erp_returnreason()
  3937. {
  3938. if (UrlPostParmsCheck("ctid"))
  3939. {
  3940. string eid = GetPostString("ctid");
  3941. CeErpTradeCell entity = null;
  3942. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3943. string userpost = CurrentUser.UserPost.Post.Code;
  3944. if (entity != null)
  3945. {
  3946. if (entity.OrderState > 6)
  3947. {
  3948. returnErrorMsg("已发货无法打回!");
  3949. return;
  3950. }
  3951. JObject jsonObject = new JObject
  3952. {
  3953. { "Userid", "77886" },
  3954. { "Pwd", "lt666888" },
  3955. { "LTOrderId",eid }
  3956. };
  3957. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3958. JObject jsonObjects = JObject.Parse(response);
  3959. string msg = (string)jsonObjects["msg"];
  3960. if (msg != "取消成功")
  3961. {
  3962. returnErrorMsg(msg);
  3963. return;
  3964. }
  3965. bool isNeedUpdateCell2 = false;
  3966. if (entity.OrderState >= 6)
  3967. {
  3968. isNeedUpdateCell2 = true;
  3969. }
  3970. int returnTag = 2;
  3971. if (userpost == "Supplier")
  3972. {
  3973. returnTag = 1;
  3974. }
  3975. if (entity.IsXianHuo == 0)
  3976. {
  3977. if (returnTag == 2)
  3978. {
  3979. int toType = GetPostInt("totype");
  3980. if (toType == 1)
  3981. {
  3982. entity.OrderState = 0;
  3983. entity.ReturnUserType = 1;
  3984. }
  3985. else
  3986. {
  3987. entity.OrderState = 4;
  3988. entity.ReturnUserType = 2;
  3989. }
  3990. entity.IsReadTag = 1;
  3991. }
  3992. else if (returnTag == 1)
  3993. {
  3994. entity.OrderState = 5;
  3995. }
  3996. entity.IsVerifyToSupplier = false;
  3997. }
  3998. entity.UnusualTag = 0;
  3999. entity.UnusualTime = null;
  4000. entity.UnusualCon = "";
  4001. entity.IsReturn = returnTag;
  4002. entity.ReturnTime = DateTime.Now;
  4003. entity.ReturnReason = GetPostString("returnreason");
  4004. entity.Update();
  4005. if (entity.OrderState == 4)
  4006. {
  4007. ApiVo apiVo = new ApiVo();
  4008. apiVo.orderNumber = entity.ctid;
  4009. apiVo.actionName = "rebutDesign";
  4010. apiVo.orderRemarks = entity.ReturnReason;
  4011. designHelper.API_WorkCore(apiVo);//rebutDesign
  4012. }
  4013. CeErpSukuraData.createInfo(entity.ctid, 5);
  4014. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4015. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4016. if (isNeedUpdateCell2)
  4017. {
  4018. if (entity.MakeSupplier.IndexOf(",") != -1)
  4019. {
  4020. StringBuilder sql2 = new StringBuilder();
  4021. 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);
  4022. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4023. }
  4024. else
  4025. {
  4026. StringBuilder sql2 = new StringBuilder();
  4027. 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);
  4028. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4029. }
  4030. }
  4031. returnSuccessMsg("操作成功!");
  4032. return;
  4033. }
  4034. returnErrorMsg("找不到订单记录");
  4035. }
  4036. }
  4037. public void upd_erp_xianhuoreturntag()
  4038. {
  4039. if (UrlPostParmsCheck("ctid"))
  4040. {
  4041. string eids = GetPostString("ctid");
  4042. string[] ctids = eids.Split(',');
  4043. foreach (string ctid in ctids)
  4044. {
  4045. CeErpTradeCell entity = null;
  4046. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4047. if (entity != null)
  4048. {
  4049. entity.IsReturn = 0;
  4050. entity.Update();
  4051. CeErpSukuraData.createInfo(entity.ctid, 5);
  4052. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4053. }
  4054. }
  4055. returnSuccessMsg("操作成功!");
  4056. return;
  4057. }
  4058. }
  4059. public void get_erp_waitdeliverylist()
  4060. {
  4061. DataStruct dStruct = GetPostStruct();
  4062. List<string> lw = new List<string>();
  4063. string tid = GetPostString("ctid");
  4064. if (tid.Length > 0)
  4065. {
  4066. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4067. if (tid.Length > 5)
  4068. {
  4069. List<string> tids = getTidByCtidLike(tid);
  4070. if (tids.Count > 0 && tids.Count < 10)
  4071. {
  4072. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4073. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4074. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4075. {
  4076. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4077. }*/
  4078. }
  4079. }
  4080. lw.Add(tid_sql);
  4081. }
  4082. string shopname = GetPostString("shopname");
  4083. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4084. string buyernick = GetPostString("buyer_nick");
  4085. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4086. //if (tid.Length == 0 && buyernick.Length == 0)
  4087. //{
  4088. // lw.Add(string.Format("IsRefund<={0}", 1));
  4089. //}
  4090. string customer = GetPostString("customer");
  4091. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4092. string design = GetPostString("design");
  4093. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4094. string orderState = GetPostString("orderState");
  4095. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4096. string address = GetPostString("address");
  4097. 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));
  4098. string sellermemo = GetPostString("seller_memo");
  4099. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4100. string supplier = GetPostString("supplier");
  4101. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4102. string OrderArea = GetPostString("order_area");
  4103. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4104. string placedate1 = GetPostString("placedate1");
  4105. string placedate2 = GetPostString("placedate2");
  4106. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4107. if (fdw.Length > 0) lw.Add(fdw);
  4108. string price1 = GetPostString("price1");
  4109. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4110. string price2 = GetPostString("price2");
  4111. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4112. string unusualCon = GetPostString("unusualcon");
  4113. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4114. string otherMemo = GetPostString("otherMemo");
  4115. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4116. string posTag = CurrentUser.UserPost.Post.Code;
  4117. if (posTag == "Supplier")
  4118. {
  4119. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4120. }
  4121. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4122. lw.Add(string.Format("type != 'PDD' "));
  4123. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4124. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4125. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4126. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4127. writeGridDataTableJson(dStruct.TotalCount, dt);
  4128. }
  4129. public void get_erp_changedeliverylist()
  4130. {
  4131. DataStruct dStruct = GetPostStruct();
  4132. List<string> lw = new List<string>();
  4133. string tid = GetPostString("ctid");
  4134. if (tid.Length > 0)
  4135. {
  4136. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4137. if (tid.Length > 5)
  4138. {
  4139. List<string> tids = getTidByCtidLike(tid);
  4140. if (tids.Count > 0 && tids.Count < 10)
  4141. {
  4142. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4143. }
  4144. }
  4145. lw.Add(tid_sql);
  4146. }
  4147. string shopname = GetPostString("shopname");
  4148. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4149. string buyernick = GetPostString("buyer_nick");
  4150. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4151. //if (tid.Length == 0 && buyernick.Length == 0)
  4152. //{
  4153. // lw.Add(string.Format("IsRefund<={0}", 1));
  4154. //}
  4155. string customer = GetPostString("customer");
  4156. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4157. string design = GetPostString("design");
  4158. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4159. string orderState = GetPostString("orderState");
  4160. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4161. string address = GetPostString("address");
  4162. 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));
  4163. string sellermemo = GetPostString("seller_memo");
  4164. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4165. string supplier = GetPostString("supplier");
  4166. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4167. string OrderArea = GetPostString("order_area");
  4168. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4169. string placedate1 = GetPostString("placedate1");
  4170. string placedate2 = GetPostString("placedate2");
  4171. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4172. if (fdw.Length > 0) lw.Add(fdw);
  4173. string price1 = GetPostString("price1");
  4174. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4175. string price2 = GetPostString("price2");
  4176. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4177. string unusualCon = GetPostString("unusualcon");
  4178. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4179. string otherMemo = GetPostString("otherMemo");
  4180. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4181. string posTag = CurrentUser.UserPost.Post.Code;
  4182. if (posTag == "Supplier")
  4183. {
  4184. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4185. }
  4186. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4187. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4188. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4189. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4190. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4191. /*if (tid.Length > 0)
  4192. {
  4193. List<string> tids = new List<string>();
  4194. if (dt != null && dt.Rows.Count > 0)
  4195. {
  4196. foreach (DataRow item in dt.Rows)
  4197. {
  4198. tids.Add("'" + item["tid"] + "'");
  4199. }
  4200. }
  4201. if (tids.Count > 0)
  4202. {
  4203. lw.RemoveAt(0);
  4204. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4205. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4206. dt = WebCache.GetData("view_erptradecell", dStruct);
  4207. }
  4208. }*/
  4209. writeGridDataTableJson(dStruct.TotalCount, dt);
  4210. }
  4211. public void get_erp_pddderiving()
  4212. {
  4213. DataStruct dStruct = GetPostStruct();
  4214. List<string> lw = new List<string>();
  4215. string tid = GetPostString("ctid");
  4216. if (tid.Length > 0)
  4217. {
  4218. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4219. if (tid.Length > 5)
  4220. {
  4221. List<string> tids = getTidByCtidLike(tid);
  4222. if (tids.Count > 0 && tids.Count < 10)
  4223. {
  4224. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4225. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4226. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4227. {
  4228. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4229. }*/
  4230. }
  4231. }
  4232. lw.Add(tid_sql);
  4233. }
  4234. string shopname = GetPostString("shopname");
  4235. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4236. string buyernick = GetPostString("buyer_nick");
  4237. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4238. //if (tid.Length == 0 && buyernick.Length == 0)
  4239. //{
  4240. // lw.Add(string.Format("IsRefund<={0}", 1));
  4241. //}
  4242. string customer = GetPostString("customer");
  4243. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4244. string design = GetPostString("design");
  4245. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4246. string orderState = GetPostString("orderState");
  4247. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4248. string address = GetPostString("address");
  4249. 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));
  4250. string sellermemo = GetPostString("seller_memo");
  4251. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4252. string supplier = GetPostString("supplier");
  4253. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4254. string OrderArea = GetPostString("order_area");
  4255. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4256. string placedate1 = GetPostString("placedate1");
  4257. string placedate2 = GetPostString("placedate2");
  4258. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4259. if (fdw.Length > 0) lw.Add(fdw);
  4260. string price1 = GetPostString("price1");
  4261. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4262. string price2 = GetPostString("price2");
  4263. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4264. string unusualCon = GetPostString("unusualcon");
  4265. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4266. string posTag = CurrentUser.UserPost.Post.Code;
  4267. if (posTag == "Supplier")
  4268. {
  4269. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4270. }
  4271. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4272. lw.Add(string.Format("type = 'PDD' "));
  4273. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4274. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4275. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4276. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4277. /*if (tid.Length > 0)
  4278. {
  4279. List<string> tids = new List<string>();
  4280. if (dt != null && dt.Rows.Count > 0)
  4281. {
  4282. foreach (DataRow item in dt.Rows)
  4283. {
  4284. tids.Add("'" + item["tid"] + "'");
  4285. }
  4286. }
  4287. if (tids.Count > 0)
  4288. {
  4289. lw.RemoveAt(0);
  4290. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4291. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4292. dt = WebCache.GetData("view_erptradecell", dStruct);
  4293. }
  4294. }*/
  4295. writeGridDataTableJson(dStruct.TotalCount, dt);
  4296. }
  4297. public void get_erp_jdderiving()
  4298. {
  4299. DataStruct dStruct = GetPostStruct();
  4300. List<string> lw = new List<string>();
  4301. string tid = GetPostString("ctid");
  4302. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4303. string shopname = GetPostString("shopname");
  4304. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4305. string buyernick = GetPostString("buyer_nick");
  4306. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4307. //if (tid.Length == 0 && buyernick.Length == 0)
  4308. //{
  4309. // lw.Add(string.Format("IsRefund<={0}", 1));
  4310. //}
  4311. string customer = GetPostString("customer");
  4312. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4313. string design = GetPostString("design");
  4314. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4315. string orderState = GetPostString("orderState");
  4316. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4317. string address = GetPostString("address");
  4318. 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));
  4319. string sellermemo = GetPostString("seller_memo");
  4320. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4321. string supplier = GetPostString("supplier");
  4322. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4323. string OrderArea = GetPostString("order_area");
  4324. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4325. string placedate1 = GetPostString("placedate1");
  4326. string placedate2 = GetPostString("placedate2");
  4327. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4328. if (fdw.Length > 0) lw.Add(fdw);
  4329. string price1 = GetPostString("price1");
  4330. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4331. string price2 = GetPostString("price2");
  4332. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4333. string unusualCon = GetPostString("unusualcon");
  4334. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4335. string posTag = CurrentUser.UserPost.Post.Code;
  4336. if (posTag == "Supplier")
  4337. {
  4338. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4339. }
  4340. lw.Add(string.Format("OrderState = 6 "));
  4341. lw.Add(string.Format("type = 'JD' "));
  4342. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4343. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4344. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4345. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4346. writeGridDataTableJson(dStruct.TotalCount, dt);
  4347. }
  4348. public void get_erp_demoorderlist()
  4349. {
  4350. DataStruct dStruct = GetPostStruct();
  4351. List<string> lw = new List<string>();
  4352. string tid = GetPostString("ctid");
  4353. if (tid.Length > 0)
  4354. {
  4355. string select_tid = getTidByCtid(tid);
  4356. lw.Add(string.Format("tid='{0}'", select_tid));
  4357. }
  4358. string shopname = GetPostString("shopname");
  4359. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4360. string buyernick = GetPostString("buyer_nick");
  4361. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4362. string customer = GetPostString("customer");
  4363. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4364. string design = GetPostString("design");
  4365. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4366. string orderState = GetPostString("orderState");
  4367. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4368. string address = GetPostString("address");
  4369. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4370. string sellermemo = GetPostString("seller_memo");
  4371. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4372. string supplier = GetPostString("supplier");
  4373. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4374. string OrderArea = GetPostString("order_area");
  4375. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4376. string date1 = GetPostString("date1");
  4377. string date2 = GetPostString("date2");
  4378. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4379. if (dw.Length > 0) lw.Add(dw);
  4380. string price1 = GetPostString("price1");
  4381. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4382. string price2 = GetPostString("price2");
  4383. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4384. string posTag = CurrentUser.UserPost.Post.Code;
  4385. if (posTag == "Supplier")
  4386. {
  4387. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4388. }
  4389. //lw.Add(string.Format("OrderState = 6 "));
  4390. lw.Add(string.Format("IsSample={0}", 3));
  4391. lw.Add(string.Format("IsRefund<={0}", 1));
  4392. dStruct.Order = "pay_time desc";
  4393. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4394. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4395. writeGridDataTableJson(dStruct.TotalCount, dt);
  4396. }
  4397. public void save_erp_checkmemo()
  4398. {
  4399. if (UrlPostParmsCheck("ctid"))
  4400. {
  4401. string ctid = GetPostString("ctid");
  4402. CeErpTradeCell entity = null;
  4403. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4404. if (entity != null)
  4405. {
  4406. entity.CheckMemo = GetPostString("CheckMemo");
  4407. entity.Update();
  4408. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4409. if (trade != null)
  4410. {
  4411. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4412. }
  4413. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4414. returnSuccessMsg("保存成功!");
  4415. return;
  4416. }
  4417. returnErrorMsg("找不到记录");
  4418. }
  4419. }
  4420. public void get_erp_returnlist()
  4421. {
  4422. DataStruct dStruct = GetPostStruct();
  4423. List<string> lw = new List<string>();
  4424. string tid = GetPostString("ctid");
  4425. if (tid.Length > 0)
  4426. {
  4427. string select_tid = getTidByCtid(tid);
  4428. lw.Add(string.Format("tid='{0}'", select_tid));
  4429. }
  4430. string shopname = GetPostString("shopname");
  4431. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4432. string buyernick = GetPostString("buyer_nick");
  4433. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4434. string customer = GetPostString("customer");
  4435. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4436. string design = GetPostString("design");
  4437. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4438. string orderState = GetPostString("orderState");
  4439. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4440. string address = GetPostString("address");
  4441. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4442. string sellermemo = GetPostString("seller_memo");
  4443. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4444. string supplier = GetPostString("supplier");
  4445. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4446. string date1 = GetPostString("date1");
  4447. string date2 = GetPostString("date2");
  4448. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4449. if (dw.Length > 0) lw.Add(dw);
  4450. string bdate1 = GetPostString("backdate1");
  4451. string bdate2 = GetPostString("backdate2");
  4452. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4453. if (dw_back.Length > 0) lw.Add(dw_back);
  4454. string price1 = GetPostString("price1");
  4455. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4456. string price2 = GetPostString("price2");
  4457. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4458. lw.Add(string.Format("IsReturn>0"));
  4459. lw.Add(string.Format("IsXianHuo=0"));
  4460. lw.Add(string.Format("IsReturn!=3"));
  4461. string backtype = GetPostString("backtype");
  4462. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4463. dStruct.Order = "FinishDesignTime desc";
  4464. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4465. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4466. writeGridDataTableJson(dStruct.TotalCount, dt);
  4467. }
  4468. public void get_erp_today_sumreturn()
  4469. {
  4470. DataStruct dStruct = GetPostStruct();
  4471. List<string> lw = new List<string>();
  4472. string bdate1 = GetPostString("returnTimeS");
  4473. string bdate2 = GetPostString("returnTimeE");
  4474. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4475. if (dw_back.Length > 0) lw.Add(dw_back);
  4476. lw.Add(string.Format("IsReturn=0"));
  4477. lw.Add(string.Format("IsXianHuo=0"));
  4478. string mainWhere = string.Join(" and ", lw.ToArray());
  4479. string sql = "";
  4480. if (dw_back.Length > 0)
  4481. {
  4482. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4483. }
  4484. else
  4485. {
  4486. 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 + "'";
  4487. }
  4488. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4489. decimal total = 0, today_finish = 0;
  4490. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4491. {
  4492. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4493. }
  4494. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4495. {
  4496. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4497. }
  4498. var res = new
  4499. {
  4500. data = total,
  4501. data1 = today_finish,
  4502. };
  4503. string ro_jsond = JsonConvert.SerializeObject(res);
  4504. returnSuccess(ro_jsond);
  4505. return;
  4506. }
  4507. public void get_erp_allreturnlist()
  4508. {
  4509. DataStruct dStruct = GetPostStruct();
  4510. List<string> lw = new List<string>();
  4511. string tid = GetPostString("ctid");
  4512. if (tid.Length > 0)
  4513. {
  4514. string select_tid = getTidByCtid(tid);
  4515. lw.Add(string.Format("tid='{0}'", select_tid));
  4516. }
  4517. string shopname = GetPostString("shopname");
  4518. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4519. string buyernick = GetPostString("buyer_nick");
  4520. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4521. string customer = GetPostString("customer");
  4522. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4523. string design = GetPostString("design");
  4524. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4525. string orderState = GetPostString("orderState");
  4526. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4527. string address = GetPostString("address");
  4528. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4529. string sellermemo = GetPostString("seller_memo");
  4530. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4531. string supplier = GetPostString("supplier");
  4532. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4533. string date1 = GetPostString("date1");
  4534. string date2 = GetPostString("date2");
  4535. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4536. if (dw.Length > 0) lw.Add(dw);
  4537. string bdate1 = GetPostString("backdate1");
  4538. string bdate2 = GetPostString("backdate2");
  4539. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4540. if (dw_back.Length > 0) lw.Add(dw_back);
  4541. string price1 = GetPostString("price1");
  4542. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4543. string price2 = GetPostString("price2");
  4544. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4545. string backreason = GetPostString("backreason");
  4546. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4547. lw.Add(string.Format("IsXianHuo=0"));
  4548. lw.Add(string.Format("ReturnTime != ''"));
  4549. string backtype = GetPostString("backtype");
  4550. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4551. dStruct.Order = "FinishDesignTime desc";
  4552. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4553. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4554. writeGridDataTableJson(dStruct.TotalCount, dt);
  4555. }
  4556. public void get_erp_aftersalereturnlist()
  4557. {
  4558. DataStruct dStruct = GetPostStruct();
  4559. List<string> lw = new List<string>();
  4560. string tid = GetPostString("ctid");
  4561. if (tid.Length > 0)
  4562. {
  4563. string select_tid = getTidByCtid(tid);
  4564. lw.Add(string.Format("tid='{0}'", select_tid));
  4565. }
  4566. string shopname = GetPostString("shopname");
  4567. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4568. string buyernick = GetPostString("buyer_nick");
  4569. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4570. string customer = GetPostString("customer");
  4571. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4572. string design = GetPostString("design");
  4573. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4574. string orderState = GetPostString("orderState");
  4575. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4576. string address = GetPostString("address");
  4577. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4578. string sellermemo = GetPostString("seller_memo");
  4579. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4580. string supplier = GetPostString("supplier");
  4581. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4582. string date1 = GetPostString("date1");
  4583. string date2 = GetPostString("date2");
  4584. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4585. if (dw.Length > 0) lw.Add(dw);
  4586. string bdate1 = GetPostString("backdate1");
  4587. string bdate2 = GetPostString("backdate2");
  4588. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4589. if (dw_back.Length > 0) lw.Add(dw_back);
  4590. string price1 = GetPostString("price1");
  4591. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4592. string price2 = GetPostString("price2");
  4593. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4594. lw.Add(string.Format("IsReturn=3"));
  4595. string backtype = GetPostString("backtype");
  4596. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4597. string backreason = GetPostString("backreason");
  4598. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4599. dStruct.Order = "ReturnTime desc";
  4600. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4601. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4602. writeGridDataTableJson(dStruct.TotalCount, dt);
  4603. }
  4604. public void get_erp_xianhuoreturnlist()
  4605. {
  4606. DataStruct dStruct = GetPostStruct();
  4607. List<string> lw = new List<string>();
  4608. string tid = GetPostString("ctid");
  4609. if (tid.Length > 0)
  4610. {
  4611. string select_tid = getTidByCtid(tid);
  4612. lw.Add(string.Format("tid='{0}'", select_tid));
  4613. }
  4614. string shopname = GetPostString("shopname");
  4615. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4616. string buyernick = GetPostString("buyer_nick");
  4617. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4618. string customer = GetPostString("customer");
  4619. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4620. string design = GetPostString("design");
  4621. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4622. string orderState = GetPostString("orderState");
  4623. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4624. string address = GetPostString("address");
  4625. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4626. string sellermemo = GetPostString("seller_memo");
  4627. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4628. string supplier = GetPostString("supplier");
  4629. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4630. string OrderArea = GetPostString("order_area");
  4631. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4632. string date1 = GetPostString("date1");
  4633. string date2 = GetPostString("date2");
  4634. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4635. if (dw.Length > 0) lw.Add(dw);
  4636. string price1 = GetPostString("price1");
  4637. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4638. string price2 = GetPostString("price2");
  4639. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4640. string posTag = CurrentUser.UserPost.Post.Code;
  4641. if (posTag == "Supplier")
  4642. {
  4643. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4644. }
  4645. lw.Add(string.Format("OrderState=6 "));
  4646. lw.Add(string.Format("IsXianHuo=1 "));
  4647. lw.Add(string.Format("IsReturn>0 "));
  4648. lw.Add(string.Format("IsReturn!=3"));
  4649. lw.Add(string.Format("IsRefund<={0}", 1));
  4650. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4651. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4652. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4653. writeGridDataTableJson(dStruct.TotalCount, dt);
  4654. }
  4655. public void set_erp_orderdelivery()
  4656. {
  4657. if (UrlPostParmsCheck("ctid"))
  4658. {
  4659. string eid = GetPostString("ctid");
  4660. CeErpTradeCell entity = null;
  4661. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4662. if (entity != null)
  4663. {
  4664. if (entity.OrderState >= 7)
  4665. {
  4666. returnErrorMsg("此单已发货,无需重复发货");
  4667. return;
  4668. }
  4669. if (entity.OrderState != 6)
  4670. {
  4671. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4672. return;
  4673. }
  4674. string shop = GetPostString("seller_nick");
  4675. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4676. string comName = GetPostString("comName");
  4677. string comCode = GetPostString("comCode");
  4678. string outSid = GetPostString("outSid");
  4679. string deliveryType = GetPostString("deliveryType");
  4680. string deliveryMemo = GetPostString("deliveryMemo");
  4681. outSid = outSid.Trim();
  4682. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4683. if (mainEn == null)
  4684. {
  4685. returnErrorMsg("找不到原始订单记录");
  4686. return;
  4687. }
  4688. bool isInitOrderDeliv = false;
  4689. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4690. {
  4691. isInitOrderDeliv = true;
  4692. }
  4693. string apires = "";
  4694. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4695. 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)
  4696. {
  4697. apires = "发货成功true";
  4698. }
  4699. else
  4700. {
  4701. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4702. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4703. }
  4704. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4705. {
  4706. entity.OrderState = 7;//发货后订单已发货
  4707. entity.OutSid = outSid;
  4708. entity.MemoOpt = 0;
  4709. entity.UpdateTime = DateTime.Now;
  4710. entity.FinishDeliveryTime = DateTime.Now;
  4711. entity.Update();
  4712. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4713. commonHelper.UpdateRelationOrder(entity.ctid);
  4714. //还要插入快递信息到 快递信息表
  4715. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4716. exinfo.tid = eid;
  4717. exinfo.out_sid = outSid;
  4718. exinfo.company_code = comCode;
  4719. exinfo.company_name = comName;
  4720. exinfo.delivery_memo = deliveryMemo;
  4721. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4722. exinfo.deliveryType = deliveryType;
  4723. exinfo.Create();
  4724. returnSuccessMsg("发货操作成功!");
  4725. commonHelper.UpdateRelationOrder(entity.ctid);
  4726. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4727. CeErpSukuraData.createInfo(entity.ctid, 4);
  4728. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  4729. {
  4730. commonHelper.sendCytExpress(exinfo);
  4731. }
  4732. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4733. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4734. }
  4735. else
  4736. {
  4737. string errmsg = commonHelper.KeepChinese(apires);
  4738. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4739. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4740. }
  4741. return;
  4742. }
  4743. returnErrorMsg("找不到订单记录");
  4744. }
  4745. }
  4746. public void set_erp_multidelivery()
  4747. {
  4748. string eids = GetPostString("tids");
  4749. string[] eidList = eids.Split(',');
  4750. if (eidList.Length <= 0)
  4751. {
  4752. returnErrorMsg("发货不能为空");
  4753. return;
  4754. }
  4755. foreach (string ctid in eidList)
  4756. {
  4757. if (ctid.Length <= 0) continue;
  4758. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4759. if (expInfo != null)
  4760. {
  4761. StringBuilder sql = new StringBuilder();
  4762. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4763. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4764. if (dt.Rows.Count > 0)
  4765. {
  4766. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4767. {
  4768. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4769. expInfo.state = "异常";
  4770. expInfo.isMultiDelivery = 1;
  4771. expInfo.Update();
  4772. continue;
  4773. }
  4774. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4775. {
  4776. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4777. expInfo.state = "异常";
  4778. expInfo.Update();
  4779. continue;
  4780. }
  4781. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4782. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4783. bool isInitOrderDeliv = false;
  4784. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4785. {
  4786. isInitOrderDeliv = true;
  4787. expInfo.isMultiDelivery = 1;
  4788. }
  4789. if (ctid.IndexOf("N") != -1)
  4790. {
  4791. StringBuilder sqlbucha = new StringBuilder();
  4792. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4793. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4794. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4795. commonHelper.UpdateRelationOrder(ctid);
  4796. expInfo.delivery_memo = "发货成功";
  4797. expInfo.state = "发货成功";
  4798. expInfo.isMultiDelivery = 1;
  4799. expInfo.Update();
  4800. }
  4801. else
  4802. {
  4803. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4804. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4805. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4806. {
  4807. expInfo.delivery_memo = "发货成功";
  4808. expInfo.state = "发货成功";
  4809. expInfo.isMultiDelivery = 1;
  4810. expInfo.Update();
  4811. commonHelper.UpdateRelationOrder(ctid);
  4812. CeErpSukuraData.createInfo(ctid, 4);
  4813. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4814. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4815. }
  4816. else
  4817. {
  4818. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4819. expInfo.state = "异常";
  4820. expInfo.Update();
  4821. }
  4822. }
  4823. }
  4824. }
  4825. }
  4826. returnSuccessMsg("操作完成");
  4827. }
  4828. public void reset_erp_memoopt()
  4829. {
  4830. if (UrlPostParmsCheck("ctid"))
  4831. {
  4832. string eid = GetPostString("ctid");
  4833. CeErpTradeCell entity = null;
  4834. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4835. if (entity != null)
  4836. {
  4837. string stropt = "";
  4838. if (entity.MemoOpt == 1)
  4839. {
  4840. stropt = "“改稿”";
  4841. }
  4842. else if (entity.MemoOpt == 2)
  4843. {
  4844. stropt = "“定稿”";
  4845. }
  4846. else if (entity.MemoOpt == 3)
  4847. {
  4848. stropt = "“完成查货”";
  4849. CeErpSukuraData.createInfo(entity.ctid, 6);
  4850. }
  4851. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4852. entity.UpdateTime = DateTime.Now;
  4853. entity.MemoOpt = 0;
  4854. entity.Update();
  4855. returnSuccessMsg("操作成功!");
  4856. return;
  4857. }
  4858. returnErrorMsg("找不到记录");
  4859. }
  4860. }
  4861. public void get_erp_deliveryunusual()
  4862. {
  4863. DataStruct dStruct = GetPostStruct();
  4864. List<string> lw = new List<string>();
  4865. string tid = GetPostString("ctid");
  4866. if (tid.Length > 0)
  4867. {
  4868. string select_tid = getTidByCtid(tid);
  4869. lw.Add(string.Format("tid='{0}'", select_tid));
  4870. }
  4871. string shopname = GetPostString("shopname");
  4872. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4873. string buyernick = GetPostString("buyer_nick");
  4874. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4875. string customer = GetPostString("customer");
  4876. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4877. string design = GetPostString("design");
  4878. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4879. string sellermemo = GetPostString("seller_memo");
  4880. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4881. string supplier = GetPostString("supplier");
  4882. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4883. string date1 = GetPostString("date1");
  4884. string date2 = GetPostString("date2");
  4885. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4886. if (dw.Length > 0) lw.Add(dw);
  4887. string placedate1 = GetPostString("placedate1");
  4888. string placedate2 = GetPostString("placedate2");
  4889. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4890. if (dw_place.Length > 0) lw.Add(dw_place);
  4891. string price1 = GetPostString("price1");
  4892. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4893. string price2 = GetPostString("price2");
  4894. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4895. string unusualCon = GetPostString("unusualcon");
  4896. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4897. string posTag = CurrentUser.UserPost.Post.Code;
  4898. if (posTag == "Supplier")
  4899. {
  4900. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4901. }
  4902. lw.Add(string.Format("OrderState = 6"));
  4903. lw.Add(string.Format("UnusualTag = 5"));
  4904. lw.Add(string.Format("IsRefund<={0}", 1));
  4905. dStruct.Order = "FinishPlaceTime desc";
  4906. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4907. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4908. writeGridDataTableJson(dStruct.TotalCount, dt);
  4909. }
  4910. public void get_erp_deliveryedlist()
  4911. {
  4912. DataStruct dStruct = GetPostStruct();
  4913. List<string> lw = new List<string>();
  4914. string tid = GetPostString("ctid");
  4915. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4916. string shopname = GetPostString("shopname");
  4917. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4918. string buyernick = GetPostString("buyer_nick");
  4919. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4920. string customer = GetPostString("customer");
  4921. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4922. string design = GetPostString("design");
  4923. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4924. string sellermemo = GetPostString("seller_memo");
  4925. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4926. string logistics = GetPostString("logistics");
  4927. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4928. string date1 = GetPostString("date1");
  4929. string date2 = GetPostString("date2");
  4930. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4931. //if (dw.Length > 0) lw.Add(dw);
  4932. string placedate1 = GetPostString("placedate1");
  4933. string placedate2 = GetPostString("placedate2");
  4934. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4935. if (fdw.Length > 0) lw.Add(fdw);
  4936. string devdate1 = GetPostString("deliverydate1");
  4937. string devdate2 = GetPostString("deliverydate2");
  4938. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4939. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4940. string price1 = GetPostString("price1");
  4941. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4942. string price2 = GetPostString("price2");
  4943. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4944. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4945. {
  4946. if (tid.Length > 0)
  4947. {
  4948. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4949. if (tid.Length > 5)
  4950. {
  4951. List<string> tids = getTidByCtidLike(tid);
  4952. if (tids.Count > 0 && tids.Count < 10)
  4953. {
  4954. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4955. }
  4956. }
  4957. lw.Add(tid_sql);
  4958. }
  4959. if (buyernick.Length > 0)
  4960. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4961. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4962. if (dw.Length > 0) lw.Add(dw);
  4963. }
  4964. else
  4965. {
  4966. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  4967. }
  4968. string posTag = CurrentUser.UserPost.Post.Code;
  4969. if (posTag == "Supplier")
  4970. {
  4971. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4972. }
  4973. else
  4974. {
  4975. string supplier = GetPostString("supplier");
  4976. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4977. }
  4978. lw.Add(string.Format(" OrderState IN (7, 8)"));
  4979. lw.Add(string.Format("type != 'PDD' "));
  4980. lw.Add(string.Format("IsRefund!={0}", 2));
  4981. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4982. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4983. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4984. /*if (tid.Length > 0)
  4985. {
  4986. List<string> tids = new List<string>();
  4987. if (dt != null && dt.Rows.Count > 0)
  4988. {
  4989. foreach (DataRow item in dt.Rows)
  4990. {
  4991. tids.Add("'" + item["tid"] + "'");
  4992. }
  4993. }
  4994. if (tids.Count > 0)
  4995. {
  4996. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4997. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4998. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4999. dt = WebCache.GetData("view_erptradecell", dStruct);
  5000. }
  5001. }*/
  5002. if (dt != null)
  5003. {
  5004. foreach (DataRow dr in dt.Rows)
  5005. {
  5006. 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();
  5007. }
  5008. }
  5009. writeGridDataTableJson(dStruct.TotalCount, dt);
  5010. }
  5011. public void get_erp_pdddeliveryed()
  5012. {
  5013. DataStruct dStruct = GetPostStruct();
  5014. List<string> lw = new List<string>();
  5015. string tid = GetPostString("ctid");
  5016. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5017. string shopname = GetPostString("shopname");
  5018. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5019. string buyernick = GetPostString("buyer_nick");
  5020. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5021. string customer = GetPostString("customer");
  5022. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5023. string design = GetPostString("design");
  5024. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5025. string sellermemo = GetPostString("seller_memo");
  5026. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5027. string logistics = GetPostString("logistics");
  5028. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5029. string date1 = GetPostString("date1");
  5030. string date2 = GetPostString("date2");
  5031. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5032. //if (dw.Length > 0) lw.Add(dw);
  5033. string placedate1 = GetPostString("placedate1");
  5034. string placedate2 = GetPostString("placedate2");
  5035. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5036. if (fdw.Length > 0) lw.Add(fdw);
  5037. string devdate1 = GetPostString("deliverydate1");
  5038. string devdate2 = GetPostString("deliverydate2");
  5039. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5040. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5041. string price1 = GetPostString("price1");
  5042. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5043. string price2 = GetPostString("price2");
  5044. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5045. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5046. {
  5047. if (tid.Length > 0)
  5048. {
  5049. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5050. if (tid.Length > 5)
  5051. {
  5052. List<string> tids = getTidByCtidLike(tid);
  5053. if (tids.Count > 0 && tids.Count < 10)
  5054. {
  5055. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5056. }
  5057. }
  5058. lw.Add(tid_sql);
  5059. }
  5060. if (buyernick.Length > 0)
  5061. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5062. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5063. if (dw.Length > 0) lw.Add(dw);
  5064. }
  5065. else
  5066. {
  5067. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5068. }
  5069. string posTag = CurrentUser.UserPost.Post.Code;
  5070. if (posTag == "Supplier")
  5071. {
  5072. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5073. }
  5074. else
  5075. {
  5076. string supplier = GetPostString("supplier");
  5077. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5078. }
  5079. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5080. lw.Add(string.Format("type = 'PDD' "));
  5081. lw.Add(string.Format("IsRefund!={0}", 2));
  5082. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5083. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5084. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5085. /* if (tid.Length > 0)
  5086. {
  5087. List<string> tids = new List<string>();
  5088. if (dt != null && dt.Rows.Count > 0)
  5089. {
  5090. foreach (DataRow item in dt.Rows)
  5091. {
  5092. tids.Add("'" + item["tid"] + "'");
  5093. }
  5094. }
  5095. if (tids.Count > 0)
  5096. {
  5097. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5098. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5099. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5100. dt = WebCache.GetData("view_erptradecell", dStruct);
  5101. }
  5102. }*/
  5103. foreach (DataRow dr in dt.Rows)
  5104. {
  5105. 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();
  5106. }
  5107. writeGridDataTableJson(dStruct.TotalCount, dt);
  5108. }
  5109. public void get_erp_jddeliveryed()
  5110. {
  5111. DataStruct dStruct = GetPostStruct();
  5112. List<string> lw = new List<string>();
  5113. string tid = GetPostString("ctid");
  5114. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5115. string shopname = GetPostString("shopname");
  5116. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5117. string buyernick = GetPostString("buyer_nick");
  5118. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5119. string customer = GetPostString("customer");
  5120. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5121. string design = GetPostString("design");
  5122. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5123. string sellermemo = GetPostString("seller_memo");
  5124. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5125. string date1 = GetPostString("date1");
  5126. string date2 = GetPostString("date2");
  5127. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5128. //if (dw.Length > 0) lw.Add(dw);
  5129. string placedate1 = GetPostString("placedate1");
  5130. string placedate2 = GetPostString("placedate2");
  5131. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5132. if (fdw.Length > 0) lw.Add(fdw);
  5133. string devdate1 = GetPostString("deliverydate1");
  5134. string devdate2 = GetPostString("deliverydate2");
  5135. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5136. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5137. string price1 = GetPostString("price1");
  5138. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5139. string price2 = GetPostString("price2");
  5140. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5141. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5142. {
  5143. if (tid.Length > 0)
  5144. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5145. if (buyernick.Length > 0)
  5146. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5147. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5148. if (dw.Length > 0) lw.Add(dw);
  5149. }
  5150. else
  5151. {
  5152. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5153. }
  5154. string posTag = CurrentUser.UserPost.Post.Code;
  5155. if (posTag == "Supplier")
  5156. {
  5157. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5158. }
  5159. else
  5160. {
  5161. string supplier = GetPostString("supplier");
  5162. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5163. }
  5164. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5165. lw.Add(string.Format("type = 'JD' "));
  5166. lw.Add(string.Format("IsRefund!={0}", 2));
  5167. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5168. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5169. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5170. foreach (DataRow dr in dt.Rows)
  5171. {
  5172. 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();
  5173. }
  5174. writeGridDataTableJson(dStruct.TotalCount, dt);
  5175. }
  5176. public void get_erp_allplacelist()
  5177. {
  5178. DataStruct dStruct = GetPostStruct();
  5179. List<string> lw = new List<string>();
  5180. string tid = GetPostString("ctid");
  5181. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5182. string shopname = GetPostString("shopname");
  5183. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5184. string buyernick = GetPostString("buyer_nick");
  5185. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5186. string customer = GetPostString("customer");
  5187. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5188. string design = GetPostString("design");
  5189. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5190. string sellermemo = GetPostString("seller_memo");
  5191. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5192. string supplier = GetPostString("supplier");
  5193. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5194. string date1 = GetPostString("date1");
  5195. string date2 = GetPostString("date2");
  5196. string pldate1 = GetPostString("placedate1");
  5197. string pldate2 = GetPostString("placedate2");
  5198. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5199. //if (dw.Length > 0) lw.Add(dw);
  5200. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5201. {
  5202. if (tid.Length > 0)
  5203. {
  5204. string select_tid = getTidByCtid(tid);
  5205. lw.Add(string.Format("tid='{0}'", select_tid));
  5206. }
  5207. if (buyernick.Length > 0)
  5208. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5209. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5210. if (dw.Length > 0) lw.Add(dw);
  5211. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5212. if (dw_place.Length > 0) lw.Add(dw_place);
  5213. }
  5214. else
  5215. {
  5216. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5217. {
  5218. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5219. }
  5220. }
  5221. string price1 = GetPostString("price1");
  5222. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5223. string price2 = GetPostString("price2");
  5224. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5225. string posTag = CurrentUser.UserPost.Post.Code;
  5226. if (posTag == "Supplier")
  5227. {
  5228. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5229. }
  5230. lw.Add(string.Format("OrderState >= 6"));
  5231. lw.Add(string.Format("IsSample != 2 "));
  5232. //lw.Add(string.Format("isDianziOrder = 0 "));
  5233. lw.Add(string.Format("SupplierId > 0 "));
  5234. //lw.Add(string.Format("IsRefund<={0}", 1));
  5235. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5236. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5237. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5238. foreach (DataRow dr in dt.Rows)
  5239. {
  5240. 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();
  5241. }
  5242. writeGridDataTableJson(dStruct.TotalCount, dt);
  5243. }
  5244. public void get_erp_financeallplacelist()
  5245. {
  5246. DataStruct dStruct = GetPostStruct();
  5247. List<string> lw = new List<string>();
  5248. string tid = GetPostString("ctid");
  5249. string shopname = GetPostString("shopname");
  5250. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5251. string buyernick = GetPostString("buyer_nick");
  5252. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5253. string customer = GetPostString("customer");
  5254. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5255. string design = GetPostString("design");
  5256. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5257. string sellermemo = GetPostString("seller_memo");
  5258. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5259. string supplier = GetPostString("supplier");
  5260. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5261. string date1 = GetPostString("date1");
  5262. string date2 = GetPostString("date2");
  5263. string pldate1 = GetPostString("placedate1");
  5264. string pldate2 = GetPostString("placedate2");
  5265. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5266. {
  5267. if (tid.Length > 0)
  5268. {
  5269. string select_tid = getTidByCtid(tid);
  5270. lw.Add(string.Format("tid='{0}'", select_tid));
  5271. }
  5272. if (buyernick.Length > 0)
  5273. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5274. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5275. if (dw.Length > 0) lw.Add(dw);
  5276. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5277. if (dw_place.Length > 0) lw.Add(dw_place);
  5278. }
  5279. else
  5280. {
  5281. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5282. {
  5283. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5284. }
  5285. }
  5286. string price1 = GetPostString("price1");
  5287. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5288. string price2 = GetPostString("price2");
  5289. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5290. string posTag = CurrentUser.UserPost.Post.Code;
  5291. if (posTag == "Supplier")
  5292. {
  5293. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5294. }
  5295. //lw.Add(string.Format("OrderState >= 6"));
  5296. lw.Add(string.Format("IsSample != 2 "));
  5297. lw.Add(string.Format("isDianziOrder = 0 "));
  5298. //lw.Add(string.Format("IsRefund<={0}", 1));
  5299. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5300. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5301. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5302. foreach (DataRow dr in dt.Rows)
  5303. {
  5304. 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();
  5305. }
  5306. writeGridDataTableJson(dStruct.TotalCount, dt);
  5307. }
  5308. public void get_erp_expresslist()
  5309. {
  5310. int listtype = GetInt("ltype");
  5311. DataStruct dStruct = GetPostStruct();
  5312. List<string> lw = new List<string>();
  5313. string tid = GetPostString("tid");
  5314. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5315. string outsid = GetPostString("out_sid");
  5316. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5317. string importer = GetPostString("ImportUserName");
  5318. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5319. string file = GetPostString("import_file");
  5320. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5321. string printman = GetPostString("printman");
  5322. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5323. string date1 = GetPostString("date1");
  5324. string date2 = GetPostString("date2");
  5325. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5326. if (dw.Length > 0) lw.Add(dw);
  5327. string fdate1 = GetPostString("finishdate1");
  5328. string fdate2 = GetPostString("finishdate2");
  5329. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5330. if (fdw.Length > 0) lw.Add(fdw);
  5331. string supplierId = GetPostString("supplierId");
  5332. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5333. if (listtype == 1)
  5334. {
  5335. lw.Add(string.Format("importUserId !=0"));
  5336. }
  5337. string posTag = CurrentUser.UserPost.Post.Code;
  5338. if (posTag == "Supplier")
  5339. {
  5340. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5341. }
  5342. if (dStruct.PageSize != 100000)
  5343. {
  5344. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5345. }
  5346. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5347. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5348. writeGridDataTableJson(dStruct.TotalCount, dt);
  5349. }
  5350. public void set_erp_buchaorderdelivery()
  5351. {
  5352. if (UrlPostParmsCheck("ctid"))
  5353. {
  5354. string eid = GetPostString("ctid");
  5355. CeErpTradeCell entity = null;
  5356. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5357. if (entity != null)
  5358. {
  5359. if (entity.IsSample != 2)
  5360. {
  5361. returnErrorMsg("补差价单才能标记为已发货");
  5362. return;
  5363. }
  5364. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5365. entity.OrderState = 7;
  5366. entity.Update();
  5367. returnSuccessMsg("操作成功!");
  5368. return;
  5369. }
  5370. returnErrorMsg("找不到记录");
  5371. }
  5372. }
  5373. public void get_stdtemplates()
  5374. {
  5375. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5376. //string res = taobaoHelper.test();
  5377. string res = apiHelper.API_PrintTemplate();
  5378. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5379. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5380. {
  5381. int sidx = res.IndexOf("error_code");
  5382. int eidx = res.IndexOf("success");
  5383. string msg = res.Substring(sidx, eidx - sidx);
  5384. returnErrorMsg(msg);
  5385. return;
  5386. }
  5387. if (res.Length <= 0)
  5388. {
  5389. returnErrorMsg("模板数据为空!");
  5390. return;
  5391. }
  5392. ReturnSuccess(res);
  5393. }
  5394. public void cancel_print_order()
  5395. {
  5396. if (UrlPostParmsCheck("ctid"))
  5397. {
  5398. string ctid = GetPostString("ctid");
  5399. CeErpTradeCell entity = null;
  5400. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5401. if (entity != null)
  5402. {
  5403. string res = "";
  5404. string code = entity.LastBillWaybillCode;
  5405. if (code == "")
  5406. {
  5407. code = entity.OutSid;
  5408. }
  5409. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5410. XLog.SaveLog(0, "取消面单" + res);
  5411. }
  5412. }
  5413. }
  5414. public void set_erp_printwaybill()
  5415. {
  5416. if (UrlPostParmsCheck("ctid"))
  5417. {
  5418. string ctid = GetPostString("ctid");
  5419. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5420. string cpName = GetPostString("cpname");
  5421. string isTogether = GetPostString("together");
  5422. string printType = GetPostString("printType");
  5423. //var res_obj = new
  5424. //{
  5425. // restype = 1,
  5426. // 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\"}"
  5427. //};
  5428. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5429. //ReturnSuccess(ro_json);
  5430. //return;
  5431. bool isUseLastWayBillCode = false;
  5432. CeErpTradeCell entity = null;
  5433. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5434. if (entity != null)
  5435. {
  5436. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5437. {
  5438. isUseLastWayBillCode = true;
  5439. }
  5440. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5441. {
  5442. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5443. return;
  5444. }
  5445. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5446. {
  5447. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5448. return;
  5449. }
  5450. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5451. {
  5452. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5453. return;
  5454. }
  5455. }
  5456. string res = "";
  5457. Api_waybill_code_response_Obj fullObj = null;
  5458. string pData_str = "";
  5459. string curUseWayBillCode = "";
  5460. if (isUseLastWayBillCode == false)
  5461. {
  5462. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5463. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5464. if (res.IndexOf("failure") != -1)
  5465. {
  5466. //int idx = res.IndexOf("sub_message");
  5467. //int idx2 = res.IndexOf("flag");
  5468. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5469. string errMsgNeed = commonHelper.KeepChinese(res);
  5470. var res_objd = new
  5471. {
  5472. restype = 0,
  5473. data = "获取面单失败" + errMsgNeed
  5474. };
  5475. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5476. returnSuccess(ro_jsond);
  5477. if (res.IndexOf("停发") != -1)
  5478. {
  5479. entity.UnusualCon = "物流停发";
  5480. entity.Update();
  5481. }
  5482. //returnErrorMsg("获取面单失败,"+emsg);
  5483. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5484. return;
  5485. }
  5486. else if (res.IndexOf("errorMsg") != -1)
  5487. {
  5488. //int idx = res.IndexOf("errorMsg");
  5489. //int idx2 = res.IndexOf("}]}");
  5490. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5491. string errMsgNeed = commonHelper.KeepChinese(res);
  5492. var res_objf = new
  5493. {
  5494. restype = 0,
  5495. data = "获取面单失败2" + errMsgNeed
  5496. };
  5497. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5498. if (res.IndexOf("停发") != -1)
  5499. {
  5500. entity.UnusualCon = "物流停发";
  5501. entity.Update();
  5502. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5503. if (trade != null)
  5504. {
  5505. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5506. }
  5507. }
  5508. returnSuccess(ro_jsonf);
  5509. //returnErrorMsg("获取面单失败," + emsg);
  5510. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5511. return;
  5512. }
  5513. try
  5514. {
  5515. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5516. //res = res.Replace(" ", "");
  5517. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5518. }
  5519. catch (Exception ex)
  5520. {
  5521. XLog.SaveLog(0, "生成fullObj" + res);
  5522. var res_objf = new
  5523. {
  5524. restype = 0,
  5525. data = "生成fullObj发生错误" + ex.Message
  5526. };
  5527. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5528. returnSuccess(ro_jsonf);
  5529. return;
  5530. }
  5531. if (fullObj.response.data.content.Count > 0)
  5532. {
  5533. ContentItem codeObj = fullObj.response.data.content[0];
  5534. if (cpCode.IndexOf("SFFQ-") != -1)
  5535. {
  5536. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5537. }
  5538. else
  5539. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5540. curUseWayBillCode = codeObj.waybillCode;
  5541. }
  5542. else
  5543. {
  5544. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5545. var res_objf = new
  5546. {
  5547. restype = 0,
  5548. data = "生成fullObj找不到快递单号waybillCode"
  5549. };
  5550. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5551. returnSuccess(ro_jsonf);
  5552. return;
  5553. }
  5554. }
  5555. else
  5556. {
  5557. //使用上次打印的快递单号
  5558. if (cpCode == "SFFQ-LY")
  5559. {
  5560. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5561. }
  5562. else
  5563. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5564. curUseWayBillCode = entity.LastBillWaybillCode;
  5565. }
  5566. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5567. {
  5568. var res_obje = new
  5569. {
  5570. restype = 0,
  5571. data = "获取加密打印数据失败"
  5572. };
  5573. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5574. returnSuccess(ro_jsone);
  5575. entity.LastBillCpCode = cpCode;
  5576. entity.LastBillWaybillCode = curUseWayBillCode;
  5577. entity.Update();
  5578. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5579. //returnErrorMsg("获取加密打印数据失败");
  5580. return;
  5581. }
  5582. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5583. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5584. string btnType = "";
  5585. string errorMsg = "";
  5586. if (entity != null)
  5587. {
  5588. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5589. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5590. //cpcode是 YTO-CAINIAO
  5591. //string comCode = cpCode.Split('-')[0].ToString();
  5592. string apires = "";
  5593. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5594. //isTogether=2是新的合包弹窗
  5595. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5596. {
  5597. if (ctid.IndexOf("N") != -1)
  5598. {
  5599. apires = "发货成功";
  5600. }
  5601. else
  5602. {
  5603. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5604. }
  5605. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5606. //打单后发货
  5607. StringBuilder sql = new StringBuilder();
  5608. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5609. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5610. {
  5611. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5612. }
  5613. else
  5614. {
  5615. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5616. }
  5617. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5618. foreach (DataRow row in dt.Rows)
  5619. {
  5620. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5621. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5622. {
  5623. try
  5624. {
  5625. btnType = "待发货";
  5626. entity.OutSid = curUseWayBillCode;
  5627. entity.OrderState = 7;
  5628. entity.IsUrgency = false;
  5629. entity.LastBillCpCode = "";
  5630. entity.LastBillWaybillCode = "";
  5631. entity.FinishDeliveryTime = DateTime.Now;
  5632. entity.IsReturn = 0;
  5633. entity.MemoOpt = 0;
  5634. entity.UpdateTime = DateTime.Now;
  5635. entity.Update();
  5636. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5637. //还要插入快递信息到 快递信息表
  5638. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5639. exinfo.tid = entity.ctid;
  5640. exinfo.out_sid = curUseWayBillCode;
  5641. exinfo.company_code = cpCode;
  5642. exinfo.company_name = cpName;
  5643. exinfo.supplierUserName = supplierName;
  5644. exinfo.deliveryType = "发货成功";
  5645. exinfo.print_time = DateTime.Now;
  5646. exinfo.printUser = CurrentUser.UserName;
  5647. exinfo.postData = pData_str;
  5648. exinfo.Create();
  5649. commonHelper.UpdateRelationOrder(entity.ctid);
  5650. CeErpSukuraData.createInfo(ctid, 4);
  5651. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5652. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5653. {
  5654. commonHelper.sendCytExpress(exinfo);
  5655. }
  5656. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5657. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5658. }
  5659. catch (Exception ex)
  5660. {
  5661. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5662. }
  5663. }
  5664. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5665. {
  5666. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5667. if (entity.OrderState == 6)
  5668. {
  5669. entity.OrderState = 7;
  5670. }
  5671. entity.UpdateTime = DateTime.Now;
  5672. entity.FinishDeliveryTime = DateTime.Now;
  5673. btnType = "已发货";
  5674. entity.Update();
  5675. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5676. exinfo.tid = entity.ctid;
  5677. exinfo.out_sid = curUseWayBillCode;
  5678. exinfo.company_code = cpCode;
  5679. exinfo.company_name = cpName;
  5680. exinfo.supplierUserName = supplierName;
  5681. exinfo.deliveryType = "发货成功";
  5682. exinfo.print_time = DateTime.Now;
  5683. exinfo.printUser = CurrentUser.UserName;
  5684. exinfo.postData = pData_str;
  5685. exinfo.Create();
  5686. commonHelper.UpdateRelationOrder(entity.ctid);
  5687. CeErpSukuraData.createInfo(entity.ctid, 4);
  5688. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5689. {
  5690. commonHelper.sendCytExpress(exinfo);
  5691. }
  5692. //不处理
  5693. }
  5694. else
  5695. {
  5696. entity.UpdateTime = DateTime.Now;
  5697. entity.LastBillCpCode = cpCode;
  5698. entity.LastBillWaybillCode = curUseWayBillCode;
  5699. entity.Update();
  5700. string errmsg = commonHelper.KeepChinese(apires);
  5701. var res_objz = new
  5702. {
  5703. restype = 0,
  5704. data = "打单后发货失败"
  5705. };
  5706. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5707. returnSuccess(ro_jsonz);
  5708. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5709. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5710. return;
  5711. }
  5712. }
  5713. }
  5714. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5715. {
  5716. string ctids = GetPostString("ctids");
  5717. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5718. List<string> list = new List<string>();
  5719. List<string> send_list = new List<string>();
  5720. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5721. CeErpTrade ceErpTrade = new CeErpTrade();
  5722. //可合包的合并一起发货
  5723. if (dt == null && string.IsNullOrEmpty(ctids))
  5724. {
  5725. var res_objz = new
  5726. {
  5727. restype = 0,
  5728. data = "打单后发货失败"
  5729. };
  5730. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5731. returnSuccess(ro_jsonz);
  5732. return;
  5733. }
  5734. if (!string.IsNullOrEmpty(ctids))
  5735. {
  5736. StringBuilder sql = new StringBuilder();
  5737. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5738. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5739. }
  5740. foreach (DataRow row in dt.Rows)
  5741. {
  5742. list.Add("'" + row["ctid"] + "'");
  5743. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5744. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5745. if (ctid.IndexOf("N") != -1)
  5746. {
  5747. apires = "发货成功";
  5748. }
  5749. else
  5750. {
  5751. if (!send_list.Contains(ceErpTrade.tid))
  5752. {
  5753. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5754. }
  5755. else
  5756. {
  5757. apires = "发货成功";
  5758. }
  5759. }
  5760. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5761. {
  5762. send_list.Add(ceErpTrade.tid);
  5763. try
  5764. {
  5765. btnType = "待发货";
  5766. ceErpTradeCell.OutSid = curUseWayBillCode;
  5767. ceErpTradeCell.OrderState = 7;
  5768. ceErpTradeCell.IsUrgency = false;
  5769. ceErpTradeCell.LastBillCpCode = "";
  5770. ceErpTradeCell.LastBillWaybillCode = "";
  5771. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5772. ceErpTradeCell.IsReturn = 0;
  5773. ceErpTradeCell.MemoOpt = 0;
  5774. ceErpTradeCell.UpdateTime = DateTime.Now;
  5775. ceErpTradeCell.Update();
  5776. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5777. //还要插入快递信息到 快递信息表
  5778. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5779. exinfo.tid = ceErpTradeCell.ctid;
  5780. exinfo.out_sid = curUseWayBillCode;
  5781. exinfo.company_code = cpCode;
  5782. exinfo.company_name = cpName;
  5783. exinfo.supplierUserName = supplierName;
  5784. exinfo.deliveryType = "发货成功";
  5785. exinfo.print_time = DateTime.Now;
  5786. exinfo.printUser = CurrentUser.UserName;
  5787. exinfo.postData = pData_str;
  5788. exinfo.Create();
  5789. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5790. CeErpSukuraData.createInfo(ctid, 4);
  5791. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5792. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80)
  5793. {
  5794. commonHelper.sendCytExpress(exinfo);
  5795. }
  5796. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5797. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5798. }
  5799. catch (Exception ex)
  5800. {
  5801. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5802. }
  5803. }
  5804. else
  5805. {
  5806. ceErpTradeCell.UpdateTime = DateTime.Now;
  5807. ceErpTradeCell.LastBillCpCode = cpCode;
  5808. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5809. ceErpTradeCell.Update();
  5810. string errmsg = commonHelper.KeepChinese(apires);
  5811. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5812. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5813. }
  5814. }
  5815. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5816. }
  5817. }
  5818. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5819. var res_obj = new
  5820. {
  5821. restype = 1,
  5822. data = pData_str,
  5823. errorMsg
  5824. };
  5825. string ro_json = JsonConvert.SerializeObject(res_obj);
  5826. ReturnSuccess(ro_json);
  5827. return;
  5828. }
  5829. }
  5830. private string GetUTF8String(byte[] vs)
  5831. {
  5832. throw new NotImplementedException();
  5833. }
  5834. public void set_erp_printwaybill_cn()
  5835. {
  5836. if (UrlPostParmsCheck("ctid"))
  5837. {
  5838. string ctid = GetPostString("ctid");
  5839. string cpCode = GetPostString("cpcode");
  5840. string cpName = GetPostString("cpname");
  5841. string tempUrl = GetPostString("tempurl");
  5842. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5843. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5844. //string res = taobaoHelper.test();
  5845. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5846. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5847. {
  5848. int sidx = res.IndexOf("errorMsg");
  5849. int eidx = res.IndexOf("}");
  5850. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5851. var res_objzxx = new
  5852. {
  5853. restype = 0,
  5854. data = msg
  5855. };
  5856. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5857. returnSuccess(ro_jsonzxx);
  5858. //returnErrorMsg(msg);
  5859. return;
  5860. }
  5861. int idx = res.IndexOf("waybillCode");
  5862. int idx2 = res.IndexOf("printData");
  5863. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5864. string eid = GetPostString("ctid");
  5865. CeErpTradeCell entity = null;
  5866. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5867. if (entity != null)
  5868. {
  5869. string osid = entity.OutSid;
  5870. entity.OutSid = osid + "," + outsid;
  5871. entity.FinishDeliveryTime = DateTime.Now;
  5872. entity.OrderState = 7;
  5873. entity.UpdateTime = DateTime.Now;
  5874. entity.IsReturn = 0;
  5875. entity.Update();
  5876. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5877. exinfo.tid = entity.ctid;
  5878. exinfo.out_sid = outsid;
  5879. exinfo.company_code = cpCode;
  5880. exinfo.company_name = cpName;
  5881. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5882. exinfo.deliveryType = "发货成功";
  5883. exinfo.print_time = DateTime.Now;
  5884. exinfo.printUser = CurrentUser.UserName;
  5885. exinfo.Create();
  5886. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5887. {
  5888. commonHelper.sendCytExpress(exinfo);
  5889. }
  5890. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5891. }
  5892. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5893. var res_objz = new
  5894. {
  5895. restype = 1,
  5896. data = res
  5897. };
  5898. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5899. returnSuccess(ro_jsonz);
  5900. //ReturnSuccess(res);
  5901. }
  5902. }
  5903. ////打单,打印面单 获取面单号
  5904. //public void set_erp_printwaybill()
  5905. //{
  5906. // if (UrlPostParmsCheck("ctid"))
  5907. // {
  5908. // string ctid = GetPostString("ctid");
  5909. // string cpCode = GetPostString("cpcode");
  5910. // string tempUrl = GetPostString("tempurl");
  5911. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5912. // //string res = taobaoHelper.test();
  5913. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5914. // if (res.IndexOf("error_response") != -1)
  5915. // {
  5916. // int sidx = res.IndexOf("sub_msg");
  5917. // int eidx = res.IndexOf("request_id");
  5918. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5919. // returnErrorMsg(msg);
  5920. // return;
  5921. // }
  5922. // int idx = res.IndexOf("waybill_code");
  5923. // int idx2 = res.IndexOf("}]}");
  5924. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5925. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5926. // ReturnSuccess(res);
  5927. // }
  5928. //}
  5929. public void cancel_erp_aftersale()
  5930. {
  5931. if (UrlPostParmsCheck("ctid"))
  5932. {
  5933. string eid = GetPostString("ctid");
  5934. CeErpTradeCell entity = null;
  5935. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5936. if (entity != null)
  5937. {
  5938. //有过处理的售后,取消也不能删除 售 字,保留
  5939. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5940. {
  5941. entity.AfterSaleState = 4;
  5942. }
  5943. else
  5944. entity.AfterSaleState = 0;
  5945. entity.UpdateTime = DateTime.Now;
  5946. entity.Update();
  5947. returnSuccessMsg("操作成功!");
  5948. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5949. return;
  5950. }
  5951. returnErrorMsg("找不到订单记录");
  5952. }
  5953. }
  5954. public void get_erp_aftersalelist()
  5955. {
  5956. DataStruct dStruct = GetPostStruct();
  5957. List<string> lw = new List<string>();
  5958. int st = GetInt("st");
  5959. string tid = GetPostString("ctid");
  5960. if (st == 3)
  5961. {
  5962. if (tid.Length > 0)
  5963. {
  5964. string select_tid = getTidByCtid(tid);
  5965. lw.Add(string.Format("tid='{0}'", select_tid));
  5966. }
  5967. }
  5968. else
  5969. {
  5970. if (tid.Length > 0)
  5971. {
  5972. string select_tid = getTidByCtid(tid);
  5973. lw.Add(string.Format("tid='{0}'", select_tid));
  5974. }
  5975. }
  5976. string shopname = GetPostString("shopname");
  5977. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5978. string buyernick = GetPostString("buyer_nick");
  5979. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5980. string sellermemo = GetPostString("seller_memo");
  5981. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5982. string orderState = GetPostString("orderState");
  5983. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5984. string afterState = GetPostString("afterstate");
  5985. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5986. string date1 = GetPostString("date1");
  5987. string date2 = GetPostString("date2");
  5988. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5989. if (dw.Length > 0) lw.Add(dw);
  5990. string price1 = GetPostString("price1");
  5991. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5992. string price2 = GetPostString("price2");
  5993. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5994. //lw.Add(string.Format("IsRefund!={0}", 1));
  5995. string reason = GetPostString("reason");
  5996. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5997. string method = GetPostString("method");
  5998. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5999. string handler = GetPostString("handler");
  6000. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6001. string handledate1 = GetPostString("handledate1");
  6002. string handledate2 = GetPostString("handledate2");
  6003. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6004. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6005. string finish1 = GetPostString("finishdate1");
  6006. string finish2 = GetPostString("finishdate2");
  6007. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6008. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6009. string afterdate1 = GetPostString("afterdate1");
  6010. string afterdate2 = GetPostString("afterdate2");
  6011. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6012. if (afterDate.Length > 0) lw.Add(afterDate);
  6013. string supplier = GetPostString("supplier");
  6014. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6015. string responsible = GetPostString("responsibleman");
  6016. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6017. string customer = GetPostString("customer");
  6018. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6019. string design = GetPostString("design");
  6020. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6021. string afterMemoType = GetPostString("aftermemotype");
  6022. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6023. string posCode = CurrentUser.UserPost.Post.Code;
  6024. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6025. //{
  6026. // string vstate = GetPostString("vstate");
  6027. // if (vstate.Length > 0)
  6028. // {
  6029. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6030. // }
  6031. // if (posCode == "Supplier")
  6032. // {
  6033. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6034. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6035. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6036. // }
  6037. // else
  6038. // {
  6039. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6040. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6041. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6042. // {
  6043. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6044. // }
  6045. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6046. // {
  6047. // int orgid = CurrentUser.UserPost.OrgID;
  6048. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6049. // }
  6050. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6051. // {
  6052. // string shopid = CurrentUser.User.pemShop;
  6053. // lw.Add(string.Format("shopId in ({0})", shopid));
  6054. // }
  6055. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6056. // //{
  6057. // // int org_id = CurrentUser.UserPost.OrgID;
  6058. // // lw.Add(string.Format("OrgID={0}", org_id));
  6059. // //}
  6060. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6061. // }
  6062. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6063. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6064. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6065. //}
  6066. if (st == 5)
  6067. {
  6068. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6069. {
  6070. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6071. {
  6072. string shopid = CurrentUser.User.pemShop;
  6073. lw.Add(string.Format("shopId in ({0})", shopid));
  6074. }
  6075. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6076. {
  6077. int mrOrgid = CurrentUser.UserPost.OrgID;
  6078. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6079. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6080. }
  6081. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6082. //{
  6083. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6084. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6085. //}
  6086. else
  6087. {
  6088. string userIdStr = "";
  6089. if (posCode == "CustomerService")
  6090. {
  6091. userIdStr = CurrentUser.UserID + "_k";
  6092. }
  6093. else if (posCode == "Designer" || posCode == "wxDesigner")
  6094. {
  6095. userIdStr = CurrentUser.UserID + "_s";
  6096. }
  6097. else if (posCode == "Place")
  6098. {
  6099. userIdStr = CurrentUser.UserID + "_x";
  6100. }
  6101. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6102. }
  6103. }
  6104. string placedate1 = GetPostString("placedate1");
  6105. string placedate2 = GetPostString("placedate2");
  6106. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6107. if (dwplace.Length > 0) lw.Add(dwplace);
  6108. string supState = GetPostString("supState");
  6109. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6110. string searchType = GetPostString("searchType");
  6111. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6112. {
  6113. lw.Add(string.Format("BackNum>1"));
  6114. }
  6115. lw.Add(string.Format("AfterSaleState>0"));
  6116. if (ex_psize > 0)
  6117. {
  6118. if (CurrentUser.UserPost.Post.Code == "Finance")
  6119. dStruct.Order = "pay_time desc";
  6120. else
  6121. dStruct.Order = "HandleTime desc";
  6122. }
  6123. else
  6124. dStruct.Order = "HandleTime desc";
  6125. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6126. DataTable dt = WebCache.GetData("view_test", dStruct);
  6127. writeGridDataTableJson(dStruct.TotalCount, dt);
  6128. }
  6129. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6130. //{
  6131. // lw.Add(string.Format("AfterSaleState=4"));
  6132. // string code = CurrentUser.UserPost.Post.Code;
  6133. // if (code == "CustomerService")
  6134. // {
  6135. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6136. // }
  6137. // else if (code == "Designer" || code == "DesignerMr")
  6138. // {
  6139. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6140. // }
  6141. // else if (code == "Place" || code == "PlaceMr")
  6142. // {
  6143. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6144. // }
  6145. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6146. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6147. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6148. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6149. //}
  6150. //else //处理中的售后,待处理和处理中合并
  6151. //{
  6152. // if (afterState.Length <= 0)
  6153. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6154. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6155. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6156. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6157. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6158. //}
  6159. }
  6160. public void get_erp_disagreeftersalelist()
  6161. {
  6162. DataStruct dStruct = GetPostStruct();
  6163. List<string> lw = new List<string>();
  6164. int st = 2;
  6165. string tid = GetPostString("ctid");
  6166. if (tid.Length > 0)
  6167. {
  6168. string select_tid = getTidByCtid(tid);
  6169. lw.Add(string.Format("tid='{0}'", select_tid));
  6170. }
  6171. string shopname = GetPostString("shopname");
  6172. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6173. string buyernick = GetPostString("buyer_nick");
  6174. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6175. string sellermemo = GetPostString("seller_memo");
  6176. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6177. string orderState = GetPostString("orderState");
  6178. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6179. string afterState = GetPostString("afterstate");
  6180. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6181. string date1 = GetPostString("date1");
  6182. string date2 = GetPostString("date2");
  6183. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6184. if (dw.Length > 0) lw.Add(dw);
  6185. string price1 = GetPostString("price1");
  6186. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6187. string price2 = GetPostString("price2");
  6188. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6189. //lw.Add(string.Format("IsRefund!={0}", 1));
  6190. string reason = GetPostString("reason");
  6191. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6192. string method = GetPostString("method");
  6193. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6194. string handler = GetPostString("handler");
  6195. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6196. string handledate1 = GetPostString("handledate1");
  6197. string handledate2 = GetPostString("handledate2");
  6198. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6199. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6200. string afterdate1 = GetPostString("afterdate1");
  6201. string afterdate2 = GetPostString("afterdate2");
  6202. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6203. if (afterDate.Length > 0) lw.Add(afterDate);
  6204. string backdate1 = GetPostString("backdate1");
  6205. string backdate2 = GetPostString("backdate2");
  6206. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6207. if (backDate.Length > 0) lw.Add(backDate);
  6208. string supplier = GetPostString("supplier");
  6209. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6210. string responsible = GetPostString("responsibleman");
  6211. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6212. string customer = GetPostString("customer");
  6213. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6214. string design = GetPostString("design");
  6215. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6216. string afterSaleMemo = GetPostString("afterSaleMemo");
  6217. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6218. string afterMemoType = GetPostString("aftermemotype");
  6219. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6220. string aftersakereason = GetPostString("aftersakereason");
  6221. if (aftersakereason.Length > 0)
  6222. {
  6223. if (aftersakereason == "1")
  6224. {
  6225. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6226. }
  6227. if (aftersakereason == "2")
  6228. {
  6229. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6230. }
  6231. }
  6232. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6233. string poscode = CurrentUser.UserPost.Post.Code;
  6234. if (poscode != "SysAdmin")
  6235. {
  6236. string shopid = CurrentUser.User.pemShop;
  6237. lw.Add(string.Format("shopId in ({0})", shopid));
  6238. }
  6239. string searchType = GetPostString("searchType");
  6240. if (searchType == "wait")
  6241. {
  6242. lw.Add(string.Format("HandleTime is null"));
  6243. }
  6244. if (searchType == "handling")
  6245. {
  6246. lw.Add(string.Format("HandleTime is not null "));
  6247. }
  6248. if (searchType == "back" || searchType == "puBack")
  6249. {
  6250. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6251. }
  6252. if (searchType == "reBack")
  6253. {
  6254. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6255. }
  6256. if (searchType == "moreBack")
  6257. {
  6258. lw.Add(string.Format("backNum > 1"));
  6259. }
  6260. lw.Add(string.Format("(AfterSaleState=5)"));
  6261. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6262. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6263. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6264. writeGridDataTableJson(dStruct.TotalCount, dt);
  6265. }
  6266. public void get_erp_handlingaftersalelist()
  6267. {
  6268. DataStruct dStruct = GetPostStruct();
  6269. List<string> lw = new List<string>();
  6270. int st = 2;
  6271. string tid = GetPostString("ctid");
  6272. if (tid.Length > 0)
  6273. {
  6274. string select_tid = getTidByCtid(tid);
  6275. lw.Add(string.Format("tid='{0}'", select_tid));
  6276. }
  6277. string shopname = GetPostString("shopname");
  6278. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6279. string buyernick = GetPostString("buyer_nick");
  6280. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6281. string sellermemo = GetPostString("seller_memo");
  6282. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6283. string orderState = GetPostString("orderState");
  6284. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6285. string afterState = GetPostString("afterstate");
  6286. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6287. string date1 = GetPostString("date1");
  6288. string date2 = GetPostString("date2");
  6289. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6290. if (dw.Length > 0) lw.Add(dw);
  6291. string price1 = GetPostString("price1");
  6292. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6293. string price2 = GetPostString("price2");
  6294. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6295. //lw.Add(string.Format("IsRefund!={0}", 1));
  6296. string reason = GetPostString("reason");
  6297. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6298. string method = GetPostString("method");
  6299. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6300. string handler = GetPostString("handler");
  6301. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6302. string handledate1 = GetPostString("handledate1");
  6303. string handledate2 = GetPostString("handledate2");
  6304. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6305. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6306. string afterdate1 = GetPostString("afterdate1");
  6307. string afterdate2 = GetPostString("afterdate2");
  6308. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6309. if (afterDate.Length > 0) lw.Add(afterDate);
  6310. string supplier = GetPostString("supplier");
  6311. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6312. string responsible = GetPostString("responsibleman");
  6313. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6314. string customer = GetPostString("customer");
  6315. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6316. string design = GetPostString("design");
  6317. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6318. string afterSaleMemo = GetPostString("afterSaleMemo");
  6319. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6320. string afterMemoType = GetPostString("aftermemotype");
  6321. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6322. string afterresult = GetPostString("afterresult");
  6323. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6324. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6325. string poscode = CurrentUser.UserPost.Post.Code;
  6326. if (poscode != "SysAdmin")
  6327. {
  6328. string shopid = CurrentUser.User.pemShop;
  6329. lw.Add(string.Format("shopId in ({0})", shopid));
  6330. }
  6331. string searchType = GetPostString("searchType");
  6332. if (searchType == "wait")
  6333. {
  6334. lw.Add(string.Format("HandleTime is null"));
  6335. }
  6336. if (searchType == "documentary")
  6337. {
  6338. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6339. }
  6340. if (searchType == "handling")
  6341. {
  6342. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6343. }
  6344. if (searchType == "back" || searchType == "puBack")
  6345. {
  6346. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6347. }
  6348. if (searchType == "reBack")
  6349. {
  6350. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6351. }
  6352. if (afterState.Length <= 0)
  6353. {
  6354. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6355. }
  6356. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6357. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6358. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6359. writeGridDataTableJson(dStruct.TotalCount, dt);
  6360. }
  6361. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6362. //public void get_erp_back_handlingaftersalelist()
  6363. //{
  6364. // DataStruct dStruct = GetPostStruct();
  6365. // List<string> lw = new List<string>();
  6366. // string tid = GetPostString("ctid");
  6367. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6368. // string shopname = GetPostString("shopname");
  6369. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6370. // string buyernick = GetPostString("buyer_nick");
  6371. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6372. // string sellermemo = GetPostString("seller_memo");
  6373. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6374. // string orderState = GetPostString("orderState");
  6375. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6376. // string afterState = GetPostString("afterstate");
  6377. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6378. // string date1 = GetPostString("date1");
  6379. // string date2 = GetPostString("date2");
  6380. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6381. // if (dw.Length > 0) lw.Add(dw);
  6382. // string price1 = GetPostString("price1");
  6383. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6384. // string price2 = GetPostString("price2");
  6385. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6386. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6387. // string reason = GetPostString("reason");
  6388. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6389. // string method = GetPostString("method");
  6390. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6391. // string handler = GetPostString("handler");
  6392. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6393. // string handledate1 = GetPostString("handledate1");
  6394. // string handledate2 = GetPostString("handledate2");
  6395. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6396. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6397. // string afterdate1 = GetPostString("afterdate1");
  6398. // string afterdate2 = GetPostString("afterdate2");
  6399. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6400. // if (afterDate.Length > 0) lw.Add(afterDate);
  6401. // string supplier = GetPostString("supplier");
  6402. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6403. // string responsible = GetPostString("responsibleman");
  6404. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6405. // string customer = GetPostString("customer");
  6406. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6407. // string design = GetPostString("design");
  6408. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6409. // string afterMemoType = GetPostString("aftermemotype");
  6410. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6411. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6412. // if (afterState.Length <= 0)
  6413. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6414. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6415. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6416. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6417. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6418. //}
  6419. public void get_erp_aftersaleverifylist()
  6420. {
  6421. DataStruct dStruct = GetPostStruct();
  6422. List<string> lw = new List<string>();
  6423. string tid = GetPostString("ctid");
  6424. if (tid.Length > 0)
  6425. {
  6426. string select_tid = getTidByCtid(tid);
  6427. lw.Add(string.Format("otid='{0}'", select_tid));
  6428. }
  6429. string shopname = GetPostString("shopname");
  6430. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6431. string buyernick = GetPostString("buyer_nick");
  6432. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6433. string sellermemo = GetPostString("seller_memo");
  6434. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6435. string orderState = GetPostString("orderState");
  6436. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6437. //lw.Add(string.Format("IsRefund!={0}", 1));
  6438. string reason = GetPostString("reason");
  6439. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6440. string method = GetPostString("method");
  6441. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6442. string handler = GetPostString("handler");
  6443. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6444. string handledate1 = GetPostString("handledate1");
  6445. string handledate2 = GetPostString("handledate2");
  6446. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6447. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6448. string finish1 = GetPostString("finishdate1");
  6449. string finish2 = GetPostString("finishdate2");
  6450. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6451. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6452. string supplier = GetPostString("supplier");
  6453. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6454. string responsible = GetPostString("responsibleman");
  6455. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6456. string posCode = CurrentUser.UserPost.Post.Code;
  6457. string vstate = GetPostString("vstate");
  6458. if (vstate.Length > 0)
  6459. {
  6460. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6461. }
  6462. if (posCode == "Supplier")
  6463. {
  6464. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6465. lw.Add(string.Format("VerifyState = 0"));
  6466. lw.Add("type = 1");
  6467. lw.Add(string.Format("AfterSaleState={0}", 3));
  6468. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6469. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6470. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6471. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6472. writeGridDataTableJson(dStruct.TotalCount, dt);
  6473. }
  6474. else if (posCode == "logistics")
  6475. {
  6476. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6477. lw.Add(string.Format("VerifyState = 0"));
  6478. lw.Add("type = 2");
  6479. lw.Add(string.Format("AfterSaleState={0}", 3));
  6480. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6481. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6482. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6483. writeGridDataTableJson(dStruct.TotalCount, dt);
  6484. }
  6485. else
  6486. {
  6487. lw.Add(string.Format("(AfterSaleState = 3)"));
  6488. string reasonState = GetPostString("reasonState");
  6489. lw.Add("type = 0");
  6490. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6491. || posCode == "Summarize" || posCode == "Finance")
  6492. {
  6493. if (reasonState == "2")
  6494. {
  6495. lw.Add("VerifyState = 3");
  6496. }
  6497. else if (reasonState == "1")
  6498. {
  6499. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6500. }
  6501. else
  6502. {
  6503. lw.Add("VerifyState in (0,3)");
  6504. }
  6505. //不加条件,可以看全部
  6506. }
  6507. 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")
  6508. {
  6509. int orgid = CurrentUser.UserPost.OrgID;
  6510. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6511. if (string.IsNullOrEmpty(manageOrgId))
  6512. {
  6513. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6514. }
  6515. else
  6516. {
  6517. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6518. }
  6519. if (reasonState == "1")
  6520. {
  6521. lw.Add("VerifyState = 3");
  6522. }
  6523. else if (reasonState == "2")
  6524. {
  6525. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6526. }
  6527. else
  6528. {
  6529. }
  6530. }
  6531. else
  6532. {
  6533. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6534. }
  6535. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6536. //{
  6537. // int org_id = CurrentUser.UserPost.OrgID;
  6538. // lw.Add(string.Format("OrgID={0}", org_id));
  6539. //}
  6540. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6541. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6542. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6543. writeGridDataTableJson(dStruct.TotalCount, dt);
  6544. }
  6545. }
  6546. public void get_erp_finishaftersalelist()
  6547. {
  6548. DataStruct dStruct = GetPostStruct();
  6549. List<string> lw = new List<string>();
  6550. int st = 4;
  6551. string tid = GetPostString("ctid");
  6552. if (tid.Length > 0)
  6553. {
  6554. string select_tid = getTidByCtid(tid);
  6555. lw.Add(string.Format("otid='{0}'", select_tid));
  6556. }
  6557. string shopname = GetPostString("shopname");
  6558. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6559. //lw.Add(string.Format("IsRefund!={0}", 1));
  6560. string reason = GetPostString("reason");
  6561. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6562. string method = GetPostString("method");
  6563. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6564. string buyernick = GetPostString("buyer_nick");
  6565. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6566. string handler = GetPostString("handler");
  6567. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6568. string handledate1 = GetPostString("handledate1");
  6569. string handledate2 = GetPostString("handledate2");
  6570. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6571. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6572. string finish1 = GetPostString("finishdate1");
  6573. string finish2 = GetPostString("finishdate2");
  6574. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6575. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6576. string supplier = GetPostString("supplier");
  6577. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6578. string responsible = GetPostString("responsibleman");
  6579. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6580. string vstate = GetPostString("vstate");
  6581. if (vstate.Length > 0)
  6582. {
  6583. if ("3".Equals(vstate))
  6584. {
  6585. lw.Add(string.Format("IsTem=1"));
  6586. }
  6587. else
  6588. {
  6589. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6590. }
  6591. }
  6592. lw.Add(string.Format("AfterSaleState=4"));
  6593. string code = CurrentUser.UserPost.Post.Code;
  6594. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6595. {
  6596. //不加条件,可以看全部
  6597. }
  6598. else if (code == "Supplier")
  6599. {
  6600. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6601. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6602. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6603. }
  6604. else if (code == "logistics")
  6605. {
  6606. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6607. lw.Add("type = 2");
  6608. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6609. }
  6610. 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")
  6611. {
  6612. int orgid = CurrentUser.UserPost.OrgID;
  6613. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6614. if (string.IsNullOrEmpty(manageOrgIds))
  6615. {
  6616. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6617. }
  6618. else
  6619. {
  6620. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6621. }
  6622. }
  6623. else
  6624. {
  6625. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6626. }
  6627. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6628. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6629. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6630. writeGridDataTableJson(dStruct.TotalCount, dt);
  6631. }
  6632. public void handle_erp_aftersale()
  6633. {
  6634. if (UrlPostParmsCheck("ctid"))
  6635. {
  6636. string eid = GetPostString("ctid");
  6637. string responStr = GetPostString("AfterSaleResponsible");
  6638. if (responStr.Length <= 0)
  6639. {
  6640. returnErrorMsg("售后责任人不能为空");
  6641. return;
  6642. }
  6643. bool isDesign = false;
  6644. double designFree = 0.00;
  6645. int responsibleId = 0;
  6646. CeErpTradeCell entity = null;
  6647. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6648. if (entity != null)
  6649. {
  6650. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6651. string afterMethod = GetPostString("AfterSaleMethod");
  6652. if (isNeedNewOrder == 1)
  6653. {
  6654. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6655. bool ishav = true;
  6656. if (newentity == null)
  6657. {
  6658. newentity = entity.Clone() as CeErpTradeCell;
  6659. ishav = false;
  6660. newentity.ctid = "S_" + entity.ctid;
  6661. newentity.OrderState = 0;
  6662. //唯一标识
  6663. newentity.OrderSn = newentity.ctid;
  6664. string orderSn = dataHelper.getSaleOrderSn();
  6665. if (orderSn != "")
  6666. {
  6667. newentity.OrderSn = orderSn;
  6668. }
  6669. }
  6670. newentity.UpdateTime = DateTime.Now;
  6671. newentity.AfterSaleState = 0;
  6672. newentity.AfterSaleMethod = afterMethod;
  6673. if (!ishav)
  6674. {
  6675. string memo_str = newentity.seller_memo;
  6676. memo_str = memo_str.Replace("(", "(");
  6677. memo_str = memo_str.Replace(")", ")");
  6678. int sIndex = memo_str.IndexOf("(");
  6679. int eIndex = memo_str.IndexOf(")");
  6680. if (sIndex == -1 || eIndex == -1)
  6681. {
  6682. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6683. return;
  6684. }
  6685. string first = memo_str.Substring(0, sIndex + 1);
  6686. string memoCtid = newentity.OrderSn;
  6687. //if (memoCtid.IndexOf("C") != -1)
  6688. //{
  6689. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6690. //if (CIdx.IndexOf("+") != -1)
  6691. //{
  6692. //CIdx = "C" + CIdx.Split('+')[1];
  6693. //}
  6694. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6695. //}
  6696. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6697. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6698. string newMemo = first + memoCtid + last;
  6699. newentity.seller_memo = newMemo;
  6700. newentity.FinishPlaceTime = null;
  6701. newentity.UnusualTag = 0;
  6702. newentity.UnusualCon = "";
  6703. newentity.UnusualTime = null;
  6704. newentity.AfterSaleMemo = "";
  6705. newentity.AfterSaleMethod = afterMethod;
  6706. newentity.AfterSalePreTime = null;
  6707. newentity.AfterSaleReason = "";
  6708. newentity.AfterSaleResponsible = "";
  6709. newentity.AfterSaleState = 0;
  6710. newentity.AfterSaleTime = null;
  6711. newentity.AfterSaleUserId = 0;
  6712. newentity.AfterSaleSupplierState = 0;
  6713. newentity.LastBillWaybillCode = "";
  6714. newentity.LastBillCpCode = "";
  6715. newentity.FinishAfterSaleTime = null;
  6716. newentity.HandleTime = null;
  6717. newentity.IsSF = 0;
  6718. newentity.IsOldCustomer = 0;
  6719. newentity.UrgencyTime = null;
  6720. newentity.ResponsibleUserId = "";
  6721. newentity.IsVerifyToSupplier = false;
  6722. newentity.payment = 0;
  6723. newentity.CheckMemo = "";
  6724. newentity.OutSid = "";
  6725. newentity.CheckOrderTime = null;
  6726. newentity.MemoOpt = 0;
  6727. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6728. }
  6729. newentity.isAfterSaleOrder = 1;
  6730. newentity.IsRefund = 0;
  6731. string receiveMobile = GetPostString("receiver_mobile");
  6732. if (receiveMobile.Length > 0)
  6733. {
  6734. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6735. if (trade != null)
  6736. {
  6737. trade.receiver_name = GetPostString("receiver_name");
  6738. trade.receiver_mobile = receiveMobile;
  6739. trade.receiver_state = GetPostString("receiver_state");
  6740. trade.receiver_city = GetPostString("receiver_city");
  6741. trade.receiver_district = GetPostString("receiver_district");
  6742. trade.receiver_address = GetPostString("receiver_address");
  6743. newentity.IsOffLineOrder = 1;
  6744. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6745. }
  6746. }
  6747. string st = GetPostString("ToState");
  6748. if (st.Length > 0)
  6749. {
  6750. if (newentity.OrderState <= 3)
  6751. {
  6752. newentity.WaitDesignTime = DateTime.Now;
  6753. newentity.StartDesignTime = null;
  6754. newentity.FinishDesignTime = null;
  6755. newentity.OrderState = 3;
  6756. if (st == "下单员")
  6757. {
  6758. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6759. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6760. {
  6761. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6762. }
  6763. }
  6764. else
  6765. {
  6766. newentity.WaitDesignTime = DateTime.Now;
  6767. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6768. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6769. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6770. {
  6771. DataRow user = dt1.Rows[0];
  6772. //找主管
  6773. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6774. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6775. if (dt != null && dt.Rows.Count > 0)
  6776. {
  6777. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6778. newentity.DesignUserId = designMr;
  6779. string key = "aftersale_order_" + designMr;
  6780. if (RedisHelper.HasKey(key))
  6781. {
  6782. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6783. list.Add(newentity.ctid);
  6784. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6785. }
  6786. }
  6787. //账号正常
  6788. if (user["State"].ToString() == "0")
  6789. {
  6790. newentity.DesignUserId = entity.DesignUserId;
  6791. string key = "aftersale_order_" + entity.DesignUserId;
  6792. if (RedisHelper.HasKey(key))
  6793. {
  6794. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6795. list.Add(newentity.ctid);
  6796. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6797. }
  6798. }
  6799. }
  6800. }
  6801. }
  6802. if (entity.IsXianHuo == 1)
  6803. {
  6804. newentity.OrderState = 6;
  6805. entity.FinishPlaceTime = DateTime.Now;
  6806. }
  6807. }
  6808. if (ishav)
  6809. {
  6810. newentity.Update();
  6811. }
  6812. else
  6813. {
  6814. newentity.Create();
  6815. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6816. newCellExtend.ctid = newentity.ctid;
  6817. newCellExtend.orderFrom = 20;
  6818. newCellExtend.orderType = 30;
  6819. if (st == "下单员")
  6820. {
  6821. }
  6822. else
  6823. {
  6824. newCellExtend.ReprintTime = DateTime.Now;
  6825. }
  6826. newCellExtend.Create();
  6827. }
  6828. if (st != "下单员")
  6829. {
  6830. if (entity.DispatchSort == 2)
  6831. {
  6832. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6833. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6834. }
  6835. }
  6836. }
  6837. //处理售后扩展
  6838. string resIdStr = GetPostString("ResponsibleUserId");
  6839. string refundFees = GetPostString("refundFrees");
  6840. int IsComplain = GetPostInt("isComplain");
  6841. int IsBad = GetPostInt("isBad");
  6842. string IsOriginal = GetPostString("isOriginal");
  6843. double diffResultPrice = GetPostDouble("diffResultPrice");
  6844. string textResult = GetPostString("textResult");
  6845. string supplierResponsible = GetPostString("supplierResponsible");
  6846. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6847. if (ceErpTradeAfterSaleExtend == null)
  6848. {
  6849. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6850. ceErpTradeAfterSaleExtend.tid = eid;
  6851. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6852. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6853. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6854. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6855. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6856. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6857. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6858. ceErpTradeAfterSaleExtend.Create();
  6859. }
  6860. else
  6861. {
  6862. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6863. {
  6864. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6865. }
  6866. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6867. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6868. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6869. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6870. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6871. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6872. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6873. ceErpTradeAfterSaleExtend.Update();
  6874. }
  6875. int gysid = GetPostInt("ResponsibleSupId");
  6876. if (entity.AfterSaleUserId == 0)
  6877. {
  6878. entity.AfterSaleUserId = CurrentUser.UserID;
  6879. }
  6880. entity.ResponsibleUserId = resIdStr;
  6881. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6882. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6883. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6884. {
  6885. CeErpTradeResponsible.DelByTid(eid, -1);
  6886. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6887. int backNum = 0;
  6888. if (number != null)
  6889. {
  6890. backNum = number.BackNum;
  6891. }
  6892. char[] separator = { ',' };
  6893. string[] sArray = resIdStr.Split(separator);
  6894. string[] refundFreeList = { };
  6895. if (refundFees.Length > 0)
  6896. {
  6897. refundFreeList = refundFees.Split(separator);
  6898. }
  6899. int index = -1;
  6900. foreach (string i in sArray)
  6901. {
  6902. index++;
  6903. if (i.Length <= 0) continue;
  6904. char[] separator2 = { '_' };
  6905. string idstr = i.Split(separator2)[0];
  6906. string idtype = i.Split(separator2)[1];
  6907. double refudFree = 0;
  6908. if (refundFreeList.Length > 0)
  6909. {
  6910. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6911. }
  6912. if (idtype == "s")
  6913. {
  6914. isDesign = true;
  6915. designFree = refudFree;
  6916. }
  6917. int userId = Convert.ToInt32(idstr);
  6918. int type = 0;
  6919. if (idtype == "g")
  6920. {
  6921. type = 1;
  6922. }
  6923. if (idtype == "w")
  6924. {
  6925. type = 2;
  6926. }
  6927. if (idtype == "t")
  6928. {
  6929. type = 3;
  6930. }
  6931. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6932. if (ceErpTradeResponsible == null)
  6933. {
  6934. ceErpTradeResponsible = new CeErpTradeResponsible();
  6935. ceErpTradeResponsible.tid = eid;
  6936. ceErpTradeResponsible.UserId = userId;
  6937. ceErpTradeResponsible.createdTime = DateTime.Now;
  6938. ceErpTradeResponsible.type = type;
  6939. if (type == 1)
  6940. {
  6941. ceErpTradeResponsible.IsSup = 1;
  6942. }
  6943. if (type == 2)
  6944. {
  6945. ceErpTradeResponsible.IsFlow = 1;
  6946. }
  6947. }
  6948. ceErpTradeResponsible.RefundFee = refudFree;
  6949. ceErpTradeResponsible.VerifyState = 0;
  6950. if (userId == 2125 || idtype == "w")
  6951. {
  6952. ceErpTradeResponsible.VerifyState = 1;
  6953. }
  6954. if (idtype == "w" && userId == 101)
  6955. {
  6956. ceErpTradeResponsible.VerifyState = 0;
  6957. }
  6958. if (ceErpTradeResponsible.ID > 0)
  6959. {
  6960. ceErpTradeResponsible.Update();
  6961. }
  6962. else
  6963. {
  6964. ceErpTradeResponsible.Create();
  6965. }
  6966. if (isDesign)
  6967. {
  6968. responsibleId = ceErpTradeResponsible.ID;
  6969. }
  6970. }
  6971. CeErpTradeResponsible.NumByTid(backNum, eid);
  6972. }
  6973. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6974. if (ceErpTradeCellExtend != null)
  6975. {
  6976. ceErpTradeCellExtend.returnVisit = 0;
  6977. ceErpTradeCellExtend.Update();
  6978. }
  6979. if (entity.HandleTime != null)
  6980. {
  6981. if (entity.AfterSaleState == 1)
  6982. {
  6983. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6984. }
  6985. else
  6986. {
  6987. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6988. }
  6989. }
  6990. else
  6991. {
  6992. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6993. entity.HandleTime = DateTime.Now;
  6994. }
  6995. bool isCompale = false;
  6996. if (entity.AfterSaleState == 5)
  6997. {
  6998. isCompale = true;
  6999. entity.AfterSaleState = 3;
  7000. }
  7001. entity.AfterSaleSupplierState = 0;
  7002. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7003. {
  7004. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7005. }
  7006. string sImgs = GetPostString("img");
  7007. entity.AfterSaleSupplierImg = sImgs;
  7008. entity.supRefundType = GetPostString("supRefundType");
  7009. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7010. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7011. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7012. entity.AfterSaleMemoType = GetPostString("MemoType");
  7013. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7014. {
  7015. //entity.AfterSaleSupplierState = 2;
  7016. }
  7017. string df = GetPostString("DeductFee");
  7018. if (df == "")
  7019. {
  7020. df = "0";
  7021. }
  7022. string rf = GetPostString("RefundFee");
  7023. if (rf == "")
  7024. {
  7025. rf = "0";
  7026. }
  7027. string pm = GetPostString("AfterSalePayment");
  7028. if (pm == "")
  7029. {
  7030. pm = "0";
  7031. }
  7032. entity.AfterSalePayment = Convert.ToDouble(pm);
  7033. entity.DeductFee = Convert.ToDouble(df);
  7034. entity.RefundFee = Convert.ToDouble(rf);
  7035. entity.UpdateTime = DateTime.Now;
  7036. entity.Update();
  7037. string toState = GetPostString("ToState");
  7038. string original = GetPostString("isOriginal");
  7039. ApiVo apiVo = new ApiVo();
  7040. apiVo.orderNumber = entity.ctid;
  7041. apiVo.actionName = "afterDesign";
  7042. apiVo.orderRemarks = entity.AfterSaleMethod;
  7043. apiVo.reasonRemarks = entity.AfterSaleReason;
  7044. apiVo.isDesign = isDesign;
  7045. apiVo.designFree = designFree;
  7046. apiVo.responsibleId = responsibleId;
  7047. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7048. if (toState == "设计师")
  7049. {
  7050. apiVo.isOriginal = Convert.ToBoolean(original);
  7051. }
  7052. designHelper.API_WorkCore(apiVo);//afterDesign
  7053. CeErpMethod methodSql = new CeErpMethod();
  7054. methodSql.con = entity.AfterSaleMethod;
  7055. methodSql.addTime = DateTime.Now;
  7056. methodSql.Create();
  7057. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7058. CeErpMethod.ExecuteNonQuery(delsql);
  7059. if (isCompale)
  7060. {
  7061. aftersale_data_change(entity.ctid);
  7062. }
  7063. returnSuccessMsg("操作成功!");
  7064. return;
  7065. }
  7066. returnErrorMsg("找不到订单记录");
  7067. }
  7068. }
  7069. public void ins_erp_toresponsible()
  7070. {
  7071. if (UrlPostParmsCheck("ctid"))
  7072. {
  7073. string eid = GetPostString("ctid");
  7074. CeErpTradeCell entity = null;
  7075. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7076. if (entity != null)
  7077. {
  7078. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7079. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7080. {
  7081. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7082. return;
  7083. }
  7084. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7085. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7086. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7087. if (entity.AfterSalePreTime == null)
  7088. {
  7089. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7090. {
  7091. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7092. }
  7093. }
  7094. entity.AfterSalePreTime = DateTime.Now;
  7095. //预完成给售后主管审核客户问题直接完成
  7096. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7097. {
  7098. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7099. {
  7100. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7101. }
  7102. }
  7103. ceErpTradeAfterSaleExtend.Update();
  7104. entity.AfterSaleState = 2;
  7105. entity.UpdateTime = DateTime.Now;
  7106. entity.Update();
  7107. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7108. aftersale_data_change(entity.ctid);
  7109. returnSuccessMsg("操作成功!");
  7110. return;
  7111. }
  7112. returnErrorMsg("找不到订单记录");
  7113. }
  7114. }
  7115. public void cancel_erp_aftersaleanddelnew()
  7116. {
  7117. if (UrlPostParmsCheck("ctid"))
  7118. {
  7119. string eid = GetPostString("ctid");
  7120. CeErpTradeCell entity = null;
  7121. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7122. if (entity != null)
  7123. {
  7124. entity.AfterSaleState = 0;
  7125. entity.AfterSaleReason = "";
  7126. entity.AfterSaleMethod = "";
  7127. entity.AfterSaleMemo = "";
  7128. entity.AfterSaleResponsible = "";
  7129. entity.ResponsibleUserId = "";
  7130. entity.DeductFee = 0;
  7131. entity.RefundFee = 0;
  7132. entity.IsArbitrate = 0;
  7133. CeErpTradeResponsible.DelByTid(eid, -1);
  7134. entity.Update();
  7135. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7136. if (after != null)
  7137. {
  7138. if (after.OrderState < 5)
  7139. CeErpTradeCell.DelByCtid("S_" + eid);
  7140. }
  7141. returnSuccessMsg("操作成功!");
  7142. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7143. return;
  7144. }
  7145. returnErrorMsg("找不到订单记录");
  7146. }
  7147. }
  7148. public void get_erp_aftersale_pregather()
  7149. {
  7150. List<string> lw = new List<string>();
  7151. int st = GetInt("st");
  7152. string tid = GetPostString("ctid");
  7153. if (tid.Length > 0)
  7154. {
  7155. string select_tid = getTidByCtid(tid);
  7156. lw.Add(string.Format("tid='{0}'", select_tid));
  7157. }
  7158. string shopname = GetPostString("shopname");
  7159. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7160. string buyernick = GetPostString("buyer_nick");
  7161. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7162. string sellermemo = GetPostString("seller_memo");
  7163. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7164. string orderState = GetPostString("orderState");
  7165. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7166. string reason = GetPostString("reason");
  7167. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7168. string method = GetPostString("method");
  7169. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7170. string handler = GetPostString("handler");
  7171. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7172. string handledate1 = GetPostString("handledate1");
  7173. string handledate2 = GetPostString("handledate2");
  7174. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7175. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7176. string supplier = GetPostString("supplier");
  7177. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7178. string responsible = GetPostString("responsibleman");
  7179. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7180. string customer = GetPostString("customer");
  7181. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7182. string design = GetPostString("design");
  7183. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7184. string afterMemoType = GetPostString("aftermemotype");
  7185. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7186. string afterSaleMemo = GetPostString("afterSaleMemo");
  7187. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7188. string afterresult = GetPostString("afterresult");
  7189. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7190. string poscode = CurrentUser.UserPost.Post.Code;
  7191. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7192. {
  7193. string shopid = CurrentUser.User.pemShop;
  7194. lw.Add(string.Format("shopId in ({0})", shopid));
  7195. }
  7196. var mainwhere = string.Join(" and ", lw.ToArray());
  7197. string ro_json = "";
  7198. string type = GetPostString("gather_type");
  7199. int number = 0;
  7200. if (poscode == "AfterSale")
  7201. {
  7202. //处理中
  7203. if (type == "Handling")
  7204. {
  7205. 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) : ""));
  7206. DataTable dt = null;
  7207. try
  7208. {
  7209. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7210. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7211. }
  7212. catch (Exception e)
  7213. {
  7214. dt = new DataTable();
  7215. }
  7216. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7217. return;
  7218. }
  7219. if (type == "Wait")
  7220. {
  7221. //待处理
  7222. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7223. DataTable dt1 = null;
  7224. try
  7225. {
  7226. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7227. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7228. }
  7229. catch (Exception e)
  7230. {
  7231. dt1 = new DataTable();
  7232. }
  7233. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7234. return;
  7235. }
  7236. if (type == "back")
  7237. {
  7238. //打回
  7239. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7240. DataTable dt2 = null;
  7241. try
  7242. {
  7243. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7244. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7245. }
  7246. catch (Exception e)
  7247. {
  7248. dt2 = new DataTable();
  7249. }
  7250. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7251. return;
  7252. }
  7253. if (type == "preCompletion")
  7254. {
  7255. //预完成
  7256. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7257. DataTable dt3 = null;
  7258. try
  7259. {
  7260. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7261. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7262. }
  7263. catch (Exception e)
  7264. {
  7265. dt3 = new DataTable();
  7266. }
  7267. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7268. return;
  7269. }
  7270. if (type == "documentary")
  7271. {
  7272. //跟单中
  7273. 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) : ""));
  7274. DataTable dt4 = null;
  7275. try
  7276. {
  7277. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7278. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7279. }
  7280. catch (Exception e)
  7281. {
  7282. dt4 = new DataTable();
  7283. }
  7284. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7285. return;
  7286. }
  7287. if (type == "reBack")
  7288. {
  7289. //被打回
  7290. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7291. DataTable dt1 = null;
  7292. try
  7293. {
  7294. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7295. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7296. }
  7297. catch (Exception e)
  7298. {
  7299. dt1 = new DataTable();
  7300. }
  7301. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7302. return;
  7303. }
  7304. }
  7305. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7306. {
  7307. if (type == "puBack")
  7308. {
  7309. //退回
  7310. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7311. DataTable dt = null;
  7312. try
  7313. {
  7314. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7315. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7316. }
  7317. catch (Exception e)
  7318. {
  7319. dt = new DataTable();
  7320. }
  7321. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7322. return;
  7323. }
  7324. if (type == "reBack")
  7325. {
  7326. //打回
  7327. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7328. DataTable dt1 = null;
  7329. try
  7330. {
  7331. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7332. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7333. }
  7334. catch (Exception e)
  7335. {
  7336. dt1 = new DataTable();
  7337. }
  7338. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7339. return;
  7340. }
  7341. if (type == "examEd")
  7342. {
  7343. //已审核
  7344. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7345. DataTable dt2 = null;
  7346. try
  7347. {
  7348. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7349. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7350. }
  7351. catch (Exception e)
  7352. {
  7353. dt2 = new DataTable();
  7354. }
  7355. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7356. return;
  7357. }
  7358. if (type == "waitExam")
  7359. {
  7360. //待审核
  7361. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7362. DataTable dt3 = null;
  7363. try
  7364. {
  7365. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7366. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7367. }
  7368. catch (Exception e)
  7369. {
  7370. dt3 = new DataTable();
  7371. }
  7372. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7373. return;
  7374. }
  7375. if (type == "Handling")
  7376. {
  7377. //处理中
  7378. 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) : ""));
  7379. DataTable dt4 = null;
  7380. try
  7381. {
  7382. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7383. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7384. }
  7385. catch (Exception e)
  7386. {
  7387. dt4 = new DataTable();
  7388. }
  7389. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7390. return;
  7391. }
  7392. if (type == "Wait")
  7393. {
  7394. //待处理
  7395. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7396. DataTable dt5 = null;
  7397. try
  7398. {
  7399. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7400. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7401. }
  7402. catch (Exception e)
  7403. {
  7404. dt5 = new DataTable();
  7405. }
  7406. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7407. return;
  7408. }
  7409. if (type == "documentary")
  7410. {
  7411. //跟单中
  7412. 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) : ""));
  7413. DataTable dt6 = null;
  7414. try
  7415. {
  7416. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7417. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7418. }
  7419. catch (Exception e)
  7420. {
  7421. dt6 = new DataTable();
  7422. }
  7423. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7424. return;
  7425. }
  7426. }
  7427. returnSuccess(ro_json);
  7428. }
  7429. public void end_erp_aftersale()
  7430. {
  7431. if (UrlPostParmsCheck("ctid"))
  7432. {
  7433. string eid = GetPostString("ctid");
  7434. CeErpTradeCell entity = null;
  7435. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7436. if (entity != null)
  7437. {
  7438. string stype = GetPostString("stype");
  7439. string typeStr = stype;
  7440. entity.AfterSaleState = 4;
  7441. entity.FinishAfterSaleTime = DateTime.Now;
  7442. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7443. entity.Update();
  7444. ApiVo apiVo = new ApiVo();
  7445. apiVo.orderNumber = entity.ctid;
  7446. apiVo.actionName = "afterOver";
  7447. designHelper.API_WorkCore(apiVo); //afterOver
  7448. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7449. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7450. CeErpSukuraData.createInfo(entity.ctid, 8);
  7451. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7452. returnSuccessMsg("操作成功!");
  7453. return;
  7454. }
  7455. returnErrorMsg("找不到订单记录");
  7456. }
  7457. }
  7458. public void ins_erp_finishaftersale()
  7459. {
  7460. if (UrlPostParmsCheck("id"))
  7461. {
  7462. string eid = GetPostString("id");
  7463. CeErpTradeResponsible entity = null;
  7464. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7465. if (entity != null)
  7466. {
  7467. entity.VerifyState = 1;
  7468. entity.VerifyTime = DateTime.Now;
  7469. entity.Update();
  7470. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7471. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7472. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7473. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7474. if (dt.Rows.Count <= 0)
  7475. {
  7476. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7477. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7478. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7479. CeErpSukuraData.createInfo(entity.tid, 8);
  7480. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7481. {
  7482. CeErpDesignerBill.Del(entity.tid);
  7483. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7484. }
  7485. }
  7486. returnSuccessMsg("操作成功!");
  7487. return;
  7488. }
  7489. returnErrorMsg("找不到订单记录");
  7490. }
  7491. }
  7492. public void upd_erp_arbitrateaftersale()
  7493. {
  7494. if (UrlPostParmsCheck("id"))
  7495. {
  7496. string eid = GetPostString("id");
  7497. CeErpTradeResponsible entity = null;
  7498. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7499. if (entity != null)
  7500. {
  7501. entity.IsArbitrate = 1;
  7502. entity.ArbitradeMemo = GetPostString("reason");
  7503. entity.VerifyState = 2;
  7504. entity.Update();
  7505. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7506. if (tradecell != null)
  7507. {
  7508. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7509. tradecell.IsArbitrate = 1;
  7510. tradecell.Update();
  7511. }
  7512. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7513. returnSuccessMsg("操作成功!");
  7514. return;
  7515. }
  7516. returnErrorMsg("找不到订单记录");
  7517. }
  7518. }
  7519. public void upd_erp_backaftersale()
  7520. {
  7521. if (UrlPostParmsCheck("tid"))
  7522. {
  7523. string eid = GetPostString("tid");
  7524. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7525. int backNum = 0;
  7526. if (number != null)
  7527. {
  7528. backNum = number.BackNum;
  7529. }
  7530. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7531. CeErpTradeCell entity = null;
  7532. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7533. if (entity != null)
  7534. {
  7535. entity.AfterSaleBackReason = GetPostString("backreason");
  7536. entity.AfterSaleState = 1;
  7537. entity.AfterSaleSupplierState = 0;
  7538. entity.UpdateTime = DateTime.Now;
  7539. entity.Update();
  7540. returnSuccessMsg("操作成功!");
  7541. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7542. return;
  7543. }
  7544. returnErrorMsg("找不到订单记录");
  7545. }
  7546. }
  7547. public void get_erp_supplieraftersalelist()
  7548. {
  7549. DataStruct dStruct = GetPostStruct();
  7550. List<string> lw = new List<string>();
  7551. string tid = GetPostString("ctid");
  7552. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7553. string shopname = GetPostString("shopname");
  7554. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7555. string buyernick = GetPostString("buyer_nick");
  7556. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7557. string sellermemo = GetPostString("seller_memo");
  7558. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7559. string orderState = GetPostString("orderState");
  7560. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7561. string afterState = GetPostString("afterstate");
  7562. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7563. string date1 = GetPostString("date1");
  7564. string date2 = GetPostString("date2");
  7565. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7566. if (dw.Length > 0) lw.Add(dw);
  7567. string price1 = GetPostString("price1");
  7568. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7569. string price2 = GetPostString("price2");
  7570. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7571. string reason = GetPostString("reason");
  7572. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7573. string method = GetPostString("method");
  7574. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7575. string handledate1 = GetPostString("handledate1");
  7576. string handledate2 = GetPostString("handledate2");
  7577. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7578. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7579. string handler = GetPostString("handler");
  7580. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7581. string afterdate1 = GetPostString("afterdate1");
  7582. string afterdate2 = GetPostString("afterdate2");
  7583. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7584. if (afterDate.Length > 0) lw.Add(afterDate);
  7585. string customer = GetPostString("customer");
  7586. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7587. string design = GetPostString("design");
  7588. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7589. string afterMemoType = GetPostString("aftermemotype");
  7590. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7591. string vstate = GetPostString("vstate");
  7592. if (vstate.Length > 0)
  7593. {
  7594. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7595. }
  7596. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7597. string supplier = GetPostString("supplier");
  7598. int supid = commonHelper.getSupplierIDByName(supplier);
  7599. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7600. string posCode = CurrentUser.UserPost.Post.Code;
  7601. if (posCode == "Supplier")
  7602. {
  7603. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7604. }
  7605. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7606. {
  7607. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7608. }
  7609. else
  7610. {
  7611. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7612. }
  7613. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7614. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7615. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7616. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7617. writeGridDataTableJson(dStruct.TotalCount, dt);
  7618. }
  7619. public void upd_erp_supverifyaftersale()
  7620. {
  7621. if (UrlPostParmsCheck("id"))
  7622. {
  7623. string id = GetPostString("id");
  7624. int st = GetPostInt("afterstate");
  7625. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7626. CeErpTradeCell entity = null;
  7627. if (ceErpTradeResponsible != null)
  7628. {
  7629. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7630. }
  7631. string afmemo = GetPostString("supmemo");
  7632. string image = GetPostString("image");
  7633. if (entity != null)
  7634. {
  7635. entity.AfterSaleSupplierState = st;
  7636. entity.AfterSaleSupplierMemo = afmemo;
  7637. if (st == 1)
  7638. {
  7639. ceErpTradeResponsible.VerifyState = 1;
  7640. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7641. ceErpTradeResponsible.Update();
  7642. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7643. if (isAll)
  7644. {
  7645. entity.AfterSaleState = 4;
  7646. entity.FinishAfterSaleTime = DateTime.Now;
  7647. }
  7648. }
  7649. else
  7650. {
  7651. CeErpTradeResponsible.dateByTid(entity.ctid);
  7652. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7653. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7654. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7655. if (num <= 1)
  7656. {
  7657. entity.AfterSaleState = 1;
  7658. }
  7659. else
  7660. {
  7661. entity.AfterSaleState = 5;
  7662. }
  7663. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7664. if (ceErpTradeAfterSaleExtend != null)
  7665. {
  7666. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7667. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7668. ceErpTradeAfterSaleExtend.Update();
  7669. }
  7670. else
  7671. {
  7672. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7673. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7674. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7675. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7676. ceErpTradeAfterSaleExtend.Create();
  7677. }
  7678. }
  7679. if (entity.AfterSaleState == 4)
  7680. {
  7681. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7682. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7683. {
  7684. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7685. }
  7686. ApiVo apiVo = new ApiVo();
  7687. apiVo.orderNumber = entity.ctid;
  7688. apiVo.actionName = "afterOver";
  7689. designHelper.API_WorkCore(apiVo); //afterOver
  7690. }
  7691. entity.UpdateTime = DateTime.Now;
  7692. entity.Update();
  7693. returnSuccessMsg("操作成功!");
  7694. CeErpSukuraData.createInfo(entity.ctid, 8);
  7695. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7696. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7697. return;
  7698. }
  7699. returnErrorMsg("找不到订单记录");
  7700. }
  7701. }
  7702. public void upd_erp_masteraftersale()
  7703. {
  7704. if (UrlPostParmsCheck("id"))
  7705. {
  7706. string id = GetPostString("id");
  7707. int st = GetPostInt("afterstate");
  7708. string afmemo = GetPostString("supmemo");
  7709. string image = GetPostString("image");
  7710. string textResult = GetPostString("textResult");
  7711. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7712. if (ceErpTradeResponsible != null)
  7713. {
  7714. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7715. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7716. ceErpTradeResponsible.Update();
  7717. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7718. if (entity != null)
  7719. {
  7720. entity.AfterSaleSupplierState = st;
  7721. entity.AfterSaleSupplierMemo = afmemo;
  7722. if (st == 1)
  7723. {
  7724. }
  7725. else
  7726. {
  7727. CeErpTradeResponsible.dateByTid(entity.ctid);
  7728. //退回到售后
  7729. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7730. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7731. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7732. if (num <= 1)
  7733. {
  7734. entity.AfterSaleState = 1;
  7735. }
  7736. else
  7737. {
  7738. entity.AfterSaleState = 5;
  7739. }
  7740. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7741. if (ceErpTradeAfterSaleExtend != null)
  7742. {
  7743. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7744. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7745. ceErpTradeAfterSaleExtend.Update();
  7746. }
  7747. else
  7748. {
  7749. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7750. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7751. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7752. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7753. ceErpTradeAfterSaleExtend.Create();
  7754. }
  7755. }
  7756. entity.UpdateTime = DateTime.Now;
  7757. entity.Update();
  7758. returnSuccessMsg("操作成功!");
  7759. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7760. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7761. return;
  7762. }
  7763. }
  7764. returnErrorMsg("找不到订单记录");
  7765. }
  7766. }
  7767. public void upd_erp_personaftersale()
  7768. {
  7769. if (UrlPostParmsCheck("id"))
  7770. {
  7771. //林小连
  7772. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7773. {
  7774. upd_erp_masteraftersale();
  7775. return;
  7776. }
  7777. string id = GetPostString("id");
  7778. int st = GetPostInt("afterstate");
  7779. string afmemo = GetPostString("supmemo");
  7780. string image = GetPostString("image");
  7781. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7782. if (ceErpTradeResponsible != null)
  7783. {
  7784. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7785. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7786. ceErpTradeResponsible.Update();
  7787. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7788. if (entity != null)
  7789. {
  7790. entity.AfterSaleSupplierMemo = afmemo;
  7791. entity.AfterSaleSupplierState = st;
  7792. if (st == 1)
  7793. {
  7794. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7795. if (isAll)
  7796. {
  7797. entity.AfterSaleState = 4;
  7798. entity.FinishAfterSaleTime = DateTime.Now;
  7799. }
  7800. }
  7801. else
  7802. {
  7803. CeErpTradeResponsible.dateByTid(entity.ctid);
  7804. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7805. if (ceErpTradeAfterSaleExtend != null)
  7806. {
  7807. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7808. ceErpTradeAfterSaleExtend.Update();
  7809. }
  7810. else
  7811. {
  7812. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7813. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7814. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7815. ceErpTradeAfterSaleExtend.Create();
  7816. }
  7817. //退回到主管
  7818. //entity.AfterSaleState = 2;
  7819. }
  7820. if (entity.AfterSaleState == 4)
  7821. {
  7822. ApiVo apiVo = new ApiVo();
  7823. apiVo.orderNumber = entity.ctid;
  7824. apiVo.actionName = "afterOver";
  7825. designHelper.API_WorkCore(apiVo); //afterOver
  7826. }
  7827. entity.UpdateTime = DateTime.Now;
  7828. entity.Update();
  7829. returnSuccessMsg("操作成功!");
  7830. CeErpSukuraData.createInfo(entity.ctid, 8);
  7831. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7832. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7833. return;
  7834. }
  7835. }
  7836. returnErrorMsg("找不到订单记录");
  7837. }
  7838. }
  7839. public void set_erp_supplierrefundtag()
  7840. {
  7841. if (UrlPostParmsCheck("ctid"))
  7842. {
  7843. string eid = GetPostString("ctid");
  7844. CeErpTradeCell entity = null;
  7845. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7846. if (entity != null)
  7847. {
  7848. entity.IsSupplierRefund = GetPostInt("tag");
  7849. entity.Update();
  7850. returnSuccessMsg("操作成功!");
  7851. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7852. return;
  7853. }
  7854. returnErrorMsg("找不到订单记录");
  7855. }
  7856. }
  7857. public void get_erp_refundlist()
  7858. {
  7859. DataStruct dStruct = GetPostStruct();
  7860. List<string> lw = new List<string>();
  7861. string tid = GetPostString("tid");
  7862. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7863. //string rid = GetPostString("refund_id");
  7864. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7865. string shopname = GetPostString("shopname");
  7866. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7867. string buyernick = GetPostString("buyer_nick");
  7868. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7869. string customer = GetPostString("customer");
  7870. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7871. string design = GetPostString("design");
  7872. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7873. string sellermemo = GetPostString("seller_memo");
  7874. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7875. //string date1 = GetPostString("date1");
  7876. //string date2 = GetPostString("date2");
  7877. //string dateType = GetPostString("dateType");
  7878. //if (dateType.Length > 0)
  7879. //{
  7880. // if (dateType == "1001") dateType = "0";
  7881. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7882. // if (searchDT.Count == 2)
  7883. // {
  7884. // date1 = searchDT[0].ToString();
  7885. // date2 = searchDT[1].ToString();
  7886. // }
  7887. //}
  7888. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7889. //if (dw.Length > 0) lw.Add(dw);
  7890. string redate1 = GetPostString("refunddate1");
  7891. string redate2 = GetPostString("refunddate2");
  7892. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7893. if (dwdate.Length > 0) lw.Add(dwdate);
  7894. string price1 = GetPostString("price1");
  7895. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7896. string price2 = GetPostString("price2");
  7897. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7898. string ispartrefund = GetPostString("ispartrefund");
  7899. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7900. string refundState = GetPostString("refundvstate");
  7901. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7902. int st = GetInt("st");
  7903. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7904. {
  7905. string responsible = GetPostString("responsibleman");
  7906. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7907. lw.Add(string.Format("RefundState>={0}", st));
  7908. string code = CurrentUser.UserPost.Post.Code;
  7909. if (code == "CustomerService")
  7910. {
  7911. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7912. }
  7913. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7914. {
  7915. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7916. }
  7917. else if (code == "Place" || code == "PlaceMr")
  7918. {
  7919. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7920. }
  7921. dStruct.Order = "RefundState asc,created desc";
  7922. }
  7923. else if (st == 10)
  7924. {
  7925. string responsible = GetPostString("responsibleman");
  7926. if (responsible == "空白")
  7927. {
  7928. lw.Add(string.Format("ResponsibleUserName = ''"));
  7929. }
  7930. else if (responsible.Length > 0)
  7931. {
  7932. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7933. }
  7934. lw.Add(string.Format("RefundState>=0"));
  7935. dStruct.Order = "created desc";
  7936. }
  7937. else
  7938. {
  7939. string responsible = GetPostString("responsibleman");
  7940. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7941. lw.Add(string.Format("RefundState={0}", st));
  7942. dStruct.Order = "created desc";
  7943. }
  7944. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7945. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7946. dt.Columns.Add("refund_fees");
  7947. foreach (DataRow dr in dt.Rows)
  7948. {
  7949. String status = dr["status"].ToString();
  7950. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7951. {
  7952. dr["refund_fees"] = dr["refund_fee"];
  7953. }
  7954. else
  7955. {
  7956. dr["refund_fees"] = "0.0";
  7957. }
  7958. }
  7959. writeGridDataTableJson(dStruct.TotalCount, dt);
  7960. }
  7961. public void get_erp_refunddesignlist()
  7962. {
  7963. DataStruct dStruct = GetPostStruct();
  7964. List<string> lw = new List<string>();
  7965. string tid = GetPostString("tid");
  7966. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7967. string shopname = GetPostString("shopname");
  7968. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7969. string buyernick = GetPostString("buyer_nick");
  7970. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7971. string customer = GetPostString("customer");
  7972. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7973. string design = GetPostString("design");
  7974. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7975. string sellermemo = GetPostString("seller_memo");
  7976. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7977. string redate1 = GetPostString("refunddate1");
  7978. string redate2 = GetPostString("refunddate2");
  7979. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7980. if (dwdate.Length > 0) lw.Add(dwdate);
  7981. string price1 = GetPostString("price1");
  7982. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7983. string price2 = GetPostString("price2");
  7984. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7985. string ispartrefund = GetPostString("ispartrefund");
  7986. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7987. string designerorg = GetPostString("designerorg");
  7988. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7989. string refundState = GetPostString("refundState");
  7990. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7991. int myOrgid = CurrentUser.UserPost.OrgID;
  7992. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7993. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7994. {
  7995. if (CurrentUser.User.TeamIds.Length > 0)
  7996. {
  7997. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7998. }
  7999. else
  8000. {
  8001. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8002. }
  8003. }
  8004. else if ("SysAdmin".Equals(myOrgCode))
  8005. {
  8006. }
  8007. else
  8008. {
  8009. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8010. {
  8011. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8012. }
  8013. else
  8014. {
  8015. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8016. }
  8017. }
  8018. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8019. dStruct.Order = "created desc";
  8020. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8021. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8022. dt.Columns.Add("refund_fees");
  8023. foreach (DataRow dr in dt.Rows)
  8024. {
  8025. String status = dr["status"].ToString();
  8026. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8027. {
  8028. dr["refund_fees"] = dr["refund_fee"];
  8029. }
  8030. else
  8031. {
  8032. dr["refund_fees"] = "0.0";
  8033. }
  8034. }
  8035. writeGridDataTableJson(dStruct.TotalCount, dt);
  8036. }
  8037. public void handle_erp_refundtag()
  8038. {
  8039. if (UrlPostParmsCheck("refund_id"))
  8040. {
  8041. string eid = GetPostString("refund_id");
  8042. string respMan = GetPostString("ResponsibleName");
  8043. if (respMan.Length <= 0)
  8044. {
  8045. returnErrorMsg("责任人不能为空");
  8046. return;
  8047. }
  8048. CeErpTradeRefund entity = null;
  8049. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8050. if (entity != null)
  8051. {
  8052. entity.ResponsibleUserName = respMan;
  8053. string userid = GetPostString("ResponsibleUserId");
  8054. if (userid.Length > 0)
  8055. {
  8056. entity.ResponsibleUserId = userid;
  8057. }
  8058. entity.Memo = GetPostString("Memo");
  8059. if (respMan.IndexOf("客服") != -1 ||
  8060. respMan.IndexOf("设计师") != -1 ||
  8061. respMan.IndexOf("下单员") != -1)
  8062. {
  8063. entity.RefundState = 2;
  8064. }
  8065. else
  8066. {
  8067. entity.RefundState = 3;
  8068. }
  8069. entity.modified = DateTime.Now;
  8070. entity.Update();
  8071. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8072. returnSuccessMsg("操作成功!");
  8073. return;
  8074. }
  8075. returnErrorMsg("找不到订单记录");
  8076. }
  8077. }
  8078. public void handle_erp_designrefundtag()
  8079. {
  8080. if (UrlPostParmsCheck("refund_id"))
  8081. {
  8082. string eid = GetPostString("refund_id");
  8083. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8084. if (ceErpTradeCellExtend == null)
  8085. {
  8086. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8087. ceErpTradeCellExtend.ctid = eid;
  8088. }
  8089. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8090. if (ceErpTradeCellExtend.ID > 0)
  8091. {
  8092. ceErpTradeCellExtend.Update();
  8093. }
  8094. else
  8095. {
  8096. ceErpTradeCellExtend.Create();
  8097. }
  8098. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8099. returnSuccessMsg("操作成功!");
  8100. return;
  8101. }
  8102. returnErrorMsg("找不到订单记录");
  8103. }
  8104. public void upd_erp_refundverify()
  8105. {
  8106. if (UrlPostParmsCheck("refund_id"))
  8107. {
  8108. string eid = GetPostString("refund_id");
  8109. CeErpTradeRefund entity = null;
  8110. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8111. if (entity != null)
  8112. {
  8113. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8114. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8115. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8116. {
  8117. entity.RefundState = 2;
  8118. }
  8119. else
  8120. {
  8121. entity.RefundState = 3;
  8122. }
  8123. entity.Update();
  8124. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8125. returnSuccessMsg("操作成功!");
  8126. return;
  8127. }
  8128. returnErrorMsg("找不到订单记录");
  8129. }
  8130. }
  8131. public void upd_erp_refundapprove()
  8132. {
  8133. if (UrlPostParmsCheck("refund_id"))
  8134. {
  8135. string eid = GetPostString("refund_id");
  8136. CeErpTradeRefund entity = null;
  8137. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8138. if (entity != null)
  8139. {
  8140. int apr = GetPostInt("approve");
  8141. if (apr == 0)
  8142. {
  8143. entity.RefundState = 1;
  8144. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8145. }
  8146. else if (apr == 1)
  8147. {
  8148. entity.RefundState = 3;
  8149. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8150. }
  8151. entity.modified = DateTime.Now;
  8152. entity.Update();
  8153. returnSuccessMsg("操作成功!");
  8154. return;
  8155. }
  8156. returnErrorMsg("找不到订单记录");
  8157. }
  8158. }
  8159. public void get_erp_billlist()
  8160. {
  8161. DataStruct dStruct = GetPostStruct();
  8162. List<string> lw = new List<string>();
  8163. string title = GetPostString("title");
  8164. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8165. string tid = GetPostString("tid");
  8166. string tids = GetPostString("tids");
  8167. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8168. if (tids.Length > 0)
  8169. {
  8170. tids = "'" + tids + "'";
  8171. tids = tids.Replace(",", "','");
  8172. lw.Add(string.Format("tid in ({0})", tids));
  8173. }
  8174. string shopname = GetPostString("shopname");
  8175. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8176. string buyernick = GetPostString("buyer_nick");
  8177. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8178. string customer = GetPostString("customer");
  8179. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8180. string date1 = GetPostString("date1");
  8181. string date2 = GetPostString("date2");
  8182. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8183. if (dw.Length > 0) lw.Add(dw);
  8184. string price1 = GetPostString("price1");
  8185. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8186. string price2 = GetPostString("price2");
  8187. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8188. string returndate1 = GetPostString("returndate1");
  8189. string returndate2 = GetPostString("returndate2");
  8190. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8191. if (dw1.Length > 0) lw.Add(dw1);
  8192. string billtype = GetPostString("billtype");
  8193. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8194. string billstate = GetPostString("billstate");
  8195. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8196. string usershop = CurrentUser.User.pemShop;
  8197. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8198. dStruct.Order = "createTime desc";
  8199. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8200. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8201. //foreach (DataRow dr in dt.Rows)
  8202. //{
  8203. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8204. //}
  8205. writeGridDataTableJson(dStruct.TotalCount, dt);
  8206. }
  8207. public void modify_erp_billinfo()
  8208. {
  8209. if (UrlPostParmsCheck("ID"))
  8210. {
  8211. string eid = GetPostString("ID");
  8212. CeErpBill bill_entity = null;
  8213. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8214. if (bill_entity != null)
  8215. {
  8216. bill_entity.tid = GetPostString("tid");
  8217. bill_entity.title = GetPostString("title");
  8218. bill_entity.tax = GetPostString("tax");
  8219. bill_entity.bank = GetPostString("bank");
  8220. bill_entity.bankac = GetPostString("bankac");
  8221. bill_entity.address = GetPostString("address");
  8222. bill_entity.phone = GetPostString("phone");
  8223. bill_entity.price = GetPostString("price");
  8224. bill_entity.productId = GetPostInt("ProductName");
  8225. bill_entity.num = GetPostInt("num");
  8226. bill_entity.unit = GetPostString("unit");
  8227. bill_entity.type = GetPostString("type");
  8228. bill_entity.sendType = GetPostString("SendType");
  8229. bill_entity.email = GetPostString("email");
  8230. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8231. bill_entity.shopName = GetPostString("ShopName");
  8232. bill_entity.applymemo = GetPostString("applymemo");
  8233. bill_entity.modifyTime = DateTime.Now;
  8234. bill_entity.createTime = DateTime.Now;
  8235. bill_entity.state = 0;
  8236. bill_entity.Update();
  8237. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8238. returnSuccessMsg("发票修改成功!");
  8239. return;
  8240. }
  8241. returnErrorMsg("找不到对应记录");
  8242. }
  8243. }
  8244. public void set_erp_invoicing()
  8245. {
  8246. if (UrlPostParmsCheck("id"))
  8247. {
  8248. try
  8249. {
  8250. string eid = GetPostString("id");
  8251. CeErpBill bill_entity = null;
  8252. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8253. if (bill_entity != null)
  8254. {
  8255. int ComId = GetPostInt("ComId");
  8256. //string memo = GetPostString("Memo");
  8257. int allInfo = GetPostInt("allinfo");
  8258. string clert = CurrentUser.User.Name;
  8259. //string detailValue = GetPostString("detailvalue");
  8260. string billId = bill_entity.billOrderId;
  8261. string[] billIdList = billId.Split(',');
  8262. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8263. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8264. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8265. {
  8266. billCount += 1;
  8267. }
  8268. if (billId.Length <= 0 || billIdList.Length != billCount)
  8269. {
  8270. bill_entity.billOrderId = "";
  8271. string prebill = "ltb";
  8272. for (int idx = 1; idx <= billCount; idx++)
  8273. {
  8274. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8275. string billoid = prebill + idx + dtstr;
  8276. bill_entity.billOrderId += billoid;
  8277. if (idx < billCount)
  8278. {
  8279. bill_entity.billOrderId += ",";
  8280. }
  8281. }
  8282. }
  8283. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8284. if (bill_entity.state == 5)
  8285. {
  8286. string errMsg = bill_entity.failerror;
  8287. string[] errlist = errMsg.Split('|');
  8288. string[] errTags = new string[errlist.Length];
  8289. for (int itag = 0; itag < errlist.Length; itag++)
  8290. {
  8291. if (errlist[itag].Length <= 0) continue;
  8292. errTags[itag] = errlist[itag].Split('&')[0];
  8293. }
  8294. for (int iii = 0; iii < errTags.Length; iii++)
  8295. {
  8296. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8297. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8298. if (billOrderList.Length >= erroBillOrderTag)
  8299. {
  8300. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8301. if (needModifyBillId.Length <= 19)
  8302. {
  8303. needModifyBillId = needModifyBillId + "1";
  8304. }
  8305. else
  8306. {
  8307. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8308. last = last + 1;
  8309. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8310. }
  8311. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8312. }
  8313. }
  8314. }
  8315. bool isHaveBillSucces = false;
  8316. string totalRes = "";
  8317. bill_entity.failerror = "";
  8318. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8319. {
  8320. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8321. totalRes += res;
  8322. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8323. {
  8324. isHaveBillSucces = true;
  8325. bill_entity.comId = ComId;
  8326. bill_entity.state = 1;
  8327. bill_entity.executeTime = DateTime.Now;
  8328. bill_entity.executeUser = clert;
  8329. }
  8330. else
  8331. {
  8332. bill_entity.state = 5;
  8333. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8334. }
  8335. }
  8336. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8337. bill_entity.Update();
  8338. if (isHaveBillSucces)
  8339. {
  8340. StringBuilder sql = new StringBuilder();
  8341. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8342. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8343. }
  8344. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8345. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8346. {
  8347. returnErrorMsg("开票失败");
  8348. }
  8349. else
  8350. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8351. return;
  8352. }
  8353. returnErrorMsg("找不到对应记录");
  8354. }
  8355. catch (Exception ex)
  8356. {
  8357. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8358. returnErrorMsg("操作失败");
  8359. }
  8360. }
  8361. }
  8362. public void get_erp_invoicing_back()
  8363. {
  8364. if (UrlPostParmsCheck("id"))
  8365. {
  8366. try
  8367. {
  8368. string id = GetPostString("id");
  8369. CeErpBill entiy = CeErpBill.Get(id);
  8370. if (entiy != null)
  8371. {
  8372. if (entiy.state == 0)
  8373. {
  8374. returnErrorMsg("发票还未开具");
  8375. return;
  8376. }
  8377. string[] billOrderList = entiy.billOrderId.Split(',');
  8378. int iTag = 0;
  8379. entiy.fplsh = "";
  8380. entiy.fpdm = "";
  8381. entiy.fphm = "";
  8382. foreach (string billOrderId in billOrderList)
  8383. {
  8384. iTag++;
  8385. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8386. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8387. {
  8388. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8389. try
  8390. {
  8391. Invoicing_get_response_Obj iObj = null;
  8392. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8393. if (iObj != null)
  8394. {
  8395. entiy.state = 2;
  8396. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8397. entiy.fpdm += iObj.list[0].c_fpdm;
  8398. entiy.fphm += iObj.list[0].c_fphm;
  8399. if (iTag < billOrderList.Length)
  8400. {
  8401. entiy.fplsh += ",";
  8402. entiy.fpdm += ",";
  8403. entiy.fphm += ",";
  8404. }
  8405. entiy.Update();
  8406. }
  8407. StringBuilder sql = new StringBuilder();
  8408. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8409. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8410. returnSuccessMsg("开票成功");
  8411. }
  8412. catch (Exception ex)
  8413. {
  8414. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8415. }
  8416. return;
  8417. }
  8418. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8419. {
  8420. var res_obj = new
  8421. {
  8422. data = "开票中"
  8423. };
  8424. string ro_json = JsonConvert.SerializeObject(res_obj);
  8425. returnSuccess(ro_json);
  8426. return;
  8427. }
  8428. else
  8429. {
  8430. int eidx = res.IndexOf("c_resultmsg");
  8431. int lidx = res.IndexOf("c_status");
  8432. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8433. entiy.state = 5;
  8434. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8435. entiy.Update();
  8436. returnErrorMsg("开票失败");
  8437. return;
  8438. }
  8439. }
  8440. }
  8441. }
  8442. catch (Exception ex)
  8443. {
  8444. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8445. }
  8446. return;
  8447. }
  8448. }
  8449. public void get_erp_invoicing()
  8450. {
  8451. if (UrlPostParmsCheck("id"))
  8452. {
  8453. try
  8454. {
  8455. string id = GetPostString("id");
  8456. CeErpBill entiy = CeErpBill.Get(id);
  8457. if (entiy != null)
  8458. {
  8459. if (entiy.state == 0)
  8460. {
  8461. returnErrorMsg("发票还未开具");
  8462. return;
  8463. }
  8464. if (entiy.sendType == "纸质发票")
  8465. {
  8466. if (entiy.img.Length <= 0)
  8467. {
  8468. returnErrorMsg("查无纸质发票");
  8469. return;
  8470. }
  8471. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8472. returnSuccess(returnres);
  8473. return;
  8474. }
  8475. string[] billOrderList = entiy.billOrderId.Split(',');
  8476. int iTag = 0;
  8477. string fpUrl = "";
  8478. entiy.fplsh = "";
  8479. entiy.fpdm = "";
  8480. entiy.fphm = "";
  8481. foreach (string billOrderId in billOrderList)
  8482. {
  8483. iTag++;
  8484. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8485. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8486. {
  8487. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8488. Invoicing_get_response_Obj iObj = null;
  8489. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8490. if (iObj != null)
  8491. {
  8492. //entiy.state = 2;
  8493. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8494. entiy.fpdm += iObj.list[0].c_fpdm;
  8495. entiy.fphm += iObj.list[0].c_fphm;
  8496. if (iTag < billOrderList.Length)
  8497. {
  8498. entiy.fplsh += ",";
  8499. entiy.fpdm += ",";
  8500. entiy.fphm += ",";
  8501. }
  8502. entiy.Update();
  8503. fpUrl += iObj.list[0].c_url + ",";
  8504. }
  8505. //returnSuccess(res);
  8506. StringBuilder sql = new StringBuilder();
  8507. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8508. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8509. }
  8510. else
  8511. {
  8512. int eidx = res.IndexOf("c_resultmsg");
  8513. //int lidx = res.IndexOf("c_status");
  8514. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8515. //开票失败
  8516. entiy.state = 5;
  8517. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8518. entiy.Update();
  8519. returnErrorMsg("开票失败");
  8520. return;
  8521. }
  8522. }
  8523. var returnObj = new
  8524. {
  8525. data = fpUrl
  8526. };
  8527. string ro_json = JsonConvert.SerializeObject(returnObj);
  8528. returnSuccess(ro_json);
  8529. }
  8530. }
  8531. catch (Exception ex)
  8532. {
  8533. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8534. }
  8535. return;
  8536. }
  8537. }
  8538. public void save_erp_billimg()
  8539. {
  8540. if (UrlPostParmsCheck("id"))
  8541. {
  8542. string eid = GetPostString("id");
  8543. CeErpBill bill_entity = null;
  8544. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8545. if (bill_entity != null)
  8546. {
  8547. bill_entity.img = GetPostString("img");
  8548. bill_entity.executeTime = DateTime.Now;
  8549. bill_entity.state = 2;
  8550. bill_entity.Update();
  8551. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8552. returnSuccessMsg("保存成功");
  8553. }
  8554. return;
  8555. }
  8556. }
  8557. public void upd_erp_billreturnback()
  8558. {
  8559. if (UrlPostParmsCheck("id"))
  8560. {
  8561. int eid = GetPostInt("id");
  8562. CeErpBill bill_entity = null;
  8563. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8564. if (bill_entity != null)
  8565. {
  8566. bill_entity.state = 3;
  8567. bill_entity.returnReason = GetPostString("reason");
  8568. bill_entity.Update();
  8569. returnSuccessMsg("驳回成功!");
  8570. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8571. }
  8572. return;
  8573. }
  8574. }
  8575. public void cancel_erp_bill()
  8576. {
  8577. if (UrlPostParmsCheck("id"))
  8578. {
  8579. int eid = GetPostInt("id");
  8580. int detailValue = GetPostInt("detailvalue");
  8581. CeErpBill bill_entity = null;
  8582. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8583. string cres = "";
  8584. string gres = "";
  8585. if (bill_entity != null)
  8586. {
  8587. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8588. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8589. {
  8590. int iTag = 0;
  8591. bill_entity.fplsh = "";
  8592. bill_entity.fpdm = "";
  8593. bill_entity.fphm = "";
  8594. foreach (string billOrderId in billOrderList)
  8595. {
  8596. iTag++;
  8597. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8598. if (gres.IndexOf("success") != -1)
  8599. {
  8600. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8601. Invoicing_get_response_Obj iObj = null;
  8602. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8603. if (iObj != null)
  8604. {
  8605. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8606. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8607. bill_entity.fphm += iObj.list[0].c_fphm;
  8608. if (iTag < billOrderList.Length)
  8609. {
  8610. bill_entity.fplsh += ",";
  8611. bill_entity.fpdm += ",";
  8612. bill_entity.fphm += ",";
  8613. }
  8614. bill_entity.Update();
  8615. }
  8616. }
  8617. else
  8618. {
  8619. returnErrorMsg(gres);
  8620. return;
  8621. }
  8622. }
  8623. }
  8624. if (bill_entity.sendType == "纸质发票")
  8625. {
  8626. //作废
  8627. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8628. //if (DateTime.Now.Month == extime.Month)
  8629. //{
  8630. //cres = taobaoHelper.cancel_invoicing(eid);
  8631. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8632. //{
  8633. bill_entity.state = 4;//已作废
  8634. bill_entity.Update();
  8635. returnSuccessMsg("发票已作废");
  8636. return;
  8637. //}
  8638. //else
  8639. //{
  8640. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8641. // bill_entity.Update();
  8642. // returnErrorMsg(cres);
  8643. // return;
  8644. //}
  8645. //}
  8646. //else
  8647. //{
  8648. // returnErrorMsg("纸质发票只能作废本月的发票");
  8649. // return;
  8650. //}
  8651. }
  8652. //红冲
  8653. int redTag = 0;
  8654. string[] fpdmList = bill_entity.fpdm.Split(',');
  8655. string[] fphmList = bill_entity.fphm.Split(',');
  8656. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8657. {
  8658. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8659. return;
  8660. }
  8661. foreach (string billOrderId in billOrderList)
  8662. {
  8663. redTag++;
  8664. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8665. cres += onecres;
  8666. cres += ",";
  8667. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8668. {
  8669. bill_entity.state = 4;//已作废
  8670. //bill_entity.Update();
  8671. //returnSuccessMsg("发票已红冲");
  8672. }
  8673. else if (onecres.IndexOf("重复冲红") != -1)
  8674. {
  8675. bill_entity.state = 4;//已作废
  8676. //bill_entity.Update();
  8677. //returnSuccessMsg("发票已红冲");
  8678. }
  8679. else
  8680. {
  8681. string errmsg = commonHelper.KeepChinese(onecres);
  8682. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8683. }
  8684. }
  8685. bill_entity.Update();
  8686. if (cres.IndexOf("失败") != -1)
  8687. returnErrorMsg("红冲失败");
  8688. else
  8689. returnSuccessMsg("发票已红冲");
  8690. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8691. return;
  8692. }
  8693. return;
  8694. }
  8695. }
  8696. public void del_erp_billorder()
  8697. {
  8698. if (UrlPostParmsCheck("id"))
  8699. {
  8700. string eid = GetPostString("id");
  8701. CeErpBill.Del(eid);
  8702. CeErpBill bill = CeErpBill.Get(eid);
  8703. if (bill != null)
  8704. {
  8705. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8706. }
  8707. returnSuccessMsg("删除成功");
  8708. }
  8709. }
  8710. public void finish_erp_bill()
  8711. {
  8712. if (UrlPostParmsCheck("ids"))
  8713. {
  8714. string eids = GetPostString("ids");
  8715. string[] list = eids.Split(',');
  8716. foreach (string eid in list)
  8717. {
  8718. CeErpBill bill = CeErpBill.Get(eid);
  8719. if (bill != null)
  8720. {
  8721. bill.state = 2;
  8722. bill.Update();
  8723. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8724. }
  8725. }
  8726. returnSuccessMsg("操作成功");
  8727. }
  8728. }
  8729. public void get_erp_returncash()
  8730. {
  8731. DataStruct dStruct = GetPostStruct();
  8732. List<string> lw = new List<string>();
  8733. string tid = GetPostString("tid");
  8734. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8735. string shopname = GetPostString("shopname");
  8736. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8737. string buyernick = GetPostString("buyer_nick");
  8738. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8739. string customer = GetPostString("customer");
  8740. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8741. string returndate1 = GetPostString("returndate1");
  8742. string returndate2 = GetPostString("returndate2");
  8743. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8744. if (dw.Length > 0) lw.Add(dw);
  8745. string finishDate1 = GetPostString("finishdate1");
  8746. string finishDate2 = GetPostString("finishdate2");
  8747. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8748. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8749. string returntype = GetPostString("returntype");
  8750. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8751. string returnvstate = GetPostString("returnvstate");
  8752. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8753. dStruct.Order = "created desc";
  8754. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8755. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8756. writeGridDataTableJson(dStruct.TotalCount, dt);
  8757. }
  8758. public void get_erp_staygoods()
  8759. {
  8760. DataStruct dStruct = GetPostStruct();
  8761. List<string> lw = new List<string>();
  8762. string tid = GetPostString("tid");
  8763. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8764. string shopname = GetPostString("shopname");
  8765. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8766. string wangwang = GetPostString("wangwang");
  8767. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8768. string customer = GetPostString("customer");
  8769. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8770. string returndate1 = GetPostString("returndate1");
  8771. string returndate2 = GetPostString("returndate2");
  8772. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8773. if (dw.Length > 0) lw.Add(dw);
  8774. string finishDate1 = GetPostString("finishdate1");
  8775. string finishDate2 = GetPostString("finishdate2");
  8776. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8777. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8778. string returnvstate = GetPostString("returnvstate");
  8779. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8780. string persuadetype = GetPostString("persuadetype");
  8781. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8782. string customerOrg = GetPostString("customerOrg");
  8783. if (customerOrg.Length > 0)
  8784. {
  8785. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8786. }
  8787. dStruct.Order = "creata_time desc";
  8788. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8789. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8790. writeGridDataTableJson(dStruct.TotalCount, dt);
  8791. }
  8792. public void upd_erp_staygoods()
  8793. {
  8794. if (UrlPostParmsCheck("id"))
  8795. {
  8796. int eid = GetPostInt("id");
  8797. CeErpStayGoods entity = null;
  8798. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8799. if (entity != null)
  8800. {
  8801. entity.audit_type = 1;
  8802. entity.audit_time = DateTime.Now;
  8803. entity.audit_u_id = CurrentUser.UserID;
  8804. entity.audit_u_name = CurrentUser.UserName;
  8805. entity.Update();
  8806. returnSuccessMsg("审核成功!");
  8807. return;
  8808. }
  8809. returnErrorMsg("找不到订单记录");
  8810. }
  8811. }
  8812. public void upd_erp_stayGoodsback()
  8813. {
  8814. if (UrlPostParmsCheck("id"))
  8815. {
  8816. int eid = GetPostInt("id");
  8817. CeErpStayGoods entity = null;
  8818. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8819. if (entity != null)
  8820. {
  8821. entity.audit_text = GetPostString("reason");
  8822. entity.audit_type = 2;
  8823. entity.audit_time = DateTime.Now;
  8824. entity.audit_u_id = CurrentUser.UserID;
  8825. entity.audit_u_name = CurrentUser.UserName;
  8826. entity.Update();
  8827. returnSuccessMsg("退回成功!");
  8828. return;
  8829. }
  8830. returnErrorMsg("找不到订单记录");
  8831. }
  8832. }
  8833. public void upd_erp_returncashverify()
  8834. {
  8835. if (UrlPostParmsCheck("ID"))
  8836. {
  8837. int eid = GetPostInt("ID");
  8838. CeErpReturnCash entity = null;
  8839. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8840. if (entity != null)
  8841. {
  8842. entity.cashstate = 1;
  8843. entity.verifytime = DateTime.Now;
  8844. entity.verifyuserid = CurrentUser.UserID;
  8845. entity.Update();
  8846. returnSuccessMsg("审核成功!");
  8847. return;
  8848. }
  8849. returnErrorMsg("找不到订单记录");
  8850. }
  8851. }
  8852. public void upd_all_erp_returncashverify()
  8853. {
  8854. if (UrlPostParmsCheck("ID"))
  8855. {
  8856. String[] list = GetPostString("ID").Split(',');
  8857. CeErpReturnCash entity = null;
  8858. for (int i = 0; i < list.Length; i++)
  8859. {
  8860. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8861. if (entity != null)
  8862. {
  8863. if (entity.cashstate == 1)
  8864. {
  8865. returnErrorMsg("已审核过的订单不需要在审核!");
  8866. return;
  8867. }
  8868. entity.cashstate = 1;
  8869. entity.verifytime = DateTime.Now;
  8870. entity.verifyuserid = CurrentUser.UserID;
  8871. entity.Update();
  8872. }
  8873. }
  8874. returnSuccessMsg("审核成功!");
  8875. return;
  8876. }
  8877. }
  8878. public void upd_erp_returncashback()
  8879. {
  8880. if (UrlPostParmsCheck("ID"))
  8881. {
  8882. int eid = GetPostInt("ID");
  8883. CeErpReturnCash entity = null;
  8884. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8885. if (entity != null)
  8886. {
  8887. entity.backreason = GetPostString("reason");
  8888. entity.cashstate = 2;
  8889. entity.verifytime = DateTime.Now;
  8890. entity.verifyuserid = CurrentUser.UserID;
  8891. entity.Update();
  8892. returnSuccessMsg("退回成功!");
  8893. return;
  8894. }
  8895. returnErrorMsg("找不到订单记录");
  8896. }
  8897. }
  8898. public void upd_erp_returnprice()
  8899. {
  8900. if (UrlPostParmsCheck("ID"))
  8901. {
  8902. int eid = GetPostInt("ID");
  8903. CeErpReturnCash entity = null;
  8904. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8905. if (entity != null)
  8906. {
  8907. if (entity.cashstate == 1)
  8908. {
  8909. returnErrorMsg("审核通过了不能改");
  8910. return;
  8911. }
  8912. entity.returnprice = GetPostDouble("returnprice");
  8913. entity.Update();
  8914. returnSuccessMsg("修改成功!");
  8915. return;
  8916. }
  8917. returnErrorMsg("找不到订单记录");
  8918. }
  8919. }
  8920. public void del_erp_returncash()
  8921. {
  8922. if (UrlPostParmsCheck("ID"))
  8923. {
  8924. int eid = GetPostInt("ID");
  8925. CeErpReturnCash.Del(eid);
  8926. returnSuccessMsg("操作成功");
  8927. return;
  8928. }
  8929. }
  8930. public void test_for_do_sql()
  8931. {
  8932. string sql = GetPostString("sqlstr");
  8933. if (sql.Length > 0)
  8934. {
  8935. try
  8936. {
  8937. DbHelper.DbConn.ExecuteNonQuery(sql);
  8938. var res_obj = new
  8939. {
  8940. data = "成功",
  8941. };
  8942. string ro_json = JsonConvert.SerializeObject(res_obj);
  8943. returnSuccess(ro_json);
  8944. }
  8945. catch (Exception ex)
  8946. {
  8947. var res_obj = new
  8948. {
  8949. data = ex.Message,
  8950. };
  8951. string ro_json = JsonConvert.SerializeObject(res_obj);
  8952. returnSuccess(ro_json);
  8953. }
  8954. }
  8955. }
  8956. public void get_user_info()
  8957. {
  8958. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8959. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8960. }
  8961. public void get_total_data()
  8962. {
  8963. int userId = CurrentUser.UserID;
  8964. string sql = "";
  8965. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8966. {
  8967. 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);
  8968. }
  8969. else
  8970. {
  8971. 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 " +
  8972. "(select ID from CE_ErpUser where ID = {0}) d " +
  8973. "left join " +
  8974. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8975. ") a on d.ID = a.id left join " +
  8976. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8977. ") b on a.id = b.id1 left join" +
  8978. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8979. ") c on a.id = c.id2;", userId);
  8980. }
  8981. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8982. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8983. }
  8984. public void get_date_area_total_data2()
  8985. {
  8986. int userId = CurrentUser.UserID;
  8987. string date_type = GetPostString("timetype");
  8988. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8989. string sql = "";
  8990. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8991. {
  8992. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8993. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8994. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8995. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8996. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8997. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8998. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8999. ") a on e.ID = a.id left join " +
  9000. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9001. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9002. ") b on a.id = b.id1 " +
  9003. "left join " +
  9004. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9005. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9006. ") c on a.id = c.id2 " +
  9007. "left join " +
  9008. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9009. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9010. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9011. }
  9012. else
  9013. {
  9014. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9015. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9016. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9017. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9018. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9019. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9020. ") a on e.ID = a.id left join " +
  9021. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9022. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9023. ") c on a.id = c.id2 " +
  9024. "left join " +
  9025. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9026. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9027. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9028. }
  9029. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9030. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9031. }
  9032. public void get_date_area_total_data()
  9033. {
  9034. int userId = CurrentUser.UserID;
  9035. string date_type = GetPostString("timetype");
  9036. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9037. string date1 = searchDT[0].ToString();
  9038. string date2 = searchDT[1].ToString();
  9039. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9040. {
  9041. SqlParameter[] sqlParameter ={
  9042. new SqlParameter("@userId", SqlDbType.Int,4),
  9043. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9044. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9045. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9046. };
  9047. sqlParameter[0].Value = userId;
  9048. sqlParameter[1].Value = date1;
  9049. sqlParameter[2].Value = date2;
  9050. sqlParameter[3].Direction = ParameterDirection.Output;
  9051. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9052. string res = sqlParameter[3].Value.ToString();
  9053. var res_obj = new
  9054. {
  9055. data = res
  9056. };
  9057. string ro_json = JsonConvert.SerializeObject(res_obj);
  9058. returnSuccess(ro_json);
  9059. }
  9060. else
  9061. {
  9062. SqlParameter[] sqlParameter ={
  9063. new SqlParameter("@userId", SqlDbType.Int,4),
  9064. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9065. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9066. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9067. };
  9068. sqlParameter[0].Value = userId;
  9069. sqlParameter[1].Value = date1;
  9070. sqlParameter[2].Value = date2;
  9071. sqlParameter[3].Direction = ParameterDirection.Output;
  9072. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9073. string res = sqlParameter[3].Value.ToString();
  9074. var res_obj = new
  9075. {
  9076. data = res
  9077. };
  9078. string ro_json = JsonConvert.SerializeObject(res_obj);
  9079. returnSuccess(ro_json);
  9080. }
  9081. //writeGridDataViewJson(dt.Rows.Count, dv);
  9082. }
  9083. public void get_order_list()
  9084. {
  9085. string strFields = GetPostString("paraFields");
  9086. string strOrder = GetPostString("paraOrder");
  9087. string strWhere = GetPostString("paraWhere");
  9088. string strPageSize = GetPostString("paraPageSize");
  9089. DataStruct dStruct = GetPostStruct();
  9090. dStruct.PageSize = int.Parse(strPageSize);
  9091. dStruct.Fileds = strFields;
  9092. dStruct.Order = strOrder;
  9093. dStruct.MainWhere = strWhere;
  9094. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9095. writeGridDataTableJson(dStruct.TotalCount, dt);
  9096. }
  9097. ////获取待开始订单列表
  9098. //public void get_wait_design_order_list()
  9099. //{
  9100. // string date_type = GetPostString("date_type");
  9101. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9102. // DataStruct dStruct = GetPostStruct();
  9103. // dStruct.PageSize = 1000;
  9104. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9105. // List<string> lw = new List<string>();
  9106. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9107. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9108. // dStruct.Order = "WaitDesignTime asc";
  9109. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9110. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9111. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9112. //}
  9113. //获取完成单量排名
  9114. public void get_finish_order_count_ranking()
  9115. {
  9116. /* string date_type = GetPostString("date_type");
  9117. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9118. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9119. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9120. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9121. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9122. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9123. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9124. writeGridDataTableJson(0, new DataTable());
  9125. }
  9126. public void get_finish_order_amount_ranking()
  9127. {
  9128. /*string date_type = GetPostString("date_type");
  9129. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9130. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9131. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9132. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9133. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9134. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9135. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9136. writeGridDataTableJson(0, new DataTable());
  9137. }
  9138. public void get_finish_refund_count_ranking()
  9139. {
  9140. string date_type = GetPostString("date_type");
  9141. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9142. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9143. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9144. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9145. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9146. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9147. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9148. writeGridDataTableJson(dt.Rows.Count, dt);
  9149. }
  9150. public void get_finish_refund_amount_ranking()
  9151. {
  9152. string date_type = GetPostString("date_type");
  9153. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9154. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9155. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9156. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9157. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9158. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9159. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9160. writeGridDataTableJson(dt.Rows.Count, dt);
  9161. }
  9162. public void set_erp_finishorder_director()
  9163. {
  9164. if (UrlPostParmsCheck("ctid"))
  9165. {
  9166. string eid = GetPostString("ctid");
  9167. CeErpTradeCell entity = null;
  9168. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9169. if (entity != null)
  9170. {
  9171. entity.OrderState = 8;
  9172. entity.Update();
  9173. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9174. returnSuccessMsg("操作成功!");
  9175. return;
  9176. }
  9177. returnErrorMsg("找不到记录");
  9178. }
  9179. }
  9180. public void get_erp_placeregistlist()
  9181. {
  9182. DataStruct dStruct = GetPostStruct();
  9183. List<string> lw = new List<string>();
  9184. string outsid = GetPostString("outsid");
  9185. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9186. string memo = GetPostString("memo");
  9187. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9188. string filename = GetPostString("filename");
  9189. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9190. string islate = GetPostString("islate");
  9191. if (islate.Length > 0)
  9192. {
  9193. if (islate == "1")
  9194. lw.Add(string.Format("OutLate>0"));
  9195. else
  9196. lw.Add(string.Format("OutLate=0"));
  9197. }
  9198. string placedate1 = GetPostString("placedate1");
  9199. string placedate2 = GetPostString("placedate2");
  9200. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9201. if (dw.Length > 0) lw.Add(dw);
  9202. string deliveryDate1 = GetPostString("deliverydate1");
  9203. string deliveryDate2 = GetPostString("deliverydate2");
  9204. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9205. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9206. dStruct.Order = "ID desc";
  9207. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9208. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9209. writeGridDataTableJson(dStruct.TotalCount, dt);
  9210. }
  9211. public void ins_erp_placeregist()
  9212. {
  9213. if (UrlPostParmsCheck("id"))
  9214. {
  9215. string eid = GetPostString("id");
  9216. CeErpPlaceRegister entity = null;
  9217. if (eid == "0")//新增
  9218. {
  9219. entity = new CeErpPlaceRegister();
  9220. string xdTime = GetPostString("placeTime");
  9221. if (xdTime.Length > 0)
  9222. {
  9223. entity.PlactTime = Convert.ToDateTime(xdTime);
  9224. }
  9225. string fhTime = GetPostString("deliveryTime");
  9226. if (fhTime.Length > 0)
  9227. {
  9228. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9229. }
  9230. string preTime = GetPostString("preOutTime");
  9231. if (preTime.Length > 0)
  9232. {
  9233. entity.PreOutTime = Convert.ToDateTime(preTime);
  9234. }
  9235. entity.DeliveryCount = GetPostInt("deliveryCount");
  9236. entity.ReceiveCount = GetPostInt("receiveCount");
  9237. entity.OutSid = GetPostString("outSid");
  9238. entity.FileName = GetPostString("fileName");
  9239. entity.Memo = GetPostString("memo");
  9240. entity.AddUserId = CurrentUser.UserID;
  9241. entity.CreateTime = DateTime.Now;
  9242. entity.Img = GetPostString("img");
  9243. entity.Supplier = GetPostInt("supplier");
  9244. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9245. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9246. {
  9247. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9248. DateTime dt2 = (DateTime)entity.PreOutTime;
  9249. TimeSpan span = dt1.Subtract(dt2);
  9250. if (span.Days > 0)
  9251. {
  9252. entity.OutLate = span.Days;
  9253. }
  9254. }
  9255. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9256. entity.Create();
  9257. returnSuccessMsg("添加成功!");
  9258. return;
  9259. }
  9260. else //修改
  9261. {
  9262. entity = CeErpPlaceRegister.Get(eid);
  9263. if (entity != null)
  9264. {
  9265. string xdTime = GetPostString("placeTime");
  9266. if (xdTime.Length > 0)
  9267. {
  9268. entity.PlactTime = Convert.ToDateTime(xdTime);
  9269. }
  9270. string fhTime = GetPostString("deliveryTime");
  9271. if (fhTime.Length > 0)
  9272. {
  9273. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9274. }
  9275. string preTime = GetPostString("preOutTime");
  9276. if (preTime.Length > 0)
  9277. {
  9278. entity.PreOutTime = Convert.ToDateTime(preTime);
  9279. }
  9280. entity.DeliveryCount = GetPostInt("deliveryCount");
  9281. entity.ReceiveCount = GetPostInt("receiveCount");
  9282. if (entity.DeliveryCount == entity.ReceiveCount)
  9283. {
  9284. entity.CurState = "已完成";
  9285. }
  9286. else
  9287. {
  9288. entity.CurState = "未完成";
  9289. }
  9290. entity.OutSid = GetPostString("outSid");
  9291. entity.FileName = GetPostString("fileName");
  9292. entity.Memo = GetPostString("memo");
  9293. entity.Img = GetPostString("img");
  9294. entity.Supplier = GetPostInt("supplier");
  9295. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9296. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9297. {
  9298. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9299. DateTime dt2 = (DateTime)entity.PreOutTime;
  9300. TimeSpan span = dt1.Subtract(dt2);
  9301. if (span.Days > 0)
  9302. {
  9303. entity.OutLate = span.Days;
  9304. }
  9305. }
  9306. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9307. entity.Update();
  9308. returnSuccessMsg("修改成功");
  9309. return;
  9310. }
  9311. returnErrorMsg("找不到对应的记录");
  9312. return;
  9313. }
  9314. }
  9315. returnErrorMsg("缺少必要参数");
  9316. }
  9317. public void del_erp_placeregist()
  9318. {
  9319. string eid = GetPostString("id");
  9320. CeErpPlaceRegister.Del(eid);
  9321. returnSuccessMsg("删除成功!");
  9322. return;
  9323. }
  9324. public void ins_erp_placeregistbyorder()
  9325. {
  9326. string ctid = GetPostString("ctid");
  9327. if (ctid.Length > 0)
  9328. {
  9329. StringBuilder sql = new StringBuilder();
  9330. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9331. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9332. if (dt.Rows.Count > 0)
  9333. {
  9334. foreach (DataRow dr in dt.Rows)
  9335. {
  9336. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9337. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9338. entity.AddUserId = CurrentUser.UserID;
  9339. entity.tid = dr["tid"].ToString();
  9340. entity.Did = Convert.ToString(dr["ctid"]);
  9341. entity.splitTag = dr["SplitTag"].ToString();
  9342. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9343. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9344. if (pre_ctid.Length > 0)
  9345. {
  9346. sellmemo = sellmemo.Replace(pre_ctid, "");
  9347. }
  9348. sellmemo = sellmemo.Replace("[", "");
  9349. sellmemo = sellmemo.Replace("]", "");
  9350. entity.FileName = sellmemo;
  9351. string count = dr["ProductCount"].ToString();
  9352. int usecount = commonHelper.getIntCountFromString(count);
  9353. entity.DeliveryCount = usecount;
  9354. entity.CurState = "未完成";
  9355. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9356. {
  9357. entity.Supplier = 24;//dl手提袋定制
  9358. }
  9359. else
  9360. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9361. entity.CreateTime = DateTime.Now;
  9362. entity.Create();
  9363. }
  9364. returnSuccessMsg("操作成功");
  9365. return;
  9366. }
  9367. returnErrorMsg("没有找到对应订单");
  9368. return;
  9369. }
  9370. returnErrorMsg("缺少订单编号");
  9371. return;
  9372. }
  9373. public void get_erp_persuadelist()
  9374. {
  9375. DataStruct dStruct = GetPostStruct();
  9376. List<string> lw = new List<string>();
  9377. string ctid = GetPostString("ctid");
  9378. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9379. string shopname = GetPostString("shopname");
  9380. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9381. string buyernick = GetPostString("buyer_nick");
  9382. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9383. string customer = GetPostString("customer");
  9384. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9385. string returndate1 = GetPostString("returndate1");
  9386. string returndate2 = GetPostString("returndate2");
  9387. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9388. if (dw.Length > 0) lw.Add(dw);
  9389. string finishDate1 = GetPostString("finishdate1");
  9390. string finishDate2 = GetPostString("finishdate2");
  9391. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9392. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9393. string persuadetype = GetPostString("persuadetype");
  9394. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9395. string returnvstate = GetPostString("returnvstate");
  9396. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9397. dStruct.Order = "created desc";
  9398. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9399. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9400. writeGridDataTableJson(dStruct.TotalCount, dt);
  9401. }
  9402. public void upd_erp_returnpersuadeback()
  9403. {
  9404. if (UrlPostParmsCheck("ID"))
  9405. {
  9406. int eid = GetPostInt("ID");
  9407. CeErpPersuade entity = null;
  9408. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9409. if (entity != null)
  9410. {
  9411. entity.backreason = GetPostString("reason");
  9412. entity.pstate = 2;
  9413. entity.verifytime = DateTime.Now;
  9414. entity.verifyuserid = CurrentUser.UserID;
  9415. entity.Update();
  9416. returnSuccessMsg("退回成功!");
  9417. return;
  9418. }
  9419. returnErrorMsg("找不到订单记录");
  9420. }
  9421. }
  9422. public void upd_erp_returnpersuadeverify()
  9423. {
  9424. if (UrlPostParmsCheck("ID"))
  9425. {
  9426. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9427. {
  9428. returnErrorMsg("暂无权限审核");
  9429. return;
  9430. }
  9431. int eid = GetPostInt("ID");
  9432. CeErpPersuade entity = null;
  9433. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9434. if (entity != null)
  9435. {
  9436. entity.pstate = 1;
  9437. entity.verifytime = DateTime.Now;
  9438. entity.verifyuserid = CurrentUser.UserID;
  9439. entity.Update();
  9440. returnSuccessMsg("审核成功!");
  9441. return;
  9442. }
  9443. returnErrorMsg("找不到订单记录");
  9444. }
  9445. }
  9446. public void del_erp_persuade()
  9447. {
  9448. if (UrlPostParmsCheck("ID"))
  9449. {
  9450. int eid = GetPostInt("ID");
  9451. CeErpPersuade.Del(eid);
  9452. returnSuccessMsg("操作成功");
  9453. return;
  9454. }
  9455. }
  9456. public void get_erp_oldcustoupload()
  9457. {
  9458. DataStruct dStruct = GetPostStruct();
  9459. List<string> lw = new List<string>();
  9460. string buyernick = GetPostString("buyer_nick");
  9461. if (buyernick.Length > 0)
  9462. {
  9463. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9464. }
  9465. else
  9466. return;
  9467. dStruct.Order = "pay_time desc";
  9468. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9469. DataTable dt = null;
  9470. dt = WebCache.GetData("view_erptradecell", dStruct);
  9471. writeGridDataTableJson(dStruct.TotalCount, dt);
  9472. }
  9473. public void get_erp_checkorderlist()
  9474. {
  9475. DataStruct dStruct = GetPostStruct();
  9476. List<string> lw = new List<string>();
  9477. string tid = GetPostString("ctid");
  9478. if (tid.Length > 0)
  9479. {
  9480. string select_tid = getTidByCtid(tid);
  9481. lw.Add(string.Format("tid='{0}'", select_tid));
  9482. }
  9483. string shopname = GetPostString("shopname");
  9484. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9485. string buyernick = GetPostString("buyer_nick");
  9486. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9487. string customer = GetPostString("customer");
  9488. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9489. string design = GetPostString("design");
  9490. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9491. string orderState = GetPostString("orderState");
  9492. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9493. string address = GetPostString("address");
  9494. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9495. string sellermemo = GetPostString("seller_memo");
  9496. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9497. string supplier = GetPostString("supplier");
  9498. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9499. {
  9500. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9501. }
  9502. else
  9503. {
  9504. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9505. }
  9506. string date1 = GetPostString("date1");
  9507. string date2 = GetPostString("date2");
  9508. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9509. if (dw.Length > 0) lw.Add(dw);
  9510. string placedate1 = GetPostString("placedate1");
  9511. string placedate2 = GetPostString("placedate2");
  9512. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9513. if (fdw.Length > 0) lw.Add(fdw);
  9514. string price1 = GetPostString("price1");
  9515. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9516. string price2 = GetPostString("price2");
  9517. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9518. string checkst = GetPostString("checkstate");
  9519. if (checkst.Length > 0 && "10".Equals(checkst))
  9520. {
  9521. lw.Add(string.Format("CheckOut>0"));
  9522. }
  9523. else
  9524. {
  9525. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9526. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9527. }
  9528. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9529. {
  9530. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9531. }
  9532. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9533. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9534. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9535. writeGridDataTableJson(dStruct.TotalCount, dt);
  9536. }
  9537. public void ins_erp_startCheck()
  9538. {
  9539. if (UrlPostParmsCheck("ctid"))
  9540. {
  9541. string eid = GetPostString("ctid");
  9542. CeErpTradeCell entity = null;
  9543. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9544. if (entity != null)
  9545. {
  9546. entity.MemoOpt = 4;
  9547. entity.UpdateTime = DateTime.Now;
  9548. entity.Update();
  9549. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9550. CeErpSukuraData.createInfo(entity.ctid, 6);
  9551. returnSuccessMsg("操作成功!");
  9552. return;
  9553. }
  9554. returnErrorMsg("找不到记录");
  9555. }
  9556. }
  9557. public void upd_erp_sendXlw()
  9558. {
  9559. if (UrlPostParmsCheck("ctid"))
  9560. {
  9561. string eid = GetPostString("ctid");
  9562. CeErpTradeCell entity = null;
  9563. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9564. if (entity != null)
  9565. {
  9566. if (entity.IsSendGift == 1)
  9567. {
  9568. returnErrorMsg("请勿重复标记");
  9569. return;
  9570. }
  9571. entity.IsSendGift = 1;
  9572. entity.Update();
  9573. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9574. returnSuccessMsg("操作成功!");
  9575. return;
  9576. }
  9577. returnErrorMsg("找不到记录");
  9578. }
  9579. }
  9580. public void cancel_sendXlw()
  9581. {
  9582. if (UrlPostParmsCheck("ctid"))
  9583. {
  9584. string eid = GetPostString("ctid");
  9585. CeErpTradeCell entity = null;
  9586. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9587. if (entity != null)
  9588. {
  9589. if (entity.IsSendGift == 0)
  9590. {
  9591. returnErrorMsg("未标记小礼物");
  9592. return;
  9593. }
  9594. entity.IsSendGift = 0;
  9595. entity.Update();
  9596. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9597. returnSuccessMsg("操作成功!");
  9598. return;
  9599. }
  9600. returnErrorMsg("找不到记录");
  9601. }
  9602. }
  9603. public void get_erp_designbill()
  9604. {
  9605. DataStruct dStruct = GetPostStruct();
  9606. List<string> lw = new List<string>();
  9607. int isMy = GetInt("my");
  9608. if (isMy == 1)
  9609. {
  9610. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9611. }
  9612. string tid = GetPostString("tid");
  9613. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9614. string userName = GetPostString("design");
  9615. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9616. string price1 = GetPostString("price1");
  9617. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9618. string price2 = GetPostString("price2");
  9619. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9620. string rePrice1 = GetPostString("rePrice1");
  9621. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9622. string rePrice2 = GetPostString("rePrice2");
  9623. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9624. string designerType = GetPostString("designerType");
  9625. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9626. string orderState = GetPostString("orderState");
  9627. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9628. string endTime1 = GetPostString("endTime1");
  9629. string endTime2 = GetPostString("endTime2");
  9630. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9631. if (dw.Length > 0) lw.Add(dw);
  9632. string isDk = GetPostString("isDk");
  9633. if (isDk == "1")
  9634. {
  9635. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9636. }
  9637. else if (isDk == "0")
  9638. {
  9639. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9640. }
  9641. dStruct.Order = "oid, create_time desc";
  9642. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9643. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9644. writeGridDataTableJson(dStruct.TotalCount, dt);
  9645. }
  9646. public void upd_erp_designerbill()
  9647. {
  9648. if (UrlPostParmsCheck("ID"))
  9649. {
  9650. string eid = GetPostString("ID");
  9651. CeErpDesignerBill entity = null;
  9652. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9653. if (entity != null)
  9654. {
  9655. if (GetPostDouble("designerpirce") > 0)
  9656. {
  9657. entity.realPrice = GetPostDouble("designerpirce");
  9658. entity.update_time = DateTime.Now;
  9659. entity.update_u_id = CurrentUser.UserID;
  9660. entity.update_u_name = CurrentUser.UserName;
  9661. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9662. entity.Update();
  9663. returnSuccessMsg("操作成功!");
  9664. return;
  9665. }
  9666. else
  9667. {
  9668. entity.price = GetPostDouble("price");
  9669. entity.update_time = DateTime.Now;
  9670. entity.update_u_id = CurrentUser.UserID;
  9671. entity.update_u_name = CurrentUser.UserName;
  9672. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9673. entity.Update();
  9674. returnSuccessMsg("操作成功!");
  9675. return;
  9676. }
  9677. }
  9678. returnErrorMsg("找不到记录");
  9679. }
  9680. }
  9681. public void audit_erp_designerbill()
  9682. {
  9683. if (UrlPostParmsCheck("ID"))
  9684. {
  9685. string eid = GetPostString("ID");
  9686. CeErpDesignerBill entity = null;
  9687. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9688. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9689. if (entity != null)
  9690. {
  9691. entity.realPrice = GetPostDouble("designerpirce");
  9692. entity.update_time = DateTime.Now;
  9693. entity.update_u_id = CurrentUser.UserID;
  9694. entity.update_u_name = CurrentUser.UserName;
  9695. entity.isAudit = 1;
  9696. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9697. entity.Update();
  9698. if (orderEntity != null)
  9699. {
  9700. orderEntity.IsReadTag = 3;
  9701. orderEntity.Update();
  9702. }
  9703. returnSuccessMsg("操作成功!");
  9704. return;
  9705. }
  9706. returnErrorMsg("找不到记录");
  9707. }
  9708. }
  9709. public void all_audit_erp_designerbill()
  9710. {
  9711. if (UrlPostParmsCheck("idList"))
  9712. {
  9713. string[] list = GetPostString("idList").Split(',');
  9714. CeErpDesignerBill entity = null;
  9715. for (int i = 0; i < list.Length; i++)
  9716. {
  9717. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9718. if (entity == null) return;
  9719. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9720. if (orderEntity == null) return;
  9721. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9722. entity.update_time = DateTime.Now;
  9723. entity.update_u_id = CurrentUser.UserID;
  9724. entity.update_u_name = CurrentUser.UserName;
  9725. entity.isAudit = 1;
  9726. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9727. entity.Update();
  9728. orderEntity.IsReadTag = 3;
  9729. orderEntity.Update();
  9730. }
  9731. returnSuccessMsg("操作成功!");
  9732. return;
  9733. }
  9734. }
  9735. public void get_erp_sameorders()
  9736. {
  9737. if (UrlPostParmsCheck("ctid"))
  9738. {
  9739. string eid = GetPostString("ctid");
  9740. CeErpTradeCell entity = null;
  9741. entity = CeErpTradeCell.GetByCtid(eid);
  9742. if (entity != null)
  9743. {
  9744. StringBuilder sql = new StringBuilder();
  9745. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9746. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9747. var res = new
  9748. {
  9749. data = dt.Rows.Count
  9750. };
  9751. string ro_jsond = JsonConvert.SerializeObject(res);
  9752. returnSuccess(ro_jsond);
  9753. return;
  9754. }
  9755. returnErrorMsg("未找到订单");
  9756. return;
  9757. }
  9758. returnErrorMsg("缺少必要的参数");
  9759. }
  9760. public void get_erp_islasthavesameorder()
  9761. {
  9762. if (UrlPostParmsCheck("ctid"))
  9763. {
  9764. string eid = GetPostString("ctid");
  9765. string[] ctidList = eid.Split(',');
  9766. StringBuilder sql = new StringBuilder();
  9767. string tisCtid = "";
  9768. foreach (string ctid in ctidList)
  9769. {
  9770. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9771. if (entity != null)
  9772. {
  9773. sql = new StringBuilder();
  9774. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9775. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9776. if (dth.Rows.Count > 0)
  9777. {
  9778. tisCtid += entity.ctid;
  9779. tisCtid += ",";
  9780. }
  9781. }
  9782. }
  9783. if (tisCtid.Length > 0)
  9784. {
  9785. var res = new
  9786. {
  9787. data = tisCtid
  9788. };
  9789. string ro_jsond = JsonConvert.SerializeObject(res);
  9790. returnSuccess(ro_jsond);
  9791. }
  9792. else
  9793. {
  9794. var res = new
  9795. {
  9796. data = ""
  9797. };
  9798. string ro_jsond = JsonConvert.SerializeObject(res);
  9799. returnSuccess(ro_jsond);
  9800. }
  9801. return;
  9802. }
  9803. returnErrorMsg("缺少必要的参数");
  9804. }
  9805. public void file_client_down_url()
  9806. {
  9807. if (!UrlPostParmsCheck("userId"))
  9808. {
  9809. returnErrorMsg("缺少必要的参数");
  9810. }
  9811. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9812. }
  9813. public void checkout_form_data()
  9814. {
  9815. if (!UrlPostParmsCheck("tid"))
  9816. {
  9817. returnErrorMsg("缺少必要的参数");
  9818. }
  9819. string tid = GetPostString("tid");
  9820. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9821. if (ceErpOrderFormData != null)
  9822. {
  9823. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9824. returnSuccess(ro_jsond);
  9825. return;
  9826. }
  9827. returnErrorMsg("尚未有文件!");
  9828. }
  9829. public void back_supplier_audit()
  9830. {
  9831. int userId = CurrentUser.UserID;
  9832. StringBuilder sql = new StringBuilder();
  9833. 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);
  9834. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9835. if (dt.Rows.Count > 0)
  9836. {
  9837. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9838. }
  9839. else
  9840. {
  9841. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9842. }
  9843. }
  9844. public void back_supplier_query()
  9845. {
  9846. string eid = GetPostString("ctid");
  9847. if (eid != "")
  9848. {
  9849. StringBuilder sql = new StringBuilder();
  9850. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9851. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9852. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9853. }
  9854. else
  9855. {
  9856. returnErrorMsg("找不到订单记录");
  9857. return;
  9858. }
  9859. }
  9860. public void verified_to_order()
  9861. {
  9862. int userId = CurrentUser.UserID;
  9863. StringBuilder sql = new StringBuilder();
  9864. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9865. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9866. if (dt.Rows.Count > 0)
  9867. {
  9868. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9869. }
  9870. else
  9871. {
  9872. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9873. }
  9874. }
  9875. public void upd_supplier_audit()
  9876. {
  9877. if (UrlPostParmsCheck("ctid"))
  9878. {
  9879. string eid = GetPostString("ctid");
  9880. string reason = GetPostString("returnreason");
  9881. CeErpTradeCell entity = null;
  9882. CeWithdraw withdraw = null;
  9883. withdraw = CeWithdraw.GetByTid(eid);
  9884. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9885. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9886. {
  9887. if (withdraw != null)
  9888. {
  9889. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9890. {
  9891. returnSuccessMsg("您没有权限操作!");
  9892. return;
  9893. }
  9894. else
  9895. {
  9896. if (reason.Equals("1"))
  9897. {
  9898. if (entity.OrderState == -1)
  9899. {
  9900. if (entity.FinishPlaceTime == null)
  9901. {
  9902. entity.OrderState = 2;
  9903. }
  9904. else
  9905. {
  9906. entity.OrderState = 6;
  9907. }
  9908. }
  9909. entity.Update();
  9910. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9911. if (withdraw != null)
  9912. {
  9913. withdraw.status = int.Parse(reason);
  9914. withdraw.Update();
  9915. }
  9916. returnSuccessMsg("操作成功!");
  9917. return;
  9918. }
  9919. else
  9920. {
  9921. withdraw.status = int.Parse(reason);
  9922. withdraw.acknowledgingtime = DateTime.Now;
  9923. withdraw.Update();
  9924. returnSuccessMsg("查看详细请点击线下订单查询");
  9925. return;
  9926. }
  9927. }
  9928. }
  9929. // 第一个字符是 'N'
  9930. }
  9931. if (eid[0] != 'N')
  9932. {
  9933. }
  9934. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9935. {
  9936. entity.IsVerifyToSupplier = false;
  9937. entity.IsReturn = 1;
  9938. entity.ReturnTime = DateTime.Now;
  9939. entity.ReturnReason = reason;
  9940. if (entity.OrderState == 6)
  9941. {
  9942. entity.OrderState = 5;
  9943. }
  9944. entity.Update();
  9945. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9946. if (withdraw != null)
  9947. {
  9948. withdraw.status = int.Parse(reason);
  9949. withdraw.Update();
  9950. }
  9951. returnSuccessMsg("操作成功!");
  9952. return;
  9953. }
  9954. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9955. {
  9956. ;
  9957. if (withdraw != null)
  9958. {
  9959. withdraw.status = int.Parse(reason);
  9960. withdraw.acknowledgingtime = DateTime.Now;
  9961. withdraw.Update();
  9962. returnSuccessMsg("供应商取消撤回!");
  9963. return;
  9964. }
  9965. }
  9966. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9967. {
  9968. if (entity.OrderState == -1)
  9969. {
  9970. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  9971. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9972. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  9973. {
  9974. returnErrorMsg("台湾客户需填写身份证!");
  9975. return;
  9976. }
  9977. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9978. {
  9979. returnErrorMsg("订单spu没有确认无法通过审核!");
  9980. return;
  9981. }
  9982. if (entity.FinishPlaceTime == null)
  9983. {
  9984. entity.OrderState = 2;
  9985. }
  9986. else
  9987. {
  9988. entity.OrderState = 3;
  9989. }
  9990. commonHelper.getCytPrice(entity);
  9991. }
  9992. entity.Update();
  9993. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9994. if (withdraw != null)
  9995. {
  9996. withdraw.status = int.Parse(reason);
  9997. withdraw.Update();
  9998. }
  9999. returnSuccessMsg("操作成功!");
  10000. return;
  10001. }
  10002. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10003. {
  10004. if (withdraw == null)
  10005. {
  10006. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10007. return;
  10008. }
  10009. }
  10010. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10011. {
  10012. if (withdraw != null)
  10013. {
  10014. withdraw.status = int.Parse(reason);
  10015. withdraw.acknowledgingtime = DateTime.Now;
  10016. withdraw.Update();
  10017. returnSuccessMsg("查看详细请点击线下订单查询");
  10018. return;
  10019. }
  10020. }
  10021. return;
  10022. }
  10023. }
  10024. //校验报价
  10025. public void refund_order_tip()
  10026. {
  10027. int userid = CurrentUser.UserID;
  10028. int sectionId = CurrentUser.UserPost.OrgID;
  10029. StringBuilder sql = new StringBuilder();
  10030. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10031. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10032. List<string> ids = new List<string>();
  10033. if (dth.Rows.Count > 0)
  10034. {
  10035. foreach (DataRow dr in dth.Rows)
  10036. {
  10037. ids.Add(dr["ID"].ToString());
  10038. }
  10039. try
  10040. {
  10041. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10042. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10043. }
  10044. catch (Exception ex)
  10045. {
  10046. }
  10047. }
  10048. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10049. }
  10050. public void refund_order_Design()
  10051. {
  10052. int userid = CurrentUser.UserID;
  10053. int sectionId = CurrentUser.UserPost.OrgID;
  10054. StringBuilder sql = new StringBuilder();
  10055. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10056. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10057. List<string> ids = new List<string>();
  10058. if (dth.Rows.Count > 0)
  10059. {
  10060. foreach (DataRow dr in dth.Rows)
  10061. {
  10062. ids.Add(dr["ID"].ToString());
  10063. }
  10064. try
  10065. {
  10066. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10067. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10068. }
  10069. catch (Exception ex)
  10070. {
  10071. }
  10072. }
  10073. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10074. }
  10075. public void change_order_info()
  10076. {
  10077. int userid = CurrentUser.UserID;
  10078. StringBuilder sql = new StringBuilder();
  10079. 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);
  10080. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10081. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10082. }
  10083. public void change_win_mome()
  10084. {
  10085. if (UrlPostParmsCheck("id,ctid"))
  10086. {
  10087. string id = GetPostString("id");
  10088. string ctid = GetPostString("ctid");
  10089. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10090. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10091. if (ce == null || ceErpMessageTip == null)
  10092. {
  10093. returnSuccessMsg("未找到对应的订单!");
  10094. return;
  10095. }
  10096. if (ce.OrderState >= 5)
  10097. {
  10098. ceErpMessageTip.isVisit = true;
  10099. ceErpMessageTip.Update();
  10100. returnSuccessMsg("已上传文件无法修改!");
  10101. return;
  10102. }
  10103. int type = GetPostInt("type");
  10104. string content = GetPostString("content");
  10105. if (type == 0)
  10106. {
  10107. content = content.Replace("(", "(");
  10108. content = content.Replace(")", ")");
  10109. string check = MidStrEx(content, "(", ")").Trim();
  10110. if (string.IsNullOrEmpty(check))
  10111. {
  10112. returnSuccessMsg("文件名格式不正确");
  10113. return;
  10114. }
  10115. }
  10116. ce.seller_memo = content;
  10117. ce.Update();
  10118. ceErpMessageTip.isVisit = true;
  10119. ceErpMessageTip.Update();
  10120. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10121. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10122. ApiVo apiVo = new ApiVo();
  10123. apiVo.orderNumber = ce.ctid;
  10124. apiVo.actionName = "demandDesign";
  10125. apiVo.orderRemarks = content;
  10126. apiVo.demandExamine = type + 1;
  10127. designHelper.API_WorkCore(apiVo);//demandDesign
  10128. returnSuccessMsg("修改成功!");
  10129. }
  10130. }
  10131. public static string MidStrEx(string sourse, string startstr, string endstr)
  10132. {
  10133. string result = string.Empty;
  10134. int startindex, endindex;
  10135. try
  10136. {
  10137. startindex = sourse.IndexOf(startstr);
  10138. if (startindex == -1)
  10139. return result;
  10140. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10141. endindex = tmpstr.IndexOf(endstr);
  10142. if (endindex == -1)
  10143. return result;
  10144. result = tmpstr.Remove(endindex);
  10145. }
  10146. catch (Exception ex)
  10147. {
  10148. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10149. }
  10150. return result;
  10151. }
  10152. public void refund_order_list()
  10153. {
  10154. int userid = CurrentUser.UserID;
  10155. int sectionId = CurrentUser.UserPost.OrgID;
  10156. StringBuilder sql = new StringBuilder();
  10157. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10158. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10159. DataStruct dStruct = GetPostStruct();
  10160. DataTable dt = null;
  10161. List<string> ids = new List<string>();
  10162. List<string> tids = new List<string>();
  10163. if (dth.Rows.Count > 0)
  10164. {
  10165. foreach (DataRow dr in dth.Rows)
  10166. {
  10167. tids.Add("'" + dr["tid"].ToString() + "'");
  10168. ids.Add(dr["id"].ToString());
  10169. }
  10170. try
  10171. {
  10172. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10173. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10174. List<string> lw = new List<string>();
  10175. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10176. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10177. dt = WebCache.GetData("view_orderlist", dStruct);
  10178. }
  10179. catch (Exception ex)
  10180. {
  10181. }
  10182. }
  10183. writeGridDataTableJson(dStruct.TotalCount, dt);
  10184. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10185. }
  10186. //新增
  10187. public void order_batch_downloads()
  10188. {
  10189. string ceid = GetPostString("tid");
  10190. String[] tid = ceid.Split(',');
  10191. order_batch_caiyingtong(tid);
  10192. /* (string success, string errors) = UploadFiles(tid);
  10193. returnSuccessMsg(success + errors);*/
  10194. return;
  10195. }
  10196. //报价接口
  10197. public void Get_To_Quote()
  10198. {
  10199. string ceid = GetPostString("ctid");
  10200. if (ceid != null)
  10201. {
  10202. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10203. if (entity != null)
  10204. {
  10205. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10206. {
  10207. return;
  10208. }
  10209. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10210. double price = 0;
  10211. if (cp == null)
  10212. {
  10213. JObject jsonObject12 = new JObject
  10214. {
  10215. { "UserId", "77886" },
  10216. { "Pwd", "lt666888" },
  10217. { "Filename", entity.seller_memo }
  10218. };
  10219. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10220. JObject jsonObjects1 = JObject.Parse(response1);
  10221. string ms1g = (string)jsonObjects1["msg"];
  10222. if (ms1g == "报价成功")
  10223. {
  10224. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10225. string data = (string)jsonObject1["price"];
  10226. 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 + "');";
  10227. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10228. returnSuccessMsg("获取报价成功:" + data);
  10229. price = Convert.ToDouble(data);
  10230. }
  10231. else
  10232. {
  10233. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10234. return;
  10235. }
  10236. }
  10237. String[] beizhu = entity.seller_memo.Split('-');
  10238. String chanp = "";
  10239. if (beizhu.Length > 0)
  10240. {
  10241. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10242. }
  10243. else
  10244. {
  10245. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10246. }
  10247. JObject jsonObject = new JObject
  10248. {
  10249. { "UserId", "77886" },
  10250. { "Pwd", "lt666888" },
  10251. { "Filename", chanp }
  10252. };
  10253. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10254. JObject jsonObjects = JObject.Parse(response);
  10255. string msg = (string)jsonObjects["msg"];
  10256. if (msg == "报价成功")
  10257. {
  10258. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10259. string data = (string)jsonObject1["price"];
  10260. 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 + "');";
  10261. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10262. returnSuccessMsg("获取报价成功:" + data);
  10263. price = Convert.ToDouble(data);
  10264. }
  10265. else
  10266. {
  10267. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10268. return;
  10269. }
  10270. if (price > 0)
  10271. {
  10272. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10273. if (ceErpTradeCellExtend == null)
  10274. {
  10275. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10276. ceErpTradeCellExtend.ctid = entity.ctid;
  10277. ceErpTradeCellExtend.payment_cyt = price;
  10278. ceErpTradeCellExtend.Create();
  10279. }
  10280. else
  10281. {
  10282. ceErpTradeCellExtend.payment_cyt = price;
  10283. ceErpTradeCellExtend.Update();
  10284. }
  10285. }
  10286. return;
  10287. }
  10288. }
  10289. else
  10290. {
  10291. returnErrorMsg("请至少选择一条数据");
  10292. return;
  10293. }
  10294. }
  10295. //新增
  10296. public void order_To_Supplier()
  10297. {
  10298. string ceid = GetPostString("tid");
  10299. String[] tid = ceid.Split(',');
  10300. if (tid.Length > 0)
  10301. {
  10302. try
  10303. {
  10304. for (int i = 0; i < tid.Length; i++)
  10305. {
  10306. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10307. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10308. entity.SupplierId = suid;
  10309. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10310. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10311. entity.Update();
  10312. }
  10313. }
  10314. catch (Exception ex)
  10315. {
  10316. returnErrorMsg("自动匹配供应商失败");
  10317. return;
  10318. }
  10319. }
  10320. else
  10321. {
  10322. returnErrorMsg("请至少选择一条数据");
  10323. return;
  10324. }
  10325. returnSuccessMsg("自动匹配供应商成功");
  10326. return;
  10327. }
  10328. public (string, string) UploadFiles(string[] urls)
  10329. {
  10330. string success = "";
  10331. string errors = "";
  10332. int userid = CurrentUser.UserID;
  10333. foreach (string url in urls)
  10334. {
  10335. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10336. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10337. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10338. {
  10339. JObject jsonObject = new JObject
  10340. {
  10341. { "Userid", "77886" },
  10342. { "pwd", "cyt86435015" },
  10343. { "content", base64FileContent },
  10344. { "ext", Path.GetExtension(fileName) }
  10345. };
  10346. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10347. JObject jsonObjects = JObject.Parse(response);
  10348. string msg = (string)jsonObjects["msg"];
  10349. if (msg.Equals("上传成功"))
  10350. {
  10351. success += url + " 上传成功";
  10352. }
  10353. else
  10354. {
  10355. errors += url + " 上传失败";
  10356. }
  10357. }
  10358. else
  10359. {
  10360. errors += url + " 格式出现问题";
  10361. }
  10362. }
  10363. if (urls.Length == 0)
  10364. {
  10365. return (success, errors);
  10366. }
  10367. return (success, errors);
  10368. }
  10369. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10370. {
  10371. return true; //总是接受
  10372. }
  10373. public static string HttpPost(string url, string param = null)
  10374. {
  10375. HttpWebRequest request;
  10376. //如果是发送HTTPS请求
  10377. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10378. {
  10379. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10380. request = WebRequest.Create(url) as HttpWebRequest;
  10381. request.ProtocolVersion = HttpVersion.Version10;
  10382. }
  10383. else
  10384. {
  10385. request = WebRequest.Create(url) as HttpWebRequest;
  10386. }
  10387. request.Method = "POST";
  10388. request.ContentType = "application/json";
  10389. request.Accept = "*/*";
  10390. request.Timeout = 120000;
  10391. request.AllowAutoRedirect = false;
  10392. StreamWriter requestStream = null;
  10393. WebResponse response = null;
  10394. string responseStr = null;
  10395. try
  10396. {
  10397. requestStream = new StreamWriter(request.GetRequestStream());
  10398. requestStream.Write(param);
  10399. requestStream.Close();
  10400. response = request.GetResponse();
  10401. if (response != null)
  10402. {
  10403. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10404. responseStr = reader.ReadToEnd();
  10405. reader.Close();
  10406. }
  10407. }
  10408. catch (Exception ex)
  10409. {
  10410. return ex.Message;
  10411. }
  10412. finally
  10413. {
  10414. request = null;
  10415. requestStream = null;
  10416. response = null;
  10417. }
  10418. return responseStr;
  10419. }
  10420. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10421. {
  10422. string base64FileContent;
  10423. string fileName;
  10424. using (WebClient webClient = new WebClient())
  10425. {
  10426. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10427. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10428. {
  10429. using (Stream stream = response.GetResponseStream())
  10430. {
  10431. using (MemoryStream memoryStream = new MemoryStream())
  10432. {
  10433. stream.CopyTo(memoryStream);
  10434. byte[] fileBytes = memoryStream.ToArray();
  10435. base64FileContent = Convert.ToBase64String(fileBytes);
  10436. fileName = response.Headers["Content-Disposition"];
  10437. if (!string.IsNullOrEmpty(fileName))
  10438. {
  10439. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10440. if (index >= 0)
  10441. {
  10442. fileName = fileName.Substring(index + 9).Trim('\"');
  10443. }
  10444. }
  10445. else
  10446. {
  10447. fileName = Path.GetFileName(downloadUrl);
  10448. }
  10449. }
  10450. }
  10451. }
  10452. }
  10453. return (fileName, base64FileContent);
  10454. }
  10455. //新增
  10456. public void order_batch_caiyingtong(string[] downloadUrls)
  10457. {
  10458. try
  10459. {
  10460. //遍历文件
  10461. DataStruct dStruct = GetPostStruct();
  10462. DataTable dt = null;
  10463. int userid = CurrentUser.UserID;
  10464. List<string> ids = new List<string>();//失败组
  10465. List<string> tids = new List<string>();
  10466. using (WebClient webClient = new WebClient())
  10467. {
  10468. foreach (var url in downloadUrls)
  10469. {
  10470. try
  10471. {
  10472. tids.Add("'" + url + "'");
  10473. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10474. if (entity != null)
  10475. {
  10476. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10477. if (cp == null)
  10478. {
  10479. JObject jsonObject = new JObject
  10480. {
  10481. { "Userid", "77886" },
  10482. { "pwd", "lt666888" },
  10483. { "Filename",entity.seller_memo }
  10484. };
  10485. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10486. JObject jsonObjects = JObject.Parse(response);
  10487. string msg = (string)jsonObjects["msg"];
  10488. if (msg == "报价成功")
  10489. {
  10490. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10491. DownloadAndConvertToBase64(url1);
  10492. }
  10493. else
  10494. {
  10495. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10496. }
  10497. }
  10498. else
  10499. {
  10500. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10501. JObject jsonObject = new JObject
  10502. {
  10503. { "Userid", "77886" },
  10504. { "pwd", "lt666888" },
  10505. { "Filename",chanp }
  10506. };
  10507. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10508. JObject jsonObjects = JObject.Parse(response);
  10509. string msg = (string)jsonObjects["msg"];
  10510. if (msg == "报价成功")
  10511. {
  10512. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10513. DownloadAndConvertToBase64(url1);
  10514. }
  10515. else
  10516. {
  10517. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10518. }
  10519. }
  10520. }
  10521. // 上传文件到FTP
  10522. }
  10523. catch (Exception ex)
  10524. {
  10525. Console.WriteLine($"An error occurred: {ex.Message}");
  10526. }
  10527. }
  10528. List<string> lw = new List<string>();
  10529. lw.Add(string.Format("( OrderState < 6 )"));
  10530. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10531. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10532. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10533. if (dt.Rows.Count > 0)
  10534. {
  10535. foreach (DataRow dr in dt.Rows)
  10536. {
  10537. ids.Add(dr["ctid"].ToString());
  10538. }
  10539. }
  10540. String ErrorMsgs = "";
  10541. foreach (String id in ids)
  10542. {
  10543. ErrorMsgs += id + ",";
  10544. }
  10545. if (ErrorMsgs.Length > 1)
  10546. {
  10547. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10548. }
  10549. if (ErrorMsgs.Length < 1)
  10550. {
  10551. ErrorMsgs = "上传成功";
  10552. returnSuccessMsg(ErrorMsgs);
  10553. }
  10554. else
  10555. {
  10556. returnErrorMsg("以下订单" + ErrorMsgs);
  10557. }
  10558. }
  10559. // 删除文件夹及其内容
  10560. /* Directory.Delete(localDirectory, true);*/
  10561. }
  10562. catch { }
  10563. }
  10564. public void get_center_data()
  10565. {
  10566. int userId = CurrentUser.UserID;
  10567. string postCode = CurrentUser.UserPost.Post.Code;
  10568. List<string> lw = new List<string>();
  10569. List<string> ww = new List<string>();
  10570. DateTime currentTime = DateTime.Now;
  10571. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10572. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10573. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10574. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10575. string sql = " SELECT ";
  10576. string startTime = "2023-10-01 11:22:31";
  10577. //设计
  10578. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10579. {
  10580. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10581. 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));
  10582. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10583. 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));
  10584. }
  10585. //客服
  10586. else if (postCode == "CustomerService" || postCode == "Director")
  10587. {
  10588. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10589. 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));
  10590. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10591. 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));
  10592. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10593. 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));
  10594. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10595. 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));
  10596. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10597. 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));
  10598. }
  10599. //售后
  10600. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10601. {
  10602. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10603. 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));
  10604. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10605. 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));
  10606. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10607. 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));
  10608. }
  10609. //下单部
  10610. else if (postCode == "Place" || postCode == "PlaceMr")
  10611. {
  10612. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10613. 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));
  10614. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10615. 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));
  10616. }
  10617. //车间
  10618. else if (postCode == "Supplier")
  10619. {
  10620. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10621. 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));
  10622. }
  10623. DataTable dt = new DataTable();
  10624. if (lw.Count > 0)
  10625. {
  10626. sql += string.Join(" , ", lw);
  10627. sql += " FROM ";
  10628. sql += string.Join(" , ", ww);
  10629. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10630. }
  10631. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10632. }
  10633. public void get_center_data_list()
  10634. {
  10635. int userId = CurrentUser.UserID;
  10636. string postCode = CurrentUser.UserPost.Post.Code;
  10637. string shopIds = CurrentUser.User.pemShop;
  10638. DataStruct dStruct = GetPostStruct();
  10639. List<string> lw = new List<string>();
  10640. DateTime currentTime = DateTime.Now;
  10641. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10642. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10643. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10644. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10645. string startTime = "2023-10-01 11:22:31";
  10646. int order_type = GetPostInt("order_type");
  10647. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10648. {
  10649. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10650. if (order_type == 0)
  10651. {
  10652. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10653. }
  10654. else if (order_type == 3)
  10655. {
  10656. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10657. }
  10658. else
  10659. {
  10660. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10661. }
  10662. }
  10663. //客服
  10664. if (postCode == "CustomerService" || postCode == "Director")
  10665. {
  10666. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10667. if (order_type == 0)
  10668. {
  10669. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10670. }
  10671. else if (order_type == 1)
  10672. {
  10673. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10674. }
  10675. else if (order_type == 2)
  10676. {
  10677. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10678. }
  10679. else if (order_type == 3)
  10680. {
  10681. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10682. }
  10683. else if (order_type == 4)
  10684. {
  10685. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10686. }
  10687. else
  10688. {
  10689. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10690. }
  10691. }
  10692. //售后
  10693. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10694. {
  10695. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10696. if (shopIds != "")
  10697. {
  10698. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10699. }
  10700. if (order_type == 2)
  10701. {
  10702. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10703. }
  10704. else if (order_type == 4)
  10705. {
  10706. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10707. }
  10708. else if (order_type == 5)
  10709. {
  10710. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10711. }
  10712. else
  10713. {
  10714. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10715. }
  10716. }
  10717. //下单部
  10718. if (postCode == "Place" || postCode == "PlaceMr")
  10719. {
  10720. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10721. if (shopIds != "")
  10722. {
  10723. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10724. }
  10725. else if (order_type == 1)
  10726. {
  10727. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10728. }
  10729. else if (order_type == 2)
  10730. {
  10731. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10732. }
  10733. else
  10734. {
  10735. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10736. }
  10737. }
  10738. //车间
  10739. if (postCode == "Supplier")
  10740. {
  10741. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10742. if (order_type == 5)
  10743. {
  10744. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10745. }
  10746. else
  10747. {
  10748. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10749. }
  10750. }
  10751. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10752. dStruct.Fileds = "tid,ctid";
  10753. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10754. writeGridDataTableJson(dStruct.TotalCount, dt);
  10755. }
  10756. public void aftersale_audit_master()
  10757. {
  10758. if (UrlPostParmsCheck("ctid"))
  10759. {
  10760. string ctid = GetPostString("ctid");
  10761. if (ctid.Length > 0)
  10762. {
  10763. bool result = aftersale_data_change(ctid);
  10764. if (result)
  10765. {
  10766. returnSuccessMsg("修改成功!");
  10767. return;
  10768. }
  10769. }
  10770. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10771. }
  10772. }
  10773. public void aftersale_batch_audit_master()
  10774. {
  10775. if (UrlPostParmsCheck("ctids"))
  10776. {
  10777. string ctids = GetPostString("ctids");
  10778. if (ctids.Length > 0)
  10779. {
  10780. List<string> list = new List<string>();
  10781. string[] ctid_list = ctids.Split(',');
  10782. foreach (var item in ctid_list)
  10783. {
  10784. bool result = aftersale_data_change(item);
  10785. if (!result)
  10786. {
  10787. list.Add(item);
  10788. }
  10789. }
  10790. if (list.Count > 0)
  10791. {
  10792. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10793. return;
  10794. }
  10795. returnSuccessMsg("修改成功!");
  10796. return;
  10797. }
  10798. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10799. }
  10800. }
  10801. public bool aftersale_data_change(string ctid)
  10802. {
  10803. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10804. if (ceErpTradeCell != null)
  10805. {
  10806. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10807. ceErpTradeCell.AfterSaleSupplierState = 0;
  10808. StringBuilder sql = new StringBuilder();
  10809. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10810. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10811. CeErpTradeResponsible.DelByTid(ctid, 0);
  10812. 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 == "不理赔")
  10813. {
  10814. CeErpTradeResponsible.DelByTid(ctid, 1);
  10815. ceErpTradeCell.AfterSaleSupplierState = 1;
  10816. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10817. ceErpTradeCell.AfterSaleState = 4;
  10818. }
  10819. else
  10820. {
  10821. ceErpTradeCell.AfterSaleState = 3;
  10822. }
  10823. bool needCyt = false;
  10824. if (dt != null)
  10825. {
  10826. if (dt.Rows.Count == 1)
  10827. {
  10828. bool isEnd = false;
  10829. foreach (DataRow dr in dt.Rows)
  10830. {
  10831. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10832. {
  10833. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10834. isEnd = true;
  10835. }
  10836. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10837. {
  10838. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10839. isEnd = true;
  10840. }
  10841. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10842. {
  10843. needCyt = true;
  10844. }
  10845. }
  10846. if (isEnd)
  10847. {
  10848. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10849. ceErpTradeCell.AfterSaleState = 4;
  10850. ceErpTradeCell.AfterSaleSupplierState = 1;
  10851. }
  10852. }
  10853. else
  10854. {
  10855. bool isAll = true;
  10856. foreach (DataRow dr in dt.Rows)
  10857. {
  10858. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10859. {
  10860. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10861. continue;
  10862. }
  10863. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10864. {
  10865. string path = "";
  10866. int OrgID = 0;
  10867. if (!Convert.IsDBNull(dr["OrgPath"]))
  10868. {
  10869. path = dr["OrgPath"].ToString();
  10870. }
  10871. if (!Convert.IsDBNull(dr["OrgID"]))
  10872. {
  10873. OrgID = Convert.ToInt32(dr["OrgID"]);
  10874. }
  10875. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10876. {
  10877. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10878. continue;
  10879. }
  10880. }
  10881. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10882. {
  10883. needCyt = true;
  10884. }
  10885. isAll = false;
  10886. }
  10887. if (isAll)
  10888. {
  10889. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10890. ceErpTradeCell.AfterSaleState = 4;
  10891. ceErpTradeCell.AfterSaleSupplierState = 1;
  10892. }
  10893. }
  10894. }
  10895. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10896. {
  10897. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10898. }
  10899. if (ceErpTradeCell.AfterSaleState == 4)
  10900. {
  10901. ApiVo apiVo = new ApiVo();
  10902. apiVo.orderNumber = ceErpTradeCell.ctid;
  10903. apiVo.actionName = "afterOver";
  10904. designHelper.API_WorkCore(apiVo); //afterOver
  10905. }
  10906. ceErpTradeCell.Update();
  10907. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10908. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10909. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10910. return true;
  10911. }
  10912. return false;
  10913. }
  10914. public void get_erp_wechatorder()
  10915. {
  10916. DataStruct dStruct = GetPostStruct();
  10917. List<string> lw = new List<string>();
  10918. string tid = GetPostString("tid");
  10919. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10920. string shopname = GetPostString("shopname");
  10921. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10922. string buyernick = GetPostString("buyer_nick");
  10923. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10924. string customer = GetPostString("customer");
  10925. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10926. string returndate1 = GetPostString("returndate1");
  10927. string returndate2 = GetPostString("returndate2");
  10928. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10929. if (dw.Length > 0) lw.Add(dw);
  10930. string finishDate1 = GetPostString("finishdate1");
  10931. string finishDate2 = GetPostString("finishdate2");
  10932. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10933. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10934. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10935. dStruct.Order = "created desc";
  10936. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10937. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10938. writeGridDataTableJson(dStruct.TotalCount, dt);
  10939. }
  10940. public void get_erp_wechatlist_sumprice()
  10941. {
  10942. DataStruct dStruct = GetPostStruct();
  10943. List<string> lw = new List<string>();
  10944. string tid = GetPostString("tid");
  10945. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10946. string shopname = GetPostString("shopname");
  10947. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10948. string buyernick = GetPostString("buyer_nick");
  10949. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10950. string customer = GetPostString("customer");
  10951. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10952. string returndate1 = GetPostString("returndate1");
  10953. string returndate2 = GetPostString("returndate2");
  10954. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10955. if (dw.Length > 0) lw.Add(dw);
  10956. string finishDate1 = GetPostString("finishdate1");
  10957. string finishDate2 = GetPostString("finishdate2");
  10958. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10959. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10960. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10961. string mainWhere = string.Join(" and ", lw.ToArray());
  10962. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10963. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10964. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10965. decimal total = 0;
  10966. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10967. {
  10968. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10969. }
  10970. var res = new
  10971. {
  10972. data = total
  10973. };
  10974. string ro_jsond = JsonConvert.SerializeObject(res);
  10975. returnSuccess(ro_jsond);
  10976. return;
  10977. }
  10978. public void get_erp_qr_waitdeliverylist()
  10979. {
  10980. DataStruct dStruct = GetPostStruct();
  10981. List<string> lw = new List<string>();
  10982. string tid = GetPostString("ctid");
  10983. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10984. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10985. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10986. var res_objz = new
  10987. {
  10988. restype = 1,
  10989. data = dt
  10990. };
  10991. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10992. returnSuccess(ro_jsonz);
  10993. }
  10994. public void get_erp_yield_list()
  10995. {
  10996. DataStruct dStruct = GetPostStruct();
  10997. List<string> lw = new List<string>();
  10998. string tid = GetPostString("ctid");
  10999. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11000. string shopname = GetPostString("shopname");
  11001. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11002. string buyernick = GetPostString("buyer_nick");
  11003. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11004. //if (tid.Length == 0 && buyernick.Length == 0)
  11005. //{
  11006. // lw.Add(string.Format("IsRefund<={0}", 1));
  11007. //}
  11008. string customer = GetPostString("customer");
  11009. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11010. string design = GetPostString("design");
  11011. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11012. string orderState = GetPostString("orderState");
  11013. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11014. string address = GetPostString("address");
  11015. 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));
  11016. string sellermemo = GetPostString("seller_memo");
  11017. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11018. string supplier = GetPostString("supplier");
  11019. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11020. string OrderArea = GetPostString("order_area");
  11021. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11022. string placedate1 = GetPostString("placedate1");
  11023. string placedate2 = GetPostString("placedate2");
  11024. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11025. if (fdw.Length > 0) lw.Add(fdw);
  11026. string price1 = GetPostString("price1");
  11027. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11028. string price2 = GetPostString("price2");
  11029. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11030. string unusualCon = GetPostString("unusualcon");
  11031. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11032. string posTag = CurrentUser.UserPost.Post.Code;
  11033. if (posTag == "Supplier")
  11034. {
  11035. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11036. }
  11037. lw.Add(string.Format("OrderState = 6 "));
  11038. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11039. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11040. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11041. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11042. writeGridDataTableJson(dStruct.TotalCount, dt);
  11043. }
  11044. public void change_erp_sup_state()
  11045. {
  11046. if (UrlPostParmsCheck("ctid"))
  11047. {
  11048. string ctid = GetPostString("ctid");
  11049. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11050. if (ceErpTradeCell != null)
  11051. {
  11052. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11053. if (ceErpTradeCellExtend == null)
  11054. {
  11055. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11056. ceErpTradeCellExtend.ctid = ctid;
  11057. ceErpTradeCellExtend.SupState = 1;
  11058. ceErpTradeCellExtend.Create();
  11059. }
  11060. else
  11061. {
  11062. ceErpTradeCellExtend.SupState = 1;
  11063. ceErpTradeCellExtend.Update();
  11064. }
  11065. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11066. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11067. return;
  11068. }
  11069. returnErrorMsg("找不到订单");
  11070. }
  11071. }
  11072. public void supplier_all_downs()
  11073. {
  11074. if (UrlPostParmsCheck("tids"))
  11075. {
  11076. string tids = GetPostString("tids");
  11077. if (tids != null && tids.Length > 0)
  11078. {
  11079. StringBuilder sql = new StringBuilder();
  11080. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11081. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11082. sql = new StringBuilder();
  11083. 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, "下载设计文件");
  11084. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11085. string[] list = tids.Split(',');
  11086. foreach (string ctid in list)
  11087. {
  11088. CeErpSukuraData.createInfo(ctid, 3);
  11089. }
  11090. designHelper.api_approveDesign(tids); //approveDesign
  11091. returnSuccessMsg("下载成功!");
  11092. return;
  11093. }
  11094. returnErrorMsg("下载订单更新失败");
  11095. }
  11096. }
  11097. public void uploaderFileSuccess()
  11098. {
  11099. if (UrlPostParmsCheck("fileName"))
  11100. {
  11101. string fileName = GetPostString("fileName");
  11102. ApiVo apiVo = new ApiVo();
  11103. apiVo.orderNumber = fileName;
  11104. apiVo.actionName = "finishDesign";
  11105. designHelper.API_WorkCore(apiVo);//finishDesign
  11106. returnSuccessMsg("");
  11107. }
  11108. }
  11109. public void get_sample2_order()
  11110. {
  11111. if (UrlPostParmsCheck("ctid"))
  11112. {
  11113. string ctid = GetPostString("ctid");
  11114. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11115. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11116. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11117. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11118. double total = 0.0;
  11119. double order_price = 0.0;
  11120. if (dt_bu.Rows.Count > 0)
  11121. {
  11122. foreach (DataRow dr in dt_bu.Rows)
  11123. {
  11124. total += Convert.ToDouble(dr["payment"]);
  11125. }
  11126. }
  11127. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11128. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11129. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11130. string tid = ctid.Replace("S_", "");
  11131. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11132. double paymant = 0.0;
  11133. if (entity != null)
  11134. {
  11135. paymant = entity.payment;
  11136. }
  11137. string return_reason = "";
  11138. if (dt_after != null && dt_after.Rows.Count > 0)
  11139. {
  11140. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11141. }
  11142. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11143. }
  11144. }
  11145. public void get_erp_design_status()
  11146. {
  11147. string designName = GetPostString("designName");
  11148. DataStruct dStruct = GetPostStruct();
  11149. if (designName.Length > 0)
  11150. {
  11151. 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";
  11152. sql_user += " and Name like '%" + designName + "%'";
  11153. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11154. List<string> ids_list = new List<string>();
  11155. if (user_table.Rows.Count > 0)
  11156. {
  11157. foreach (DataRow item in user_table.Rows)
  11158. {
  11159. ids_list.Add(item["id"].ToString());
  11160. string ids_s = item["TeamIds"].ToString();
  11161. if (ids_s.Length > 0)
  11162. {
  11163. ids_list.AddRange(ids_s.Split(','));
  11164. }
  11165. }
  11166. }
  11167. HashSet<string> set = new HashSet<string>(ids_list);
  11168. ids_list = set.ToList();
  11169. if (ids_list.Count > 0)
  11170. {
  11171. 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));
  11172. dStruct.MainWhere = sql;
  11173. DataTable dt = null;
  11174. dt = WebCache.GetData("view_ErpUser", dStruct);
  11175. writeGridDataTableJson(dStruct.TotalCount, dt);
  11176. }
  11177. }
  11178. }
  11179. public void change_erp_order_price()
  11180. {
  11181. string ctid = GetPostString("ctid");
  11182. double price = GetPostDouble("price");
  11183. if (ctid.Length > 0)
  11184. {
  11185. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11186. if (ceErpTradeCellExtend == null)
  11187. {
  11188. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11189. ceErpTradeCellExtend.ctid = ctid;
  11190. ceErpTradeCellExtend.payment_cyt = price;
  11191. ceErpTradeCellExtend.Create();
  11192. }
  11193. else
  11194. {
  11195. ceErpTradeCellExtend.payment_cyt = price;
  11196. ceErpTradeCellExtend.Update();
  11197. }
  11198. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11199. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11200. {
  11201. ceErpDataSendOrderInfo.isSync = false;
  11202. ceErpDataSendOrderInfo.Update();
  11203. }
  11204. if (ceErpDataSendOrderInfo == null)
  11205. {
  11206. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11207. ceErpDataSendOrderInfo.isSync = false;
  11208. ceErpDataSendOrderInfo.ctid = ctid;
  11209. ceErpDataSendOrderInfo.Create();
  11210. }
  11211. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11212. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11213. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11214. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11215. {
  11216. dataSendOrderBean dataSendOrderBean = null;
  11217. foreach (DataRow item in dth.Rows)
  11218. {
  11219. try
  11220. {
  11221. dataSendOrderBean = new dataSendOrderBean();
  11222. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11223. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11224. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11225. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11226. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11227. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11228. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11229. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11230. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11231. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11232. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11233. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11234. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11235. if (result != null)
  11236. {
  11237. if ("0".Equals(result.errcode))
  11238. {
  11239. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11240. }
  11241. else
  11242. {
  11243. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11244. }
  11245. }
  11246. }
  11247. catch (Exception ex)
  11248. {
  11249. }
  11250. }
  11251. }
  11252. returnSuccessMsg("修改成功!");
  11253. return;
  11254. }
  11255. returnErrorMsg("找不到订单");
  11256. }
  11257. public void find_he_together()
  11258. {
  11259. string ctid = GetPostString("ctid");
  11260. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11261. List<string> list = new List<string>();
  11262. if (ceErpTradeCell != null)
  11263. {
  11264. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11265. {
  11266. 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);
  11267. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11268. if (table != null && table.Rows.Count > 0)
  11269. {
  11270. foreach (TableRow row in table.Rows)
  11271. {
  11272. }
  11273. }
  11274. }
  11275. }
  11276. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11277. }
  11278. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11279. {
  11280. //chy----19
  11281. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11282. //GD-CYT-----64
  11283. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11284. //ZHX----3
  11285. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11286. //JK----97
  11287. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11288. //ZT----70
  11289. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11290. //LHCY-----98
  11291. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11292. //XD-----90
  11293. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11294. //CYCY-----14
  11295. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11296. };
  11297. //其他改名
  11298. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11299. {
  11300. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11301. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11302. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11303. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11304. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11305. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11306. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11307. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11308. };
  11309. //不统计
  11310. List<int> no_suppliers = new List<int>()
  11311. {
  11312. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11313. };
  11314. //配件单
  11315. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11316. {
  11317. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11318. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11319. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11320. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11321. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11322. {"旗杆",new List<string>(){ "班旗" } },
  11323. {"牙签",new List<string>(){ "不干胶" } }
  11324. };
  11325. public void get_place_order_data()
  11326. {
  11327. string date1 = GetPostString("date1");
  11328. string date2 = GetPostString("date2");
  11329. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11330. DateTime start = DateTime.Parse(starttime);
  11331. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11332. DateTime end = DateTime.Parse(endtime);
  11333. if (date1 != null && date1.Length > 0)
  11334. {
  11335. DateTime dateTime = DateTime.Parse(date1);
  11336. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11337. start = DateTime.Parse(starttime);
  11338. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11339. end = DateTime.Parse(endtime);
  11340. }
  11341. if (date2 != null && date2.Length > 0)
  11342. {
  11343. DateTime dateTime = DateTime.Parse(date2);
  11344. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11345. end = DateTime.Parse(endtime);
  11346. }
  11347. 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);
  11348. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11349. //不干胶-----1,卡片-----29
  11350. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11351. foreach (DataRow row in data.Rows)
  11352. {
  11353. int productId = Convert.ToInt32(row["ProductId"]);
  11354. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11355. if (no_suppliers.Contains(supplierId))
  11356. {
  11357. continue;
  11358. }
  11359. string seller_memo = row["seller_memo"].ToString();
  11360. bool ispj = false;//是否配件单
  11361. bool isfirst = true;//第一个配
  11362. maps.Keys.ForEach(key =>
  11363. {
  11364. //备注包含配件
  11365. if (seller_memo.Contains(key) && isfirst)
  11366. {
  11367. List<string> list = maps[key];
  11368. ispj = true;
  11369. isfirst = false;
  11370. for (int i = 0; i < list.Count; i++)
  11371. {
  11372. if (seller_memo.Contains(list[i]))
  11373. {
  11374. ispj = false;
  11375. break;
  11376. }
  11377. }
  11378. }
  11379. });
  11380. if (ispj)
  11381. {
  11382. continue;
  11383. }
  11384. seller_memo = seller_memo.Replace("UV", "uv");
  11385. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11386. //吊牌归到卡片
  11387. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11388. seller_memo = seller_memo.Replace("卡套", "卡片");
  11389. seller_memo = seller_memo.Replace("封套", "卡片");
  11390. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11391. seller_memo = seller_memo.Replace("腰封", "卡片");
  11392. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11393. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11394. seller_memo = seller_memo.Replace("横幅", "条幅");
  11395. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11396. string map_key = "";
  11397. string type = "";
  11398. if (supplierMap.ContainsKey(supplierId))
  11399. {
  11400. foreach (var kvp in supplierMap[supplierId])
  11401. {
  11402. if (seller_memo.Contains(kvp.Key))
  11403. {
  11404. map_key = kvp.Value;
  11405. type = kvp.Value;
  11406. break;
  11407. }
  11408. }
  11409. }
  11410. if (map_key == "")
  11411. {
  11412. type = "其他";
  11413. map_key = "其他";
  11414. }
  11415. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11416. {
  11417. map_key = suppliers[supplierId];
  11418. }
  11419. if (supplierId == 70)
  11420. {
  11421. supplierId = 70;
  11422. }
  11423. map_key += "_" + row["SupplierName"].ToString();
  11424. Dictionary<string, int> map = null;
  11425. if (other_map.ContainsKey(map_key))
  11426. {
  11427. other_map.TryGetValue(map_key, out map);
  11428. }
  11429. else
  11430. {
  11431. map = new Dictionary<string, int>();
  11432. map.Add("dayDev", 0);//当天出货
  11433. map.Add("dayTotal", 0);//下单总数
  11434. map.Add("payTotal", 0);//500以上
  11435. map.Add("today", 0);//当天出货数量
  11436. map.Add("unusua", 0);//异常数
  11437. other_map.Add(map_key, map);
  11438. other_map.TryGetValue(map_key, out map);
  11439. }
  11440. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11441. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11442. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11443. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11444. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11445. {
  11446. map["dayTotal"]++;
  11447. if (supplierId == 97)
  11448. {
  11449. supplierId = 97;
  11450. }
  11451. }
  11452. if (Convert.ToDecimal(row["payment"]) >= 500)
  11453. {
  11454. map["payTotal"]++;
  11455. }
  11456. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11457. {
  11458. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11459. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11460. {
  11461. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11462. {
  11463. map["today"]++;
  11464. }
  11465. }
  11466. else
  11467. {
  11468. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11469. {
  11470. map["today"]++;
  11471. }
  11472. else
  11473. {
  11474. if (supplierId == 119)
  11475. {
  11476. Debug.WriteLine(row["seller_memo"].ToString());
  11477. }
  11478. }
  11479. }
  11480. }
  11481. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11482. {
  11483. map["unusua"]++;
  11484. }
  11485. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11486. //GD-CYT-----64
  11487. DateTime two = palceTimeStart.AddHours(14);
  11488. DateTime three = palceTimeStart.AddHours(15);
  11489. DateTime four = palceTimeStart.AddHours(16);
  11490. DateTime six = palceTimeStart.AddHours(18);
  11491. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11492. {
  11493. //下午四点前 500-1000
  11494. string count = row["ProductCount"].ToString();
  11495. if (count != null && count.Length > 0)
  11496. {
  11497. int productCount = commonHelper.getPlaceProductCount(count);
  11498. if (productCount >= 500 && productCount <= 1000)
  11499. {
  11500. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11501. {
  11502. map["dayDev"]++;
  11503. }
  11504. }
  11505. }
  11506. }
  11507. //UV
  11508. else if ("uv".Equals(type))
  11509. {
  11510. //ZT----70
  11511. //ZHX----3
  11512. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11513. {
  11514. map["dayDev"]++;
  11515. }
  11516. //JK----97
  11517. //HZX----105
  11518. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11519. {
  11520. map["dayDev"]++;
  11521. }
  11522. }
  11523. //帆布---52|条幅---27
  11524. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11525. {
  11526. //LHCY-----98
  11527. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11528. {
  11529. map["dayDev"]++;
  11530. }
  11531. }
  11532. //条幅
  11533. else if ("条幅".Equals(type))
  11534. {
  11535. //XD-----90
  11536. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11537. {
  11538. map["dayDev"]++;
  11539. }
  11540. }
  11541. //桌布
  11542. else if ("桌布".Equals(type))
  11543. {
  11544. //XD-----90
  11545. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11546. {
  11547. map["dayDev"]++;
  11548. }
  11549. }
  11550. //DL---10
  11551. //AYTW---119
  11552. //FS-CYT-DY ----80
  11553. //JK----97
  11554. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11555. {
  11556. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11557. {
  11558. map["dayDev"]++;
  11559. }
  11560. }
  11561. // QC---121
  11562. else if (supplierId == 121)
  11563. {
  11564. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11565. {
  11566. map["dayDev"]++;
  11567. }
  11568. }
  11569. }
  11570. DataTable dt = new DataTable();
  11571. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11572. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11573. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11574. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11575. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11576. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11577. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11578. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11579. other_map.Keys.ForEach(key =>
  11580. {
  11581. DataRow dr = dt.NewRow();
  11582. Dictionary<string, int> map = other_map[key];
  11583. string[] key_list = key.Split('_');
  11584. dr[0] = key_list[0];
  11585. dr[1] = key_list[1];
  11586. if (key_list.Length > 2)
  11587. {
  11588. dr[1] += "(" + key_list[2] + ")";
  11589. }
  11590. dr[2] = map["dayTotal"];
  11591. dr[3] = map["payTotal"];
  11592. dr[4] = map["today"];
  11593. dr[5] = map["unusua"];
  11594. dr[6] = map["dayDev"];
  11595. double rate = 0.00;
  11596. if (map["dayDev"] > 0)
  11597. {
  11598. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11599. }
  11600. dr[7] = rate.ToString();
  11601. dt.Rows.Add(dr);
  11602. });
  11603. DataView dv = new DataView(dt);
  11604. dv.Sort = "SupplierName";
  11605. //dv.Sort = "AllOrder desc";
  11606. DataTable dtNew = dv.ToTable();
  11607. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11608. }
  11609. public void check_order_desing_info()
  11610. {
  11611. string ctid = GetPostString("ctid");
  11612. if (!string.IsNullOrEmpty(ctid))
  11613. {
  11614. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11615. if (ceErpTradeCell != null)
  11616. {
  11617. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11618. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11619. return;
  11620. }
  11621. returnErrorMsg("找不到订单");
  11622. return;
  11623. }
  11624. returnErrorMsg("找不到订单");
  11625. }
  11626. public void get_timeout_detail()
  11627. {
  11628. string poscode = CurrentUser.UserPost.Post.Code;
  11629. DataStruct dStruct = GetPostStruct();
  11630. List<string> lw = new List<string>();
  11631. string id = GetPostString("id");
  11632. string pay_date1 = GetPostString("pay_date1");
  11633. string pay_date2 = GetPostString("pay_date2");
  11634. int type = GetPostInt("type");
  11635. if (type == 0)
  11636. {
  11637. if (pay_date1.Length > 0)
  11638. {
  11639. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11640. }
  11641. if (pay_date2.Length > 0)
  11642. {
  11643. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11644. }
  11645. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11646. }
  11647. if (type == 1)
  11648. {
  11649. if (pay_date1.Length > 0)
  11650. {
  11651. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11652. }
  11653. if (pay_date2.Length > 0)
  11654. {
  11655. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11656. }
  11657. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11658. }
  11659. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11660. DataTable dt = null;
  11661. dt = WebCache.GetData("view_orderlist", dStruct);
  11662. writeGridDataTableJson(dStruct.TotalCount, dt);
  11663. }
  11664. public void saveUrgentChargePrice()
  11665. {
  11666. string ctid = GetPostString("ctid");
  11667. if (!string.IsNullOrEmpty(ctid))
  11668. {
  11669. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11670. if (ceErpTradeCell != null)
  11671. {
  11672. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11673. if (prices <= 100)
  11674. {
  11675. returnErrorMsg("此订单金额不足100元,无法加急。");
  11676. return;
  11677. }
  11678. double price = GetPostDouble("price");
  11679. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11680. if (ceErpTradeCellExtend == null)
  11681. {
  11682. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11683. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11684. }
  11685. ceErpTradeCellExtend.urgentCharge = price;
  11686. if (ceErpTradeCellExtend.ID > 0)
  11687. {
  11688. ceErpTradeCellExtend.Update();
  11689. }
  11690. else
  11691. {
  11692. ceErpTradeCellExtend.Save();
  11693. }
  11694. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11695. returnSuccessMsg("修改成功!");
  11696. return;
  11697. }
  11698. returnErrorMsg("找不到订单");
  11699. return;
  11700. }
  11701. returnErrorMsg("找不到订单");
  11702. }
  11703. public void finish_erp_order()
  11704. {
  11705. string ctid = GetPostString("ctid");
  11706. if (!string.IsNullOrEmpty(ctid))
  11707. {
  11708. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11709. {
  11710. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11711. if (ceErpTradeCell != null)
  11712. {
  11713. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11714. ceErpTradeCell.Update();
  11715. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11716. returnSuccessMsg("修改成功!");
  11717. return;
  11718. }
  11719. }
  11720. }
  11721. returnErrorMsg("找不到订单");
  11722. }
  11723. public void get_trade_order_list()
  11724. {
  11725. string tid = GetPostString("tid");
  11726. if (!string.IsNullOrEmpty(tid))
  11727. {
  11728. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11729. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11730. writeGridDataTableJson(data.Rows.Count, data);
  11731. return;
  11732. }
  11733. returnErrorMsg("找不到订单");
  11734. }
  11735. public void save_cell_spu()
  11736. {
  11737. string ctid = GetPostString("ctid");
  11738. string spu_id = GetPostString("spu_id");
  11739. if (!string.IsNullOrEmpty(ctid))
  11740. {
  11741. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11742. if (ceErpTradeCellExtend == null)
  11743. {
  11744. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11745. ceErpTradeCellExtend.ctid = ctid;
  11746. }
  11747. ceErpTradeCellExtend.spu_id = spu_id;
  11748. if (!string.IsNullOrEmpty(spu_id))
  11749. {
  11750. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11751. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11752. }
  11753. if (ceErpTradeCellExtend.ID == 0)
  11754. {
  11755. ceErpTradeCellExtend.Create();
  11756. }
  11757. else
  11758. {
  11759. ceErpTradeCellExtend.Update();
  11760. }
  11761. returnSuccessMsg("修改成功!");
  11762. return;
  11763. }
  11764. returnErrorMsg("找不到订单");
  11765. }
  11766. public void change_express_info()
  11767. {
  11768. string ctid = GetPostString("ctid");
  11769. string transNo = GetPostString("transNo");
  11770. string transCom = GetPostString("transCom");
  11771. if (!string.IsNullOrEmpty(ctid))
  11772. {
  11773. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11774. if (ceErpTradeCellExtend == null)
  11775. {
  11776. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11777. ceErpTradeCellExtend.ctid = ctid;
  11778. }
  11779. ceErpTradeCellExtend.modExpressNo = transNo;
  11780. ceErpTradeCellExtend.modExpressCom = transCom;
  11781. ceErpTradeCellExtend.readMod = 2;
  11782. if (ceErpTradeCellExtend.ID == 0)
  11783. {
  11784. ceErpTradeCellExtend.Create();
  11785. }
  11786. else
  11787. {
  11788. ceErpTradeCellExtend.Update();
  11789. }
  11790. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11791. returnSuccessMsg("修改成功!");
  11792. return;
  11793. }
  11794. returnErrorMsg("找不到订单");
  11795. }
  11796. public void get_change_express_list()
  11797. {
  11798. DataStruct dStruct = GetPostStruct();
  11799. List<string> lw = new List<string>();
  11800. int st = 2;
  11801. string tid = GetPostString("ctid");
  11802. if (tid.Length > 0)
  11803. {
  11804. string select_tid = getTidByCtid(tid);
  11805. lw.Add(string.Format("tid='{0}'", select_tid));
  11806. }
  11807. string shopname = GetPostString("shopname");
  11808. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11809. string buyernick = GetPostString("buyer_nick");
  11810. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11811. string sellermemo = GetPostString("seller_memo");
  11812. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11813. string supplier = GetPostString("supplier");
  11814. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11815. string customer = GetPostString("customer");
  11816. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11817. string design = GetPostString("design");
  11818. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11819. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11820. string poscode = CurrentUser.UserPost.Post.Code;
  11821. if (poscode != "SysAdmin")
  11822. {
  11823. string shopid = CurrentUser.User.pemShop;
  11824. lw.Add(string.Format("shopId in ({0})", shopid));
  11825. }
  11826. lw.Add("readMod = 2");
  11827. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11828. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11829. writeGridDataTableJson(dStruct.TotalCount, dt);
  11830. }
  11831. public void deal_express_complete()
  11832. {
  11833. string ctid = GetPostString("ctid");
  11834. if (!string.IsNullOrEmpty(ctid))
  11835. {
  11836. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11837. if (ceErpTradeCellExtend == null)
  11838. {
  11839. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11840. ceErpTradeCellExtend.ctid = ctid;
  11841. }
  11842. ceErpTradeCellExtend.readMod = 1;
  11843. if (ceErpTradeCellExtend.ID == 0)
  11844. {
  11845. ceErpTradeCellExtend.Create();
  11846. }
  11847. else
  11848. {
  11849. ceErpTradeCellExtend.Update();
  11850. }
  11851. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11852. returnSuccessMsg("修改成功!");
  11853. return;
  11854. }
  11855. returnErrorMsg("找不到订单");
  11856. }
  11857. public void aftersale_return_visit()
  11858. {
  11859. string ctid = GetPostString("ctid");
  11860. if (!string.IsNullOrEmpty(ctid))
  11861. {
  11862. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11863. if (ceErpTradeCellExtend == null)
  11864. {
  11865. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11866. ceErpTradeCellExtend.ctid = ctid;
  11867. }
  11868. ceErpTradeCellExtend.returnVisit = 1;
  11869. if (ceErpTradeCellExtend.ID == 0)
  11870. {
  11871. ceErpTradeCellExtend.Create();
  11872. }
  11873. else
  11874. {
  11875. ceErpTradeCellExtend.Update();
  11876. }
  11877. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11878. if (ceErpTradeAfterSaleExtend != null)
  11879. {
  11880. ceErpTradeAfterSaleExtend.TextResult = "";
  11881. ceErpTradeAfterSaleExtend.Update();
  11882. }
  11883. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11884. returnSuccessMsg("修改成功!");
  11885. return;
  11886. }
  11887. returnErrorMsg("找不到订单");
  11888. }
  11889. public void orderPlaceInfo()
  11890. {
  11891. string ctids = GetPostString("ctids");
  11892. string[] list = ctids.Split(',');
  11893. foreach (string ctid in list)
  11894. {
  11895. CeErpSukuraData.createInfo(ctid, 3);
  11896. }
  11897. StringBuilder sql = new StringBuilder();
  11898. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11899. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11900. designHelper.api_approveDesign(ctids); //approveDesign
  11901. returnSuccessMsg("");
  11902. }
  11903. public void get_issue_list()
  11904. {
  11905. DataStruct dStruct = GetPostStruct();
  11906. List<string> lw = new List<string>();
  11907. int st = 2;
  11908. string tid = GetPostString("ctid");
  11909. if (tid.Length > 0)
  11910. {
  11911. string select_tid = getTidByCtid(tid);
  11912. lw.Add(string.Format("tid='{0}'", select_tid));
  11913. }
  11914. string shopname = GetPostString("shopname");
  11915. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11916. string buyernick = GetPostString("buyer_nick");
  11917. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11918. string sellermemo = GetPostString("seller_memo");
  11919. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11920. string supplier = GetPostString("supplier");
  11921. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11922. string customer = GetPostString("customer");
  11923. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11924. string design = GetPostString("design");
  11925. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11926. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11927. string poscode = CurrentUser.UserPost.Post.Code;
  11928. if (poscode != "SysAdmin")
  11929. {
  11930. string shopid = CurrentUser.User.pemShop;
  11931. lw.Add(string.Format("shopId in ({0})", shopid));
  11932. }
  11933. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11934. {
  11935. lw.Add("IssueState = 1");
  11936. }
  11937. lw.Add("IssueState > 0");
  11938. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11939. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11940. writeGridDataTableJson(dStruct.TotalCount, dt);
  11941. }
  11942. public void saveIssueContent()
  11943. {
  11944. string ctid = GetPostString("ctid");
  11945. if (!string.IsNullOrEmpty(ctid))
  11946. {
  11947. string content = GetPostString("content");
  11948. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11949. if (ceErpTradeAfterSaleExtend == null)
  11950. {
  11951. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11952. ceErpTradeAfterSaleExtend.tid = ctid;
  11953. }
  11954. ceErpTradeAfterSaleExtend.IssueContent = content;
  11955. ceErpTradeAfterSaleExtend.IssueState = 1;
  11956. if (ceErpTradeAfterSaleExtend.ID > 0)
  11957. {
  11958. ceErpTradeAfterSaleExtend.Update();
  11959. }
  11960. else
  11961. {
  11962. ceErpTradeAfterSaleExtend.Create();
  11963. }
  11964. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11965. returnSuccessMsg("添加成功!");
  11966. return;
  11967. }
  11968. returnErrorMsg("找不到订单");
  11969. }
  11970. public void dealIssueContent()
  11971. {
  11972. string ctid = GetPostString("ctid");
  11973. if (!string.IsNullOrEmpty(ctid))
  11974. {
  11975. string content = GetPostString("content");
  11976. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11977. if (ceErpTradeAfterSaleExtend != null)
  11978. {
  11979. ceErpTradeAfterSaleExtend.IssueState = 2;
  11980. ceErpTradeAfterSaleExtend.Update();
  11981. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11982. returnSuccessMsg("修改完成!");
  11983. return;
  11984. }
  11985. }
  11986. returnErrorMsg("找不到订单");
  11987. }
  11988. public void set_tid_attachments()
  11989. {
  11990. string tid = GetPostString("tid");
  11991. string atta = GetPostString("atta");
  11992. if (!string.IsNullOrEmpty(tid))
  11993. {
  11994. if (string.IsNullOrEmpty(atta))
  11995. {
  11996. returnErrorMsg("文件地址为空");
  11997. return;
  11998. }
  11999. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12000. if (ceErpTradeCell != null)
  12001. {
  12002. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12003. if (ceErpTrade == null)
  12004. {
  12005. returnErrorMsg("找不到订单");
  12006. return;
  12007. }
  12008. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12009. bool isSend = false;
  12010. if (dt != null && dt.Rows.Count > 0)
  12011. {
  12012. foreach (DataRow row in dt.Rows)
  12013. {
  12014. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12015. {
  12016. isSend = true;
  12017. }
  12018. }
  12019. if (isSend)
  12020. {
  12021. returnErrorMsg("已发货无法修改");
  12022. return;
  12023. }
  12024. ceErpTrade.Attachments = atta;
  12025. ceErpTrade.Update();
  12026. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12027. returnSuccessMsg("上传成功!");
  12028. return;
  12029. }
  12030. }
  12031. }
  12032. returnErrorMsg("找不到订单");
  12033. }
  12034. public void get_tid_attachments()
  12035. {
  12036. string tid = GetPostString("tid");
  12037. if (!string.IsNullOrEmpty(tid))
  12038. {
  12039. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12040. if (ceErpTradeCell != null)
  12041. {
  12042. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12043. if (ceErpTrade == null)
  12044. {
  12045. returnErrorMsg("找不到订单");
  12046. return;
  12047. }
  12048. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12049. return;
  12050. }
  12051. }
  12052. returnErrorMsg("找不到订单");
  12053. }
  12054. public void check_erp_sameorders()
  12055. {
  12056. if (UrlPostParmsCheck("ctid"))
  12057. {
  12058. string eid = GetPostString("ctid");
  12059. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12060. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12061. if (entity != null && ceErpTrade != null)
  12062. {
  12063. if (entity.OrderState > 6)
  12064. {
  12065. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12066. return;
  12067. }
  12068. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12069. List<string> ids = new List<string>();
  12070. if (dt != null && dt.Rows.Count > 1)
  12071. {
  12072. bool needhe = true;
  12073. foreach (DataRow dr in dt.Rows)
  12074. {
  12075. ids.Add("'" + dr["ctid"] + "'");
  12076. /* //备注有合包
  12077. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12078. {
  12079. needhe = true;
  12080. }
  12081. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12082. {
  12083. needhe = true;
  12084. }
  12085. //顺丰快递
  12086. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12087. {
  12088. needhe = true;
  12089. }*/
  12090. }
  12091. if (!needhe)
  12092. {
  12093. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12094. return;
  12095. }
  12096. StringBuilder sql = new StringBuilder();
  12097. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12098. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12099. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12100. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12101. foreach (DataRow dr in dt.Rows)
  12102. {
  12103. dr["dstate"] = 0;
  12104. dr["dnumber"] = 0;
  12105. foreach (DataRow row in dt1.Rows)
  12106. {
  12107. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12108. {
  12109. dr["dstate"] = 2;
  12110. dr["default"] = 1;
  12111. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12112. }
  12113. }
  12114. if (eid.Equals(dr["ctid"].ToString()))
  12115. {
  12116. dr["dstate"] = 1;
  12117. dr["default"] = 1;
  12118. }
  12119. }
  12120. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12121. return;
  12122. }
  12123. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12124. return;
  12125. }
  12126. returnErrorMsg("未找到订单");
  12127. return;
  12128. }
  12129. returnErrorMsg("缺少必要的参数");
  12130. }
  12131. public void get_mark_number()
  12132. {
  12133. string eid = GetPostString("ctid");
  12134. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12135. if (entity != null)
  12136. {
  12137. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12138. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12139. int current = 1;
  12140. if (ceErpDeliverMark == null)
  12141. {
  12142. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12143. List<string> ids = new List<string>();
  12144. if (dt != null && dt.Rows.Count > 1)
  12145. {
  12146. foreach (DataRow dr in dt.Rows)
  12147. {
  12148. ids.Add("'" + dr["ctid"] + "'");
  12149. }
  12150. //查询已有的编号
  12151. StringBuilder sql = new StringBuilder();
  12152. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12153. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12154. if (dt1 == null || dt1.Rows.Count == 0)
  12155. {
  12156. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12157. List<int> list_number = new List<int>();
  12158. foreach (DataRow row in numbers.Rows)
  12159. {
  12160. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12161. }
  12162. //查询空余编号
  12163. for (int i = 0; i < list_number.Count + 2; i++)
  12164. {
  12165. if (!list_number.Contains(current))
  12166. {
  12167. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12168. //防止查询过程中有新数据生成
  12169. if (ceErpDeliverMark1 == null)
  12170. {
  12171. break;
  12172. }
  12173. }
  12174. current++;
  12175. }
  12176. }
  12177. else
  12178. {
  12179. foreach (DataRow row in dt1.Rows)
  12180. {
  12181. current = Convert.ToInt32(row["markNumber"]);
  12182. }
  12183. }
  12184. ceErpDeliverMark = new CeErpDeliverMark();
  12185. ceErpDeliverMark.ctid = eid;
  12186. ceErpDeliverMark.createtime = DateTime.Now;
  12187. if (ceErpTrade != null)
  12188. {
  12189. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12190. }
  12191. ceErpDeliverMark.markNumber = current;
  12192. ceErpDeliverMark.Create();
  12193. }
  12194. }
  12195. else
  12196. {
  12197. current = ceErpDeliverMark.markNumber;
  12198. }
  12199. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12200. return;
  12201. }
  12202. }
  12203. public void aftersaleCytSend()
  12204. {
  12205. string ctid = GetPostString("ctid");
  12206. if (!string.IsNullOrEmpty(ctid))
  12207. {
  12208. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12209. if (ceErpTradeCell != null)
  12210. {
  12211. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12212. }
  12213. returnSuccessMsg("推送成功");
  12214. return;
  12215. }
  12216. returnErrorMsg("缺少必要的参数");
  12217. }
  12218. public void packOrderInfo()
  12219. {
  12220. string ctids = GetPostString("ctids");
  12221. if (!string.IsNullOrEmpty(ctids))
  12222. {
  12223. string[] ctid_list = ctids.Split(',');
  12224. if (ctid_list.Length > 20)
  12225. {
  12226. returnErrorMsg("单次下载次数不能超过20个");
  12227. return;
  12228. }
  12229. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12230. StringBuilder sql = new StringBuilder();
  12231. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12232. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12233. int supplierId = 0;
  12234. StringBuilder insterSql = new StringBuilder();
  12235. for (int i = 0; i < dt.Rows.Count; i++)
  12236. {
  12237. DataRow row = dt.Rows[i];
  12238. if (i == 0)
  12239. {
  12240. supplierId = Convert.ToInt32(row["SupplierId"]);
  12241. }
  12242. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12243. {
  12244. returnErrorMsg("同车间的订单才能一起打包");
  12245. return;
  12246. }
  12247. int orderState = Convert.ToInt32(row["OrderState"]);
  12248. if (orderState != 5)
  12249. {
  12250. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12251. return;
  12252. }
  12253. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12254. }
  12255. CeErpPackData ceErpPackData = new CeErpPackData();
  12256. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12257. ceErpPackData.supplierId = supplierId;
  12258. ceErpPackData.createtime = DateTime.Now;
  12259. ceErpPackData.createBy = CurrentUser.UserID;
  12260. ceErpPackData.createName = CurrentUser.UserName;
  12261. ceErpPackData.Create();
  12262. if (ceErpPackData.ID > 0)
  12263. {
  12264. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12265. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12266. }
  12267. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12268. returnSuccessMsg("打包成功");
  12269. return;
  12270. }
  12271. returnErrorMsg("缺少必要的参数");
  12272. }
  12273. public void rePackOrderInfo()
  12274. {
  12275. string id = GetPostString("id");
  12276. if (!string.IsNullOrEmpty(id))
  12277. {
  12278. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12279. if (ceErpPackData == null)
  12280. {
  12281. returnSuccessMsg("查无数据");
  12282. return;
  12283. }
  12284. ceErpPackData.upStatus = 0;
  12285. ceErpPackData.message = "";
  12286. ceErpPackData.Update();
  12287. returnSuccessMsg("打包成功");
  12288. return;
  12289. }
  12290. returnErrorMsg("缺少必要的参数");
  12291. }
  12292. public void backPackOrderInfo()
  12293. {
  12294. string id = GetPostString("id");
  12295. if (!string.IsNullOrEmpty(id))
  12296. {
  12297. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12298. if (ceErpPackData == null)
  12299. {
  12300. returnSuccessMsg("查无数据");
  12301. return;
  12302. }
  12303. ceErpPackData.upStatus = 4;
  12304. ceErpPackData.Update();
  12305. List<string> list = new List<string>();
  12306. StringBuilder sql = new StringBuilder();
  12307. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12308. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12309. for (int i = 0; i < dt.Rows.Count; i++)
  12310. {
  12311. DataRow row = dt.Rows[i];
  12312. list.Add("'" + row["ctid"].ToString() + "'");
  12313. }
  12314. string textCtids = string.Join(",", list);
  12315. 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));
  12316. 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, "无法打包退回"));
  12317. returnSuccessMsg("退回成功");
  12318. return;
  12319. }
  12320. returnErrorMsg("缺少必要的参数");
  12321. }
  12322. public void addPackDownNum()
  12323. {
  12324. string id = GetPostString("id");
  12325. if (!string.IsNullOrEmpty(id))
  12326. {
  12327. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12328. returnSuccessMsg("下载成功");
  12329. return;
  12330. }
  12331. returnErrorMsg("缺少必要的参数");
  12332. }
  12333. public void get_pack_list()
  12334. {
  12335. DataStruct dStruct = GetPostStruct();
  12336. List<string> lw = new List<string>();
  12337. string supplier = GetPostString("supplier");
  12338. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12339. string posTag = CurrentUser.UserPost.Post.Code;
  12340. if (posTag == "Supplier")
  12341. {
  12342. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12343. }
  12344. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12345. dStruct.Order = "createtime desc";
  12346. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12347. writeGridDataTableJson(dStruct.TotalCount, dt);
  12348. }
  12349. public void get_pack_order_list()
  12350. {
  12351. string packId = GetPostString("packId");
  12352. if (string.IsNullOrEmpty(packId))
  12353. {
  12354. returnErrorMsg("缺少必要的参数");
  12355. return;
  12356. }
  12357. StringBuilder sql = new StringBuilder();
  12358. 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);
  12359. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12360. if (dt == null || dt.Rows.Count == 0)
  12361. {
  12362. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12363. return;
  12364. }
  12365. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12366. return;
  12367. }
  12368. public void get_supplier_product_time_list()
  12369. {
  12370. DataStruct dStruct = GetPostStruct();
  12371. List<string> lw = new List<string>();
  12372. string supplier = GetPostString("supplier");
  12373. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12374. string posTag = CurrentUser.UserPost.Post.Code;
  12375. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12376. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12377. writeGridDataTableJson(dStruct.TotalCount, dt);
  12378. }
  12379. public void saveSupplierProductTime()
  12380. {
  12381. string productId = GetPostString("productId");
  12382. if (string.IsNullOrEmpty(productId))
  12383. {
  12384. returnErrorMsg("缺少必要的参数");
  12385. return;
  12386. }
  12387. string productName = GetPostString("productName");
  12388. int supplierId = GetPostInt("supplierId");
  12389. if (supplierId == 0)
  12390. {
  12391. returnErrorMsg("缺少必要的参数");
  12392. return;
  12393. }
  12394. int quantity = GetPostInt("quantity");
  12395. int sendDay = GetPostInt("sendTime");
  12396. string supplierName = GetPostString("supplierName");
  12397. string craft = GetPostString("craft");
  12398. string deadLine = GetPostString("deadLine");
  12399. string dayDeadLine = GetPostString("dayDeadLine");
  12400. try
  12401. {
  12402. int eid = GetPostInt("eid");
  12403. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12404. if (ceErpSupplierProductTime == null)
  12405. {
  12406. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12407. }
  12408. ceErpSupplierProductTime.productId = productId;
  12409. ceErpSupplierProductTime.productName = productName;
  12410. ceErpSupplierProductTime.supplierId = supplierId;
  12411. ceErpSupplierProductTime.supplierName = supplierName;
  12412. ceErpSupplierProductTime.craft = craft;
  12413. ceErpSupplierProductTime.sendDay = sendDay;
  12414. ceErpSupplierProductTime.quantity = quantity;
  12415. if (!string.IsNullOrEmpty(deadLine))
  12416. {
  12417. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12418. }
  12419. if (!string.IsNullOrEmpty(dayDeadLine))
  12420. {
  12421. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12422. }
  12423. if (ceErpSupplierProductTime.ID == 0)
  12424. {
  12425. ceErpSupplierProductTime.Save();
  12426. }
  12427. else
  12428. {
  12429. ceErpSupplierProductTime.Update();
  12430. }
  12431. }
  12432. catch (Exception e)
  12433. {
  12434. }
  12435. returnSuccessMsg("保存成功");
  12436. return;
  12437. }
  12438. public void delSupplierProductTime()
  12439. {
  12440. int eid = GetPostInt("eid");
  12441. if (eid > 0)
  12442. {
  12443. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12444. if (ceErpSupplierProductTime == null)
  12445. {
  12446. returnErrorMsg("查无数据");
  12447. return;
  12448. }
  12449. ceErpSupplierProductTime.Delete();
  12450. returnSuccessMsg("保存成功");
  12451. return;
  12452. }
  12453. returnErrorMsg("缺少必要的参数");
  12454. }
  12455. public void getExpressInfo()
  12456. {
  12457. string ctid = GetPostString("ctid");
  12458. if (!string.IsNullOrEmpty(ctid))
  12459. {
  12460. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12461. if (ceErpTradeCell != null)
  12462. {
  12463. string outSid = ceErpTradeCell.OutSid;
  12464. if (outSid.Length > 0)
  12465. {
  12466. 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);
  12467. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12468. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12469. return;
  12470. }
  12471. }
  12472. returnErrorMsg("查无记录");
  12473. return;
  12474. }
  12475. returnErrorMsg("缺少必要的参数");
  12476. }
  12477. public void getExpressPostData()
  12478. {
  12479. string express = GetPostString("express");
  12480. if (!string.IsNullOrEmpty(express))
  12481. {
  12482. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12483. if (ceErpExpressInfo != null)
  12484. {
  12485. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12486. return;
  12487. }
  12488. }
  12489. returnErrorMsg("缺少必要的参数");
  12490. }
  12491. public void checkSupplierOrder()
  12492. {
  12493. string ctids = GetPostString("ctids");
  12494. if (ctids != null)
  12495. {
  12496. List<string> list = new List<string>();
  12497. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12498. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12499. for (int i = 0; i < dt.Rows.Count; i++)
  12500. {
  12501. DataRow row = dt.Rows[i];
  12502. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12503. {
  12504. continue;
  12505. }
  12506. list.Add(row["seller_memo"].ToString());
  12507. }
  12508. if (list.Count > 0)
  12509. {
  12510. 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, "点击下载按钮"));
  12511. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12512. return;
  12513. }
  12514. }
  12515. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12516. return;
  12517. }
  12518. public void addPersonId()
  12519. {
  12520. string tid = GetPostString("tid");
  12521. string personId = GetPostString("personId");
  12522. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12523. if (ceErpTrade != null)
  12524. {
  12525. ceErpTrade.receiver_zip = personId;
  12526. ceErpTrade.Update();
  12527. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12528. returnSuccessMsg("保存成功");
  12529. return;
  12530. }
  12531. returnErrorMsg("缺少必要的参数");
  12532. }
  12533. }
  12534. }