sync.order.cs 640 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. namespace SiteCore.Handler
  51. {
  52. public partial class sync
  53. {
  54. public void get_erp_orderlist()
  55. {
  56. string poscode = CurrentUser.UserPost.Post.Code;
  57. DataStruct dStruct = GetPostStruct();
  58. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\uv特殊工艺价格(1).xls");
  59. //apiHelper.Api_SyncOrderByTime("598825");
  60. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  61. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  62. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  63. //banniuApiHelper.sendLogisticsInfo(null);
  64. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  65. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  66. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  67. //int sid = commonHelper.autoDistributeToSupplier(entity);
  68. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  69. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1752654175000,\"deliveryType\":\"OFFLINE\",\"discountFee\":0.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1752826970000,\"lines\":[{\"latestDeliveryTime\":1752826970000,\"mark2\":[],\"num\":23,\"outerId\":\"DGCP\",\"payment\":460.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2200806677467/O1CN01Wlpmej251wOGAuYd2_!!0-item_pic.jpg\",\"platServiceFee\":0.0,\"price\":20.0,\"refOlId\":\"4634728491992436446\",\"refSkuId\":\"0\",\"refSpuId\":\"617207822351\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":20.0,\"singleFee\":20.0,\"spuOuterId\":\"DGCP\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"蛋糕logo插牌定制烘焙店插卡插排生日小卡片装饰甜品标签插件设计\",\"totalFee\":460.0,\"totalPrice\":460.0,\"totalSellPrice\":460.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1752658857000,\"openBuyerId\":\"AAHqRHraABkUZRPgSx1P9I8b\",\"openBuyerNick\":\"b**\",\"openSellerNick\":\"翊喜旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1752654168000,\"payTime\":1752654170000,\"payment\":460.0,\"platServiceFee\":0.0,\"posCode\":\"yixi\",\"posId\":598788,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"佛山市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"禅城区\",\"receiverId\":\"882d7aaecddc7a9698cc36e36a46ba24$\",\"receiverState\":\"广东省\",\"receiverTown\":\"石湾镇街道\",\"refOid\":\"4634728491992436446\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"60x12mm-2款各500张-插卡-350克铜板纸-直角单面烫金模切-bowie_s-英子-240元-(纯烫金)-老客户204.02.20,40x40mm-2000张-插卡-350克铜板纸-方形直角裁切-bowie_s-英子-220元--老客户2024.02.20\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":460.0,\"totalPrice\":460.0,\"totalSellPrice\":460.0,\"type\":\"SALE\"}}");
  70. //refundTmcHelper.Api_TmcRefundMsg("{\"content\":{\"afterStatus\":\"SUCCESS\",\"createTime\":1735287446000,\"desc\":\"\",\"interceptInvestor\":\"NONE\",\"interceptStatus\":\"NONE\",\"interceptType\":\"NONE\",\"lines\":[{\"num\":2,\"outerId\":\"\",\"price\":50.0,\"refAid\":\"313001208133750610\",\"refAlId\":\"313001208133750610\",\"refBoughtSkuId\":\"\",\"refOid\":\"4181722704291751006\",\"refOlId\":\"4181722704291751006\",\"refSkuId\":\"0\",\"refSpuId\":\"865893808768\",\"refundFee\":98.86,\"refundStatus\":\"SUCCESS\",\"title\":\"新年会抽奖券定制2025蛇年公司活动正副可撕代金券打印纪念票根奖品兑换尾牙晚宴邀请卡号码牌创意入场券设计\",\"totalFee\":98.86,\"type\":1}],\"logisticsCompany\":\"\",\"logisticsOrderNo\":\"\",\"mark2\":[],\"openBuyerNick\":\"0**\",\"openSellerNick\":\"万慕办公旗舰店\",\"posCode\":\"wanmu\",\"posId\":598798,\"reason\":\"订单信息拍错(规格/尺码/颜色等)\",\"receiverCity\":\"\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"\",\"receiverId\":\"\",\"receiverState\":\"\",\"receiverTown\":\"\",\"receiverZip\":\"\",\"refAid\":\"313001208133750610\",\"refOid\":\"4181722704291751006\",\"refPlatform\":\"TB\",\"refType\":\"TMALL\",\"refundCreateTime\":1735287358000,\"refundFee\":\"98.86\",\"refundPhase\":\"ON_SALE\",\"refundTime\":1735289443000,\"refundUpdateTime\":1735289443000,\"refundVersion\":1735287358100,\"senderAddress\":\"\",\"senderCity\":\"\",\"senderCountry\":\"中国\",\"senderDistrict\":\"\",\"senderMobile\":\"\",\"senderName\":\"\",\"senderPhone\":\"\",\"senderState\":\"\",\"senderTown\":\"\",\"senderZip\":\"\",\"status\":\"SUCCESS\",\"statusCode\":\"SUCCESS\",\"statusName\":\"退款成功\",\"totalFee\":\"98.86\",\"type\":\"REFUND\",\"updateTime\":1735289479000}}");
  71. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  72. //commonHelper.loginGetOrder(2152);
  73. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  74. List<string> lw = new List<string>();
  75. string tid = GetPostString("ctid");
  76. string date1 = GetPostString("date1");
  77. //12-1 修改
  78. string urgent = GetPostString("urgent");
  79. string back = GetPostString("back");
  80. string offlineSearch = GetPostString("offlineSearch");
  81. int paramsCount = 0;
  82. if (!string.IsNullOrWhiteSpace(urgent))
  83. {
  84. if (urgent.Equals("true"))
  85. {
  86. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  87. }
  88. }
  89. if (!string.IsNullOrWhiteSpace(back))
  90. {
  91. if (back.Equals("true"))
  92. {
  93. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  94. }
  95. }
  96. if (!string.IsNullOrWhiteSpace(offlineSearch))
  97. {
  98. if (offlineSearch.Equals("true"))
  99. {
  100. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  101. }
  102. }
  103. //end
  104. string date2 = GetPostString("date2");
  105. string buyernick = GetPostString("buyer_nick");
  106. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  107. {
  108. if (tid.Length <= 0 && buyernick.Length <= 0)
  109. {
  110. return;
  111. }
  112. }
  113. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  114. {
  115. if (tid.Length > 0)
  116. {
  117. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  118. if (ceErpTradeCell != null)
  119. {
  120. tid = ceErpTradeCell.tid;
  121. }
  122. List<string> select_tid = getTidByCtidMore(tid);
  123. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  124. }
  125. if (buyernick.Length > 0)
  126. {
  127. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  128. }
  129. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  130. if (dw.Length > 0)
  131. {
  132. lw.Add(dw);
  133. }
  134. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  135. {
  136. string usershop = CurrentUser.User.pemShop;
  137. lw.Add(string.Format("ShopId in ({0})", usershop));
  138. }
  139. }
  140. else
  141. {
  142. if (ex_psize == 0)
  143. {
  144. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  145. }
  146. if (PKey != "admin" && poscode != "SysAdmin")
  147. {
  148. string usershop = CurrentUser.User.pemShop;
  149. lw.Add(string.Format("ShopId in ({0})", usershop));
  150. paramsCount++;
  151. }
  152. }
  153. string uploaddate1 = GetPostString("uploaddate1");
  154. string uploaddate2 = GetPostString("uploaddate2");
  155. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  156. if (update.Length > 0) lw.Add(update);
  157. string deliverydate1 = GetPostString("deliverydate1");
  158. string deliverydate2 = GetPostString("deliverydate2");
  159. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  160. if (deliverydate.Length > 0)
  161. {
  162. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  163. };
  164. string shopname = GetPostString("shopname");
  165. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  166. string addwechat = GetPostString("addwechat");
  167. if (addwechat.Length > 0)
  168. {
  169. int addWt = Convert.ToInt32(addwechat);
  170. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  171. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  172. }
  173. string customer = GetPostString("customer");
  174. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  175. string design = GetPostString("design");
  176. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  177. string orderState = GetPostString("orderState");
  178. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  179. string address = GetPostString("address");
  180. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  181. string sellermemo = GetPostString("seller_memo");
  182. if (sellermemo.Length > 0)
  183. {
  184. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  185. }
  186. string backReason = GetPostString("backReason");
  187. if (backReason.Length > 0)
  188. {
  189. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  190. }
  191. string apdate1 = GetPostString("apdate1");
  192. string apdate2 = GetPostString("apdate2");
  193. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  194. if (dwap.Length > 0) lw.Add(dwap);
  195. string price1 = GetPostString("price1");
  196. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  197. string price2 = GetPostString("price2");
  198. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  199. string isoldcustomer = GetPostString("isoldcus");
  200. string spudata = GetPostString("spudata");
  201. if ("0".Equals(spudata))
  202. {
  203. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  204. }
  205. if ("1".Equals(spudata))
  206. {
  207. lw.Add(string.Format("spu_id <> ''"));
  208. }
  209. string finishdate1 = GetPostString("finishdate1");
  210. string finishdate2 = GetPostString("finishdate2");
  211. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  212. bool isFinish = false;
  213. if (finishdate.Length > 0)
  214. {
  215. lw.Add(finishdate);
  216. isFinish = true;
  217. paramsCount++;
  218. }
  219. if (isoldcustomer.Length > 0)
  220. {
  221. if ("2".Equals(isoldcustomer))
  222. {
  223. lw.Add(string.Format("VipCustomer=1"));
  224. }
  225. else
  226. {
  227. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  228. }
  229. }
  230. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  231. if (ex_psize > 0)
  232. {
  233. int UserID = CurrentUser.UserID;
  234. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  235. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  236. {
  237. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  238. }
  239. dStruct.Order = "pay_time desc";
  240. }
  241. string isNew = GetPostString("isNew");
  242. if (isNew == "true")
  243. {
  244. lw.Add(string.Format("IsNew = {0}", 1));
  245. }
  246. string overtime = GetPostString("overtime");
  247. if (overtime == "1")
  248. {
  249. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  250. }
  251. String usePost = CurrentUser.UserPost.Post.Code;
  252. if (usePost.Equals("Operation") == true)
  253. {
  254. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  255. }
  256. else
  257. {
  258. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  259. }
  260. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  261. if (dStruct.PageSize == 100000)
  262. {
  263. dStruct.Order = "";
  264. }
  265. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  266. DataTable dt = null;
  267. string tablename = "view_orderlist";
  268. if (isFinish)
  269. {
  270. tablename = "view_orderlist_end";
  271. }
  272. dt = WebCache.GetData(tablename, dStruct);
  273. if (dt != null && dt.Rows.Count > 0)
  274. {
  275. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  276. foreach (DataRow dr in dt.Rows)
  277. {
  278. try
  279. {
  280. if (dr["refund_fees"] != null)
  281. {
  282. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  283. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  284. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  285. if (payment == refund_fees)
  286. {
  287. dr["refund_fees"] = Math.Round(refund_fees, 2);
  288. }
  289. else if (refund_fees == total_fee)
  290. {
  291. dr["refund_fees"] = payment;
  292. }
  293. else
  294. {
  295. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  296. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  297. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  298. }
  299. }
  300. // 对象操作
  301. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  302. ceErpTradeCell.ctid = dr["ctid"].ToString();
  303. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  304. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  305. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  306. if (dStruct.PageSize != 100000)
  307. {
  308. if (dr["DispatchSort"].ToString() == "2")
  309. {
  310. dr["gongchuang"] = 200;
  311. }
  312. else if ("外协".Equals(dr["ToType"].ToString()))
  313. {
  314. dr["gongchuang"] = 200;
  315. }
  316. else if ("内部".Equals(dr["ToType"].ToString()))
  317. {
  318. dr["gongchuang"] = -1;
  319. }
  320. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  321. {
  322. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  323. dr["gongchuang"] = response.code;
  324. }
  325. }
  326. }
  327. catch (NullReferenceException ex)
  328. {
  329. // 处理空引用异常
  330. dr["refund_fees"] = "0.00";
  331. }
  332. }
  333. }
  334. writeGridDataTableJson(dStruct.TotalCount, dt);
  335. }
  336. public void get_erp_orderlist_sumprice()
  337. {
  338. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  339. return;
  340. List<string> lw = new List<string>();
  341. string tid = GetPostString("ctid");
  342. string date1 = GetPostString("date1");
  343. string date2 = GetPostString("date2");
  344. if (tid.Length > 0 || date1.Length > 0)
  345. {
  346. lw.Add(string.Format("ctid like '%{0}%'", tid));
  347. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  348. if (dw.Length > 0) lw.Add(dw);
  349. }
  350. else
  351. {
  352. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  353. }
  354. string shopname = GetPostString("shopname");
  355. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  356. string buyernick = GetPostString("buyer_nick");
  357. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  358. string customer = GetPostString("customer");
  359. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  360. string design = GetPostString("design");
  361. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  362. string orderState = GetPostString("orderState");
  363. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  364. string address = GetPostString("address");
  365. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  366. string sellermemo = GetPostString("seller_memo");
  367. if (sellermemo.Length > 0)
  368. {
  369. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  370. }
  371. string apdate1 = GetPostString("apdate1");
  372. string apdate2 = GetPostString("apdate2");
  373. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  374. if (dwap.Length > 0) lw.Add(dwap);
  375. string price1 = GetPostString("price1");
  376. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  377. string price2 = GetPostString("price2");
  378. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  379. string isoldcustomer = GetPostString("isoldcus");
  380. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  381. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  382. if (PKey != "admin")
  383. {
  384. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  385. lw.Add(string.Format("shopId in ({0})", usershop));
  386. }
  387. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  388. string mainWhere = string.Join(" and ", lw.ToArray());
  389. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  390. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  391. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  392. decimal total = 0;
  393. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  394. {
  395. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  396. }
  397. var res = new
  398. {
  399. data = total
  400. };
  401. string ro_jsond = JsonConvert.SerializeObject(res);
  402. returnSuccess(ro_jsond);
  403. return;
  404. }
  405. public void get_erp_CustomerServiceGather()
  406. {
  407. string userWhere = "", orderWhere = "";
  408. List<string> lw = new List<string>();
  409. string customer = GetPostString("customer");
  410. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  411. string shopname = GetPostString("shopname");
  412. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  413. string date1 = GetPostString("date1");
  414. string date2 = GetPostString("date2");
  415. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  416. if (dw.Length > 0) lw.Add(dw);
  417. orderWhere = string.Join(" and ", lw.ToArray());
  418. string sql = string.Format("select a.Name CusName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitRelease,0) WaitRelease, isnull(e.WaitRob,0) WaitRob, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  419. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  420. "left join " +
  421. "( " +
  422. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  423. ") as b on a.ID = b.CustomerUserId " +
  424. "left join " +
  425. "( " +
  426. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  427. ") as d on a.ID = d.CustomerUserId " +
  428. "left join " +
  429. "( " +
  430. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  431. ") as e on a.ID = e.CustomerUserId " +
  432. "left join " +
  433. "( " +
  434. " select CustomerUserId, RefundCount, RefundSum from " +
  435. " ( " +
  436. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  437. " from CE_ErpTradeRefund a " +
  438. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  439. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  440. " group by CustomerUserId " +
  441. " ) as a " +
  442. ") as f on a.ID = f.CustomerUserId " +
  443. "where a.PostCode = 'CustomerService'",
  444. userWhere, orderWhere);
  445. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  446. writeGridDataTableJson(dt.Rows.Count, dt);
  447. //writeGridDataTableJson(dt.Rows.Count, dt);
  448. }
  449. //设计汇总
  450. public void get_erp_DesignerGather()
  451. {
  452. string userWhere = "", orderWhere = "";
  453. List<string> lw = new List<string>();
  454. string Designer = GetPostString("designer");
  455. int org = GetPostInt("org");
  456. if (Designer.Length > 0)
  457. {
  458. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  459. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  460. }
  461. else if (org > 0)
  462. {
  463. userWhere = string.Format(" where OrgID ={0}", org);
  464. }
  465. string shopname = GetPostString("shopname");
  466. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  467. string state = GetPostString("state");
  468. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  469. string OrderArea = GetPostString("order_area");
  470. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  471. string date1 = GetPostString("date1");
  472. string date2 = GetPostString("date2");
  473. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  474. if (dw.Length > 0) lw.Add(dw);
  475. string UpDate1 = GetPostString("UpDate1");
  476. string UpDate2 = GetPostString("UpDate2");
  477. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  478. if (dw.Length > 0) lw.Add(dw);
  479. orderWhere = string.Join(" and ", lw.ToArray());
  480. string sql = string.Format("select *,cast(cast(z.DesignFinish as float) / (case z.AllOrder when 0 then 1 else z.AllOrder end) * 100 as numeric(18,2)) as FinalizationRate from (" +
  481. "select a.Name DesignerName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitDesign,0) WaitDesign, isnull(e.Designing,0) Designing, isnull(g.DesignFinish,0) DesignFinish, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  482. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  483. "left join " +
  484. "( " +
  485. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  486. ") as b on a.ID = b.DesignUserId " +
  487. "left join " +
  488. "( " +
  489. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  490. ") as d on a.ID = d.DesignUserId " +
  491. "left join " +
  492. "( " +
  493. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  494. ") as e on a.ID = e.DesignUserId " +
  495. "left join " +
  496. "( " +
  497. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  498. ") as g on a.ID = g.DesignUserId " +
  499. "left join " +
  500. "( " +
  501. " select CustomerUserId, RefundCount, RefundSum from " +
  502. " ( " +
  503. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  504. " from CE_ErpTradeRefund a " +
  505. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  506. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  507. " group by CustomerUserId " +
  508. " ) as a " +
  509. ") as f on a.ID = f.CustomerUserId " +
  510. "where a.PostCode = 'Designer') as z",
  511. userWhere, orderWhere);
  512. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  513. writeGridDataTableJson(dt.Rows.Count, dt);
  514. }
  515. //删除tradecell的订单
  516. public void del_erp_cellorder()
  517. {
  518. if (UrlPostParmsCheck("ctid"))
  519. {
  520. string eid = GetPostString("ctid");
  521. CeErpTradeCell.DelByCtid(eid);
  522. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  523. returnSuccessMsg("删除成功");
  524. }
  525. }
  526. public void clear_erp_refundstate()
  527. {
  528. if (UrlPostParmsCheck("ids"))
  529. {
  530. string eids = GetPostString("ids");
  531. string[] ctidList = eids.Split(',');
  532. foreach (string ctid in ctidList)
  533. {
  534. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  535. if (entity != null)
  536. {
  537. entity.IsRefund = 0;
  538. entity.Update();
  539. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  540. }
  541. else
  542. continue;
  543. }
  544. returnSuccessMsg("操作成功");
  545. return;
  546. }
  547. returnErrorMsg("缺少必要参数");
  548. }
  549. public void set_erp_urgency()
  550. {
  551. if (UrlPostParmsCheck("ctid"))
  552. {
  553. string eid = GetPostString("ctid");
  554. CeErpTradeCell entity = null;
  555. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  556. if (entity != null)
  557. {
  558. double prices = commonHelper.calculationPrice(entity);
  559. if (prices <= 100)
  560. {
  561. returnErrorMsg("此订单金额不足100元,无法加急。");
  562. return;
  563. }
  564. string utime = GetPostString("urgencytime");
  565. if (utime.Length > 0)
  566. {
  567. entity.UrgencyTime = Convert.ToDateTime(utime);
  568. }
  569. else
  570. {
  571. returnErrorMsg("请选择加急时间");
  572. return;
  573. }
  574. if (entity.OrderState <= 4)
  575. {
  576. //entity.seller_memo = entity.seller_memo + "-加急";
  577. string smemo = entity.seller_memo;
  578. int kindex = smemo.IndexOf(")");
  579. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  580. if (lastoneStr != "-")
  581. {
  582. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  583. }
  584. string prememo = smemo.Substring(0, kindex + 2);
  585. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  586. int lastkindex = lastmemo.IndexOf("(");
  587. DateTime urgtime = Convert.ToDateTime(utime);
  588. string newlastmemo = "";
  589. if (lastkindex == 0)
  590. {
  591. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  592. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  593. }
  594. else
  595. {
  596. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  597. }
  598. entity.seller_memo = prememo + newlastmemo;
  599. }
  600. entity.IsUrgency = true;
  601. entity.UpdateTime = DateTime.Now;
  602. entity.Update();
  603. ApiVo apiVo = new ApiVo();
  604. apiVo.orderNumber = entity.ctid;
  605. apiVo.actionName = "changeDesign";
  606. apiVo.orderRemarks = entity.seller_memo;
  607. apiVo.remarkSign = 3;
  608. designHelper.API_WorkCore(apiVo); //changeDesign
  609. CeErpSukuraData.createInfo(entity.ctid, 7);
  610. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  611. returnSuccessMsg("设置成功!");
  612. return;
  613. }
  614. returnErrorMsg("找不到记录");
  615. }
  616. }
  617. public void set_erp_reset()
  618. {
  619. if (UrlPostParmsCheck("ctid"))
  620. {
  621. string eid = GetPostString("ctid");
  622. CeErpTradeCell entity = null;
  623. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  624. if (entity != null)
  625. {
  626. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  627. {
  628. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  629. {
  630. returnErrorMsg("财务要求已下单已发货无法重置");
  631. return;
  632. }
  633. }
  634. entity.IsUrgency = false;
  635. entity.seller_memo = "";
  636. entity.OtherMemo = "";
  637. entity.OrderState = 0;
  638. entity.IsReturn = 0;
  639. //entity.IsRefund = 0;
  640. entity.MemoOpt = 0;
  641. entity.AfterSaleState = 0;
  642. entity.AfterSaleResponsible = "";
  643. entity.AfterSaleUserId = 0;
  644. entity.IsNeedBill = 0;
  645. entity.CustomerUserId = 0;
  646. entity.DesignUserId = 0;
  647. entity.SupplierId = 0;
  648. entity.PlaceUserId = 0;
  649. entity.ptid = "";
  650. entity.IsSample = 0;
  651. entity.IsXianHuo = 0;
  652. entity.isDianziOrder = 0;
  653. entity.DispatchSort = 0;
  654. entity.FinishPlaceTime = null;
  655. entity.Update();
  656. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  657. if (trade != null)
  658. {
  659. trade.seller_memo = "";
  660. trade.Update();
  661. }
  662. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  663. returnSuccessMsg("重置成功!");
  664. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  665. if (desginBill != null)
  666. {
  667. desginBill.isDel = 1;
  668. desginBill.Update();
  669. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  670. }
  671. ApiVo apiVo = new ApiVo();
  672. apiVo.orderNumber = entity.ctid;
  673. apiVo.actionName = "resetDesign";
  674. designHelper.API_WorkCore(apiVo);//resetDesign
  675. return;
  676. }
  677. returnErrorMsg("找不到记录");
  678. }
  679. }
  680. public void save_erp_sellermemo()
  681. {
  682. if (UrlPostParmsCheck("ctid"))
  683. {
  684. string ctid = GetPostString("ctid");
  685. CeErpTradeCell entity = null;
  686. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  687. if (entity != null)
  688. {
  689. string memo = GetPostString("seller_memo");
  690. memo = memo.Replace(" ", "");
  691. if (memo.Contains("补差"))
  692. {
  693. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  694. return;
  695. }
  696. List<string> bitList = new List<string>
  697. {
  698. "\\","/",":","*","?", "\"","<" ,">","|"
  699. };
  700. bool isIn = false;
  701. foreach (string bit in bitList)
  702. {
  703. if (memo.Contains(bit))
  704. {
  705. isIn = true;
  706. }
  707. }
  708. if (isIn)
  709. {
  710. returnErrorMsg("不能使用 一些符合作为文件名");
  711. return;
  712. }
  713. if (entity.seller_memo != memo)
  714. {
  715. if (entity.IsSample == 2)
  716. {
  717. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  718. return;
  719. }
  720. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  721. {
  722. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  723. {
  724. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  725. return;
  726. }
  727. /*if (CurrentUser.UserPost.Post.Code != "Place")
  728. {
  729. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  730. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  731. {
  732. returnErrorMsg("售前系统订单无法再此修改!");
  733. return;
  734. }
  735. }*/
  736. }
  737. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  738. }
  739. commonHelper.getCytPrice(entity);
  740. int memoopt = GetPostInt("MemoOpt");
  741. Boolean ismemoopt = false;
  742. if (memoopt > 0)
  743. {
  744. string stropt = "";
  745. if (memoopt == 1)
  746. {
  747. stropt = "“改稿”";
  748. ismemoopt = true;
  749. }
  750. else if (memoopt == 2)
  751. {
  752. stropt = "“定稿”";
  753. }
  754. else if (memoopt == 3)
  755. {
  756. stropt = "“查货”";
  757. CeErpSukuraData.createInfo(entity.ctid, 6);
  758. }
  759. entity.MemoOpt = Convert.ToInt32(memoopt);
  760. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  761. }
  762. if (entity.OrderState < 5)
  763. {
  764. memo = memo.Replace("(", "(");
  765. memo = memo.Replace(")", ")");
  766. }
  767. if (entity.OrderState < 3)
  768. {
  769. entity.DispatchSort = 0;
  770. }
  771. entity.seller_memo = memo;
  772. entity.UpdateTime = DateTime.Now;
  773. entity.Update();
  774. ApiVo apiVo = new ApiVo();
  775. apiVo.orderNumber = entity.ctid;
  776. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  777. apiVo.orderRemarks = memo;
  778. apiVo.remarkSign = memoopt;
  779. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  780. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  781. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  782. {
  783. dataHelper.api_orderBack(entity.ctid, "0", "");
  784. }
  785. if (entity.seller_memo.Contains("改稿"))
  786. {
  787. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  788. }
  789. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  790. returnSuccessMsg("保存成功!");
  791. return;
  792. }
  793. returnErrorMsg("找不到记录");
  794. }
  795. }
  796. public void ins_erp_checkorder()
  797. {
  798. if (UrlPostParmsCheck("ctid"))
  799. {
  800. string ctid = GetPostString("ctid");
  801. CeErpTradeCell entity = null;
  802. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  803. if (entity != null)
  804. {
  805. if (entity.OrderState < 6)
  806. {
  807. returnErrorMsg("下单完成后才可查货");
  808. return;
  809. }
  810. /*if (entity.OrderState > 6)
  811. {
  812. returnErrorMsg("订单已发货");
  813. return;
  814. }*/
  815. if (entity.FinishPlaceTime != null)
  816. {
  817. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  818. {
  819. returnErrorMsg("下单时间不足,无法查货");
  820. return;
  821. }
  822. }
  823. entity.MemoOpt = 3;
  824. entity.CheckOrderTime = DateTime.Now;
  825. entity.UpdateTime = DateTime.Now;
  826. entity.Update();
  827. CeErpSukuraData.createInfo(entity.ctid, 6);
  828. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  829. returnSuccessMsg("操作成功!");
  830. return;
  831. }
  832. returnErrorMsg("找不到记录");
  833. }
  834. }
  835. public void save_erp_othermemo()
  836. {
  837. if (UrlPostParmsCheck("ctid"))
  838. {
  839. string ctid = GetPostString("ctid");
  840. CeErpTradeCell entity = null;
  841. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  842. if (entity != null)
  843. {
  844. entity.OtherMemo = GetPostString("otherMemo");
  845. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  846. {
  847. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  848. StringBuilder sql = new StringBuilder();
  849. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  850. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  851. if (dt != null && dt.Rows.Count > 0)
  852. {
  853. foreach (DataRow dr in dt.Rows)
  854. {
  855. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  856. {
  857. //品类一直
  858. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  859. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  860. if (ceErpSampleCustomer == null)
  861. {
  862. ceErpSampleCustomer = new CeErpSampleCustomer();
  863. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  864. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  865. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  866. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  867. ceErpSampleCustomer.shopId = entity.ShopId;
  868. }
  869. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  870. ceErpSampleCustomer.lastTid = entity.tid;
  871. if (ceErpSampleCustomer.ID > 0)
  872. {
  873. ceErpSampleCustomer.Update();
  874. }
  875. else
  876. {
  877. ceErpSampleCustomer.Create();
  878. }
  879. }
  880. }
  881. }
  882. }
  883. //if (entity.IsOldCustomer == 1)
  884. //{
  885. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  886. //{
  887. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  888. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  889. //}
  890. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  891. //{
  892. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  893. // {
  894. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  895. // {
  896. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  897. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  898. // }
  899. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  900. // {
  901. // entity.OrderState = 2;
  902. // entity.DesignUserId = 0;
  903. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  904. // }
  905. // else
  906. // {
  907. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  908. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  909. // }
  910. // }
  911. //}
  912. //}
  913. entity.UpdateTime = DateTime.Now;
  914. entity.Update();
  915. returnSuccessMsg("保存成功!");
  916. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  917. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  918. if (entity.OtherMemo.Contains("改稿"))
  919. {
  920. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  921. }
  922. return;
  923. }
  924. returnErrorMsg("找不到记录");
  925. }
  926. }
  927. public void save_erp_customermemo()
  928. {
  929. if (UrlPostParmsCheck("ctid"))
  930. {
  931. string ctid = GetPostString("ctid");
  932. CeErpTradeCell entity = null;
  933. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  934. if (entity != null)
  935. {
  936. entity.UpdateTime = DateTime.Now;
  937. entity.CustomerMemo = GetPostString("CustomerMemo");
  938. entity.Update();
  939. ApiVo apiVo = new ApiVo();
  940. apiVo.orderNumber = entity.ctid;
  941. apiVo.actionName = "followRemarks";
  942. apiVo.orderRemarks = entity.CustomerMemo;
  943. designHelper.API_WorkCore(apiVo);//followRemarks
  944. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  945. returnSuccessMsg("保存成功!");
  946. return;
  947. }
  948. returnErrorMsg("找不到记录");
  949. }
  950. }
  951. public void upd_erp_addmemotag()
  952. {
  953. if (UrlPostParmsCheck("ctid"))
  954. {
  955. ;
  956. string eid = GetPostString("ctid");
  957. string sfTagstr = GetPostString("memotag");
  958. CeErpTradeCell entity = null;
  959. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  960. if (entity != null)
  961. {
  962. ApiVo apiVo = new ApiVo();
  963. if (entity.OrderState == 0)
  964. {
  965. returnErrorMsg("请先领单");
  966. return;
  967. }
  968. //撤销顺丰
  969. if (sfTagstr == "撤销顺丰")
  970. {
  971. entity.IsSF = 0;
  972. string reMsg = "";
  973. string oldmemo = entity.seller_memo;
  974. if (entity.OrderState < 5)
  975. {
  976. oldmemo = oldmemo.Replace("顺丰到付", "");
  977. oldmemo = oldmemo.Replace("顺丰寄付", "");
  978. entity.seller_memo = oldmemo;
  979. }
  980. else
  981. {
  982. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  983. {
  984. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  985. }
  986. }
  987. entity.Update();
  988. apiVo.orderNumber = entity.ctid;
  989. apiVo.actionName = "orderRemarks";
  990. apiVo.orderRemarks = entity.seller_memo;
  991. apiVo.isSf = entity.IsSF.ToString();
  992. designHelper.API_WorkCore(apiVo);//orderRemarks
  993. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  994. returnSuccessMsg("撤销成功!" + reMsg);
  995. return;
  996. }
  997. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  998. {
  999. //string oldmemo = entity.seller_memo;
  1000. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1001. string sfStr = GetPostString("memotag");
  1002. string smemo = entity.seller_memo;
  1003. int kindex = smemo.IndexOf(")");
  1004. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1005. if (lastoneStr != "-")
  1006. {
  1007. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1008. }
  1009. string prememo = smemo.Substring(0, kindex + 2);
  1010. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1011. int lastkindex = lastmemo.IndexOf("(");
  1012. string newlastmemo = "";
  1013. if (lastkindex == 0)
  1014. {
  1015. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1016. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1017. }
  1018. else
  1019. {
  1020. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1021. }
  1022. entity.seller_memo = prememo + newlastmemo;
  1023. }
  1024. string sfTagMSg = "";
  1025. if (sfTagstr == "顺丰寄付")
  1026. {
  1027. entity.IsSF = 1;
  1028. sfTagMSg = "顺丰寄付";
  1029. }
  1030. else if (sfTagstr == "顺丰到付")
  1031. {
  1032. entity.IsSF = 2;
  1033. sfTagMSg = "顺丰到付";
  1034. }
  1035. entity.Update();
  1036. apiVo = new ApiVo();
  1037. apiVo.orderNumber = entity.ctid;
  1038. apiVo.actionName = "orderRemarks";
  1039. apiVo.orderRemarks = entity.seller_memo;
  1040. apiVo.isSf = entity.IsSF.ToString();
  1041. designHelper.API_WorkCore(apiVo);//orderRemarks
  1042. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1043. returnSuccessMsg("标记成功!");
  1044. return;
  1045. }
  1046. returnErrorMsg("找不到记录");
  1047. }
  1048. }
  1049. public void upd_erp_ordertag()
  1050. {
  1051. if (UrlPostParmsCheck("ctid"))
  1052. {
  1053. string eid = GetPostString("ctid");
  1054. CeErpTradeCell entity = null;
  1055. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1056. if (entity != null)
  1057. {
  1058. int tag = GetPostInt("wechattag");
  1059. //if(tag==4 && entity.IsSample == 2)
  1060. //{
  1061. // returnErrorMsg("补差价单不能标记微信单");
  1062. // return;
  1063. //}
  1064. entity.wechatTag = tag;
  1065. entity.Update();
  1066. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1067. if (tag == 1)
  1068. {
  1069. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1070. if (cash == null)
  1071. {
  1072. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1073. cash = new CeErpReturnCash();
  1074. cash.tid = entity.tid;
  1075. cash.seller_nick = main.seller_nick;
  1076. cash.payment = trade.payment;
  1077. cash.buyer_nick = main.buyer_nick;
  1078. cash.cashstate = 0;
  1079. cash.rtype = "微信返现";
  1080. cash.returnprice = 0;
  1081. cash.created = DateTime.Now;
  1082. cash.con = "订单标记微信单";
  1083. cash.img = "";
  1084. cash.applyuserid = CurrentUser.UserID;
  1085. cash.Create();
  1086. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1087. }
  1088. else
  1089. {
  1090. cash.cashstate = 0;
  1091. cash.Update();
  1092. }
  1093. CeErpSukuraData.createInfo(entity.ctid, 9);
  1094. }
  1095. else if (tag == 2)
  1096. {
  1097. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1098. if (cash == null)
  1099. {
  1100. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1101. cash = new CeErpReturnCash();
  1102. cash.tid = entity.tid;
  1103. cash.seller_nick = main.seller_nick;
  1104. cash.payment = trade.payment;
  1105. cash.buyer_nick = main.buyer_nick;
  1106. cash.cashstate = 0;
  1107. cash.rtype = "推购返现";
  1108. cash.returnprice = 5;
  1109. cash.created = DateTime.Now;
  1110. cash.con = "订单标记推购单";
  1111. cash.img = "";
  1112. cash.applyuserid = CurrentUser.UserID;
  1113. cash.Create();
  1114. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1115. }
  1116. else
  1117. {
  1118. cash.cashstate = 0;
  1119. cash.Update();
  1120. }
  1121. CeErpSukuraData.createInfo(entity.ctid, 9);
  1122. }
  1123. else if (tag == 3)
  1124. {
  1125. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1126. if (pers == null)
  1127. {
  1128. pers = new CeErpPersuade();
  1129. pers.ctid = entity.ctid;
  1130. pers.pstate = 0;
  1131. pers.created = DateTime.Now;
  1132. pers.applyuserid = CurrentUser.UserID;
  1133. pers.Create();
  1134. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1135. }
  1136. else
  1137. {
  1138. pers.pstate = 0;
  1139. pers.Update();
  1140. }
  1141. }
  1142. else if (tag == 4 || tag == 5)
  1143. {
  1144. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1145. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1146. if (pers == null)
  1147. {
  1148. pers = CeErpStayGoods.GetByTid(entity.tid);
  1149. }
  1150. if (pers == null)
  1151. {
  1152. pers = new CeErpStayGoods();
  1153. pers.t_id = entity.tid;
  1154. pers.ctid = entity.ctid;
  1155. pers.status = "待审核";
  1156. pers.audit_type = 0;
  1157. if (tag == 4)
  1158. {
  1159. pers.stay_type = "微信推购";
  1160. }
  1161. else
  1162. {
  1163. pers.stay_type = "旺旺推购";
  1164. }
  1165. if (entity.IsXianHuo == 0)
  1166. {
  1167. pers.product_id = entity.ProductId;
  1168. }
  1169. pers.wangwang = main.buyer_nick;
  1170. pers.shop_name = main.seller_nick;
  1171. pers.creata_time = DateTime.Now;
  1172. pers.create_u_id = CurrentUser.UserID;
  1173. pers.create_u_name = CurrentUser.UserName;
  1174. pers.Create();
  1175. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1176. }
  1177. else
  1178. {
  1179. pers.ctid = entity.ctid;
  1180. pers.audit_type = 0;
  1181. pers.Update();
  1182. }
  1183. CeErpSukuraData.createInfo(entity.ctid, 10);
  1184. }
  1185. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1186. returnSuccessMsg("标记成功!");
  1187. return;
  1188. }
  1189. returnErrorMsg("找不到记录");
  1190. }
  1191. }
  1192. public void upd_erp_ordertag_cancel()
  1193. {
  1194. if (UrlPostParmsCheck("ctid"))
  1195. {
  1196. string eid = GetPostString("ctid");
  1197. CeErpTradeCell entity = null;
  1198. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1199. if (entity != null)
  1200. {
  1201. entity.wechatTag = 0;
  1202. entity.Update();
  1203. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1204. if (pers != null)
  1205. {
  1206. pers.status = "取消推购";
  1207. pers.audit_type = 3;
  1208. pers.Update();
  1209. }
  1210. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1211. returnSuccessMsg("标记成功!");
  1212. return;
  1213. }
  1214. returnErrorMsg("找不到记录");
  1215. }
  1216. }
  1217. public void upd_erp_addweichattag()
  1218. {
  1219. if (UrlPostParmsCheck("ctid"))
  1220. {
  1221. ;
  1222. string eid = GetPostString("ctid");
  1223. CeErpTradeCell entity = null;
  1224. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1225. if (entity != null)
  1226. {
  1227. if (entity.IsAddWechat > 0)
  1228. {
  1229. returnErrorMsg("此单已经标记过了");
  1230. return;
  1231. }
  1232. string sql = string.Format("select * from view_erptradecell where IsAddWechat>0 and buyer_nick=(select buyer_nick from ce_erptrade where tid='{0}')", entity.tid);
  1233. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1234. if (dt.Rows.Count > 0)
  1235. {
  1236. entity.IsAddWechat = 2;
  1237. }
  1238. else
  1239. {
  1240. entity.IsAddWechat = 1;
  1241. }
  1242. entity.Update();
  1243. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1244. returnSuccessMsg("标记成功!");
  1245. return;
  1246. }
  1247. returnErrorMsg("找不到记录");
  1248. }
  1249. }
  1250. public void upd_erp_getmyorder()
  1251. {
  1252. if (UrlPostParmsCheck("ctid"))
  1253. {
  1254. ;
  1255. string eid = GetPostString("ctid");
  1256. CeErpTradeCell entity = null;
  1257. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1258. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1259. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1260. {
  1261. returnErrorMsg("台湾客户需填写身份证号!");
  1262. return;
  1263. }
  1264. if (entity != null)
  1265. {
  1266. if (entity.ctid.IndexOf("C") != -1)
  1267. {
  1268. StringBuilder sql = new StringBuilder();
  1269. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1270. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1271. if (dt.Rows.Count > 0)
  1272. {
  1273. decimal total = 0;
  1274. foreach (DataRow dr in dt.Rows)
  1275. {
  1276. total += Convert.ToDecimal(dr["payment"]);
  1277. }
  1278. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1279. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1280. {
  1281. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1282. return;
  1283. }
  1284. }
  1285. }
  1286. if (entity.OrderState == -1)
  1287. {
  1288. returnErrorMsg("待审核订单无法领取!");
  1289. return;
  1290. }
  1291. entity.CustomerUserId = CurrentUser.UserID;
  1292. if (entity.OrderState < 2)
  1293. {
  1294. entity.OrderState = 2;
  1295. if (entity.ShopId != 0)
  1296. {
  1297. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1298. }
  1299. }
  1300. entity.UpdateTime = DateTime.Now;
  1301. entity.Update();
  1302. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1303. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1304. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1305. {
  1306. dataHelper.api_orderBack(entity.ctid, "0", "");
  1307. }
  1308. returnSuccessMsg("领单成功!");
  1309. return;
  1310. }
  1311. returnErrorMsg("找不到记录");
  1312. }
  1313. }
  1314. public void getmyorder_from_init()
  1315. {
  1316. if (UrlPostParmsCheck("ctid"))
  1317. {
  1318. string eid = GetPostString("ctid");
  1319. CeErpTradeCell entity = null;
  1320. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1321. if (entity != null)
  1322. {
  1323. string sellerMemo = GetPostString("sellerMemo");
  1324. if (sellerMemo.Length > 0)
  1325. {
  1326. entity.seller_memo = sellerMemo;
  1327. }
  1328. string oterhMemo = GetPostString("otherMemo");
  1329. if (oterhMemo.Length > 0)
  1330. {
  1331. entity.OtherMemo = oterhMemo;
  1332. }
  1333. int urg = GetPostInt("urgency");
  1334. entity.IsUrgency = (urg == 1 ? true : false);
  1335. int wechat = GetPostInt("wechat");
  1336. int command = GetPostInt("command");
  1337. if (wechat == 1)
  1338. {
  1339. entity.wechatTag = 1;
  1340. }
  1341. if (command == 1)
  1342. {
  1343. entity.wechatTag = 2;
  1344. }
  1345. string pPro = GetPostString("pprofession");
  1346. if (pPro.Length > 0)
  1347. {
  1348. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1349. string spro = GetPostString("profession");
  1350. if (spro.Length > 0)
  1351. {
  1352. entity.ProfessionId = Convert.ToInt32(spro);
  1353. }
  1354. }
  1355. string proId = GetPostString("productId");
  1356. if (proId.Length > 0)
  1357. {
  1358. entity.ProductId = Convert.ToInt32(proId);
  1359. }
  1360. entity.Material = GetPostString("material");
  1361. entity.Craft = GetPostString("craft");
  1362. entity.CustomerUserId = CurrentUser.UserID;
  1363. if (entity.OrderState < 2)
  1364. {
  1365. entity.OrderState = 2;
  1366. if (entity.ShopId != 0)
  1367. {
  1368. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1369. }
  1370. }
  1371. entity.Update();
  1372. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1373. returnSuccessMsg("领单成功!");
  1374. return;
  1375. }
  1376. returnErrorMsg("找不到记录");
  1377. }
  1378. }
  1379. public void upd_erp_setrelationorder()
  1380. {
  1381. if (UrlPostParmsCheck("ctid"))
  1382. {
  1383. ;
  1384. string eid = GetPostString("ctid");
  1385. string ftid = GetPostString("ftid");
  1386. CeErpTradeCell entity = null;
  1387. CeErpTradeCell fentity = null;
  1388. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1389. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1390. if (fentity == null)
  1391. {
  1392. returnErrorMsg("找不到关联的主订单");
  1393. return;
  1394. }
  1395. if (entity != null)
  1396. {
  1397. if (entity.OrderState >= 5)
  1398. {
  1399. returnErrorMsg("本单已经设计完成无法关联");
  1400. return;
  1401. }
  1402. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1403. {
  1404. returnErrorMsg("线下单续审核后才能关联!");
  1405. return;
  1406. }
  1407. entity.ptid = ftid;
  1408. entity.OrderState = fentity.OrderState;
  1409. //entity.status = fentity.status;
  1410. entity.CustomerUserId = fentity.CustomerUserId;
  1411. entity.DesignUserId = fentity.DesignUserId;
  1412. entity.seller_memo = "补差价单:" + ftid;
  1413. entity.IsSample = 2;
  1414. entity.Update();
  1415. ApiVo apiVo = new ApiVo();
  1416. apiVo.orderNumber = ftid;
  1417. apiVo.payment = entity.payment;
  1418. apiVo.actionName = "repairDesign";
  1419. designHelper.API_WorkCore(apiVo);//repairDesign
  1420. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1421. returnSuccessMsg("关联成功!");
  1422. return;
  1423. }
  1424. else
  1425. returnErrorMsg("找不到记录");
  1426. }
  1427. }
  1428. public void download_erp_neworder()
  1429. {
  1430. string seller = GetPostString("seller_nick");
  1431. string tid = GetPostString("tid");
  1432. if (seller.Length <= 0 || tid.Length <= 0)
  1433. {
  1434. returnErrorMsg("数据错误");
  1435. }
  1436. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1437. //{
  1438. // returnErrorMsg("找不到店铺Sessionkey");
  1439. //}
  1440. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1441. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1442. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1443. if (res.IndexOf("refOid") == -1)
  1444. {
  1445. returnErrorMsg("下载订单数据失败");
  1446. return;
  1447. }
  1448. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1449. returnSuccessMsg("下载完成");
  1450. //tmcHelper.createNewOrder(res);
  1451. //CeErpTrade entr = null;
  1452. //entr = CeErpTrade.Get(tid);
  1453. //if (entr != null)
  1454. //{
  1455. // returnSuccess("下载成功");
  1456. // //下载成功之后,Cell表生成对应的订单;
  1457. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1458. //}
  1459. //else
  1460. //{
  1461. // returnErrorMsg("下载失败或者创建订单失败");
  1462. //}
  1463. }
  1464. public void set_erp_atersale()
  1465. {
  1466. if (UrlPostParmsCheck("ctid"))
  1467. {
  1468. string eid = GetPostString("ctid");
  1469. string reason = GetPostString("AfterSaleReason");
  1470. CeErpTradeCell entity = null;
  1471. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1472. if (entity != null)
  1473. {
  1474. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1475. {
  1476. returnErrorMsg("此订单已经在售后");
  1477. return;
  1478. }
  1479. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1480. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1481. entity.AfterSaleTime = DateTime.Now;
  1482. entity.Update();
  1483. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1484. returnSuccessMsg("转售后成功!");
  1485. return;
  1486. }
  1487. returnErrorMsg("找不到记录");
  1488. }
  1489. }
  1490. public void set_erp_withdraw()
  1491. {
  1492. if (UrlPostParmsCheck("ctid"))
  1493. {
  1494. try
  1495. {
  1496. string eid = GetPostString("ctid");//商品id
  1497. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1498. CeWithdraw ceWithdrawSelect = null;
  1499. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1500. if (ceWithdrawSelect != null)
  1501. {
  1502. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1503. {
  1504. ceWithdrawSelect.status = -1;
  1505. ceWithdrawSelect.Update();
  1506. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1507. returnSuccessMsg("重新发起审核成功");
  1508. return;
  1509. }
  1510. else
  1511. {
  1512. returnSuccessMsg("请勿重复申请!");
  1513. return;
  1514. }
  1515. }
  1516. else
  1517. {
  1518. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1519. if (string.IsNullOrEmpty(CustomerUserId))
  1520. {
  1521. CustomerUserId = "-1";
  1522. }
  1523. int Userid = CurrentUser.UserID;//用户id
  1524. CeWithdraw ceWithdraw = new CeWithdraw();
  1525. ceWithdraw.tid = eid;
  1526. ceWithdraw.userid = Userid;
  1527. ceWithdraw.providerid = CustomerUserId;
  1528. ceWithdraw.status = 3;
  1529. ceWithdraw.creationtime = DateTime.Now;
  1530. ceWithdraw.Create();
  1531. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1532. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1533. return;
  1534. }
  1535. }
  1536. catch
  1537. {
  1538. returnErrorMsg("申请撤回订单失败");
  1539. return;
  1540. }
  1541. }
  1542. }
  1543. public void ins_erp_billinfo()
  1544. {
  1545. if (UrlPostParmsCheck("ctid"))
  1546. {
  1547. string eid = GetPostString("ctid");
  1548. CeErpTradeCell entity = null;
  1549. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1550. if (entity != null)
  1551. {
  1552. CeErpBill bill = CeErpBill.GetByTid(eid);
  1553. bool isHave = false;
  1554. if (bill != null)
  1555. {
  1556. isHave = true;
  1557. if (bill.state != 4)
  1558. {
  1559. returnErrorMsg("此单已经申请过发票了");
  1560. return;
  1561. }
  1562. }
  1563. if (entity.IsNeedBill == 0)
  1564. {
  1565. entity.IsNeedBill = 1;
  1566. }
  1567. entity.Update();
  1568. string errjson = "";
  1569. try
  1570. {
  1571. CeErpBill bill_entity = new CeErpBill();
  1572. bill_entity.tid = entity.tid;
  1573. bill_entity.title = GetPostString("title");
  1574. string taxstr = GetPostString("tax");
  1575. taxstr = taxstr.Replace(" ", "");
  1576. bill_entity.tax = taxstr;
  1577. bill_entity.bank = GetPostString("bank");
  1578. string bankacstr = GetPostString("bankac");
  1579. bankacstr = bankacstr.Replace(" ", "");
  1580. bill_entity.bankac = bankacstr;
  1581. bill_entity.address = GetPostString("address");
  1582. bill_entity.phone = GetPostString("phone");
  1583. bill_entity.price = GetPostString("price");
  1584. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1585. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1586. {
  1587. billCount += 1;
  1588. }
  1589. string prebill = "ltb";
  1590. for (int idx = 1; idx <= billCount; idx++)
  1591. {
  1592. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1593. string billoid = prebill + idx + dtstr;
  1594. bill_entity.billOrderId += billoid;
  1595. if (idx < billCount)
  1596. {
  1597. bill_entity.billOrderId += ",";
  1598. }
  1599. }
  1600. bill_entity.productId = GetPostInt("ProductName");
  1601. bill_entity.num = GetPostInt("num");
  1602. bill_entity.unit = GetPostString("unit");
  1603. bill_entity.type = GetPostString("type");
  1604. bill_entity.sendType = GetPostString("SendType");
  1605. bill_entity.email = GetPostString("email");
  1606. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1607. bill_entity.shopName = GetPostString("ShopName");
  1608. bill_entity.applymemo = GetPostString("applyMemo");
  1609. bill_entity.createTime = DateTime.Now;
  1610. bill_entity.state = 0;
  1611. bill_entity.userId = CurrentUser.UserID;
  1612. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1613. bill_entity.Create();
  1614. }
  1615. catch (Exception ex)
  1616. {
  1617. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1618. returnErrorMsg("创建发票出错!");
  1619. return;
  1620. }
  1621. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1622. returnSuccessMsg("发票申请成功!");
  1623. return;
  1624. }
  1625. returnErrorMsg("找不到记录");
  1626. }
  1627. }
  1628. public void ins_erp_neworder()
  1629. {
  1630. if (UrlPostParmsCheck("receiver_name"))
  1631. {
  1632. CeErpTrade entity = new CeErpTrade();
  1633. string plat_form = GetPostString("platform");
  1634. string preStr = "N_";
  1635. if (plat_form == "拼多多")
  1636. {
  1637. preStr = "P_";
  1638. }
  1639. else if (plat_form == "阿里巴巴")
  1640. {
  1641. preStr = "A_";
  1642. }
  1643. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1644. entity.seller_nick = GetPostString("seller_nick");
  1645. entity.buyer_nick = GetPostString("buyer_nick");
  1646. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1647. entity.total_fee = entity.payment;
  1648. entity.pay_time = DateTime.Now;
  1649. entity.status = "NOT_SHIPPED";
  1650. entity.receiver_name = GetPostString("receiver_name");
  1651. entity.receiver_mobile = GetPostString("receiver_mobile");
  1652. entity.receiver_state = GetPostString("receiver_state");
  1653. entity.receiver_city = GetPostString("receiver_city");
  1654. entity.receiver_district = GetPostString("receiver_district");
  1655. entity.receiver_address = GetPostString("receiver_address");
  1656. if (entity.receiver_state == "" || entity.receiver_city == "")
  1657. {
  1658. returnErrorMsg("收件地址不能为空");
  1659. return;
  1660. }
  1661. int shopId = 0;
  1662. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1663. if (nShop != null)
  1664. {
  1665. shopId = nShop.ID;
  1666. }
  1667. if (shopId != 34 && entity.payment == 0)
  1668. {
  1669. returnErrorMsg("公司自用的单金额才能为0");
  1670. return;
  1671. }
  1672. entity.Create();
  1673. CeErpTradeCell entitycell = new CeErpTradeCell();
  1674. entitycell.ctid = entity.tid;
  1675. entitycell.tid = entity.tid;
  1676. entitycell.ShopId = shopId;
  1677. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1678. entitycell.OrderState = 0;
  1679. entitycell.pay_time = entity.pay_time;
  1680. entitycell.IsOffLineOrder = 1;
  1681. entitycell.Create();
  1682. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1683. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1684. return;
  1685. }
  1686. }
  1687. public void ins_erp_neworder2()
  1688. {
  1689. if (UrlPostParmsCheck("receiver_name"))
  1690. {
  1691. //string plat_form = GetPostString("platform");
  1692. string preStr = "X_";
  1693. string memo = GetPostString("memo");
  1694. string productId = GetPostString("productId");
  1695. string primg = GetPostString("proofimg");
  1696. string sellerNick = GetPostString("seller_nick");
  1697. string addFrom = GetPostString("addfrom");
  1698. if (addFrom == "1")
  1699. {
  1700. preStr = "N_";
  1701. }
  1702. int shopId = 0;
  1703. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1704. if (nShop != null)
  1705. {
  1706. shopId = nShop.ID;
  1707. }
  1708. else
  1709. {
  1710. returnErrorMsg("找不到对应店铺");
  1711. return;
  1712. }
  1713. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1714. {
  1715. returnErrorMsg("必须上传付款凭证");
  1716. return;
  1717. }
  1718. CeErpTrade entity = new CeErpTrade();
  1719. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1720. entity.seller_nick = sellerNick;
  1721. entity.buyer_nick = GetPostString("buyer_nick");
  1722. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1723. entity.total_fee = entity.payment;
  1724. entity.pay_time = DateTime.Now;
  1725. entity.status = "NOT_SHIPPED";
  1726. entity.receiver_name = GetPostString("receiver_name");
  1727. entity.receiver_mobile = GetPostString("receiver_mobile");
  1728. entity.receiver_state = GetPostString("receiver_state");
  1729. entity.receiver_city = GetPostString("receiver_city");
  1730. entity.receiver_district = GetPostString("receiver_district");
  1731. entity.receiver_address = GetPostString("receiver_address");
  1732. entity.seller_memo = memo;
  1733. entity.orderFrom = 20;
  1734. entity.orderType = 15;
  1735. if (entity.receiver_state == "" || entity.receiver_city == "")
  1736. {
  1737. returnErrorMsg("收件地址不能为空");
  1738. return;
  1739. }
  1740. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1741. {
  1742. returnErrorMsg("公司自用的单金额才能为0");
  1743. return;
  1744. }
  1745. entity.Create();
  1746. string toWhere = GetPostString("towhere");
  1747. CeErpTradeCell entitycell = new CeErpTradeCell();
  1748. entitycell.ctid = entity.tid;
  1749. //唯一标识
  1750. entitycell.OrderSn = entity.tid;
  1751. string orderSn = dataHelper.getSaleOrderSn();
  1752. if (orderSn != "")
  1753. {
  1754. entitycell.OrderSn = orderSn;
  1755. }
  1756. entitycell.tid = entity.tid;
  1757. //if (preStr == "X_")
  1758. //{
  1759. entitycell.IsOffLineOrder = 1;
  1760. //}
  1761. entitycell.CustomerUserId = CurrentUser.UserID;
  1762. entitycell.PayProofImg = primg;
  1763. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1764. entitycell.ProductId = Convert.ToInt32(productId);
  1765. entitycell.ShopId = shopId;
  1766. entitycell.UpdateTime = DateTime.Now;
  1767. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1768. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1769. {
  1770. entitycell.IsXianHuo = 1;
  1771. }
  1772. entitycell.pay_time = entity.pay_time;
  1773. if (toWhere == "1")
  1774. {
  1775. entitycell.OrderState = 2;
  1776. }
  1777. else
  1778. {
  1779. entitycell.OrderState = 6;
  1780. entitycell.FinishPlaceTime = entitycell.pay_time;
  1781. }
  1782. if (shopId == 94)
  1783. {
  1784. entitycell.OrderState = 4;
  1785. entitycell.WaitDesignTime = entitycell.pay_time;
  1786. entitycell.StartDesignTime = entitycell.pay_time;
  1787. entitycell.DesignUserId = 218;
  1788. }
  1789. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1790. {
  1791. entitycell.OrderState = -1;//修改12-5
  1792. CeWithdraw ceWithdraw = new CeWithdraw();
  1793. ceWithdraw.tid = entity.tid;
  1794. ceWithdraw.providerid = "-1";
  1795. ceWithdraw.status = -1;
  1796. ceWithdraw.creationtime = DateTime.Now;
  1797. ceWithdraw.userid = 1337;
  1798. ceWithdraw.Create();
  1799. }
  1800. entitycell.Create();
  1801. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1802. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1803. {
  1804. addPlaceRegist(entitycell, CurrentUser.UserID);
  1805. }
  1806. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1807. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1808. return;
  1809. }
  1810. }
  1811. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1812. {
  1813. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1814. entity.PlactTime = tradecell.pay_time;
  1815. entity.AddUserId = userid;
  1816. entity.FileName = tradecell.seller_memo;
  1817. entity.Supplier = 24;
  1818. entity.CreateTime = DateTime.Now;
  1819. entity.Did = tradecell.ctid;
  1820. entity.tid = tradecell.tid;
  1821. entity.splitTag = tradecell.SplitTag;
  1822. entity.CurState = "未完成";
  1823. entity.Create();
  1824. }
  1825. public void get_erp_offlinelist()
  1826. {
  1827. DataStruct dStruct = GetPostStruct();
  1828. List<string> lw = new List<string>();
  1829. string tid = GetPostString("ctid");
  1830. string date1 = GetPostString("date1");
  1831. string date2 = GetPostString("date2");
  1832. if (tid.Length > 0 || date1.Length > 0)
  1833. {
  1834. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1835. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1836. if (dw.Length > 0) lw.Add(dw);
  1837. }
  1838. else
  1839. {
  1840. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1841. }
  1842. string shopname = GetPostString("shopname");
  1843. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1844. string buyernick = GetPostString("buyer_nick");
  1845. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1846. string customer = GetPostString("customer");
  1847. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1848. string design = GetPostString("design");
  1849. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1850. string orderState = GetPostString("orderState");
  1851. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1852. string address = GetPostString("address");
  1853. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  1854. string sellermemo = GetPostString("seller_memo");
  1855. if (sellermemo.Length > 0)
  1856. {
  1857. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1858. }
  1859. string price1 = GetPostString("price1");
  1860. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1861. string price2 = GetPostString("price2");
  1862. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1863. //if (PKey != "admin")
  1864. //{
  1865. // string usershop = CurrentUser.User.pemShop;
  1866. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1867. //}
  1868. //if (ex_psize > 0)
  1869. //{
  1870. dStruct.Order = "pay_time desc";
  1871. //}
  1872. //else
  1873. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1874. lw.Add(string.Format("IsOffLineOrder=1"));
  1875. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1876. DataTable dt = null;
  1877. dt = WebCache.GetData("view_erptradecell", dStruct);
  1878. writeGridDataTableJson(dStruct.TotalCount, dt);
  1879. }
  1880. public void get_erp_returncashrecord()
  1881. {
  1882. DataStruct dStruct = GetPostStruct();
  1883. List<string> lw = new List<string>();
  1884. string tid = GetPostString("ctid");
  1885. if (tid.Length > 0)
  1886. {
  1887. lw.Add(string.Format("tid like '%{0}%'", tid));
  1888. dStruct.Order = "id desc";
  1889. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1890. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1891. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1892. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1893. return;
  1894. }
  1895. returnErrorMsg("id数据错误!");
  1896. }
  1897. public void ins_erp_returncashrecord()
  1898. {
  1899. if (UrlPostParmsCheck("tid"))
  1900. {
  1901. string tid = GetPostString("tid");
  1902. string retype = GetPostString("type");
  1903. StringBuilder sql = new StringBuilder();
  1904. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1905. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1906. if (dt.Rows.Count > 0)
  1907. {
  1908. returnErrorMsg("相同返现类型记录已存在");
  1909. return;
  1910. }
  1911. CeErpReturnCash entity = new CeErpReturnCash();
  1912. entity.tid = tid;
  1913. entity.seller_nick = GetPostString("seller_nick");
  1914. string pment = GetPostString("payment");
  1915. if (pment.Length > 0)
  1916. {
  1917. entity.payment = Convert.ToDouble(pment);
  1918. }
  1919. entity.buyer_nick = GetPostString("buyer_nick");
  1920. entity.cashstate = 0;
  1921. entity.rtype = retype;
  1922. string rPrice = GetPostString("returnprice");
  1923. if (rPrice.Length > 0)
  1924. {
  1925. entity.returnprice = Convert.ToDouble(rPrice);
  1926. }
  1927. entity.created = DateTime.Now;
  1928. entity.con = GetPostString("con");
  1929. entity.img = GetPostString("img");
  1930. entity.applyuserid = CurrentUser.UserID;
  1931. entity.Create();
  1932. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1933. returnSuccessMsg("操作成功!");
  1934. return;
  1935. }
  1936. }
  1937. public void set_erp_predelivery()
  1938. {
  1939. if (UrlPostParmsCheck("ctid"))
  1940. {
  1941. string eid = GetPostString("ctid");
  1942. CeErpTradeCell entity = null;
  1943. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1944. if (entity != null)
  1945. {
  1946. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1947. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1948. //{
  1949. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1950. // return;
  1951. //}
  1952. entity.IsPreDelivery = 1;
  1953. entity.Update();
  1954. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1955. returnSuccessMsg("预发货成功!");
  1956. return;
  1957. //string shop = GetPostString("seller_nick");
  1958. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1959. //string comName = GetPostString("comName");
  1960. //string comCode = GetPostString("comCode");
  1961. //string outSid = GetPostString("outSid");//运单号
  1962. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1963. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1964. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1965. //string apires = "";
  1966. //if (deliveryType == "虚拟发货")
  1967. //{
  1968. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1969. //}
  1970. //else
  1971. //{
  1972. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1973. //}
  1974. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1975. ////{
  1976. //if (apires.IndexOf("发货成功") != -1)
  1977. //{
  1978. // if (deliveryType != "虚拟发货")
  1979. // {
  1980. // //还要插入快递信息到 快递信息表
  1981. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1982. // exinfo.tid = eid;
  1983. // exinfo.out_sid = outSid;
  1984. // exinfo.company_code = comCode;
  1985. // exinfo.company_name = comName;
  1986. // exinfo.delivery_memo = deliveryMemo;
  1987. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1988. // exinfo.deliveryType = deliveryType;
  1989. // exinfo.Create();
  1990. // }
  1991. // returnSuccessMsg("发货成功!");
  1992. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1993. //}
  1994. //else
  1995. //{
  1996. // returnErrorMsg("淘宝发货失败!!");
  1997. //}
  1998. //return;
  1999. }
  2000. returnErrorMsg("找不到订单记录");
  2001. }
  2002. }
  2003. public void get_erp_unusuallist()
  2004. {
  2005. DataStruct dStruct = GetPostStruct();
  2006. List<string> lw = new List<string>();
  2007. string tid = GetPostString("ctid");
  2008. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2009. string shopname = GetPostString("shopname");
  2010. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2011. string buyernick = GetPostString("buyer_nick");
  2012. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2013. string ResponsibleMan = GetPostString("responsible");
  2014. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2015. string date1 = GetPostString("date1");
  2016. string date2 = GetPostString("date2");
  2017. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2018. if (dw.Length > 0) lw.Add(dw);
  2019. string price1 = GetPostString("price1");
  2020. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2021. string price2 = GetPostString("price2");
  2022. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2023. string orderState = GetPostString("orderState");
  2024. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2025. string sellermemo = GetPostString("seller_memo");
  2026. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2027. lw.Add(string.Format("UnusualTag > 0"));
  2028. lw.Add(string.Format("IsRefund<={0}", 1));
  2029. dStruct.Order = "pay_time desc";
  2030. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2031. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2032. writeGridDataTableJson(dStruct.TotalCount, dt);
  2033. }
  2034. public void set_erp_unusualtonomal()
  2035. {
  2036. if (UrlPostParmsCheck("ctid"))
  2037. {
  2038. string eid = GetPostString("ctid");
  2039. CeErpTradeCell entity = null;
  2040. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2041. if (entity != null)
  2042. {
  2043. entity.UnusualTag = -1;
  2044. entity.Update();
  2045. returnSuccessMsg("忽略成功!");
  2046. return;
  2047. }
  2048. returnErrorMsg("找不到记录");
  2049. }
  2050. }
  2051. public void ins_erp_unusualreason()
  2052. {
  2053. if (UrlPostParmsCheck("ctid"))
  2054. {
  2055. string eid = GetPostString("ctid");
  2056. CeErpTradeCell entity = null;
  2057. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2058. if (entity != null)
  2059. {
  2060. entity.MemoOpt = 4;
  2061. entity.UnusualCon = GetPostString("con");
  2062. entity.Update();
  2063. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2064. if (trade != null)
  2065. {
  2066. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2067. }
  2068. //查货是否超时
  2069. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2070. if (ceErpTradeCellExtend == null)
  2071. {
  2072. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2073. ceErpTradeCellExtend.ctid = entity.ctid;
  2074. }
  2075. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2076. {
  2077. ceErpTradeCellExtend.CheckOut += 1;
  2078. }
  2079. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2080. if (ceErpTradeCellExtend.ID > 0)
  2081. {
  2082. ceErpTradeCellExtend.Update();
  2083. }
  2084. else
  2085. {
  2086. ceErpTradeCellExtend.Create();
  2087. }
  2088. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2089. returnSuccessMsg("操作成功!");
  2090. return;
  2091. }
  2092. returnErrorMsg("找不到记录");
  2093. }
  2094. }
  2095. public void upd_erp_sampleorder()
  2096. {
  2097. if (UrlPostParmsCheck("ctid"))
  2098. {
  2099. string eid = GetPostString("ctid");
  2100. string[] eArr = eid.Split(',');
  2101. if (eArr.Length > 1)
  2102. {
  2103. List<string> eLst = new List<string>();
  2104. for (int i = 0; i < eArr.Length; i++)
  2105. {
  2106. eLst.Add("'" + eArr[i] + "'");
  2107. }
  2108. eid = string.Join(",", eLst.ToArray());
  2109. }
  2110. else
  2111. {
  2112. eid = "'" + eid + "'";
  2113. }
  2114. StringBuilder sql = new StringBuilder();
  2115. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2116. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2117. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2118. if (dt.Rows.Count > 0)
  2119. {
  2120. string errmsg = "";
  2121. foreach (DataRow dr in dt.Rows)
  2122. {
  2123. StringBuilder sqlsb = new StringBuilder();
  2124. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2125. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2126. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2127. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2128. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2129. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2130. {
  2131. continue;
  2132. }
  2133. else
  2134. {
  2135. string emsg = commonHelper.KeepChinese(apires);
  2136. errmsg += emsg;
  2137. }
  2138. }
  2139. if (errmsg.Length > 0)
  2140. {
  2141. returnErrorMsg(errmsg);
  2142. return;
  2143. }
  2144. returnSuccessMsg("操作成功");
  2145. return;
  2146. }
  2147. returnErrorMsg("找不到记录");
  2148. }
  2149. }
  2150. public void upd_erp_transcustomer()
  2151. {
  2152. if (UrlPostParmsCheck("ctid"))
  2153. {
  2154. string eid = GetPostString("ctid");
  2155. int userid = GetPostInt("CustomerUserId");
  2156. CeErpTradeCell entity = null;
  2157. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2158. if (entity != null)
  2159. {
  2160. //string[] mlist = entity.seller_memo.Split('-');
  2161. //string sql = "select * from view_erpuser where id=" + userid;
  2162. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2163. //if (dt != null && dt.Rows.Count > 0)
  2164. //{
  2165. // string nmemo = "";
  2166. // for(int i = 0; i < mlist.Length - 1; i++)
  2167. // {
  2168. // nmemo += mlist[i];
  2169. // nmemo += "-";
  2170. // }
  2171. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2172. // entity.seller_memo = nmemo;
  2173. //}
  2174. entity.CustomerUserId = userid;
  2175. entity.Update();
  2176. returnSuccessMsg("操作成功!");
  2177. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2178. return;
  2179. }
  2180. returnErrorMsg("找不到记录");
  2181. }
  2182. }
  2183. public void upd_erp_transdesigner()
  2184. {
  2185. if (UrlPostParmsCheck("ctid"))
  2186. {
  2187. string eids = GetPostString("ctid");
  2188. string[] ctidList = eids.Split(',');
  2189. int userid = GetPostInt("DesignUserId");
  2190. foreach (string ctid in ctidList)
  2191. {
  2192. CeErpTradeCell entity = null;
  2193. CeErpDesignerBill entitys = null;
  2194. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2195. entitys = CeErpDesignerBill.GetByTid(ctid);
  2196. if (entity != null)
  2197. {
  2198. if (entity.OrderState > 4)
  2199. {
  2200. continue;
  2201. }
  2202. //存在退款不能流转
  2203. if (entity.IsRefund > 0)
  2204. {
  2205. continue;
  2206. }
  2207. entity.DesignUserId = userid;
  2208. entity.WaitDesignTime = DateTime.Now;
  2209. entity.Update();
  2210. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2211. }
  2212. }
  2213. returnSuccessMsg("操作成功!");
  2214. }
  2215. }
  2216. public void upd_erp_distributedesigner()
  2217. {
  2218. if (UrlPostParmsCheck("ctid"))
  2219. {
  2220. string eid = GetPostString("ctid");
  2221. int userid = GetPostInt("DesignUserId");
  2222. string[] idlist = eid.Split(',');
  2223. if (idlist.Length <= 0)
  2224. {
  2225. returnErrorMsg("订单不能为空");
  2226. return;
  2227. }
  2228. foreach (string ctid in idlist)
  2229. {
  2230. CeErpTradeCell entity = null;
  2231. CeErpDesignerBill entitys = null;
  2232. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2233. else continue;
  2234. if (entity != null)
  2235. {
  2236. if (userid == 2125 || userid == 3542)
  2237. { }
  2238. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2239. {
  2240. returnErrorMsg("金额错误的订单无法指派");
  2241. return;
  2242. }
  2243. if (entity.OrderState >= 5)
  2244. {
  2245. returnErrorMsg("已经设计完成无法指派");
  2246. return;
  2247. }
  2248. if (entity.OrderState == -1)
  2249. {
  2250. returnErrorMsg("审核中的订单无法指派");
  2251. return;
  2252. }
  2253. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2254. {
  2255. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2256. return;
  2257. }
  2258. //157赖橙帆 159林晨 73 静之颖
  2259. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && CurrentUser.UserID != 157 && CurrentUser.UserID != 159 && CurrentUser.UserID != 1479 && CurrentUser.UserID != 73)
  2260. {
  2261. returnErrorMsg("指派设计共创无法再次指派!");
  2262. return;
  2263. }
  2264. entity.OrderState = 3;
  2265. if (entity.SupplierId == 0)
  2266. {
  2267. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2268. entity.SupplierId = suid;
  2269. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2270. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2271. }
  2272. if (userid == 2125 && entity.seller_memo != "")
  2273. {
  2274. apiDesign.API_GetPrintData_CreateOrder(entity);
  2275. }
  2276. if (userid == 3542 && entity.seller_memo != "")
  2277. {
  2278. string userPost = CurrentUser.UserPost.Post.Code;
  2279. if (CurrentUser.UserID == 73)
  2280. {
  2281. userPost = "SysAdmin";
  2282. }
  2283. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2284. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2285. if (response.msg != "设计共创:成功")
  2286. {
  2287. returnErrorMsg(response.msg);
  2288. return;
  2289. }
  2290. entity.DispatchSort = 2;
  2291. }
  2292. else
  2293. {
  2294. if (entity.DispatchSort == 2)
  2295. {
  2296. ApiVo apiVo = new ApiVo();
  2297. apiVo.actionName = "closeDesign";
  2298. apiVo.orderNumber = entity.ctid;
  2299. designHelper.API_WorkCore(apiVo);//closeDesign
  2300. }
  2301. entity.DispatchSort = 0;
  2302. }
  2303. entity.DesignUserId = userid;
  2304. entity.WaitDesignTime = DateTime.Now;
  2305. entity.UpdateTime = DateTime.Now;
  2306. entity.Update();
  2307. string name = commonHelper.getUserNameById(userid);
  2308. commonHelper.UpdateRelationOrder(entity.ctid);
  2309. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2310. }
  2311. }
  2312. returnSuccessMsg("操作成功!");
  2313. return;
  2314. }
  2315. }
  2316. public string getTidByCtid(string ctid)
  2317. {
  2318. string tid = "";
  2319. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2320. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2321. if (dataTable != null && dataTable.Rows.Count > 0)
  2322. {
  2323. tid = dataTable.Rows[0]["tid"].ToString();
  2324. }
  2325. return tid;
  2326. }
  2327. public List<string> getTidByCtidMore(string ctid)
  2328. {
  2329. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2330. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2331. List<string> list = new List<string>();
  2332. if (dataTable != null && dataTable.Rows.Count > 0)
  2333. {
  2334. foreach (DataRow item in dataTable.Rows)
  2335. {
  2336. list.Add("'" + item["tid"].ToString() + "'");
  2337. }
  2338. }
  2339. return list;
  2340. }
  2341. public List<string> getTidByCtidLike(string ctid)
  2342. {
  2343. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2344. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2345. List<string> list = new List<string>();
  2346. if (dataTable != null && dataTable.Rows.Count > 0)
  2347. {
  2348. foreach (DataRow item in dataTable.Rows)
  2349. {
  2350. list.Add("'" + item["tid"].ToString() + "'");
  2351. }
  2352. }
  2353. return list;
  2354. }
  2355. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2356. {
  2357. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2358. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2359. List<string> list = new List<string>();
  2360. if (dataTable != null && dataTable.Rows.Count > 0)
  2361. {
  2362. foreach (DataRow item in dataTable.Rows)
  2363. {
  2364. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2365. {
  2366. continue;
  2367. }
  2368. list.Add("'" + item["receiverId"].ToString() + "'");
  2369. }
  2370. }
  2371. return list;
  2372. }
  2373. public void get_erp_myorderlist()
  2374. {
  2375. DataStruct dStruct = GetPostStruct();
  2376. List<string> lw = new List<string>();
  2377. string tid = GetPostString("ctid");
  2378. if (tid.Length > 0)
  2379. {
  2380. string select_tid = getTidByCtid(tid);
  2381. lw.Add(string.Format("tid='{0}'", select_tid));
  2382. }
  2383. else
  2384. {
  2385. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2386. }
  2387. //12-1 修改
  2388. string urgent = GetPostString("urgent");
  2389. string back = GetPostString("back");
  2390. string offlineSearch = GetPostString("offlineSearch");
  2391. if (!string.IsNullOrWhiteSpace(urgent))
  2392. {
  2393. if (urgent.Equals("true"))
  2394. {
  2395. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2396. }
  2397. }
  2398. if (!string.IsNullOrWhiteSpace(back))
  2399. {
  2400. if (back.Equals("true"))
  2401. {
  2402. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2403. }
  2404. }
  2405. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2406. {
  2407. if (offlineSearch.Equals("true"))
  2408. {
  2409. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2410. }
  2411. }
  2412. //end
  2413. string shopname = GetPostString("shopname");
  2414. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2415. string buyernick = GetPostString("buyer_nick");
  2416. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2417. string design = GetPostString("design");
  2418. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2419. string orderState = GetPostString("orderState");
  2420. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2421. string sellermemo = GetPostString("seller_memo");
  2422. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2423. string date1 = GetPostString("date1");
  2424. string date2 = GetPostString("date2");
  2425. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2426. if (dw.Length > 0) lw.Add(dw);
  2427. string price1 = GetPostString("price1");
  2428. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2429. string price2 = GetPostString("price2");
  2430. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2431. string urgency = GetPostString("urgency");
  2432. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2433. string after = GetPostString("after");
  2434. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2435. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2436. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2437. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2438. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2439. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2440. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2441. if (dt != null && dt.Rows.Count > 0)
  2442. {
  2443. foreach (DataRow dr in dt.Rows)
  2444. {
  2445. try
  2446. {
  2447. // 对象操作
  2448. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2449. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2450. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2451. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2452. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2453. if (dStruct.PageSize != 100000)
  2454. {
  2455. if (dr["DispatchSort"].ToString() == "2")
  2456. {
  2457. dr["gongchuang"] = 200;
  2458. }
  2459. else if ("外协".Equals(dr["ToType"].ToString()))
  2460. {
  2461. dr["gongchuang"] = 200;
  2462. }
  2463. else if ("内部".Equals(dr["ToType"].ToString()))
  2464. {
  2465. dr["gongchuang"] = -1;
  2466. }
  2467. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2468. {
  2469. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2470. dr["gongchuang"] = response.code;
  2471. }
  2472. }
  2473. }
  2474. catch (NullReferenceException ex)
  2475. {
  2476. }
  2477. }
  2478. }
  2479. writeGridDataTableJson(dStruct.TotalCount, dt);
  2480. }
  2481. public void get_erp_myreturnorderlist()
  2482. {
  2483. DataStruct dStruct = GetPostStruct();
  2484. List<string> lw = new List<string>();
  2485. string tid = GetPostString("ctid");
  2486. if (tid.Length > 0)
  2487. {
  2488. string select_tid = getTidByCtid(tid);
  2489. lw.Add(string.Format("tid='{0}'", select_tid));
  2490. }
  2491. else
  2492. {
  2493. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2494. }
  2495. string shopname = GetPostString("shopname");
  2496. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2497. string buyernick = GetPostString("buyer_nick");
  2498. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2499. string design = GetPostString("design");
  2500. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2501. string orderState = GetPostString("orderState");
  2502. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2503. string sellermemo = GetPostString("seller_memo");
  2504. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2505. string date1 = GetPostString("date1");
  2506. string date2 = GetPostString("date2");
  2507. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2508. if (dw.Length > 0) lw.Add(dw);
  2509. string price1 = GetPostString("price1");
  2510. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2511. string price2 = GetPostString("price2");
  2512. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2513. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2514. {
  2515. lw.Add(string.Format("CusOrgID = 94"));
  2516. }
  2517. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2518. {
  2519. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2520. }
  2521. else
  2522. {
  2523. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2524. }
  2525. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2526. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2527. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2528. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2529. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2530. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2531. if (dt != null && dt.Rows.Count > 0)
  2532. {
  2533. foreach (DataRow dr in dt.Rows)
  2534. {
  2535. try
  2536. {
  2537. // 对象操作
  2538. if (dStruct.PageSize != 100000)
  2539. {
  2540. if (dr["DispatchSort"].ToString() == "2")
  2541. {
  2542. dr["gongchuang"] = 200;
  2543. }
  2544. else if ("外协".Equals(dr["ToType"].ToString()))
  2545. {
  2546. dr["gongchuang"] = 200;
  2547. }
  2548. else if ("内部".Equals(dr["ToType"].ToString()))
  2549. {
  2550. dr["gongchuang"] = -1;
  2551. }
  2552. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2553. {
  2554. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2555. dr["gongchuang"] = response.code;
  2556. }
  2557. }
  2558. }
  2559. catch (NullReferenceException ex)
  2560. {
  2561. // 处理空引用异常
  2562. }
  2563. }
  2564. }
  2565. writeGridDataTableJson(dStruct.TotalCount, dt);
  2566. }
  2567. public void get_erp_myorderlist_pregather()
  2568. {
  2569. string date1 = GetPostString("date1");
  2570. string date2 = GetPostString("date2");
  2571. int userId = CurrentUser.UserID; //客服id
  2572. string orderWhere = "";
  2573. List<string> lw = new List<string>();
  2574. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2575. if (dw.Length > 0) lw.Add(dw);
  2576. lw.Add(string.Format("CustomerUserId={0}", userId));
  2577. lw.Add(string.Format("OrderState<9"));
  2578. orderWhere = string.Join(" and ", lw.ToArray());
  2579. string orderWhere2 = "";
  2580. List<string> lw2 = new List<string>();
  2581. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2582. if (dw2.Length > 0) lw2.Add(dw2);
  2583. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2584. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2585. string sql = string.Format("select *" +
  2586. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2587. "left join(select CustomerUserId, count(ctid) as dCount from View_ErpTradeCell where OrderState = 6 and " + orderWhere2 + " group by CustomerUserId) b on a.CustomerUserId = b.CustomerUserId " +
  2588. "left join(select CustomerUserId, count(ctid) as jCount from View_ErpTradeCell where IsUrgency = 1 and " + orderWhere + " group by CustomerUserId) c on a.CustomerUserId = c.CustomerUserId " +
  2589. "left join(select CustomerUserId, count(ctid) as sCount from View_ErpTradeCell where AfterSaleState > 0 and CHARINDEX(','+CONVERT(varchar," + userId + ")+'_k,',','+ResponsibleUserId+',')>0 and " + orderWhere + " group by CustomerUserId) d on a.CustomerUserId = d.CustomerUserId");
  2590. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2591. //writeGridDataTableJson(dt.Rows.Count, dt);
  2592. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2593. }
  2594. public void upd_erp_publishorder()
  2595. {
  2596. if (UrlPostParmsCheck("ctid"))
  2597. {
  2598. string eid = GetPostString("ctid");
  2599. CeErpTradeCell entity = null;
  2600. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2601. if (entity != null)
  2602. {
  2603. entity.OrderState = 0; //发布后,变为待抢单
  2604. entity.Update();
  2605. commonHelper.UpdateRelationOrder(entity.ctid);
  2606. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2607. returnSuccessMsg("发布成功!");
  2608. return;
  2609. }
  2610. returnErrorMsg("找不到记录");
  2611. }
  2612. }
  2613. public void get_erp_my_tiporder()
  2614. {
  2615. StringBuilder sql = new StringBuilder();
  2616. int userId = 0;
  2617. if (CurrentUser != null) userId = CurrentUser.UserID;
  2618. string posCode = CurrentUser.UserPost.Post.Code;
  2619. string isTipedAfterSaleVerify = GetPostString("af");
  2620. DataTable dt = new DataTable();
  2621. if (posCode != "Supplier")
  2622. {
  2623. if (posCode == "CustomerService" || posCode == "Director")
  2624. {
  2625. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2626. }
  2627. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2628. {
  2629. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2630. }
  2631. else
  2632. {
  2633. string teamIds = CurrentUser.User.TeamIds;
  2634. if (teamIds == "")
  2635. {
  2636. teamIds = "0";
  2637. }
  2638. sql.AppendFormat("select * from ce_erptradecell where (DesignUserId={0} or DesignUserId in (select ID from view_erpuser where OnDuty=0 and ID in ({1}))) and OrderState in (3,4) and IsReadTag>0 ", userId, teamIds);
  2639. }
  2640. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2641. }
  2642. if (dt.Rows.Count <= 0)
  2643. {
  2644. string key = "aftersale_order_" + userId;
  2645. if (RedisHelper.HasKey(key))
  2646. {
  2647. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2648. dt.Columns.Add("ctid", typeof(string));
  2649. dt.Columns.Add("IsReadTag", typeof(int));
  2650. foreach (var i in list)
  2651. {
  2652. DataRow data = dt.NewRow();
  2653. data["ctid"] = i;
  2654. data["IsReadTag"] = 4;
  2655. dt.Rows.Add(data);
  2656. }
  2657. RedisHelper.StringDelete(key);
  2658. }
  2659. }
  2660. if (dt.Rows.Count <= 0)
  2661. {
  2662. sql = new StringBuilder();
  2663. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2664. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2665. }
  2666. if (posCode == "Supplier")
  2667. {
  2668. string ids = CurrentUser.User.pemVend;
  2669. if (ids != null && ids.Length > 0)
  2670. {
  2671. string[] ids_list = ids.Split(',');
  2672. foreach (var item in ids_list)
  2673. {
  2674. string key = "return_order_" + item;
  2675. if (RedisHelper.HasKey(key))
  2676. {
  2677. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2678. dt.Columns.Add("ctid", typeof(string));
  2679. dt.Columns.Add("IsReadTag", typeof(int));
  2680. foreach (var i in list)
  2681. {
  2682. DataRow data = dt.NewRow();
  2683. data["ctid"] = i;
  2684. data["IsReadTag"] = 1;
  2685. dt.Rows.Add(data);
  2686. }
  2687. RedisHelper.StringDelete(key);
  2688. }
  2689. }
  2690. }
  2691. if (dt.Rows.Count <= 0)
  2692. {
  2693. sql = new StringBuilder();
  2694. sql.AppendFormat("select MemoOpt,SupplierId,ctid from ce_erptradecell where SupplierId in ({0}) and MemoOpt=3 and DATEDIFF(MINUTE,CheckOrderTime,GETDATE())<=3", CurrentUser.User.pemVend);
  2695. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2696. }
  2697. }
  2698. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2699. }
  2700. public void reset_erp_tiporder()
  2701. {
  2702. string ids = GetPostString("ids");
  2703. string[] ctidList = ids.Split(',');
  2704. foreach (string ctid in ctidList)
  2705. {
  2706. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2707. if (enty != null)
  2708. {
  2709. enty.IsReadTag = 0;
  2710. enty.Update();
  2711. }
  2712. }
  2713. returnSuccessMsg("成功!");
  2714. return;
  2715. }
  2716. public void get_erp_designlist()
  2717. {
  2718. DataStruct dStruct = GetPostStruct();
  2719. List<string> lw = new List<string>();
  2720. string tid = GetPostString("ctid");
  2721. if (tid.Length > 0)
  2722. {
  2723. string select_tid = getTidByCtid(tid);
  2724. lw.Add(string.Format("tid='{0}'", select_tid));
  2725. }
  2726. string shopname = GetPostString("shopname");
  2727. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2728. string buyernick = GetPostString("buyer_nick");
  2729. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2730. string customer = GetPostString("customer");
  2731. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2732. string design = GetPostString("design");
  2733. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2734. string orderState = GetPostString("orderState");
  2735. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2736. lw.Add(string.Format("OrderState<6"));
  2737. string address = GetPostString("address");
  2738. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2739. string sellermemo = GetPostString("seller_memo");
  2740. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2741. string date1 = GetPostString("date1");
  2742. string date2 = GetPostString("date2");
  2743. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2744. if (dw.Length > 0) lw.Add(dw);
  2745. string apdate1 = GetPostString("apdate1");
  2746. string apdate2 = GetPostString("apdate2");
  2747. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2748. if (dwap.Length > 0) lw.Add(dwap);
  2749. string price1 = GetPostString("price1");
  2750. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2751. string price2 = GetPostString("price2");
  2752. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2753. string designTime = GetPostString("designtime");
  2754. if (designTime.Length > 0)
  2755. {
  2756. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2757. }
  2758. string usershop = CurrentUser.User.pemShop;
  2759. if (usershop.Length > 0)
  2760. {
  2761. lw.Add(string.Format("shopId in ({0})", usershop));
  2762. }
  2763. int myOrgid = CurrentUser.UserPost.OrgID;
  2764. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2765. if (myOrgCode.IndexOf("Designer") != -1)
  2766. {
  2767. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2768. {
  2769. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2770. }
  2771. else
  2772. {
  2773. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2774. }
  2775. }
  2776. else
  2777. {
  2778. string orgId = GetPostString("designerhd");
  2779. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2780. }
  2781. if (tid.Length > 0 || buyernick.Length > 0)
  2782. {
  2783. lw.Add(string.Format("OrderState >= 3"));
  2784. }
  2785. else
  2786. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2787. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2788. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2789. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2790. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2791. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2792. if (dt != null && dt.Rows.Count > 0)
  2793. {
  2794. foreach (DataRow dr in dt.Rows)
  2795. {
  2796. try
  2797. {
  2798. // 对象操作
  2799. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2800. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2801. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2802. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2803. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2804. if (dStruct.PageSize != 100000)
  2805. {
  2806. if (dr["DispatchSort"].ToString() == "2")
  2807. {
  2808. dr["gongchuang"] = 200;
  2809. }
  2810. else if ("外协".Equals(dr["ToType"].ToString()))
  2811. {
  2812. dr["gongchuang"] = 200;
  2813. }
  2814. else if ("内部".Equals(dr["ToType"].ToString()))
  2815. {
  2816. dr["gongchuang"] = -1;
  2817. }
  2818. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2819. {
  2820. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2821. dr["gongchuang"] = response.code;
  2822. }
  2823. }
  2824. }
  2825. catch (NullReferenceException ex)
  2826. {
  2827. }
  2828. }
  2829. }
  2830. writeGridDataTableJson(dStruct.TotalCount, dt);
  2831. }
  2832. public void get_erp_mydesignlist()
  2833. {
  2834. DataStruct dStruct = GetPostStruct();
  2835. List<string> lw = new List<string>();
  2836. string tid = GetPostString("ctid");
  2837. if (tid.Length > 0)
  2838. {
  2839. string select_tid = getTidByCtid(tid);
  2840. lw.Add(string.Format("tid='{0}'", select_tid));
  2841. }
  2842. string shopname = GetPostString("shopname");
  2843. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2844. string buyernick = GetPostString("buyer_nick");
  2845. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2846. string customer = GetPostString("customer");
  2847. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2848. string orderState = GetPostString("orderState");
  2849. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2850. //lw.Add(string.Format("OrderState<6"));
  2851. string date1 = GetPostString("date1");
  2852. string date2 = GetPostString("date2");
  2853. string dw = GetDateWhere("pay_time", date1, date2);
  2854. if (dw.Length > 0) lw.Add(dw);
  2855. string apdate1 = GetPostString("apdate1");
  2856. string apdate2 = GetPostString("apdate2");
  2857. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2858. if (dwap.Length > 0) lw.Add(dwap);
  2859. string price1 = GetPostString("price1");
  2860. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2861. string price2 = GetPostString("price2");
  2862. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2863. string olddownload = GetPostString("olddown");
  2864. if (olddownload == "1")
  2865. {
  2866. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2867. }
  2868. else if (olddownload == "2")
  2869. {
  2870. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2871. }
  2872. string sellermemo = GetPostString("seller_memo");
  2873. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2874. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2875. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2876. {
  2877. if (CurrentUser.User.TeamIds.Length > 0)
  2878. {
  2879. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2880. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2881. else
  2882. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2883. }
  2884. else
  2885. {
  2886. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2887. }
  2888. }
  2889. if (tid.Length <= 0)
  2890. {
  2891. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2892. }
  2893. lw.Add(string.Format("IsReturn!=3"));
  2894. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2895. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2896. string teamids = CurrentUser.User.TeamIds.ToString();
  2897. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2898. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2899. if (dt != null && dt.Rows.Count > 0)
  2900. {
  2901. foreach (DataRow dr in dt.Rows)
  2902. {
  2903. try
  2904. {
  2905. // 对象操作
  2906. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2907. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2908. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2909. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2910. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2911. if (dStruct.PageSize != 100000)
  2912. {
  2913. if (dr["DispatchSort"].ToString() == "2")
  2914. {
  2915. dr["gongchuang"] = 200;
  2916. }
  2917. else if ("外协".Equals(dr["ToType"].ToString()))
  2918. {
  2919. dr["gongchuang"] = 200;
  2920. }
  2921. else if ("内部".Equals(dr["ToType"].ToString()))
  2922. {
  2923. dr["gongchuang"] = -1;
  2924. }
  2925. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2926. {
  2927. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2928. dr["gongchuang"] = response.code;
  2929. }
  2930. }
  2931. }
  2932. catch (NullReferenceException ex)
  2933. {
  2934. }
  2935. }
  2936. }
  2937. writeGridDataTableJson(dStruct.TotalCount, dt);
  2938. }
  2939. public void set_erp_startdesign()
  2940. {
  2941. if (UrlPostParmsCheck("ctid"))
  2942. {
  2943. string eid = GetPostString("ctid");
  2944. CeErpTradeCell entity = null;
  2945. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2946. if (entity != null)
  2947. {
  2948. if (entity.OrderState != 3)
  2949. {
  2950. returnErrorMsg("请刷新,订单已经设计了");
  2951. return;
  2952. }
  2953. entity.StartDesignTime = DateTime.Now;
  2954. entity.OrderState = 4;
  2955. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2956. {
  2957. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2958. entity.SupplierId = suid;
  2959. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2960. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2961. }
  2962. entity.UpdateTime = DateTime.Now;
  2963. //entity.MakeSupplier = suname;
  2964. entity.Update();
  2965. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2966. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2967. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2968. commonHelper.getCytPrice(entity);
  2969. returnSuccessMsg("操作成功!");
  2970. return;
  2971. }
  2972. returnErrorMsg("找不到记录");
  2973. }
  2974. }
  2975. public void ins_erp_designselfmemo()
  2976. {
  2977. if (UrlPostParmsCheck("ctid"))
  2978. {
  2979. string eid = GetPostString("ctid");
  2980. string con = GetPostString("con");
  2981. CeErpTradeCell entity = null;
  2982. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2983. if (entity != null)
  2984. {
  2985. entity.DesignSelfMemo = con;
  2986. entity.Update();
  2987. returnSuccessMsg("操作成功!");
  2988. return;
  2989. }
  2990. returnErrorMsg("找不到记录");
  2991. }
  2992. }
  2993. public void ins_erp_designprice()
  2994. {
  2995. if (UrlPostParmsCheck("ctid"))
  2996. {
  2997. string eid = GetPostString("ctid");
  2998. int uid = CurrentUser.UserID;
  2999. string userName = CurrentUser.UserName;
  3000. CeErpTradeCell entity = null;
  3001. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3002. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3003. if (entitys == null)
  3004. {
  3005. entitys = new CeErpDesignerBill();
  3006. }
  3007. if (entity != null)
  3008. {
  3009. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3010. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3011. entity.StartDesignTime = DateTime.Now;
  3012. entity.OrderState = 4;
  3013. string suname = "";
  3014. if (entity.SupplierId == 0)
  3015. {
  3016. int sid = commonHelper.autoDistributeToSupplier(entity);
  3017. entity.SupplierId = sid;
  3018. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3019. }
  3020. entity.Update();
  3021. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3022. if (ceErpUserPost != null)
  3023. {
  3024. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3025. if (ceErpPost != null)
  3026. {
  3027. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3028. {
  3029. entitys.tid = entity.ctid;
  3030. entitys.oid = entity.tid;
  3031. entitys.uid = uid;
  3032. entitys.userName = userName;
  3033. entitys.designerType = 1;
  3034. entitys.designerTypeText = "内部设计师";
  3035. entitys.price = Convert.ToDouble(GetPostString("price"));
  3036. entitys.designNum = GetPostInt("designNum");
  3037. entitys.modifyNum = GetPostInt("modifyNum");
  3038. entitys.designSize = GetPostString("designSize");
  3039. entitys.modifySize = GetPostString("modifySize");
  3040. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3041. {
  3042. entitys.create_time = DateTime.Now;
  3043. entitys.create_u_id = uid;
  3044. entitys.create_u_name = userName;
  3045. entitys.Save();
  3046. }
  3047. else
  3048. {
  3049. entitys.update_time = DateTime.Now;
  3050. entitys.update_u_id = uid;
  3051. entitys.update_u_name = userName;
  3052. entitys.Update();
  3053. }
  3054. }
  3055. }
  3056. }
  3057. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3058. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3059. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3060. if (suname != "")
  3061. {
  3062. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3063. }
  3064. commonHelper.getCytPrice(entity);
  3065. returnSuccessMsg("操作成功!");
  3066. return;
  3067. }
  3068. returnErrorMsg("找不到记录");
  3069. }
  3070. }
  3071. public void upload_erp_filecomplete()
  3072. {
  3073. if (UrlPostParmsCheck("ctid"))
  3074. {
  3075. string eid = GetPostString("ctid");
  3076. CeErpTradeCell entity = null;
  3077. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3078. if (entity != null)
  3079. {
  3080. entity.OrderState = 5; //设计完成
  3081. entity.Update();
  3082. returnSuccessMsg(eid + "上传成功,设计完成!");
  3083. return;
  3084. }
  3085. returnErrorMsg("找不到订单记录");
  3086. }
  3087. }
  3088. public void get_erp_designovertimelist()
  3089. {
  3090. DataStruct dStruct = GetPostStruct();
  3091. List<string> lw = new List<string>();
  3092. string tid = GetPostString("ctid");
  3093. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3094. string shopname = GetPostString("shopname");
  3095. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3096. string buyernick = GetPostString("buyer_nick");
  3097. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3098. string ResponsibleMan = GetPostString("responsible");
  3099. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3100. string date1 = GetPostString("date1");
  3101. string date2 = GetPostString("date2");
  3102. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3103. if (dw.Length > 0) lw.Add(dw);
  3104. string price1 = GetPostString("price1");
  3105. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3106. string price2 = GetPostString("price2");
  3107. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3108. string orderState = GetPostString("orderState");
  3109. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3110. string sellermemo = GetPostString("seller_memo");
  3111. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3112. lw.Add(string.Format("UnusualTag=3"));
  3113. lw.Add(string.Format("IsRefund<={0}", 1));
  3114. dStruct.Order = "WaitDesignTime desc";
  3115. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3116. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3117. writeGridDataTableJson(dStruct.TotalCount, dt);
  3118. }
  3119. //设计管理 获取抢单大厅列表
  3120. public void get_erp_grabinglist()
  3121. {
  3122. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3123. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3124. bool oldOrder = false;
  3125. if (org != null)
  3126. {
  3127. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3128. }
  3129. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3130. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3131. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3132. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3133. //先处理订单数据
  3134. if (dt.Rows.Count > 0)
  3135. {
  3136. Dictionary<string, int> design = null;
  3137. int count = 0;
  3138. foreach (DataRow row in dt.Rows)
  3139. {
  3140. if (map.ContainsKey(row["ShopId"].ToString()))
  3141. {
  3142. map.TryGetValue(row["ShopId"].ToString(), out design);
  3143. }
  3144. else
  3145. {
  3146. design = new Dictionary<string, int>();
  3147. }
  3148. if (design.ContainsKey(row["ProductId"].ToString()))
  3149. {
  3150. design.TryGetValue(row["ProductId"].ToString(), out count);
  3151. }
  3152. count++;
  3153. design[row["ProductId"].ToString()] = count;
  3154. map[row["ShopId"].ToString()] = design;
  3155. }
  3156. }
  3157. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3158. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3159. //把店铺排序和技能排序分类
  3160. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3161. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3162. if (design_dt.Rows.Count > 0)
  3163. {
  3164. Dictionary<string, string> design = null;
  3165. List<string> shopIds = null;
  3166. foreach (DataRow row in design_dt.Rows)
  3167. {
  3168. if ("0".Equals(row["designId"].ToString()))
  3169. {
  3170. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3171. {
  3172. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3173. }
  3174. else
  3175. {
  3176. shopIds = new List<string>();
  3177. }
  3178. shopIds.Add(row["shopId"].ToString());
  3179. shop_orders[row["orders"].ToString()] = shopIds;
  3180. }
  3181. else
  3182. {
  3183. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3184. {
  3185. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3186. }
  3187. else
  3188. {
  3189. design = new Dictionary<string, string>();
  3190. }
  3191. design[row["orders"].ToString()] = row["designId"].ToString();
  3192. design_orders[row["shopId"].ToString()] = design;
  3193. }
  3194. }
  3195. //处理成key value后根据key排序
  3196. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3197. foreach (List<string> val in shop_orders.Values)
  3198. {
  3199. if (val != null)
  3200. {
  3201. foreach (string key in val)
  3202. {
  3203. if (design_orders.ContainsKey(key.ToString()))
  3204. {
  3205. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3206. }
  3207. }
  3208. }
  3209. }
  3210. }
  3211. //校验哪个优先级有订单
  3212. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3213. foreach (string key in shop_orders.Keys)
  3214. {
  3215. List<string> ids = null;
  3216. shop_orders.TryGetValue(key, out ids);
  3217. //id为shopid
  3218. foreach (string id in ids)
  3219. {
  3220. Dictionary<string, int> list = null;
  3221. Dictionary<string, string> desing = null;
  3222. map.TryGetValue(id, out list);
  3223. design_orders.TryGetValue(id, out desing);
  3224. if (list != null && desing != null)
  3225. {
  3226. foreach (var item in desing)
  3227. {
  3228. int count = 0;
  3229. if (list.ContainsKey(item.Value))
  3230. {
  3231. list.TryGetValue(item.Value, out count);
  3232. if (count > 0)
  3233. {
  3234. designIds[id] = item.Value;
  3235. break;
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. if (designIds.Count > 0)
  3242. {
  3243. break;
  3244. }
  3245. }
  3246. DataTable table = new DataTable();
  3247. table.Columns.Add("tid", typeof(string));
  3248. table.Columns.Add("ctid", typeof(string));
  3249. table.Columns.Add("seller_nick", typeof(string));
  3250. table.Columns.Add("productName", typeof(string));
  3251. table.Columns.Add("pay_time", typeof(string));
  3252. table.Columns.Add("seller_memo", typeof(string));
  3253. if (designIds.Count > 0)
  3254. {
  3255. string shopId = "";
  3256. string productId = "";
  3257. foreach (var designInfo in designIds)
  3258. {
  3259. shopId = designInfo.Key;
  3260. productId = designInfo.Value;
  3261. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3262. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3263. if (dt.Rows.Count > 0)
  3264. {
  3265. foreach (DataRow row in dt.Rows)
  3266. {
  3267. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3268. {
  3269. DataRow data = table.NewRow();
  3270. data["ctid"] = row["ctid"].ToString();
  3271. data["tid"] = row["tid"].ToString();
  3272. data["seller_nick"] = ceErpShop.ShopName;
  3273. data["pay_time"] = row["pay_time"].ToString();
  3274. data["seller_memo"] = row["seller_memo"].ToString();
  3275. data["productName"] = ceErpProduct.PType;
  3276. table.Rows.Add(data);
  3277. }
  3278. }
  3279. }
  3280. }
  3281. }
  3282. writeGridDataTableJson(table.Rows.Count, table);
  3283. }
  3284. private object rushLockObject = new object();
  3285. public void set_erp_grabingorder()
  3286. {
  3287. if (UrlPostParmsCheck("ctid"))
  3288. {
  3289. int total = CurrentUser.User.Person.Total;
  3290. int userId = CurrentUser.User.ID;
  3291. int noFinish = CurrentUser.User.Person.NoFinish;
  3292. int finalization = CurrentUser.User.Person.Finalization;
  3293. string eids = GetPostString("ctid");
  3294. string key = "RushKey_" + userId;
  3295. int count = 0;
  3296. if (erpRedis.RedisHelper.KeyExists(key))
  3297. {
  3298. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3299. if (redisCount != null)
  3300. {
  3301. count = Convert.ToInt32(redisCount);
  3302. }
  3303. }
  3304. if (count >= total)
  3305. {
  3306. returnErrorMsg("半小时内已经抢" + total + "单");
  3307. return;
  3308. }
  3309. string[] ctidlist = eids.Split(',');
  3310. if (count + ctidlist.Length > total)
  3311. {
  3312. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3313. return;
  3314. }
  3315. int itag = 0;
  3316. lock (rushLockObject)
  3317. {
  3318. if (ctidlist.Length > 0)
  3319. {
  3320. string[] dtList = new string[ctidlist.Length];
  3321. for (int i = 0; i < ctidlist.Length; i++)
  3322. {
  3323. dtList[i] = "'" + ctidlist[i] + "'";
  3324. }
  3325. string sql_user = string.Format("select OrderState from CE_ErpTradeCell where DesignUserId = {0} and WaitDesignTime BETWEEN '{1}' and '{2}'", userId, DateTime.Now.ToString("yyyy-MM-dd 00:00:00"), DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  3326. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3327. if (dt_user.Rows.Count > 0)
  3328. {
  3329. int doing = 0;//未定稿
  3330. int finish = 0;//已完成
  3331. foreach (DataRow dr in dt_user.Rows)
  3332. {
  3333. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3334. {
  3335. doing++;
  3336. }
  3337. else
  3338. {
  3339. finish++;
  3340. }
  3341. }
  3342. if (doing >= noFinish)
  3343. {
  3344. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3345. return;
  3346. }
  3347. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3348. {
  3349. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3350. return;
  3351. }
  3352. }
  3353. //校验选择单子状态
  3354. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3355. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3356. if (dt.Rows.Count > 0)
  3357. {
  3358. List<string> list = new List<string>();
  3359. foreach (DataRow dr in dt.Rows)
  3360. {
  3361. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3362. {
  3363. list.Add(dr["ctid"].ToString());
  3364. }
  3365. }
  3366. if (list.Count > 0)
  3367. {
  3368. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3369. return;
  3370. }
  3371. }
  3372. foreach (string ctid in ctidlist)
  3373. {
  3374. CeErpTradeCell entity = null;
  3375. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3376. if (entity != null)
  3377. {
  3378. entity.OrderState = 3;
  3379. entity.DesignUserId = CurrentUser.UserID;
  3380. entity.WaitDesignTime = DateTime.Now;
  3381. entity.StartDesignTime = DateTime.Now;
  3382. entity.Update();
  3383. commonHelper.UpdateRelationOrder(entity.ctid);
  3384. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3385. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3386. itag++;
  3387. }
  3388. }
  3389. }
  3390. }
  3391. count += ctidlist.Length;
  3392. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3393. if (itag == 0)
  3394. returnErrorMsg("没有找到相关订单");
  3395. else
  3396. returnSuccessMsg("抢单成功!");
  3397. return;
  3398. }
  3399. }
  3400. public void get_erp_waitorderlist()
  3401. {
  3402. DataStruct dStruct = GetPostStruct();
  3403. List<string> lw = new List<string>();
  3404. string tid = GetPostString("ctid");
  3405. if (tid.Length > 0)
  3406. {
  3407. string select_tid = getTidByCtid(tid);
  3408. lw.Add(string.Format("tid='{0}'", select_tid));
  3409. }
  3410. string shopname = GetPostString("shopname");
  3411. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3412. string buyernick = GetPostString("buyer_nick");
  3413. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3414. string customer = GetPostString("customer");
  3415. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3416. string design = GetPostString("design");
  3417. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3418. string orderState = GetPostString("orderState");
  3419. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3420. string supplier = GetPostString("supplier");
  3421. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3422. string sellermemo = GetPostString("seller_memo");
  3423. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3424. string otherMemo = GetPostString("otherMemo");
  3425. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3426. string address = GetPostString("address");
  3427. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  3428. string date1 = GetPostString("date1");
  3429. string date2 = GetPostString("date2");
  3430. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3431. if (dw.Length > 0) lw.Add(dw);
  3432. string price1 = GetPostString("price1");
  3433. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3434. string price2 = GetPostString("price2");
  3435. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3436. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3437. lw.Add(string.Format("IsSample != 2 "));
  3438. lw.Add(string.Format("OrderState = 5 "));
  3439. lw.Add(string.Format("IsRefund<={0}", 1));
  3440. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3441. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3442. string pagesize = GetPostString("pagesize");
  3443. if (pagesize != null)
  3444. {
  3445. dStruct.PageSize = 200;
  3446. }
  3447. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3448. List<string> tids = new List<string>();
  3449. if (dt != null)
  3450. {
  3451. dt.Columns.Add("compenPrice", typeof(double));
  3452. foreach (DataRow dr in dt.Rows)
  3453. {
  3454. if (Convert.IsDBNull(dr["compenPrice"]))
  3455. {
  3456. dr["compenPrice"] = 0;
  3457. }
  3458. tids.Add("'" + dr["tid"].ToString() + "'");
  3459. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3460. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3461. {
  3462. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3463. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3464. entity.SupplierId = suid;
  3465. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3466. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3467. entity.Update();
  3468. }
  3469. }
  3470. }
  3471. if (tids.Count > 0)
  3472. {
  3473. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3474. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3475. if (dt_price != null && dt_price.Rows.Count > 0)
  3476. {
  3477. foreach (DataRow dr in dt_price.Rows)
  3478. {
  3479. foreach (DataRow row in dt.Rows)
  3480. {
  3481. if (row["tid"].Equals(dr["ptid"]))
  3482. {
  3483. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3484. break;
  3485. }
  3486. }
  3487. }
  3488. }
  3489. }
  3490. writeGridDataTableJson(dStruct.TotalCount, dt);
  3491. }
  3492. public void get_erp_supplierwaitorderlist()
  3493. {
  3494. DataStruct dStruct = GetPostStruct();
  3495. List<string> lw = new List<string>();
  3496. string tid = GetPostString("ctid");
  3497. if (tid.Length > 0)
  3498. {
  3499. string select_tid = getTidByCtid(tid);
  3500. lw.Add(string.Format("tid='{0}'", select_tid));
  3501. }
  3502. string shopname = GetPostString("shopname");
  3503. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3504. string sellermemo = GetPostString("seller_memo");
  3505. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3506. string date1 = GetPostString("date1");
  3507. string date2 = GetPostString("date2");
  3508. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3509. if (dw.Length > 0) lw.Add(dw);
  3510. lw.Add(string.Format("OrderState = 5 "));
  3511. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3512. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3513. {
  3514. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3515. }
  3516. string supplier = GetPostString("supplier");
  3517. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3518. {
  3519. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3520. }
  3521. lw.Add(string.Format("IsRefund<={0}", 1));
  3522. dStruct.Order = "FinishDesignTime desc";
  3523. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3524. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3525. if (dt != null)
  3526. {
  3527. foreach (DataRow dr in dt.Rows)
  3528. {
  3529. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3530. }
  3531. }
  3532. writeGridDataTableJson(dStruct.TotalCount, dt);
  3533. }
  3534. public void upd_erp_verifytosupplier()
  3535. {
  3536. if (UrlPostParmsCheck("ctid"))
  3537. {
  3538. string eids = GetPostString("ctid");
  3539. CeErpTradeCell entity = null;
  3540. string[] eidsList = eids.Split(',');
  3541. if (eidsList.Length <= 0)
  3542. {
  3543. returnErrorMsg("订单号不能空");
  3544. return;
  3545. }
  3546. List<string> tLst = new List<string>();
  3547. foreach (string ctidstr in eidsList)
  3548. {
  3549. tLst.Add("'" + ctidstr + "'");
  3550. CeErpDataSendOrderInfo.createObject(ctidstr);
  3551. }
  3552. string needtids = string.Join(",", tLst.ToArray());
  3553. StringBuilder sql = new StringBuilder();
  3554. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3555. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3556. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3557. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3558. returnSuccessMsg("操作成功!");
  3559. return;
  3560. /**foreach (string ctidstr in eidsList)
  3561. {
  3562. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3563. if (entity != null)
  3564. {
  3565. if (entity.SupplierId == 0)
  3566. {
  3567. continue;
  3568. }
  3569. entity.IsVerifyToSupplier = true;
  3570. if (entity.IsReturn == 1) //1是供应商打回
  3571. {
  3572. entity.IsReturn = 0;
  3573. }
  3574. entity.FinishPlaceTime = DateTime.Now;
  3575. entity.PlaceUserId = CurrentUser.UserID;
  3576. entity.Update();
  3577. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3578. }
  3579. }
  3580. returnSuccessMsg("操作成功!");
  3581. return;**/
  3582. }
  3583. }
  3584. public void upd_erp_supplierback()
  3585. {
  3586. if (UrlPostParmsCheck("ctid"))
  3587. {
  3588. string eid = GetPostString("ctid");
  3589. string reason = GetPostString("returnreason");
  3590. CeErpTradeCell entity = null;
  3591. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3592. if (entity != null)
  3593. {
  3594. string message = "操作成功!";
  3595. string isDown = "";
  3596. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3597. {
  3598. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3599. isDown = "被点击下载";
  3600. }
  3601. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3602. {
  3603. string key = "return_order_" + entity.SupplierId;
  3604. List<string> list = new List<string>();
  3605. if (RedisHelper.HasKey(key))
  3606. {
  3607. object data = RedisHelper.StringGet(key);
  3608. list = Convert.ToString(data).Split(',').ToList();
  3609. }
  3610. list.Add(eid);
  3611. RedisHelper.StringSet(key, string.Join(",", list));
  3612. }
  3613. entity.IsVerifyToSupplier = false;
  3614. entity.IsReturn = 1;
  3615. entity.IsHaveNewOrder = 0;
  3616. entity.ReturnTime = DateTime.Now;
  3617. entity.ReturnReason = reason;
  3618. if (entity.OrderState == 6)
  3619. {
  3620. entity.OrderState = 5;
  3621. }
  3622. entity.Update();
  3623. CeErpSukuraData.createInfo(entity.ctid, 5);
  3624. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3625. returnSuccessMsg(message);
  3626. return;
  3627. }
  3628. returnErrorMsg("找不到订单记录");
  3629. }
  3630. }
  3631. public void upd_erp_toaftersaleorder()
  3632. {
  3633. if (UrlPostParmsCheck("ctid"))
  3634. {
  3635. string eid = GetPostString("ctid");
  3636. string reason = GetPostString("returnreason");
  3637. CeErpTradeCell entity = null;
  3638. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3639. if (entity != null)
  3640. {
  3641. if (entity.isAfterSaleOrder != 1)
  3642. {
  3643. returnErrorMsg("带S的售后单才能打回给售后");
  3644. return;
  3645. }
  3646. if (entity.OrderState >= 5)
  3647. {
  3648. returnErrorMsg("已经设计完成了不能打回给售后");
  3649. return;
  3650. }
  3651. entity.OrderState = 0;
  3652. entity.IsReturn = 3;
  3653. entity.ReturnTime = DateTime.Now;
  3654. entity.UpdateTime = DateTime.Now;
  3655. entity.ReturnReason = reason;
  3656. entity.Update();
  3657. CeErpSukuraData.createInfo(entity.ctid, 5);
  3658. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3659. returnSuccessMsg("操作成功!");
  3660. return;
  3661. }
  3662. returnErrorMsg("找不到订单记录");
  3663. }
  3664. }
  3665. public void upd_erp_aftersaletodesign()
  3666. {
  3667. if (UrlPostParmsCheck("ctid"))
  3668. {
  3669. string eid = GetPostString("ctid");
  3670. CeErpTradeCell entity = null;
  3671. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3672. if (entity != null)
  3673. {
  3674. entity.OrderState = 3;
  3675. entity.IsReturn = 0;
  3676. entity.UpdateTime = DateTime.Now;
  3677. entity.Update();
  3678. CeErpSukuraData.createInfo(entity.ctid, 5);
  3679. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3680. returnSuccessMsg("操作成功!");
  3681. return;
  3682. }
  3683. returnErrorMsg("找不到订单记录");
  3684. }
  3685. }
  3686. public void assign_erp_supplier()
  3687. {
  3688. if (UrlPostParmsCheck("ctid"))
  3689. {
  3690. string eids = GetPostString("ctid");
  3691. int sid = GetPostInt("SupplierName");
  3692. string fromTag = GetPostString("tag");
  3693. string[] eidList = eids.Split(',');
  3694. if (eidList.Length <= 0)
  3695. {
  3696. returnErrorMsg("指派不能为空");
  3697. return;
  3698. }
  3699. string errMsg = "";
  3700. string suname = commonHelper.getSupplierNameById(sid);
  3701. foreach (string ctid in eidList)
  3702. {
  3703. CeErpTradeCell entity = null;
  3704. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3705. if (entity != null)
  3706. {
  3707. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3708. {
  3709. errMsg += (ctid + "指派失败!!!");
  3710. continue;
  3711. }
  3712. entity.SupplierId = sid;
  3713. entity.Update();
  3714. commonHelper.UpdateRelationOrder(entity.ctid);
  3715. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3716. if (entity.OrderState >= 6)
  3717. {
  3718. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3719. //{
  3720. // string msl = entity.MakeSupplier;
  3721. // string[] mslist = msl.Split(',');
  3722. // sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={2} where ID in (select top {1} ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, mslist.Length,sid);
  3723. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3724. //}
  3725. //else
  3726. //{
  3727. StringBuilder sql = new StringBuilder();
  3728. sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={1},MakeSupplier='{2}' where ID in (select top 1 ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, sid, entity.MakeSupplier);
  3729. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3730. //}
  3731. }
  3732. }
  3733. else
  3734. {
  3735. continue;
  3736. }
  3737. }
  3738. if (errMsg.Length > 0)
  3739. {
  3740. returnErrorMsg(errMsg);
  3741. return;
  3742. }
  3743. returnSuccessMsg("操作成功!");
  3744. return;
  3745. }
  3746. }
  3747. public void assign_erp_makesupplier()
  3748. {
  3749. if (UrlPostParmsCheck("ctid"))
  3750. {
  3751. string eids = GetPostString("ctid");
  3752. string sname = GetPostString("SupplierName");
  3753. string[] eidList = eids.Split(',');
  3754. if (eidList.Length <= 0)
  3755. {
  3756. returnErrorMsg("指派不能为空");
  3757. return;
  3758. }
  3759. List<string> tLst = new List<string>();
  3760. foreach (string ctid in eidList)
  3761. {
  3762. CeErpTradeCell entity = null;
  3763. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3764. if (entity != null)
  3765. {
  3766. entity.MakeSupplier = sname;
  3767. entity.Update();
  3768. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3769. tLst.Add("'" + ctid + "'");
  3770. }
  3771. else
  3772. {
  3773. continue;
  3774. }
  3775. }
  3776. string ctids = string.Join(",", tLst.ToArray());
  3777. StringBuilder sql2 = new StringBuilder();
  3778. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3779. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3780. returnSuccessMsg("操作成功!");
  3781. return;
  3782. }
  3783. }
  3784. public void ins_erp_returnreason()
  3785. {
  3786. if (UrlPostParmsCheck("ctid"))
  3787. {
  3788. string eid = GetPostString("ctid");
  3789. CeErpTradeCell entity = null;
  3790. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3791. string userpost = CurrentUser.UserPost.Post.Code;
  3792. if (entity != null)
  3793. {
  3794. bool isPlace = false;
  3795. if (entity.OrderState > 6)
  3796. {
  3797. returnErrorMsg("已发货无法打回!");
  3798. return;
  3799. }
  3800. if (entity.OrderState == 6)
  3801. {
  3802. isPlace = true;
  3803. }
  3804. bool isNeedUpdateCell2 = false;
  3805. if (entity.OrderState >= 6)
  3806. {
  3807. isNeedUpdateCell2 = true;
  3808. }
  3809. int returnTag = 2;
  3810. if (userpost == "Supplier")
  3811. {
  3812. returnTag = 1;
  3813. }
  3814. int toType = GetPostInt("totype");
  3815. string fromType = "3";
  3816. if (entity.OrderState < 5)
  3817. {
  3818. fromType = "3";
  3819. }
  3820. else
  3821. {
  3822. fromType = "4";
  3823. }
  3824. if (entity.IsXianHuo == 0)
  3825. {
  3826. if (returnTag == 2)
  3827. {
  3828. if (toType == 1)
  3829. {
  3830. entity.OrderState = 0;
  3831. entity.ReturnUserType = 1;
  3832. string clearman = GetPostString("clearman");
  3833. if (!string.IsNullOrEmpty(clearman))
  3834. {
  3835. entity.DesignUserId = 0;
  3836. }
  3837. }
  3838. else
  3839. {
  3840. entity.OrderState = 3;
  3841. entity.ReturnUserType = 2;
  3842. }
  3843. entity.IsReadTag = 1;
  3844. }
  3845. else if (returnTag == 1)
  3846. {
  3847. entity.OrderState = 5;
  3848. }
  3849. entity.IsVerifyToSupplier = false;
  3850. }
  3851. if (entity.IsXianHuo == 1)
  3852. {
  3853. entity.OrderState = 5;
  3854. }
  3855. entity.UnusualTag = 0;
  3856. entity.UnusualTime = null;
  3857. entity.UnusualCon = "";
  3858. entity.IsReturn = returnTag;
  3859. entity.ReturnTime = DateTime.Now;
  3860. entity.UpdateTime = DateTime.Now;
  3861. entity.ReturnReason = GetPostString("returnreason");
  3862. entity.Update();
  3863. if (entity.OrderState == 3)
  3864. {
  3865. ApiVo apiVo = new ApiVo();
  3866. apiVo.orderNumber = entity.ctid;
  3867. apiVo.actionName = "rebutDesign";
  3868. apiVo.orderRemarks = entity.ReturnReason;
  3869. designHelper.API_WorkCore(apiVo);//rebutDesign
  3870. }
  3871. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3872. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3873. {
  3874. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3875. }
  3876. CeErpSukuraData.createInfo(entity.ctid, 5);
  3877. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3878. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3879. if (isPlace)
  3880. {
  3881. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3882. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3883. if (dth != null && dth.Rows.Count > 0)
  3884. {
  3885. dataSendOrderBean dataSendOrderBean = null;
  3886. foreach (DataRow item in dth.Rows)
  3887. {
  3888. try
  3889. {
  3890. dataSendOrderBean = new dataSendOrderBean();
  3891. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3892. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3893. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3894. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3895. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3896. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3897. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3898. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3899. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3900. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3901. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3902. dataSendOrderBean.Radio1723534706288 = "打回";
  3903. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3904. if (result != null)
  3905. {
  3906. if ("0".Equals(result.errcode))
  3907. {
  3908. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3909. }
  3910. else
  3911. {
  3912. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3913. }
  3914. }
  3915. }
  3916. catch (Exception ex)
  3917. {
  3918. }
  3919. }
  3920. }
  3921. }
  3922. if (isNeedUpdateCell2)
  3923. {
  3924. if (entity.MakeSupplier.IndexOf(",") != -1)
  3925. {
  3926. StringBuilder sql2 = new StringBuilder();
  3927. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 2 ID from ce_erptradecell2 where ctid='{1}' order by ID desc) ", entity.ReturnReason, entity.ctid, returnTag);
  3928. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3929. }
  3930. else
  3931. {
  3932. StringBuilder sql2 = new StringBuilder();
  3933. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 1 ID from ce_erptradecell2 where ctid='{1}' order by ID desc)", entity.ReturnReason, entity.ctid, returnTag);
  3934. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3935. }
  3936. }
  3937. returnSuccessMsg("操作成功!");
  3938. return;
  3939. }
  3940. returnErrorMsg("找不到订单记录");
  3941. }
  3942. }
  3943. public void cyt_erp_returnreason()
  3944. {
  3945. if (UrlPostParmsCheck("ctid"))
  3946. {
  3947. string eid = GetPostString("ctid");
  3948. CeErpTradeCell entity = null;
  3949. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3950. string userpost = CurrentUser.UserPost.Post.Code;
  3951. if (entity != null)
  3952. {
  3953. if (entity.OrderState > 6)
  3954. {
  3955. returnErrorMsg("已发货无法打回!");
  3956. return;
  3957. }
  3958. JObject jsonObject = new JObject
  3959. {
  3960. { "Userid", "77886" },
  3961. { "Pwd", "lt666888" },
  3962. { "LTOrderId",eid }
  3963. };
  3964. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3965. JObject jsonObjects = JObject.Parse(response);
  3966. string msg = (string)jsonObjects["msg"];
  3967. if (msg != "取消成功")
  3968. {
  3969. returnErrorMsg(msg);
  3970. return;
  3971. }
  3972. bool isNeedUpdateCell2 = false;
  3973. if (entity.OrderState >= 6)
  3974. {
  3975. isNeedUpdateCell2 = true;
  3976. }
  3977. int returnTag = 2;
  3978. if (userpost == "Supplier")
  3979. {
  3980. returnTag = 1;
  3981. }
  3982. if (entity.IsXianHuo == 0)
  3983. {
  3984. if (returnTag == 2)
  3985. {
  3986. int toType = GetPostInt("totype");
  3987. if (toType == 1)
  3988. {
  3989. entity.OrderState = 0;
  3990. entity.ReturnUserType = 1;
  3991. }
  3992. else
  3993. {
  3994. entity.OrderState = 4;
  3995. entity.ReturnUserType = 2;
  3996. }
  3997. entity.IsReadTag = 1;
  3998. }
  3999. else if (returnTag == 1)
  4000. {
  4001. entity.OrderState = 5;
  4002. }
  4003. entity.IsVerifyToSupplier = false;
  4004. }
  4005. entity.UnusualTag = 0;
  4006. entity.UnusualTime = null;
  4007. entity.UnusualCon = "";
  4008. entity.IsReturn = returnTag;
  4009. entity.ReturnTime = DateTime.Now;
  4010. entity.ReturnReason = GetPostString("returnreason");
  4011. entity.Update();
  4012. if (entity.OrderState == 4)
  4013. {
  4014. ApiVo apiVo = new ApiVo();
  4015. apiVo.orderNumber = entity.ctid;
  4016. apiVo.actionName = "rebutDesign";
  4017. apiVo.orderRemarks = entity.ReturnReason;
  4018. designHelper.API_WorkCore(apiVo);//rebutDesign
  4019. }
  4020. CeErpSukuraData.createInfo(entity.ctid, 5);
  4021. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4022. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4023. if (isNeedUpdateCell2)
  4024. {
  4025. if (entity.MakeSupplier.IndexOf(",") != -1)
  4026. {
  4027. StringBuilder sql2 = new StringBuilder();
  4028. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 2 ID from ce_erptradecell2 where ctid='{1}' order by ID desc) ", entity.ReturnReason, entity.ctid, returnTag);
  4029. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4030. }
  4031. else
  4032. {
  4033. StringBuilder sql2 = new StringBuilder();
  4034. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 1 ID from ce_erptradecell2 where ctid='{1}' order by ID desc)", entity.ReturnReason, entity.ctid, returnTag);
  4035. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4036. }
  4037. }
  4038. returnSuccessMsg("操作成功!");
  4039. return;
  4040. }
  4041. returnErrorMsg("找不到订单记录");
  4042. }
  4043. }
  4044. public void upd_erp_xianhuoreturntag()
  4045. {
  4046. if (UrlPostParmsCheck("ctid"))
  4047. {
  4048. string eids = GetPostString("ctid");
  4049. string[] ctids = eids.Split(',');
  4050. foreach (string ctid in ctids)
  4051. {
  4052. CeErpTradeCell entity = null;
  4053. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4054. if (entity != null)
  4055. {
  4056. entity.IsReturn = 0;
  4057. entity.Update();
  4058. CeErpSukuraData.createInfo(entity.ctid, 5);
  4059. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4060. }
  4061. }
  4062. returnSuccessMsg("操作成功!");
  4063. return;
  4064. }
  4065. }
  4066. public void get_erp_waitdeliverylist()
  4067. {
  4068. DataStruct dStruct = GetPostStruct();
  4069. List<string> lw = new List<string>();
  4070. string tid = GetPostString("ctid");
  4071. if (tid.Length > 0)
  4072. {
  4073. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4074. if (tid.Length > 5)
  4075. {
  4076. List<string> tids = getTidByCtidLike(tid);
  4077. if (tids.Count > 0 && tids.Count < 10)
  4078. {
  4079. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4080. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4081. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4082. {
  4083. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4084. }*/
  4085. }
  4086. }
  4087. lw.Add(tid_sql);
  4088. }
  4089. string shopname = GetPostString("shopname");
  4090. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4091. string buyernick = GetPostString("buyer_nick");
  4092. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4093. //if (tid.Length == 0 && buyernick.Length == 0)
  4094. //{
  4095. // lw.Add(string.Format("IsRefund<={0}", 1));
  4096. //}
  4097. string customer = GetPostString("customer");
  4098. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4099. string design = GetPostString("design");
  4100. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4101. string orderState = GetPostString("orderState");
  4102. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4103. string address = GetPostString("address");
  4104. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4105. string sellermemo = GetPostString("seller_memo");
  4106. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4107. string supplier = GetPostString("supplier");
  4108. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4109. string OrderArea = GetPostString("order_area");
  4110. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4111. string placedate1 = GetPostString("placedate1");
  4112. string placedate2 = GetPostString("placedate2");
  4113. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4114. if (fdw.Length > 0) lw.Add(fdw);
  4115. string price1 = GetPostString("price1");
  4116. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4117. string price2 = GetPostString("price2");
  4118. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4119. string unusualCon = GetPostString("unusualcon");
  4120. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4121. string otherMemo = GetPostString("otherMemo");
  4122. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4123. string posTag = CurrentUser.UserPost.Post.Code;
  4124. if (posTag == "Supplier")
  4125. {
  4126. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4127. }
  4128. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4129. lw.Add(string.Format("type != 'PDD' "));
  4130. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4131. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4132. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4133. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4134. writeGridDataTableJson(dStruct.TotalCount, dt);
  4135. }
  4136. public void get_erp_changedeliverylist()
  4137. {
  4138. DataStruct dStruct = GetPostStruct();
  4139. List<string> lw = new List<string>();
  4140. string tid = GetPostString("ctid");
  4141. if (tid.Length > 0)
  4142. {
  4143. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4144. if (tid.Length > 5)
  4145. {
  4146. List<string> tids = getTidByCtidLike(tid);
  4147. if (tids.Count > 0 && tids.Count < 10)
  4148. {
  4149. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4150. }
  4151. }
  4152. lw.Add(tid_sql);
  4153. }
  4154. string shopname = GetPostString("shopname");
  4155. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4156. string buyernick = GetPostString("buyer_nick");
  4157. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4158. //if (tid.Length == 0 && buyernick.Length == 0)
  4159. //{
  4160. // lw.Add(string.Format("IsRefund<={0}", 1));
  4161. //}
  4162. string customer = GetPostString("customer");
  4163. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4164. string design = GetPostString("design");
  4165. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4166. string orderState = GetPostString("orderState");
  4167. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4168. string address = GetPostString("address");
  4169. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4170. string sellermemo = GetPostString("seller_memo");
  4171. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4172. string supplier = GetPostString("supplier");
  4173. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4174. string OrderArea = GetPostString("order_area");
  4175. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4176. string placedate1 = GetPostString("placedate1");
  4177. string placedate2 = GetPostString("placedate2");
  4178. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4179. if (fdw.Length > 0) lw.Add(fdw);
  4180. string price1 = GetPostString("price1");
  4181. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4182. string price2 = GetPostString("price2");
  4183. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4184. string unusualCon = GetPostString("unusualcon");
  4185. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4186. string otherMemo = GetPostString("otherMemo");
  4187. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4188. string posTag = CurrentUser.UserPost.Post.Code;
  4189. if (posTag == "Supplier")
  4190. {
  4191. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4192. }
  4193. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4194. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4195. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4196. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4197. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4198. /*if (tid.Length > 0)
  4199. {
  4200. List<string> tids = new List<string>();
  4201. if (dt != null && dt.Rows.Count > 0)
  4202. {
  4203. foreach (DataRow item in dt.Rows)
  4204. {
  4205. tids.Add("'" + item["tid"] + "'");
  4206. }
  4207. }
  4208. if (tids.Count > 0)
  4209. {
  4210. lw.RemoveAt(0);
  4211. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4212. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4213. dt = WebCache.GetData("view_erptradecell", dStruct);
  4214. }
  4215. }*/
  4216. writeGridDataTableJson(dStruct.TotalCount, dt);
  4217. }
  4218. public void get_erp_pddderiving()
  4219. {
  4220. DataStruct dStruct = GetPostStruct();
  4221. List<string> lw = new List<string>();
  4222. string tid = GetPostString("ctid");
  4223. if (tid.Length > 0)
  4224. {
  4225. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4226. if (tid.Length > 5)
  4227. {
  4228. List<string> tids = getTidByCtidLike(tid);
  4229. if (tids.Count > 0 && tids.Count < 10)
  4230. {
  4231. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4232. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4233. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4234. {
  4235. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4236. }*/
  4237. }
  4238. }
  4239. lw.Add(tid_sql);
  4240. }
  4241. string shopname = GetPostString("shopname");
  4242. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4243. string buyernick = GetPostString("buyer_nick");
  4244. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4245. //if (tid.Length == 0 && buyernick.Length == 0)
  4246. //{
  4247. // lw.Add(string.Format("IsRefund<={0}", 1));
  4248. //}
  4249. string customer = GetPostString("customer");
  4250. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4251. string design = GetPostString("design");
  4252. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4253. string orderState = GetPostString("orderState");
  4254. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4255. string address = GetPostString("address");
  4256. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4257. string sellermemo = GetPostString("seller_memo");
  4258. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4259. string supplier = GetPostString("supplier");
  4260. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4261. string OrderArea = GetPostString("order_area");
  4262. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4263. string placedate1 = GetPostString("placedate1");
  4264. string placedate2 = GetPostString("placedate2");
  4265. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4266. if (fdw.Length > 0) lw.Add(fdw);
  4267. string price1 = GetPostString("price1");
  4268. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4269. string price2 = GetPostString("price2");
  4270. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4271. string unusualCon = GetPostString("unusualcon");
  4272. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4273. string posTag = CurrentUser.UserPost.Post.Code;
  4274. if (posTag == "Supplier")
  4275. {
  4276. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4277. }
  4278. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4279. lw.Add(string.Format("type = 'PDD' "));
  4280. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4281. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4282. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4283. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4284. /*if (tid.Length > 0)
  4285. {
  4286. List<string> tids = new List<string>();
  4287. if (dt != null && dt.Rows.Count > 0)
  4288. {
  4289. foreach (DataRow item in dt.Rows)
  4290. {
  4291. tids.Add("'" + item["tid"] + "'");
  4292. }
  4293. }
  4294. if (tids.Count > 0)
  4295. {
  4296. lw.RemoveAt(0);
  4297. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4298. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4299. dt = WebCache.GetData("view_erptradecell", dStruct);
  4300. }
  4301. }*/
  4302. writeGridDataTableJson(dStruct.TotalCount, dt);
  4303. }
  4304. public void get_erp_jdderiving()
  4305. {
  4306. DataStruct dStruct = GetPostStruct();
  4307. List<string> lw = new List<string>();
  4308. string tid = GetPostString("ctid");
  4309. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4310. string shopname = GetPostString("shopname");
  4311. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4312. string buyernick = GetPostString("buyer_nick");
  4313. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4314. //if (tid.Length == 0 && buyernick.Length == 0)
  4315. //{
  4316. // lw.Add(string.Format("IsRefund<={0}", 1));
  4317. //}
  4318. string customer = GetPostString("customer");
  4319. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4320. string design = GetPostString("design");
  4321. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4322. string orderState = GetPostString("orderState");
  4323. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4324. string address = GetPostString("address");
  4325. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4326. string sellermemo = GetPostString("seller_memo");
  4327. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4328. string supplier = GetPostString("supplier");
  4329. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4330. string OrderArea = GetPostString("order_area");
  4331. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4332. string placedate1 = GetPostString("placedate1");
  4333. string placedate2 = GetPostString("placedate2");
  4334. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4335. if (fdw.Length > 0) lw.Add(fdw);
  4336. string price1 = GetPostString("price1");
  4337. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4338. string price2 = GetPostString("price2");
  4339. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4340. string unusualCon = GetPostString("unusualcon");
  4341. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4342. string posTag = CurrentUser.UserPost.Post.Code;
  4343. if (posTag == "Supplier")
  4344. {
  4345. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4346. }
  4347. lw.Add(string.Format("OrderState = 6 "));
  4348. lw.Add(string.Format("type = 'JD' "));
  4349. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4350. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4351. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4352. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4353. writeGridDataTableJson(dStruct.TotalCount, dt);
  4354. }
  4355. public void get_erp_demoorderlist()
  4356. {
  4357. DataStruct dStruct = GetPostStruct();
  4358. List<string> lw = new List<string>();
  4359. string tid = GetPostString("ctid");
  4360. if (tid.Length > 0)
  4361. {
  4362. string select_tid = getTidByCtid(tid);
  4363. lw.Add(string.Format("tid='{0}'", select_tid));
  4364. }
  4365. string shopname = GetPostString("shopname");
  4366. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4367. string buyernick = GetPostString("buyer_nick");
  4368. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4369. string customer = GetPostString("customer");
  4370. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4371. string design = GetPostString("design");
  4372. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4373. string orderState = GetPostString("orderState");
  4374. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4375. string address = GetPostString("address");
  4376. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4377. string sellermemo = GetPostString("seller_memo");
  4378. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4379. string supplier = GetPostString("supplier");
  4380. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4381. string OrderArea = GetPostString("order_area");
  4382. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4383. string date1 = GetPostString("date1");
  4384. string date2 = GetPostString("date2");
  4385. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4386. if (dw.Length > 0) lw.Add(dw);
  4387. string price1 = GetPostString("price1");
  4388. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4389. string price2 = GetPostString("price2");
  4390. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4391. string posTag = CurrentUser.UserPost.Post.Code;
  4392. if (posTag == "Supplier")
  4393. {
  4394. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4395. }
  4396. //lw.Add(string.Format("OrderState = 6 "));
  4397. lw.Add(string.Format("IsSample={0}", 3));
  4398. lw.Add(string.Format("IsRefund<={0}", 1));
  4399. dStruct.Order = "pay_time desc";
  4400. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4401. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4402. writeGridDataTableJson(dStruct.TotalCount, dt);
  4403. }
  4404. public void save_erp_checkmemo()
  4405. {
  4406. if (UrlPostParmsCheck("ctid"))
  4407. {
  4408. string ctid = GetPostString("ctid");
  4409. CeErpTradeCell entity = null;
  4410. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4411. if (entity != null)
  4412. {
  4413. entity.CheckMemo = GetPostString("CheckMemo");
  4414. entity.Update();
  4415. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4416. if (trade != null)
  4417. {
  4418. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4419. }
  4420. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4421. returnSuccessMsg("保存成功!");
  4422. return;
  4423. }
  4424. returnErrorMsg("找不到记录");
  4425. }
  4426. }
  4427. public void get_erp_returnlist()
  4428. {
  4429. DataStruct dStruct = GetPostStruct();
  4430. List<string> lw = new List<string>();
  4431. string tid = GetPostString("ctid");
  4432. if (tid.Length > 0)
  4433. {
  4434. string select_tid = getTidByCtid(tid);
  4435. lw.Add(string.Format("tid='{0}'", select_tid));
  4436. }
  4437. string shopname = GetPostString("shopname");
  4438. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4439. string buyernick = GetPostString("buyer_nick");
  4440. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4441. string customer = GetPostString("customer");
  4442. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4443. string design = GetPostString("design");
  4444. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4445. string orderState = GetPostString("orderState");
  4446. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4447. string address = GetPostString("address");
  4448. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4449. string sellermemo = GetPostString("seller_memo");
  4450. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4451. string supplier = GetPostString("supplier");
  4452. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4453. string date1 = GetPostString("date1");
  4454. string date2 = GetPostString("date2");
  4455. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4456. if (dw.Length > 0) lw.Add(dw);
  4457. string bdate1 = GetPostString("backdate1");
  4458. string bdate2 = GetPostString("backdate2");
  4459. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4460. if (dw_back.Length > 0) lw.Add(dw_back);
  4461. string price1 = GetPostString("price1");
  4462. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4463. string price2 = GetPostString("price2");
  4464. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4465. lw.Add(string.Format("IsReturn>0"));
  4466. lw.Add(string.Format("IsXianHuo=0"));
  4467. lw.Add(string.Format("IsReturn!=3"));
  4468. string backtype = GetPostString("backtype");
  4469. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4470. dStruct.Order = "FinishDesignTime desc";
  4471. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4472. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4473. writeGridDataTableJson(dStruct.TotalCount, dt);
  4474. }
  4475. public void get_erp_today_sumreturn()
  4476. {
  4477. DataStruct dStruct = GetPostStruct();
  4478. List<string> lw = new List<string>();
  4479. string bdate1 = GetPostString("returnTimeS");
  4480. string bdate2 = GetPostString("returnTimeE");
  4481. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4482. if (dw_back.Length > 0) lw.Add(dw_back);
  4483. lw.Add(string.Format("IsReturn=0"));
  4484. lw.Add(string.Format("IsXianHuo=0"));
  4485. string mainWhere = string.Join(" and ", lw.ToArray());
  4486. string sql = "";
  4487. if (dw_back.Length > 0)
  4488. {
  4489. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4490. }
  4491. else
  4492. {
  4493. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + " and ReturnTime >= '" + DateTime.Now.Date + "') as today_finish from view_erptradecell where ReturnTime >= '" + DateTime.Now.Date + "'";
  4494. }
  4495. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4496. decimal total = 0, today_finish = 0;
  4497. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4498. {
  4499. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4500. }
  4501. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4502. {
  4503. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4504. }
  4505. var res = new
  4506. {
  4507. data = total,
  4508. data1 = today_finish,
  4509. };
  4510. string ro_jsond = JsonConvert.SerializeObject(res);
  4511. returnSuccess(ro_jsond);
  4512. return;
  4513. }
  4514. public void get_erp_allreturnlist()
  4515. {
  4516. DataStruct dStruct = GetPostStruct();
  4517. List<string> lw = new List<string>();
  4518. string tid = GetPostString("ctid");
  4519. if (tid.Length > 0)
  4520. {
  4521. string select_tid = getTidByCtid(tid);
  4522. lw.Add(string.Format("tid='{0}'", select_tid));
  4523. }
  4524. string shopname = GetPostString("shopname");
  4525. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4526. string buyernick = GetPostString("buyer_nick");
  4527. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4528. string customer = GetPostString("customer");
  4529. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4530. string design = GetPostString("design");
  4531. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4532. string orderState = GetPostString("orderState");
  4533. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4534. string address = GetPostString("address");
  4535. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4536. string sellermemo = GetPostString("seller_memo");
  4537. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4538. string supplier = GetPostString("supplier");
  4539. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4540. string date1 = GetPostString("date1");
  4541. string date2 = GetPostString("date2");
  4542. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4543. if (dw.Length > 0) lw.Add(dw);
  4544. string bdate1 = GetPostString("backdate1");
  4545. string bdate2 = GetPostString("backdate2");
  4546. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4547. if (dw_back.Length > 0) lw.Add(dw_back);
  4548. string price1 = GetPostString("price1");
  4549. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4550. string price2 = GetPostString("price2");
  4551. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4552. string backreason = GetPostString("backreason");
  4553. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4554. lw.Add(string.Format("IsXianHuo=0"));
  4555. lw.Add(string.Format("ReturnTime != ''"));
  4556. string backtype = GetPostString("backtype");
  4557. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4558. dStruct.Order = "FinishDesignTime desc";
  4559. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4560. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4561. writeGridDataTableJson(dStruct.TotalCount, dt);
  4562. }
  4563. public void get_erp_aftersalereturnlist()
  4564. {
  4565. DataStruct dStruct = GetPostStruct();
  4566. List<string> lw = new List<string>();
  4567. string tid = GetPostString("ctid");
  4568. if (tid.Length > 0)
  4569. {
  4570. string select_tid = getTidByCtid(tid);
  4571. lw.Add(string.Format("tid='{0}'", select_tid));
  4572. }
  4573. string shopname = GetPostString("shopname");
  4574. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4575. string buyernick = GetPostString("buyer_nick");
  4576. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4577. string customer = GetPostString("customer");
  4578. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4579. string design = GetPostString("design");
  4580. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4581. string orderState = GetPostString("orderState");
  4582. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4583. string address = GetPostString("address");
  4584. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4585. string sellermemo = GetPostString("seller_memo");
  4586. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4587. string supplier = GetPostString("supplier");
  4588. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4589. string date1 = GetPostString("date1");
  4590. string date2 = GetPostString("date2");
  4591. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4592. if (dw.Length > 0) lw.Add(dw);
  4593. string bdate1 = GetPostString("backdate1");
  4594. string bdate2 = GetPostString("backdate2");
  4595. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4596. if (dw_back.Length > 0) lw.Add(dw_back);
  4597. string price1 = GetPostString("price1");
  4598. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4599. string price2 = GetPostString("price2");
  4600. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4601. lw.Add(string.Format("IsReturn=3"));
  4602. string backtype = GetPostString("backtype");
  4603. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4604. string backreason = GetPostString("backreason");
  4605. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4606. dStruct.Order = "ReturnTime desc";
  4607. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4608. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4609. writeGridDataTableJson(dStruct.TotalCount, dt);
  4610. }
  4611. public void get_erp_xianhuoreturnlist()
  4612. {
  4613. DataStruct dStruct = GetPostStruct();
  4614. List<string> lw = new List<string>();
  4615. string tid = GetPostString("ctid");
  4616. if (tid.Length > 0)
  4617. {
  4618. string select_tid = getTidByCtid(tid);
  4619. lw.Add(string.Format("tid='{0}'", select_tid));
  4620. }
  4621. string shopname = GetPostString("shopname");
  4622. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4623. string buyernick = GetPostString("buyer_nick");
  4624. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4625. string customer = GetPostString("customer");
  4626. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4627. string design = GetPostString("design");
  4628. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4629. string orderState = GetPostString("orderState");
  4630. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4631. string address = GetPostString("address");
  4632. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4633. string sellermemo = GetPostString("seller_memo");
  4634. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4635. string supplier = GetPostString("supplier");
  4636. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4637. string OrderArea = GetPostString("order_area");
  4638. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4639. string date1 = GetPostString("date1");
  4640. string date2 = GetPostString("date2");
  4641. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4642. if (dw.Length > 0) lw.Add(dw);
  4643. string price1 = GetPostString("price1");
  4644. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4645. string price2 = GetPostString("price2");
  4646. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4647. string posTag = CurrentUser.UserPost.Post.Code;
  4648. if (posTag == "Supplier")
  4649. {
  4650. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4651. }
  4652. lw.Add(string.Format("OrderState=6 "));
  4653. lw.Add(string.Format("IsXianHuo=1 "));
  4654. lw.Add(string.Format("IsReturn>0 "));
  4655. lw.Add(string.Format("IsReturn!=3"));
  4656. lw.Add(string.Format("IsRefund<={0}", 1));
  4657. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4658. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4659. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4660. writeGridDataTableJson(dStruct.TotalCount, dt);
  4661. }
  4662. public void set_erp_orderdelivery()
  4663. {
  4664. if (UrlPostParmsCheck("ctid"))
  4665. {
  4666. string eid = GetPostString("ctid");
  4667. CeErpTradeCell entity = null;
  4668. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4669. if (entity != null)
  4670. {
  4671. if (entity.OrderState >= 7)
  4672. {
  4673. returnErrorMsg("此单已发货,无需重复发货");
  4674. return;
  4675. }
  4676. if (entity.OrderState != 6)
  4677. {
  4678. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4679. return;
  4680. }
  4681. string shop = GetPostString("seller_nick");
  4682. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4683. string comName = GetPostString("comName");
  4684. string comCode = GetPostString("comCode");
  4685. string outSid = GetPostString("outSid");
  4686. string deliveryType = GetPostString("deliveryType");
  4687. string deliveryMemo = GetPostString("deliveryMemo");
  4688. outSid = outSid.Trim();
  4689. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4690. if (mainEn == null)
  4691. {
  4692. returnErrorMsg("找不到原始订单记录");
  4693. return;
  4694. }
  4695. bool isInitOrderDeliv = false;
  4696. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4697. {
  4698. isInitOrderDeliv = true;
  4699. }
  4700. string apires = "";
  4701. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4702. if (entity.ctid.IndexOf("N") != -1 || entity.ctid.IndexOf("P") != -1 || entity.ctid.IndexOf("A") != -1 || entity.ctid.IndexOf("X") != -1 || entity.ctid.IndexOf("S") != -1)
  4703. {
  4704. apires = "发货成功true";
  4705. }
  4706. else
  4707. {
  4708. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4709. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4710. }
  4711. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4712. {
  4713. entity.OrderState = 7;//发货后订单已发货
  4714. entity.OutSid = outSid;
  4715. entity.MemoOpt = 0;
  4716. entity.UpdateTime = DateTime.Now;
  4717. entity.FinishDeliveryTime = DateTime.Now;
  4718. entity.Update();
  4719. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4720. commonHelper.UpdateRelationOrder(entity.ctid);
  4721. //还要插入快递信息到 快递信息表
  4722. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4723. exinfo.tid = eid;
  4724. exinfo.out_sid = outSid;
  4725. exinfo.company_code = comCode;
  4726. exinfo.company_name = comName;
  4727. exinfo.delivery_memo = deliveryMemo;
  4728. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4729. exinfo.deliveryType = deliveryType;
  4730. exinfo.Create();
  4731. returnSuccessMsg("发货操作成功!");
  4732. commonHelper.UpdateRelationOrder(entity.ctid);
  4733. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4734. CeErpSukuraData.createInfo(entity.ctid, 4);
  4735. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  4736. {
  4737. commonHelper.sendCytExpress(exinfo);
  4738. }
  4739. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4740. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4741. }
  4742. else
  4743. {
  4744. string errmsg = commonHelper.KeepChinese(apires);
  4745. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4746. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4747. }
  4748. return;
  4749. }
  4750. returnErrorMsg("找不到订单记录");
  4751. }
  4752. }
  4753. public void set_erp_multidelivery()
  4754. {
  4755. string eids = GetPostString("tids");
  4756. string[] eidList = eids.Split(',');
  4757. if (eidList.Length <= 0)
  4758. {
  4759. returnErrorMsg("发货不能为空");
  4760. return;
  4761. }
  4762. foreach (string ctid in eidList)
  4763. {
  4764. if (ctid.Length <= 0) continue;
  4765. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4766. if (expInfo != null)
  4767. {
  4768. StringBuilder sql = new StringBuilder();
  4769. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4770. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4771. if (dt.Rows.Count > 0)
  4772. {
  4773. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4774. {
  4775. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4776. expInfo.state = "异常";
  4777. expInfo.isMultiDelivery = 1;
  4778. expInfo.Update();
  4779. continue;
  4780. }
  4781. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4782. {
  4783. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4784. expInfo.state = "异常";
  4785. expInfo.Update();
  4786. continue;
  4787. }
  4788. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4789. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4790. bool isInitOrderDeliv = false;
  4791. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4792. {
  4793. isInitOrderDeliv = true;
  4794. expInfo.isMultiDelivery = 1;
  4795. }
  4796. if (ctid.IndexOf("N") != -1)
  4797. {
  4798. StringBuilder sqlbucha = new StringBuilder();
  4799. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4800. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4801. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4802. commonHelper.UpdateRelationOrder(ctid);
  4803. expInfo.delivery_memo = "发货成功";
  4804. expInfo.state = "发货成功";
  4805. expInfo.isMultiDelivery = 1;
  4806. expInfo.Update();
  4807. }
  4808. else
  4809. {
  4810. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4811. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4812. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4813. {
  4814. expInfo.delivery_memo = "发货成功";
  4815. expInfo.state = "发货成功";
  4816. expInfo.isMultiDelivery = 1;
  4817. expInfo.Update();
  4818. commonHelper.UpdateRelationOrder(ctid);
  4819. CeErpSukuraData.createInfo(ctid, 4);
  4820. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4821. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4822. }
  4823. else
  4824. {
  4825. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4826. expInfo.state = "异常";
  4827. expInfo.Update();
  4828. }
  4829. }
  4830. }
  4831. }
  4832. }
  4833. returnSuccessMsg("操作完成");
  4834. }
  4835. public void reset_erp_memoopt()
  4836. {
  4837. if (UrlPostParmsCheck("ctid"))
  4838. {
  4839. string eid = GetPostString("ctid");
  4840. CeErpTradeCell entity = null;
  4841. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4842. if (entity != null)
  4843. {
  4844. string stropt = "";
  4845. if (entity.MemoOpt == 1)
  4846. {
  4847. stropt = "“改稿”";
  4848. }
  4849. else if (entity.MemoOpt == 2)
  4850. {
  4851. stropt = "“定稿”";
  4852. }
  4853. else if (entity.MemoOpt == 3)
  4854. {
  4855. stropt = "“完成查货”";
  4856. CeErpSukuraData.createInfo(entity.ctid, 6);
  4857. }
  4858. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4859. entity.UpdateTime = DateTime.Now;
  4860. entity.MemoOpt = 0;
  4861. entity.Update();
  4862. returnSuccessMsg("操作成功!");
  4863. return;
  4864. }
  4865. returnErrorMsg("找不到记录");
  4866. }
  4867. }
  4868. public void get_erp_deliveryunusual()
  4869. {
  4870. DataStruct dStruct = GetPostStruct();
  4871. List<string> lw = new List<string>();
  4872. string tid = GetPostString("ctid");
  4873. if (tid.Length > 0)
  4874. {
  4875. string select_tid = getTidByCtid(tid);
  4876. lw.Add(string.Format("tid='{0}'", select_tid));
  4877. }
  4878. string shopname = GetPostString("shopname");
  4879. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4880. string buyernick = GetPostString("buyer_nick");
  4881. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4882. string customer = GetPostString("customer");
  4883. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4884. string design = GetPostString("design");
  4885. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4886. string sellermemo = GetPostString("seller_memo");
  4887. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4888. string supplier = GetPostString("supplier");
  4889. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4890. string date1 = GetPostString("date1");
  4891. string date2 = GetPostString("date2");
  4892. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4893. if (dw.Length > 0) lw.Add(dw);
  4894. string placedate1 = GetPostString("placedate1");
  4895. string placedate2 = GetPostString("placedate2");
  4896. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4897. if (dw_place.Length > 0) lw.Add(dw_place);
  4898. string price1 = GetPostString("price1");
  4899. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4900. string price2 = GetPostString("price2");
  4901. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4902. string unusualCon = GetPostString("unusualcon");
  4903. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4904. string posTag = CurrentUser.UserPost.Post.Code;
  4905. if (posTag == "Supplier")
  4906. {
  4907. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4908. }
  4909. lw.Add(string.Format("OrderState = 6"));
  4910. lw.Add(string.Format("UnusualTag = 5"));
  4911. lw.Add(string.Format("IsRefund<={0}", 1));
  4912. dStruct.Order = "FinishPlaceTime desc";
  4913. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4914. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4915. writeGridDataTableJson(dStruct.TotalCount, dt);
  4916. }
  4917. public void get_erp_deliveryedlist()
  4918. {
  4919. DataStruct dStruct = GetPostStruct();
  4920. List<string> lw = new List<string>();
  4921. string tid = GetPostString("ctid");
  4922. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4923. string shopname = GetPostString("shopname");
  4924. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4925. string buyernick = GetPostString("buyer_nick");
  4926. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4927. string customer = GetPostString("customer");
  4928. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4929. string design = GetPostString("design");
  4930. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4931. string sellermemo = GetPostString("seller_memo");
  4932. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4933. string logistics = GetPostString("logistics");
  4934. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4935. string date1 = GetPostString("date1");
  4936. string date2 = GetPostString("date2");
  4937. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4938. //if (dw.Length > 0) lw.Add(dw);
  4939. string placedate1 = GetPostString("placedate1");
  4940. string placedate2 = GetPostString("placedate2");
  4941. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4942. if (fdw.Length > 0) lw.Add(fdw);
  4943. string devdate1 = GetPostString("deliverydate1");
  4944. string devdate2 = GetPostString("deliverydate2");
  4945. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4946. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4947. string price1 = GetPostString("price1");
  4948. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4949. string price2 = GetPostString("price2");
  4950. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4951. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4952. {
  4953. if (tid.Length > 0)
  4954. {
  4955. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4956. if (tid.Length > 5)
  4957. {
  4958. List<string> tids = getTidByCtidLike(tid);
  4959. if (tids.Count > 0 && tids.Count < 10)
  4960. {
  4961. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4962. }
  4963. }
  4964. lw.Add(tid_sql);
  4965. }
  4966. if (buyernick.Length > 0)
  4967. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4968. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4969. if (dw.Length > 0) lw.Add(dw);
  4970. }
  4971. else
  4972. {
  4973. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  4974. }
  4975. string posTag = CurrentUser.UserPost.Post.Code;
  4976. if (posTag == "Supplier")
  4977. {
  4978. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4979. }
  4980. else
  4981. {
  4982. string supplier = GetPostString("supplier");
  4983. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4984. }
  4985. lw.Add(string.Format(" OrderState IN (7, 8)"));
  4986. lw.Add(string.Format("type != 'PDD' "));
  4987. lw.Add(string.Format("IsRefund!={0}", 2));
  4988. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4989. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4990. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4991. /*if (tid.Length > 0)
  4992. {
  4993. List<string> tids = new List<string>();
  4994. if (dt != null && dt.Rows.Count > 0)
  4995. {
  4996. foreach (DataRow item in dt.Rows)
  4997. {
  4998. tids.Add("'" + item["tid"] + "'");
  4999. }
  5000. }
  5001. if (tids.Count > 0)
  5002. {
  5003. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5004. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5005. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5006. dt = WebCache.GetData("view_erptradecell", dStruct);
  5007. }
  5008. }*/
  5009. if (dt != null)
  5010. {
  5011. foreach (DataRow dr in dt.Rows)
  5012. {
  5013. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5014. }
  5015. }
  5016. writeGridDataTableJson(dStruct.TotalCount, dt);
  5017. }
  5018. public void get_erp_pdddeliveryed()
  5019. {
  5020. DataStruct dStruct = GetPostStruct();
  5021. List<string> lw = new List<string>();
  5022. string tid = GetPostString("ctid");
  5023. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5024. string shopname = GetPostString("shopname");
  5025. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5026. string buyernick = GetPostString("buyer_nick");
  5027. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5028. string customer = GetPostString("customer");
  5029. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5030. string design = GetPostString("design");
  5031. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5032. string sellermemo = GetPostString("seller_memo");
  5033. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5034. string logistics = GetPostString("logistics");
  5035. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5036. string date1 = GetPostString("date1");
  5037. string date2 = GetPostString("date2");
  5038. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5039. //if (dw.Length > 0) lw.Add(dw);
  5040. string placedate1 = GetPostString("placedate1");
  5041. string placedate2 = GetPostString("placedate2");
  5042. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5043. if (fdw.Length > 0) lw.Add(fdw);
  5044. string devdate1 = GetPostString("deliverydate1");
  5045. string devdate2 = GetPostString("deliverydate2");
  5046. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5047. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5048. string price1 = GetPostString("price1");
  5049. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5050. string price2 = GetPostString("price2");
  5051. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5052. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5053. {
  5054. if (tid.Length > 0)
  5055. {
  5056. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5057. if (tid.Length > 5)
  5058. {
  5059. List<string> tids = getTidByCtidLike(tid);
  5060. if (tids.Count > 0 && tids.Count < 10)
  5061. {
  5062. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5063. }
  5064. }
  5065. lw.Add(tid_sql);
  5066. }
  5067. if (buyernick.Length > 0)
  5068. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5069. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5070. if (dw.Length > 0) lw.Add(dw);
  5071. }
  5072. else
  5073. {
  5074. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5075. }
  5076. string posTag = CurrentUser.UserPost.Post.Code;
  5077. if (posTag == "Supplier")
  5078. {
  5079. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5080. }
  5081. else
  5082. {
  5083. string supplier = GetPostString("supplier");
  5084. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5085. }
  5086. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5087. lw.Add(string.Format("type = 'PDD' "));
  5088. lw.Add(string.Format("IsRefund!={0}", 2));
  5089. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5090. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5091. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5092. /* if (tid.Length > 0)
  5093. {
  5094. List<string> tids = new List<string>();
  5095. if (dt != null && dt.Rows.Count > 0)
  5096. {
  5097. foreach (DataRow item in dt.Rows)
  5098. {
  5099. tids.Add("'" + item["tid"] + "'");
  5100. }
  5101. }
  5102. if (tids.Count > 0)
  5103. {
  5104. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5105. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5106. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5107. dt = WebCache.GetData("view_erptradecell", dStruct);
  5108. }
  5109. }*/
  5110. foreach (DataRow dr in dt.Rows)
  5111. {
  5112. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5113. }
  5114. writeGridDataTableJson(dStruct.TotalCount, dt);
  5115. }
  5116. public void get_erp_jddeliveryed()
  5117. {
  5118. DataStruct dStruct = GetPostStruct();
  5119. List<string> lw = new List<string>();
  5120. string tid = GetPostString("ctid");
  5121. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5122. string shopname = GetPostString("shopname");
  5123. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5124. string buyernick = GetPostString("buyer_nick");
  5125. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5126. string customer = GetPostString("customer");
  5127. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5128. string design = GetPostString("design");
  5129. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5130. string sellermemo = GetPostString("seller_memo");
  5131. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5132. string date1 = GetPostString("date1");
  5133. string date2 = GetPostString("date2");
  5134. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5135. //if (dw.Length > 0) lw.Add(dw);
  5136. string placedate1 = GetPostString("placedate1");
  5137. string placedate2 = GetPostString("placedate2");
  5138. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5139. if (fdw.Length > 0) lw.Add(fdw);
  5140. string devdate1 = GetPostString("deliverydate1");
  5141. string devdate2 = GetPostString("deliverydate2");
  5142. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5143. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5144. string price1 = GetPostString("price1");
  5145. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5146. string price2 = GetPostString("price2");
  5147. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5148. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5149. {
  5150. if (tid.Length > 0)
  5151. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5152. if (buyernick.Length > 0)
  5153. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5154. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5155. if (dw.Length > 0) lw.Add(dw);
  5156. }
  5157. else
  5158. {
  5159. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5160. }
  5161. string posTag = CurrentUser.UserPost.Post.Code;
  5162. if (posTag == "Supplier")
  5163. {
  5164. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5165. }
  5166. else
  5167. {
  5168. string supplier = GetPostString("supplier");
  5169. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5170. }
  5171. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5172. lw.Add(string.Format("type = 'JD' "));
  5173. lw.Add(string.Format("IsRefund!={0}", 2));
  5174. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5175. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5176. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5177. foreach (DataRow dr in dt.Rows)
  5178. {
  5179. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5180. }
  5181. writeGridDataTableJson(dStruct.TotalCount, dt);
  5182. }
  5183. public void get_erp_allplacelist()
  5184. {
  5185. DataStruct dStruct = GetPostStruct();
  5186. List<string> lw = new List<string>();
  5187. string tid = GetPostString("ctid");
  5188. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5189. string shopname = GetPostString("shopname");
  5190. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5191. string buyernick = GetPostString("buyer_nick");
  5192. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5193. string customer = GetPostString("customer");
  5194. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5195. string design = GetPostString("design");
  5196. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5197. string sellermemo = GetPostString("seller_memo");
  5198. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5199. string supplier = GetPostString("supplier");
  5200. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5201. string date1 = GetPostString("date1");
  5202. string date2 = GetPostString("date2");
  5203. string pldate1 = GetPostString("placedate1");
  5204. string pldate2 = GetPostString("placedate2");
  5205. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5206. //if (dw.Length > 0) lw.Add(dw);
  5207. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5208. {
  5209. if (tid.Length > 0)
  5210. {
  5211. string select_tid = getTidByCtid(tid);
  5212. lw.Add(string.Format("tid='{0}'", select_tid));
  5213. }
  5214. if (buyernick.Length > 0)
  5215. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5216. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5217. if (dw.Length > 0) lw.Add(dw);
  5218. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5219. if (dw_place.Length > 0) lw.Add(dw_place);
  5220. }
  5221. else
  5222. {
  5223. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5224. {
  5225. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5226. }
  5227. }
  5228. string price1 = GetPostString("price1");
  5229. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5230. string price2 = GetPostString("price2");
  5231. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5232. string posTag = CurrentUser.UserPost.Post.Code;
  5233. if (posTag == "Supplier")
  5234. {
  5235. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5236. }
  5237. lw.Add(string.Format("OrderState >= 6"));
  5238. lw.Add(string.Format("IsSample != 2 "));
  5239. //lw.Add(string.Format("isDianziOrder = 0 "));
  5240. lw.Add(string.Format("SupplierId > 0 "));
  5241. //lw.Add(string.Format("IsRefund<={0}", 1));
  5242. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5243. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5244. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5245. foreach (DataRow dr in dt.Rows)
  5246. {
  5247. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5248. }
  5249. writeGridDataTableJson(dStruct.TotalCount, dt);
  5250. }
  5251. public void get_erp_financeallplacelist()
  5252. {
  5253. DataStruct dStruct = GetPostStruct();
  5254. List<string> lw = new List<string>();
  5255. string tid = GetPostString("ctid");
  5256. string shopname = GetPostString("shopname");
  5257. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5258. string buyernick = GetPostString("buyer_nick");
  5259. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5260. string customer = GetPostString("customer");
  5261. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5262. string design = GetPostString("design");
  5263. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5264. string sellermemo = GetPostString("seller_memo");
  5265. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5266. string supplier = GetPostString("supplier");
  5267. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5268. string date1 = GetPostString("date1");
  5269. string date2 = GetPostString("date2");
  5270. string pldate1 = GetPostString("placedate1");
  5271. string pldate2 = GetPostString("placedate2");
  5272. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5273. {
  5274. if (tid.Length > 0)
  5275. {
  5276. string select_tid = getTidByCtid(tid);
  5277. lw.Add(string.Format("tid='{0}'", select_tid));
  5278. }
  5279. if (buyernick.Length > 0)
  5280. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5281. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5282. if (dw.Length > 0) lw.Add(dw);
  5283. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5284. if (dw_place.Length > 0) lw.Add(dw_place);
  5285. }
  5286. else
  5287. {
  5288. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5289. {
  5290. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5291. }
  5292. }
  5293. string price1 = GetPostString("price1");
  5294. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5295. string price2 = GetPostString("price2");
  5296. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5297. string posTag = CurrentUser.UserPost.Post.Code;
  5298. if (posTag == "Supplier")
  5299. {
  5300. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5301. }
  5302. //lw.Add(string.Format("OrderState >= 6"));
  5303. lw.Add(string.Format("IsSample != 2 "));
  5304. lw.Add(string.Format("isDianziOrder = 0 "));
  5305. //lw.Add(string.Format("IsRefund<={0}", 1));
  5306. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5307. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5308. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5309. foreach (DataRow dr in dt.Rows)
  5310. {
  5311. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5312. }
  5313. writeGridDataTableJson(dStruct.TotalCount, dt);
  5314. }
  5315. public void get_erp_expresslist()
  5316. {
  5317. int listtype = GetInt("ltype");
  5318. DataStruct dStruct = GetPostStruct();
  5319. List<string> lw = new List<string>();
  5320. string tid = GetPostString("tid");
  5321. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5322. string outsid = GetPostString("out_sid");
  5323. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5324. string importer = GetPostString("ImportUserName");
  5325. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5326. string file = GetPostString("import_file");
  5327. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5328. string printman = GetPostString("printman");
  5329. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5330. string date1 = GetPostString("date1");
  5331. string date2 = GetPostString("date2");
  5332. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5333. if (dw.Length > 0) lw.Add(dw);
  5334. string fdate1 = GetPostString("finishdate1");
  5335. string fdate2 = GetPostString("finishdate2");
  5336. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5337. if (fdw.Length > 0) lw.Add(fdw);
  5338. string supplierId = GetPostString("supplierId");
  5339. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5340. if (listtype == 1)
  5341. {
  5342. lw.Add(string.Format("importUserId !=0"));
  5343. }
  5344. string posTag = CurrentUser.UserPost.Post.Code;
  5345. if (posTag == "Supplier")
  5346. {
  5347. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5348. }
  5349. if (dStruct.PageSize != 100000)
  5350. {
  5351. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5352. }
  5353. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5354. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5355. writeGridDataTableJson(dStruct.TotalCount, dt);
  5356. }
  5357. public void set_erp_buchaorderdelivery()
  5358. {
  5359. if (UrlPostParmsCheck("ctid"))
  5360. {
  5361. string eid = GetPostString("ctid");
  5362. CeErpTradeCell entity = null;
  5363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5364. if (entity != null)
  5365. {
  5366. if (entity.IsSample != 2)
  5367. {
  5368. returnErrorMsg("补差价单才能标记为已发货");
  5369. return;
  5370. }
  5371. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5372. entity.OrderState = 7;
  5373. entity.Update();
  5374. returnSuccessMsg("操作成功!");
  5375. return;
  5376. }
  5377. returnErrorMsg("找不到记录");
  5378. }
  5379. }
  5380. public void get_stdtemplates()
  5381. {
  5382. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5383. //string res = taobaoHelper.test();
  5384. string res = apiHelper.API_PrintTemplate();
  5385. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5386. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5387. {
  5388. int sidx = res.IndexOf("error_code");
  5389. int eidx = res.IndexOf("success");
  5390. string msg = res.Substring(sidx, eidx - sidx);
  5391. returnErrorMsg(msg);
  5392. return;
  5393. }
  5394. if (res.Length <= 0)
  5395. {
  5396. returnErrorMsg("模板数据为空!");
  5397. return;
  5398. }
  5399. ReturnSuccess(res);
  5400. }
  5401. public void cancel_print_order()
  5402. {
  5403. if (UrlPostParmsCheck("ctid"))
  5404. {
  5405. string ctid = GetPostString("ctid");
  5406. CeErpTradeCell entity = null;
  5407. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5408. if (entity != null)
  5409. {
  5410. string res = "";
  5411. string code = entity.LastBillWaybillCode;
  5412. if (code == "")
  5413. {
  5414. code = entity.OutSid;
  5415. }
  5416. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5417. XLog.SaveLog(0, "取消面单" + res);
  5418. }
  5419. }
  5420. }
  5421. public void set_erp_printwaybill()
  5422. {
  5423. if (UrlPostParmsCheck("ctid"))
  5424. {
  5425. string ctid = GetPostString("ctid");
  5426. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5427. string cpName = GetPostString("cpname");
  5428. string isTogether = GetPostString("together");
  5429. string printType = GetPostString("printType");
  5430. //var res_obj = new
  5431. //{
  5432. // restype = 1,
  5433. // data = "{\"response\":{\"data\":{\"content\":[{\"openOrderSubId\":\"\",\"parentWaybillCode\":\"\",\"platformType\":\"WB_PDD\",\"updateTime\":1686537867000,\"orderPlatform\":\"PDD\",\"openOrderId\":\"230611-632307127861975\",\"merchId\":1,\"props\":{\"ver\":\"8\",\"signature\":\"lYwcylRHKaeMOxfUvBg7ySYTGGur75biVxO5LTXxM3KeTpMaf6rIvIUFG0HtW4m7+JynVGS83sdGaIAYK3Rrr4QZZTKskIXWKGHKES7lmCP1yM7xD8Cm50aBAfelZo390L1PBb5WSn3EQB40vNIuV2itH2ajXqHtr93Mk2mDnno=\",\"dataVerification\":\"c609dcf70cf85832458adffe1aec3933\",\"encryptedData\":\"50830ac2124673c1abf81fc49c845bd5c55e9e4d1b2d03cd5f7b5445b79a95d763c60072c76649bec3effe329c02bc8c0a6ef3b43603bcfe31fd83dea03352a019cd2ab261c89b883168484f512c03f3fd586e2d487f2b612ed74ffd7d00ccc933739947ca46579f6187e4e23417a7b4f5b09faeb3045aa995fc177d9cc854ba6c1f0f345ad92320e1ed2bbdabc285b86f92b1e705e70bf2d3472b375a0bff031b385a1d2365865b0723d1fd0ecafd45ef01cb1cbf70613d83aa09d5a8c381d2099f5badee8c39e757159f86d6162e1f4bda68723eabb70526c2c0671df7463b281c43bca1b1a4f47b8b59ed666e76353eb4bb5e0be1223c150c8ebd6c623bb2b2448a8c818a76da9fbf1bcc5c3ec45545439f9d4d508fd72b2b127a478cf42b81300fae885c06a0459006bf6fe95db21fab2d7ba9a9a5d635df5eae7ec96248e067dd9ee3fb86b6c93f85a4eb91a290474495cd82b345aa977427946ae6f4034c14fc9b62252657fc03aae9d13d58380affce3c3138690391f1b895da3413d764258aeb26a94ffacec8ab511693462c2bc039a6674b18f7a1bf82abfaf9ebbfd40b2ed77fc7ea95db5ef34c24ee93fc5107cfa13de5ff674f259df1817276ab05f1716c276bd517719a164ab0c4490250f5bd10b6fe1e8b2212fc91a99bc1c42fd6273ef3a68f9c7fc900dc0b2792c2810d361aa054db691ac4c6b578b146f31b9413d43b3af8b8b54ff606b500891e0cbac7d4c4fed8398ccf63ce952e1babe6dbb5deb469ad5f791f2f8df175c6bcfb2c2659441b1e3f4752ef3e727b80587b8a354abe6230263bf4f6e4460154342737ead1f7520f18570ecc633575f7c9d5c23f1c1fe578b5a495398bd14b641d76df38a36f6c6db025258cf02e59e04fa931c00a077bf91aa74ec3d2c03a5b83ded3ff73942699006b36390bed0372683e49cc06a5e906350dcc9ea96f42be381be814c3b9035b8385cdc6f1195b124bfbe42d05406dc7b5d76e096d938e31b5255532271fbc1786459c9081cc068c2f62ffc1a901686b55cd1e712e4bdcfe2a83c324366f8ea734c15332365a9f738746252472e44995d75c2114fbf804bf0769bda4310df5ee95cc94ccd965661cb446af66e048db112bad54dccdc650fa723761baa9449ee6af9196ef936f209310117b4b74aaf955bc1d279d00fe74e3ef9aa96023b714a710cf7e820437106eb10f0d17a4ad7fd100241c56d387e4c4caefbd9d4b438ba0b5799bec54da643f91a65c8fcc0c7dde39e7eca708e237b92a99133c48c9e2a0aaa616acfc0d7336abec25314628ae778e84b35a4319ad6f2ef87f271fd60eba53811ea02a4d5e023216e1dee04fc8960a2bfcaba873ba204cdc675f66f8230818f84e9d7e893867088469ec90e54b96fa78cde6a51e2a2ab4611dfbf4aa8f8c802547a5f24fbc2912786cfb045ef821aa277797211012c28fd836921dba83e1829325bbdf17ad0302e16455b4defbe5a5fadbdc3677505f1d4901531e1db7b13981f31556d743ad3d48eaf2c000be18d5b036837f979240fa3afee74790e82f01dcbd434ff129ecbfed3a0dabaa2a615bac9487a1197323476556eb05469ad8bf75ba95e82a527b93115b360a5920cc23c1f5cf885022dd65e1bd430ffa3d1baf6592b3d6a226c53161a11be8133d3f254ac845e69ed02dd3758cc9adccf42985d8695f8942e08d08d0b27ee49b4bacd4954fe6804e202318f9143feaec7569c7a0759d0d0ee7b537f95b21f4c8ba9743c12da95802ab2600bdecd7bb3c676207e624a35711287afaeeec6ca2be07eebbc4bf1a56c3615ad6830f3e7dd28ed88a6f9ce8b80727316f959b5f09d9a7545ce2609309e71662910fa702b59f8fc07b55c24a254a1e3237dbd054569832111658f3e747aaa619124e2c2467e241d30c1e756a1338a89bad3ce6b8c7fccbd656b1cfbd1cec8bb46e05a5f5f8d87c1f43058389bc64f1f4cbb3fefe5b427892a4064ed83855cdab9f645810170bdee8d8d0e2c5f1cea3732d4699071803a62f3bb056cdd019ac74ce899cc653b76765c0bafee7cfc17521cc3162e01efe25497fe04af1f91fe7033b66f34b08a9451149e4be0ab5b6ce0e2b236626eec93b1e645515fd98b781dceef19b299c692def81095d3114e091c0fb4d6f37d83bb47c1282efd0361716aaebf8b837cc8a17b7ade3305cedcc7736062ac8b4619eb7ee48d6ee954ae977ef4f393ceefe50117874556c30f892f522f0bdb94fa3faceef691579397c1666d21c3264e58eded67f95f6f5b17bf8737ef73d4fd6f66168a148be89368d262807d0817fb67c9580b8d03ea8009951754722?v=8&pv=1\",\"templateUrl\":\"https://file-link.pinduoduo.com/yto_one\"},\"updateBy\":0,\"tenantId\":34,\"waybillCode\":\"YT8910742640842\",\"id\":989598,\"partnerId\":794928,\"mark\":[],\"status\":\"USED\"}]},\"success\":true},\"_req_id\":\"W4Yffp19yC\"}"
  5434. //};
  5435. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5436. //ReturnSuccess(ro_json);
  5437. //return;
  5438. bool isUseLastWayBillCode = false;
  5439. CeErpTradeCell entity = null;
  5440. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5441. if (entity != null)
  5442. {
  5443. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5444. {
  5445. isUseLastWayBillCode = true;
  5446. }
  5447. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5448. {
  5449. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5450. return;
  5451. }
  5452. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5453. {
  5454. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5455. return;
  5456. }
  5457. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5458. {
  5459. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5460. return;
  5461. }
  5462. }
  5463. string res = "";
  5464. Api_waybill_code_response_Obj fullObj = null;
  5465. string pData_str = "";
  5466. string curUseWayBillCode = "";
  5467. if (isUseLastWayBillCode == false)
  5468. {
  5469. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5470. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5471. if (res.IndexOf("failure") != -1)
  5472. {
  5473. //int idx = res.IndexOf("sub_message");
  5474. //int idx2 = res.IndexOf("flag");
  5475. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5476. string errMsgNeed = commonHelper.KeepChinese(res);
  5477. var res_objd = new
  5478. {
  5479. restype = 0,
  5480. data = "获取面单失败" + errMsgNeed
  5481. };
  5482. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5483. returnSuccess(ro_jsond);
  5484. if (res.IndexOf("停发") != -1)
  5485. {
  5486. entity.UnusualCon = "物流停发";
  5487. entity.Update();
  5488. }
  5489. //returnErrorMsg("获取面单失败,"+emsg);
  5490. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5491. return;
  5492. }
  5493. else if (res.IndexOf("errorMsg") != -1)
  5494. {
  5495. //int idx = res.IndexOf("errorMsg");
  5496. //int idx2 = res.IndexOf("}]}");
  5497. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5498. string errMsgNeed = commonHelper.KeepChinese(res);
  5499. var res_objf = new
  5500. {
  5501. restype = 0,
  5502. data = "获取面单失败2" + errMsgNeed
  5503. };
  5504. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5505. if (res.IndexOf("停发") != -1)
  5506. {
  5507. entity.UnusualCon = "物流停发";
  5508. entity.Update();
  5509. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5510. if (trade != null)
  5511. {
  5512. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5513. }
  5514. }
  5515. returnSuccess(ro_jsonf);
  5516. //returnErrorMsg("获取面单失败," + emsg);
  5517. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5518. return;
  5519. }
  5520. try
  5521. {
  5522. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5523. //res = res.Replace(" ", "");
  5524. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5525. }
  5526. catch (Exception ex)
  5527. {
  5528. XLog.SaveLog(0, "生成fullObj" + res);
  5529. var res_objf = new
  5530. {
  5531. restype = 0,
  5532. data = "生成fullObj发生错误" + ex.Message
  5533. };
  5534. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5535. returnSuccess(ro_jsonf);
  5536. return;
  5537. }
  5538. if (fullObj.response.data.content.Count > 0)
  5539. {
  5540. ContentItem codeObj = fullObj.response.data.content[0];
  5541. if (cpCode.IndexOf("SFFQ-") != -1)
  5542. {
  5543. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5544. }
  5545. else
  5546. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5547. curUseWayBillCode = codeObj.waybillCode;
  5548. }
  5549. else
  5550. {
  5551. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5552. var res_objf = new
  5553. {
  5554. restype = 0,
  5555. data = "生成fullObj找不到快递单号waybillCode"
  5556. };
  5557. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5558. returnSuccess(ro_jsonf);
  5559. return;
  5560. }
  5561. }
  5562. else
  5563. {
  5564. //使用上次打印的快递单号
  5565. if (cpCode == "SFFQ-LY")
  5566. {
  5567. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5568. }
  5569. else
  5570. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5571. curUseWayBillCode = entity.LastBillWaybillCode;
  5572. }
  5573. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5574. {
  5575. var res_obje = new
  5576. {
  5577. restype = 0,
  5578. data = "获取加密打印数据失败"
  5579. };
  5580. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5581. returnSuccess(ro_jsone);
  5582. entity.LastBillCpCode = cpCode;
  5583. entity.LastBillWaybillCode = curUseWayBillCode;
  5584. entity.Update();
  5585. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5586. //returnErrorMsg("获取加密打印数据失败");
  5587. return;
  5588. }
  5589. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5590. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5591. string btnType = "";
  5592. string errorMsg = "";
  5593. if (entity != null)
  5594. {
  5595. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5596. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5597. //cpcode是 YTO-CAINIAO
  5598. //string comCode = cpCode.Split('-')[0].ToString();
  5599. string apires = "";
  5600. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5601. //isTogether=2是新的合包弹窗
  5602. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5603. {
  5604. if (ctid.IndexOf("N") != -1)
  5605. {
  5606. apires = "发货成功";
  5607. }
  5608. else
  5609. {
  5610. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5611. }
  5612. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5613. //打单后发货
  5614. StringBuilder sql = new StringBuilder();
  5615. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5616. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5617. {
  5618. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5619. }
  5620. else
  5621. {
  5622. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5623. }
  5624. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5625. foreach (DataRow row in dt.Rows)
  5626. {
  5627. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5628. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5629. {
  5630. try
  5631. {
  5632. btnType = "待发货";
  5633. entity.OutSid = curUseWayBillCode;
  5634. entity.OrderState = 7;
  5635. entity.IsUrgency = false;
  5636. entity.LastBillCpCode = "";
  5637. entity.LastBillWaybillCode = "";
  5638. entity.FinishDeliveryTime = DateTime.Now;
  5639. entity.IsReturn = 0;
  5640. entity.MemoOpt = 0;
  5641. entity.UpdateTime = DateTime.Now;
  5642. entity.Update();
  5643. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5644. //还要插入快递信息到 快递信息表
  5645. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5646. exinfo.tid = entity.ctid;
  5647. exinfo.out_sid = curUseWayBillCode;
  5648. exinfo.company_code = cpCode;
  5649. exinfo.company_name = cpName;
  5650. exinfo.supplierUserName = supplierName;
  5651. exinfo.deliveryType = "发货成功";
  5652. exinfo.print_time = DateTime.Now;
  5653. exinfo.printUser = CurrentUser.UserName;
  5654. exinfo.postData = pData_str;
  5655. exinfo.Create();
  5656. commonHelper.UpdateRelationOrder(entity.ctid);
  5657. CeErpSukuraData.createInfo(ctid, 4);
  5658. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5659. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5660. {
  5661. commonHelper.sendCytExpress(exinfo);
  5662. }
  5663. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5664. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5665. }
  5666. catch (Exception ex)
  5667. {
  5668. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5669. }
  5670. }
  5671. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5672. {
  5673. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5674. if (entity.OrderState == 6)
  5675. {
  5676. entity.OrderState = 7;
  5677. }
  5678. entity.UpdateTime = DateTime.Now;
  5679. entity.FinishDeliveryTime = DateTime.Now;
  5680. btnType = "已发货";
  5681. entity.Update();
  5682. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5683. exinfo.tid = entity.ctid;
  5684. exinfo.out_sid = curUseWayBillCode;
  5685. exinfo.company_code = cpCode;
  5686. exinfo.company_name = cpName;
  5687. exinfo.supplierUserName = supplierName;
  5688. exinfo.deliveryType = "发货成功";
  5689. exinfo.print_time = DateTime.Now;
  5690. exinfo.printUser = CurrentUser.UserName;
  5691. exinfo.postData = pData_str;
  5692. exinfo.Create();
  5693. commonHelper.UpdateRelationOrder(entity.ctid);
  5694. CeErpSukuraData.createInfo(entity.ctid, 4);
  5695. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5696. {
  5697. commonHelper.sendCytExpress(exinfo);
  5698. }
  5699. //不处理
  5700. }
  5701. else
  5702. {
  5703. entity.UpdateTime = DateTime.Now;
  5704. entity.LastBillCpCode = cpCode;
  5705. entity.LastBillWaybillCode = curUseWayBillCode;
  5706. entity.Update();
  5707. string errmsg = commonHelper.KeepChinese(apires);
  5708. var res_objz = new
  5709. {
  5710. restype = 0,
  5711. data = "打单后发货失败"
  5712. };
  5713. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5714. returnSuccess(ro_jsonz);
  5715. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5716. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5717. return;
  5718. }
  5719. }
  5720. }
  5721. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5722. {
  5723. string ctids = GetPostString("ctids");
  5724. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5725. List<string> list = new List<string>();
  5726. List<string> send_list = new List<string>();
  5727. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5728. CeErpTrade ceErpTrade = new CeErpTrade();
  5729. //可合包的合并一起发货
  5730. if (dt == null && string.IsNullOrEmpty(ctids))
  5731. {
  5732. var res_objz = new
  5733. {
  5734. restype = 0,
  5735. data = "打单后发货失败"
  5736. };
  5737. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5738. returnSuccess(ro_jsonz);
  5739. return;
  5740. }
  5741. if (!string.IsNullOrEmpty(ctids))
  5742. {
  5743. StringBuilder sql = new StringBuilder();
  5744. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5745. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5746. }
  5747. foreach (DataRow row in dt.Rows)
  5748. {
  5749. list.Add("'" + row["ctid"] + "'");
  5750. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5751. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5752. if (ctid.IndexOf("N") != -1)
  5753. {
  5754. apires = "发货成功";
  5755. }
  5756. else
  5757. {
  5758. if (!send_list.Contains(ceErpTrade.tid))
  5759. {
  5760. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5761. }
  5762. else
  5763. {
  5764. apires = "发货成功";
  5765. }
  5766. }
  5767. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5768. {
  5769. send_list.Add(ceErpTrade.tid);
  5770. try
  5771. {
  5772. btnType = "待发货";
  5773. ceErpTradeCell.OutSid = curUseWayBillCode;
  5774. ceErpTradeCell.OrderState = 7;
  5775. ceErpTradeCell.IsUrgency = false;
  5776. ceErpTradeCell.LastBillCpCode = "";
  5777. ceErpTradeCell.LastBillWaybillCode = "";
  5778. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5779. ceErpTradeCell.IsReturn = 0;
  5780. ceErpTradeCell.MemoOpt = 0;
  5781. ceErpTradeCell.UpdateTime = DateTime.Now;
  5782. ceErpTradeCell.Update();
  5783. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5784. //还要插入快递信息到 快递信息表
  5785. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5786. exinfo.tid = ceErpTradeCell.ctid;
  5787. exinfo.out_sid = curUseWayBillCode;
  5788. exinfo.company_code = cpCode;
  5789. exinfo.company_name = cpName;
  5790. exinfo.supplierUserName = supplierName;
  5791. exinfo.deliveryType = "发货成功";
  5792. exinfo.print_time = DateTime.Now;
  5793. exinfo.printUser = CurrentUser.UserName;
  5794. exinfo.postData = pData_str;
  5795. exinfo.Create();
  5796. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5797. CeErpSukuraData.createInfo(ctid, 4);
  5798. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5799. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80)
  5800. {
  5801. commonHelper.sendCytExpress(exinfo);
  5802. }
  5803. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5804. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5805. }
  5806. catch (Exception ex)
  5807. {
  5808. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5809. }
  5810. }
  5811. else
  5812. {
  5813. ceErpTradeCell.UpdateTime = DateTime.Now;
  5814. ceErpTradeCell.LastBillCpCode = cpCode;
  5815. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5816. ceErpTradeCell.Update();
  5817. string errmsg = commonHelper.KeepChinese(apires);
  5818. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5819. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5820. }
  5821. }
  5822. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5823. }
  5824. }
  5825. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5826. var res_obj = new
  5827. {
  5828. restype = 1,
  5829. data = pData_str,
  5830. errorMsg
  5831. };
  5832. string ro_json = JsonConvert.SerializeObject(res_obj);
  5833. ReturnSuccess(ro_json);
  5834. return;
  5835. }
  5836. }
  5837. private string GetUTF8String(byte[] vs)
  5838. {
  5839. throw new NotImplementedException();
  5840. }
  5841. public void set_erp_printwaybill_cn()
  5842. {
  5843. if (UrlPostParmsCheck("ctid"))
  5844. {
  5845. string ctid = GetPostString("ctid");
  5846. string cpCode = GetPostString("cpcode");
  5847. string cpName = GetPostString("cpname");
  5848. string tempUrl = GetPostString("tempurl");
  5849. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5850. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5851. //string res = taobaoHelper.test();
  5852. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5853. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5854. {
  5855. int sidx = res.IndexOf("errorMsg");
  5856. int eidx = res.IndexOf("}");
  5857. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5858. var res_objzxx = new
  5859. {
  5860. restype = 0,
  5861. data = msg
  5862. };
  5863. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5864. returnSuccess(ro_jsonzxx);
  5865. //returnErrorMsg(msg);
  5866. return;
  5867. }
  5868. int idx = res.IndexOf("waybillCode");
  5869. int idx2 = res.IndexOf("printData");
  5870. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5871. string eid = GetPostString("ctid");
  5872. CeErpTradeCell entity = null;
  5873. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5874. if (entity != null)
  5875. {
  5876. string osid = entity.OutSid;
  5877. entity.OutSid = osid + "," + outsid;
  5878. entity.FinishDeliveryTime = DateTime.Now;
  5879. entity.OrderState = 7;
  5880. entity.UpdateTime = DateTime.Now;
  5881. entity.IsReturn = 0;
  5882. entity.Update();
  5883. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5884. exinfo.tid = entity.ctid;
  5885. exinfo.out_sid = outsid;
  5886. exinfo.company_code = cpCode;
  5887. exinfo.company_name = cpName;
  5888. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5889. exinfo.deliveryType = "发货成功";
  5890. exinfo.print_time = DateTime.Now;
  5891. exinfo.printUser = CurrentUser.UserName;
  5892. exinfo.Create();
  5893. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5894. {
  5895. commonHelper.sendCytExpress(exinfo);
  5896. }
  5897. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5898. }
  5899. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5900. var res_objz = new
  5901. {
  5902. restype = 1,
  5903. data = res
  5904. };
  5905. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5906. returnSuccess(ro_jsonz);
  5907. //ReturnSuccess(res);
  5908. }
  5909. }
  5910. ////打单,打印面单 获取面单号
  5911. //public void set_erp_printwaybill()
  5912. //{
  5913. // if (UrlPostParmsCheck("ctid"))
  5914. // {
  5915. // string ctid = GetPostString("ctid");
  5916. // string cpCode = GetPostString("cpcode");
  5917. // string tempUrl = GetPostString("tempurl");
  5918. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5919. // //string res = taobaoHelper.test();
  5920. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5921. // if (res.IndexOf("error_response") != -1)
  5922. // {
  5923. // int sidx = res.IndexOf("sub_msg");
  5924. // int eidx = res.IndexOf("request_id");
  5925. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5926. // returnErrorMsg(msg);
  5927. // return;
  5928. // }
  5929. // int idx = res.IndexOf("waybill_code");
  5930. // int idx2 = res.IndexOf("}]}");
  5931. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5932. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5933. // ReturnSuccess(res);
  5934. // }
  5935. //}
  5936. public void cancel_erp_aftersale()
  5937. {
  5938. if (UrlPostParmsCheck("ctid"))
  5939. {
  5940. string eid = GetPostString("ctid");
  5941. CeErpTradeCell entity = null;
  5942. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5943. if (entity != null)
  5944. {
  5945. //有过处理的售后,取消也不能删除 售 字,保留
  5946. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5947. {
  5948. entity.AfterSaleState = 4;
  5949. }
  5950. else
  5951. entity.AfterSaleState = 0;
  5952. entity.UpdateTime = DateTime.Now;
  5953. entity.Update();
  5954. returnSuccessMsg("操作成功!");
  5955. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5956. return;
  5957. }
  5958. returnErrorMsg("找不到订单记录");
  5959. }
  5960. }
  5961. public void get_erp_aftersalelist()
  5962. {
  5963. DataStruct dStruct = GetPostStruct();
  5964. List<string> lw = new List<string>();
  5965. int st = GetInt("st");
  5966. string tid = GetPostString("ctid");
  5967. if (st == 3)
  5968. {
  5969. if (tid.Length > 0)
  5970. {
  5971. string select_tid = getTidByCtid(tid);
  5972. lw.Add(string.Format("tid='{0}'", select_tid));
  5973. }
  5974. }
  5975. else
  5976. {
  5977. if (tid.Length > 0)
  5978. {
  5979. string select_tid = getTidByCtid(tid);
  5980. lw.Add(string.Format("tid='{0}'", select_tid));
  5981. }
  5982. }
  5983. string shopname = GetPostString("shopname");
  5984. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5985. string buyernick = GetPostString("buyer_nick");
  5986. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5987. string sellermemo = GetPostString("seller_memo");
  5988. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5989. string orderState = GetPostString("orderState");
  5990. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5991. string afterState = GetPostString("afterstate");
  5992. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5993. string date1 = GetPostString("date1");
  5994. string date2 = GetPostString("date2");
  5995. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5996. if (dw.Length > 0) lw.Add(dw);
  5997. string price1 = GetPostString("price1");
  5998. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5999. string price2 = GetPostString("price2");
  6000. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6001. //lw.Add(string.Format("IsRefund!={0}", 1));
  6002. string reason = GetPostString("reason");
  6003. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6004. string method = GetPostString("method");
  6005. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6006. string handler = GetPostString("handler");
  6007. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6008. string handledate1 = GetPostString("handledate1");
  6009. string handledate2 = GetPostString("handledate2");
  6010. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6011. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6012. string finish1 = GetPostString("finishdate1");
  6013. string finish2 = GetPostString("finishdate2");
  6014. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6015. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6016. string afterdate1 = GetPostString("afterdate1");
  6017. string afterdate2 = GetPostString("afterdate2");
  6018. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6019. if (afterDate.Length > 0) lw.Add(afterDate);
  6020. string supplier = GetPostString("supplier");
  6021. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6022. string responsible = GetPostString("responsibleman");
  6023. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6024. string customer = GetPostString("customer");
  6025. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6026. string design = GetPostString("design");
  6027. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6028. string afterMemoType = GetPostString("aftermemotype");
  6029. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6030. string posCode = CurrentUser.UserPost.Post.Code;
  6031. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6032. //{
  6033. // string vstate = GetPostString("vstate");
  6034. // if (vstate.Length > 0)
  6035. // {
  6036. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6037. // }
  6038. // if (posCode == "Supplier")
  6039. // {
  6040. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6041. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6042. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6043. // }
  6044. // else
  6045. // {
  6046. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6047. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6048. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6049. // {
  6050. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6051. // }
  6052. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6053. // {
  6054. // int orgid = CurrentUser.UserPost.OrgID;
  6055. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6056. // }
  6057. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6058. // {
  6059. // string shopid = CurrentUser.User.pemShop;
  6060. // lw.Add(string.Format("shopId in ({0})", shopid));
  6061. // }
  6062. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6063. // //{
  6064. // // int org_id = CurrentUser.UserPost.OrgID;
  6065. // // lw.Add(string.Format("OrgID={0}", org_id));
  6066. // //}
  6067. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6068. // }
  6069. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6070. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6071. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6072. //}
  6073. if (st == 5)
  6074. {
  6075. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6076. {
  6077. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6078. {
  6079. string shopid = CurrentUser.User.pemShop;
  6080. lw.Add(string.Format("shopId in ({0})", shopid));
  6081. }
  6082. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6083. {
  6084. int mrOrgid = CurrentUser.UserPost.OrgID;
  6085. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6086. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6087. }
  6088. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6089. //{
  6090. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6091. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6092. //}
  6093. else
  6094. {
  6095. string userIdStr = "";
  6096. if (posCode == "CustomerService")
  6097. {
  6098. userIdStr = CurrentUser.UserID + "_k";
  6099. }
  6100. else if (posCode == "Designer" || posCode == "wxDesigner")
  6101. {
  6102. userIdStr = CurrentUser.UserID + "_s";
  6103. }
  6104. else if (posCode == "Place")
  6105. {
  6106. userIdStr = CurrentUser.UserID + "_x";
  6107. }
  6108. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6109. }
  6110. }
  6111. string placedate1 = GetPostString("placedate1");
  6112. string placedate2 = GetPostString("placedate2");
  6113. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6114. if (dwplace.Length > 0) lw.Add(dwplace);
  6115. string supState = GetPostString("supState");
  6116. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6117. string searchType = GetPostString("searchType");
  6118. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6119. {
  6120. lw.Add(string.Format("BackNum>1"));
  6121. }
  6122. lw.Add(string.Format("AfterSaleState>0"));
  6123. if (ex_psize > 0)
  6124. {
  6125. if (CurrentUser.UserPost.Post.Code == "Finance")
  6126. dStruct.Order = "pay_time desc";
  6127. else
  6128. dStruct.Order = "HandleTime desc";
  6129. }
  6130. else
  6131. dStruct.Order = "HandleTime desc";
  6132. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6133. DataTable dt = WebCache.GetData("view_test", dStruct);
  6134. writeGridDataTableJson(dStruct.TotalCount, dt);
  6135. }
  6136. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6137. //{
  6138. // lw.Add(string.Format("AfterSaleState=4"));
  6139. // string code = CurrentUser.UserPost.Post.Code;
  6140. // if (code == "CustomerService")
  6141. // {
  6142. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6143. // }
  6144. // else if (code == "Designer" || code == "DesignerMr")
  6145. // {
  6146. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6147. // }
  6148. // else if (code == "Place" || code == "PlaceMr")
  6149. // {
  6150. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6151. // }
  6152. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6153. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6154. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6155. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6156. //}
  6157. //else //处理中的售后,待处理和处理中合并
  6158. //{
  6159. // if (afterState.Length <= 0)
  6160. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6161. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6162. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6163. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6164. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6165. //}
  6166. }
  6167. public void get_erp_disagreeftersalelist()
  6168. {
  6169. DataStruct dStruct = GetPostStruct();
  6170. List<string> lw = new List<string>();
  6171. int st = 2;
  6172. string tid = GetPostString("ctid");
  6173. if (tid.Length > 0)
  6174. {
  6175. string select_tid = getTidByCtid(tid);
  6176. lw.Add(string.Format("tid='{0}'", select_tid));
  6177. }
  6178. string shopname = GetPostString("shopname");
  6179. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6180. string buyernick = GetPostString("buyer_nick");
  6181. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6182. string sellermemo = GetPostString("seller_memo");
  6183. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6184. string orderState = GetPostString("orderState");
  6185. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6186. string afterState = GetPostString("afterstate");
  6187. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6188. string date1 = GetPostString("date1");
  6189. string date2 = GetPostString("date2");
  6190. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6191. if (dw.Length > 0) lw.Add(dw);
  6192. string price1 = GetPostString("price1");
  6193. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6194. string price2 = GetPostString("price2");
  6195. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6196. //lw.Add(string.Format("IsRefund!={0}", 1));
  6197. string reason = GetPostString("reason");
  6198. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6199. string method = GetPostString("method");
  6200. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6201. string handler = GetPostString("handler");
  6202. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6203. string handledate1 = GetPostString("handledate1");
  6204. string handledate2 = GetPostString("handledate2");
  6205. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6206. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6207. string afterdate1 = GetPostString("afterdate1");
  6208. string afterdate2 = GetPostString("afterdate2");
  6209. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6210. if (afterDate.Length > 0) lw.Add(afterDate);
  6211. string backdate1 = GetPostString("backdate1");
  6212. string backdate2 = GetPostString("backdate2");
  6213. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6214. if (backDate.Length > 0) lw.Add(backDate);
  6215. string supplier = GetPostString("supplier");
  6216. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6217. string responsible = GetPostString("responsibleman");
  6218. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6219. string customer = GetPostString("customer");
  6220. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6221. string design = GetPostString("design");
  6222. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6223. string afterSaleMemo = GetPostString("afterSaleMemo");
  6224. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6225. string afterMemoType = GetPostString("aftermemotype");
  6226. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6227. string aftersakereason = GetPostString("aftersakereason");
  6228. if (aftersakereason.Length > 0)
  6229. {
  6230. if (aftersakereason == "1")
  6231. {
  6232. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6233. }
  6234. if (aftersakereason == "2")
  6235. {
  6236. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6237. }
  6238. }
  6239. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6240. string poscode = CurrentUser.UserPost.Post.Code;
  6241. if (poscode != "SysAdmin")
  6242. {
  6243. string shopid = CurrentUser.User.pemShop;
  6244. lw.Add(string.Format("shopId in ({0})", shopid));
  6245. }
  6246. string searchType = GetPostString("searchType");
  6247. if (searchType == "wait")
  6248. {
  6249. lw.Add(string.Format("HandleTime is null"));
  6250. }
  6251. if (searchType == "handling")
  6252. {
  6253. lw.Add(string.Format("HandleTime is not null "));
  6254. }
  6255. if (searchType == "back" || searchType == "puBack")
  6256. {
  6257. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6258. }
  6259. if (searchType == "reBack")
  6260. {
  6261. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6262. }
  6263. if (searchType == "moreBack")
  6264. {
  6265. lw.Add(string.Format("backNum > 1"));
  6266. }
  6267. lw.Add(string.Format("(AfterSaleState=5)"));
  6268. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6269. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6270. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6271. writeGridDataTableJson(dStruct.TotalCount, dt);
  6272. }
  6273. public void get_erp_handlingaftersalelist()
  6274. {
  6275. DataStruct dStruct = GetPostStruct();
  6276. List<string> lw = new List<string>();
  6277. int st = 2;
  6278. string tid = GetPostString("ctid");
  6279. if (tid.Length > 0)
  6280. {
  6281. string select_tid = getTidByCtid(tid);
  6282. lw.Add(string.Format("tid='{0}'", select_tid));
  6283. }
  6284. string shopname = GetPostString("shopname");
  6285. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6286. string buyernick = GetPostString("buyer_nick");
  6287. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6288. string sellermemo = GetPostString("seller_memo");
  6289. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6290. string orderState = GetPostString("orderState");
  6291. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6292. string afterState = GetPostString("afterstate");
  6293. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6294. string date1 = GetPostString("date1");
  6295. string date2 = GetPostString("date2");
  6296. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6297. if (dw.Length > 0) lw.Add(dw);
  6298. string price1 = GetPostString("price1");
  6299. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6300. string price2 = GetPostString("price2");
  6301. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6302. //lw.Add(string.Format("IsRefund!={0}", 1));
  6303. string reason = GetPostString("reason");
  6304. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6305. string method = GetPostString("method");
  6306. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6307. string handler = GetPostString("handler");
  6308. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6309. string handledate1 = GetPostString("handledate1");
  6310. string handledate2 = GetPostString("handledate2");
  6311. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6312. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6313. string afterdate1 = GetPostString("afterdate1");
  6314. string afterdate2 = GetPostString("afterdate2");
  6315. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6316. if (afterDate.Length > 0) lw.Add(afterDate);
  6317. string supplier = GetPostString("supplier");
  6318. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6319. string responsible = GetPostString("responsibleman");
  6320. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6321. string customer = GetPostString("customer");
  6322. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6323. string design = GetPostString("design");
  6324. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6325. string afterSaleMemo = GetPostString("afterSaleMemo");
  6326. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6327. string afterMemoType = GetPostString("aftermemotype");
  6328. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6329. string afterresult = GetPostString("afterresult");
  6330. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6331. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6332. string poscode = CurrentUser.UserPost.Post.Code;
  6333. if (poscode != "SysAdmin")
  6334. {
  6335. string shopid = CurrentUser.User.pemShop;
  6336. lw.Add(string.Format("shopId in ({0})", shopid));
  6337. }
  6338. string searchType = GetPostString("searchType");
  6339. if (searchType == "wait")
  6340. {
  6341. lw.Add(string.Format("HandleTime is null"));
  6342. }
  6343. if (searchType == "documentary")
  6344. {
  6345. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6346. }
  6347. if (searchType == "handling")
  6348. {
  6349. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6350. }
  6351. if (searchType == "back" || searchType == "puBack")
  6352. {
  6353. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6354. }
  6355. if (searchType == "reBack")
  6356. {
  6357. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6358. }
  6359. if (afterState.Length <= 0)
  6360. {
  6361. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6362. }
  6363. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6364. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6365. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6366. writeGridDataTableJson(dStruct.TotalCount, dt);
  6367. }
  6368. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6369. //public void get_erp_back_handlingaftersalelist()
  6370. //{
  6371. // DataStruct dStruct = GetPostStruct();
  6372. // List<string> lw = new List<string>();
  6373. // string tid = GetPostString("ctid");
  6374. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6375. // string shopname = GetPostString("shopname");
  6376. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6377. // string buyernick = GetPostString("buyer_nick");
  6378. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6379. // string sellermemo = GetPostString("seller_memo");
  6380. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6381. // string orderState = GetPostString("orderState");
  6382. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6383. // string afterState = GetPostString("afterstate");
  6384. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6385. // string date1 = GetPostString("date1");
  6386. // string date2 = GetPostString("date2");
  6387. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6388. // if (dw.Length > 0) lw.Add(dw);
  6389. // string price1 = GetPostString("price1");
  6390. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6391. // string price2 = GetPostString("price2");
  6392. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6393. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6394. // string reason = GetPostString("reason");
  6395. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6396. // string method = GetPostString("method");
  6397. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6398. // string handler = GetPostString("handler");
  6399. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6400. // string handledate1 = GetPostString("handledate1");
  6401. // string handledate2 = GetPostString("handledate2");
  6402. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6403. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6404. // string afterdate1 = GetPostString("afterdate1");
  6405. // string afterdate2 = GetPostString("afterdate2");
  6406. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6407. // if (afterDate.Length > 0) lw.Add(afterDate);
  6408. // string supplier = GetPostString("supplier");
  6409. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6410. // string responsible = GetPostString("responsibleman");
  6411. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6412. // string customer = GetPostString("customer");
  6413. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6414. // string design = GetPostString("design");
  6415. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6416. // string afterMemoType = GetPostString("aftermemotype");
  6417. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6418. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6419. // if (afterState.Length <= 0)
  6420. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6421. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6422. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6423. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6424. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6425. //}
  6426. public void get_erp_aftersaleverifylist()
  6427. {
  6428. DataStruct dStruct = GetPostStruct();
  6429. List<string> lw = new List<string>();
  6430. string tid = GetPostString("ctid");
  6431. if (tid.Length > 0)
  6432. {
  6433. string select_tid = getTidByCtid(tid);
  6434. lw.Add(string.Format("otid='{0}'", select_tid));
  6435. }
  6436. string shopname = GetPostString("shopname");
  6437. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6438. string buyernick = GetPostString("buyer_nick");
  6439. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6440. string sellermemo = GetPostString("seller_memo");
  6441. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6442. string orderState = GetPostString("orderState");
  6443. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6444. //lw.Add(string.Format("IsRefund!={0}", 1));
  6445. string reason = GetPostString("reason");
  6446. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6447. string method = GetPostString("method");
  6448. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6449. string handler = GetPostString("handler");
  6450. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6451. string handledate1 = GetPostString("handledate1");
  6452. string handledate2 = GetPostString("handledate2");
  6453. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6454. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6455. string finish1 = GetPostString("finishdate1");
  6456. string finish2 = GetPostString("finishdate2");
  6457. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6458. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6459. string supplier = GetPostString("supplier");
  6460. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6461. string responsible = GetPostString("responsibleman");
  6462. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6463. string posCode = CurrentUser.UserPost.Post.Code;
  6464. string vstate = GetPostString("vstate");
  6465. if (vstate.Length > 0)
  6466. {
  6467. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6468. }
  6469. if (posCode == "Supplier")
  6470. {
  6471. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6472. lw.Add(string.Format("VerifyState = 0"));
  6473. lw.Add("type = 1");
  6474. lw.Add(string.Format("AfterSaleState={0}", 3));
  6475. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6476. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6477. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6478. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6479. writeGridDataTableJson(dStruct.TotalCount, dt);
  6480. }
  6481. else if (posCode == "logistics")
  6482. {
  6483. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6484. lw.Add(string.Format("VerifyState = 0"));
  6485. lw.Add("type = 2");
  6486. lw.Add(string.Format("AfterSaleState={0}", 3));
  6487. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6488. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6489. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6490. writeGridDataTableJson(dStruct.TotalCount, dt);
  6491. }
  6492. else
  6493. {
  6494. lw.Add(string.Format("(AfterSaleState = 3)"));
  6495. string reasonState = GetPostString("reasonState");
  6496. lw.Add("type = 0");
  6497. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6498. || posCode == "Summarize" || posCode == "Finance")
  6499. {
  6500. if (reasonState == "2")
  6501. {
  6502. lw.Add("VerifyState = 3");
  6503. }
  6504. else if (reasonState == "1")
  6505. {
  6506. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6507. }
  6508. else
  6509. {
  6510. lw.Add("VerifyState in (0,3)");
  6511. }
  6512. //不加条件,可以看全部
  6513. }
  6514. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMaster" || CurrentUser.UserPost.Post.Code == "CustomerMr" || CurrentUser.UserPost.Post.Code == "DesignerMr" || CurrentUser.UserPost.Post.Code == "wxDesignerMr" || CurrentUser.UserPost.Post.Code == "Designerhd" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  6515. {
  6516. int orgid = CurrentUser.UserPost.OrgID;
  6517. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6518. if (string.IsNullOrEmpty(manageOrgId))
  6519. {
  6520. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6521. }
  6522. else
  6523. {
  6524. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6525. }
  6526. if (reasonState == "1")
  6527. {
  6528. lw.Add("VerifyState = 3");
  6529. }
  6530. else if (reasonState == "2")
  6531. {
  6532. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6533. }
  6534. else
  6535. {
  6536. }
  6537. }
  6538. else
  6539. {
  6540. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6541. }
  6542. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6543. //{
  6544. // int org_id = CurrentUser.UserPost.OrgID;
  6545. // lw.Add(string.Format("OrgID={0}", org_id));
  6546. //}
  6547. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6548. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6549. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6550. writeGridDataTableJson(dStruct.TotalCount, dt);
  6551. }
  6552. }
  6553. public void get_erp_finishaftersalelist()
  6554. {
  6555. DataStruct dStruct = GetPostStruct();
  6556. List<string> lw = new List<string>();
  6557. int st = 4;
  6558. string tid = GetPostString("ctid");
  6559. if (tid.Length > 0)
  6560. {
  6561. string select_tid = getTidByCtid(tid);
  6562. lw.Add(string.Format("otid='{0}'", select_tid));
  6563. }
  6564. string shopname = GetPostString("shopname");
  6565. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6566. //lw.Add(string.Format("IsRefund!={0}", 1));
  6567. string reason = GetPostString("reason");
  6568. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6569. string method = GetPostString("method");
  6570. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6571. string buyernick = GetPostString("buyer_nick");
  6572. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6573. string handler = GetPostString("handler");
  6574. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6575. string handledate1 = GetPostString("handledate1");
  6576. string handledate2 = GetPostString("handledate2");
  6577. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6578. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6579. string finish1 = GetPostString("finishdate1");
  6580. string finish2 = GetPostString("finishdate2");
  6581. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6582. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6583. string supplier = GetPostString("supplier");
  6584. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6585. string responsible = GetPostString("responsibleman");
  6586. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6587. string vstate = GetPostString("vstate");
  6588. if (vstate.Length > 0)
  6589. {
  6590. if ("3".Equals(vstate))
  6591. {
  6592. lw.Add(string.Format("IsTem=1"));
  6593. }
  6594. else
  6595. {
  6596. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6597. }
  6598. }
  6599. lw.Add(string.Format("AfterSaleState=4"));
  6600. string code = CurrentUser.UserPost.Post.Code;
  6601. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6602. {
  6603. //不加条件,可以看全部
  6604. }
  6605. else if (code == "Supplier")
  6606. {
  6607. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6608. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6609. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6610. }
  6611. else if (code == "logistics")
  6612. {
  6613. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6614. lw.Add("type = 2");
  6615. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6616. }
  6617. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMaster" || CurrentUser.UserPost.Post.Code == "CustomerMr" || CurrentUser.UserPost.Post.Code == "DesignerMr" || CurrentUser.UserPost.Post.Code == "wxDesignerMr" || CurrentUser.UserPost.Post.Code == "Designerhd" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  6618. {
  6619. int orgid = CurrentUser.UserPost.OrgID;
  6620. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6621. if (string.IsNullOrEmpty(manageOrgIds))
  6622. {
  6623. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6624. }
  6625. else
  6626. {
  6627. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6628. }
  6629. }
  6630. else
  6631. {
  6632. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6633. }
  6634. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6635. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6636. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6637. writeGridDataTableJson(dStruct.TotalCount, dt);
  6638. }
  6639. public void handle_erp_aftersale()
  6640. {
  6641. if (UrlPostParmsCheck("ctid"))
  6642. {
  6643. string eid = GetPostString("ctid");
  6644. string responStr = GetPostString("AfterSaleResponsible");
  6645. if (responStr.Length <= 0)
  6646. {
  6647. returnErrorMsg("售后责任人不能为空");
  6648. return;
  6649. }
  6650. bool isDesign = false;
  6651. double designFree = 0.00;
  6652. int responsibleId = 0;
  6653. CeErpTradeCell entity = null;
  6654. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6655. if (entity != null)
  6656. {
  6657. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6658. string afterMethod = GetPostString("AfterSaleMethod");
  6659. if (isNeedNewOrder == 1)
  6660. {
  6661. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6662. bool ishav = true;
  6663. if (newentity == null)
  6664. {
  6665. newentity = entity.Clone() as CeErpTradeCell;
  6666. ishav = false;
  6667. newentity.ctid = "S_" + entity.ctid;
  6668. newentity.OrderState = 0;
  6669. //唯一标识
  6670. newentity.OrderSn = newentity.ctid;
  6671. string orderSn = dataHelper.getSaleOrderSn();
  6672. if (orderSn != "")
  6673. {
  6674. newentity.OrderSn = orderSn;
  6675. }
  6676. }
  6677. newentity.UpdateTime = DateTime.Now;
  6678. newentity.AfterSaleState = 0;
  6679. newentity.AfterSaleMethod = afterMethod;
  6680. if (!ishav)
  6681. {
  6682. string memo_str = newentity.seller_memo;
  6683. memo_str = memo_str.Replace("(", "(");
  6684. memo_str = memo_str.Replace(")", ")");
  6685. int sIndex = memo_str.IndexOf("(");
  6686. int eIndex = memo_str.IndexOf(")");
  6687. if (sIndex == -1 || eIndex == -1)
  6688. {
  6689. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6690. return;
  6691. }
  6692. string first = memo_str.Substring(0, sIndex + 1);
  6693. string memoCtid = newentity.OrderSn;
  6694. //if (memoCtid.IndexOf("C") != -1)
  6695. //{
  6696. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6697. //if (CIdx.IndexOf("+") != -1)
  6698. //{
  6699. //CIdx = "C" + CIdx.Split('+')[1];
  6700. //}
  6701. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6702. //}
  6703. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6704. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6705. string newMemo = first + memoCtid + last;
  6706. newentity.seller_memo = newMemo;
  6707. newentity.FinishPlaceTime = null;
  6708. newentity.UnusualTag = 0;
  6709. newentity.UnusualCon = "";
  6710. newentity.UnusualTime = null;
  6711. newentity.AfterSaleMemo = "";
  6712. newentity.AfterSaleMethod = afterMethod;
  6713. newentity.AfterSalePreTime = null;
  6714. newentity.AfterSaleReason = "";
  6715. newentity.AfterSaleResponsible = "";
  6716. newentity.AfterSaleState = 0;
  6717. newentity.AfterSaleTime = null;
  6718. newentity.AfterSaleUserId = 0;
  6719. newentity.AfterSaleSupplierState = 0;
  6720. newentity.LastBillWaybillCode = "";
  6721. newentity.LastBillCpCode = "";
  6722. newentity.FinishAfterSaleTime = null;
  6723. newentity.HandleTime = null;
  6724. newentity.IsSF = 0;
  6725. newentity.IsOldCustomer = 0;
  6726. newentity.UrgencyTime = null;
  6727. newentity.ResponsibleUserId = "";
  6728. newentity.IsVerifyToSupplier = false;
  6729. newentity.payment = 0;
  6730. newentity.CheckMemo = "";
  6731. newentity.OutSid = "";
  6732. newentity.CheckOrderTime = null;
  6733. newentity.MemoOpt = 0;
  6734. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6735. }
  6736. newentity.isAfterSaleOrder = 1;
  6737. newentity.IsRefund = 0;
  6738. string receiveMobile = GetPostString("receiver_mobile");
  6739. if (receiveMobile.Length > 0)
  6740. {
  6741. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6742. if (trade != null)
  6743. {
  6744. trade.receiver_name = GetPostString("receiver_name");
  6745. trade.receiver_mobile = receiveMobile;
  6746. trade.receiver_state = GetPostString("receiver_state");
  6747. trade.receiver_city = GetPostString("receiver_city");
  6748. trade.receiver_district = GetPostString("receiver_district");
  6749. trade.receiver_address = GetPostString("receiver_address");
  6750. newentity.IsOffLineOrder = 1;
  6751. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6752. }
  6753. }
  6754. string st = GetPostString("ToState");
  6755. if (st.Length > 0)
  6756. {
  6757. if (newentity.OrderState <= 3)
  6758. {
  6759. newentity.WaitDesignTime = DateTime.Now;
  6760. newentity.StartDesignTime = null;
  6761. newentity.FinishDesignTime = null;
  6762. newentity.OrderState = 3;
  6763. if (st == "下单员")
  6764. {
  6765. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6766. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6767. {
  6768. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6769. }
  6770. }
  6771. else
  6772. {
  6773. newentity.WaitDesignTime = DateTime.Now;
  6774. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6775. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6776. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6777. {
  6778. DataRow user = dt1.Rows[0];
  6779. //找主管
  6780. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6781. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6782. if (dt != null && dt.Rows.Count > 0)
  6783. {
  6784. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6785. newentity.DesignUserId = designMr;
  6786. string key = "aftersale_order_" + designMr;
  6787. if (RedisHelper.HasKey(key))
  6788. {
  6789. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6790. list.Add(newentity.ctid);
  6791. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6792. }
  6793. }
  6794. //账号正常
  6795. if (user["State"].ToString() == "0")
  6796. {
  6797. newentity.DesignUserId = entity.DesignUserId;
  6798. string key = "aftersale_order_" + entity.DesignUserId;
  6799. if (RedisHelper.HasKey(key))
  6800. {
  6801. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6802. list.Add(newentity.ctid);
  6803. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6804. }
  6805. }
  6806. }
  6807. }
  6808. }
  6809. if (entity.IsXianHuo == 1)
  6810. {
  6811. newentity.OrderState = 6;
  6812. entity.FinishPlaceTime = DateTime.Now;
  6813. }
  6814. }
  6815. if (ishav)
  6816. {
  6817. newentity.Update();
  6818. }
  6819. else
  6820. {
  6821. newentity.Create();
  6822. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6823. newCellExtend.ctid = newentity.ctid;
  6824. newCellExtend.orderFrom = 20;
  6825. newCellExtend.orderType = 30;
  6826. if (st == "下单员")
  6827. {
  6828. }
  6829. else
  6830. {
  6831. newCellExtend.ReprintTime = DateTime.Now;
  6832. }
  6833. newCellExtend.Create();
  6834. }
  6835. if (st != "下单员")
  6836. {
  6837. if (entity.DispatchSort == 2)
  6838. {
  6839. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6840. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6841. }
  6842. }
  6843. }
  6844. //处理售后扩展
  6845. string resIdStr = GetPostString("ResponsibleUserId");
  6846. string refundFees = GetPostString("refundFrees");
  6847. int IsComplain = GetPostInt("isComplain");
  6848. int IsBad = GetPostInt("isBad");
  6849. string IsOriginal = GetPostString("isOriginal");
  6850. double diffResultPrice = GetPostDouble("diffResultPrice");
  6851. string textResult = GetPostString("textResult");
  6852. string supplierResponsible = GetPostString("supplierResponsible");
  6853. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6854. if (ceErpTradeAfterSaleExtend == null)
  6855. {
  6856. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6857. ceErpTradeAfterSaleExtend.tid = eid;
  6858. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6859. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6860. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6861. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6862. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6863. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6864. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6865. ceErpTradeAfterSaleExtend.Create();
  6866. }
  6867. else
  6868. {
  6869. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6870. {
  6871. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6872. }
  6873. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6874. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6875. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6876. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6877. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6878. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6879. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6880. ceErpTradeAfterSaleExtend.Update();
  6881. }
  6882. int gysid = GetPostInt("ResponsibleSupId");
  6883. if (entity.AfterSaleUserId == 0)
  6884. {
  6885. entity.AfterSaleUserId = CurrentUser.UserID;
  6886. }
  6887. entity.ResponsibleUserId = resIdStr;
  6888. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6889. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6890. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6891. {
  6892. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6893. int backNum = 0;
  6894. if (number != null)
  6895. {
  6896. backNum = number.BackNum;
  6897. }
  6898. char[] separator = { ',' };
  6899. string[] sArray = resIdStr.Split(separator);
  6900. string[] refundFreeList = { };
  6901. if (refundFees.Length > 0)
  6902. {
  6903. refundFreeList = refundFees.Split(separator);
  6904. }
  6905. int index = -1;
  6906. List<int> responsibleIds = new List<int>();
  6907. foreach (string i in sArray)
  6908. {
  6909. index++;
  6910. if (i.Length <= 0) continue;
  6911. char[] separator2 = { '_' };
  6912. string idstr = i.Split(separator2)[0];
  6913. string idtype = i.Split(separator2)[1];
  6914. double refudFree = 0;
  6915. if (refundFreeList.Length > 0)
  6916. {
  6917. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6918. }
  6919. if (idtype == "s")
  6920. {
  6921. isDesign = true;
  6922. designFree = refudFree;
  6923. }
  6924. int userId = Convert.ToInt32(idstr);
  6925. int type = 0;
  6926. if (idtype == "g")
  6927. {
  6928. type = 1;
  6929. }
  6930. if (idtype == "w")
  6931. {
  6932. type = 2;
  6933. }
  6934. if (idtype == "t")
  6935. {
  6936. type = 3;
  6937. }
  6938. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6939. if (ceErpTradeResponsible == null)
  6940. {
  6941. ceErpTradeResponsible = new CeErpTradeResponsible();
  6942. ceErpTradeResponsible.tid = eid;
  6943. ceErpTradeResponsible.UserId = userId;
  6944. ceErpTradeResponsible.createdTime = DateTime.Now;
  6945. ceErpTradeResponsible.type = type;
  6946. if (type == 1)
  6947. {
  6948. ceErpTradeResponsible.IsSup = 1;
  6949. }
  6950. if (type == 2)
  6951. {
  6952. ceErpTradeResponsible.IsFlow = 1;
  6953. }
  6954. }
  6955. int state = 0;
  6956. //已认可的不需要再次认可
  6957. if (ceErpTradeResponsible.VerifyState == 1)
  6958. {
  6959. state = 1;
  6960. }
  6961. ceErpTradeResponsible.RefundFee = refudFree;
  6962. ceErpTradeResponsible.VerifyState = state;
  6963. if (userId == 2125 || idtype == "w")
  6964. {
  6965. ceErpTradeResponsible.VerifyState = 1;
  6966. }
  6967. if (idtype == "w" && userId == 101)
  6968. {
  6969. ceErpTradeResponsible.VerifyState = state;
  6970. }
  6971. if (ceErpTradeResponsible.ID > 0)
  6972. {
  6973. ceErpTradeResponsible.Update();
  6974. }
  6975. else
  6976. {
  6977. ceErpTradeResponsible.Create();
  6978. }
  6979. if (isDesign)
  6980. {
  6981. responsibleId = ceErpTradeResponsible.ID;
  6982. }
  6983. responsibleIds.Add(responsibleId);
  6984. }
  6985. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  6986. CeErpTradeResponsible.NumByTid(backNum, eid);
  6987. }
  6988. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6989. if (ceErpTradeCellExtend != null)
  6990. {
  6991. ceErpTradeCellExtend.returnVisit = 0;
  6992. ceErpTradeCellExtend.Update();
  6993. }
  6994. if (entity.HandleTime != null)
  6995. {
  6996. if (entity.AfterSaleState == 1)
  6997. {
  6998. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6999. }
  7000. else
  7001. {
  7002. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7003. }
  7004. }
  7005. else
  7006. {
  7007. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7008. entity.HandleTime = DateTime.Now;
  7009. }
  7010. bool isCompale = false;
  7011. if (entity.AfterSaleState == 5)
  7012. {
  7013. isCompale = true;
  7014. entity.AfterSaleState = 3;
  7015. }
  7016. entity.AfterSaleSupplierState = 0;
  7017. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7018. {
  7019. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7020. }
  7021. string sImgs = GetPostString("img");
  7022. entity.AfterSaleSupplierImg = sImgs;
  7023. entity.supRefundType = GetPostString("supRefundType");
  7024. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7025. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7026. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7027. entity.AfterSaleMemoType = GetPostString("MemoType");
  7028. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7029. {
  7030. //entity.AfterSaleSupplierState = 2;
  7031. }
  7032. string df = GetPostString("DeductFee");
  7033. if (df == "")
  7034. {
  7035. df = "0";
  7036. }
  7037. string rf = GetPostString("RefundFee");
  7038. if (rf == "")
  7039. {
  7040. rf = "0";
  7041. }
  7042. string pm = GetPostString("AfterSalePayment");
  7043. if (pm == "")
  7044. {
  7045. pm = "0";
  7046. }
  7047. entity.AfterSalePayment = Convert.ToDouble(pm);
  7048. entity.DeductFee = Convert.ToDouble(df);
  7049. entity.RefundFee = Convert.ToDouble(rf);
  7050. entity.UpdateTime = DateTime.Now;
  7051. entity.Update();
  7052. string toState = GetPostString("ToState");
  7053. string original = GetPostString("isOriginal");
  7054. ApiVo apiVo = new ApiVo();
  7055. apiVo.orderNumber = entity.ctid;
  7056. apiVo.actionName = "afterDesign";
  7057. apiVo.orderRemarks = entity.AfterSaleMethod;
  7058. apiVo.reasonRemarks = entity.AfterSaleReason;
  7059. apiVo.isDesign = isDesign;
  7060. apiVo.designFree = designFree;
  7061. apiVo.responsibleId = responsibleId;
  7062. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7063. if (toState == "设计师")
  7064. {
  7065. apiVo.isOriginal = Convert.ToBoolean(original);
  7066. }
  7067. designHelper.API_WorkCore(apiVo);//afterDesign
  7068. CeErpMethod methodSql = new CeErpMethod();
  7069. methodSql.con = entity.AfterSaleMethod;
  7070. methodSql.addTime = DateTime.Now;
  7071. methodSql.Create();
  7072. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7073. CeErpMethod.ExecuteNonQuery(delsql);
  7074. if (isCompale)
  7075. {
  7076. aftersale_data_change(entity.ctid);
  7077. }
  7078. returnSuccessMsg("操作成功!");
  7079. return;
  7080. }
  7081. returnErrorMsg("找不到订单记录");
  7082. }
  7083. }
  7084. public void ins_erp_toresponsible()
  7085. {
  7086. if (UrlPostParmsCheck("ctid"))
  7087. {
  7088. string eid = GetPostString("ctid");
  7089. CeErpTradeCell entity = null;
  7090. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7091. if (entity != null)
  7092. {
  7093. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7094. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7095. {
  7096. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7097. return;
  7098. }
  7099. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7100. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7101. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7102. if (entity.AfterSalePreTime == null)
  7103. {
  7104. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7105. {
  7106. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7107. }
  7108. }
  7109. entity.AfterSalePreTime = DateTime.Now;
  7110. //预完成给售后主管审核客户问题直接完成
  7111. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7112. {
  7113. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7114. {
  7115. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7116. }
  7117. }
  7118. ceErpTradeAfterSaleExtend.Update();
  7119. entity.AfterSaleState = 2;
  7120. entity.UpdateTime = DateTime.Now;
  7121. entity.Update();
  7122. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7123. aftersale_data_change(entity.ctid);
  7124. returnSuccessMsg("操作成功!");
  7125. return;
  7126. }
  7127. returnErrorMsg("找不到订单记录");
  7128. }
  7129. }
  7130. public void cancel_erp_aftersaleanddelnew()
  7131. {
  7132. if (UrlPostParmsCheck("ctid"))
  7133. {
  7134. string eid = GetPostString("ctid");
  7135. CeErpTradeCell entity = null;
  7136. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7137. if (entity != null)
  7138. {
  7139. entity.AfterSaleState = 0;
  7140. entity.AfterSaleReason = "";
  7141. entity.AfterSaleMethod = "";
  7142. entity.AfterSaleMemo = "";
  7143. entity.AfterSaleResponsible = "";
  7144. entity.ResponsibleUserId = "";
  7145. entity.DeductFee = 0;
  7146. entity.RefundFee = 0;
  7147. entity.IsArbitrate = 0;
  7148. CeErpTradeResponsible.DelByTid(eid, -1);
  7149. entity.Update();
  7150. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7151. if (after != null)
  7152. {
  7153. if (after.OrderState < 5)
  7154. CeErpTradeCell.DelByCtid("S_" + eid);
  7155. }
  7156. returnSuccessMsg("操作成功!");
  7157. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7158. return;
  7159. }
  7160. returnErrorMsg("找不到订单记录");
  7161. }
  7162. }
  7163. public void get_erp_aftersale_pregather()
  7164. {
  7165. List<string> lw = new List<string>();
  7166. int st = GetInt("st");
  7167. string tid = GetPostString("ctid");
  7168. if (tid.Length > 0)
  7169. {
  7170. string select_tid = getTidByCtid(tid);
  7171. lw.Add(string.Format("tid='{0}'", select_tid));
  7172. }
  7173. string shopname = GetPostString("shopname");
  7174. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7175. string buyernick = GetPostString("buyer_nick");
  7176. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7177. string sellermemo = GetPostString("seller_memo");
  7178. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7179. string orderState = GetPostString("orderState");
  7180. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7181. string reason = GetPostString("reason");
  7182. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7183. string method = GetPostString("method");
  7184. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7185. string handler = GetPostString("handler");
  7186. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7187. string handledate1 = GetPostString("handledate1");
  7188. string handledate2 = GetPostString("handledate2");
  7189. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7190. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7191. string supplier = GetPostString("supplier");
  7192. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7193. string responsible = GetPostString("responsibleman");
  7194. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7195. string customer = GetPostString("customer");
  7196. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7197. string design = GetPostString("design");
  7198. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7199. string afterMemoType = GetPostString("aftermemotype");
  7200. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7201. string afterSaleMemo = GetPostString("afterSaleMemo");
  7202. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7203. string afterresult = GetPostString("afterresult");
  7204. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7205. string poscode = CurrentUser.UserPost.Post.Code;
  7206. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7207. {
  7208. string shopid = CurrentUser.User.pemShop;
  7209. lw.Add(string.Format("shopId in ({0})", shopid));
  7210. }
  7211. var mainwhere = string.Join(" and ", lw.ToArray());
  7212. string ro_json = "";
  7213. string type = GetPostString("gather_type");
  7214. int number = 0;
  7215. if (poscode == "AfterSale")
  7216. {
  7217. //处理中
  7218. if (type == "Handling")
  7219. {
  7220. 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) : ""));
  7221. DataTable dt = null;
  7222. try
  7223. {
  7224. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7225. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7226. }
  7227. catch (Exception e)
  7228. {
  7229. dt = new DataTable();
  7230. }
  7231. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7232. return;
  7233. }
  7234. if (type == "Wait")
  7235. {
  7236. //待处理
  7237. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7238. DataTable dt1 = null;
  7239. try
  7240. {
  7241. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7242. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7243. }
  7244. catch (Exception e)
  7245. {
  7246. dt1 = new DataTable();
  7247. }
  7248. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7249. return;
  7250. }
  7251. if (type == "back")
  7252. {
  7253. //打回
  7254. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7255. DataTable dt2 = null;
  7256. try
  7257. {
  7258. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7259. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7260. }
  7261. catch (Exception e)
  7262. {
  7263. dt2 = new DataTable();
  7264. }
  7265. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7266. return;
  7267. }
  7268. if (type == "preCompletion")
  7269. {
  7270. //预完成
  7271. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7272. DataTable dt3 = null;
  7273. try
  7274. {
  7275. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7276. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7277. }
  7278. catch (Exception e)
  7279. {
  7280. dt3 = new DataTable();
  7281. }
  7282. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7283. return;
  7284. }
  7285. if (type == "documentary")
  7286. {
  7287. //跟单中
  7288. 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) : ""));
  7289. DataTable dt4 = null;
  7290. try
  7291. {
  7292. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7293. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7294. }
  7295. catch (Exception e)
  7296. {
  7297. dt4 = new DataTable();
  7298. }
  7299. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7300. return;
  7301. }
  7302. if (type == "reBack")
  7303. {
  7304. //被打回
  7305. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7306. DataTable dt1 = null;
  7307. try
  7308. {
  7309. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7310. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7311. }
  7312. catch (Exception e)
  7313. {
  7314. dt1 = new DataTable();
  7315. }
  7316. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7317. return;
  7318. }
  7319. }
  7320. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7321. {
  7322. if (type == "puBack")
  7323. {
  7324. //退回
  7325. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7326. DataTable dt = null;
  7327. try
  7328. {
  7329. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7330. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7331. }
  7332. catch (Exception e)
  7333. {
  7334. dt = new DataTable();
  7335. }
  7336. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7337. return;
  7338. }
  7339. if (type == "reBack")
  7340. {
  7341. //打回
  7342. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7343. DataTable dt1 = null;
  7344. try
  7345. {
  7346. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7347. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7348. }
  7349. catch (Exception e)
  7350. {
  7351. dt1 = new DataTable();
  7352. }
  7353. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7354. return;
  7355. }
  7356. if (type == "examEd")
  7357. {
  7358. //已审核
  7359. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7360. DataTable dt2 = null;
  7361. try
  7362. {
  7363. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7364. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7365. }
  7366. catch (Exception e)
  7367. {
  7368. dt2 = new DataTable();
  7369. }
  7370. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7371. return;
  7372. }
  7373. if (type == "waitExam")
  7374. {
  7375. //待审核
  7376. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7377. DataTable dt3 = null;
  7378. try
  7379. {
  7380. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7381. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7382. }
  7383. catch (Exception e)
  7384. {
  7385. dt3 = new DataTable();
  7386. }
  7387. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7388. return;
  7389. }
  7390. if (type == "Handling")
  7391. {
  7392. //处理中
  7393. 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) : ""));
  7394. DataTable dt4 = null;
  7395. try
  7396. {
  7397. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7398. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7399. }
  7400. catch (Exception e)
  7401. {
  7402. dt4 = new DataTable();
  7403. }
  7404. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7405. return;
  7406. }
  7407. if (type == "Wait")
  7408. {
  7409. //待处理
  7410. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7411. DataTable dt5 = null;
  7412. try
  7413. {
  7414. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7415. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7416. }
  7417. catch (Exception e)
  7418. {
  7419. dt5 = new DataTable();
  7420. }
  7421. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7422. return;
  7423. }
  7424. if (type == "documentary")
  7425. {
  7426. //跟单中
  7427. 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) : ""));
  7428. DataTable dt6 = null;
  7429. try
  7430. {
  7431. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7432. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7433. }
  7434. catch (Exception e)
  7435. {
  7436. dt6 = new DataTable();
  7437. }
  7438. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7439. return;
  7440. }
  7441. }
  7442. returnSuccess(ro_json);
  7443. }
  7444. public void end_erp_aftersale()
  7445. {
  7446. if (UrlPostParmsCheck("ctid"))
  7447. {
  7448. string eid = GetPostString("ctid");
  7449. CeErpTradeCell entity = null;
  7450. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7451. if (entity != null)
  7452. {
  7453. string stype = GetPostString("stype");
  7454. string typeStr = stype;
  7455. entity.AfterSaleState = 4;
  7456. entity.FinishAfterSaleTime = DateTime.Now;
  7457. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7458. entity.Update();
  7459. ApiVo apiVo = new ApiVo();
  7460. apiVo.orderNumber = entity.ctid;
  7461. apiVo.actionName = "afterOver";
  7462. designHelper.API_WorkCore(apiVo); //afterOver
  7463. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7464. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7465. CeErpSukuraData.createInfo(entity.ctid, 8);
  7466. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7467. returnSuccessMsg("操作成功!");
  7468. return;
  7469. }
  7470. returnErrorMsg("找不到订单记录");
  7471. }
  7472. }
  7473. public void ins_erp_finishaftersale()
  7474. {
  7475. if (UrlPostParmsCheck("id"))
  7476. {
  7477. string eid = GetPostString("id");
  7478. CeErpTradeResponsible entity = null;
  7479. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7480. if (entity != null)
  7481. {
  7482. entity.VerifyState = 1;
  7483. entity.VerifyTime = DateTime.Now;
  7484. entity.Update();
  7485. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7486. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7487. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7488. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7489. if (dt.Rows.Count <= 0)
  7490. {
  7491. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7492. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7493. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7494. CeErpSukuraData.createInfo(entity.tid, 8);
  7495. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7496. {
  7497. CeErpDesignerBill.Del(entity.tid);
  7498. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7499. }
  7500. }
  7501. returnSuccessMsg("操作成功!");
  7502. return;
  7503. }
  7504. returnErrorMsg("找不到订单记录");
  7505. }
  7506. }
  7507. public void upd_erp_arbitrateaftersale()
  7508. {
  7509. if (UrlPostParmsCheck("id"))
  7510. {
  7511. string eid = GetPostString("id");
  7512. CeErpTradeResponsible entity = null;
  7513. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7514. if (entity != null)
  7515. {
  7516. entity.IsArbitrate = 1;
  7517. entity.ArbitradeMemo = GetPostString("reason");
  7518. entity.VerifyState = 2;
  7519. entity.Update();
  7520. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7521. if (tradecell != null)
  7522. {
  7523. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7524. tradecell.IsArbitrate = 1;
  7525. tradecell.Update();
  7526. }
  7527. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7528. returnSuccessMsg("操作成功!");
  7529. return;
  7530. }
  7531. returnErrorMsg("找不到订单记录");
  7532. }
  7533. }
  7534. public void upd_erp_backaftersale()
  7535. {
  7536. if (UrlPostParmsCheck("tid"))
  7537. {
  7538. string eid = GetPostString("tid");
  7539. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7540. int backNum = 0;
  7541. if (number != null)
  7542. {
  7543. backNum = number.BackNum;
  7544. }
  7545. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7546. CeErpTradeCell entity = null;
  7547. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7548. if (entity != null)
  7549. {
  7550. entity.AfterSaleBackReason = GetPostString("backreason");
  7551. entity.AfterSaleState = 1;
  7552. entity.AfterSaleSupplierState = 0;
  7553. entity.UpdateTime = DateTime.Now;
  7554. entity.Update();
  7555. returnSuccessMsg("操作成功!");
  7556. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7557. return;
  7558. }
  7559. returnErrorMsg("找不到订单记录");
  7560. }
  7561. }
  7562. public void get_erp_supplieraftersalelist()
  7563. {
  7564. DataStruct dStruct = GetPostStruct();
  7565. List<string> lw = new List<string>();
  7566. string tid = GetPostString("ctid");
  7567. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7568. string shopname = GetPostString("shopname");
  7569. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7570. string buyernick = GetPostString("buyer_nick");
  7571. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7572. string sellermemo = GetPostString("seller_memo");
  7573. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7574. string orderState = GetPostString("orderState");
  7575. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7576. string afterState = GetPostString("afterstate");
  7577. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7578. string date1 = GetPostString("date1");
  7579. string date2 = GetPostString("date2");
  7580. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7581. if (dw.Length > 0) lw.Add(dw);
  7582. string price1 = GetPostString("price1");
  7583. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7584. string price2 = GetPostString("price2");
  7585. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7586. string reason = GetPostString("reason");
  7587. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7588. string method = GetPostString("method");
  7589. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7590. string handledate1 = GetPostString("handledate1");
  7591. string handledate2 = GetPostString("handledate2");
  7592. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7593. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7594. string handler = GetPostString("handler");
  7595. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7596. string afterdate1 = GetPostString("afterdate1");
  7597. string afterdate2 = GetPostString("afterdate2");
  7598. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7599. if (afterDate.Length > 0) lw.Add(afterDate);
  7600. string customer = GetPostString("customer");
  7601. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7602. string design = GetPostString("design");
  7603. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7604. string afterMemoType = GetPostString("aftermemotype");
  7605. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7606. string vstate = GetPostString("vstate");
  7607. if (vstate.Length > 0)
  7608. {
  7609. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7610. }
  7611. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7612. string supplier = GetPostString("supplier");
  7613. int supid = commonHelper.getSupplierIDByName(supplier);
  7614. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7615. string posCode = CurrentUser.UserPost.Post.Code;
  7616. if (posCode == "Supplier")
  7617. {
  7618. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7619. }
  7620. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7621. {
  7622. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7623. }
  7624. else
  7625. {
  7626. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7627. }
  7628. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7629. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7630. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7631. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7632. writeGridDataTableJson(dStruct.TotalCount, dt);
  7633. }
  7634. public void upd_erp_supverifyaftersale()
  7635. {
  7636. if (UrlPostParmsCheck("id"))
  7637. {
  7638. string id = GetPostString("id");
  7639. int st = GetPostInt("afterstate");
  7640. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7641. CeErpTradeCell entity = null;
  7642. if (ceErpTradeResponsible != null)
  7643. {
  7644. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7645. }
  7646. string afmemo = GetPostString("supmemo");
  7647. string image = GetPostString("image");
  7648. if (entity != null)
  7649. {
  7650. entity.AfterSaleSupplierState = st;
  7651. entity.AfterSaleSupplierMemo = afmemo;
  7652. if (st == 1)
  7653. {
  7654. ceErpTradeResponsible.VerifyState = 1;
  7655. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7656. ceErpTradeResponsible.Update();
  7657. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7658. if (isAll)
  7659. {
  7660. entity.AfterSaleState = 4;
  7661. entity.FinishAfterSaleTime = DateTime.Now;
  7662. }
  7663. }
  7664. else
  7665. {
  7666. CeErpTradeResponsible.dateByTid(entity.ctid);
  7667. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7668. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7669. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7670. if (num <= 1)
  7671. {
  7672. entity.AfterSaleState = 1;
  7673. }
  7674. else
  7675. {
  7676. entity.AfterSaleState = 5;
  7677. }
  7678. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7679. if (ceErpTradeAfterSaleExtend != null)
  7680. {
  7681. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7682. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7683. ceErpTradeAfterSaleExtend.Update();
  7684. }
  7685. else
  7686. {
  7687. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7688. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7689. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7690. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7691. ceErpTradeAfterSaleExtend.Create();
  7692. }
  7693. }
  7694. if (entity.AfterSaleState == 4)
  7695. {
  7696. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7697. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7698. {
  7699. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7700. }
  7701. ApiVo apiVo = new ApiVo();
  7702. apiVo.orderNumber = entity.ctid;
  7703. apiVo.actionName = "afterOver";
  7704. designHelper.API_WorkCore(apiVo); //afterOver
  7705. }
  7706. entity.UpdateTime = DateTime.Now;
  7707. entity.Update();
  7708. returnSuccessMsg("操作成功!");
  7709. CeErpSukuraData.createInfo(entity.ctid, 8);
  7710. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7711. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7712. return;
  7713. }
  7714. returnErrorMsg("找不到订单记录");
  7715. }
  7716. }
  7717. public void upd_erp_masteraftersale()
  7718. {
  7719. if (UrlPostParmsCheck("id"))
  7720. {
  7721. string id = GetPostString("id");
  7722. int st = GetPostInt("afterstate");
  7723. string afmemo = GetPostString("supmemo");
  7724. string image = GetPostString("image");
  7725. string textResult = GetPostString("textResult");
  7726. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7727. if (ceErpTradeResponsible != null)
  7728. {
  7729. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7730. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7731. ceErpTradeResponsible.Update();
  7732. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7733. if (entity != null)
  7734. {
  7735. entity.AfterSaleSupplierState = st;
  7736. entity.AfterSaleSupplierMemo = afmemo;
  7737. if (st == 1)
  7738. {
  7739. }
  7740. else
  7741. {
  7742. CeErpTradeResponsible.dateByTid(entity.ctid);
  7743. //退回到售后
  7744. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7745. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7746. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7747. if (num <= 1)
  7748. {
  7749. entity.AfterSaleState = 1;
  7750. }
  7751. else
  7752. {
  7753. entity.AfterSaleState = 5;
  7754. }
  7755. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7756. if (ceErpTradeAfterSaleExtend != null)
  7757. {
  7758. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7759. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7760. ceErpTradeAfterSaleExtend.Update();
  7761. }
  7762. else
  7763. {
  7764. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7765. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7766. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7767. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7768. ceErpTradeAfterSaleExtend.Create();
  7769. }
  7770. }
  7771. entity.UpdateTime = DateTime.Now;
  7772. entity.Update();
  7773. returnSuccessMsg("操作成功!");
  7774. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7775. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7776. return;
  7777. }
  7778. }
  7779. returnErrorMsg("找不到订单记录");
  7780. }
  7781. }
  7782. public void upd_erp_personaftersale()
  7783. {
  7784. if (UrlPostParmsCheck("id"))
  7785. {
  7786. //林小连
  7787. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7788. {
  7789. upd_erp_masteraftersale();
  7790. return;
  7791. }
  7792. string id = GetPostString("id");
  7793. int st = GetPostInt("afterstate");
  7794. string afmemo = GetPostString("supmemo");
  7795. string image = GetPostString("image");
  7796. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7797. if (ceErpTradeResponsible != null)
  7798. {
  7799. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7800. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7801. ceErpTradeResponsible.Update();
  7802. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7803. if (entity != null)
  7804. {
  7805. entity.AfterSaleSupplierMemo = afmemo;
  7806. entity.AfterSaleSupplierState = st;
  7807. if (st == 1)
  7808. {
  7809. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7810. if (isAll)
  7811. {
  7812. entity.AfterSaleState = 4;
  7813. entity.FinishAfterSaleTime = DateTime.Now;
  7814. }
  7815. }
  7816. else
  7817. {
  7818. CeErpTradeResponsible.dateByTid(entity.ctid);
  7819. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7820. if (ceErpTradeAfterSaleExtend != null)
  7821. {
  7822. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7823. ceErpTradeAfterSaleExtend.Update();
  7824. }
  7825. else
  7826. {
  7827. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7828. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7829. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7830. ceErpTradeAfterSaleExtend.Create();
  7831. }
  7832. //退回到主管
  7833. //entity.AfterSaleState = 2;
  7834. }
  7835. if (entity.AfterSaleState == 4)
  7836. {
  7837. ApiVo apiVo = new ApiVo();
  7838. apiVo.orderNumber = entity.ctid;
  7839. apiVo.actionName = "afterOver";
  7840. designHelper.API_WorkCore(apiVo); //afterOver
  7841. }
  7842. entity.UpdateTime = DateTime.Now;
  7843. entity.Update();
  7844. returnSuccessMsg("操作成功!");
  7845. CeErpSukuraData.createInfo(entity.ctid, 8);
  7846. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7847. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7848. return;
  7849. }
  7850. }
  7851. returnErrorMsg("找不到订单记录");
  7852. }
  7853. }
  7854. public void set_erp_supplierrefundtag()
  7855. {
  7856. if (UrlPostParmsCheck("ctid"))
  7857. {
  7858. string eid = GetPostString("ctid");
  7859. CeErpTradeCell entity = null;
  7860. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7861. if (entity != null)
  7862. {
  7863. entity.IsSupplierRefund = GetPostInt("tag");
  7864. entity.Update();
  7865. returnSuccessMsg("操作成功!");
  7866. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7867. return;
  7868. }
  7869. returnErrorMsg("找不到订单记录");
  7870. }
  7871. }
  7872. public void get_erp_refundlist()
  7873. {
  7874. DataStruct dStruct = GetPostStruct();
  7875. List<string> lw = new List<string>();
  7876. string tid = GetPostString("tid");
  7877. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7878. //string rid = GetPostString("refund_id");
  7879. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7880. string shopname = GetPostString("shopname");
  7881. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7882. string buyernick = GetPostString("buyer_nick");
  7883. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7884. string customer = GetPostString("customer");
  7885. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7886. string design = GetPostString("design");
  7887. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7888. string sellermemo = GetPostString("seller_memo");
  7889. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7890. //string date1 = GetPostString("date1");
  7891. //string date2 = GetPostString("date2");
  7892. //string dateType = GetPostString("dateType");
  7893. //if (dateType.Length > 0)
  7894. //{
  7895. // if (dateType == "1001") dateType = "0";
  7896. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7897. // if (searchDT.Count == 2)
  7898. // {
  7899. // date1 = searchDT[0].ToString();
  7900. // date2 = searchDT[1].ToString();
  7901. // }
  7902. //}
  7903. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7904. //if (dw.Length > 0) lw.Add(dw);
  7905. string redate1 = GetPostString("refunddate1");
  7906. string redate2 = GetPostString("refunddate2");
  7907. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7908. if (dwdate.Length > 0) lw.Add(dwdate);
  7909. string price1 = GetPostString("price1");
  7910. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7911. string price2 = GetPostString("price2");
  7912. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7913. string ispartrefund = GetPostString("ispartrefund");
  7914. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7915. string refundState = GetPostString("refundvstate");
  7916. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7917. int st = GetInt("st");
  7918. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7919. {
  7920. string responsible = GetPostString("responsibleman");
  7921. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7922. lw.Add(string.Format("RefundState>={0}", st));
  7923. string code = CurrentUser.UserPost.Post.Code;
  7924. if (code == "CustomerService")
  7925. {
  7926. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7927. }
  7928. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7929. {
  7930. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7931. }
  7932. else if (code == "Place" || code == "PlaceMr")
  7933. {
  7934. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7935. }
  7936. dStruct.Order = "RefundState asc,created desc";
  7937. }
  7938. else if (st == 10)
  7939. {
  7940. string responsible = GetPostString("responsibleman");
  7941. if (responsible == "空白")
  7942. {
  7943. lw.Add(string.Format("ResponsibleUserName = ''"));
  7944. }
  7945. else if (responsible.Length > 0)
  7946. {
  7947. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7948. }
  7949. lw.Add(string.Format("RefundState>=0"));
  7950. dStruct.Order = "created desc";
  7951. }
  7952. else
  7953. {
  7954. string responsible = GetPostString("responsibleman");
  7955. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7956. lw.Add(string.Format("RefundState={0}", st));
  7957. dStruct.Order = "created desc";
  7958. }
  7959. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7960. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7961. dt.Columns.Add("refund_fees");
  7962. foreach (DataRow dr in dt.Rows)
  7963. {
  7964. String status = dr["status"].ToString();
  7965. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7966. {
  7967. dr["refund_fees"] = dr["refund_fee"];
  7968. }
  7969. else
  7970. {
  7971. dr["refund_fees"] = "0.0";
  7972. }
  7973. }
  7974. writeGridDataTableJson(dStruct.TotalCount, dt);
  7975. }
  7976. public void get_erp_refunddesignlist()
  7977. {
  7978. DataStruct dStruct = GetPostStruct();
  7979. List<string> lw = new List<string>();
  7980. string tid = GetPostString("tid");
  7981. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7982. string shopname = GetPostString("shopname");
  7983. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7984. string buyernick = GetPostString("buyer_nick");
  7985. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7986. string customer = GetPostString("customer");
  7987. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7988. string design = GetPostString("design");
  7989. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7990. string sellermemo = GetPostString("seller_memo");
  7991. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7992. string redate1 = GetPostString("refunddate1");
  7993. string redate2 = GetPostString("refunddate2");
  7994. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7995. if (dwdate.Length > 0) lw.Add(dwdate);
  7996. string price1 = GetPostString("price1");
  7997. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7998. string price2 = GetPostString("price2");
  7999. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8000. string ispartrefund = GetPostString("ispartrefund");
  8001. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8002. string designerorg = GetPostString("designerorg");
  8003. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8004. string refundState = GetPostString("refundState");
  8005. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8006. int myOrgid = CurrentUser.UserPost.OrgID;
  8007. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8008. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8009. {
  8010. if (CurrentUser.User.TeamIds.Length > 0)
  8011. {
  8012. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8013. }
  8014. else
  8015. {
  8016. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8017. }
  8018. }
  8019. else if ("SysAdmin".Equals(myOrgCode))
  8020. {
  8021. }
  8022. else
  8023. {
  8024. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8025. {
  8026. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8027. }
  8028. else
  8029. {
  8030. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8031. }
  8032. }
  8033. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8034. dStruct.Order = "created desc";
  8035. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8036. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8037. dt.Columns.Add("refund_fees");
  8038. foreach (DataRow dr in dt.Rows)
  8039. {
  8040. String status = dr["status"].ToString();
  8041. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8042. {
  8043. dr["refund_fees"] = dr["refund_fee"];
  8044. }
  8045. else
  8046. {
  8047. dr["refund_fees"] = "0.0";
  8048. }
  8049. }
  8050. writeGridDataTableJson(dStruct.TotalCount, dt);
  8051. }
  8052. public void handle_erp_refundtag()
  8053. {
  8054. if (UrlPostParmsCheck("refund_id"))
  8055. {
  8056. string eid = GetPostString("refund_id");
  8057. string respMan = GetPostString("ResponsibleName");
  8058. if (respMan.Length <= 0)
  8059. {
  8060. returnErrorMsg("责任人不能为空");
  8061. return;
  8062. }
  8063. CeErpTradeRefund entity = null;
  8064. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8065. if (entity != null)
  8066. {
  8067. entity.ResponsibleUserName = respMan;
  8068. string userid = GetPostString("ResponsibleUserId");
  8069. if (userid.Length > 0)
  8070. {
  8071. entity.ResponsibleUserId = userid;
  8072. }
  8073. entity.Memo = GetPostString("Memo");
  8074. if (respMan.IndexOf("客服") != -1 ||
  8075. respMan.IndexOf("设计师") != -1 ||
  8076. respMan.IndexOf("下单员") != -1)
  8077. {
  8078. entity.RefundState = 2;
  8079. }
  8080. else
  8081. {
  8082. entity.RefundState = 3;
  8083. }
  8084. entity.modified = DateTime.Now;
  8085. entity.Update();
  8086. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8087. returnSuccessMsg("操作成功!");
  8088. return;
  8089. }
  8090. returnErrorMsg("找不到订单记录");
  8091. }
  8092. }
  8093. public void handle_erp_designrefundtag()
  8094. {
  8095. if (UrlPostParmsCheck("refund_id"))
  8096. {
  8097. string eid = GetPostString("refund_id");
  8098. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8099. if (ceErpTradeCellExtend == null)
  8100. {
  8101. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8102. ceErpTradeCellExtend.ctid = eid;
  8103. }
  8104. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8105. if (ceErpTradeCellExtend.ID > 0)
  8106. {
  8107. ceErpTradeCellExtend.Update();
  8108. }
  8109. else
  8110. {
  8111. ceErpTradeCellExtend.Create();
  8112. }
  8113. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8114. returnSuccessMsg("操作成功!");
  8115. return;
  8116. }
  8117. returnErrorMsg("找不到订单记录");
  8118. }
  8119. public void upd_erp_refundverify()
  8120. {
  8121. if (UrlPostParmsCheck("refund_id"))
  8122. {
  8123. string eid = GetPostString("refund_id");
  8124. CeErpTradeRefund entity = null;
  8125. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8126. if (entity != null)
  8127. {
  8128. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8129. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8130. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8131. {
  8132. entity.RefundState = 2;
  8133. }
  8134. else
  8135. {
  8136. entity.RefundState = 3;
  8137. }
  8138. entity.Update();
  8139. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8140. returnSuccessMsg("操作成功!");
  8141. return;
  8142. }
  8143. returnErrorMsg("找不到订单记录");
  8144. }
  8145. }
  8146. public void upd_erp_refundapprove()
  8147. {
  8148. if (UrlPostParmsCheck("refund_id"))
  8149. {
  8150. string eid = GetPostString("refund_id");
  8151. CeErpTradeRefund entity = null;
  8152. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8153. if (entity != null)
  8154. {
  8155. int apr = GetPostInt("approve");
  8156. if (apr == 0)
  8157. {
  8158. entity.RefundState = 1;
  8159. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8160. }
  8161. else if (apr == 1)
  8162. {
  8163. entity.RefundState = 3;
  8164. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8165. }
  8166. entity.modified = DateTime.Now;
  8167. entity.Update();
  8168. returnSuccessMsg("操作成功!");
  8169. return;
  8170. }
  8171. returnErrorMsg("找不到订单记录");
  8172. }
  8173. }
  8174. public void get_erp_billlist()
  8175. {
  8176. DataStruct dStruct = GetPostStruct();
  8177. List<string> lw = new List<string>();
  8178. string title = GetPostString("title");
  8179. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8180. string tid = GetPostString("tid");
  8181. string tids = GetPostString("tids");
  8182. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8183. if (tids.Length > 0)
  8184. {
  8185. tids = "'" + tids + "'";
  8186. tids = tids.Replace(",", "','");
  8187. lw.Add(string.Format("tid in ({0})", tids));
  8188. }
  8189. string shopname = GetPostString("shopname");
  8190. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8191. string buyernick = GetPostString("buyer_nick");
  8192. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8193. string customer = GetPostString("customer");
  8194. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8195. string date1 = GetPostString("date1");
  8196. string date2 = GetPostString("date2");
  8197. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8198. if (dw.Length > 0) lw.Add(dw);
  8199. string price1 = GetPostString("price1");
  8200. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8201. string price2 = GetPostString("price2");
  8202. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8203. string returndate1 = GetPostString("returndate1");
  8204. string returndate2 = GetPostString("returndate2");
  8205. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8206. if (dw1.Length > 0) lw.Add(dw1);
  8207. string billtype = GetPostString("billtype");
  8208. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8209. string billstate = GetPostString("billstate");
  8210. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8211. string usershop = CurrentUser.User.pemShop;
  8212. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8213. dStruct.Order = "createTime desc";
  8214. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8215. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8216. //foreach (DataRow dr in dt.Rows)
  8217. //{
  8218. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8219. //}
  8220. writeGridDataTableJson(dStruct.TotalCount, dt);
  8221. }
  8222. public void modify_erp_billinfo()
  8223. {
  8224. if (UrlPostParmsCheck("ID"))
  8225. {
  8226. string eid = GetPostString("ID");
  8227. CeErpBill bill_entity = null;
  8228. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8229. if (bill_entity != null)
  8230. {
  8231. bill_entity.tid = GetPostString("tid");
  8232. bill_entity.title = GetPostString("title");
  8233. bill_entity.tax = GetPostString("tax");
  8234. bill_entity.bank = GetPostString("bank");
  8235. bill_entity.bankac = GetPostString("bankac");
  8236. bill_entity.address = GetPostString("address");
  8237. bill_entity.phone = GetPostString("phone");
  8238. bill_entity.price = GetPostString("price");
  8239. bill_entity.productId = GetPostInt("ProductName");
  8240. bill_entity.num = GetPostInt("num");
  8241. bill_entity.unit = GetPostString("unit");
  8242. bill_entity.type = GetPostString("type");
  8243. bill_entity.sendType = GetPostString("SendType");
  8244. bill_entity.email = GetPostString("email");
  8245. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8246. bill_entity.shopName = GetPostString("ShopName");
  8247. bill_entity.applymemo = GetPostString("applymemo");
  8248. bill_entity.modifyTime = DateTime.Now;
  8249. bill_entity.createTime = DateTime.Now;
  8250. bill_entity.state = 0;
  8251. bill_entity.Update();
  8252. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8253. returnSuccessMsg("发票修改成功!");
  8254. return;
  8255. }
  8256. returnErrorMsg("找不到对应记录");
  8257. }
  8258. }
  8259. public void set_erp_invoicing()
  8260. {
  8261. if (UrlPostParmsCheck("id"))
  8262. {
  8263. try
  8264. {
  8265. string eid = GetPostString("id");
  8266. CeErpBill bill_entity = null;
  8267. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8268. if (bill_entity != null)
  8269. {
  8270. int ComId = GetPostInt("ComId");
  8271. //string memo = GetPostString("Memo");
  8272. int allInfo = GetPostInt("allinfo");
  8273. string clert = CurrentUser.User.Name;
  8274. //string detailValue = GetPostString("detailvalue");
  8275. string billId = bill_entity.billOrderId;
  8276. string[] billIdList = billId.Split(',');
  8277. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8278. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8279. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8280. {
  8281. billCount += 1;
  8282. }
  8283. if (billId.Length <= 0 || billIdList.Length != billCount)
  8284. {
  8285. bill_entity.billOrderId = "";
  8286. string prebill = "ltb";
  8287. for (int idx = 1; idx <= billCount; idx++)
  8288. {
  8289. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8290. string billoid = prebill + idx + dtstr;
  8291. bill_entity.billOrderId += billoid;
  8292. if (idx < billCount)
  8293. {
  8294. bill_entity.billOrderId += ",";
  8295. }
  8296. }
  8297. }
  8298. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8299. if (bill_entity.state == 5)
  8300. {
  8301. string errMsg = bill_entity.failerror;
  8302. string[] errlist = errMsg.Split('|');
  8303. string[] errTags = new string[errlist.Length];
  8304. for (int itag = 0; itag < errlist.Length; itag++)
  8305. {
  8306. if (errlist[itag].Length <= 0) continue;
  8307. errTags[itag] = errlist[itag].Split('&')[0];
  8308. }
  8309. for (int iii = 0; iii < errTags.Length; iii++)
  8310. {
  8311. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8312. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8313. if (billOrderList.Length >= erroBillOrderTag)
  8314. {
  8315. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8316. if (needModifyBillId.Length <= 19)
  8317. {
  8318. needModifyBillId = needModifyBillId + "1";
  8319. }
  8320. else
  8321. {
  8322. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8323. last = last + 1;
  8324. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8325. }
  8326. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8327. }
  8328. }
  8329. }
  8330. bool isHaveBillSucces = false;
  8331. string totalRes = "";
  8332. bill_entity.failerror = "";
  8333. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8334. {
  8335. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8336. totalRes += res;
  8337. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8338. {
  8339. isHaveBillSucces = true;
  8340. bill_entity.comId = ComId;
  8341. bill_entity.state = 1;
  8342. bill_entity.executeTime = DateTime.Now;
  8343. bill_entity.executeUser = clert;
  8344. }
  8345. else
  8346. {
  8347. bill_entity.state = 5;
  8348. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8349. }
  8350. }
  8351. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8352. bill_entity.Update();
  8353. if (isHaveBillSucces)
  8354. {
  8355. StringBuilder sql = new StringBuilder();
  8356. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8357. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8358. }
  8359. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8360. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8361. {
  8362. returnErrorMsg("开票失败");
  8363. }
  8364. else
  8365. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8366. return;
  8367. }
  8368. returnErrorMsg("找不到对应记录");
  8369. }
  8370. catch (Exception ex)
  8371. {
  8372. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8373. returnErrorMsg("操作失败");
  8374. }
  8375. }
  8376. }
  8377. public void get_erp_invoicing_back()
  8378. {
  8379. if (UrlPostParmsCheck("id"))
  8380. {
  8381. try
  8382. {
  8383. string id = GetPostString("id");
  8384. CeErpBill entiy = CeErpBill.Get(id);
  8385. if (entiy != null)
  8386. {
  8387. if (entiy.state == 0)
  8388. {
  8389. returnErrorMsg("发票还未开具");
  8390. return;
  8391. }
  8392. string[] billOrderList = entiy.billOrderId.Split(',');
  8393. int iTag = 0;
  8394. entiy.fplsh = "";
  8395. entiy.fpdm = "";
  8396. entiy.fphm = "";
  8397. foreach (string billOrderId in billOrderList)
  8398. {
  8399. iTag++;
  8400. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8401. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8402. {
  8403. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8404. try
  8405. {
  8406. Invoicing_get_response_Obj iObj = null;
  8407. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8408. if (iObj != null)
  8409. {
  8410. entiy.state = 2;
  8411. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8412. entiy.fpdm += iObj.list[0].c_fpdm;
  8413. entiy.fphm += iObj.list[0].c_fphm;
  8414. if (iTag < billOrderList.Length)
  8415. {
  8416. entiy.fplsh += ",";
  8417. entiy.fpdm += ",";
  8418. entiy.fphm += ",";
  8419. }
  8420. entiy.Update();
  8421. }
  8422. StringBuilder sql = new StringBuilder();
  8423. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8424. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8425. returnSuccessMsg("开票成功");
  8426. }
  8427. catch (Exception ex)
  8428. {
  8429. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8430. }
  8431. return;
  8432. }
  8433. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8434. {
  8435. var res_obj = new
  8436. {
  8437. data = "开票中"
  8438. };
  8439. string ro_json = JsonConvert.SerializeObject(res_obj);
  8440. returnSuccess(ro_json);
  8441. return;
  8442. }
  8443. else
  8444. {
  8445. int eidx = res.IndexOf("c_resultmsg");
  8446. int lidx = res.IndexOf("c_status");
  8447. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8448. entiy.state = 5;
  8449. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8450. entiy.Update();
  8451. returnErrorMsg("开票失败");
  8452. return;
  8453. }
  8454. }
  8455. }
  8456. }
  8457. catch (Exception ex)
  8458. {
  8459. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8460. }
  8461. return;
  8462. }
  8463. }
  8464. public void get_erp_invoicing()
  8465. {
  8466. if (UrlPostParmsCheck("id"))
  8467. {
  8468. try
  8469. {
  8470. string id = GetPostString("id");
  8471. CeErpBill entiy = CeErpBill.Get(id);
  8472. if (entiy != null)
  8473. {
  8474. if (entiy.state == 0)
  8475. {
  8476. returnErrorMsg("发票还未开具");
  8477. return;
  8478. }
  8479. if (entiy.sendType == "纸质发票")
  8480. {
  8481. if (entiy.img.Length <= 0)
  8482. {
  8483. returnErrorMsg("查无纸质发票");
  8484. return;
  8485. }
  8486. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8487. returnSuccess(returnres);
  8488. return;
  8489. }
  8490. string[] billOrderList = entiy.billOrderId.Split(',');
  8491. int iTag = 0;
  8492. string fpUrl = "";
  8493. entiy.fplsh = "";
  8494. entiy.fpdm = "";
  8495. entiy.fphm = "";
  8496. foreach (string billOrderId in billOrderList)
  8497. {
  8498. iTag++;
  8499. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8500. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8501. {
  8502. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8503. Invoicing_get_response_Obj iObj = null;
  8504. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8505. if (iObj != null)
  8506. {
  8507. //entiy.state = 2;
  8508. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8509. entiy.fpdm += iObj.list[0].c_fpdm;
  8510. entiy.fphm += iObj.list[0].c_fphm;
  8511. if (iTag < billOrderList.Length)
  8512. {
  8513. entiy.fplsh += ",";
  8514. entiy.fpdm += ",";
  8515. entiy.fphm += ",";
  8516. }
  8517. entiy.Update();
  8518. fpUrl += iObj.list[0].c_url + ",";
  8519. }
  8520. //returnSuccess(res);
  8521. StringBuilder sql = new StringBuilder();
  8522. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8523. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8524. }
  8525. else
  8526. {
  8527. int eidx = res.IndexOf("c_resultmsg");
  8528. //int lidx = res.IndexOf("c_status");
  8529. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8530. //开票失败
  8531. entiy.state = 5;
  8532. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8533. entiy.Update();
  8534. returnErrorMsg("开票失败");
  8535. return;
  8536. }
  8537. }
  8538. var returnObj = new
  8539. {
  8540. data = fpUrl
  8541. };
  8542. string ro_json = JsonConvert.SerializeObject(returnObj);
  8543. returnSuccess(ro_json);
  8544. }
  8545. }
  8546. catch (Exception ex)
  8547. {
  8548. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8549. }
  8550. return;
  8551. }
  8552. }
  8553. public void save_erp_billimg()
  8554. {
  8555. if (UrlPostParmsCheck("id"))
  8556. {
  8557. string eid = GetPostString("id");
  8558. CeErpBill bill_entity = null;
  8559. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8560. if (bill_entity != null)
  8561. {
  8562. bill_entity.img = GetPostString("img");
  8563. bill_entity.executeTime = DateTime.Now;
  8564. bill_entity.state = 2;
  8565. bill_entity.Update();
  8566. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8567. returnSuccessMsg("保存成功");
  8568. }
  8569. return;
  8570. }
  8571. }
  8572. public void upd_erp_billreturnback()
  8573. {
  8574. if (UrlPostParmsCheck("id"))
  8575. {
  8576. int eid = GetPostInt("id");
  8577. CeErpBill bill_entity = null;
  8578. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8579. if (bill_entity != null)
  8580. {
  8581. bill_entity.state = 3;
  8582. bill_entity.returnReason = GetPostString("reason");
  8583. bill_entity.Update();
  8584. returnSuccessMsg("驳回成功!");
  8585. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8586. }
  8587. return;
  8588. }
  8589. }
  8590. public void cancel_erp_bill()
  8591. {
  8592. if (UrlPostParmsCheck("id"))
  8593. {
  8594. int eid = GetPostInt("id");
  8595. int detailValue = GetPostInt("detailvalue");
  8596. CeErpBill bill_entity = null;
  8597. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8598. string cres = "";
  8599. string gres = "";
  8600. if (bill_entity != null)
  8601. {
  8602. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8603. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8604. {
  8605. int iTag = 0;
  8606. bill_entity.fplsh = "";
  8607. bill_entity.fpdm = "";
  8608. bill_entity.fphm = "";
  8609. foreach (string billOrderId in billOrderList)
  8610. {
  8611. iTag++;
  8612. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8613. if (gres.IndexOf("success") != -1)
  8614. {
  8615. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8616. Invoicing_get_response_Obj iObj = null;
  8617. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8618. if (iObj != null)
  8619. {
  8620. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8621. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8622. bill_entity.fphm += iObj.list[0].c_fphm;
  8623. if (iTag < billOrderList.Length)
  8624. {
  8625. bill_entity.fplsh += ",";
  8626. bill_entity.fpdm += ",";
  8627. bill_entity.fphm += ",";
  8628. }
  8629. bill_entity.Update();
  8630. }
  8631. }
  8632. else
  8633. {
  8634. returnErrorMsg(gres);
  8635. return;
  8636. }
  8637. }
  8638. }
  8639. if (bill_entity.sendType == "纸质发票")
  8640. {
  8641. //作废
  8642. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8643. //if (DateTime.Now.Month == extime.Month)
  8644. //{
  8645. //cres = taobaoHelper.cancel_invoicing(eid);
  8646. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8647. //{
  8648. bill_entity.state = 4;//已作废
  8649. bill_entity.Update();
  8650. returnSuccessMsg("发票已作废");
  8651. return;
  8652. //}
  8653. //else
  8654. //{
  8655. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8656. // bill_entity.Update();
  8657. // returnErrorMsg(cres);
  8658. // return;
  8659. //}
  8660. //}
  8661. //else
  8662. //{
  8663. // returnErrorMsg("纸质发票只能作废本月的发票");
  8664. // return;
  8665. //}
  8666. }
  8667. //红冲
  8668. int redTag = 0;
  8669. string[] fpdmList = bill_entity.fpdm.Split(',');
  8670. string[] fphmList = bill_entity.fphm.Split(',');
  8671. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8672. {
  8673. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8674. return;
  8675. }
  8676. foreach (string billOrderId in billOrderList)
  8677. {
  8678. redTag++;
  8679. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8680. cres += onecres;
  8681. cres += ",";
  8682. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8683. {
  8684. bill_entity.state = 4;//已作废
  8685. //bill_entity.Update();
  8686. //returnSuccessMsg("发票已红冲");
  8687. }
  8688. else if (onecres.IndexOf("重复冲红") != -1)
  8689. {
  8690. bill_entity.state = 4;//已作废
  8691. //bill_entity.Update();
  8692. //returnSuccessMsg("发票已红冲");
  8693. }
  8694. else
  8695. {
  8696. string errmsg = commonHelper.KeepChinese(onecres);
  8697. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8698. }
  8699. }
  8700. bill_entity.Update();
  8701. if (cres.IndexOf("失败") != -1)
  8702. returnErrorMsg("红冲失败");
  8703. else
  8704. returnSuccessMsg("发票已红冲");
  8705. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8706. return;
  8707. }
  8708. return;
  8709. }
  8710. }
  8711. public void del_erp_billorder()
  8712. {
  8713. if (UrlPostParmsCheck("id"))
  8714. {
  8715. string eid = GetPostString("id");
  8716. CeErpBill.Del(eid);
  8717. CeErpBill bill = CeErpBill.Get(eid);
  8718. if (bill != null)
  8719. {
  8720. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8721. }
  8722. returnSuccessMsg("删除成功");
  8723. }
  8724. }
  8725. public void finish_erp_bill()
  8726. {
  8727. if (UrlPostParmsCheck("ids"))
  8728. {
  8729. string eids = GetPostString("ids");
  8730. string[] list = eids.Split(',');
  8731. foreach (string eid in list)
  8732. {
  8733. CeErpBill bill = CeErpBill.Get(eid);
  8734. if (bill != null)
  8735. {
  8736. bill.state = 2;
  8737. bill.Update();
  8738. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8739. }
  8740. }
  8741. returnSuccessMsg("操作成功");
  8742. }
  8743. }
  8744. public void get_erp_returncash()
  8745. {
  8746. DataStruct dStruct = GetPostStruct();
  8747. List<string> lw = new List<string>();
  8748. string tid = GetPostString("tid");
  8749. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8750. string shopname = GetPostString("shopname");
  8751. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8752. string buyernick = GetPostString("buyer_nick");
  8753. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8754. string customer = GetPostString("customer");
  8755. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8756. string returndate1 = GetPostString("returndate1");
  8757. string returndate2 = GetPostString("returndate2");
  8758. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8759. if (dw.Length > 0) lw.Add(dw);
  8760. string finishDate1 = GetPostString("finishdate1");
  8761. string finishDate2 = GetPostString("finishdate2");
  8762. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8763. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8764. string returntype = GetPostString("returntype");
  8765. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8766. string returnvstate = GetPostString("returnvstate");
  8767. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8768. dStruct.Order = "created desc";
  8769. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8770. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8771. writeGridDataTableJson(dStruct.TotalCount, dt);
  8772. }
  8773. public void get_erp_staygoods()
  8774. {
  8775. DataStruct dStruct = GetPostStruct();
  8776. List<string> lw = new List<string>();
  8777. string tid = GetPostString("tid");
  8778. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8779. string shopname = GetPostString("shopname");
  8780. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8781. string wangwang = GetPostString("wangwang");
  8782. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8783. string customer = GetPostString("customer");
  8784. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8785. string returndate1 = GetPostString("returndate1");
  8786. string returndate2 = GetPostString("returndate2");
  8787. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8788. if (dw.Length > 0) lw.Add(dw);
  8789. string finishDate1 = GetPostString("finishdate1");
  8790. string finishDate2 = GetPostString("finishdate2");
  8791. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8792. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8793. string returnvstate = GetPostString("returnvstate");
  8794. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8795. string persuadetype = GetPostString("persuadetype");
  8796. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8797. string customerOrg = GetPostString("customerOrg");
  8798. if (customerOrg.Length > 0)
  8799. {
  8800. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8801. }
  8802. dStruct.Order = "creata_time desc";
  8803. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8804. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8805. writeGridDataTableJson(dStruct.TotalCount, dt);
  8806. }
  8807. public void upd_erp_staygoods()
  8808. {
  8809. if (UrlPostParmsCheck("id"))
  8810. {
  8811. int eid = GetPostInt("id");
  8812. CeErpStayGoods entity = null;
  8813. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8814. if (entity != null)
  8815. {
  8816. entity.audit_type = 1;
  8817. entity.audit_time = DateTime.Now;
  8818. entity.audit_u_id = CurrentUser.UserID;
  8819. entity.audit_u_name = CurrentUser.UserName;
  8820. entity.Update();
  8821. returnSuccessMsg("审核成功!");
  8822. return;
  8823. }
  8824. returnErrorMsg("找不到订单记录");
  8825. }
  8826. }
  8827. public void upd_erp_stayGoodsback()
  8828. {
  8829. if (UrlPostParmsCheck("id"))
  8830. {
  8831. int eid = GetPostInt("id");
  8832. CeErpStayGoods entity = null;
  8833. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8834. if (entity != null)
  8835. {
  8836. entity.audit_text = GetPostString("reason");
  8837. entity.audit_type = 2;
  8838. entity.audit_time = DateTime.Now;
  8839. entity.audit_u_id = CurrentUser.UserID;
  8840. entity.audit_u_name = CurrentUser.UserName;
  8841. entity.Update();
  8842. returnSuccessMsg("退回成功!");
  8843. return;
  8844. }
  8845. returnErrorMsg("找不到订单记录");
  8846. }
  8847. }
  8848. public void upd_erp_returncashverify()
  8849. {
  8850. if (UrlPostParmsCheck("ID"))
  8851. {
  8852. int eid = GetPostInt("ID");
  8853. CeErpReturnCash entity = null;
  8854. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8855. if (entity != null)
  8856. {
  8857. entity.cashstate = 1;
  8858. entity.verifytime = DateTime.Now;
  8859. entity.verifyuserid = CurrentUser.UserID;
  8860. entity.Update();
  8861. returnSuccessMsg("审核成功!");
  8862. return;
  8863. }
  8864. returnErrorMsg("找不到订单记录");
  8865. }
  8866. }
  8867. public void upd_all_erp_returncashverify()
  8868. {
  8869. if (UrlPostParmsCheck("ID"))
  8870. {
  8871. String[] list = GetPostString("ID").Split(',');
  8872. CeErpReturnCash entity = null;
  8873. for (int i = 0; i < list.Length; i++)
  8874. {
  8875. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8876. if (entity != null)
  8877. {
  8878. if (entity.cashstate == 1)
  8879. {
  8880. returnErrorMsg("已审核过的订单不需要在审核!");
  8881. return;
  8882. }
  8883. entity.cashstate = 1;
  8884. entity.verifytime = DateTime.Now;
  8885. entity.verifyuserid = CurrentUser.UserID;
  8886. entity.Update();
  8887. }
  8888. }
  8889. returnSuccessMsg("审核成功!");
  8890. return;
  8891. }
  8892. }
  8893. public void upd_erp_returncashback()
  8894. {
  8895. if (UrlPostParmsCheck("ID"))
  8896. {
  8897. int eid = GetPostInt("ID");
  8898. CeErpReturnCash entity = null;
  8899. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8900. if (entity != null)
  8901. {
  8902. entity.backreason = GetPostString("reason");
  8903. entity.cashstate = 2;
  8904. entity.verifytime = DateTime.Now;
  8905. entity.verifyuserid = CurrentUser.UserID;
  8906. entity.Update();
  8907. returnSuccessMsg("退回成功!");
  8908. return;
  8909. }
  8910. returnErrorMsg("找不到订单记录");
  8911. }
  8912. }
  8913. public void upd_erp_returnprice()
  8914. {
  8915. if (UrlPostParmsCheck("ID"))
  8916. {
  8917. int eid = GetPostInt("ID");
  8918. CeErpReturnCash entity = null;
  8919. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8920. if (entity != null)
  8921. {
  8922. if (entity.cashstate == 1)
  8923. {
  8924. returnErrorMsg("审核通过了不能改");
  8925. return;
  8926. }
  8927. entity.returnprice = GetPostDouble("returnprice");
  8928. entity.Update();
  8929. returnSuccessMsg("修改成功!");
  8930. return;
  8931. }
  8932. returnErrorMsg("找不到订单记录");
  8933. }
  8934. }
  8935. public void del_erp_returncash()
  8936. {
  8937. if (UrlPostParmsCheck("ID"))
  8938. {
  8939. int eid = GetPostInt("ID");
  8940. CeErpReturnCash.Del(eid);
  8941. returnSuccessMsg("操作成功");
  8942. return;
  8943. }
  8944. }
  8945. public void test_for_do_sql()
  8946. {
  8947. string sql = GetPostString("sqlstr");
  8948. if (sql.Length > 0)
  8949. {
  8950. try
  8951. {
  8952. DbHelper.DbConn.ExecuteNonQuery(sql);
  8953. var res_obj = new
  8954. {
  8955. data = "成功",
  8956. };
  8957. string ro_json = JsonConvert.SerializeObject(res_obj);
  8958. returnSuccess(ro_json);
  8959. }
  8960. catch (Exception ex)
  8961. {
  8962. var res_obj = new
  8963. {
  8964. data = ex.Message,
  8965. };
  8966. string ro_json = JsonConvert.SerializeObject(res_obj);
  8967. returnSuccess(ro_json);
  8968. }
  8969. }
  8970. }
  8971. public void get_user_info()
  8972. {
  8973. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8974. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8975. }
  8976. public void get_total_data()
  8977. {
  8978. int userId = CurrentUser.UserID;
  8979. string sql = "";
  8980. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8981. {
  8982. 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);
  8983. }
  8984. else
  8985. {
  8986. 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 " +
  8987. "(select ID from CE_ErpUser where ID = {0}) d " +
  8988. "left join " +
  8989. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8990. ") a on d.ID = a.id left join " +
  8991. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8992. ") b on a.id = b.id1 left join" +
  8993. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8994. ") c on a.id = c.id2;", userId);
  8995. }
  8996. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8997. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8998. }
  8999. public void get_date_area_total_data2()
  9000. {
  9001. int userId = CurrentUser.UserID;
  9002. string date_type = GetPostString("timetype");
  9003. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9004. string sql = "";
  9005. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9006. {
  9007. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9008. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9009. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9010. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9011. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9012. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9013. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9014. ") a on e.ID = a.id left join " +
  9015. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9016. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9017. ") b on a.id = b.id1 " +
  9018. "left join " +
  9019. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9020. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9021. ") c on a.id = c.id2 " +
  9022. "left join " +
  9023. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9024. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9025. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9026. }
  9027. else
  9028. {
  9029. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9030. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9031. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9032. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9033. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9034. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9035. ") a on e.ID = a.id left join " +
  9036. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9037. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9038. ") c on a.id = c.id2 " +
  9039. "left join " +
  9040. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9041. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9042. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9043. }
  9044. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9045. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9046. }
  9047. public void get_date_area_total_data()
  9048. {
  9049. int userId = CurrentUser.UserID;
  9050. string date_type = GetPostString("timetype");
  9051. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9052. string date1 = searchDT[0].ToString();
  9053. string date2 = searchDT[1].ToString();
  9054. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9055. {
  9056. SqlParameter[] sqlParameter ={
  9057. new SqlParameter("@userId", SqlDbType.Int,4),
  9058. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9059. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9060. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9061. };
  9062. sqlParameter[0].Value = userId;
  9063. sqlParameter[1].Value = date1;
  9064. sqlParameter[2].Value = date2;
  9065. sqlParameter[3].Direction = ParameterDirection.Output;
  9066. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9067. string res = sqlParameter[3].Value.ToString();
  9068. var res_obj = new
  9069. {
  9070. data = res
  9071. };
  9072. string ro_json = JsonConvert.SerializeObject(res_obj);
  9073. returnSuccess(ro_json);
  9074. }
  9075. else
  9076. {
  9077. SqlParameter[] sqlParameter ={
  9078. new SqlParameter("@userId", SqlDbType.Int,4),
  9079. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9080. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9081. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9082. };
  9083. sqlParameter[0].Value = userId;
  9084. sqlParameter[1].Value = date1;
  9085. sqlParameter[2].Value = date2;
  9086. sqlParameter[3].Direction = ParameterDirection.Output;
  9087. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9088. string res = sqlParameter[3].Value.ToString();
  9089. var res_obj = new
  9090. {
  9091. data = res
  9092. };
  9093. string ro_json = JsonConvert.SerializeObject(res_obj);
  9094. returnSuccess(ro_json);
  9095. }
  9096. //writeGridDataViewJson(dt.Rows.Count, dv);
  9097. }
  9098. public void get_order_list()
  9099. {
  9100. string strFields = GetPostString("paraFields");
  9101. string strOrder = GetPostString("paraOrder");
  9102. string strWhere = GetPostString("paraWhere");
  9103. string strPageSize = GetPostString("paraPageSize");
  9104. DataStruct dStruct = GetPostStruct();
  9105. dStruct.PageSize = int.Parse(strPageSize);
  9106. dStruct.Fileds = strFields;
  9107. dStruct.Order = strOrder;
  9108. dStruct.MainWhere = strWhere;
  9109. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9110. writeGridDataTableJson(dStruct.TotalCount, dt);
  9111. }
  9112. ////获取待开始订单列表
  9113. //public void get_wait_design_order_list()
  9114. //{
  9115. // string date_type = GetPostString("date_type");
  9116. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9117. // DataStruct dStruct = GetPostStruct();
  9118. // dStruct.PageSize = 1000;
  9119. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9120. // List<string> lw = new List<string>();
  9121. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9122. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9123. // dStruct.Order = "WaitDesignTime asc";
  9124. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9125. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9126. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9127. //}
  9128. //获取完成单量排名
  9129. public void get_finish_order_count_ranking()
  9130. {
  9131. /* string date_type = GetPostString("date_type");
  9132. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9133. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9134. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9135. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9136. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9137. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9138. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9139. writeGridDataTableJson(0, new DataTable());
  9140. }
  9141. public void get_finish_order_amount_ranking()
  9142. {
  9143. /*string date_type = GetPostString("date_type");
  9144. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9145. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9146. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9147. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9148. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9149. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9150. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9151. writeGridDataTableJson(0, new DataTable());
  9152. }
  9153. public void get_finish_refund_count_ranking()
  9154. {
  9155. string date_type = GetPostString("date_type");
  9156. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9157. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9158. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9159. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9160. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9161. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9162. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9163. writeGridDataTableJson(dt.Rows.Count, dt);
  9164. }
  9165. public void get_finish_refund_amount_ranking()
  9166. {
  9167. string date_type = GetPostString("date_type");
  9168. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9169. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9170. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9171. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9172. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9173. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9174. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9175. writeGridDataTableJson(dt.Rows.Count, dt);
  9176. }
  9177. public void set_erp_finishorder_director()
  9178. {
  9179. if (UrlPostParmsCheck("ctid"))
  9180. {
  9181. string eid = GetPostString("ctid");
  9182. CeErpTradeCell entity = null;
  9183. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9184. if (entity != null)
  9185. {
  9186. entity.OrderState = 8;
  9187. entity.Update();
  9188. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9189. returnSuccessMsg("操作成功!");
  9190. return;
  9191. }
  9192. returnErrorMsg("找不到记录");
  9193. }
  9194. }
  9195. public void get_erp_placeregistlist()
  9196. {
  9197. DataStruct dStruct = GetPostStruct();
  9198. List<string> lw = new List<string>();
  9199. string outsid = GetPostString("outsid");
  9200. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9201. string memo = GetPostString("memo");
  9202. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9203. string filename = GetPostString("filename");
  9204. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9205. string islate = GetPostString("islate");
  9206. if (islate.Length > 0)
  9207. {
  9208. if (islate == "1")
  9209. lw.Add(string.Format("OutLate>0"));
  9210. else
  9211. lw.Add(string.Format("OutLate=0"));
  9212. }
  9213. string placedate1 = GetPostString("placedate1");
  9214. string placedate2 = GetPostString("placedate2");
  9215. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9216. if (dw.Length > 0) lw.Add(dw);
  9217. string deliveryDate1 = GetPostString("deliverydate1");
  9218. string deliveryDate2 = GetPostString("deliverydate2");
  9219. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9220. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9221. dStruct.Order = "ID desc";
  9222. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9223. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9224. writeGridDataTableJson(dStruct.TotalCount, dt);
  9225. }
  9226. public void ins_erp_placeregist()
  9227. {
  9228. if (UrlPostParmsCheck("id"))
  9229. {
  9230. string eid = GetPostString("id");
  9231. CeErpPlaceRegister entity = null;
  9232. if (eid == "0")//新增
  9233. {
  9234. entity = new CeErpPlaceRegister();
  9235. string xdTime = GetPostString("placeTime");
  9236. if (xdTime.Length > 0)
  9237. {
  9238. entity.PlactTime = Convert.ToDateTime(xdTime);
  9239. }
  9240. string fhTime = GetPostString("deliveryTime");
  9241. if (fhTime.Length > 0)
  9242. {
  9243. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9244. }
  9245. string preTime = GetPostString("preOutTime");
  9246. if (preTime.Length > 0)
  9247. {
  9248. entity.PreOutTime = Convert.ToDateTime(preTime);
  9249. }
  9250. entity.DeliveryCount = GetPostInt("deliveryCount");
  9251. entity.ReceiveCount = GetPostInt("receiveCount");
  9252. entity.OutSid = GetPostString("outSid");
  9253. entity.FileName = GetPostString("fileName");
  9254. entity.Memo = GetPostString("memo");
  9255. entity.AddUserId = CurrentUser.UserID;
  9256. entity.CreateTime = DateTime.Now;
  9257. entity.Img = GetPostString("img");
  9258. entity.Supplier = GetPostInt("supplier");
  9259. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9260. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9261. {
  9262. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9263. DateTime dt2 = (DateTime)entity.PreOutTime;
  9264. TimeSpan span = dt1.Subtract(dt2);
  9265. if (span.Days > 0)
  9266. {
  9267. entity.OutLate = span.Days;
  9268. }
  9269. }
  9270. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9271. entity.Create();
  9272. returnSuccessMsg("添加成功!");
  9273. return;
  9274. }
  9275. else //修改
  9276. {
  9277. entity = CeErpPlaceRegister.Get(eid);
  9278. if (entity != null)
  9279. {
  9280. string xdTime = GetPostString("placeTime");
  9281. if (xdTime.Length > 0)
  9282. {
  9283. entity.PlactTime = Convert.ToDateTime(xdTime);
  9284. }
  9285. string fhTime = GetPostString("deliveryTime");
  9286. if (fhTime.Length > 0)
  9287. {
  9288. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9289. }
  9290. string preTime = GetPostString("preOutTime");
  9291. if (preTime.Length > 0)
  9292. {
  9293. entity.PreOutTime = Convert.ToDateTime(preTime);
  9294. }
  9295. entity.DeliveryCount = GetPostInt("deliveryCount");
  9296. entity.ReceiveCount = GetPostInt("receiveCount");
  9297. if (entity.DeliveryCount == entity.ReceiveCount)
  9298. {
  9299. entity.CurState = "已完成";
  9300. }
  9301. else
  9302. {
  9303. entity.CurState = "未完成";
  9304. }
  9305. entity.OutSid = GetPostString("outSid");
  9306. entity.FileName = GetPostString("fileName");
  9307. entity.Memo = GetPostString("memo");
  9308. entity.Img = GetPostString("img");
  9309. entity.Supplier = GetPostInt("supplier");
  9310. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9311. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9312. {
  9313. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9314. DateTime dt2 = (DateTime)entity.PreOutTime;
  9315. TimeSpan span = dt1.Subtract(dt2);
  9316. if (span.Days > 0)
  9317. {
  9318. entity.OutLate = span.Days;
  9319. }
  9320. }
  9321. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9322. entity.Update();
  9323. returnSuccessMsg("修改成功");
  9324. return;
  9325. }
  9326. returnErrorMsg("找不到对应的记录");
  9327. return;
  9328. }
  9329. }
  9330. returnErrorMsg("缺少必要参数");
  9331. }
  9332. public void del_erp_placeregist()
  9333. {
  9334. string eid = GetPostString("id");
  9335. CeErpPlaceRegister.Del(eid);
  9336. returnSuccessMsg("删除成功!");
  9337. return;
  9338. }
  9339. public void ins_erp_placeregistbyorder()
  9340. {
  9341. string ctid = GetPostString("ctid");
  9342. if (ctid.Length > 0)
  9343. {
  9344. StringBuilder sql = new StringBuilder();
  9345. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9346. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9347. if (dt.Rows.Count > 0)
  9348. {
  9349. foreach (DataRow dr in dt.Rows)
  9350. {
  9351. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9352. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9353. entity.AddUserId = CurrentUser.UserID;
  9354. entity.tid = dr["tid"].ToString();
  9355. entity.Did = Convert.ToString(dr["ctid"]);
  9356. entity.splitTag = dr["SplitTag"].ToString();
  9357. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9358. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9359. if (pre_ctid.Length > 0)
  9360. {
  9361. sellmemo = sellmemo.Replace(pre_ctid, "");
  9362. }
  9363. sellmemo = sellmemo.Replace("[", "");
  9364. sellmemo = sellmemo.Replace("]", "");
  9365. entity.FileName = sellmemo;
  9366. string count = dr["ProductCount"].ToString();
  9367. int usecount = commonHelper.getIntCountFromString(count);
  9368. entity.DeliveryCount = usecount;
  9369. entity.CurState = "未完成";
  9370. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9371. {
  9372. entity.Supplier = 24;//dl手提袋定制
  9373. }
  9374. else
  9375. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9376. entity.CreateTime = DateTime.Now;
  9377. entity.Create();
  9378. }
  9379. returnSuccessMsg("操作成功");
  9380. return;
  9381. }
  9382. returnErrorMsg("没有找到对应订单");
  9383. return;
  9384. }
  9385. returnErrorMsg("缺少订单编号");
  9386. return;
  9387. }
  9388. public void get_erp_persuadelist()
  9389. {
  9390. DataStruct dStruct = GetPostStruct();
  9391. List<string> lw = new List<string>();
  9392. string ctid = GetPostString("ctid");
  9393. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9394. string shopname = GetPostString("shopname");
  9395. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9396. string buyernick = GetPostString("buyer_nick");
  9397. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9398. string customer = GetPostString("customer");
  9399. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9400. string returndate1 = GetPostString("returndate1");
  9401. string returndate2 = GetPostString("returndate2");
  9402. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9403. if (dw.Length > 0) lw.Add(dw);
  9404. string finishDate1 = GetPostString("finishdate1");
  9405. string finishDate2 = GetPostString("finishdate2");
  9406. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9407. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9408. string persuadetype = GetPostString("persuadetype");
  9409. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9410. string returnvstate = GetPostString("returnvstate");
  9411. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9412. dStruct.Order = "created desc";
  9413. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9414. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9415. writeGridDataTableJson(dStruct.TotalCount, dt);
  9416. }
  9417. public void upd_erp_returnpersuadeback()
  9418. {
  9419. if (UrlPostParmsCheck("ID"))
  9420. {
  9421. int eid = GetPostInt("ID");
  9422. CeErpPersuade entity = null;
  9423. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9424. if (entity != null)
  9425. {
  9426. entity.backreason = GetPostString("reason");
  9427. entity.pstate = 2;
  9428. entity.verifytime = DateTime.Now;
  9429. entity.verifyuserid = CurrentUser.UserID;
  9430. entity.Update();
  9431. returnSuccessMsg("退回成功!");
  9432. return;
  9433. }
  9434. returnErrorMsg("找不到订单记录");
  9435. }
  9436. }
  9437. public void upd_erp_returnpersuadeverify()
  9438. {
  9439. if (UrlPostParmsCheck("ID"))
  9440. {
  9441. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9442. {
  9443. returnErrorMsg("暂无权限审核");
  9444. return;
  9445. }
  9446. int eid = GetPostInt("ID");
  9447. CeErpPersuade entity = null;
  9448. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9449. if (entity != null)
  9450. {
  9451. entity.pstate = 1;
  9452. entity.verifytime = DateTime.Now;
  9453. entity.verifyuserid = CurrentUser.UserID;
  9454. entity.Update();
  9455. returnSuccessMsg("审核成功!");
  9456. return;
  9457. }
  9458. returnErrorMsg("找不到订单记录");
  9459. }
  9460. }
  9461. public void del_erp_persuade()
  9462. {
  9463. if (UrlPostParmsCheck("ID"))
  9464. {
  9465. int eid = GetPostInt("ID");
  9466. CeErpPersuade.Del(eid);
  9467. returnSuccessMsg("操作成功");
  9468. return;
  9469. }
  9470. }
  9471. public void get_erp_oldcustoupload()
  9472. {
  9473. DataStruct dStruct = GetPostStruct();
  9474. List<string> lw = new List<string>();
  9475. string buyernick = GetPostString("buyer_nick");
  9476. if (buyernick.Length > 0)
  9477. {
  9478. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9479. }
  9480. else
  9481. return;
  9482. dStruct.Order = "pay_time desc";
  9483. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9484. DataTable dt = null;
  9485. dt = WebCache.GetData("view_erptradecell", dStruct);
  9486. writeGridDataTableJson(dStruct.TotalCount, dt);
  9487. }
  9488. public void get_erp_checkorderlist()
  9489. {
  9490. DataStruct dStruct = GetPostStruct();
  9491. List<string> lw = new List<string>();
  9492. string tid = GetPostString("ctid");
  9493. if (tid.Length > 0)
  9494. {
  9495. string select_tid = getTidByCtid(tid);
  9496. lw.Add(string.Format("tid='{0}'", select_tid));
  9497. }
  9498. string shopname = GetPostString("shopname");
  9499. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9500. string buyernick = GetPostString("buyer_nick");
  9501. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9502. string customer = GetPostString("customer");
  9503. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9504. string design = GetPostString("design");
  9505. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9506. string orderState = GetPostString("orderState");
  9507. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9508. string address = GetPostString("address");
  9509. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9510. string sellermemo = GetPostString("seller_memo");
  9511. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9512. string supplier = GetPostString("supplier");
  9513. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9514. {
  9515. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9516. }
  9517. else
  9518. {
  9519. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9520. }
  9521. string date1 = GetPostString("date1");
  9522. string date2 = GetPostString("date2");
  9523. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9524. if (dw.Length > 0) lw.Add(dw);
  9525. string placedate1 = GetPostString("placedate1");
  9526. string placedate2 = GetPostString("placedate2");
  9527. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9528. if (fdw.Length > 0) lw.Add(fdw);
  9529. string price1 = GetPostString("price1");
  9530. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9531. string price2 = GetPostString("price2");
  9532. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9533. string checkst = GetPostString("checkstate");
  9534. if (checkst.Length > 0 && "10".Equals(checkst))
  9535. {
  9536. lw.Add(string.Format("CheckOut>0"));
  9537. }
  9538. else
  9539. {
  9540. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9541. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9542. }
  9543. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9544. {
  9545. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9546. }
  9547. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9548. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9549. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9550. writeGridDataTableJson(dStruct.TotalCount, dt);
  9551. }
  9552. public void ins_erp_startCheck()
  9553. {
  9554. if (UrlPostParmsCheck("ctid"))
  9555. {
  9556. string eid = GetPostString("ctid");
  9557. CeErpTradeCell entity = null;
  9558. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9559. if (entity != null)
  9560. {
  9561. entity.MemoOpt = 4;
  9562. entity.UpdateTime = DateTime.Now;
  9563. entity.Update();
  9564. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9565. CeErpSukuraData.createInfo(entity.ctid, 6);
  9566. returnSuccessMsg("操作成功!");
  9567. return;
  9568. }
  9569. returnErrorMsg("找不到记录");
  9570. }
  9571. }
  9572. public void upd_erp_sendXlw()
  9573. {
  9574. if (UrlPostParmsCheck("ctid"))
  9575. {
  9576. string eid = GetPostString("ctid");
  9577. CeErpTradeCell entity = null;
  9578. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9579. if (entity != null)
  9580. {
  9581. if (entity.IsSendGift == 1)
  9582. {
  9583. returnErrorMsg("请勿重复标记");
  9584. return;
  9585. }
  9586. entity.IsSendGift = 1;
  9587. entity.Update();
  9588. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9589. returnSuccessMsg("操作成功!");
  9590. return;
  9591. }
  9592. returnErrorMsg("找不到记录");
  9593. }
  9594. }
  9595. public void cancel_sendXlw()
  9596. {
  9597. if (UrlPostParmsCheck("ctid"))
  9598. {
  9599. string eid = GetPostString("ctid");
  9600. CeErpTradeCell entity = null;
  9601. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9602. if (entity != null)
  9603. {
  9604. if (entity.IsSendGift == 0)
  9605. {
  9606. returnErrorMsg("未标记小礼物");
  9607. return;
  9608. }
  9609. entity.IsSendGift = 0;
  9610. entity.Update();
  9611. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9612. returnSuccessMsg("操作成功!");
  9613. return;
  9614. }
  9615. returnErrorMsg("找不到记录");
  9616. }
  9617. }
  9618. public void get_erp_designbill()
  9619. {
  9620. DataStruct dStruct = GetPostStruct();
  9621. List<string> lw = new List<string>();
  9622. int isMy = GetInt("my");
  9623. if (isMy == 1)
  9624. {
  9625. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9626. }
  9627. string tid = GetPostString("tid");
  9628. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9629. string userName = GetPostString("design");
  9630. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9631. string price1 = GetPostString("price1");
  9632. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9633. string price2 = GetPostString("price2");
  9634. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9635. string rePrice1 = GetPostString("rePrice1");
  9636. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9637. string rePrice2 = GetPostString("rePrice2");
  9638. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9639. string designerType = GetPostString("designerType");
  9640. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9641. string orderState = GetPostString("orderState");
  9642. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9643. string endTime1 = GetPostString("endTime1");
  9644. string endTime2 = GetPostString("endTime2");
  9645. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9646. if (dw.Length > 0) lw.Add(dw);
  9647. string isDk = GetPostString("isDk");
  9648. if (isDk == "1")
  9649. {
  9650. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9651. }
  9652. else if (isDk == "0")
  9653. {
  9654. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9655. }
  9656. dStruct.Order = "oid, create_time desc";
  9657. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9658. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9659. writeGridDataTableJson(dStruct.TotalCount, dt);
  9660. }
  9661. public void upd_erp_designerbill()
  9662. {
  9663. if (UrlPostParmsCheck("ID"))
  9664. {
  9665. string eid = GetPostString("ID");
  9666. CeErpDesignerBill entity = null;
  9667. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9668. if (entity != null)
  9669. {
  9670. if (GetPostDouble("designerpirce") > 0)
  9671. {
  9672. entity.realPrice = GetPostDouble("designerpirce");
  9673. entity.update_time = DateTime.Now;
  9674. entity.update_u_id = CurrentUser.UserID;
  9675. entity.update_u_name = CurrentUser.UserName;
  9676. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9677. entity.Update();
  9678. returnSuccessMsg("操作成功!");
  9679. return;
  9680. }
  9681. else
  9682. {
  9683. entity.price = GetPostDouble("price");
  9684. entity.update_time = DateTime.Now;
  9685. entity.update_u_id = CurrentUser.UserID;
  9686. entity.update_u_name = CurrentUser.UserName;
  9687. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9688. entity.Update();
  9689. returnSuccessMsg("操作成功!");
  9690. return;
  9691. }
  9692. }
  9693. returnErrorMsg("找不到记录");
  9694. }
  9695. }
  9696. public void audit_erp_designerbill()
  9697. {
  9698. if (UrlPostParmsCheck("ID"))
  9699. {
  9700. string eid = GetPostString("ID");
  9701. CeErpDesignerBill entity = null;
  9702. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9703. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9704. if (entity != null)
  9705. {
  9706. entity.realPrice = GetPostDouble("designerpirce");
  9707. entity.update_time = DateTime.Now;
  9708. entity.update_u_id = CurrentUser.UserID;
  9709. entity.update_u_name = CurrentUser.UserName;
  9710. entity.isAudit = 1;
  9711. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9712. entity.Update();
  9713. if (orderEntity != null)
  9714. {
  9715. orderEntity.IsReadTag = 3;
  9716. orderEntity.Update();
  9717. }
  9718. returnSuccessMsg("操作成功!");
  9719. return;
  9720. }
  9721. returnErrorMsg("找不到记录");
  9722. }
  9723. }
  9724. public void all_audit_erp_designerbill()
  9725. {
  9726. if (UrlPostParmsCheck("idList"))
  9727. {
  9728. string[] list = GetPostString("idList").Split(',');
  9729. CeErpDesignerBill entity = null;
  9730. for (int i = 0; i < list.Length; i++)
  9731. {
  9732. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9733. if (entity == null) return;
  9734. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9735. if (orderEntity == null) return;
  9736. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9737. entity.update_time = DateTime.Now;
  9738. entity.update_u_id = CurrentUser.UserID;
  9739. entity.update_u_name = CurrentUser.UserName;
  9740. entity.isAudit = 1;
  9741. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9742. entity.Update();
  9743. orderEntity.IsReadTag = 3;
  9744. orderEntity.Update();
  9745. }
  9746. returnSuccessMsg("操作成功!");
  9747. return;
  9748. }
  9749. }
  9750. public void get_erp_sameorders()
  9751. {
  9752. if (UrlPostParmsCheck("ctid"))
  9753. {
  9754. string eid = GetPostString("ctid");
  9755. CeErpTradeCell entity = null;
  9756. entity = CeErpTradeCell.GetByCtid(eid);
  9757. if (entity != null)
  9758. {
  9759. StringBuilder sql = new StringBuilder();
  9760. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9761. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9762. var res = new
  9763. {
  9764. data = dt.Rows.Count
  9765. };
  9766. string ro_jsond = JsonConvert.SerializeObject(res);
  9767. returnSuccess(ro_jsond);
  9768. return;
  9769. }
  9770. returnErrorMsg("未找到订单");
  9771. return;
  9772. }
  9773. returnErrorMsg("缺少必要的参数");
  9774. }
  9775. public void get_erp_islasthavesameorder()
  9776. {
  9777. if (UrlPostParmsCheck("ctid"))
  9778. {
  9779. string eid = GetPostString("ctid");
  9780. string[] ctidList = eid.Split(',');
  9781. StringBuilder sql = new StringBuilder();
  9782. string tisCtid = "";
  9783. foreach (string ctid in ctidList)
  9784. {
  9785. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9786. if (entity != null)
  9787. {
  9788. sql = new StringBuilder();
  9789. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9790. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9791. if (dth.Rows.Count > 0)
  9792. {
  9793. tisCtid += entity.ctid;
  9794. tisCtid += ",";
  9795. }
  9796. }
  9797. }
  9798. if (tisCtid.Length > 0)
  9799. {
  9800. var res = new
  9801. {
  9802. data = tisCtid
  9803. };
  9804. string ro_jsond = JsonConvert.SerializeObject(res);
  9805. returnSuccess(ro_jsond);
  9806. }
  9807. else
  9808. {
  9809. var res = new
  9810. {
  9811. data = ""
  9812. };
  9813. string ro_jsond = JsonConvert.SerializeObject(res);
  9814. returnSuccess(ro_jsond);
  9815. }
  9816. return;
  9817. }
  9818. returnErrorMsg("缺少必要的参数");
  9819. }
  9820. public void file_client_down_url()
  9821. {
  9822. if (!UrlPostParmsCheck("userId"))
  9823. {
  9824. returnErrorMsg("缺少必要的参数");
  9825. }
  9826. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9827. }
  9828. public void checkout_form_data()
  9829. {
  9830. if (!UrlPostParmsCheck("tid"))
  9831. {
  9832. returnErrorMsg("缺少必要的参数");
  9833. }
  9834. string tid = GetPostString("tid");
  9835. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9836. if (ceErpOrderFormData != null)
  9837. {
  9838. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9839. returnSuccess(ro_jsond);
  9840. return;
  9841. }
  9842. returnErrorMsg("尚未有文件!");
  9843. }
  9844. public void back_supplier_audit()
  9845. {
  9846. int userId = CurrentUser.UserID;
  9847. StringBuilder sql = new StringBuilder();
  9848. 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);
  9849. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9850. if (dt.Rows.Count > 0)
  9851. {
  9852. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9853. }
  9854. else
  9855. {
  9856. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9857. }
  9858. }
  9859. public void back_supplier_query()
  9860. {
  9861. string eid = GetPostString("ctid");
  9862. if (eid != "")
  9863. {
  9864. StringBuilder sql = new StringBuilder();
  9865. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9866. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9867. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9868. }
  9869. else
  9870. {
  9871. returnErrorMsg("找不到订单记录");
  9872. return;
  9873. }
  9874. }
  9875. public void verified_to_order()
  9876. {
  9877. int userId = CurrentUser.UserID;
  9878. StringBuilder sql = new StringBuilder();
  9879. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9880. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9881. if (dt.Rows.Count > 0)
  9882. {
  9883. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9884. }
  9885. else
  9886. {
  9887. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9888. }
  9889. }
  9890. public void upd_supplier_audit()
  9891. {
  9892. if (UrlPostParmsCheck("ctid"))
  9893. {
  9894. string eid = GetPostString("ctid");
  9895. string reason = GetPostString("returnreason");
  9896. CeErpTradeCell entity = null;
  9897. CeWithdraw withdraw = null;
  9898. withdraw = CeWithdraw.GetByTid(eid);
  9899. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9900. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9901. {
  9902. if (withdraw != null)
  9903. {
  9904. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9905. {
  9906. returnSuccessMsg("您没有权限操作!");
  9907. return;
  9908. }
  9909. else
  9910. {
  9911. if (reason.Equals("1"))
  9912. {
  9913. if (entity.OrderState == -1)
  9914. {
  9915. if (entity.FinishPlaceTime == null)
  9916. {
  9917. entity.OrderState = 2;
  9918. }
  9919. else
  9920. {
  9921. entity.OrderState = 6;
  9922. }
  9923. }
  9924. entity.Update();
  9925. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9926. if (withdraw != null)
  9927. {
  9928. withdraw.status = int.Parse(reason);
  9929. withdraw.Update();
  9930. }
  9931. returnSuccessMsg("操作成功!");
  9932. return;
  9933. }
  9934. else
  9935. {
  9936. withdraw.status = int.Parse(reason);
  9937. withdraw.acknowledgingtime = DateTime.Now;
  9938. withdraw.Update();
  9939. returnSuccessMsg("查看详细请点击线下订单查询");
  9940. return;
  9941. }
  9942. }
  9943. }
  9944. // 第一个字符是 'N'
  9945. }
  9946. if (eid[0] != 'N')
  9947. {
  9948. }
  9949. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9950. {
  9951. entity.IsVerifyToSupplier = false;
  9952. entity.IsReturn = 1;
  9953. entity.ReturnTime = DateTime.Now;
  9954. entity.ReturnReason = reason;
  9955. if (entity.OrderState == 6)
  9956. {
  9957. entity.OrderState = 5;
  9958. }
  9959. entity.Update();
  9960. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9961. if (withdraw != null)
  9962. {
  9963. withdraw.status = int.Parse(reason);
  9964. withdraw.Update();
  9965. }
  9966. returnSuccessMsg("操作成功!");
  9967. return;
  9968. }
  9969. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9970. {
  9971. ;
  9972. if (withdraw != null)
  9973. {
  9974. withdraw.status = int.Parse(reason);
  9975. withdraw.acknowledgingtime = DateTime.Now;
  9976. withdraw.Update();
  9977. returnSuccessMsg("供应商取消撤回!");
  9978. return;
  9979. }
  9980. }
  9981. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9982. {
  9983. if (entity.OrderState == -1)
  9984. {
  9985. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  9986. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9987. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  9988. {
  9989. returnErrorMsg("台湾客户需填写身份证!");
  9990. return;
  9991. }
  9992. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9993. {
  9994. returnErrorMsg("订单spu没有确认无法通过审核!");
  9995. return;
  9996. }
  9997. if (entity.FinishPlaceTime == null)
  9998. {
  9999. entity.OrderState = 2;
  10000. }
  10001. else
  10002. {
  10003. entity.OrderState = 3;
  10004. }
  10005. commonHelper.getCytPrice(entity);
  10006. }
  10007. entity.Update();
  10008. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10009. if (withdraw != null)
  10010. {
  10011. withdraw.status = int.Parse(reason);
  10012. withdraw.Update();
  10013. }
  10014. returnSuccessMsg("操作成功!");
  10015. return;
  10016. }
  10017. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10018. {
  10019. if (withdraw == null)
  10020. {
  10021. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10022. return;
  10023. }
  10024. }
  10025. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10026. {
  10027. if (withdraw != null)
  10028. {
  10029. withdraw.status = int.Parse(reason);
  10030. withdraw.acknowledgingtime = DateTime.Now;
  10031. withdraw.Update();
  10032. returnSuccessMsg("查看详细请点击线下订单查询");
  10033. return;
  10034. }
  10035. }
  10036. return;
  10037. }
  10038. }
  10039. //校验报价
  10040. public void refund_order_tip()
  10041. {
  10042. int userid = CurrentUser.UserID;
  10043. int sectionId = CurrentUser.UserPost.OrgID;
  10044. StringBuilder sql = new StringBuilder();
  10045. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10046. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10047. List<string> ids = new List<string>();
  10048. if (dth.Rows.Count > 0)
  10049. {
  10050. foreach (DataRow dr in dth.Rows)
  10051. {
  10052. ids.Add(dr["ID"].ToString());
  10053. }
  10054. try
  10055. {
  10056. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10057. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10058. }
  10059. catch (Exception ex)
  10060. {
  10061. }
  10062. }
  10063. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10064. }
  10065. public void refund_order_Design()
  10066. {
  10067. int userid = CurrentUser.UserID;
  10068. int sectionId = CurrentUser.UserPost.OrgID;
  10069. StringBuilder sql = new StringBuilder();
  10070. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10071. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10072. List<string> ids = new List<string>();
  10073. if (dth.Rows.Count > 0)
  10074. {
  10075. foreach (DataRow dr in dth.Rows)
  10076. {
  10077. ids.Add(dr["ID"].ToString());
  10078. }
  10079. try
  10080. {
  10081. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10082. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10083. }
  10084. catch (Exception ex)
  10085. {
  10086. }
  10087. }
  10088. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10089. }
  10090. public void change_order_info()
  10091. {
  10092. int userid = CurrentUser.UserID;
  10093. StringBuilder sql = new StringBuilder();
  10094. 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);
  10095. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10096. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10097. }
  10098. public void change_win_mome()
  10099. {
  10100. if (UrlPostParmsCheck("id,ctid"))
  10101. {
  10102. string id = GetPostString("id");
  10103. string ctid = GetPostString("ctid");
  10104. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10105. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10106. if (ce == null || ceErpMessageTip == null)
  10107. {
  10108. returnSuccessMsg("未找到对应的订单!");
  10109. return;
  10110. }
  10111. if (ce.OrderState >= 5)
  10112. {
  10113. ceErpMessageTip.isVisit = true;
  10114. ceErpMessageTip.Update();
  10115. returnSuccessMsg("已上传文件无法修改!");
  10116. return;
  10117. }
  10118. int type = GetPostInt("type");
  10119. string content = GetPostString("content");
  10120. if (type == 0)
  10121. {
  10122. content = content.Replace("(", "(");
  10123. content = content.Replace(")", ")");
  10124. string check = MidStrEx(content, "(", ")").Trim();
  10125. if (string.IsNullOrEmpty(check))
  10126. {
  10127. returnSuccessMsg("文件名格式不正确");
  10128. return;
  10129. }
  10130. }
  10131. ce.seller_memo = content;
  10132. ce.Update();
  10133. ceErpMessageTip.isVisit = true;
  10134. ceErpMessageTip.Update();
  10135. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10136. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10137. ApiVo apiVo = new ApiVo();
  10138. apiVo.orderNumber = ce.ctid;
  10139. apiVo.actionName = "demandDesign";
  10140. apiVo.orderRemarks = content;
  10141. apiVo.demandExamine = type + 1;
  10142. designHelper.API_WorkCore(apiVo);//demandDesign
  10143. returnSuccessMsg("修改成功!");
  10144. }
  10145. }
  10146. public static string MidStrEx(string sourse, string startstr, string endstr)
  10147. {
  10148. string result = string.Empty;
  10149. int startindex, endindex;
  10150. try
  10151. {
  10152. startindex = sourse.IndexOf(startstr);
  10153. if (startindex == -1)
  10154. return result;
  10155. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10156. endindex = tmpstr.IndexOf(endstr);
  10157. if (endindex == -1)
  10158. return result;
  10159. result = tmpstr.Remove(endindex);
  10160. }
  10161. catch (Exception ex)
  10162. {
  10163. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10164. }
  10165. return result;
  10166. }
  10167. public void refund_order_list()
  10168. {
  10169. int userid = CurrentUser.UserID;
  10170. int sectionId = CurrentUser.UserPost.OrgID;
  10171. StringBuilder sql = new StringBuilder();
  10172. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10173. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10174. DataStruct dStruct = GetPostStruct();
  10175. DataTable dt = null;
  10176. List<string> ids = new List<string>();
  10177. List<string> tids = new List<string>();
  10178. if (dth.Rows.Count > 0)
  10179. {
  10180. foreach (DataRow dr in dth.Rows)
  10181. {
  10182. tids.Add("'" + dr["tid"].ToString() + "'");
  10183. ids.Add(dr["id"].ToString());
  10184. }
  10185. try
  10186. {
  10187. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10188. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10189. List<string> lw = new List<string>();
  10190. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10191. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10192. dt = WebCache.GetData("view_orderlist", dStruct);
  10193. }
  10194. catch (Exception ex)
  10195. {
  10196. }
  10197. }
  10198. writeGridDataTableJson(dStruct.TotalCount, dt);
  10199. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10200. }
  10201. //新增
  10202. public void order_batch_downloads()
  10203. {
  10204. string ceid = GetPostString("tid");
  10205. String[] tid = ceid.Split(',');
  10206. order_batch_caiyingtong(tid);
  10207. /* (string success, string errors) = UploadFiles(tid);
  10208. returnSuccessMsg(success + errors);*/
  10209. return;
  10210. }
  10211. //报价接口
  10212. public void Get_To_Quote()
  10213. {
  10214. string ceid = GetPostString("ctid");
  10215. if (ceid != null)
  10216. {
  10217. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10218. if (entity != null)
  10219. {
  10220. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10221. {
  10222. return;
  10223. }
  10224. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10225. double price = 0;
  10226. if (cp == null)
  10227. {
  10228. JObject jsonObject12 = new JObject
  10229. {
  10230. { "UserId", "77886" },
  10231. { "Pwd", "lt666888" },
  10232. { "Filename", entity.seller_memo }
  10233. };
  10234. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10235. JObject jsonObjects1 = JObject.Parse(response1);
  10236. string ms1g = (string)jsonObjects1["msg"];
  10237. if (ms1g == "报价成功")
  10238. {
  10239. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10240. string data = (string)jsonObject1["price"];
  10241. 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 + "');";
  10242. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10243. returnSuccessMsg("获取报价成功:" + data);
  10244. price = Convert.ToDouble(data);
  10245. }
  10246. else
  10247. {
  10248. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10249. return;
  10250. }
  10251. }
  10252. String[] beizhu = entity.seller_memo.Split('-');
  10253. String chanp = "";
  10254. if (beizhu.Length > 0)
  10255. {
  10256. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10257. }
  10258. else
  10259. {
  10260. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10261. }
  10262. JObject jsonObject = new JObject
  10263. {
  10264. { "UserId", "77886" },
  10265. { "Pwd", "lt666888" },
  10266. { "Filename", chanp }
  10267. };
  10268. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10269. JObject jsonObjects = JObject.Parse(response);
  10270. string msg = (string)jsonObjects["msg"];
  10271. if (msg == "报价成功")
  10272. {
  10273. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10274. string data = (string)jsonObject1["price"];
  10275. 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 + "');";
  10276. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10277. returnSuccessMsg("获取报价成功:" + data);
  10278. price = Convert.ToDouble(data);
  10279. }
  10280. else
  10281. {
  10282. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10283. return;
  10284. }
  10285. if (price > 0)
  10286. {
  10287. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10288. if (ceErpTradeCellExtend == null)
  10289. {
  10290. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10291. ceErpTradeCellExtend.ctid = entity.ctid;
  10292. ceErpTradeCellExtend.payment_cyt = price;
  10293. ceErpTradeCellExtend.Create();
  10294. }
  10295. else
  10296. {
  10297. ceErpTradeCellExtend.payment_cyt = price;
  10298. ceErpTradeCellExtend.Update();
  10299. }
  10300. }
  10301. return;
  10302. }
  10303. }
  10304. else
  10305. {
  10306. returnErrorMsg("请至少选择一条数据");
  10307. return;
  10308. }
  10309. }
  10310. //新增
  10311. public void order_To_Supplier()
  10312. {
  10313. string ceid = GetPostString("tid");
  10314. String[] tid = ceid.Split(',');
  10315. if (tid.Length > 0)
  10316. {
  10317. try
  10318. {
  10319. for (int i = 0; i < tid.Length; i++)
  10320. {
  10321. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10322. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10323. entity.SupplierId = suid;
  10324. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10325. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10326. entity.Update();
  10327. }
  10328. }
  10329. catch (Exception ex)
  10330. {
  10331. returnErrorMsg("自动匹配供应商失败");
  10332. return;
  10333. }
  10334. }
  10335. else
  10336. {
  10337. returnErrorMsg("请至少选择一条数据");
  10338. return;
  10339. }
  10340. returnSuccessMsg("自动匹配供应商成功");
  10341. return;
  10342. }
  10343. public (string, string) UploadFiles(string[] urls)
  10344. {
  10345. string success = "";
  10346. string errors = "";
  10347. int userid = CurrentUser.UserID;
  10348. foreach (string url in urls)
  10349. {
  10350. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10351. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10352. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10353. {
  10354. JObject jsonObject = new JObject
  10355. {
  10356. { "Userid", "77886" },
  10357. { "pwd", "cyt86435015" },
  10358. { "content", base64FileContent },
  10359. { "ext", Path.GetExtension(fileName) }
  10360. };
  10361. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10362. JObject jsonObjects = JObject.Parse(response);
  10363. string msg = (string)jsonObjects["msg"];
  10364. if (msg.Equals("上传成功"))
  10365. {
  10366. success += url + " 上传成功";
  10367. }
  10368. else
  10369. {
  10370. errors += url + " 上传失败";
  10371. }
  10372. }
  10373. else
  10374. {
  10375. errors += url + " 格式出现问题";
  10376. }
  10377. }
  10378. if (urls.Length == 0)
  10379. {
  10380. return (success, errors);
  10381. }
  10382. return (success, errors);
  10383. }
  10384. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10385. {
  10386. return true; //总是接受
  10387. }
  10388. public static string HttpPost(string url, string param = null)
  10389. {
  10390. HttpWebRequest request;
  10391. //如果是发送HTTPS请求
  10392. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10393. {
  10394. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10395. request = WebRequest.Create(url) as HttpWebRequest;
  10396. request.ProtocolVersion = HttpVersion.Version10;
  10397. }
  10398. else
  10399. {
  10400. request = WebRequest.Create(url) as HttpWebRequest;
  10401. }
  10402. request.Method = "POST";
  10403. request.ContentType = "application/json";
  10404. request.Accept = "*/*";
  10405. request.Timeout = 120000;
  10406. request.AllowAutoRedirect = false;
  10407. StreamWriter requestStream = null;
  10408. WebResponse response = null;
  10409. string responseStr = null;
  10410. try
  10411. {
  10412. requestStream = new StreamWriter(request.GetRequestStream());
  10413. requestStream.Write(param);
  10414. requestStream.Close();
  10415. response = request.GetResponse();
  10416. if (response != null)
  10417. {
  10418. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10419. responseStr = reader.ReadToEnd();
  10420. reader.Close();
  10421. }
  10422. }
  10423. catch (Exception ex)
  10424. {
  10425. return ex.Message;
  10426. }
  10427. finally
  10428. {
  10429. request = null;
  10430. requestStream = null;
  10431. response = null;
  10432. }
  10433. return responseStr;
  10434. }
  10435. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10436. {
  10437. string base64FileContent;
  10438. string fileName;
  10439. using (WebClient webClient = new WebClient())
  10440. {
  10441. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10442. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10443. {
  10444. using (Stream stream = response.GetResponseStream())
  10445. {
  10446. using (MemoryStream memoryStream = new MemoryStream())
  10447. {
  10448. stream.CopyTo(memoryStream);
  10449. byte[] fileBytes = memoryStream.ToArray();
  10450. base64FileContent = Convert.ToBase64String(fileBytes);
  10451. fileName = response.Headers["Content-Disposition"];
  10452. if (!string.IsNullOrEmpty(fileName))
  10453. {
  10454. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10455. if (index >= 0)
  10456. {
  10457. fileName = fileName.Substring(index + 9).Trim('\"');
  10458. }
  10459. }
  10460. else
  10461. {
  10462. fileName = Path.GetFileName(downloadUrl);
  10463. }
  10464. }
  10465. }
  10466. }
  10467. }
  10468. return (fileName, base64FileContent);
  10469. }
  10470. //新增
  10471. public void order_batch_caiyingtong(string[] downloadUrls)
  10472. {
  10473. try
  10474. {
  10475. //遍历文件
  10476. DataStruct dStruct = GetPostStruct();
  10477. DataTable dt = null;
  10478. int userid = CurrentUser.UserID;
  10479. List<string> ids = new List<string>();//失败组
  10480. List<string> tids = new List<string>();
  10481. using (WebClient webClient = new WebClient())
  10482. {
  10483. foreach (var url in downloadUrls)
  10484. {
  10485. try
  10486. {
  10487. tids.Add("'" + url + "'");
  10488. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10489. if (entity != null)
  10490. {
  10491. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10492. if (cp == null)
  10493. {
  10494. JObject jsonObject = new JObject
  10495. {
  10496. { "Userid", "77886" },
  10497. { "pwd", "lt666888" },
  10498. { "Filename",entity.seller_memo }
  10499. };
  10500. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10501. JObject jsonObjects = JObject.Parse(response);
  10502. string msg = (string)jsonObjects["msg"];
  10503. if (msg == "报价成功")
  10504. {
  10505. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10506. DownloadAndConvertToBase64(url1);
  10507. }
  10508. else
  10509. {
  10510. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10511. }
  10512. }
  10513. else
  10514. {
  10515. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10516. JObject jsonObject = new JObject
  10517. {
  10518. { "Userid", "77886" },
  10519. { "pwd", "lt666888" },
  10520. { "Filename",chanp }
  10521. };
  10522. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10523. JObject jsonObjects = JObject.Parse(response);
  10524. string msg = (string)jsonObjects["msg"];
  10525. if (msg == "报价成功")
  10526. {
  10527. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10528. DownloadAndConvertToBase64(url1);
  10529. }
  10530. else
  10531. {
  10532. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10533. }
  10534. }
  10535. }
  10536. // 上传文件到FTP
  10537. }
  10538. catch (Exception ex)
  10539. {
  10540. Console.WriteLine($"An error occurred: {ex.Message}");
  10541. }
  10542. }
  10543. List<string> lw = new List<string>();
  10544. lw.Add(string.Format("( OrderState < 6 )"));
  10545. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10546. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10547. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10548. if (dt.Rows.Count > 0)
  10549. {
  10550. foreach (DataRow dr in dt.Rows)
  10551. {
  10552. ids.Add(dr["ctid"].ToString());
  10553. }
  10554. }
  10555. String ErrorMsgs = "";
  10556. foreach (String id in ids)
  10557. {
  10558. ErrorMsgs += id + ",";
  10559. }
  10560. if (ErrorMsgs.Length > 1)
  10561. {
  10562. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10563. }
  10564. if (ErrorMsgs.Length < 1)
  10565. {
  10566. ErrorMsgs = "上传成功";
  10567. returnSuccessMsg(ErrorMsgs);
  10568. }
  10569. else
  10570. {
  10571. returnErrorMsg("以下订单" + ErrorMsgs);
  10572. }
  10573. }
  10574. // 删除文件夹及其内容
  10575. /* Directory.Delete(localDirectory, true);*/
  10576. }
  10577. catch { }
  10578. }
  10579. public void get_center_data()
  10580. {
  10581. int userId = CurrentUser.UserID;
  10582. string postCode = CurrentUser.UserPost.Post.Code;
  10583. List<string> lw = new List<string>();
  10584. List<string> ww = new List<string>();
  10585. DateTime currentTime = DateTime.Now;
  10586. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10587. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10588. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10589. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10590. string sql = " SELECT ";
  10591. string startTime = "2023-10-01 11:22:31";
  10592. //设计
  10593. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10594. {
  10595. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10596. ww.Add(string.Format("( SELECT COUNT ( * ) AS designCount FROM CE_ErpTradeCell WHERE pay_time < '{2}' AND OrderState < 5 AND IsReturn = 0 AND pay_time > '{0}' AND DesignUserId = {1} ) AS dc", startTime, userId, payTime));
  10597. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10598. 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));
  10599. }
  10600. //客服
  10601. else if (postCode == "CustomerService" || postCode == "Director")
  10602. {
  10603. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10604. 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));
  10605. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10606. 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));
  10607. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10608. 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));
  10609. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10610. 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));
  10611. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10612. ww.Add(string.Format("( SELECT COUNT ( * ) AS refundCount FROM CE_ErpTradeCell WHERE IsRefund > 0 AND OrderState NOT IN ( 8, 9 ) AND pay_time > '{0}' AND CustomerUserId = {1} ) AS rc", startTime, userId));
  10613. }
  10614. //售后
  10615. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10616. {
  10617. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10618. 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));
  10619. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10620. 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));
  10621. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10622. 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));
  10623. }
  10624. //下单部
  10625. else if (postCode == "Place" || postCode == "PlaceMr")
  10626. {
  10627. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10628. 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));
  10629. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10630. 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));
  10631. }
  10632. //车间
  10633. else if (postCode == "Supplier")
  10634. {
  10635. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10636. 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));
  10637. }
  10638. DataTable dt = new DataTable();
  10639. if (lw.Count > 0)
  10640. {
  10641. sql += string.Join(" , ", lw);
  10642. sql += " FROM ";
  10643. sql += string.Join(" , ", ww);
  10644. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10645. }
  10646. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10647. }
  10648. public void get_center_data_list()
  10649. {
  10650. int userId = CurrentUser.UserID;
  10651. string postCode = CurrentUser.UserPost.Post.Code;
  10652. string shopIds = CurrentUser.User.pemShop;
  10653. DataStruct dStruct = GetPostStruct();
  10654. List<string> lw = new List<string>();
  10655. DateTime currentTime = DateTime.Now;
  10656. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10657. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10658. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10659. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10660. string startTime = "2023-10-01 11:22:31";
  10661. int order_type = GetPostInt("order_type");
  10662. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10663. {
  10664. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10665. if (order_type == 0)
  10666. {
  10667. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10668. }
  10669. else if (order_type == 3)
  10670. {
  10671. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10672. }
  10673. else
  10674. {
  10675. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10676. }
  10677. }
  10678. //客服
  10679. if (postCode == "CustomerService" || postCode == "Director")
  10680. {
  10681. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10682. if (order_type == 0)
  10683. {
  10684. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10685. }
  10686. else if (order_type == 1)
  10687. {
  10688. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10689. }
  10690. else if (order_type == 2)
  10691. {
  10692. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10693. }
  10694. else if (order_type == 3)
  10695. {
  10696. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10697. }
  10698. else if (order_type == 4)
  10699. {
  10700. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10701. }
  10702. else
  10703. {
  10704. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10705. }
  10706. }
  10707. //售后
  10708. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10709. {
  10710. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10711. if (shopIds != "")
  10712. {
  10713. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10714. }
  10715. if (order_type == 2)
  10716. {
  10717. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10718. }
  10719. else if (order_type == 4)
  10720. {
  10721. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10722. }
  10723. else if (order_type == 5)
  10724. {
  10725. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10726. }
  10727. else
  10728. {
  10729. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10730. }
  10731. }
  10732. //下单部
  10733. if (postCode == "Place" || postCode == "PlaceMr")
  10734. {
  10735. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10736. if (shopIds != "")
  10737. {
  10738. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10739. }
  10740. else if (order_type == 1)
  10741. {
  10742. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10743. }
  10744. else if (order_type == 2)
  10745. {
  10746. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10747. }
  10748. else
  10749. {
  10750. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10751. }
  10752. }
  10753. //车间
  10754. if (postCode == "Supplier")
  10755. {
  10756. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10757. if (order_type == 5)
  10758. {
  10759. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10760. }
  10761. else
  10762. {
  10763. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10764. }
  10765. }
  10766. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10767. dStruct.Fileds = "tid,ctid";
  10768. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10769. writeGridDataTableJson(dStruct.TotalCount, dt);
  10770. }
  10771. public void aftersale_audit_master()
  10772. {
  10773. if (UrlPostParmsCheck("ctid"))
  10774. {
  10775. string ctid = GetPostString("ctid");
  10776. if (ctid.Length > 0)
  10777. {
  10778. bool result = aftersale_data_change(ctid);
  10779. if (result)
  10780. {
  10781. returnSuccessMsg("修改成功!");
  10782. return;
  10783. }
  10784. }
  10785. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10786. }
  10787. }
  10788. public void aftersale_batch_audit_master()
  10789. {
  10790. if (UrlPostParmsCheck("ctids"))
  10791. {
  10792. string ctids = GetPostString("ctids");
  10793. if (ctids.Length > 0)
  10794. {
  10795. List<string> list = new List<string>();
  10796. string[] ctid_list = ctids.Split(',');
  10797. foreach (var item in ctid_list)
  10798. {
  10799. bool result = aftersale_data_change(item);
  10800. if (!result)
  10801. {
  10802. list.Add(item);
  10803. }
  10804. }
  10805. if (list.Count > 0)
  10806. {
  10807. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10808. return;
  10809. }
  10810. returnSuccessMsg("修改成功!");
  10811. return;
  10812. }
  10813. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10814. }
  10815. }
  10816. public bool aftersale_data_change(string ctid)
  10817. {
  10818. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10819. if (ceErpTradeCell != null)
  10820. {
  10821. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10822. ceErpTradeCell.AfterSaleSupplierState = 0;
  10823. StringBuilder sql = new StringBuilder();
  10824. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10825. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10826. CeErpTradeResponsible.DelByTid(ctid, 0);
  10827. 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 == "不理赔")
  10828. {
  10829. CeErpTradeResponsible.DelByTid(ctid, 1);
  10830. ceErpTradeCell.AfterSaleSupplierState = 1;
  10831. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10832. ceErpTradeCell.AfterSaleState = 4;
  10833. }
  10834. else
  10835. {
  10836. ceErpTradeCell.AfterSaleState = 3;
  10837. }
  10838. bool needCyt = false;
  10839. if (dt != null)
  10840. {
  10841. if (dt.Rows.Count == 1)
  10842. {
  10843. bool isEnd = false;
  10844. foreach (DataRow dr in dt.Rows)
  10845. {
  10846. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10847. {
  10848. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10849. isEnd = true;
  10850. }
  10851. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10852. {
  10853. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10854. isEnd = true;
  10855. }
  10856. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10857. {
  10858. needCyt = true;
  10859. }
  10860. }
  10861. if (isEnd)
  10862. {
  10863. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10864. ceErpTradeCell.AfterSaleState = 4;
  10865. ceErpTradeCell.AfterSaleSupplierState = 1;
  10866. }
  10867. }
  10868. else
  10869. {
  10870. bool isAll = true;
  10871. foreach (DataRow dr in dt.Rows)
  10872. {
  10873. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10874. {
  10875. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10876. continue;
  10877. }
  10878. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10879. {
  10880. string path = "";
  10881. int OrgID = 0;
  10882. if (!Convert.IsDBNull(dr["OrgPath"]))
  10883. {
  10884. path = dr["OrgPath"].ToString();
  10885. }
  10886. if (!Convert.IsDBNull(dr["OrgID"]))
  10887. {
  10888. OrgID = Convert.ToInt32(dr["OrgID"]);
  10889. }
  10890. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10891. {
  10892. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10893. continue;
  10894. }
  10895. }
  10896. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10897. {
  10898. needCyt = true;
  10899. }
  10900. isAll = false;
  10901. }
  10902. if (isAll)
  10903. {
  10904. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10905. ceErpTradeCell.AfterSaleState = 4;
  10906. ceErpTradeCell.AfterSaleSupplierState = 1;
  10907. }
  10908. }
  10909. }
  10910. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10911. {
  10912. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10913. }
  10914. if (ceErpTradeCell.AfterSaleState == 4)
  10915. {
  10916. ApiVo apiVo = new ApiVo();
  10917. apiVo.orderNumber = ceErpTradeCell.ctid;
  10918. apiVo.actionName = "afterOver";
  10919. designHelper.API_WorkCore(apiVo); //afterOver
  10920. }
  10921. ceErpTradeCell.Update();
  10922. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10923. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10924. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10925. return true;
  10926. }
  10927. return false;
  10928. }
  10929. public void get_erp_wechatorder()
  10930. {
  10931. DataStruct dStruct = GetPostStruct();
  10932. List<string> lw = new List<string>();
  10933. string tid = GetPostString("tid");
  10934. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10935. string shopname = GetPostString("shopname");
  10936. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10937. string buyernick = GetPostString("buyer_nick");
  10938. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10939. string customer = GetPostString("customer");
  10940. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10941. string returndate1 = GetPostString("returndate1");
  10942. string returndate2 = GetPostString("returndate2");
  10943. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10944. if (dw.Length > 0) lw.Add(dw);
  10945. string finishDate1 = GetPostString("finishdate1");
  10946. string finishDate2 = GetPostString("finishdate2");
  10947. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10948. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10949. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10950. dStruct.Order = "created desc";
  10951. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10952. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10953. writeGridDataTableJson(dStruct.TotalCount, dt);
  10954. }
  10955. public void get_erp_wechatlist_sumprice()
  10956. {
  10957. DataStruct dStruct = GetPostStruct();
  10958. List<string> lw = new List<string>();
  10959. string tid = GetPostString("tid");
  10960. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10961. string shopname = GetPostString("shopname");
  10962. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10963. string buyernick = GetPostString("buyer_nick");
  10964. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10965. string customer = GetPostString("customer");
  10966. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10967. string returndate1 = GetPostString("returndate1");
  10968. string returndate2 = GetPostString("returndate2");
  10969. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10970. if (dw.Length > 0) lw.Add(dw);
  10971. string finishDate1 = GetPostString("finishdate1");
  10972. string finishDate2 = GetPostString("finishdate2");
  10973. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10974. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10975. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10976. string mainWhere = string.Join(" and ", lw.ToArray());
  10977. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10978. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10979. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10980. decimal total = 0;
  10981. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10982. {
  10983. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10984. }
  10985. var res = new
  10986. {
  10987. data = total
  10988. };
  10989. string ro_jsond = JsonConvert.SerializeObject(res);
  10990. returnSuccess(ro_jsond);
  10991. return;
  10992. }
  10993. public void get_erp_qr_waitdeliverylist()
  10994. {
  10995. DataStruct dStruct = GetPostStruct();
  10996. List<string> lw = new List<string>();
  10997. string tid = GetPostString("ctid");
  10998. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10999. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11000. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11001. var res_objz = new
  11002. {
  11003. restype = 1,
  11004. data = dt
  11005. };
  11006. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11007. returnSuccess(ro_jsonz);
  11008. }
  11009. public void get_erp_yield_list()
  11010. {
  11011. DataStruct dStruct = GetPostStruct();
  11012. List<string> lw = new List<string>();
  11013. string tid = GetPostString("ctid");
  11014. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11015. string shopname = GetPostString("shopname");
  11016. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11017. string buyernick = GetPostString("buyer_nick");
  11018. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11019. //if (tid.Length == 0 && buyernick.Length == 0)
  11020. //{
  11021. // lw.Add(string.Format("IsRefund<={0}", 1));
  11022. //}
  11023. string customer = GetPostString("customer");
  11024. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11025. string design = GetPostString("design");
  11026. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11027. string orderState = GetPostString("orderState");
  11028. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11029. string address = GetPostString("address");
  11030. 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));
  11031. string sellermemo = GetPostString("seller_memo");
  11032. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11033. string supplier = GetPostString("supplier");
  11034. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11035. string OrderArea = GetPostString("order_area");
  11036. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11037. string placedate1 = GetPostString("placedate1");
  11038. string placedate2 = GetPostString("placedate2");
  11039. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11040. if (fdw.Length > 0) lw.Add(fdw);
  11041. string price1 = GetPostString("price1");
  11042. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11043. string price2 = GetPostString("price2");
  11044. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11045. string unusualCon = GetPostString("unusualcon");
  11046. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11047. string posTag = CurrentUser.UserPost.Post.Code;
  11048. if (posTag == "Supplier")
  11049. {
  11050. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11051. }
  11052. lw.Add(string.Format("OrderState = 6 "));
  11053. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11054. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11055. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11056. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11057. writeGridDataTableJson(dStruct.TotalCount, dt);
  11058. }
  11059. public void change_erp_sup_state()
  11060. {
  11061. if (UrlPostParmsCheck("ctid"))
  11062. {
  11063. string ctid = GetPostString("ctid");
  11064. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11065. if (ceErpTradeCell != null)
  11066. {
  11067. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11068. if (ceErpTradeCellExtend == null)
  11069. {
  11070. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11071. ceErpTradeCellExtend.ctid = ctid;
  11072. ceErpTradeCellExtend.SupState = 1;
  11073. ceErpTradeCellExtend.Create();
  11074. }
  11075. else
  11076. {
  11077. ceErpTradeCellExtend.SupState = 1;
  11078. ceErpTradeCellExtend.Update();
  11079. }
  11080. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11081. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11082. return;
  11083. }
  11084. returnErrorMsg("找不到订单");
  11085. }
  11086. }
  11087. public void supplier_all_downs()
  11088. {
  11089. if (UrlPostParmsCheck("tids"))
  11090. {
  11091. string tids = GetPostString("tids");
  11092. if (tids != null && tids.Length > 0)
  11093. {
  11094. StringBuilder sql = new StringBuilder();
  11095. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11096. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11097. sql = new StringBuilder();
  11098. 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, "下载设计文件");
  11099. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11100. string[] list = tids.Split(',');
  11101. foreach (string ctid in list)
  11102. {
  11103. CeErpSukuraData.createInfo(ctid, 3);
  11104. }
  11105. designHelper.api_approveDesign(tids); //approveDesign
  11106. returnSuccessMsg("下载成功!");
  11107. return;
  11108. }
  11109. returnErrorMsg("下载订单更新失败");
  11110. }
  11111. }
  11112. public void uploaderFileSuccess()
  11113. {
  11114. if (UrlPostParmsCheck("fileName"))
  11115. {
  11116. string fileName = GetPostString("fileName");
  11117. ApiVo apiVo = new ApiVo();
  11118. apiVo.orderNumber = fileName;
  11119. apiVo.actionName = "finishDesign";
  11120. designHelper.API_WorkCore(apiVo);//finishDesign
  11121. returnSuccessMsg("");
  11122. }
  11123. }
  11124. public void get_sample2_order()
  11125. {
  11126. if (UrlPostParmsCheck("ctid"))
  11127. {
  11128. string ctid = GetPostString("ctid");
  11129. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11130. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11131. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11132. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11133. double total = 0.0;
  11134. double order_price = 0.0;
  11135. if (dt_bu.Rows.Count > 0)
  11136. {
  11137. foreach (DataRow dr in dt_bu.Rows)
  11138. {
  11139. total += Convert.ToDouble(dr["payment"]);
  11140. }
  11141. }
  11142. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11143. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11144. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11145. string tid = ctid.Replace("S_", "");
  11146. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11147. double paymant = 0.0;
  11148. if (entity != null)
  11149. {
  11150. paymant = entity.payment;
  11151. }
  11152. string return_reason = "";
  11153. if (dt_after != null && dt_after.Rows.Count > 0)
  11154. {
  11155. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11156. }
  11157. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11158. }
  11159. }
  11160. public void get_erp_design_status()
  11161. {
  11162. string designName = GetPostString("designName");
  11163. DataStruct dStruct = GetPostStruct();
  11164. if (designName.Length > 0)
  11165. {
  11166. 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";
  11167. sql_user += " and Name like '%" + designName + "%'";
  11168. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11169. List<string> ids_list = new List<string>();
  11170. if (user_table.Rows.Count > 0)
  11171. {
  11172. foreach (DataRow item in user_table.Rows)
  11173. {
  11174. ids_list.Add(item["id"].ToString());
  11175. string ids_s = item["TeamIds"].ToString();
  11176. if (ids_s.Length > 0)
  11177. {
  11178. ids_list.AddRange(ids_s.Split(','));
  11179. }
  11180. }
  11181. }
  11182. HashSet<string> set = new HashSet<string>(ids_list);
  11183. ids_list = set.ToList();
  11184. if (ids_list.Count > 0)
  11185. {
  11186. 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));
  11187. dStruct.MainWhere = sql;
  11188. DataTable dt = null;
  11189. dt = WebCache.GetData("view_ErpUser", dStruct);
  11190. writeGridDataTableJson(dStruct.TotalCount, dt);
  11191. }
  11192. }
  11193. }
  11194. public void change_erp_order_price()
  11195. {
  11196. string ctid = GetPostString("ctid");
  11197. double price = GetPostDouble("price");
  11198. if (ctid.Length > 0)
  11199. {
  11200. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11201. if (ceErpTradeCellExtend == null)
  11202. {
  11203. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11204. ceErpTradeCellExtend.ctid = ctid;
  11205. ceErpTradeCellExtend.payment_cyt = price;
  11206. ceErpTradeCellExtend.Create();
  11207. }
  11208. else
  11209. {
  11210. ceErpTradeCellExtend.payment_cyt = price;
  11211. ceErpTradeCellExtend.Update();
  11212. }
  11213. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11214. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11215. {
  11216. ceErpDataSendOrderInfo.isSync = false;
  11217. ceErpDataSendOrderInfo.Update();
  11218. }
  11219. if (ceErpDataSendOrderInfo == null)
  11220. {
  11221. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11222. ceErpDataSendOrderInfo.isSync = false;
  11223. ceErpDataSendOrderInfo.ctid = ctid;
  11224. ceErpDataSendOrderInfo.Create();
  11225. }
  11226. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11227. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11228. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11229. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11230. {
  11231. dataSendOrderBean dataSendOrderBean = null;
  11232. foreach (DataRow item in dth.Rows)
  11233. {
  11234. try
  11235. {
  11236. dataSendOrderBean = new dataSendOrderBean();
  11237. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11238. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11239. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11240. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11241. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11242. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11243. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11244. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11245. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11246. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11247. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11248. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11249. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11250. if (result != null)
  11251. {
  11252. if ("0".Equals(result.errcode))
  11253. {
  11254. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11255. }
  11256. else
  11257. {
  11258. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11259. }
  11260. }
  11261. }
  11262. catch (Exception ex)
  11263. {
  11264. }
  11265. }
  11266. }
  11267. returnSuccessMsg("修改成功!");
  11268. return;
  11269. }
  11270. returnErrorMsg("找不到订单");
  11271. }
  11272. public void find_he_together()
  11273. {
  11274. string ctid = GetPostString("ctid");
  11275. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11276. List<string> list = new List<string>();
  11277. if (ceErpTradeCell != null)
  11278. {
  11279. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11280. {
  11281. 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);
  11282. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11283. if (table != null && table.Rows.Count > 0)
  11284. {
  11285. foreach (TableRow row in table.Rows)
  11286. {
  11287. }
  11288. }
  11289. }
  11290. }
  11291. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11292. }
  11293. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11294. {
  11295. //chy----19
  11296. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11297. //GD-CYT-----64
  11298. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11299. //ZHX----3
  11300. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11301. //JK----97
  11302. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11303. //ZT----70
  11304. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11305. //LHCY-----98
  11306. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11307. //XD-----90
  11308. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11309. //CYCY-----14
  11310. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11311. };
  11312. //其他改名
  11313. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11314. {
  11315. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11316. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11317. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11318. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11319. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11320. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11321. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11322. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11323. };
  11324. //不统计
  11325. List<int> no_suppliers = new List<int>()
  11326. {
  11327. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11328. };
  11329. //配件单
  11330. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11331. {
  11332. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11333. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11334. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11335. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11336. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11337. {"旗杆",new List<string>(){ "班旗" } },
  11338. {"牙签",new List<string>(){ "不干胶" } }
  11339. };
  11340. public void get_place_order_data()
  11341. {
  11342. string date1 = GetPostString("date1");
  11343. string date2 = GetPostString("date2");
  11344. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11345. DateTime start = DateTime.Parse(starttime);
  11346. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11347. DateTime end = DateTime.Parse(endtime);
  11348. if (date1 != null && date1.Length > 0)
  11349. {
  11350. DateTime dateTime = DateTime.Parse(date1);
  11351. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11352. start = DateTime.Parse(starttime);
  11353. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11354. end = DateTime.Parse(endtime);
  11355. }
  11356. if (date2 != null && date2.Length > 0)
  11357. {
  11358. DateTime dateTime = DateTime.Parse(date2);
  11359. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11360. end = DateTime.Parse(endtime);
  11361. }
  11362. 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);
  11363. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11364. //不干胶-----1,卡片-----29
  11365. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11366. foreach (DataRow row in data.Rows)
  11367. {
  11368. int productId = Convert.ToInt32(row["ProductId"]);
  11369. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11370. if (no_suppliers.Contains(supplierId))
  11371. {
  11372. continue;
  11373. }
  11374. string seller_memo = row["seller_memo"].ToString();
  11375. bool ispj = false;//是否配件单
  11376. bool isfirst = true;//第一个配
  11377. maps.Keys.ForEach(key =>
  11378. {
  11379. //备注包含配件
  11380. if (seller_memo.Contains(key) && isfirst)
  11381. {
  11382. List<string> list = maps[key];
  11383. ispj = true;
  11384. isfirst = false;
  11385. for (int i = 0; i < list.Count; i++)
  11386. {
  11387. if (seller_memo.Contains(list[i]))
  11388. {
  11389. ispj = false;
  11390. break;
  11391. }
  11392. }
  11393. }
  11394. });
  11395. if (ispj)
  11396. {
  11397. continue;
  11398. }
  11399. seller_memo = seller_memo.Replace("UV", "uv");
  11400. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11401. //吊牌归到卡片
  11402. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11403. seller_memo = seller_memo.Replace("卡套", "卡片");
  11404. seller_memo = seller_memo.Replace("封套", "卡片");
  11405. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11406. seller_memo = seller_memo.Replace("腰封", "卡片");
  11407. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11408. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11409. seller_memo = seller_memo.Replace("横幅", "条幅");
  11410. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11411. string map_key = "";
  11412. string type = "";
  11413. if (supplierMap.ContainsKey(supplierId))
  11414. {
  11415. foreach (var kvp in supplierMap[supplierId])
  11416. {
  11417. if (seller_memo.Contains(kvp.Key))
  11418. {
  11419. map_key = kvp.Value;
  11420. type = kvp.Value;
  11421. break;
  11422. }
  11423. }
  11424. }
  11425. if (map_key == "")
  11426. {
  11427. type = "其他";
  11428. map_key = "其他";
  11429. }
  11430. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11431. {
  11432. map_key = suppliers[supplierId];
  11433. }
  11434. if (supplierId == 70)
  11435. {
  11436. supplierId = 70;
  11437. }
  11438. map_key += "_" + row["SupplierName"].ToString();
  11439. Dictionary<string, int> map = null;
  11440. if (other_map.ContainsKey(map_key))
  11441. {
  11442. other_map.TryGetValue(map_key, out map);
  11443. }
  11444. else
  11445. {
  11446. map = new Dictionary<string, int>();
  11447. map.Add("dayDev", 0);//当天出货
  11448. map.Add("dayTotal", 0);//下单总数
  11449. map.Add("payTotal", 0);//500以上
  11450. map.Add("today", 0);//当天出货数量
  11451. map.Add("unusua", 0);//异常数
  11452. other_map.Add(map_key, map);
  11453. other_map.TryGetValue(map_key, out map);
  11454. }
  11455. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11456. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11457. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11458. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11459. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11460. {
  11461. map["dayTotal"]++;
  11462. if (supplierId == 97)
  11463. {
  11464. supplierId = 97;
  11465. }
  11466. }
  11467. if (Convert.ToDecimal(row["payment"]) >= 500)
  11468. {
  11469. map["payTotal"]++;
  11470. }
  11471. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11472. {
  11473. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11474. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11475. {
  11476. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11477. {
  11478. map["today"]++;
  11479. }
  11480. }
  11481. else
  11482. {
  11483. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11484. {
  11485. map["today"]++;
  11486. }
  11487. else
  11488. {
  11489. if (supplierId == 119)
  11490. {
  11491. Debug.WriteLine(row["seller_memo"].ToString());
  11492. }
  11493. }
  11494. }
  11495. }
  11496. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11497. {
  11498. map["unusua"]++;
  11499. }
  11500. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11501. //GD-CYT-----64
  11502. DateTime two = palceTimeStart.AddHours(14);
  11503. DateTime three = palceTimeStart.AddHours(15);
  11504. DateTime four = palceTimeStart.AddHours(16);
  11505. DateTime six = palceTimeStart.AddHours(18);
  11506. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11507. {
  11508. //下午四点前 500-1000
  11509. string count = row["ProductCount"].ToString();
  11510. if (count != null && count.Length > 0)
  11511. {
  11512. int productCount = commonHelper.getPlaceProductCount(count);
  11513. if (productCount >= 500 && productCount <= 1000)
  11514. {
  11515. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11516. {
  11517. map["dayDev"]++;
  11518. }
  11519. }
  11520. }
  11521. }
  11522. //UV
  11523. else if ("uv".Equals(type))
  11524. {
  11525. //ZT----70
  11526. //ZHX----3
  11527. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11528. {
  11529. map["dayDev"]++;
  11530. }
  11531. //JK----97
  11532. //HZX----105
  11533. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11534. {
  11535. map["dayDev"]++;
  11536. }
  11537. }
  11538. //帆布---52|条幅---27
  11539. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11540. {
  11541. //LHCY-----98
  11542. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11543. {
  11544. map["dayDev"]++;
  11545. }
  11546. }
  11547. //条幅
  11548. else if ("条幅".Equals(type))
  11549. {
  11550. //XD-----90
  11551. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11552. {
  11553. map["dayDev"]++;
  11554. }
  11555. }
  11556. //桌布
  11557. else if ("桌布".Equals(type))
  11558. {
  11559. //XD-----90
  11560. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11561. {
  11562. map["dayDev"]++;
  11563. }
  11564. }
  11565. //DL---10
  11566. //AYTW---119
  11567. //FS-CYT-DY ----80
  11568. //JK----97
  11569. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11570. {
  11571. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11572. {
  11573. map["dayDev"]++;
  11574. }
  11575. }
  11576. // QC---121
  11577. else if (supplierId == 121)
  11578. {
  11579. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11580. {
  11581. map["dayDev"]++;
  11582. }
  11583. }
  11584. }
  11585. DataTable dt = new DataTable();
  11586. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11587. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11588. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11589. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11590. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11591. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11592. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11593. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11594. other_map.Keys.ForEach(key =>
  11595. {
  11596. DataRow dr = dt.NewRow();
  11597. Dictionary<string, int> map = other_map[key];
  11598. string[] key_list = key.Split('_');
  11599. dr[0] = key_list[0];
  11600. dr[1] = key_list[1];
  11601. if (key_list.Length > 2)
  11602. {
  11603. dr[1] += "(" + key_list[2] + ")";
  11604. }
  11605. dr[2] = map["dayTotal"];
  11606. dr[3] = map["payTotal"];
  11607. dr[4] = map["today"];
  11608. dr[5] = map["unusua"];
  11609. dr[6] = map["dayDev"];
  11610. double rate = 0.00;
  11611. if (map["dayDev"] > 0)
  11612. {
  11613. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11614. }
  11615. dr[7] = rate.ToString();
  11616. dt.Rows.Add(dr);
  11617. });
  11618. DataView dv = new DataView(dt);
  11619. dv.Sort = "SupplierName";
  11620. //dv.Sort = "AllOrder desc";
  11621. DataTable dtNew = dv.ToTable();
  11622. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11623. }
  11624. public void check_order_desing_info()
  11625. {
  11626. string ctid = GetPostString("ctid");
  11627. if (!string.IsNullOrEmpty(ctid))
  11628. {
  11629. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11630. if (ceErpTradeCell != null)
  11631. {
  11632. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11633. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11634. return;
  11635. }
  11636. returnErrorMsg("找不到订单");
  11637. return;
  11638. }
  11639. returnErrorMsg("找不到订单");
  11640. }
  11641. public void get_timeout_detail()
  11642. {
  11643. string poscode = CurrentUser.UserPost.Post.Code;
  11644. DataStruct dStruct = GetPostStruct();
  11645. List<string> lw = new List<string>();
  11646. string id = GetPostString("id");
  11647. string pay_date1 = GetPostString("pay_date1");
  11648. string pay_date2 = GetPostString("pay_date2");
  11649. int type = GetPostInt("type");
  11650. if (type == 0)
  11651. {
  11652. if (pay_date1.Length > 0)
  11653. {
  11654. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11655. }
  11656. if (pay_date2.Length > 0)
  11657. {
  11658. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11659. }
  11660. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11661. }
  11662. if (type == 1)
  11663. {
  11664. if (pay_date1.Length > 0)
  11665. {
  11666. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11667. }
  11668. if (pay_date2.Length > 0)
  11669. {
  11670. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11671. }
  11672. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11673. }
  11674. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11675. DataTable dt = null;
  11676. dt = WebCache.GetData("view_orderlist", dStruct);
  11677. writeGridDataTableJson(dStruct.TotalCount, dt);
  11678. }
  11679. public void saveUrgentChargePrice()
  11680. {
  11681. string ctid = GetPostString("ctid");
  11682. if (!string.IsNullOrEmpty(ctid))
  11683. {
  11684. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11685. if (ceErpTradeCell != null)
  11686. {
  11687. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11688. if (prices <= 100)
  11689. {
  11690. returnErrorMsg("此订单金额不足100元,无法加急。");
  11691. return;
  11692. }
  11693. double price = GetPostDouble("price");
  11694. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11695. if (ceErpTradeCellExtend == null)
  11696. {
  11697. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11698. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11699. }
  11700. ceErpTradeCellExtend.urgentCharge = price;
  11701. if (ceErpTradeCellExtend.ID > 0)
  11702. {
  11703. ceErpTradeCellExtend.Update();
  11704. }
  11705. else
  11706. {
  11707. ceErpTradeCellExtend.Save();
  11708. }
  11709. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11710. returnSuccessMsg("修改成功!");
  11711. return;
  11712. }
  11713. returnErrorMsg("找不到订单");
  11714. return;
  11715. }
  11716. returnErrorMsg("找不到订单");
  11717. }
  11718. public void finish_erp_order()
  11719. {
  11720. string ctid = GetPostString("ctid");
  11721. if (!string.IsNullOrEmpty(ctid))
  11722. {
  11723. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11724. {
  11725. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11726. if (ceErpTradeCell != null)
  11727. {
  11728. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11729. ceErpTradeCell.Update();
  11730. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11731. returnSuccessMsg("修改成功!");
  11732. return;
  11733. }
  11734. }
  11735. }
  11736. returnErrorMsg("找不到订单");
  11737. }
  11738. public void get_trade_order_list()
  11739. {
  11740. string tid = GetPostString("tid");
  11741. if (!string.IsNullOrEmpty(tid))
  11742. {
  11743. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11744. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11745. writeGridDataTableJson(data.Rows.Count, data);
  11746. return;
  11747. }
  11748. returnErrorMsg("找不到订单");
  11749. }
  11750. public void save_cell_spu()
  11751. {
  11752. string ctid = GetPostString("ctid");
  11753. string spu_id = GetPostString("spu_id");
  11754. if (!string.IsNullOrEmpty(ctid))
  11755. {
  11756. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11757. if (ceErpTradeCellExtend == null)
  11758. {
  11759. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11760. ceErpTradeCellExtend.ctid = ctid;
  11761. }
  11762. ceErpTradeCellExtend.spu_id = spu_id;
  11763. if (!string.IsNullOrEmpty(spu_id))
  11764. {
  11765. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11766. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11767. }
  11768. if (ceErpTradeCellExtend.ID == 0)
  11769. {
  11770. ceErpTradeCellExtend.Create();
  11771. }
  11772. else
  11773. {
  11774. ceErpTradeCellExtend.Update();
  11775. }
  11776. returnSuccessMsg("修改成功!");
  11777. return;
  11778. }
  11779. returnErrorMsg("找不到订单");
  11780. }
  11781. public void change_express_info()
  11782. {
  11783. string ctid = GetPostString("ctid");
  11784. string transNo = GetPostString("transNo");
  11785. string transCom = GetPostString("transCom");
  11786. if (!string.IsNullOrEmpty(ctid))
  11787. {
  11788. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11789. if (ceErpTradeCellExtend == null)
  11790. {
  11791. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11792. ceErpTradeCellExtend.ctid = ctid;
  11793. }
  11794. ceErpTradeCellExtend.modExpressNo = transNo;
  11795. ceErpTradeCellExtend.modExpressCom = transCom;
  11796. ceErpTradeCellExtend.readMod = 2;
  11797. if (ceErpTradeCellExtend.ID == 0)
  11798. {
  11799. ceErpTradeCellExtend.Create();
  11800. }
  11801. else
  11802. {
  11803. ceErpTradeCellExtend.Update();
  11804. }
  11805. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11806. returnSuccessMsg("修改成功!");
  11807. return;
  11808. }
  11809. returnErrorMsg("找不到订单");
  11810. }
  11811. public void get_change_express_list()
  11812. {
  11813. DataStruct dStruct = GetPostStruct();
  11814. List<string> lw = new List<string>();
  11815. int st = 2;
  11816. string tid = GetPostString("ctid");
  11817. if (tid.Length > 0)
  11818. {
  11819. string select_tid = getTidByCtid(tid);
  11820. lw.Add(string.Format("tid='{0}'", select_tid));
  11821. }
  11822. string shopname = GetPostString("shopname");
  11823. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11824. string buyernick = GetPostString("buyer_nick");
  11825. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11826. string sellermemo = GetPostString("seller_memo");
  11827. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11828. string supplier = GetPostString("supplier");
  11829. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11830. string customer = GetPostString("customer");
  11831. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11832. string design = GetPostString("design");
  11833. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11834. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11835. string poscode = CurrentUser.UserPost.Post.Code;
  11836. if (poscode != "SysAdmin")
  11837. {
  11838. string shopid = CurrentUser.User.pemShop;
  11839. lw.Add(string.Format("shopId in ({0})", shopid));
  11840. }
  11841. lw.Add("readMod = 2");
  11842. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11843. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11844. writeGridDataTableJson(dStruct.TotalCount, dt);
  11845. }
  11846. public void deal_express_complete()
  11847. {
  11848. string ctid = GetPostString("ctid");
  11849. if (!string.IsNullOrEmpty(ctid))
  11850. {
  11851. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11852. if (ceErpTradeCellExtend == null)
  11853. {
  11854. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11855. ceErpTradeCellExtend.ctid = ctid;
  11856. }
  11857. ceErpTradeCellExtend.readMod = 1;
  11858. if (ceErpTradeCellExtend.ID == 0)
  11859. {
  11860. ceErpTradeCellExtend.Create();
  11861. }
  11862. else
  11863. {
  11864. ceErpTradeCellExtend.Update();
  11865. }
  11866. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11867. returnSuccessMsg("修改成功!");
  11868. return;
  11869. }
  11870. returnErrorMsg("找不到订单");
  11871. }
  11872. public void aftersale_return_visit()
  11873. {
  11874. string ctid = GetPostString("ctid");
  11875. if (!string.IsNullOrEmpty(ctid))
  11876. {
  11877. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11878. if (ceErpTradeCellExtend == null)
  11879. {
  11880. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11881. ceErpTradeCellExtend.ctid = ctid;
  11882. }
  11883. ceErpTradeCellExtend.returnVisit = 1;
  11884. if (ceErpTradeCellExtend.ID == 0)
  11885. {
  11886. ceErpTradeCellExtend.Create();
  11887. }
  11888. else
  11889. {
  11890. ceErpTradeCellExtend.Update();
  11891. }
  11892. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11893. if (ceErpTradeAfterSaleExtend != null)
  11894. {
  11895. ceErpTradeAfterSaleExtend.TextResult = "";
  11896. ceErpTradeAfterSaleExtend.Update();
  11897. }
  11898. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11899. returnSuccessMsg("修改成功!");
  11900. return;
  11901. }
  11902. returnErrorMsg("找不到订单");
  11903. }
  11904. public void orderPlaceInfo()
  11905. {
  11906. string ctids = GetPostString("ctids");
  11907. string[] list = ctids.Split(',');
  11908. foreach (string ctid in list)
  11909. {
  11910. CeErpSukuraData.createInfo(ctid, 3);
  11911. }
  11912. StringBuilder sql = new StringBuilder();
  11913. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11914. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11915. designHelper.api_approveDesign(ctids); //approveDesign
  11916. returnSuccessMsg("");
  11917. }
  11918. public void get_issue_list()
  11919. {
  11920. DataStruct dStruct = GetPostStruct();
  11921. List<string> lw = new List<string>();
  11922. int st = 2;
  11923. string tid = GetPostString("ctid");
  11924. if (tid.Length > 0)
  11925. {
  11926. string select_tid = getTidByCtid(tid);
  11927. lw.Add(string.Format("tid='{0}'", select_tid));
  11928. }
  11929. string shopname = GetPostString("shopname");
  11930. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11931. string buyernick = GetPostString("buyer_nick");
  11932. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11933. string sellermemo = GetPostString("seller_memo");
  11934. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11935. string supplier = GetPostString("supplier");
  11936. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11937. string customer = GetPostString("customer");
  11938. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11939. string design = GetPostString("design");
  11940. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11941. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11942. string poscode = CurrentUser.UserPost.Post.Code;
  11943. if (poscode != "SysAdmin")
  11944. {
  11945. string shopid = CurrentUser.User.pemShop;
  11946. lw.Add(string.Format("shopId in ({0})", shopid));
  11947. }
  11948. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11949. {
  11950. lw.Add("IssueState = 1");
  11951. }
  11952. else
  11953. {
  11954. string iisstate = GetPostString("iisstate");
  11955. if ("1".Equals(iisstate))
  11956. {
  11957. lw.Add("IssueState =1");
  11958. }
  11959. else if ("2".Equals(iisstate))
  11960. {
  11961. lw.Add("IssueState = 2");
  11962. }
  11963. else
  11964. {
  11965. lw.Add("IssueState > 0");
  11966. }
  11967. }
  11968. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11969. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11970. writeGridDataTableJson(dStruct.TotalCount, dt);
  11971. }
  11972. public void saveIssueContent()
  11973. {
  11974. string ctid = GetPostString("ctid");
  11975. if (!string.IsNullOrEmpty(ctid))
  11976. {
  11977. string content = GetPostString("content");
  11978. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11979. if (ceErpTradeAfterSaleExtend == null)
  11980. {
  11981. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11982. ceErpTradeAfterSaleExtend.tid = ctid;
  11983. }
  11984. ceErpTradeAfterSaleExtend.IssueContent = content;
  11985. ceErpTradeAfterSaleExtend.IssueState = 1;
  11986. if (ceErpTradeAfterSaleExtend.ID > 0)
  11987. {
  11988. ceErpTradeAfterSaleExtend.Update();
  11989. }
  11990. else
  11991. {
  11992. ceErpTradeAfterSaleExtend.Create();
  11993. }
  11994. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11995. returnSuccessMsg("添加成功!");
  11996. return;
  11997. }
  11998. returnErrorMsg("找不到订单");
  11999. }
  12000. public void dealIssueContent()
  12001. {
  12002. string ctid = GetPostString("ctid");
  12003. if (!string.IsNullOrEmpty(ctid))
  12004. {
  12005. string content = GetPostString("content");
  12006. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12007. if (ceErpTradeAfterSaleExtend != null)
  12008. {
  12009. ceErpTradeAfterSaleExtend.IssueState = 2;
  12010. ceErpTradeAfterSaleExtend.Update();
  12011. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12012. returnSuccessMsg("修改完成!");
  12013. return;
  12014. }
  12015. }
  12016. returnErrorMsg("找不到订单");
  12017. }
  12018. public void set_tid_attachments()
  12019. {
  12020. string tid = GetPostString("tid");
  12021. string atta = GetPostString("atta");
  12022. if (!string.IsNullOrEmpty(tid))
  12023. {
  12024. if (string.IsNullOrEmpty(atta))
  12025. {
  12026. returnErrorMsg("文件地址为空");
  12027. return;
  12028. }
  12029. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12030. if (ceErpTradeCell != null)
  12031. {
  12032. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12033. if (ceErpTrade == null)
  12034. {
  12035. returnErrorMsg("找不到订单");
  12036. return;
  12037. }
  12038. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12039. bool isSend = false;
  12040. if (dt != null && dt.Rows.Count > 0)
  12041. {
  12042. foreach (DataRow row in dt.Rows)
  12043. {
  12044. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12045. {
  12046. isSend = true;
  12047. }
  12048. }
  12049. if (isSend)
  12050. {
  12051. returnErrorMsg("已发货无法修改");
  12052. return;
  12053. }
  12054. ceErpTrade.Attachments = atta;
  12055. ceErpTrade.Update();
  12056. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12057. returnSuccessMsg("上传成功!");
  12058. return;
  12059. }
  12060. }
  12061. }
  12062. returnErrorMsg("找不到订单");
  12063. }
  12064. public void get_tid_attachments()
  12065. {
  12066. string tid = GetPostString("tid");
  12067. if (!string.IsNullOrEmpty(tid))
  12068. {
  12069. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12070. if (ceErpTradeCell != null)
  12071. {
  12072. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12073. if (ceErpTrade == null)
  12074. {
  12075. returnErrorMsg("找不到订单");
  12076. return;
  12077. }
  12078. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12079. return;
  12080. }
  12081. }
  12082. returnErrorMsg("找不到订单");
  12083. }
  12084. public void check_erp_sameorders()
  12085. {
  12086. if (UrlPostParmsCheck("ctid"))
  12087. {
  12088. string eid = GetPostString("ctid");
  12089. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12090. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12091. if (entity != null && ceErpTrade != null)
  12092. {
  12093. if (entity.OrderState > 6)
  12094. {
  12095. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12096. return;
  12097. }
  12098. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12099. List<string> ids = new List<string>();
  12100. if (dt != null && dt.Rows.Count > 1)
  12101. {
  12102. bool needhe = true;
  12103. foreach (DataRow dr in dt.Rows)
  12104. {
  12105. ids.Add("'" + dr["ctid"] + "'");
  12106. /* //备注有合包
  12107. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12108. {
  12109. needhe = true;
  12110. }
  12111. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12112. {
  12113. needhe = true;
  12114. }
  12115. //顺丰快递
  12116. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12117. {
  12118. needhe = true;
  12119. }*/
  12120. }
  12121. if (!needhe)
  12122. {
  12123. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12124. return;
  12125. }
  12126. StringBuilder sql = new StringBuilder();
  12127. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12128. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12129. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12130. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12131. foreach (DataRow dr in dt.Rows)
  12132. {
  12133. dr["dstate"] = 0;
  12134. dr["dnumber"] = 0;
  12135. foreach (DataRow row in dt1.Rows)
  12136. {
  12137. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12138. {
  12139. dr["dstate"] = 2;
  12140. dr["default"] = 1;
  12141. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12142. }
  12143. }
  12144. if (eid.Equals(dr["ctid"].ToString()))
  12145. {
  12146. dr["dstate"] = 1;
  12147. dr["default"] = 1;
  12148. }
  12149. }
  12150. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12151. return;
  12152. }
  12153. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12154. return;
  12155. }
  12156. returnErrorMsg("未找到订单");
  12157. return;
  12158. }
  12159. returnErrorMsg("缺少必要的参数");
  12160. }
  12161. public void get_mark_number()
  12162. {
  12163. string eid = GetPostString("ctid");
  12164. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12165. if (entity != null)
  12166. {
  12167. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12168. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12169. int current = 1;
  12170. if (ceErpDeliverMark == null)
  12171. {
  12172. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12173. List<string> ids = new List<string>();
  12174. if (dt != null && dt.Rows.Count > 1)
  12175. {
  12176. foreach (DataRow dr in dt.Rows)
  12177. {
  12178. ids.Add("'" + dr["ctid"] + "'");
  12179. }
  12180. //查询已有的编号
  12181. StringBuilder sql = new StringBuilder();
  12182. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12183. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12184. if (dt1 == null || dt1.Rows.Count == 0)
  12185. {
  12186. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12187. List<int> list_number = new List<int>();
  12188. foreach (DataRow row in numbers.Rows)
  12189. {
  12190. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12191. }
  12192. //查询空余编号
  12193. for (int i = 0; i < list_number.Count + 2; i++)
  12194. {
  12195. if (!list_number.Contains(current))
  12196. {
  12197. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12198. //防止查询过程中有新数据生成
  12199. if (ceErpDeliverMark1 == null)
  12200. {
  12201. break;
  12202. }
  12203. }
  12204. current++;
  12205. }
  12206. }
  12207. else
  12208. {
  12209. foreach (DataRow row in dt1.Rows)
  12210. {
  12211. current = Convert.ToInt32(row["markNumber"]);
  12212. }
  12213. }
  12214. ceErpDeliverMark = new CeErpDeliverMark();
  12215. ceErpDeliverMark.ctid = eid;
  12216. ceErpDeliverMark.createtime = DateTime.Now;
  12217. if (ceErpTrade != null)
  12218. {
  12219. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12220. }
  12221. ceErpDeliverMark.markNumber = current;
  12222. ceErpDeliverMark.Create();
  12223. }
  12224. }
  12225. else
  12226. {
  12227. current = ceErpDeliverMark.markNumber;
  12228. }
  12229. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12230. return;
  12231. }
  12232. }
  12233. public void aftersaleCytSend()
  12234. {
  12235. string ctid = GetPostString("ctid");
  12236. if (!string.IsNullOrEmpty(ctid))
  12237. {
  12238. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12239. if (ceErpTradeCell != null)
  12240. {
  12241. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12242. }
  12243. returnSuccessMsg("推送成功");
  12244. return;
  12245. }
  12246. returnErrorMsg("缺少必要的参数");
  12247. }
  12248. public void packOrderInfo()
  12249. {
  12250. string ctids = GetPostString("ctids");
  12251. if (!string.IsNullOrEmpty(ctids))
  12252. {
  12253. string[] ctid_list = ctids.Split(',');
  12254. if (ctid_list.Length > 20)
  12255. {
  12256. returnErrorMsg("单次下载次数不能超过20个");
  12257. return;
  12258. }
  12259. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12260. StringBuilder sql = new StringBuilder();
  12261. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12262. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12263. int supplierId = 0;
  12264. StringBuilder insterSql = new StringBuilder();
  12265. for (int i = 0; i < dt.Rows.Count; i++)
  12266. {
  12267. DataRow row = dt.Rows[i];
  12268. if (i == 0)
  12269. {
  12270. supplierId = Convert.ToInt32(row["SupplierId"]);
  12271. }
  12272. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12273. {
  12274. returnErrorMsg("同车间的订单才能一起打包");
  12275. return;
  12276. }
  12277. int orderState = Convert.ToInt32(row["OrderState"]);
  12278. if (orderState != 5)
  12279. {
  12280. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12281. return;
  12282. }
  12283. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12284. }
  12285. CeErpPackData ceErpPackData = new CeErpPackData();
  12286. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12287. ceErpPackData.supplierId = supplierId;
  12288. ceErpPackData.createtime = DateTime.Now;
  12289. ceErpPackData.createBy = CurrentUser.UserID;
  12290. ceErpPackData.createName = CurrentUser.UserName;
  12291. ceErpPackData.Create();
  12292. if (ceErpPackData.ID > 0)
  12293. {
  12294. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12295. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12296. }
  12297. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12298. returnSuccessMsg("打包成功");
  12299. return;
  12300. }
  12301. returnErrorMsg("缺少必要的参数");
  12302. }
  12303. public void rePackOrderInfo()
  12304. {
  12305. string id = GetPostString("id");
  12306. if (!string.IsNullOrEmpty(id))
  12307. {
  12308. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12309. if (ceErpPackData == null)
  12310. {
  12311. returnSuccessMsg("查无数据");
  12312. return;
  12313. }
  12314. ceErpPackData.upStatus = 0;
  12315. ceErpPackData.message = "";
  12316. ceErpPackData.Update();
  12317. returnSuccessMsg("打包成功");
  12318. return;
  12319. }
  12320. returnErrorMsg("缺少必要的参数");
  12321. }
  12322. public void backPackOrderInfo()
  12323. {
  12324. string id = GetPostString("id");
  12325. if (!string.IsNullOrEmpty(id))
  12326. {
  12327. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12328. if (ceErpPackData == null)
  12329. {
  12330. returnSuccessMsg("查无数据");
  12331. return;
  12332. }
  12333. ceErpPackData.upStatus = 4;
  12334. ceErpPackData.Update();
  12335. List<string> list = new List<string>();
  12336. StringBuilder sql = new StringBuilder();
  12337. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12338. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12339. for (int i = 0; i < dt.Rows.Count; i++)
  12340. {
  12341. DataRow row = dt.Rows[i];
  12342. list.Add("'" + row["ctid"].ToString() + "'");
  12343. }
  12344. string textCtids = string.Join(",", list);
  12345. 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));
  12346. 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, "无法打包退回"));
  12347. returnSuccessMsg("退回成功");
  12348. return;
  12349. }
  12350. returnErrorMsg("缺少必要的参数");
  12351. }
  12352. public void addPackDownNum()
  12353. {
  12354. string id = GetPostString("id");
  12355. if (!string.IsNullOrEmpty(id))
  12356. {
  12357. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12358. returnSuccessMsg("下载成功");
  12359. return;
  12360. }
  12361. returnErrorMsg("缺少必要的参数");
  12362. }
  12363. public void get_pack_list()
  12364. {
  12365. DataStruct dStruct = GetPostStruct();
  12366. List<string> lw = new List<string>();
  12367. string supplier = GetPostString("supplier");
  12368. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12369. string posTag = CurrentUser.UserPost.Post.Code;
  12370. if (posTag == "Supplier")
  12371. {
  12372. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12373. }
  12374. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12375. dStruct.Order = "createtime desc";
  12376. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12377. writeGridDataTableJson(dStruct.TotalCount, dt);
  12378. }
  12379. public void get_pack_order_list()
  12380. {
  12381. string packId = GetPostString("packId");
  12382. if (string.IsNullOrEmpty(packId))
  12383. {
  12384. returnErrorMsg("缺少必要的参数");
  12385. return;
  12386. }
  12387. StringBuilder sql = new StringBuilder();
  12388. 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);
  12389. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12390. if (dt == null || dt.Rows.Count == 0)
  12391. {
  12392. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12393. return;
  12394. }
  12395. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12396. return;
  12397. }
  12398. public void get_supplier_product_time_list()
  12399. {
  12400. DataStruct dStruct = GetPostStruct();
  12401. List<string> lw = new List<string>();
  12402. string supplier = GetPostString("supplier");
  12403. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12404. string posTag = CurrentUser.UserPost.Post.Code;
  12405. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12406. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12407. writeGridDataTableJson(dStruct.TotalCount, dt);
  12408. }
  12409. public void saveSupplierProductTime()
  12410. {
  12411. string productId = GetPostString("productId");
  12412. if (string.IsNullOrEmpty(productId))
  12413. {
  12414. returnErrorMsg("缺少必要的参数");
  12415. return;
  12416. }
  12417. string productName = GetPostString("productName");
  12418. int supplierId = GetPostInt("supplierId");
  12419. if (supplierId == 0)
  12420. {
  12421. returnErrorMsg("缺少必要的参数");
  12422. return;
  12423. }
  12424. int quantity = GetPostInt("quantity");
  12425. int sendDay = GetPostInt("sendTime");
  12426. string supplierName = GetPostString("supplierName");
  12427. string craft = GetPostString("craft");
  12428. string deadLine = GetPostString("deadLine");
  12429. string dayDeadLine = GetPostString("dayDeadLine");
  12430. try
  12431. {
  12432. int eid = GetPostInt("eid");
  12433. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12434. if (ceErpSupplierProductTime == null)
  12435. {
  12436. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12437. }
  12438. ceErpSupplierProductTime.productId = productId;
  12439. ceErpSupplierProductTime.productName = productName;
  12440. ceErpSupplierProductTime.supplierId = supplierId;
  12441. ceErpSupplierProductTime.supplierName = supplierName;
  12442. ceErpSupplierProductTime.craft = craft;
  12443. ceErpSupplierProductTime.sendDay = sendDay;
  12444. ceErpSupplierProductTime.quantity = quantity;
  12445. if (!string.IsNullOrEmpty(deadLine))
  12446. {
  12447. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12448. }
  12449. if (!string.IsNullOrEmpty(dayDeadLine))
  12450. {
  12451. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12452. }
  12453. if (ceErpSupplierProductTime.ID == 0)
  12454. {
  12455. ceErpSupplierProductTime.Save();
  12456. }
  12457. else
  12458. {
  12459. ceErpSupplierProductTime.Update();
  12460. }
  12461. }
  12462. catch (Exception e)
  12463. {
  12464. }
  12465. returnSuccessMsg("保存成功");
  12466. return;
  12467. }
  12468. public void delSupplierProductTime()
  12469. {
  12470. int eid = GetPostInt("eid");
  12471. if (eid > 0)
  12472. {
  12473. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12474. if (ceErpSupplierProductTime == null)
  12475. {
  12476. returnErrorMsg("查无数据");
  12477. return;
  12478. }
  12479. ceErpSupplierProductTime.Delete();
  12480. returnSuccessMsg("保存成功");
  12481. return;
  12482. }
  12483. returnErrorMsg("缺少必要的参数");
  12484. }
  12485. public void getExpressInfo()
  12486. {
  12487. string ctid = GetPostString("ctid");
  12488. if (!string.IsNullOrEmpty(ctid))
  12489. {
  12490. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12491. if (ceErpTradeCell != null)
  12492. {
  12493. string outSid = ceErpTradeCell.OutSid;
  12494. if (outSid.Length > 0)
  12495. {
  12496. 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);
  12497. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12498. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12499. return;
  12500. }
  12501. }
  12502. returnErrorMsg("查无记录");
  12503. return;
  12504. }
  12505. returnErrorMsg("缺少必要的参数");
  12506. }
  12507. public void getExpressPostData()
  12508. {
  12509. string express = GetPostString("express");
  12510. if (!string.IsNullOrEmpty(express))
  12511. {
  12512. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12513. if (ceErpExpressInfo != null)
  12514. {
  12515. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12516. return;
  12517. }
  12518. }
  12519. returnErrorMsg("缺少必要的参数");
  12520. }
  12521. public void checkSupplierOrder()
  12522. {
  12523. string ctids = GetPostString("ctids");
  12524. if (ctids != null)
  12525. {
  12526. List<string> list = new List<string>();
  12527. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12528. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12529. for (int i = 0; i < dt.Rows.Count; i++)
  12530. {
  12531. DataRow row = dt.Rows[i];
  12532. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12533. {
  12534. continue;
  12535. }
  12536. list.Add(row["seller_memo"].ToString());
  12537. }
  12538. if (list.Count > 0)
  12539. {
  12540. 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, "点击下载按钮"));
  12541. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12542. return;
  12543. }
  12544. }
  12545. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12546. return;
  12547. }
  12548. public void addPersonId()
  12549. {
  12550. string tid = GetPostString("tid");
  12551. string personId = GetPostString("personId");
  12552. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12553. if (ceErpTrade != null)
  12554. {
  12555. ceErpTrade.receiver_zip = personId;
  12556. ceErpTrade.Update();
  12557. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12558. returnSuccessMsg("保存成功");
  12559. return;
  12560. }
  12561. returnErrorMsg("缺少必要的参数");
  12562. }
  12563. }
  12564. }