sync.order.cs 619 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355
  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. namespace SiteCore.Handler
  48. {
  49. public partial class sync
  50. {
  51. public void get_erp_orderlist()
  52. {
  53. string poscode = CurrentUser.UserPost.Post.Code;
  54. DataStruct dStruct = GetPostStruct();
  55. //apiHelper.Api_SyncOrderByTime("598825");
  56. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  57. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  58. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  59. //banniuApiHelper.sendLogisticsInfo(null);
  60. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  61. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  62. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  63. //int sid = commonHelper.autoDistributeToSupplier(entity);
  64. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  65. //tmcHelper.Api_TmcTradeMsg("{\r\n \"content\": {\r\n \"businessType\": \"GUARANTEE\",\r\n \"buyerMemo\": \"\",\r\n \"consolidateType\": \"\",\r\n \"createTime\": 1744882656361,\r\n \"deliveryType\": \"OFFLINE\",\r\n \"discountFee\": 0.0,\r\n \"flag\": \"NONE\",\r\n \"latestDeliveryTime\": 1744882656361,\r\n \"lines\": [\r\n {\r\n \"mark2\": [],\r\n \"num\": 4,\r\n \"outerId\": \"\",\r\n \"payment\": 60.0,\r\n \"picUrl\": \"https://img.alicdn.com/bao/uploaded/i4/2209226402185/O1CN011Zh53V1S0mQKgHJyF_!!4611686018427382153-0-item_pic.jpg\",\r\n \"platServiceFee\": 0.0,\r\n \"price\": 10.0,\r\n \"refOlId\": \"1111122222333338942\",\r\n \"refSkuId\": \"0\",\r\n \"refSpuId\": \"908453435193\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellPrice\": 10.0,\r\n \"singleFee\": 10.0,\r\n \"standards\": \"测试内部\",\r\n \"status\": \"NOT_SHIPPED\",\r\n \"title\": \"【老客户订单2】测试老客户订单内部\",\r\n \"totalFee\": 60.0,\r\n \"totalPrice\": 60.0,\r\n \"totalSellPrice\": 60.0\r\n }\r\n ],\r\n \"logisticsOrderNo\": \"\",\r\n \"mark2\": [],\r\n \"modifyTime\": 1744882656361,\r\n \"openBuyerId\": \"AAG1RHraABkUZRPgSx3g7Eam\",\r\n \"openBuyerNick\": \"0**\",\r\n \"openSellerNick\": \"海角七旗舰店\",\r\n \"orderSource\": \"SYNC\",\r\n \"orderTime\": 1744882656361,\r\n \"payTime\": 1744882656361,\r\n \"payment\": 100.0,\r\n \"platServiceFee\": 0.0,\r\n \"posCode\": \"HJQ\",\r\n \"posId\": 663281,\r\n \"postFee\": 0.0,\r\n \"props\": {\r\n \"payType\": \"ALI_PAY\",\r\n \"govSubsidyAmount\": 0\r\n },\r\n \"receivedPayment\": 0.0,\r\n \"receiverCity\": \"龙岩市\",\r\n \"receiverCountry\": \"中国\",\r\n \"receiverDistrict\": \"新罗区\",\r\n \"receiverId\": \"d1b65912ef886228ac4ada4b65055e52$\",\r\n \"receiverState\": \"福建省\",\r\n \"receiverTown\": \"西陂街道\",\r\n \"refOid\": \"1111122222333338942\",\r\n \"refType\": \"TB\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellerMemo\": \"\",\r\n \"serviceFee\": 0.0,\r\n \"status\": \"NOT_SHIPPED\",\r\n \"totalFee\": 100.0,\r\n \"totalPrice\": 100.0,\r\n \"totalSellPrice\": 100.0,\r\n \"type\": \"SALE\"\r\n }\r\n}");
  66. //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}}");
  67. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  68. List<string> lw = new List<string>();
  69. string tid = GetPostString("ctid");
  70. string date1 = GetPostString("date1");
  71. //12-1 修改
  72. string urgent = GetPostString("urgent");
  73. string back = GetPostString("back");
  74. string offlineSearch = GetPostString("offlineSearch");
  75. int paramsCount = 0;
  76. if (!string.IsNullOrWhiteSpace(urgent))
  77. {
  78. if (urgent.Equals("true"))
  79. {
  80. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  81. }
  82. }
  83. if (!string.IsNullOrWhiteSpace(back))
  84. {
  85. if (back.Equals("true"))
  86. {
  87. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  88. }
  89. }
  90. if (!string.IsNullOrWhiteSpace(offlineSearch))
  91. {
  92. if (offlineSearch.Equals("true"))
  93. {
  94. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  95. }
  96. }
  97. //end
  98. string date2 = GetPostString("date2");
  99. string buyernick = GetPostString("buyer_nick");
  100. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  101. {
  102. if (tid.Length <= 0 && buyernick.Length <= 0)
  103. {
  104. return;
  105. }
  106. }
  107. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  108. {
  109. if (tid.Length > 0)
  110. {
  111. string select_tid = getTidByCtid(tid);
  112. lw.Add(string.Format("tid='{0}'", select_tid));
  113. }
  114. if (buyernick.Length > 0)
  115. {
  116. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  117. }
  118. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  119. if (dw.Length > 0)
  120. {
  121. lw.Add(dw);
  122. }
  123. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  124. {
  125. string usershop = CurrentUser.User.pemShop;
  126. lw.Add(string.Format("ShopId in ({0})", usershop));
  127. }
  128. }
  129. else
  130. {
  131. if (ex_psize == 0)
  132. {
  133. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  134. }
  135. if (PKey != "admin")
  136. {
  137. string usershop = CurrentUser.User.pemShop;
  138. lw.Add(string.Format("ShopId in ({0})", usershop));
  139. paramsCount++;
  140. }
  141. }
  142. string uploaddate1 = GetPostString("uploaddate1");
  143. string uploaddate2 = GetPostString("uploaddate2");
  144. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  145. if (update.Length > 0) lw.Add(update);
  146. string deliverydate1 = GetPostString("deliverydate1");
  147. string deliverydate2 = GetPostString("deliverydate2");
  148. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  149. if (deliverydate.Length > 0)
  150. {
  151. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  152. };
  153. string shopname = GetPostString("shopname");
  154. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  155. string addwechat = GetPostString("addwechat");
  156. if (addwechat.Length > 0)
  157. {
  158. int addWt = Convert.ToInt32(addwechat);
  159. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  160. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  161. }
  162. string customer = GetPostString("customer");
  163. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  164. string design = GetPostString("design");
  165. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  166. string orderState = GetPostString("orderState");
  167. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  168. string address = GetPostString("address");
  169. 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));
  170. string sellermemo = GetPostString("seller_memo");
  171. if (sellermemo.Length > 0)
  172. {
  173. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  174. }
  175. string backReason = GetPostString("backReason");
  176. if (backReason.Length > 0)
  177. {
  178. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  179. }
  180. string apdate1 = GetPostString("apdate1");
  181. string apdate2 = GetPostString("apdate2");
  182. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  183. if (dwap.Length > 0) lw.Add(dwap);
  184. string price1 = GetPostString("price1");
  185. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  186. string price2 = GetPostString("price2");
  187. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  188. string isoldcustomer = GetPostString("isoldcus");
  189. string spudata = GetPostString("spudata");
  190. if ("0".Equals(spudata))
  191. {
  192. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  193. }
  194. if ("1".Equals(spudata))
  195. {
  196. lw.Add(string.Format("spu_id <> ''"));
  197. }
  198. string finishdate1 = GetPostString("finishdate1");
  199. string finishdate2 = GetPostString("finishdate2");
  200. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  201. bool isFinish = false;
  202. if (finishdate.Length > 0)
  203. {
  204. lw.Add(finishdate);
  205. isFinish = true;
  206. paramsCount++;
  207. }
  208. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  209. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  210. if (ex_psize > 0)
  211. {
  212. int UserID = CurrentUser.UserID;
  213. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  214. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  215. {
  216. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  217. }
  218. dStruct.Order = "pay_time desc";
  219. }
  220. string isNew = GetPostString("isNew");
  221. if (isNew == "true")
  222. {
  223. lw.Add(string.Format("IsNew = {0}", 1));
  224. }
  225. string overtime = GetPostString("overtime");
  226. if (overtime == "1")
  227. {
  228. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  229. }
  230. String usePost = CurrentUser.UserPost.Post.Code;
  231. if (usePost.Equals("Operation") == true)
  232. {
  233. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  234. }
  235. else
  236. {
  237. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  238. }
  239. //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";
  240. if (dStruct.PageSize == 100000)
  241. {
  242. dStruct.Order = "";
  243. }
  244. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  245. DataTable dt = null;
  246. string tablename = "view_orderlist";
  247. if (isFinish)
  248. {
  249. tablename = "view_orderlist_end";
  250. }
  251. dt = WebCache.GetData(tablename, dStruct);
  252. if (dt != null && dt.Rows.Count > 0)
  253. {
  254. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  255. foreach (DataRow dr in dt.Rows)
  256. {
  257. try
  258. {
  259. if (dr["refund_fees"] != null)
  260. {
  261. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  262. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  263. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  264. if (payment == refund_fees)
  265. {
  266. dr["refund_fees"] = Math.Round(refund_fees, 2);
  267. }
  268. else if (refund_fees == total_fee)
  269. {
  270. dr["refund_fees"] = payment;
  271. }
  272. else
  273. {
  274. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  275. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  276. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  277. }
  278. }
  279. // 对象操作
  280. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  281. ceErpTradeCell.ctid = dr["ctid"].ToString();
  282. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  283. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  284. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  285. if (dStruct.PageSize != 100000)
  286. {
  287. if (dr["DispatchSort"].ToString() == "2")
  288. {
  289. dr["gongchuang"] = 200;
  290. }
  291. else if ("外协".Equals(dr["ToType"].ToString()))
  292. {
  293. dr["gongchuang"] = 200;
  294. }
  295. else if ("内部".Equals(dr["ToType"].ToString()))
  296. {
  297. dr["gongchuang"] = -1;
  298. }
  299. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  300. {
  301. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  302. dr["gongchuang"] = response.code;
  303. }
  304. }
  305. }
  306. catch (NullReferenceException ex)
  307. {
  308. // 处理空引用异常
  309. dr["refund_fees"] = "0.00";
  310. }
  311. }
  312. }
  313. writeGridDataTableJson(dStruct.TotalCount, dt);
  314. }
  315. public void get_erp_orderlist_sumprice()
  316. {
  317. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  318. return;
  319. List<string> lw = new List<string>();
  320. string tid = GetPostString("ctid");
  321. string date1 = GetPostString("date1");
  322. string date2 = GetPostString("date2");
  323. if (tid.Length > 0 || date1.Length > 0)
  324. {
  325. lw.Add(string.Format("ctid like '%{0}%'", tid));
  326. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  327. if (dw.Length > 0) lw.Add(dw);
  328. }
  329. else
  330. {
  331. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  332. }
  333. string shopname = GetPostString("shopname");
  334. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  335. string buyernick = GetPostString("buyer_nick");
  336. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  337. string customer = GetPostString("customer");
  338. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  339. string design = GetPostString("design");
  340. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  341. string orderState = GetPostString("orderState");
  342. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  343. string address = GetPostString("address");
  344. 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));
  345. string sellermemo = GetPostString("seller_memo");
  346. if (sellermemo.Length > 0)
  347. {
  348. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  349. }
  350. string apdate1 = GetPostString("apdate1");
  351. string apdate2 = GetPostString("apdate2");
  352. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  353. if (dwap.Length > 0) lw.Add(dwap);
  354. string price1 = GetPostString("price1");
  355. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  356. string price2 = GetPostString("price2");
  357. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  358. string isoldcustomer = GetPostString("isoldcus");
  359. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  360. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  361. if (PKey != "admin")
  362. {
  363. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  364. lw.Add(string.Format("shopId in ({0})", usershop));
  365. }
  366. //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";
  367. string mainWhere = string.Join(" and ", lw.ToArray());
  368. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  369. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  370. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  371. decimal total = 0;
  372. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  373. {
  374. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  375. }
  376. var res = new
  377. {
  378. data = total
  379. };
  380. string ro_jsond = JsonConvert.SerializeObject(res);
  381. returnSuccess(ro_jsond);
  382. return;
  383. }
  384. public void get_erp_CustomerServiceGather()
  385. {
  386. string userWhere = "", orderWhere = "";
  387. List<string> lw = new List<string>();
  388. string customer = GetPostString("customer");
  389. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  390. string shopname = GetPostString("shopname");
  391. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  392. string date1 = GetPostString("date1");
  393. string date2 = GetPostString("date2");
  394. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  395. if (dw.Length > 0) lw.Add(dw);
  396. orderWhere = string.Join(" and ", lw.ToArray());
  397. 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 " +
  398. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  399. "left join " +
  400. "( " +
  401. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  402. ") as b on a.ID = b.CustomerUserId " +
  403. "left join " +
  404. "( " +
  405. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  406. ") as d on a.ID = d.CustomerUserId " +
  407. "left join " +
  408. "( " +
  409. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  410. ") as e on a.ID = e.CustomerUserId " +
  411. "left join " +
  412. "( " +
  413. " select CustomerUserId, RefundCount, RefundSum from " +
  414. " ( " +
  415. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  416. " from CE_ErpTradeRefund a " +
  417. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  418. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  419. " group by CustomerUserId " +
  420. " ) as a " +
  421. ") as f on a.ID = f.CustomerUserId " +
  422. "where a.PostCode = 'CustomerService'",
  423. userWhere, orderWhere);
  424. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  425. writeGridDataTableJson(dt.Rows.Count, dt);
  426. //writeGridDataTableJson(dt.Rows.Count, dt);
  427. }
  428. //设计汇总
  429. public void get_erp_DesignerGather()
  430. {
  431. string userWhere = "", orderWhere = "";
  432. List<string> lw = new List<string>();
  433. string Designer = GetPostString("designer");
  434. int org = GetPostInt("org");
  435. if (Designer.Length > 0)
  436. {
  437. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  438. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  439. }
  440. else if (org > 0)
  441. {
  442. userWhere = string.Format(" where OrgID ={0}", org);
  443. }
  444. string shopname = GetPostString("shopname");
  445. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  446. string state = GetPostString("state");
  447. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  448. string OrderArea = GetPostString("order_area");
  449. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  450. string date1 = GetPostString("date1");
  451. string date2 = GetPostString("date2");
  452. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  453. if (dw.Length > 0) lw.Add(dw);
  454. string UpDate1 = GetPostString("UpDate1");
  455. string UpDate2 = GetPostString("UpDate2");
  456. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  457. if (dw.Length > 0) lw.Add(dw);
  458. orderWhere = string.Join(" and ", lw.ToArray());
  459. 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 (" +
  460. "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 " +
  461. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  462. "left join " +
  463. "( " +
  464. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  465. ") as b on a.ID = b.DesignUserId " +
  466. "left join " +
  467. "( " +
  468. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  469. ") as d on a.ID = d.DesignUserId " +
  470. "left join " +
  471. "( " +
  472. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  473. ") as e on a.ID = e.DesignUserId " +
  474. "left join " +
  475. "( " +
  476. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  477. ") as g on a.ID = g.DesignUserId " +
  478. "left join " +
  479. "( " +
  480. " select CustomerUserId, RefundCount, RefundSum from " +
  481. " ( " +
  482. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  483. " from CE_ErpTradeRefund a " +
  484. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  485. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  486. " group by CustomerUserId " +
  487. " ) as a " +
  488. ") as f on a.ID = f.CustomerUserId " +
  489. "where a.PostCode = 'Designer') as z",
  490. userWhere, orderWhere);
  491. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  492. writeGridDataTableJson(dt.Rows.Count, dt);
  493. }
  494. //删除tradecell的订单
  495. public void del_erp_cellorder()
  496. {
  497. if (UrlPostParmsCheck("ctid"))
  498. {
  499. string eid = GetPostString("ctid");
  500. CeErpTradeCell.DelByCtid(eid);
  501. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  502. returnSuccessMsg("删除成功");
  503. }
  504. }
  505. public void clear_erp_refundstate()
  506. {
  507. if (UrlPostParmsCheck("ids"))
  508. {
  509. string eids = GetPostString("ids");
  510. string[] ctidList = eids.Split(',');
  511. foreach (string ctid in ctidList)
  512. {
  513. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  514. if (entity != null)
  515. {
  516. entity.IsRefund = 0;
  517. entity.Update();
  518. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  519. }
  520. else
  521. continue;
  522. }
  523. returnSuccessMsg("操作成功");
  524. return;
  525. }
  526. returnErrorMsg("缺少必要参数");
  527. }
  528. public void set_erp_urgency()
  529. {
  530. if (UrlPostParmsCheck("ctid"))
  531. {
  532. string eid = GetPostString("ctid");
  533. CeErpTradeCell entity = null;
  534. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  535. if (entity != null)
  536. {
  537. string utime = GetPostString("urgencytime");
  538. if (utime.Length > 0)
  539. {
  540. entity.UrgencyTime = Convert.ToDateTime(utime);
  541. }
  542. else
  543. {
  544. returnErrorMsg("请选择加急时间");
  545. return;
  546. }
  547. if (entity.OrderState <= 4)
  548. {
  549. //entity.seller_memo = entity.seller_memo + "-加急";
  550. string smemo = entity.seller_memo;
  551. int kindex = smemo.IndexOf(")");
  552. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  553. if (lastoneStr != "-")
  554. {
  555. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  556. }
  557. string prememo = smemo.Substring(0, kindex + 2);
  558. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  559. int lastkindex = lastmemo.IndexOf("(");
  560. DateTime urgtime = Convert.ToDateTime(utime);
  561. string newlastmemo = "";
  562. if (lastkindex == 0)
  563. {
  564. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  565. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  566. }
  567. else
  568. {
  569. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  570. }
  571. entity.seller_memo = prememo + newlastmemo;
  572. }
  573. entity.IsUrgency = true;
  574. entity.UpdateTime = DateTime.Now;
  575. entity.Update();
  576. ApiVo apiVo = new ApiVo();
  577. apiVo.orderNumber = entity.ctid;
  578. apiVo.actionName = "changeDesign";
  579. apiVo.orderRemarks = entity.seller_memo;
  580. apiVo.remarkSign = 3;
  581. designHelper.API_WorkCore(apiVo); //changeDesign
  582. CeErpSukuraData.createInfo(entity.ctid, 7);
  583. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  584. returnSuccessMsg("设置成功!");
  585. return;
  586. }
  587. returnErrorMsg("找不到记录");
  588. }
  589. }
  590. public void set_erp_reset()
  591. {
  592. if (UrlPostParmsCheck("ctid"))
  593. {
  594. string eid = GetPostString("ctid");
  595. CeErpTradeCell entity = null;
  596. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  597. if (entity != null)
  598. {
  599. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  600. {
  601. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  602. {
  603. returnErrorMsg("财务要求已下单已发货无法重置");
  604. return;
  605. }
  606. }
  607. entity.IsUrgency = false;
  608. entity.seller_memo = "";
  609. entity.OtherMemo = "";
  610. entity.OrderState = 0;
  611. entity.IsReturn = 0;
  612. //entity.IsRefund = 0;
  613. entity.MemoOpt = 0;
  614. entity.AfterSaleState = 0;
  615. entity.AfterSaleResponsible = "";
  616. entity.AfterSaleUserId = 0;
  617. entity.IsNeedBill = 0;
  618. entity.CustomerUserId = 0;
  619. entity.DesignUserId = 0;
  620. entity.SupplierId = 0;
  621. entity.PlaceUserId = 0;
  622. entity.ptid = "";
  623. entity.IsSample = 0;
  624. entity.IsXianHuo = 0;
  625. entity.isDianziOrder = 0;
  626. entity.DispatchSort = 0;
  627. entity.FinishPlaceTime = null;
  628. entity.Update();
  629. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  630. if (trade != null)
  631. {
  632. trade.seller_memo = "";
  633. trade.Update();
  634. }
  635. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  636. returnSuccessMsg("重置成功!");
  637. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  638. if (desginBill != null)
  639. {
  640. desginBill.isDel = 1;
  641. desginBill.Update();
  642. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  643. }
  644. ApiVo apiVo = new ApiVo();
  645. apiVo.orderNumber = entity.ctid;
  646. apiVo.actionName = "resetDesign";
  647. designHelper.API_WorkCore(apiVo);//resetDesign
  648. return;
  649. }
  650. returnErrorMsg("找不到记录");
  651. }
  652. }
  653. public void save_erp_sellermemo()
  654. {
  655. if (UrlPostParmsCheck("ctid"))
  656. {
  657. string ctid = GetPostString("ctid");
  658. CeErpTradeCell entity = null;
  659. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  660. if (entity != null)
  661. {
  662. string memo = GetPostString("seller_memo");
  663. memo = memo.Replace(" ", "");
  664. if (memo.Contains("补差"))
  665. {
  666. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  667. return;
  668. }
  669. List<string> bitList = new List<string>
  670. {
  671. "\\","/",":","*","?", "\"","<" ,">","|"
  672. };
  673. bool isIn = false;
  674. foreach (string bit in bitList)
  675. {
  676. if (memo.Contains(bit))
  677. {
  678. isIn = true;
  679. }
  680. }
  681. if (isIn)
  682. {
  683. returnErrorMsg("不能使用 一些符合作为文件名");
  684. return;
  685. }
  686. if (entity.seller_memo != memo)
  687. {
  688. if (entity.IsSample == 2)
  689. {
  690. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  691. return;
  692. }
  693. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  694. {
  695. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  696. {
  697. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  698. return;
  699. }
  700. }
  701. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  702. }
  703. commonHelper.getCytPrice(entity);
  704. int memoopt = GetPostInt("MemoOpt");
  705. Boolean ismemoopt = false;
  706. if (memoopt > 0)
  707. {
  708. string stropt = "";
  709. if (memoopt == 1)
  710. {
  711. stropt = "“改稿”";
  712. ismemoopt = true;
  713. }
  714. else if (memoopt == 2)
  715. {
  716. stropt = "“定稿”";
  717. }
  718. else if (memoopt == 3)
  719. {
  720. stropt = "“查货”";
  721. CeErpSukuraData.createInfo(entity.ctid, 6);
  722. }
  723. entity.MemoOpt = Convert.ToInt32(memoopt);
  724. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  725. }
  726. if (entity.OrderState < 5)
  727. {
  728. memo = memo.Replace("(", "(");
  729. memo = memo.Replace(")", ")");
  730. }
  731. if (entity.OrderState < 3)
  732. {
  733. entity.DispatchSort = 0;
  734. }
  735. entity.seller_memo = memo;
  736. entity.UpdateTime = DateTime.Now;
  737. entity.Update();
  738. ApiVo apiVo = new ApiVo();
  739. apiVo.orderNumber = entity.ctid;
  740. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  741. apiVo.orderRemarks = memo;
  742. apiVo.remarkSign = memoopt;
  743. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  744. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  745. returnSuccessMsg("保存成功!");
  746. return;
  747. }
  748. returnErrorMsg("找不到记录");
  749. }
  750. }
  751. public void ins_erp_checkorder()
  752. {
  753. if (UrlPostParmsCheck("ctid"))
  754. {
  755. string ctid = GetPostString("ctid");
  756. CeErpTradeCell entity = null;
  757. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  758. if (entity != null)
  759. {
  760. if (entity.OrderState < 6)
  761. {
  762. returnErrorMsg("下单完成后才可查货");
  763. return;
  764. }
  765. /*if (entity.OrderState > 6)
  766. {
  767. returnErrorMsg("订单已发货");
  768. return;
  769. }*/
  770. if (entity.FinishPlaceTime != null)
  771. {
  772. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  773. {
  774. returnErrorMsg("下单时间不足,无法查货");
  775. return;
  776. }
  777. }
  778. entity.MemoOpt = 3;
  779. entity.CheckOrderTime = DateTime.Now;
  780. entity.UpdateTime = DateTime.Now;
  781. entity.Update();
  782. CeErpSukuraData.createInfo(entity.ctid, 6);
  783. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  784. returnSuccessMsg("操作成功!");
  785. return;
  786. }
  787. returnErrorMsg("找不到记录");
  788. }
  789. }
  790. public void save_erp_othermemo()
  791. {
  792. if (UrlPostParmsCheck("ctid"))
  793. {
  794. string ctid = GetPostString("ctid");
  795. CeErpTradeCell entity = null;
  796. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  797. if (entity != null)
  798. {
  799. entity.OtherMemo = GetPostString("otherMemo");
  800. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  801. {
  802. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  803. StringBuilder sql = new StringBuilder();
  804. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  805. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  806. if (dt != null && dt.Rows.Count > 0)
  807. {
  808. foreach (DataRow dr in dt.Rows)
  809. {
  810. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  811. {
  812. //品类一直
  813. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  814. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  815. if (ceErpSampleCustomer == null)
  816. {
  817. ceErpSampleCustomer = new CeErpSampleCustomer();
  818. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  819. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  820. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  821. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  822. ceErpSampleCustomer.shopId = entity.ShopId;
  823. }
  824. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  825. ceErpSampleCustomer.lastTid = entity.tid;
  826. if (ceErpSampleCustomer.ID > 0)
  827. {
  828. ceErpSampleCustomer.Update();
  829. }
  830. else
  831. {
  832. ceErpSampleCustomer.Create();
  833. }
  834. }
  835. }
  836. }
  837. }
  838. //if (entity.IsOldCustomer == 1)
  839. //{
  840. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  841. //{
  842. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  843. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  844. //}
  845. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  846. //{
  847. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  848. // {
  849. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  850. // {
  851. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  852. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  853. // }
  854. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  855. // {
  856. // entity.OrderState = 2;
  857. // entity.DesignUserId = 0;
  858. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  859. // }
  860. // else
  861. // {
  862. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  863. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  864. // }
  865. // }
  866. //}
  867. //}
  868. entity.Update();
  869. returnSuccessMsg("保存成功!");
  870. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  871. return;
  872. }
  873. returnErrorMsg("找不到记录");
  874. }
  875. }
  876. public void save_erp_customermemo()
  877. {
  878. if (UrlPostParmsCheck("ctid"))
  879. {
  880. string ctid = GetPostString("ctid");
  881. CeErpTradeCell entity = null;
  882. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  883. if (entity != null)
  884. {
  885. entity.CustomerMemo = GetPostString("CustomerMemo");
  886. entity.Update();
  887. ApiVo apiVo = new ApiVo();
  888. apiVo.orderNumber = entity.ctid;
  889. apiVo.actionName = "followRemarks";
  890. apiVo.orderRemarks = entity.CustomerMemo;
  891. designHelper.API_WorkCore(apiVo);//followRemarks
  892. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  893. returnSuccessMsg("保存成功!");
  894. return;
  895. }
  896. returnErrorMsg("找不到记录");
  897. }
  898. }
  899. public void upd_erp_addmemotag()
  900. {
  901. if (UrlPostParmsCheck("ctid"))
  902. {
  903. ;
  904. string eid = GetPostString("ctid");
  905. string sfTagstr = GetPostString("memotag");
  906. CeErpTradeCell entity = null;
  907. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  908. if (entity != null)
  909. {
  910. ApiVo apiVo = new ApiVo();
  911. if (entity.OrderState == 0)
  912. {
  913. returnErrorMsg("请先领单");
  914. return;
  915. }
  916. //撤销顺丰
  917. if (sfTagstr == "撤销顺丰")
  918. {
  919. entity.IsSF = 0;
  920. string reMsg = "";
  921. string oldmemo = entity.seller_memo;
  922. if (entity.OrderState < 5)
  923. {
  924. oldmemo = oldmemo.Replace("顺丰到付", "");
  925. oldmemo = oldmemo.Replace("顺丰寄付", "");
  926. entity.seller_memo = oldmemo;
  927. }
  928. else
  929. {
  930. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  931. {
  932. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  933. }
  934. }
  935. entity.Update();
  936. apiVo.orderNumber = entity.ctid;
  937. apiVo.actionName = "orderRemarks";
  938. apiVo.orderRemarks = entity.seller_memo;
  939. apiVo.isSf = entity.IsSF.ToString();
  940. designHelper.API_WorkCore(apiVo);//orderRemarks
  941. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  942. returnSuccessMsg("撤销成功!" + reMsg);
  943. return;
  944. }
  945. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  946. {
  947. //string oldmemo = entity.seller_memo;
  948. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  949. string sfStr = GetPostString("memotag");
  950. string smemo = entity.seller_memo;
  951. int kindex = smemo.IndexOf(")");
  952. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  953. if (lastoneStr != "-")
  954. {
  955. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  956. }
  957. string prememo = smemo.Substring(0, kindex + 2);
  958. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  959. int lastkindex = lastmemo.IndexOf("(");
  960. string newlastmemo = "";
  961. if (lastkindex == 0)
  962. {
  963. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  964. newlastmemo = "(" + sfStr + "." + useLastmemo;
  965. }
  966. else
  967. {
  968. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  969. }
  970. entity.seller_memo = prememo + newlastmemo;
  971. }
  972. string sfTagMSg = "";
  973. if (sfTagstr == "顺丰寄付")
  974. {
  975. entity.IsSF = 1;
  976. sfTagMSg = "顺丰寄付";
  977. }
  978. else if (sfTagstr == "顺丰到付")
  979. {
  980. entity.IsSF = 2;
  981. sfTagMSg = "顺丰到付";
  982. }
  983. entity.Update();
  984. apiVo = new ApiVo();
  985. apiVo.orderNumber = entity.ctid;
  986. apiVo.actionName = "orderRemarks";
  987. apiVo.orderRemarks = entity.seller_memo;
  988. apiVo.isSf = entity.IsSF.ToString();
  989. designHelper.API_WorkCore(apiVo);//orderRemarks
  990. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  991. returnSuccessMsg("标记成功!");
  992. return;
  993. }
  994. returnErrorMsg("找不到记录");
  995. }
  996. }
  997. public void upd_erp_ordertag()
  998. {
  999. if (UrlPostParmsCheck("ctid"))
  1000. {
  1001. string eid = GetPostString("ctid");
  1002. CeErpTradeCell entity = null;
  1003. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1004. if (entity != null)
  1005. {
  1006. int tag = GetPostInt("wechattag");
  1007. //if(tag==4 && entity.IsSample == 2)
  1008. //{
  1009. // returnErrorMsg("补差价单不能标记微信单");
  1010. // return;
  1011. //}
  1012. entity.wechatTag = tag;
  1013. entity.Update();
  1014. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1015. if (tag == 1)
  1016. {
  1017. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1018. if (cash == null)
  1019. {
  1020. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1021. cash = new CeErpReturnCash();
  1022. cash.tid = entity.tid;
  1023. cash.seller_nick = main.seller_nick;
  1024. cash.payment = trade.payment;
  1025. cash.buyer_nick = main.buyer_nick;
  1026. cash.cashstate = 0;
  1027. cash.rtype = "微信返现";
  1028. cash.returnprice = 0;
  1029. cash.created = DateTime.Now;
  1030. cash.con = "订单标记微信单";
  1031. cash.img = "";
  1032. cash.applyuserid = CurrentUser.UserID;
  1033. cash.Create();
  1034. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1035. }
  1036. else
  1037. {
  1038. cash.cashstate = 0;
  1039. cash.Update();
  1040. }
  1041. CeErpSukuraData.createInfo(entity.ctid, 9);
  1042. }
  1043. else if (tag == 2)
  1044. {
  1045. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1046. if (cash == null)
  1047. {
  1048. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1049. cash = new CeErpReturnCash();
  1050. cash.tid = entity.tid;
  1051. cash.seller_nick = main.seller_nick;
  1052. cash.payment = trade.payment;
  1053. cash.buyer_nick = main.buyer_nick;
  1054. cash.cashstate = 0;
  1055. cash.rtype = "推购返现";
  1056. cash.returnprice = 5;
  1057. cash.created = DateTime.Now;
  1058. cash.con = "订单标记推购单";
  1059. cash.img = "";
  1060. cash.applyuserid = CurrentUser.UserID;
  1061. cash.Create();
  1062. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1063. }
  1064. else
  1065. {
  1066. cash.cashstate = 0;
  1067. cash.Update();
  1068. }
  1069. CeErpSukuraData.createInfo(entity.ctid, 9);
  1070. }
  1071. else if (tag == 3)
  1072. {
  1073. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1074. if (pers == null)
  1075. {
  1076. pers = new CeErpPersuade();
  1077. pers.ctid = entity.ctid;
  1078. pers.pstate = 0;
  1079. pers.created = DateTime.Now;
  1080. pers.applyuserid = CurrentUser.UserID;
  1081. pers.Create();
  1082. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1083. }
  1084. else
  1085. {
  1086. pers.pstate = 0;
  1087. pers.Update();
  1088. }
  1089. }
  1090. else if (tag == 4 || tag == 5)
  1091. {
  1092. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1093. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1094. if (pers == null)
  1095. {
  1096. pers = new CeErpStayGoods();
  1097. pers.t_id = entity.tid;
  1098. pers.status = "待审核";
  1099. pers.audit_type = 0;
  1100. if (tag == 4)
  1101. {
  1102. pers.stay_type = "微信推购";
  1103. }
  1104. else
  1105. {
  1106. pers.stay_type = "旺旺推购";
  1107. }
  1108. if (entity.IsXianHuo == 0)
  1109. {
  1110. pers.product_id = entity.ProductId;
  1111. }
  1112. pers.wangwang = main.buyer_nick;
  1113. pers.shop_name = main.seller_nick;
  1114. pers.creata_time = DateTime.Now;
  1115. pers.create_u_id = CurrentUser.UserID;
  1116. pers.create_u_name = CurrentUser.UserName;
  1117. pers.Create();
  1118. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1119. }
  1120. else
  1121. {
  1122. pers.audit_type = 0;
  1123. pers.Update();
  1124. }
  1125. CeErpSukuraData.createInfo(entity.ctid, 10);
  1126. }
  1127. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1128. returnSuccessMsg("标记成功!");
  1129. return;
  1130. }
  1131. returnErrorMsg("找不到记录");
  1132. }
  1133. }
  1134. public void upd_erp_ordertag_cancel()
  1135. {
  1136. if (UrlPostParmsCheck("ctid"))
  1137. {
  1138. string eid = GetPostString("ctid");
  1139. CeErpTradeCell entity = null;
  1140. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1141. if (entity != null)
  1142. {
  1143. entity.wechatTag = 0;
  1144. entity.Update();
  1145. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1146. if (pers != null)
  1147. {
  1148. pers.status = "取消推购";
  1149. pers.audit_type = 3;
  1150. pers.Update();
  1151. }
  1152. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1153. returnSuccessMsg("标记成功!");
  1154. return;
  1155. }
  1156. returnErrorMsg("找不到记录");
  1157. }
  1158. }
  1159. public void upd_erp_addweichattag()
  1160. {
  1161. if (UrlPostParmsCheck("ctid"))
  1162. {
  1163. ;
  1164. string eid = GetPostString("ctid");
  1165. CeErpTradeCell entity = null;
  1166. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1167. if (entity != null)
  1168. {
  1169. if (entity.IsAddWechat > 0)
  1170. {
  1171. returnErrorMsg("此单已经标记过了");
  1172. return;
  1173. }
  1174. 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);
  1175. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1176. if (dt.Rows.Count > 0)
  1177. {
  1178. entity.IsAddWechat = 2;
  1179. }
  1180. else
  1181. {
  1182. entity.IsAddWechat = 1;
  1183. }
  1184. entity.Update();
  1185. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1186. returnSuccessMsg("标记成功!");
  1187. return;
  1188. }
  1189. returnErrorMsg("找不到记录");
  1190. }
  1191. }
  1192. public void upd_erp_getmyorder()
  1193. {
  1194. if (UrlPostParmsCheck("ctid"))
  1195. {
  1196. ;
  1197. string eid = GetPostString("ctid");
  1198. CeErpTradeCell entity = null;
  1199. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1200. if (entity != null)
  1201. {
  1202. if (entity.ctid.IndexOf("C") != -1)
  1203. {
  1204. StringBuilder sql = new StringBuilder();
  1205. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1206. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1207. if (dt.Rows.Count > 0)
  1208. {
  1209. decimal total = 0;
  1210. foreach (DataRow dr in dt.Rows)
  1211. {
  1212. total += Convert.ToDecimal(dr["payment"]);
  1213. }
  1214. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1215. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1216. {
  1217. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1218. return;
  1219. }
  1220. }
  1221. }
  1222. if (entity.OrderState == -1)
  1223. {
  1224. returnErrorMsg("待审核订单无法领取!");
  1225. return;
  1226. }
  1227. entity.CustomerUserId = CurrentUser.UserID;
  1228. if (entity.OrderState < 2)
  1229. {
  1230. entity.OrderState = 2;
  1231. if (entity.ShopId != 0)
  1232. {
  1233. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1234. }
  1235. }
  1236. entity.UpdateTime = DateTime.Now;
  1237. entity.Update();
  1238. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1239. returnSuccessMsg("领单成功!");
  1240. return;
  1241. }
  1242. returnErrorMsg("找不到记录");
  1243. }
  1244. }
  1245. public void getmyorder_from_init()
  1246. {
  1247. if (UrlPostParmsCheck("ctid"))
  1248. {
  1249. string eid = GetPostString("ctid");
  1250. CeErpTradeCell entity = null;
  1251. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1252. if (entity != null)
  1253. {
  1254. string sellerMemo = GetPostString("sellerMemo");
  1255. if (sellerMemo.Length > 0)
  1256. {
  1257. entity.seller_memo = sellerMemo;
  1258. }
  1259. string oterhMemo = GetPostString("otherMemo");
  1260. if (oterhMemo.Length > 0)
  1261. {
  1262. entity.OtherMemo = oterhMemo;
  1263. }
  1264. int urg = GetPostInt("urgency");
  1265. entity.IsUrgency = (urg == 1 ? true : false);
  1266. int wechat = GetPostInt("wechat");
  1267. int command = GetPostInt("command");
  1268. if (wechat == 1)
  1269. {
  1270. entity.wechatTag = 1;
  1271. }
  1272. if (command == 1)
  1273. {
  1274. entity.wechatTag = 2;
  1275. }
  1276. string pPro = GetPostString("pprofession");
  1277. if (pPro.Length > 0)
  1278. {
  1279. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1280. string spro = GetPostString("profession");
  1281. if (spro.Length > 0)
  1282. {
  1283. entity.ProfessionId = Convert.ToInt32(spro);
  1284. }
  1285. }
  1286. string proId = GetPostString("productId");
  1287. if (proId.Length > 0)
  1288. {
  1289. entity.ProductId = Convert.ToInt32(proId);
  1290. }
  1291. entity.Material = GetPostString("material");
  1292. entity.Craft = GetPostString("craft");
  1293. entity.CustomerUserId = CurrentUser.UserID;
  1294. if (entity.OrderState < 2)
  1295. {
  1296. entity.OrderState = 2;
  1297. if (entity.ShopId != 0)
  1298. {
  1299. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1300. }
  1301. }
  1302. entity.Update();
  1303. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1304. returnSuccessMsg("领单成功!");
  1305. return;
  1306. }
  1307. returnErrorMsg("找不到记录");
  1308. }
  1309. }
  1310. public void upd_erp_setrelationorder()
  1311. {
  1312. if (UrlPostParmsCheck("ctid"))
  1313. {
  1314. ;
  1315. string eid = GetPostString("ctid");
  1316. string ftid = GetPostString("ftid");
  1317. CeErpTradeCell entity = null;
  1318. CeErpTradeCell fentity = null;
  1319. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1320. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1321. if (fentity == null)
  1322. {
  1323. returnErrorMsg("找不到关联的主订单");
  1324. return;
  1325. }
  1326. if (entity != null)
  1327. {
  1328. if (entity.OrderState >= 5)
  1329. {
  1330. returnErrorMsg("本单已经设计完成无法关联");
  1331. return;
  1332. }
  1333. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1334. {
  1335. returnErrorMsg("线下单续审核后才能关联!");
  1336. return;
  1337. }
  1338. entity.ptid = ftid;
  1339. entity.OrderState = fentity.OrderState;
  1340. //entity.status = fentity.status;
  1341. entity.CustomerUserId = fentity.CustomerUserId;
  1342. entity.DesignUserId = fentity.DesignUserId;
  1343. entity.seller_memo = "补差价单:" + ftid;
  1344. entity.IsSample = 2;
  1345. entity.Update();
  1346. ApiVo apiVo = new ApiVo();
  1347. apiVo.orderNumber = ftid;
  1348. apiVo.payment = entity.payment;
  1349. apiVo.actionName = "repairDesign";
  1350. designHelper.API_WorkCore(apiVo);//repairDesign
  1351. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1352. returnSuccessMsg("关联成功!");
  1353. return;
  1354. }
  1355. else
  1356. returnErrorMsg("找不到记录");
  1357. }
  1358. }
  1359. public void download_erp_neworder()
  1360. {
  1361. string seller = GetPostString("seller_nick");
  1362. string tid = GetPostString("tid");
  1363. if (seller.Length <= 0 || tid.Length <= 0)
  1364. {
  1365. returnErrorMsg("数据错误");
  1366. }
  1367. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1368. //{
  1369. // returnErrorMsg("找不到店铺Sessionkey");
  1370. //}
  1371. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1372. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1373. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1374. if (res.IndexOf("refOid") == -1)
  1375. {
  1376. returnErrorMsg("下载订单数据失败");
  1377. return;
  1378. }
  1379. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1380. returnSuccessMsg("下载完成");
  1381. //tmcHelper.createNewOrder(res);
  1382. //CeErpTrade entr = null;
  1383. //entr = CeErpTrade.Get(tid);
  1384. //if (entr != null)
  1385. //{
  1386. // returnSuccess("下载成功");
  1387. // //下载成功之后,Cell表生成对应的订单;
  1388. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1389. //}
  1390. //else
  1391. //{
  1392. // returnErrorMsg("下载失败或者创建订单失败");
  1393. //}
  1394. }
  1395. public void set_erp_atersale()
  1396. {
  1397. if (UrlPostParmsCheck("ctid"))
  1398. {
  1399. string eid = GetPostString("ctid");
  1400. string reason = GetPostString("AfterSaleReason");
  1401. CeErpTradeCell entity = null;
  1402. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1403. if (entity != null)
  1404. {
  1405. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1406. {
  1407. returnErrorMsg("此订单已经在售后");
  1408. return;
  1409. }
  1410. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1411. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1412. entity.AfterSaleTime = DateTime.Now;
  1413. entity.Update();
  1414. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1415. returnSuccessMsg("转售后成功!");
  1416. return;
  1417. }
  1418. returnErrorMsg("找不到记录");
  1419. }
  1420. }
  1421. public void set_erp_withdraw()
  1422. {
  1423. if (UrlPostParmsCheck("ctid"))
  1424. {
  1425. try
  1426. {
  1427. string eid = GetPostString("ctid");//商品id
  1428. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1429. CeWithdraw ceWithdrawSelect = null;
  1430. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1431. if (ceWithdrawSelect != null)
  1432. {
  1433. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1434. {
  1435. ceWithdrawSelect.status = -1;
  1436. ceWithdrawSelect.Update();
  1437. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1438. returnSuccessMsg("重新发起审核成功");
  1439. return;
  1440. }
  1441. else
  1442. {
  1443. returnSuccessMsg("请勿重复申请!");
  1444. return;
  1445. }
  1446. }
  1447. else
  1448. {
  1449. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1450. if (string.IsNullOrEmpty(CustomerUserId))
  1451. {
  1452. CustomerUserId = "-1";
  1453. }
  1454. int Userid = CurrentUser.UserID;//用户id
  1455. CeWithdraw ceWithdraw = new CeWithdraw();
  1456. ceWithdraw.tid = eid;
  1457. ceWithdraw.userid = Userid;
  1458. ceWithdraw.providerid = CustomerUserId;
  1459. ceWithdraw.status = 3;
  1460. ceWithdraw.creationtime = DateTime.Now;
  1461. ceWithdraw.Create();
  1462. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1463. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1464. return;
  1465. }
  1466. }
  1467. catch
  1468. {
  1469. returnErrorMsg("申请撤回订单失败");
  1470. return;
  1471. }
  1472. }
  1473. }
  1474. public void ins_erp_billinfo()
  1475. {
  1476. if (UrlPostParmsCheck("ctid"))
  1477. {
  1478. string eid = GetPostString("ctid");
  1479. CeErpTradeCell entity = null;
  1480. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1481. if (entity != null)
  1482. {
  1483. CeErpBill bill = CeErpBill.GetByTid(eid);
  1484. bool isHave = false;
  1485. if (bill != null)
  1486. {
  1487. isHave = true;
  1488. if (bill.state != 4)
  1489. {
  1490. returnErrorMsg("此单已经申请过发票了");
  1491. return;
  1492. }
  1493. }
  1494. if (entity.IsNeedBill == 0)
  1495. {
  1496. entity.IsNeedBill = 1;
  1497. }
  1498. entity.Update();
  1499. string errjson = "";
  1500. try
  1501. {
  1502. CeErpBill bill_entity = new CeErpBill();
  1503. bill_entity.tid = entity.tid;
  1504. bill_entity.title = GetPostString("title");
  1505. string taxstr = GetPostString("tax");
  1506. taxstr = taxstr.Replace(" ", "");
  1507. bill_entity.tax = taxstr;
  1508. bill_entity.bank = GetPostString("bank");
  1509. string bankacstr = GetPostString("bankac");
  1510. bankacstr = bankacstr.Replace(" ", "");
  1511. bill_entity.bankac = bankacstr;
  1512. bill_entity.address = GetPostString("address");
  1513. bill_entity.phone = GetPostString("phone");
  1514. bill_entity.price = GetPostString("price");
  1515. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1516. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1517. {
  1518. billCount += 1;
  1519. }
  1520. string prebill = "ltb";
  1521. for (int idx = 1; idx <= billCount; idx++)
  1522. {
  1523. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1524. string billoid = prebill + idx + dtstr;
  1525. bill_entity.billOrderId += billoid;
  1526. if (idx < billCount)
  1527. {
  1528. bill_entity.billOrderId += ",";
  1529. }
  1530. }
  1531. bill_entity.productId = GetPostInt("ProductName");
  1532. bill_entity.num = GetPostInt("num");
  1533. bill_entity.unit = GetPostString("unit");
  1534. bill_entity.type = GetPostString("type");
  1535. bill_entity.sendType = GetPostString("SendType");
  1536. bill_entity.email = GetPostString("email");
  1537. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1538. bill_entity.shopName = GetPostString("ShopName");
  1539. bill_entity.applymemo = GetPostString("applyMemo");
  1540. bill_entity.createTime = DateTime.Now;
  1541. bill_entity.state = 0;
  1542. bill_entity.userId = CurrentUser.UserID;
  1543. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1544. bill_entity.Create();
  1545. }
  1546. catch (Exception ex)
  1547. {
  1548. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1549. returnErrorMsg("创建发票出错!");
  1550. return;
  1551. }
  1552. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1553. returnSuccessMsg("发票申请成功!");
  1554. return;
  1555. }
  1556. returnErrorMsg("找不到记录");
  1557. }
  1558. }
  1559. public void ins_erp_neworder()
  1560. {
  1561. if (UrlPostParmsCheck("receiver_name"))
  1562. {
  1563. CeErpTrade entity = new CeErpTrade();
  1564. string plat_form = GetPostString("platform");
  1565. string preStr = "N_";
  1566. if (plat_form == "拼多多")
  1567. {
  1568. preStr = "P_";
  1569. }
  1570. else if (plat_form == "阿里巴巴")
  1571. {
  1572. preStr = "A_";
  1573. }
  1574. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1575. entity.seller_nick = GetPostString("seller_nick");
  1576. entity.buyer_nick = GetPostString("buyer_nick");
  1577. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1578. entity.total_fee = entity.payment;
  1579. entity.pay_time = DateTime.Now;
  1580. entity.status = "NOT_SHIPPED";
  1581. entity.receiver_name = GetPostString("receiver_name");
  1582. entity.receiver_mobile = GetPostString("receiver_mobile");
  1583. entity.receiver_state = GetPostString("receiver_state");
  1584. entity.receiver_city = GetPostString("receiver_city");
  1585. entity.receiver_district = GetPostString("receiver_district");
  1586. entity.receiver_address = GetPostString("receiver_address");
  1587. if (entity.receiver_state == "" || entity.receiver_city == "")
  1588. {
  1589. returnErrorMsg("收件地址不能为空");
  1590. return;
  1591. }
  1592. int shopId = 0;
  1593. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1594. if (nShop != null)
  1595. {
  1596. shopId = nShop.ID;
  1597. }
  1598. if (shopId != 34 && entity.payment == 0)
  1599. {
  1600. returnErrorMsg("公司自用的单金额才能为0");
  1601. return;
  1602. }
  1603. entity.Create();
  1604. CeErpTradeCell entitycell = new CeErpTradeCell();
  1605. entitycell.ctid = entity.tid;
  1606. entitycell.tid = entity.tid;
  1607. entitycell.ShopId = shopId;
  1608. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1609. entitycell.OrderState = 0;
  1610. entitycell.pay_time = entity.pay_time;
  1611. entitycell.IsOffLineOrder = 1;
  1612. entitycell.Create();
  1613. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1614. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1615. return;
  1616. }
  1617. }
  1618. public void ins_erp_neworder2()
  1619. {
  1620. if (UrlPostParmsCheck("receiver_name"))
  1621. {
  1622. //string plat_form = GetPostString("platform");
  1623. string preStr = "X_";
  1624. string memo = GetPostString("memo");
  1625. string productId = GetPostString("productId");
  1626. string primg = GetPostString("proofimg");
  1627. string sellerNick = GetPostString("seller_nick");
  1628. string addFrom = GetPostString("addfrom");
  1629. if (addFrom == "1")
  1630. {
  1631. preStr = "N_";
  1632. }
  1633. int shopId = 0;
  1634. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1635. if (nShop != null)
  1636. {
  1637. shopId = nShop.ID;
  1638. }
  1639. else
  1640. {
  1641. returnErrorMsg("找不到对应店铺");
  1642. return;
  1643. }
  1644. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1645. {
  1646. returnErrorMsg("必须上传付款凭证");
  1647. return;
  1648. }
  1649. CeErpTrade entity = new CeErpTrade();
  1650. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1651. entity.seller_nick = sellerNick;
  1652. entity.buyer_nick = GetPostString("buyer_nick");
  1653. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1654. entity.total_fee = entity.payment;
  1655. entity.pay_time = DateTime.Now;
  1656. entity.status = "NOT_SHIPPED";
  1657. entity.receiver_name = GetPostString("receiver_name");
  1658. entity.receiver_mobile = GetPostString("receiver_mobile");
  1659. entity.receiver_state = GetPostString("receiver_state");
  1660. entity.receiver_city = GetPostString("receiver_city");
  1661. entity.receiver_district = GetPostString("receiver_district");
  1662. entity.receiver_address = GetPostString("receiver_address");
  1663. entity.seller_memo = memo;
  1664. entity.orderFrom = 20;
  1665. entity.orderType = 15;
  1666. if (entity.receiver_state == "" || entity.receiver_city == "")
  1667. {
  1668. returnErrorMsg("收件地址不能为空");
  1669. return;
  1670. }
  1671. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1672. {
  1673. returnErrorMsg("公司自用的单金额才能为0");
  1674. return;
  1675. }
  1676. entity.Create();
  1677. string toWhere = GetPostString("towhere");
  1678. CeErpTradeCell entitycell = new CeErpTradeCell();
  1679. entitycell.ctid = entity.tid;
  1680. //唯一标识
  1681. entitycell.OrderSn = entity.tid;
  1682. string orderSn = dataHelper.getSaleOrderSn();
  1683. if (orderSn != "")
  1684. {
  1685. entitycell.OrderSn = orderSn;
  1686. }
  1687. entitycell.tid = entity.tid;
  1688. //if (preStr == "X_")
  1689. //{
  1690. entitycell.IsOffLineOrder = 1;
  1691. //}
  1692. entitycell.CustomerUserId = CurrentUser.UserID;
  1693. entitycell.PayProofImg = primg;
  1694. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1695. entitycell.ProductId = Convert.ToInt32(productId);
  1696. entitycell.ShopId = shopId;
  1697. entitycell.UpdateTime = DateTime.Now;
  1698. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1699. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1700. {
  1701. entitycell.IsXianHuo = 1;
  1702. }
  1703. entitycell.pay_time = entity.pay_time;
  1704. if (toWhere == "1")
  1705. {
  1706. entitycell.OrderState = 2;
  1707. }
  1708. else
  1709. {
  1710. entitycell.OrderState = 6;
  1711. entitycell.FinishPlaceTime = entitycell.pay_time;
  1712. }
  1713. if (shopId == 94)
  1714. {
  1715. entitycell.OrderState = 4;
  1716. entitycell.WaitDesignTime = entitycell.pay_time;
  1717. entitycell.StartDesignTime = entitycell.pay_time;
  1718. entitycell.DesignUserId = 218;
  1719. }
  1720. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1721. {
  1722. entitycell.OrderState = -1;//修改12-5
  1723. CeWithdraw ceWithdraw = new CeWithdraw();
  1724. ceWithdraw.tid = entity.tid;
  1725. ceWithdraw.providerid = "-1";
  1726. ceWithdraw.status = -1;
  1727. ceWithdraw.creationtime = DateTime.Now;
  1728. ceWithdraw.userid = 1337;
  1729. ceWithdraw.Create();
  1730. }
  1731. entitycell.Create();
  1732. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1733. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1734. {
  1735. addPlaceRegist(entitycell, CurrentUser.UserID);
  1736. }
  1737. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1738. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1739. return;
  1740. }
  1741. }
  1742. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1743. {
  1744. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1745. entity.PlactTime = tradecell.pay_time;
  1746. entity.AddUserId = userid;
  1747. entity.FileName = tradecell.seller_memo;
  1748. entity.Supplier = 24;
  1749. entity.CreateTime = DateTime.Now;
  1750. entity.Did = tradecell.ctid;
  1751. entity.tid = tradecell.tid;
  1752. entity.splitTag = tradecell.SplitTag;
  1753. entity.CurState = "未完成";
  1754. entity.Create();
  1755. }
  1756. public void get_erp_offlinelist()
  1757. {
  1758. DataStruct dStruct = GetPostStruct();
  1759. List<string> lw = new List<string>();
  1760. string tid = GetPostString("ctid");
  1761. string date1 = GetPostString("date1");
  1762. string date2 = GetPostString("date2");
  1763. if (tid.Length > 0 || date1.Length > 0)
  1764. {
  1765. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1766. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1767. if (dw.Length > 0) lw.Add(dw);
  1768. }
  1769. else
  1770. {
  1771. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1772. }
  1773. string shopname = GetPostString("shopname");
  1774. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1775. string buyernick = GetPostString("buyer_nick");
  1776. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1777. string customer = GetPostString("customer");
  1778. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1779. string design = GetPostString("design");
  1780. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1781. string orderState = GetPostString("orderState");
  1782. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1783. string address = GetPostString("address");
  1784. 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));
  1785. string sellermemo = GetPostString("seller_memo");
  1786. if (sellermemo.Length > 0)
  1787. {
  1788. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1789. }
  1790. string price1 = GetPostString("price1");
  1791. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1792. string price2 = GetPostString("price2");
  1793. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1794. //if (PKey != "admin")
  1795. //{
  1796. // string usershop = CurrentUser.User.pemShop;
  1797. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1798. //}
  1799. //if (ex_psize > 0)
  1800. //{
  1801. dStruct.Order = "pay_time desc";
  1802. //}
  1803. //else
  1804. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1805. lw.Add(string.Format("IsOffLineOrder=1"));
  1806. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1807. DataTable dt = null;
  1808. dt = WebCache.GetData("view_erptradecell", dStruct);
  1809. writeGridDataTableJson(dStruct.TotalCount, dt);
  1810. }
  1811. public void get_erp_returncashrecord()
  1812. {
  1813. DataStruct dStruct = GetPostStruct();
  1814. List<string> lw = new List<string>();
  1815. string tid = GetPostString("ctid");
  1816. if (tid.Length > 0)
  1817. {
  1818. lw.Add(string.Format("tid like '%{0}%'", tid));
  1819. dStruct.Order = "id desc";
  1820. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1821. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1822. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1823. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1824. return;
  1825. }
  1826. returnErrorMsg("id数据错误!");
  1827. }
  1828. public void ins_erp_returncashrecord()
  1829. {
  1830. if (UrlPostParmsCheck("tid"))
  1831. {
  1832. string tid = GetPostString("tid");
  1833. string retype = GetPostString("type");
  1834. StringBuilder sql = new StringBuilder();
  1835. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1836. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1837. if (dt.Rows.Count > 0)
  1838. {
  1839. returnErrorMsg("相同返现类型记录已存在");
  1840. return;
  1841. }
  1842. CeErpReturnCash entity = new CeErpReturnCash();
  1843. entity.tid = tid;
  1844. entity.seller_nick = GetPostString("seller_nick");
  1845. string pment = GetPostString("payment");
  1846. if (pment.Length > 0)
  1847. {
  1848. entity.payment = Convert.ToDouble(pment);
  1849. }
  1850. entity.buyer_nick = GetPostString("buyer_nick");
  1851. entity.cashstate = 0;
  1852. entity.rtype = retype;
  1853. string rPrice = GetPostString("returnprice");
  1854. if (rPrice.Length > 0)
  1855. {
  1856. entity.returnprice = Convert.ToDouble(rPrice);
  1857. }
  1858. entity.created = DateTime.Now;
  1859. entity.con = GetPostString("con");
  1860. entity.img = GetPostString("img");
  1861. entity.applyuserid = CurrentUser.UserID;
  1862. entity.Create();
  1863. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1864. returnSuccessMsg("操作成功!");
  1865. return;
  1866. }
  1867. }
  1868. public void set_erp_predelivery()
  1869. {
  1870. if (UrlPostParmsCheck("ctid"))
  1871. {
  1872. string eid = GetPostString("ctid");
  1873. CeErpTradeCell entity = null;
  1874. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1875. if (entity != null)
  1876. {
  1877. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1878. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1879. //{
  1880. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1881. // return;
  1882. //}
  1883. entity.IsPreDelivery = 1;
  1884. entity.Update();
  1885. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1886. returnSuccessMsg("预发货成功!");
  1887. return;
  1888. //string shop = GetPostString("seller_nick");
  1889. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1890. //string comName = GetPostString("comName");
  1891. //string comCode = GetPostString("comCode");
  1892. //string outSid = GetPostString("outSid");//运单号
  1893. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1894. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1895. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1896. //string apires = "";
  1897. //if (deliveryType == "虚拟发货")
  1898. //{
  1899. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1900. //}
  1901. //else
  1902. //{
  1903. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1904. //}
  1905. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1906. ////{
  1907. //if (apires.IndexOf("发货成功") != -1)
  1908. //{
  1909. // if (deliveryType != "虚拟发货")
  1910. // {
  1911. // //还要插入快递信息到 快递信息表
  1912. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1913. // exinfo.tid = eid;
  1914. // exinfo.out_sid = outSid;
  1915. // exinfo.company_code = comCode;
  1916. // exinfo.company_name = comName;
  1917. // exinfo.delivery_memo = deliveryMemo;
  1918. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1919. // exinfo.deliveryType = deliveryType;
  1920. // exinfo.Create();
  1921. // }
  1922. // returnSuccessMsg("发货成功!");
  1923. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1924. //}
  1925. //else
  1926. //{
  1927. // returnErrorMsg("淘宝发货失败!!");
  1928. //}
  1929. //return;
  1930. }
  1931. returnErrorMsg("找不到订单记录");
  1932. }
  1933. }
  1934. public void get_erp_unusuallist()
  1935. {
  1936. DataStruct dStruct = GetPostStruct();
  1937. List<string> lw = new List<string>();
  1938. string tid = GetPostString("ctid");
  1939. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1940. string shopname = GetPostString("shopname");
  1941. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1942. string buyernick = GetPostString("buyer_nick");
  1943. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1944. string ResponsibleMan = GetPostString("responsible");
  1945. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1946. string date1 = GetPostString("date1");
  1947. string date2 = GetPostString("date2");
  1948. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1949. if (dw.Length > 0) lw.Add(dw);
  1950. string price1 = GetPostString("price1");
  1951. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1952. string price2 = GetPostString("price2");
  1953. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1954. string orderState = GetPostString("orderState");
  1955. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1956. string sellermemo = GetPostString("seller_memo");
  1957. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1958. lw.Add(string.Format("UnusualTag > 0"));
  1959. lw.Add(string.Format("IsRefund<={0}", 1));
  1960. dStruct.Order = "pay_time desc";
  1961. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1962. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1963. writeGridDataTableJson(dStruct.TotalCount, dt);
  1964. }
  1965. public void set_erp_unusualtonomal()
  1966. {
  1967. if (UrlPostParmsCheck("ctid"))
  1968. {
  1969. string eid = GetPostString("ctid");
  1970. CeErpTradeCell entity = null;
  1971. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1972. if (entity != null)
  1973. {
  1974. entity.UnusualTag = -1;
  1975. entity.Update();
  1976. returnSuccessMsg("忽略成功!");
  1977. return;
  1978. }
  1979. returnErrorMsg("找不到记录");
  1980. }
  1981. }
  1982. public void ins_erp_unusualreason()
  1983. {
  1984. if (UrlPostParmsCheck("ctid"))
  1985. {
  1986. string eid = GetPostString("ctid");
  1987. CeErpTradeCell entity = null;
  1988. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1989. if (entity != null)
  1990. {
  1991. entity.MemoOpt = 4;
  1992. entity.UnusualCon = GetPostString("con");
  1993. entity.Update();
  1994. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1995. if (trade != null)
  1996. {
  1997. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  1998. }
  1999. //查货是否超时
  2000. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2001. if (ceErpTradeCellExtend == null)
  2002. {
  2003. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2004. ceErpTradeCellExtend.ctid = entity.ctid;
  2005. }
  2006. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2007. {
  2008. ceErpTradeCellExtend.CheckOut += 1;
  2009. }
  2010. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2011. if (ceErpTradeCellExtend.ID > 0)
  2012. {
  2013. ceErpTradeCellExtend.Update();
  2014. }
  2015. else
  2016. {
  2017. ceErpTradeCellExtend.Create();
  2018. }
  2019. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2020. returnSuccessMsg("操作成功!");
  2021. return;
  2022. }
  2023. returnErrorMsg("找不到记录");
  2024. }
  2025. }
  2026. public void upd_erp_sampleorder()
  2027. {
  2028. if (UrlPostParmsCheck("ctid"))
  2029. {
  2030. string eid = GetPostString("ctid");
  2031. string[] eArr = eid.Split(',');
  2032. if (eArr.Length > 1)
  2033. {
  2034. List<string> eLst = new List<string>();
  2035. for (int i = 0; i < eArr.Length; i++)
  2036. {
  2037. eLst.Add("'" + eArr[i] + "'");
  2038. }
  2039. eid = string.Join(",", eLst.ToArray());
  2040. }
  2041. else
  2042. {
  2043. eid = "'" + eid + "'";
  2044. }
  2045. StringBuilder sql = new StringBuilder();
  2046. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2047. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2048. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2049. if (dt.Rows.Count > 0)
  2050. {
  2051. string errmsg = "";
  2052. foreach (DataRow dr in dt.Rows)
  2053. {
  2054. StringBuilder sqlsb = new StringBuilder();
  2055. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2056. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2057. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2058. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2059. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2060. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2061. {
  2062. continue;
  2063. }
  2064. else
  2065. {
  2066. string emsg = commonHelper.KeepChinese(apires);
  2067. errmsg += emsg;
  2068. }
  2069. }
  2070. if (errmsg.Length > 0)
  2071. {
  2072. returnErrorMsg(errmsg);
  2073. return;
  2074. }
  2075. returnSuccessMsg("操作成功");
  2076. return;
  2077. }
  2078. returnErrorMsg("找不到记录");
  2079. }
  2080. }
  2081. public void upd_erp_transcustomer()
  2082. {
  2083. if (UrlPostParmsCheck("ctid"))
  2084. {
  2085. string eid = GetPostString("ctid");
  2086. int userid = GetPostInt("CustomerUserId");
  2087. CeErpTradeCell entity = null;
  2088. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2089. if (entity != null)
  2090. {
  2091. //string[] mlist = entity.seller_memo.Split('-');
  2092. //string sql = "select * from view_erpuser where id=" + userid;
  2093. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2094. //if (dt != null && dt.Rows.Count > 0)
  2095. //{
  2096. // string nmemo = "";
  2097. // for(int i = 0; i < mlist.Length - 1; i++)
  2098. // {
  2099. // nmemo += mlist[i];
  2100. // nmemo += "-";
  2101. // }
  2102. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2103. // entity.seller_memo = nmemo;
  2104. //}
  2105. entity.CustomerUserId = userid;
  2106. entity.Update();
  2107. returnSuccessMsg("操作成功!");
  2108. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2109. return;
  2110. }
  2111. returnErrorMsg("找不到记录");
  2112. }
  2113. }
  2114. public void upd_erp_transdesigner()
  2115. {
  2116. if (UrlPostParmsCheck("ctid"))
  2117. {
  2118. string eids = GetPostString("ctid");
  2119. string[] ctidList = eids.Split(',');
  2120. int userid = GetPostInt("DesignUserId");
  2121. foreach (string ctid in ctidList)
  2122. {
  2123. CeErpTradeCell entity = null;
  2124. CeErpDesignerBill entitys = null;
  2125. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2126. entitys = CeErpDesignerBill.GetByTid(ctid);
  2127. if (entity != null)
  2128. {
  2129. if (entity.OrderState > 4)
  2130. {
  2131. continue;
  2132. }
  2133. //存在退款不能流转
  2134. if (entity.IsRefund > 0)
  2135. {
  2136. continue;
  2137. }
  2138. entity.DesignUserId = userid;
  2139. entity.WaitDesignTime = DateTime.Now;
  2140. entity.Update();
  2141. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2142. }
  2143. }
  2144. returnSuccessMsg("操作成功!");
  2145. }
  2146. }
  2147. public void upd_erp_distributedesigner()
  2148. {
  2149. if (UrlPostParmsCheck("ctid"))
  2150. {
  2151. string eid = GetPostString("ctid");
  2152. int userid = GetPostInt("DesignUserId");
  2153. string[] idlist = eid.Split(',');
  2154. if (idlist.Length <= 0)
  2155. {
  2156. returnErrorMsg("订单不能为空");
  2157. return;
  2158. }
  2159. foreach (string ctid in idlist)
  2160. {
  2161. CeErpTradeCell entity = null;
  2162. CeErpDesignerBill entitys = null;
  2163. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2164. else continue;
  2165. if (entity != null)
  2166. {
  2167. if (userid == 2125 || userid == 3542)
  2168. { }
  2169. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2170. {
  2171. returnErrorMsg("金额错误的订单无法指派");
  2172. return;
  2173. }
  2174. if (entity.OrderState >= 5)
  2175. {
  2176. returnErrorMsg("已经设计完成无法指派");
  2177. return;
  2178. }
  2179. if (entity.OrderState == -1)
  2180. {
  2181. returnErrorMsg("审核中的订单无法指派");
  2182. return;
  2183. }
  2184. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2185. {
  2186. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2187. return;
  2188. }
  2189. //157赖橙帆 159林晨 73 静之颖
  2190. 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)
  2191. {
  2192. returnErrorMsg("指派设计共创无法再次指派!");
  2193. return;
  2194. }
  2195. entity.OrderState = 3;
  2196. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  2197. if (entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  2198. {
  2199. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2200. entity.SupplierId = suid;
  2201. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2202. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2203. }
  2204. if (userid == 2125 && entity.seller_memo != "")
  2205. {
  2206. apiDesign.API_GetPrintData_CreateOrder(entity);
  2207. }
  2208. if (userid == 3542 && entity.seller_memo != "")
  2209. {
  2210. string userPost = CurrentUser.UserPost.Post.Code;
  2211. if (CurrentUser.UserID == 73)
  2212. {
  2213. userPost = "SysAdmin";
  2214. }
  2215. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2216. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2217. if (response.msg != "设计共创:成功")
  2218. {
  2219. returnErrorMsg(response.msg);
  2220. return;
  2221. }
  2222. entity.DispatchSort = 2;
  2223. }
  2224. else
  2225. {
  2226. if (entity.DispatchSort == 2)
  2227. {
  2228. ApiVo apiVo = new ApiVo();
  2229. apiVo.actionName = "closeDesign";
  2230. apiVo.orderNumber = entity.ctid;
  2231. designHelper.API_WorkCore(apiVo);//closeDesign
  2232. }
  2233. entity.DispatchSort = 0;
  2234. }
  2235. entity.DesignUserId = userid;
  2236. entity.WaitDesignTime = DateTime.Now;
  2237. entity.UpdateTime = DateTime.Now;
  2238. entity.Update();
  2239. string name = commonHelper.getUserNameById(userid);
  2240. commonHelper.UpdateRelationOrder(entity.ctid);
  2241. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2242. }
  2243. }
  2244. returnSuccessMsg("操作成功!");
  2245. return;
  2246. }
  2247. }
  2248. public string getTidByCtid(string ctid)
  2249. {
  2250. string tid = "";
  2251. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2252. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2253. if (dataTable != null && dataTable.Rows.Count > 0)
  2254. {
  2255. tid = dataTable.Rows[0]["tid"].ToString();
  2256. }
  2257. return tid;
  2258. }
  2259. public List<string> getTidByCtidLike(string ctid)
  2260. {
  2261. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2262. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2263. List<string> list = new List<string>();
  2264. if (dataTable != null && dataTable.Rows.Count > 0)
  2265. {
  2266. foreach (DataRow item in dataTable.Rows)
  2267. {
  2268. list.Add("'" + item["tid"].ToString() + "'");
  2269. }
  2270. }
  2271. return list;
  2272. }
  2273. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2274. {
  2275. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2276. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2277. List<string> list = new List<string>();
  2278. if (dataTable != null && dataTable.Rows.Count > 0)
  2279. {
  2280. foreach (DataRow item in dataTable.Rows)
  2281. {
  2282. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2283. {
  2284. continue;
  2285. }
  2286. list.Add("'" + item["receiverId"].ToString() + "'");
  2287. }
  2288. }
  2289. return list;
  2290. }
  2291. public void get_erp_myorderlist()
  2292. {
  2293. DataStruct dStruct = GetPostStruct();
  2294. List<string> lw = new List<string>();
  2295. string tid = GetPostString("ctid");
  2296. if (tid.Length > 0)
  2297. {
  2298. string select_tid = getTidByCtid(tid);
  2299. lw.Add(string.Format("tid='{0}'", select_tid));
  2300. }
  2301. else
  2302. {
  2303. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2304. }
  2305. //12-1 修改
  2306. string urgent = GetPostString("urgent");
  2307. string back = GetPostString("back");
  2308. string offlineSearch = GetPostString("offlineSearch");
  2309. if (!string.IsNullOrWhiteSpace(urgent))
  2310. {
  2311. if (urgent.Equals("true"))
  2312. {
  2313. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2314. }
  2315. }
  2316. if (!string.IsNullOrWhiteSpace(back))
  2317. {
  2318. if (back.Equals("true"))
  2319. {
  2320. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2321. }
  2322. }
  2323. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2324. {
  2325. if (offlineSearch.Equals("true"))
  2326. {
  2327. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2328. }
  2329. }
  2330. //end
  2331. string shopname = GetPostString("shopname");
  2332. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2333. string buyernick = GetPostString("buyer_nick");
  2334. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2335. string design = GetPostString("design");
  2336. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2337. string orderState = GetPostString("orderState");
  2338. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2339. string sellermemo = GetPostString("seller_memo");
  2340. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2341. string date1 = GetPostString("date1");
  2342. string date2 = GetPostString("date2");
  2343. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2344. if (dw.Length > 0) lw.Add(dw);
  2345. string price1 = GetPostString("price1");
  2346. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2347. string price2 = GetPostString("price2");
  2348. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2349. string urgency = GetPostString("urgency");
  2350. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2351. string after = GetPostString("after");
  2352. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2353. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2354. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2355. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2356. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2357. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2358. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2359. if (dt != null && dt.Rows.Count > 0)
  2360. {
  2361. foreach (DataRow dr in dt.Rows)
  2362. {
  2363. try
  2364. {
  2365. // 对象操作
  2366. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2367. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2368. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2369. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2370. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2371. if (dStruct.PageSize != 100000)
  2372. {
  2373. if (dr["DispatchSort"].ToString() == "2")
  2374. {
  2375. dr["gongchuang"] = 200;
  2376. }
  2377. else if ("外协".Equals(dr["ToType"].ToString()))
  2378. {
  2379. dr["gongchuang"] = 200;
  2380. }
  2381. else if ("内部".Equals(dr["ToType"].ToString()))
  2382. {
  2383. dr["gongchuang"] = -1;
  2384. }
  2385. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2386. {
  2387. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2388. dr["gongchuang"] = response.code;
  2389. }
  2390. }
  2391. }
  2392. catch (NullReferenceException ex)
  2393. {
  2394. }
  2395. }
  2396. }
  2397. writeGridDataTableJson(dStruct.TotalCount, dt);
  2398. }
  2399. public void get_erp_myreturnorderlist()
  2400. {
  2401. DataStruct dStruct = GetPostStruct();
  2402. List<string> lw = new List<string>();
  2403. string tid = GetPostString("ctid");
  2404. if (tid.Length > 0)
  2405. {
  2406. string select_tid = getTidByCtid(tid);
  2407. lw.Add(string.Format("tid='{0}'", select_tid));
  2408. }
  2409. else
  2410. {
  2411. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2412. }
  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. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2432. {
  2433. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2434. }
  2435. else
  2436. {
  2437. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2438. }
  2439. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2440. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2441. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2442. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2443. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2444. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2445. if (dt != null && dt.Rows.Count > 0)
  2446. {
  2447. foreach (DataRow dr in dt.Rows)
  2448. {
  2449. try
  2450. {
  2451. // 对象操作
  2452. if (dStruct.PageSize != 100000)
  2453. {
  2454. if (dr["DispatchSort"].ToString() == "2")
  2455. {
  2456. dr["gongchuang"] = 200;
  2457. }
  2458. else if ("外协".Equals(dr["ToType"].ToString()))
  2459. {
  2460. dr["gongchuang"] = 200;
  2461. }
  2462. else if ("内部".Equals(dr["ToType"].ToString()))
  2463. {
  2464. dr["gongchuang"] = -1;
  2465. }
  2466. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2467. {
  2468. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2469. dr["gongchuang"] = response.code;
  2470. }
  2471. }
  2472. }
  2473. catch (NullReferenceException ex)
  2474. {
  2475. // 处理空引用异常
  2476. }
  2477. }
  2478. }
  2479. writeGridDataTableJson(dStruct.TotalCount, dt);
  2480. }
  2481. public void get_erp_myorderlist_pregather()
  2482. {
  2483. string date1 = GetPostString("date1");
  2484. string date2 = GetPostString("date2");
  2485. int userId = CurrentUser.UserID; //客服id
  2486. string orderWhere = "";
  2487. List<string> lw = new List<string>();
  2488. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2489. if (dw.Length > 0) lw.Add(dw);
  2490. lw.Add(string.Format("CustomerUserId={0}", userId));
  2491. lw.Add(string.Format("OrderState<9"));
  2492. orderWhere = string.Join(" and ", lw.ToArray());
  2493. string orderWhere2 = "";
  2494. List<string> lw2 = new List<string>();
  2495. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2496. if (dw2.Length > 0) lw2.Add(dw2);
  2497. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2498. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2499. string sql = string.Format("select *" +
  2500. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2501. "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 " +
  2502. "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 " +
  2503. "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");
  2504. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2505. //writeGridDataTableJson(dt.Rows.Count, dt);
  2506. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2507. }
  2508. public void upd_erp_publishorder()
  2509. {
  2510. if (UrlPostParmsCheck("ctid"))
  2511. {
  2512. string eid = GetPostString("ctid");
  2513. CeErpTradeCell entity = null;
  2514. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2515. if (entity != null)
  2516. {
  2517. entity.OrderState = 0; //发布后,变为待抢单
  2518. entity.Update();
  2519. commonHelper.UpdateRelationOrder(entity.ctid);
  2520. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2521. returnSuccessMsg("发布成功!");
  2522. return;
  2523. }
  2524. returnErrorMsg("找不到记录");
  2525. }
  2526. }
  2527. public void get_erp_my_tiporder()
  2528. {
  2529. StringBuilder sql = new StringBuilder();
  2530. int userId = 0;
  2531. if (CurrentUser != null) userId = CurrentUser.UserID;
  2532. string posCode = CurrentUser.UserPost.Post.Code;
  2533. string isTipedAfterSaleVerify = GetPostString("af");
  2534. DataTable dt = new DataTable();
  2535. if (posCode != "Supplier")
  2536. {
  2537. if (posCode == "CustomerService" || posCode == "Director")
  2538. {
  2539. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2540. }
  2541. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2542. {
  2543. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2544. }
  2545. else
  2546. {
  2547. string teamIds = CurrentUser.User.TeamIds;
  2548. if (teamIds == "")
  2549. {
  2550. teamIds = "0";
  2551. }
  2552. 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);
  2553. }
  2554. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2555. }
  2556. if (dt.Rows.Count <= 0)
  2557. {
  2558. string key = "aftersale_order_" + userId;
  2559. if (RedisHelper.HasKey(key))
  2560. {
  2561. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2562. dt.Columns.Add("ctid", typeof(string));
  2563. dt.Columns.Add("IsReadTag", typeof(int));
  2564. foreach (var i in list)
  2565. {
  2566. DataRow data = dt.NewRow();
  2567. data["ctid"] = i;
  2568. data["IsReadTag"] = 4;
  2569. dt.Rows.Add(data);
  2570. }
  2571. RedisHelper.StringDelete(key);
  2572. }
  2573. }
  2574. if (dt.Rows.Count <= 0)
  2575. {
  2576. sql = new StringBuilder();
  2577. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2578. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2579. }
  2580. if (posCode == "Supplier")
  2581. {
  2582. string ids = CurrentUser.User.pemVend;
  2583. if (ids != null && ids.Length > 0)
  2584. {
  2585. string[] ids_list = ids.Split(',');
  2586. foreach (var item in ids_list)
  2587. {
  2588. string key = "return_order_" + item;
  2589. if (RedisHelper.HasKey(key))
  2590. {
  2591. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2592. dt.Columns.Add("ctid", typeof(string));
  2593. dt.Columns.Add("IsReadTag", typeof(int));
  2594. foreach (var i in list)
  2595. {
  2596. DataRow data = dt.NewRow();
  2597. data["ctid"] = i;
  2598. data["IsReadTag"] = 1;
  2599. dt.Rows.Add(data);
  2600. }
  2601. RedisHelper.StringDelete(key);
  2602. }
  2603. }
  2604. }
  2605. if (dt.Rows.Count <= 0)
  2606. {
  2607. sql = new StringBuilder();
  2608. 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);
  2609. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2610. }
  2611. }
  2612. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2613. }
  2614. public void reset_erp_tiporder()
  2615. {
  2616. string ids = GetPostString("ids");
  2617. string[] ctidList = ids.Split(',');
  2618. foreach (string ctid in ctidList)
  2619. {
  2620. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2621. if (enty != null)
  2622. {
  2623. enty.IsReadTag = 0;
  2624. enty.Update();
  2625. }
  2626. }
  2627. returnSuccessMsg("成功!");
  2628. return;
  2629. }
  2630. public void get_erp_designlist()
  2631. {
  2632. DataStruct dStruct = GetPostStruct();
  2633. List<string> lw = new List<string>();
  2634. string tid = GetPostString("ctid");
  2635. if (tid.Length > 0)
  2636. {
  2637. string select_tid = getTidByCtid(tid);
  2638. lw.Add(string.Format("tid='{0}'", select_tid));
  2639. }
  2640. string shopname = GetPostString("shopname");
  2641. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2642. string buyernick = GetPostString("buyer_nick");
  2643. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2644. string customer = GetPostString("customer");
  2645. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2646. string design = GetPostString("design");
  2647. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2648. string orderState = GetPostString("orderState");
  2649. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2650. lw.Add(string.Format("OrderState<6"));
  2651. string address = GetPostString("address");
  2652. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2653. string sellermemo = GetPostString("seller_memo");
  2654. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2655. string date1 = GetPostString("date1");
  2656. string date2 = GetPostString("date2");
  2657. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2658. if (dw.Length > 0) lw.Add(dw);
  2659. string apdate1 = GetPostString("apdate1");
  2660. string apdate2 = GetPostString("apdate2");
  2661. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2662. if (dwap.Length > 0) lw.Add(dwap);
  2663. string price1 = GetPostString("price1");
  2664. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2665. string price2 = GetPostString("price2");
  2666. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2667. string designTime = GetPostString("designtime");
  2668. if (designTime.Length > 0)
  2669. {
  2670. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2671. }
  2672. string usershop = CurrentUser.User.pemShop;
  2673. if (usershop.Length > 0)
  2674. {
  2675. lw.Add(string.Format("shopId in ({0})", usershop));
  2676. }
  2677. int myOrgid = CurrentUser.UserPost.OrgID;
  2678. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2679. if (myOrgCode.IndexOf("Designer") != -1)
  2680. {
  2681. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2682. {
  2683. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2684. }
  2685. else
  2686. {
  2687. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2688. }
  2689. }
  2690. else
  2691. {
  2692. string orgId = GetPostString("designerhd");
  2693. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2694. }
  2695. if (tid.Length > 0 || buyernick.Length > 0)
  2696. {
  2697. lw.Add(string.Format("OrderState >= 3"));
  2698. }
  2699. else
  2700. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2701. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2702. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2703. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2704. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2705. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2706. if (dt != null && dt.Rows.Count > 0)
  2707. {
  2708. foreach (DataRow dr in dt.Rows)
  2709. {
  2710. try
  2711. {
  2712. // 对象操作
  2713. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2714. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2715. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2716. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2717. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2718. if (dStruct.PageSize != 100000)
  2719. {
  2720. if (dr["DispatchSort"].ToString() == "2")
  2721. {
  2722. dr["gongchuang"] = 200;
  2723. }
  2724. else if ("外协".Equals(dr["ToType"].ToString()))
  2725. {
  2726. dr["gongchuang"] = 200;
  2727. }
  2728. else if ("内部".Equals(dr["ToType"].ToString()))
  2729. {
  2730. dr["gongchuang"] = -1;
  2731. }
  2732. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2733. {
  2734. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2735. dr["gongchuang"] = response.code;
  2736. }
  2737. }
  2738. }
  2739. catch (NullReferenceException ex)
  2740. {
  2741. }
  2742. }
  2743. }
  2744. writeGridDataTableJson(dStruct.TotalCount, dt);
  2745. }
  2746. public void get_erp_mydesignlist()
  2747. {
  2748. DataStruct dStruct = GetPostStruct();
  2749. List<string> lw = new List<string>();
  2750. string tid = GetPostString("ctid");
  2751. if (tid.Length > 0)
  2752. {
  2753. string select_tid = getTidByCtid(tid);
  2754. lw.Add(string.Format("tid='{0}'", select_tid));
  2755. }
  2756. string shopname = GetPostString("shopname");
  2757. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2758. string buyernick = GetPostString("buyer_nick");
  2759. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2760. string customer = GetPostString("customer");
  2761. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2762. string orderState = GetPostString("orderState");
  2763. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2764. //lw.Add(string.Format("OrderState<6"));
  2765. string date1 = GetPostString("date1");
  2766. string date2 = GetPostString("date2");
  2767. string dw = GetDateWhere("pay_time", date1, date2);
  2768. if (dw.Length > 0) lw.Add(dw);
  2769. string apdate1 = GetPostString("apdate1");
  2770. string apdate2 = GetPostString("apdate2");
  2771. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2772. if (dwap.Length > 0) lw.Add(dwap);
  2773. string price1 = GetPostString("price1");
  2774. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2775. string price2 = GetPostString("price2");
  2776. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2777. string olddownload = GetPostString("olddown");
  2778. if (olddownload == "1")
  2779. {
  2780. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2781. }
  2782. else if (olddownload == "2")
  2783. {
  2784. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2785. }
  2786. string sellermemo = GetPostString("seller_memo");
  2787. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2788. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2789. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2790. {
  2791. if (CurrentUser.User.TeamIds.Length > 0)
  2792. {
  2793. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2794. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2795. else
  2796. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2797. }
  2798. else
  2799. {
  2800. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2801. }
  2802. }
  2803. if (tid.Length <= 0)
  2804. {
  2805. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2806. }
  2807. lw.Add(string.Format("IsReturn!=3"));
  2808. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2809. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2810. string teamids = CurrentUser.User.TeamIds.ToString();
  2811. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2812. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2813. if (dt != null && dt.Rows.Count > 0)
  2814. {
  2815. foreach (DataRow dr in dt.Rows)
  2816. {
  2817. try
  2818. {
  2819. // 对象操作
  2820. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2821. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2822. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2823. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2824. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2825. if (dStruct.PageSize != 100000)
  2826. {
  2827. if (dr["DispatchSort"].ToString() == "2")
  2828. {
  2829. dr["gongchuang"] = 200;
  2830. }
  2831. else if ("外协".Equals(dr["ToType"].ToString()))
  2832. {
  2833. dr["gongchuang"] = 200;
  2834. }
  2835. else if ("内部".Equals(dr["ToType"].ToString()))
  2836. {
  2837. dr["gongchuang"] = -1;
  2838. }
  2839. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2840. {
  2841. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2842. dr["gongchuang"] = response.code;
  2843. }
  2844. }
  2845. }
  2846. catch (NullReferenceException ex)
  2847. {
  2848. }
  2849. }
  2850. }
  2851. writeGridDataTableJson(dStruct.TotalCount, dt);
  2852. }
  2853. public void set_erp_startdesign()
  2854. {
  2855. if (UrlPostParmsCheck("ctid"))
  2856. {
  2857. string eid = GetPostString("ctid");
  2858. CeErpTradeCell entity = null;
  2859. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2860. if (entity != null)
  2861. {
  2862. if (entity.OrderState != 3)
  2863. {
  2864. returnErrorMsg("请刷新,订单已经设计了");
  2865. return;
  2866. }
  2867. entity.StartDesignTime = DateTime.Now;
  2868. entity.OrderState = 4;
  2869. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2870. {
  2871. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2872. entity.SupplierId = suid;
  2873. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2874. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2875. }
  2876. entity.UpdateTime = DateTime.Now;
  2877. //entity.MakeSupplier = suname;
  2878. entity.Update();
  2879. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2880. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2881. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2882. commonHelper.getCytPrice(entity);
  2883. returnSuccessMsg("操作成功!");
  2884. return;
  2885. }
  2886. returnErrorMsg("找不到记录");
  2887. }
  2888. }
  2889. public void ins_erp_designselfmemo()
  2890. {
  2891. if (UrlPostParmsCheck("ctid"))
  2892. {
  2893. string eid = GetPostString("ctid");
  2894. string con = GetPostString("con");
  2895. CeErpTradeCell entity = null;
  2896. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2897. if (entity != null)
  2898. {
  2899. entity.DesignSelfMemo = con;
  2900. entity.Update();
  2901. returnSuccessMsg("操作成功!");
  2902. return;
  2903. }
  2904. returnErrorMsg("找不到记录");
  2905. }
  2906. }
  2907. public void ins_erp_designprice()
  2908. {
  2909. if (UrlPostParmsCheck("ctid"))
  2910. {
  2911. string eid = GetPostString("ctid");
  2912. int uid = CurrentUser.UserID;
  2913. string userName = CurrentUser.UserName;
  2914. CeErpTradeCell entity = null;
  2915. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2916. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2917. if (entitys == null)
  2918. {
  2919. entitys = new CeErpDesignerBill();
  2920. }
  2921. if (entity != null)
  2922. {
  2923. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2924. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2925. entity.StartDesignTime = DateTime.Now;
  2926. entity.OrderState = 4;
  2927. string suname = "";
  2928. if (entity.SupplierId == 0)
  2929. {
  2930. int sid = commonHelper.autoDistributeToSupplier(entity);
  2931. entity.SupplierId = sid;
  2932. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2933. }
  2934. entity.Update();
  2935. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2936. if (ceErpUserPost != null)
  2937. {
  2938. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2939. if (ceErpPost != null)
  2940. {
  2941. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2942. {
  2943. entitys.tid = entity.ctid;
  2944. entitys.oid = entity.tid;
  2945. entitys.uid = uid;
  2946. entitys.userName = userName;
  2947. entitys.designerType = 1;
  2948. entitys.designerTypeText = "内部设计师";
  2949. entitys.price = Convert.ToDouble(GetPostString("price"));
  2950. entitys.designNum = GetPostInt("designNum");
  2951. entitys.modifyNum = GetPostInt("modifyNum");
  2952. entitys.designSize = GetPostString("designSize");
  2953. entitys.modifySize = GetPostString("modifySize");
  2954. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2955. {
  2956. entitys.create_time = DateTime.Now;
  2957. entitys.create_u_id = uid;
  2958. entitys.create_u_name = userName;
  2959. entitys.Save();
  2960. }
  2961. else
  2962. {
  2963. entitys.update_time = DateTime.Now;
  2964. entitys.update_u_id = uid;
  2965. entitys.update_u_name = userName;
  2966. entitys.Update();
  2967. }
  2968. }
  2969. }
  2970. }
  2971. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2972. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2973. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2974. if (suname != "")
  2975. {
  2976. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2977. }
  2978. commonHelper.getCytPrice(entity);
  2979. returnSuccessMsg("操作成功!");
  2980. return;
  2981. }
  2982. returnErrorMsg("找不到记录");
  2983. }
  2984. }
  2985. public void upload_erp_filecomplete()
  2986. {
  2987. if (UrlPostParmsCheck("ctid"))
  2988. {
  2989. string eid = GetPostString("ctid");
  2990. CeErpTradeCell entity = null;
  2991. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2992. if (entity != null)
  2993. {
  2994. entity.OrderState = 5; //设计完成
  2995. entity.Update();
  2996. returnSuccessMsg(eid + "上传成功,设计完成!");
  2997. return;
  2998. }
  2999. returnErrorMsg("找不到订单记录");
  3000. }
  3001. }
  3002. public void get_erp_designovertimelist()
  3003. {
  3004. DataStruct dStruct = GetPostStruct();
  3005. List<string> lw = new List<string>();
  3006. string tid = GetPostString("ctid");
  3007. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3008. string shopname = GetPostString("shopname");
  3009. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3010. string buyernick = GetPostString("buyer_nick");
  3011. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3012. string ResponsibleMan = GetPostString("responsible");
  3013. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3014. string date1 = GetPostString("date1");
  3015. string date2 = GetPostString("date2");
  3016. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3017. if (dw.Length > 0) lw.Add(dw);
  3018. string price1 = GetPostString("price1");
  3019. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3020. string price2 = GetPostString("price2");
  3021. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3022. string orderState = GetPostString("orderState");
  3023. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3024. string sellermemo = GetPostString("seller_memo");
  3025. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3026. lw.Add(string.Format("UnusualTag=3"));
  3027. lw.Add(string.Format("IsRefund<={0}", 1));
  3028. dStruct.Order = "WaitDesignTime desc";
  3029. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3030. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3031. writeGridDataTableJson(dStruct.TotalCount, dt);
  3032. }
  3033. //设计管理 获取抢单大厅列表
  3034. public void get_erp_grabinglist()
  3035. {
  3036. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3037. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3038. bool oldOrder = false;
  3039. if (org != null)
  3040. {
  3041. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3042. }
  3043. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3044. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3045. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3046. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3047. //先处理订单数据
  3048. if (dt.Rows.Count > 0)
  3049. {
  3050. Dictionary<string, int> design = null;
  3051. int count = 0;
  3052. foreach (DataRow row in dt.Rows)
  3053. {
  3054. if (map.ContainsKey(row["ShopId"].ToString()))
  3055. {
  3056. map.TryGetValue(row["ShopId"].ToString(), out design);
  3057. }
  3058. else
  3059. {
  3060. design = new Dictionary<string, int>();
  3061. }
  3062. if (design.ContainsKey(row["ProductId"].ToString()))
  3063. {
  3064. design.TryGetValue(row["ProductId"].ToString(), out count);
  3065. }
  3066. count++;
  3067. design[row["ProductId"].ToString()] = count;
  3068. map[row["ShopId"].ToString()] = design;
  3069. }
  3070. }
  3071. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3072. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3073. //把店铺排序和技能排序分类
  3074. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3075. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3076. if (design_dt.Rows.Count > 0)
  3077. {
  3078. Dictionary<string, string> design = null;
  3079. List<string> shopIds = null;
  3080. foreach (DataRow row in design_dt.Rows)
  3081. {
  3082. if ("0".Equals(row["designId"].ToString()))
  3083. {
  3084. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3085. {
  3086. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3087. }
  3088. else
  3089. {
  3090. shopIds = new List<string>();
  3091. }
  3092. shopIds.Add(row["shopId"].ToString());
  3093. shop_orders[row["orders"].ToString()] = shopIds;
  3094. }
  3095. else
  3096. {
  3097. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3098. {
  3099. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3100. }
  3101. else
  3102. {
  3103. design = new Dictionary<string, string>();
  3104. }
  3105. design[row["orders"].ToString()] = row["designId"].ToString();
  3106. design_orders[row["shopId"].ToString()] = design;
  3107. }
  3108. }
  3109. //处理成key value后根据key排序
  3110. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3111. foreach (List<string> val in shop_orders.Values)
  3112. {
  3113. if (val != null)
  3114. {
  3115. foreach (string key in val)
  3116. {
  3117. if (design_orders.ContainsKey(key.ToString()))
  3118. {
  3119. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3120. }
  3121. }
  3122. }
  3123. }
  3124. }
  3125. //校验哪个优先级有订单
  3126. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3127. foreach (string key in shop_orders.Keys)
  3128. {
  3129. List<string> ids = null;
  3130. shop_orders.TryGetValue(key, out ids);
  3131. //id为shopid
  3132. foreach (string id in ids)
  3133. {
  3134. Dictionary<string, int> list = null;
  3135. Dictionary<string, string> desing = null;
  3136. map.TryGetValue(id, out list);
  3137. design_orders.TryGetValue(id, out desing);
  3138. if (list != null && desing != null)
  3139. {
  3140. foreach (var item in desing)
  3141. {
  3142. int count = 0;
  3143. if (list.ContainsKey(item.Value))
  3144. {
  3145. list.TryGetValue(item.Value, out count);
  3146. if (count > 0)
  3147. {
  3148. designIds[id] = item.Value;
  3149. break;
  3150. }
  3151. }
  3152. }
  3153. }
  3154. }
  3155. if (designIds.Count > 0)
  3156. {
  3157. break;
  3158. }
  3159. }
  3160. DataTable table = new DataTable();
  3161. table.Columns.Add("tid", typeof(string));
  3162. table.Columns.Add("ctid", typeof(string));
  3163. table.Columns.Add("seller_nick", typeof(string));
  3164. table.Columns.Add("productName", typeof(string));
  3165. table.Columns.Add("pay_time", typeof(string));
  3166. table.Columns.Add("seller_memo", typeof(string));
  3167. if (designIds.Count > 0)
  3168. {
  3169. string shopId = "";
  3170. string productId = "";
  3171. foreach (var designInfo in designIds)
  3172. {
  3173. shopId = designInfo.Key;
  3174. productId = designInfo.Value;
  3175. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3176. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3177. if (dt.Rows.Count > 0)
  3178. {
  3179. foreach (DataRow row in dt.Rows)
  3180. {
  3181. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3182. {
  3183. DataRow data = table.NewRow();
  3184. data["ctid"] = row["ctid"].ToString();
  3185. data["tid"] = row["tid"].ToString();
  3186. data["seller_nick"] = ceErpShop.ShopName;
  3187. data["pay_time"] = row["pay_time"].ToString();
  3188. data["seller_memo"] = row["seller_memo"].ToString();
  3189. data["productName"] = ceErpProduct.PType;
  3190. table.Rows.Add(data);
  3191. }
  3192. }
  3193. }
  3194. }
  3195. }
  3196. writeGridDataTableJson(table.Rows.Count, table);
  3197. }
  3198. private object rushLockObject = new object();
  3199. public void set_erp_grabingorder()
  3200. {
  3201. if (UrlPostParmsCheck("ctid"))
  3202. {
  3203. int total = CurrentUser.User.Person.Total;
  3204. int userId = CurrentUser.User.ID;
  3205. int noFinish = CurrentUser.User.Person.NoFinish;
  3206. int finalization = CurrentUser.User.Person.Finalization;
  3207. string eids = GetPostString("ctid");
  3208. string key = "RushKey_" + userId;
  3209. int count = 0;
  3210. if (erpRedis.RedisHelper.KeyExists(key))
  3211. {
  3212. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3213. if (redisCount != null)
  3214. {
  3215. count = Convert.ToInt32(redisCount);
  3216. }
  3217. }
  3218. if (count >= total)
  3219. {
  3220. returnErrorMsg("半小时内已经抢" + total + "单");
  3221. return;
  3222. }
  3223. string[] ctidlist = eids.Split(',');
  3224. if (count + ctidlist.Length > total)
  3225. {
  3226. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3227. return;
  3228. }
  3229. int itag = 0;
  3230. lock (rushLockObject)
  3231. {
  3232. if (ctidlist.Length > 0)
  3233. {
  3234. string[] dtList = new string[ctidlist.Length];
  3235. for (int i = 0; i < ctidlist.Length; i++)
  3236. {
  3237. dtList[i] = "'" + ctidlist[i] + "'";
  3238. }
  3239. 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"));
  3240. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3241. if (dt_user.Rows.Count > 0)
  3242. {
  3243. int doing = 0;//未定稿
  3244. int finish = 0;//已完成
  3245. foreach (DataRow dr in dt_user.Rows)
  3246. {
  3247. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3248. {
  3249. doing++;
  3250. }
  3251. else
  3252. {
  3253. finish++;
  3254. }
  3255. }
  3256. if (doing >= noFinish)
  3257. {
  3258. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3259. return;
  3260. }
  3261. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3262. {
  3263. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3264. return;
  3265. }
  3266. }
  3267. //校验选择单子状态
  3268. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3269. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3270. if (dt.Rows.Count > 0)
  3271. {
  3272. List<string> list = new List<string>();
  3273. foreach (DataRow dr in dt.Rows)
  3274. {
  3275. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3276. {
  3277. list.Add(dr["ctid"].ToString());
  3278. }
  3279. }
  3280. if (list.Count > 0)
  3281. {
  3282. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3283. return;
  3284. }
  3285. }
  3286. foreach (string ctid in ctidlist)
  3287. {
  3288. CeErpTradeCell entity = null;
  3289. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3290. if (entity != null)
  3291. {
  3292. entity.OrderState = 3;
  3293. entity.DesignUserId = CurrentUser.UserID;
  3294. entity.WaitDesignTime = DateTime.Now;
  3295. entity.StartDesignTime = DateTime.Now;
  3296. entity.Update();
  3297. commonHelper.UpdateRelationOrder(entity.ctid);
  3298. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3299. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3300. itag++;
  3301. }
  3302. }
  3303. }
  3304. }
  3305. count += ctidlist.Length;
  3306. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3307. if (itag == 0)
  3308. returnErrorMsg("没有找到相关订单");
  3309. else
  3310. returnSuccessMsg("抢单成功!");
  3311. return;
  3312. }
  3313. }
  3314. public void get_erp_waitorderlist()
  3315. {
  3316. DataStruct dStruct = GetPostStruct();
  3317. List<string> lw = new List<string>();
  3318. string tid = GetPostString("ctid");
  3319. if (tid.Length > 0)
  3320. {
  3321. string select_tid = getTidByCtid(tid);
  3322. lw.Add(string.Format("tid='{0}'", select_tid));
  3323. }
  3324. string shopname = GetPostString("shopname");
  3325. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3326. string buyernick = GetPostString("buyer_nick");
  3327. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3328. string customer = GetPostString("customer");
  3329. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3330. string design = GetPostString("design");
  3331. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3332. string orderState = GetPostString("orderState");
  3333. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3334. string supplier = GetPostString("supplier");
  3335. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3336. string sellermemo = GetPostString("seller_memo");
  3337. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3338. string otherMemo = GetPostString("otherMemo");
  3339. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3340. string address = GetPostString("address");
  3341. 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));
  3342. string date1 = GetPostString("date1");
  3343. string date2 = GetPostString("date2");
  3344. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3345. if (dw.Length > 0) lw.Add(dw);
  3346. string price1 = GetPostString("price1");
  3347. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3348. string price2 = GetPostString("price2");
  3349. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3350. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3351. lw.Add(string.Format("IsSample != 2 "));
  3352. lw.Add(string.Format("OrderState = 5 "));
  3353. lw.Add(string.Format("IsRefund<={0}", 1));
  3354. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3355. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3356. string pagesize = GetPostString("pagesize");
  3357. if (pagesize != null)
  3358. {
  3359. dStruct.PageSize = 200;
  3360. }
  3361. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3362. if (dt != null)
  3363. {
  3364. foreach (DataRow dr in dt.Rows)
  3365. {
  3366. 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();
  3367. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3368. {
  3369. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3370. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3371. entity.SupplierId = suid;
  3372. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3373. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3374. entity.Update();
  3375. }
  3376. }
  3377. }
  3378. writeGridDataTableJson(dStruct.TotalCount, dt);
  3379. }
  3380. public void get_erp_supplierwaitorderlist()
  3381. {
  3382. DataStruct dStruct = GetPostStruct();
  3383. List<string> lw = new List<string>();
  3384. string tid = GetPostString("ctid");
  3385. if (tid.Length > 0)
  3386. {
  3387. string select_tid = getTidByCtid(tid);
  3388. lw.Add(string.Format("tid='{0}'", select_tid));
  3389. }
  3390. string shopname = GetPostString("shopname");
  3391. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3392. string sellermemo = GetPostString("seller_memo");
  3393. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3394. string date1 = GetPostString("date1");
  3395. string date2 = GetPostString("date2");
  3396. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3397. if (dw.Length > 0) lw.Add(dw);
  3398. lw.Add(string.Format("OrderState = 5 "));
  3399. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3400. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3401. {
  3402. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3403. }
  3404. string supplier = GetPostString("supplier");
  3405. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3406. {
  3407. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3408. }
  3409. lw.Add(string.Format("IsRefund<={0}", 1));
  3410. dStruct.Order = "FinishDesignTime desc";
  3411. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3412. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3413. if (dt != null)
  3414. {
  3415. foreach (DataRow dr in dt.Rows)
  3416. {
  3417. 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();
  3418. }
  3419. }
  3420. writeGridDataTableJson(dStruct.TotalCount, dt);
  3421. }
  3422. public void upd_erp_verifytosupplier()
  3423. {
  3424. if (UrlPostParmsCheck("ctid"))
  3425. {
  3426. string eids = GetPostString("ctid");
  3427. CeErpTradeCell entity = null;
  3428. string[] eidsList = eids.Split(',');
  3429. if (eidsList.Length <= 0)
  3430. {
  3431. returnErrorMsg("订单号不能空");
  3432. return;
  3433. }
  3434. List<string> tLst = new List<string>();
  3435. foreach (string ctidstr in eidsList)
  3436. {
  3437. tLst.Add("'" + ctidstr + "'");
  3438. CeErpDataSendOrderInfo.createObject(ctidstr);
  3439. }
  3440. string needtids = string.Join(",", tLst.ToArray());
  3441. StringBuilder sql = new StringBuilder();
  3442. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3443. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3444. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3445. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3446. returnSuccessMsg("操作成功!");
  3447. return;
  3448. /**foreach (string ctidstr in eidsList)
  3449. {
  3450. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3451. if (entity != null)
  3452. {
  3453. if (entity.SupplierId == 0)
  3454. {
  3455. continue;
  3456. }
  3457. entity.IsVerifyToSupplier = true;
  3458. if (entity.IsReturn == 1) //1是供应商打回
  3459. {
  3460. entity.IsReturn = 0;
  3461. }
  3462. entity.FinishPlaceTime = DateTime.Now;
  3463. entity.PlaceUserId = CurrentUser.UserID;
  3464. entity.Update();
  3465. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3466. }
  3467. }
  3468. returnSuccessMsg("操作成功!");
  3469. return;**/
  3470. }
  3471. }
  3472. public void upd_erp_supplierback()
  3473. {
  3474. if (UrlPostParmsCheck("ctid"))
  3475. {
  3476. string eid = GetPostString("ctid");
  3477. string reason = GetPostString("returnreason");
  3478. CeErpTradeCell entity = null;
  3479. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3480. if (entity != null)
  3481. {
  3482. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3483. {
  3484. string key = "return_order_" + entity.SupplierId;
  3485. List<string> list = new List<string>();
  3486. if (RedisHelper.HasKey(key))
  3487. {
  3488. object data = RedisHelper.StringGet(key);
  3489. list = Convert.ToString(data).Split(',').ToList();
  3490. }
  3491. list.Add(eid);
  3492. RedisHelper.StringSet(key, string.Join(",", list));
  3493. }
  3494. entity.IsVerifyToSupplier = false;
  3495. entity.IsReturn = 1;
  3496. entity.ReturnTime = DateTime.Now;
  3497. entity.ReturnReason = reason;
  3498. if (entity.OrderState == 6)
  3499. {
  3500. entity.OrderState = 5;
  3501. }
  3502. entity.Update();
  3503. CeErpSukuraData.createInfo(entity.ctid, 5);
  3504. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3505. returnSuccessMsg("操作成功!");
  3506. return;
  3507. }
  3508. returnErrorMsg("找不到订单记录");
  3509. }
  3510. }
  3511. public void upd_erp_toaftersaleorder()
  3512. {
  3513. if (UrlPostParmsCheck("ctid"))
  3514. {
  3515. string eid = GetPostString("ctid");
  3516. string reason = GetPostString("returnreason");
  3517. CeErpTradeCell entity = null;
  3518. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3519. if (entity != null)
  3520. {
  3521. if (entity.isAfterSaleOrder != 1)
  3522. {
  3523. returnErrorMsg("带S的售后单才能打回给售后");
  3524. return;
  3525. }
  3526. if (entity.OrderState >= 5)
  3527. {
  3528. returnErrorMsg("已经设计完成了不能打回给售后");
  3529. return;
  3530. }
  3531. entity.OrderState = 0;
  3532. entity.IsReturn = 3;
  3533. entity.ReturnTime = DateTime.Now;
  3534. entity.UpdateTime = DateTime.Now;
  3535. entity.ReturnReason = reason;
  3536. entity.Update();
  3537. CeErpSukuraData.createInfo(entity.ctid, 5);
  3538. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3539. returnSuccessMsg("操作成功!");
  3540. return;
  3541. }
  3542. returnErrorMsg("找不到订单记录");
  3543. }
  3544. }
  3545. public void upd_erp_aftersaletodesign()
  3546. {
  3547. if (UrlPostParmsCheck("ctid"))
  3548. {
  3549. string eid = GetPostString("ctid");
  3550. CeErpTradeCell entity = null;
  3551. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3552. if (entity != null)
  3553. {
  3554. entity.OrderState = 3;
  3555. entity.IsReturn = 0;
  3556. entity.UpdateTime = DateTime.Now;
  3557. entity.Update();
  3558. CeErpSukuraData.createInfo(entity.ctid, 5);
  3559. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3560. returnSuccessMsg("操作成功!");
  3561. return;
  3562. }
  3563. returnErrorMsg("找不到订单记录");
  3564. }
  3565. }
  3566. public void assign_erp_supplier()
  3567. {
  3568. if (UrlPostParmsCheck("ctid"))
  3569. {
  3570. string eids = GetPostString("ctid");
  3571. int sid = GetPostInt("SupplierName");
  3572. string fromTag = GetPostString("tag");
  3573. string[] eidList = eids.Split(',');
  3574. if (eidList.Length <= 0)
  3575. {
  3576. returnErrorMsg("指派不能为空");
  3577. return;
  3578. }
  3579. string errMsg = "";
  3580. string suname = commonHelper.getSupplierNameById(sid);
  3581. foreach (string ctid in eidList)
  3582. {
  3583. CeErpTradeCell entity = null;
  3584. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3585. if (entity != null)
  3586. {
  3587. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3588. {
  3589. errMsg += (ctid + "指派失败!!!");
  3590. continue;
  3591. }
  3592. entity.SupplierId = sid;
  3593. entity.Update();
  3594. commonHelper.UpdateRelationOrder(entity.ctid);
  3595. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3596. if (entity.OrderState >= 6)
  3597. {
  3598. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3599. //{
  3600. // string msl = entity.MakeSupplier;
  3601. // string[] mslist = msl.Split(',');
  3602. // 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);
  3603. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3604. //}
  3605. //else
  3606. //{
  3607. StringBuilder sql = new StringBuilder();
  3608. 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);
  3609. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3610. //}
  3611. }
  3612. }
  3613. else
  3614. {
  3615. continue;
  3616. }
  3617. }
  3618. if (errMsg.Length > 0)
  3619. {
  3620. returnErrorMsg(errMsg);
  3621. return;
  3622. }
  3623. returnSuccessMsg("操作成功!");
  3624. return;
  3625. }
  3626. }
  3627. public void assign_erp_makesupplier()
  3628. {
  3629. if (UrlPostParmsCheck("ctid"))
  3630. {
  3631. string eids = GetPostString("ctid");
  3632. string sname = GetPostString("SupplierName");
  3633. string[] eidList = eids.Split(',');
  3634. if (eidList.Length <= 0)
  3635. {
  3636. returnErrorMsg("指派不能为空");
  3637. return;
  3638. }
  3639. List<string> tLst = new List<string>();
  3640. foreach (string ctid in eidList)
  3641. {
  3642. CeErpTradeCell entity = null;
  3643. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3644. if (entity != null)
  3645. {
  3646. entity.MakeSupplier = sname;
  3647. entity.Update();
  3648. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3649. tLst.Add("'" + ctid + "'");
  3650. }
  3651. else
  3652. {
  3653. continue;
  3654. }
  3655. }
  3656. string ctids = string.Join(",", tLst.ToArray());
  3657. StringBuilder sql2 = new StringBuilder();
  3658. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3659. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3660. returnSuccessMsg("操作成功!");
  3661. return;
  3662. }
  3663. }
  3664. public void ins_erp_returnreason()
  3665. {
  3666. if (UrlPostParmsCheck("ctid"))
  3667. {
  3668. string eid = GetPostString("ctid");
  3669. CeErpTradeCell entity = null;
  3670. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3671. string userpost = CurrentUser.UserPost.Post.Code;
  3672. if (entity != null)
  3673. {
  3674. bool isPlace = false;
  3675. if (entity.OrderState > 6)
  3676. {
  3677. returnErrorMsg("已发货无法打回!");
  3678. return;
  3679. }
  3680. if (entity.OrderState == 6)
  3681. {
  3682. isPlace = true;
  3683. }
  3684. bool isNeedUpdateCell2 = false;
  3685. if (entity.OrderState >= 6)
  3686. {
  3687. isNeedUpdateCell2 = true;
  3688. }
  3689. int returnTag = 2;
  3690. if (userpost == "Supplier")
  3691. {
  3692. returnTag = 1;
  3693. }
  3694. int toType = GetPostInt("totype");
  3695. string fromType = "3";
  3696. if (entity.OrderState < 5)
  3697. {
  3698. fromType = "3";
  3699. }
  3700. else
  3701. {
  3702. fromType = "4";
  3703. }
  3704. if (entity.IsXianHuo == 0)
  3705. {
  3706. if (returnTag == 2)
  3707. {
  3708. if (toType == 1)
  3709. {
  3710. entity.OrderState = 0;
  3711. entity.ReturnUserType = 1;
  3712. string clearman = GetPostString("clearman");
  3713. if (!string.IsNullOrEmpty(clearman))
  3714. {
  3715. entity.DesignUserId = 0;
  3716. }
  3717. }
  3718. else
  3719. {
  3720. entity.OrderState = 3;
  3721. entity.ReturnUserType = 2;
  3722. }
  3723. entity.IsReadTag = 1;
  3724. }
  3725. else if (returnTag == 1)
  3726. {
  3727. entity.OrderState = 5;
  3728. }
  3729. entity.IsVerifyToSupplier = false;
  3730. }
  3731. if (entity.IsXianHuo == 1)
  3732. {
  3733. entity.OrderState = 5;
  3734. }
  3735. entity.UnusualTag = 0;
  3736. entity.UnusualTime = null;
  3737. entity.UnusualCon = "";
  3738. entity.IsReturn = returnTag;
  3739. entity.ReturnTime = DateTime.Now;
  3740. entity.UpdateTime = DateTime.Now;
  3741. entity.ReturnReason = GetPostString("returnreason");
  3742. entity.Update();
  3743. if (entity.OrderState == 3)
  3744. {
  3745. ApiVo apiVo = new ApiVo();
  3746. apiVo.orderNumber = entity.ctid;
  3747. apiVo.actionName = "rebutDesign";
  3748. apiVo.orderRemarks = entity.ReturnReason;
  3749. designHelper.API_WorkCore(apiVo);//rebutDesign
  3750. }
  3751. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3752. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3753. {
  3754. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3755. }
  3756. CeErpSukuraData.createInfo(entity.ctid, 5);
  3757. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3758. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3759. if (isPlace)
  3760. {
  3761. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3762. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3763. if (dth != null && dth.Rows.Count > 0)
  3764. {
  3765. dataSendOrderBean dataSendOrderBean = null;
  3766. foreach (DataRow item in dth.Rows)
  3767. {
  3768. try
  3769. {
  3770. dataSendOrderBean = new dataSendOrderBean();
  3771. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3772. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3773. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3774. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3775. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3776. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3777. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3778. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3779. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3780. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3781. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3782. dataSendOrderBean.Radio1723534706288 = "打回";
  3783. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3784. if (result != null)
  3785. {
  3786. if ("0".Equals(result.errcode))
  3787. {
  3788. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3789. }
  3790. else
  3791. {
  3792. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3793. }
  3794. }
  3795. }
  3796. catch (Exception ex)
  3797. {
  3798. }
  3799. }
  3800. }
  3801. }
  3802. if (isNeedUpdateCell2)
  3803. {
  3804. if (entity.MakeSupplier.IndexOf(",") != -1)
  3805. {
  3806. StringBuilder sql2 = new StringBuilder();
  3807. 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);
  3808. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3809. }
  3810. else
  3811. {
  3812. StringBuilder sql2 = new StringBuilder();
  3813. 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);
  3814. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3815. }
  3816. }
  3817. returnSuccessMsg("操作成功!");
  3818. return;
  3819. }
  3820. returnErrorMsg("找不到订单记录");
  3821. }
  3822. }
  3823. public void cyt_erp_returnreason()
  3824. {
  3825. if (UrlPostParmsCheck("ctid"))
  3826. {
  3827. string eid = GetPostString("ctid");
  3828. CeErpTradeCell entity = null;
  3829. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3830. string userpost = CurrentUser.UserPost.Post.Code;
  3831. if (entity != null)
  3832. {
  3833. if (entity.OrderState > 6)
  3834. {
  3835. returnErrorMsg("已发货无法打回!");
  3836. return;
  3837. }
  3838. JObject jsonObject = new JObject
  3839. {
  3840. { "Userid", "77886" },
  3841. { "Pwd", "lt666888" },
  3842. { "LTOrderId",eid }
  3843. };
  3844. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3845. JObject jsonObjects = JObject.Parse(response);
  3846. string msg = (string)jsonObjects["msg"];
  3847. if (msg != "取消成功")
  3848. {
  3849. returnErrorMsg(msg);
  3850. return;
  3851. }
  3852. bool isNeedUpdateCell2 = false;
  3853. if (entity.OrderState >= 6)
  3854. {
  3855. isNeedUpdateCell2 = true;
  3856. }
  3857. int returnTag = 2;
  3858. if (userpost == "Supplier")
  3859. {
  3860. returnTag = 1;
  3861. }
  3862. if (entity.IsXianHuo == 0)
  3863. {
  3864. if (returnTag == 2)
  3865. {
  3866. int toType = GetPostInt("totype");
  3867. if (toType == 1)
  3868. {
  3869. entity.OrderState = 0;
  3870. entity.ReturnUserType = 1;
  3871. }
  3872. else
  3873. {
  3874. entity.OrderState = 4;
  3875. entity.ReturnUserType = 2;
  3876. }
  3877. entity.IsReadTag = 1;
  3878. }
  3879. else if (returnTag == 1)
  3880. {
  3881. entity.OrderState = 5;
  3882. }
  3883. entity.IsVerifyToSupplier = false;
  3884. }
  3885. entity.UnusualTag = 0;
  3886. entity.UnusualTime = null;
  3887. entity.UnusualCon = "";
  3888. entity.IsReturn = returnTag;
  3889. entity.ReturnTime = DateTime.Now;
  3890. entity.ReturnReason = GetPostString("returnreason");
  3891. entity.Update();
  3892. if (entity.OrderState == 4)
  3893. {
  3894. ApiVo apiVo = new ApiVo();
  3895. apiVo.orderNumber = entity.ctid;
  3896. apiVo.actionName = "rebutDesign";
  3897. apiVo.orderRemarks = entity.ReturnReason;
  3898. designHelper.API_WorkCore(apiVo);//rebutDesign
  3899. }
  3900. CeErpSukuraData.createInfo(entity.ctid, 5);
  3901. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3902. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3903. if (isNeedUpdateCell2)
  3904. {
  3905. if (entity.MakeSupplier.IndexOf(",") != -1)
  3906. {
  3907. StringBuilder sql2 = new StringBuilder();
  3908. 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);
  3909. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3910. }
  3911. else
  3912. {
  3913. StringBuilder sql2 = new StringBuilder();
  3914. 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);
  3915. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3916. }
  3917. }
  3918. returnSuccessMsg("操作成功!");
  3919. return;
  3920. }
  3921. returnErrorMsg("找不到订单记录");
  3922. }
  3923. }
  3924. public void upd_erp_xianhuoreturntag()
  3925. {
  3926. if (UrlPostParmsCheck("ctid"))
  3927. {
  3928. string eids = GetPostString("ctid");
  3929. string[] ctids = eids.Split(',');
  3930. foreach (string ctid in ctids)
  3931. {
  3932. CeErpTradeCell entity = null;
  3933. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3934. if (entity != null)
  3935. {
  3936. entity.IsReturn = 0;
  3937. entity.Update();
  3938. CeErpSukuraData.createInfo(entity.ctid, 5);
  3939. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3940. }
  3941. }
  3942. returnSuccessMsg("操作成功!");
  3943. return;
  3944. }
  3945. }
  3946. public void get_erp_waitdeliverylist()
  3947. {
  3948. DataStruct dStruct = GetPostStruct();
  3949. List<string> lw = new List<string>();
  3950. string tid = GetPostString("ctid");
  3951. if (tid.Length > 0)
  3952. {
  3953. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3954. if (tid.Length > 5)
  3955. {
  3956. List<string> tids = getTidByCtidLike(tid);
  3957. if (tids.Count > 0 && tids.Count < 10)
  3958. {
  3959. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3960. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  3961. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  3962. {
  3963. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  3964. }
  3965. }
  3966. }
  3967. lw.Add(tid_sql);
  3968. }
  3969. string shopname = GetPostString("shopname");
  3970. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3971. string buyernick = GetPostString("buyer_nick");
  3972. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3973. //if (tid.Length == 0 && buyernick.Length == 0)
  3974. //{
  3975. // lw.Add(string.Format("IsRefund<={0}", 1));
  3976. //}
  3977. string customer = GetPostString("customer");
  3978. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3979. string design = GetPostString("design");
  3980. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3981. string orderState = GetPostString("orderState");
  3982. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3983. string address = GetPostString("address");
  3984. 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));
  3985. string sellermemo = GetPostString("seller_memo");
  3986. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3987. string supplier = GetPostString("supplier");
  3988. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3989. string OrderArea = GetPostString("order_area");
  3990. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3991. string placedate1 = GetPostString("placedate1");
  3992. string placedate2 = GetPostString("placedate2");
  3993. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3994. if (fdw.Length > 0) lw.Add(fdw);
  3995. string price1 = GetPostString("price1");
  3996. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3997. string price2 = GetPostString("price2");
  3998. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3999. string unusualCon = GetPostString("unusualcon");
  4000. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4001. string otherMemo = GetPostString("otherMemo");
  4002. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4003. string posTag = CurrentUser.UserPost.Post.Code;
  4004. if (posTag == "Supplier")
  4005. {
  4006. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4007. }
  4008. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4009. lw.Add(string.Format("type != 'PDD' "));
  4010. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4011. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4012. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4013. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4014. writeGridDataTableJson(dStruct.TotalCount, dt);
  4015. }
  4016. public void get_erp_changedeliverylist()
  4017. {
  4018. DataStruct dStruct = GetPostStruct();
  4019. List<string> lw = new List<string>();
  4020. string tid = GetPostString("ctid");
  4021. if (tid.Length > 0)
  4022. {
  4023. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4024. if (tid.Length > 5)
  4025. {
  4026. List<string> tids = getTidByCtidLike(tid);
  4027. if (tids.Count > 0 && tids.Count < 10)
  4028. {
  4029. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4030. }
  4031. }
  4032. lw.Add(tid_sql);
  4033. }
  4034. string shopname = GetPostString("shopname");
  4035. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4036. string buyernick = GetPostString("buyer_nick");
  4037. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4038. //if (tid.Length == 0 && buyernick.Length == 0)
  4039. //{
  4040. // lw.Add(string.Format("IsRefund<={0}", 1));
  4041. //}
  4042. string customer = GetPostString("customer");
  4043. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4044. string design = GetPostString("design");
  4045. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4046. string orderState = GetPostString("orderState");
  4047. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4048. string address = GetPostString("address");
  4049. 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));
  4050. string sellermemo = GetPostString("seller_memo");
  4051. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4052. string supplier = GetPostString("supplier");
  4053. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4054. string OrderArea = GetPostString("order_area");
  4055. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4056. string placedate1 = GetPostString("placedate1");
  4057. string placedate2 = GetPostString("placedate2");
  4058. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4059. if (fdw.Length > 0) lw.Add(fdw);
  4060. string price1 = GetPostString("price1");
  4061. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4062. string price2 = GetPostString("price2");
  4063. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4064. string unusualCon = GetPostString("unusualcon");
  4065. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4066. string otherMemo = GetPostString("otherMemo");
  4067. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4068. string posTag = CurrentUser.UserPost.Post.Code;
  4069. if (posTag == "Supplier")
  4070. {
  4071. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4072. }
  4073. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4074. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4075. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4076. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4077. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4078. /*if (tid.Length > 0)
  4079. {
  4080. List<string> tids = new List<string>();
  4081. if (dt != null && dt.Rows.Count > 0)
  4082. {
  4083. foreach (DataRow item in dt.Rows)
  4084. {
  4085. tids.Add("'" + item["tid"] + "'");
  4086. }
  4087. }
  4088. if (tids.Count > 0)
  4089. {
  4090. lw.RemoveAt(0);
  4091. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4092. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4093. dt = WebCache.GetData("view_erptradecell", dStruct);
  4094. }
  4095. }*/
  4096. writeGridDataTableJson(dStruct.TotalCount, dt);
  4097. }
  4098. public void get_erp_pddderiving()
  4099. {
  4100. DataStruct dStruct = GetPostStruct();
  4101. List<string> lw = new List<string>();
  4102. string tid = GetPostString("ctid");
  4103. if (tid.Length > 0)
  4104. {
  4105. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4106. if (tid.Length > 5)
  4107. {
  4108. List<string> tids = getTidByCtidLike(tid);
  4109. if (tids.Count > 0 && tids.Count < 10)
  4110. {
  4111. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4112. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4113. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4114. {
  4115. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4116. }
  4117. }
  4118. }
  4119. lw.Add(tid_sql);
  4120. }
  4121. string shopname = GetPostString("shopname");
  4122. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4123. string buyernick = GetPostString("buyer_nick");
  4124. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4125. //if (tid.Length == 0 && buyernick.Length == 0)
  4126. //{
  4127. // lw.Add(string.Format("IsRefund<={0}", 1));
  4128. //}
  4129. string customer = GetPostString("customer");
  4130. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4131. string design = GetPostString("design");
  4132. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4133. string orderState = GetPostString("orderState");
  4134. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4135. string address = GetPostString("address");
  4136. 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));
  4137. string sellermemo = GetPostString("seller_memo");
  4138. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4139. string supplier = GetPostString("supplier");
  4140. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4141. string OrderArea = GetPostString("order_area");
  4142. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4143. string placedate1 = GetPostString("placedate1");
  4144. string placedate2 = GetPostString("placedate2");
  4145. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4146. if (fdw.Length > 0) lw.Add(fdw);
  4147. string price1 = GetPostString("price1");
  4148. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4149. string price2 = GetPostString("price2");
  4150. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4151. string unusualCon = GetPostString("unusualcon");
  4152. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4153. string posTag = CurrentUser.UserPost.Post.Code;
  4154. if (posTag == "Supplier")
  4155. {
  4156. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4157. }
  4158. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4159. lw.Add(string.Format("type = 'PDD' "));
  4160. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4161. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4162. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4163. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4164. /*if (tid.Length > 0)
  4165. {
  4166. List<string> tids = new List<string>();
  4167. if (dt != null && dt.Rows.Count > 0)
  4168. {
  4169. foreach (DataRow item in dt.Rows)
  4170. {
  4171. tids.Add("'" + item["tid"] + "'");
  4172. }
  4173. }
  4174. if (tids.Count > 0)
  4175. {
  4176. lw.RemoveAt(0);
  4177. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4178. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4179. dt = WebCache.GetData("view_erptradecell", dStruct);
  4180. }
  4181. }*/
  4182. writeGridDataTableJson(dStruct.TotalCount, dt);
  4183. }
  4184. public void get_erp_jdderiving()
  4185. {
  4186. DataStruct dStruct = GetPostStruct();
  4187. List<string> lw = new List<string>();
  4188. string tid = GetPostString("ctid");
  4189. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4190. string shopname = GetPostString("shopname");
  4191. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4192. string buyernick = GetPostString("buyer_nick");
  4193. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4194. //if (tid.Length == 0 && buyernick.Length == 0)
  4195. //{
  4196. // lw.Add(string.Format("IsRefund<={0}", 1));
  4197. //}
  4198. string customer = GetPostString("customer");
  4199. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4200. string design = GetPostString("design");
  4201. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4202. string orderState = GetPostString("orderState");
  4203. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4204. string address = GetPostString("address");
  4205. 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));
  4206. string sellermemo = GetPostString("seller_memo");
  4207. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4208. string supplier = GetPostString("supplier");
  4209. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4210. string OrderArea = GetPostString("order_area");
  4211. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4212. string placedate1 = GetPostString("placedate1");
  4213. string placedate2 = GetPostString("placedate2");
  4214. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4215. if (fdw.Length > 0) lw.Add(fdw);
  4216. string price1 = GetPostString("price1");
  4217. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4218. string price2 = GetPostString("price2");
  4219. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4220. string unusualCon = GetPostString("unusualcon");
  4221. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4222. string posTag = CurrentUser.UserPost.Post.Code;
  4223. if (posTag == "Supplier")
  4224. {
  4225. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4226. }
  4227. lw.Add(string.Format("OrderState = 6 "));
  4228. lw.Add(string.Format("type = 'JD' "));
  4229. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4230. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4231. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4232. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4233. writeGridDataTableJson(dStruct.TotalCount, dt);
  4234. }
  4235. public void get_erp_demoorderlist()
  4236. {
  4237. DataStruct dStruct = GetPostStruct();
  4238. List<string> lw = new List<string>();
  4239. string tid = GetPostString("ctid");
  4240. if (tid.Length > 0)
  4241. {
  4242. string select_tid = getTidByCtid(tid);
  4243. lw.Add(string.Format("tid='{0}'", select_tid));
  4244. }
  4245. string shopname = GetPostString("shopname");
  4246. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4247. string buyernick = GetPostString("buyer_nick");
  4248. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  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("address 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 date1 = GetPostString("date1");
  4264. string date2 = GetPostString("date2");
  4265. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4266. if (dw.Length > 0) lw.Add(dw);
  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 posTag = CurrentUser.UserPost.Post.Code;
  4272. if (posTag == "Supplier")
  4273. {
  4274. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4275. }
  4276. //lw.Add(string.Format("OrderState = 6 "));
  4277. lw.Add(string.Format("IsSample={0}", 3));
  4278. lw.Add(string.Format("IsRefund<={0}", 1));
  4279. dStruct.Order = "pay_time desc";
  4280. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4281. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4282. writeGridDataTableJson(dStruct.TotalCount, dt);
  4283. }
  4284. public void save_erp_checkmemo()
  4285. {
  4286. if (UrlPostParmsCheck("ctid"))
  4287. {
  4288. string ctid = GetPostString("ctid");
  4289. CeErpTradeCell entity = null;
  4290. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4291. if (entity != null)
  4292. {
  4293. entity.CheckMemo = GetPostString("CheckMemo");
  4294. entity.Update();
  4295. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4296. if (trade != null)
  4297. {
  4298. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4299. }
  4300. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4301. returnSuccessMsg("保存成功!");
  4302. return;
  4303. }
  4304. returnErrorMsg("找不到记录");
  4305. }
  4306. }
  4307. public void get_erp_returnlist()
  4308. {
  4309. DataStruct dStruct = GetPostStruct();
  4310. List<string> lw = new List<string>();
  4311. string tid = GetPostString("ctid");
  4312. if (tid.Length > 0)
  4313. {
  4314. string select_tid = getTidByCtid(tid);
  4315. lw.Add(string.Format("tid='{0}'", select_tid));
  4316. }
  4317. string shopname = GetPostString("shopname");
  4318. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4319. string buyernick = GetPostString("buyer_nick");
  4320. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4321. string customer = GetPostString("customer");
  4322. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4323. string design = GetPostString("design");
  4324. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4325. string orderState = GetPostString("orderState");
  4326. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4327. string address = GetPostString("address");
  4328. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4329. string sellermemo = GetPostString("seller_memo");
  4330. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4331. string supplier = GetPostString("supplier");
  4332. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4333. string date1 = GetPostString("date1");
  4334. string date2 = GetPostString("date2");
  4335. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4336. if (dw.Length > 0) lw.Add(dw);
  4337. string bdate1 = GetPostString("backdate1");
  4338. string bdate2 = GetPostString("backdate2");
  4339. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4340. if (dw_back.Length > 0) lw.Add(dw_back);
  4341. string price1 = GetPostString("price1");
  4342. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4343. string price2 = GetPostString("price2");
  4344. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4345. lw.Add(string.Format("IsReturn>0"));
  4346. lw.Add(string.Format("IsXianHuo=0"));
  4347. lw.Add(string.Format("IsReturn!=3"));
  4348. string backtype = GetPostString("backtype");
  4349. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4350. dStruct.Order = "FinishDesignTime 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_today_sumreturn()
  4356. {
  4357. DataStruct dStruct = GetPostStruct();
  4358. List<string> lw = new List<string>();
  4359. string bdate1 = GetPostString("returnTimeS");
  4360. string bdate2 = GetPostString("returnTimeE");
  4361. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4362. if (dw_back.Length > 0) lw.Add(dw_back);
  4363. lw.Add(string.Format("IsReturn=0"));
  4364. lw.Add(string.Format("IsXianHuo=0"));
  4365. string mainWhere = string.Join(" and ", lw.ToArray());
  4366. string sql = "";
  4367. if (dw_back.Length > 0)
  4368. {
  4369. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4370. }
  4371. else
  4372. {
  4373. 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 + "'";
  4374. }
  4375. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4376. decimal total = 0, today_finish = 0;
  4377. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4378. {
  4379. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4380. }
  4381. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4382. {
  4383. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4384. }
  4385. var res = new
  4386. {
  4387. data = total,
  4388. data1 = today_finish,
  4389. };
  4390. string ro_jsond = JsonConvert.SerializeObject(res);
  4391. returnSuccess(ro_jsond);
  4392. return;
  4393. }
  4394. public void get_erp_allreturnlist()
  4395. {
  4396. DataStruct dStruct = GetPostStruct();
  4397. List<string> lw = new List<string>();
  4398. string tid = GetPostString("ctid");
  4399. if (tid.Length > 0)
  4400. {
  4401. string select_tid = getTidByCtid(tid);
  4402. lw.Add(string.Format("tid='{0}'", select_tid));
  4403. }
  4404. string shopname = GetPostString("shopname");
  4405. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4406. string buyernick = GetPostString("buyer_nick");
  4407. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4408. string customer = GetPostString("customer");
  4409. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4410. string design = GetPostString("design");
  4411. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4412. string orderState = GetPostString("orderState");
  4413. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4414. string address = GetPostString("address");
  4415. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4416. string sellermemo = GetPostString("seller_memo");
  4417. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4418. string supplier = GetPostString("supplier");
  4419. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4420. string date1 = GetPostString("date1");
  4421. string date2 = GetPostString("date2");
  4422. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4423. if (dw.Length > 0) lw.Add(dw);
  4424. string bdate1 = GetPostString("backdate1");
  4425. string bdate2 = GetPostString("backdate2");
  4426. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4427. if (dw_back.Length > 0) lw.Add(dw_back);
  4428. string price1 = GetPostString("price1");
  4429. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4430. string price2 = GetPostString("price2");
  4431. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4432. string backreason = GetPostString("backreason");
  4433. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4434. lw.Add(string.Format("IsXianHuo=0"));
  4435. lw.Add(string.Format("ReturnTime != ''"));
  4436. string backtype = GetPostString("backtype");
  4437. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4438. dStruct.Order = "FinishDesignTime desc";
  4439. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4440. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4441. writeGridDataTableJson(dStruct.TotalCount, dt);
  4442. }
  4443. public void get_erp_aftersalereturnlist()
  4444. {
  4445. DataStruct dStruct = GetPostStruct();
  4446. List<string> lw = new List<string>();
  4447. string tid = GetPostString("ctid");
  4448. if (tid.Length > 0)
  4449. {
  4450. string select_tid = getTidByCtid(tid);
  4451. lw.Add(string.Format("tid='{0}'", select_tid));
  4452. }
  4453. string shopname = GetPostString("shopname");
  4454. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4455. string buyernick = GetPostString("buyer_nick");
  4456. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4457. string customer = GetPostString("customer");
  4458. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4459. string design = GetPostString("design");
  4460. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4461. string orderState = GetPostString("orderState");
  4462. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4463. string address = GetPostString("address");
  4464. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4465. string sellermemo = GetPostString("seller_memo");
  4466. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4467. string supplier = GetPostString("supplier");
  4468. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4469. string date1 = GetPostString("date1");
  4470. string date2 = GetPostString("date2");
  4471. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4472. if (dw.Length > 0) lw.Add(dw);
  4473. string bdate1 = GetPostString("backdate1");
  4474. string bdate2 = GetPostString("backdate2");
  4475. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4476. if (dw_back.Length > 0) lw.Add(dw_back);
  4477. string price1 = GetPostString("price1");
  4478. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4479. string price2 = GetPostString("price2");
  4480. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4481. lw.Add(string.Format("IsReturn=3"));
  4482. string backtype = GetPostString("backtype");
  4483. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4484. string backreason = GetPostString("backreason");
  4485. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4486. dStruct.Order = "ReturnTime desc";
  4487. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4488. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4489. writeGridDataTableJson(dStruct.TotalCount, dt);
  4490. }
  4491. public void get_erp_xianhuoreturnlist()
  4492. {
  4493. DataStruct dStruct = GetPostStruct();
  4494. List<string> lw = new List<string>();
  4495. string tid = GetPostString("ctid");
  4496. if (tid.Length > 0)
  4497. {
  4498. string select_tid = getTidByCtid(tid);
  4499. lw.Add(string.Format("tid='{0}'", select_tid));
  4500. }
  4501. string shopname = GetPostString("shopname");
  4502. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4503. string buyernick = GetPostString("buyer_nick");
  4504. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4505. string customer = GetPostString("customer");
  4506. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4507. string design = GetPostString("design");
  4508. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4509. string orderState = GetPostString("orderState");
  4510. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4511. string address = GetPostString("address");
  4512. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4513. string sellermemo = GetPostString("seller_memo");
  4514. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4515. string supplier = GetPostString("supplier");
  4516. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4517. string OrderArea = GetPostString("order_area");
  4518. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4519. string date1 = GetPostString("date1");
  4520. string date2 = GetPostString("date2");
  4521. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4522. if (dw.Length > 0) lw.Add(dw);
  4523. string price1 = GetPostString("price1");
  4524. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4525. string price2 = GetPostString("price2");
  4526. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4527. string posTag = CurrentUser.UserPost.Post.Code;
  4528. if (posTag == "Supplier")
  4529. {
  4530. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4531. }
  4532. lw.Add(string.Format("OrderState=6 "));
  4533. lw.Add(string.Format("IsXianHuo=1 "));
  4534. lw.Add(string.Format("IsReturn>0 "));
  4535. lw.Add(string.Format("IsReturn!=3"));
  4536. lw.Add(string.Format("IsRefund<={0}", 1));
  4537. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4538. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4539. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4540. writeGridDataTableJson(dStruct.TotalCount, dt);
  4541. }
  4542. public void set_erp_orderdelivery()
  4543. {
  4544. if (UrlPostParmsCheck("ctid"))
  4545. {
  4546. string eid = GetPostString("ctid");
  4547. CeErpTradeCell entity = null;
  4548. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4549. if (entity != null)
  4550. {
  4551. if (entity.OrderState >= 7)
  4552. {
  4553. returnErrorMsg("此单已发货,无需重复发货");
  4554. return;
  4555. }
  4556. if (entity.OrderState != 6)
  4557. {
  4558. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4559. return;
  4560. }
  4561. string shop = GetPostString("seller_nick");
  4562. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4563. string comName = GetPostString("comName");
  4564. string comCode = GetPostString("comCode");
  4565. string outSid = GetPostString("outSid");
  4566. string deliveryType = GetPostString("deliveryType");
  4567. string deliveryMemo = GetPostString("deliveryMemo");
  4568. outSid = outSid.Trim();
  4569. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4570. if (mainEn == null)
  4571. {
  4572. returnErrorMsg("找不到原始订单记录");
  4573. return;
  4574. }
  4575. bool isInitOrderDeliv = false;
  4576. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4577. {
  4578. isInitOrderDeliv = true;
  4579. }
  4580. string apires = "";
  4581. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4582. 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)
  4583. {
  4584. apires = "发货成功true";
  4585. }
  4586. else
  4587. {
  4588. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4589. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4590. }
  4591. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4592. {
  4593. entity.OrderState = 7;//发货后订单已发货
  4594. entity.OutSid = outSid;
  4595. entity.MemoOpt = 0;
  4596. entity.UpdateTime = DateTime.Now;
  4597. entity.FinishDeliveryTime = DateTime.Now;
  4598. entity.Update();
  4599. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4600. commonHelper.UpdateRelationOrder(entity.ctid);
  4601. //还要插入快递信息到 快递信息表
  4602. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4603. exinfo.tid = eid;
  4604. exinfo.out_sid = outSid;
  4605. exinfo.company_code = comCode;
  4606. exinfo.company_name = comName;
  4607. exinfo.delivery_memo = deliveryMemo;
  4608. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4609. exinfo.deliveryType = deliveryType;
  4610. exinfo.Create();
  4611. returnSuccessMsg("发货操作成功!");
  4612. commonHelper.UpdateRelationOrder(entity.ctid);
  4613. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4614. CeErpSukuraData.createInfo(entity.ctid, 4);
  4615. if (entity.SupplierId == 64)
  4616. {
  4617. commonHelper.sendCytExpress(exinfo);
  4618. }
  4619. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4620. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4621. }
  4622. else
  4623. {
  4624. string errmsg = commonHelper.KeepChinese(apires);
  4625. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4626. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4627. }
  4628. return;
  4629. }
  4630. returnErrorMsg("找不到订单记录");
  4631. }
  4632. }
  4633. public void set_erp_multidelivery()
  4634. {
  4635. string eids = GetPostString("tids");
  4636. string[] eidList = eids.Split(',');
  4637. if (eidList.Length <= 0)
  4638. {
  4639. returnErrorMsg("发货不能为空");
  4640. return;
  4641. }
  4642. foreach (string ctid in eidList)
  4643. {
  4644. if (ctid.Length <= 0) continue;
  4645. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4646. if (expInfo != null)
  4647. {
  4648. StringBuilder sql = new StringBuilder();
  4649. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4650. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4651. if (dt.Rows.Count > 0)
  4652. {
  4653. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4654. {
  4655. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4656. expInfo.state = "异常";
  4657. expInfo.isMultiDelivery = 1;
  4658. expInfo.Update();
  4659. continue;
  4660. }
  4661. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4662. {
  4663. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4664. expInfo.state = "异常";
  4665. expInfo.Update();
  4666. continue;
  4667. }
  4668. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4669. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4670. bool isInitOrderDeliv = false;
  4671. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4672. {
  4673. isInitOrderDeliv = true;
  4674. expInfo.isMultiDelivery = 1;
  4675. }
  4676. if (ctid.IndexOf("N") != -1)
  4677. {
  4678. StringBuilder sqlbucha = new StringBuilder();
  4679. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4680. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4681. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4682. commonHelper.UpdateRelationOrder(ctid);
  4683. expInfo.delivery_memo = "发货成功";
  4684. expInfo.state = "发货成功";
  4685. expInfo.isMultiDelivery = 1;
  4686. expInfo.Update();
  4687. }
  4688. else
  4689. {
  4690. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4691. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4692. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4693. {
  4694. expInfo.delivery_memo = "发货成功";
  4695. expInfo.state = "发货成功";
  4696. expInfo.isMultiDelivery = 1;
  4697. expInfo.Update();
  4698. commonHelper.UpdateRelationOrder(ctid);
  4699. CeErpSukuraData.createInfo(ctid, 4);
  4700. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4701. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4702. }
  4703. else
  4704. {
  4705. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4706. expInfo.state = "异常";
  4707. expInfo.Update();
  4708. }
  4709. }
  4710. }
  4711. }
  4712. }
  4713. returnSuccessMsg("操作完成");
  4714. }
  4715. public void reset_erp_memoopt()
  4716. {
  4717. if (UrlPostParmsCheck("ctid"))
  4718. {
  4719. string eid = GetPostString("ctid");
  4720. CeErpTradeCell entity = null;
  4721. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4722. if (entity != null)
  4723. {
  4724. string stropt = "";
  4725. if (entity.MemoOpt == 1)
  4726. {
  4727. stropt = "“改稿”";
  4728. }
  4729. else if (entity.MemoOpt == 2)
  4730. {
  4731. stropt = "“定稿”";
  4732. }
  4733. else if (entity.MemoOpt == 3)
  4734. {
  4735. stropt = "“完成查货”";
  4736. CeErpSukuraData.createInfo(entity.ctid, 6);
  4737. }
  4738. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4739. entity.UpdateTime = DateTime.Now;
  4740. entity.MemoOpt = 0;
  4741. entity.Update();
  4742. returnSuccessMsg("操作成功!");
  4743. return;
  4744. }
  4745. returnErrorMsg("找不到记录");
  4746. }
  4747. }
  4748. public void get_erp_deliveryunusual()
  4749. {
  4750. DataStruct dStruct = GetPostStruct();
  4751. List<string> lw = new List<string>();
  4752. string tid = GetPostString("ctid");
  4753. if (tid.Length > 0)
  4754. {
  4755. string select_tid = getTidByCtid(tid);
  4756. lw.Add(string.Format("tid='{0}'", select_tid));
  4757. }
  4758. string shopname = GetPostString("shopname");
  4759. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4760. string buyernick = GetPostString("buyer_nick");
  4761. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4762. string customer = GetPostString("customer");
  4763. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4764. string design = GetPostString("design");
  4765. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4766. string sellermemo = GetPostString("seller_memo");
  4767. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4768. string supplier = GetPostString("supplier");
  4769. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4770. string date1 = GetPostString("date1");
  4771. string date2 = GetPostString("date2");
  4772. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4773. if (dw.Length > 0) lw.Add(dw);
  4774. string placedate1 = GetPostString("placedate1");
  4775. string placedate2 = GetPostString("placedate2");
  4776. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4777. if (dw_place.Length > 0) lw.Add(dw_place);
  4778. string price1 = GetPostString("price1");
  4779. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4780. string price2 = GetPostString("price2");
  4781. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4782. string unusualCon = GetPostString("unusualcon");
  4783. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4784. string posTag = CurrentUser.UserPost.Post.Code;
  4785. if (posTag == "Supplier")
  4786. {
  4787. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4788. }
  4789. lw.Add(string.Format("OrderState = 6"));
  4790. lw.Add(string.Format("UnusualTag = 5"));
  4791. lw.Add(string.Format("IsRefund<={0}", 1));
  4792. dStruct.Order = "FinishPlaceTime desc";
  4793. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4794. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4795. writeGridDataTableJson(dStruct.TotalCount, dt);
  4796. }
  4797. public void get_erp_deliveryedlist()
  4798. {
  4799. DataStruct dStruct = GetPostStruct();
  4800. List<string> lw = new List<string>();
  4801. string tid = GetPostString("ctid");
  4802. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4803. string shopname = GetPostString("shopname");
  4804. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4805. string buyernick = GetPostString("buyer_nick");
  4806. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4807. string customer = GetPostString("customer");
  4808. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4809. string design = GetPostString("design");
  4810. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4811. string sellermemo = GetPostString("seller_memo");
  4812. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4813. string logistics = GetPostString("logistics");
  4814. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4815. string date1 = GetPostString("date1");
  4816. string date2 = GetPostString("date2");
  4817. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4818. //if (dw.Length > 0) lw.Add(dw);
  4819. string placedate1 = GetPostString("placedate1");
  4820. string placedate2 = GetPostString("placedate2");
  4821. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4822. if (fdw.Length > 0) lw.Add(fdw);
  4823. string devdate1 = GetPostString("deliverydate1");
  4824. string devdate2 = GetPostString("deliverydate2");
  4825. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4826. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4827. string price1 = GetPostString("price1");
  4828. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4829. string price2 = GetPostString("price2");
  4830. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4831. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4832. {
  4833. if (tid.Length > 0)
  4834. {
  4835. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4836. if (tid.Length > 5)
  4837. {
  4838. List<string> tids = getTidByCtidLike(tid);
  4839. if (tids.Count > 0 && tids.Count < 10)
  4840. {
  4841. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4842. }
  4843. }
  4844. lw.Add(tid_sql);
  4845. }
  4846. if (buyernick.Length > 0)
  4847. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4848. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4849. if (dw.Length > 0) lw.Add(dw);
  4850. }
  4851. else
  4852. {
  4853. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4854. }
  4855. string posTag = CurrentUser.UserPost.Post.Code;
  4856. if (posTag == "Supplier")
  4857. {
  4858. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4859. }
  4860. else
  4861. {
  4862. string supplier = GetPostString("supplier");
  4863. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4864. }
  4865. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4866. lw.Add(string.Format("type != 'PDD' "));
  4867. lw.Add(string.Format("IsRefund!={0}", 2));
  4868. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4869. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4870. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4871. /*if (tid.Length > 0)
  4872. {
  4873. List<string> tids = new List<string>();
  4874. if (dt != null && dt.Rows.Count > 0)
  4875. {
  4876. foreach (DataRow item in dt.Rows)
  4877. {
  4878. tids.Add("'" + item["tid"] + "'");
  4879. }
  4880. }
  4881. if (tids.Count > 0)
  4882. {
  4883. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4884. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4885. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4886. dt = WebCache.GetData("view_erptradecell", dStruct);
  4887. }
  4888. }*/
  4889. if (dt != null)
  4890. {
  4891. foreach (DataRow dr in dt.Rows)
  4892. {
  4893. 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();
  4894. }
  4895. }
  4896. writeGridDataTableJson(dStruct.TotalCount, dt);
  4897. }
  4898. public void get_erp_pdddeliveryed()
  4899. {
  4900. DataStruct dStruct = GetPostStruct();
  4901. List<string> lw = new List<string>();
  4902. string tid = GetPostString("ctid");
  4903. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4904. string shopname = GetPostString("shopname");
  4905. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4906. string buyernick = GetPostString("buyer_nick");
  4907. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4908. string customer = GetPostString("customer");
  4909. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4910. string design = GetPostString("design");
  4911. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4912. string sellermemo = GetPostString("seller_memo");
  4913. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4914. string logistics = GetPostString("logistics");
  4915. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4916. string date1 = GetPostString("date1");
  4917. string date2 = GetPostString("date2");
  4918. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4919. //if (dw.Length > 0) lw.Add(dw);
  4920. string placedate1 = GetPostString("placedate1");
  4921. string placedate2 = GetPostString("placedate2");
  4922. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4923. if (fdw.Length > 0) lw.Add(fdw);
  4924. string devdate1 = GetPostString("deliverydate1");
  4925. string devdate2 = GetPostString("deliverydate2");
  4926. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4927. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4928. string price1 = GetPostString("price1");
  4929. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4930. string price2 = GetPostString("price2");
  4931. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4932. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4933. {
  4934. if (tid.Length > 0)
  4935. {
  4936. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4937. if (tid.Length > 5)
  4938. {
  4939. List<string> tids = getTidByCtidLike(tid);
  4940. if (tids.Count > 0 && tids.Count < 10)
  4941. {
  4942. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4943. }
  4944. }
  4945. lw.Add(tid_sql);
  4946. }
  4947. if (buyernick.Length > 0)
  4948. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4949. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4950. if (dw.Length > 0) lw.Add(dw);
  4951. }
  4952. else
  4953. {
  4954. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4955. }
  4956. string posTag = CurrentUser.UserPost.Post.Code;
  4957. if (posTag == "Supplier")
  4958. {
  4959. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4960. }
  4961. else
  4962. {
  4963. string supplier = GetPostString("supplier");
  4964. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4965. }
  4966. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4967. lw.Add(string.Format("type = 'PDD' "));
  4968. lw.Add(string.Format("IsRefund!={0}", 2));
  4969. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4970. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4971. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4972. /* if (tid.Length > 0)
  4973. {
  4974. List<string> tids = new List<string>();
  4975. if (dt != null && dt.Rows.Count > 0)
  4976. {
  4977. foreach (DataRow item in dt.Rows)
  4978. {
  4979. tids.Add("'" + item["tid"] + "'");
  4980. }
  4981. }
  4982. if (tids.Count > 0)
  4983. {
  4984. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4985. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4986. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4987. dt = WebCache.GetData("view_erptradecell", dStruct);
  4988. }
  4989. }*/
  4990. foreach (DataRow dr in dt.Rows)
  4991. {
  4992. 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();
  4993. }
  4994. writeGridDataTableJson(dStruct.TotalCount, dt);
  4995. }
  4996. public void get_erp_jddeliveryed()
  4997. {
  4998. DataStruct dStruct = GetPostStruct();
  4999. List<string> lw = new List<string>();
  5000. string tid = GetPostString("ctid");
  5001. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5002. string shopname = GetPostString("shopname");
  5003. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5004. string buyernick = GetPostString("buyer_nick");
  5005. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5006. string customer = GetPostString("customer");
  5007. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5008. string design = GetPostString("design");
  5009. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5010. string sellermemo = GetPostString("seller_memo");
  5011. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5012. string date1 = GetPostString("date1");
  5013. string date2 = GetPostString("date2");
  5014. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5015. //if (dw.Length > 0) lw.Add(dw);
  5016. string placedate1 = GetPostString("placedate1");
  5017. string placedate2 = GetPostString("placedate2");
  5018. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5019. if (fdw.Length > 0) lw.Add(fdw);
  5020. string devdate1 = GetPostString("deliverydate1");
  5021. string devdate2 = GetPostString("deliverydate2");
  5022. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5023. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5024. string price1 = GetPostString("price1");
  5025. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5026. string price2 = GetPostString("price2");
  5027. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5028. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5029. {
  5030. if (tid.Length > 0)
  5031. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5032. if (buyernick.Length > 0)
  5033. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5034. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5035. if (dw.Length > 0) lw.Add(dw);
  5036. }
  5037. else
  5038. {
  5039. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5040. }
  5041. string posTag = CurrentUser.UserPost.Post.Code;
  5042. if (posTag == "Supplier")
  5043. {
  5044. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5045. }
  5046. else
  5047. {
  5048. string supplier = GetPostString("supplier");
  5049. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5050. }
  5051. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5052. lw.Add(string.Format("type = 'JD' "));
  5053. lw.Add(string.Format("IsRefund!={0}", 2));
  5054. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5055. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5056. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5057. foreach (DataRow dr in dt.Rows)
  5058. {
  5059. 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();
  5060. }
  5061. writeGridDataTableJson(dStruct.TotalCount, dt);
  5062. }
  5063. public void get_erp_allplacelist()
  5064. {
  5065. DataStruct dStruct = GetPostStruct();
  5066. List<string> lw = new List<string>();
  5067. string tid = GetPostString("ctid");
  5068. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5069. string shopname = GetPostString("shopname");
  5070. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5071. string buyernick = GetPostString("buyer_nick");
  5072. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5073. string customer = GetPostString("customer");
  5074. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5075. string design = GetPostString("design");
  5076. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5077. string sellermemo = GetPostString("seller_memo");
  5078. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5079. string supplier = GetPostString("supplier");
  5080. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5081. string date1 = GetPostString("date1");
  5082. string date2 = GetPostString("date2");
  5083. string pldate1 = GetPostString("placedate1");
  5084. string pldate2 = GetPostString("placedate2");
  5085. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5086. //if (dw.Length > 0) lw.Add(dw);
  5087. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5088. {
  5089. if (tid.Length > 0)
  5090. {
  5091. string select_tid = getTidByCtid(tid);
  5092. lw.Add(string.Format("tid='{0}'", select_tid));
  5093. }
  5094. if (buyernick.Length > 0)
  5095. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5096. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5097. if (dw.Length > 0) lw.Add(dw);
  5098. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5099. if (dw_place.Length > 0) lw.Add(dw_place);
  5100. }
  5101. else
  5102. {
  5103. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5104. {
  5105. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5106. }
  5107. }
  5108. string price1 = GetPostString("price1");
  5109. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5110. string price2 = GetPostString("price2");
  5111. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5112. string posTag = CurrentUser.UserPost.Post.Code;
  5113. if (posTag == "Supplier")
  5114. {
  5115. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5116. }
  5117. lw.Add(string.Format("OrderState >= 6"));
  5118. lw.Add(string.Format("IsSample != 2 "));
  5119. //lw.Add(string.Format("isDianziOrder = 0 "));
  5120. lw.Add(string.Format("SupplierId > 0 "));
  5121. //lw.Add(string.Format("IsRefund<={0}", 1));
  5122. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5123. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5124. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5125. foreach (DataRow dr in dt.Rows)
  5126. {
  5127. 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();
  5128. }
  5129. writeGridDataTableJson(dStruct.TotalCount, dt);
  5130. }
  5131. public void get_erp_financeallplacelist()
  5132. {
  5133. DataStruct dStruct = GetPostStruct();
  5134. List<string> lw = new List<string>();
  5135. string tid = GetPostString("ctid");
  5136. string shopname = GetPostString("shopname");
  5137. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5138. string buyernick = GetPostString("buyer_nick");
  5139. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5140. string customer = GetPostString("customer");
  5141. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5142. string design = GetPostString("design");
  5143. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5144. string sellermemo = GetPostString("seller_memo");
  5145. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5146. string supplier = GetPostString("supplier");
  5147. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5148. string date1 = GetPostString("date1");
  5149. string date2 = GetPostString("date2");
  5150. string pldate1 = GetPostString("placedate1");
  5151. string pldate2 = GetPostString("placedate2");
  5152. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5153. {
  5154. if (tid.Length > 0)
  5155. {
  5156. string select_tid = getTidByCtid(tid);
  5157. lw.Add(string.Format("tid='{0}'", select_tid));
  5158. }
  5159. if (buyernick.Length > 0)
  5160. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5161. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5162. if (dw.Length > 0) lw.Add(dw);
  5163. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5164. if (dw_place.Length > 0) lw.Add(dw_place);
  5165. }
  5166. else
  5167. {
  5168. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5169. {
  5170. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5171. }
  5172. }
  5173. string price1 = GetPostString("price1");
  5174. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5175. string price2 = GetPostString("price2");
  5176. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5177. string posTag = CurrentUser.UserPost.Post.Code;
  5178. if (posTag == "Supplier")
  5179. {
  5180. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5181. }
  5182. //lw.Add(string.Format("OrderState >= 6"));
  5183. lw.Add(string.Format("IsSample != 2 "));
  5184. lw.Add(string.Format("isDianziOrder = 0 "));
  5185. //lw.Add(string.Format("IsRefund<={0}", 1));
  5186. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5187. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5188. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5189. foreach (DataRow dr in dt.Rows)
  5190. {
  5191. 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();
  5192. }
  5193. writeGridDataTableJson(dStruct.TotalCount, dt);
  5194. }
  5195. public void get_erp_expresslist()
  5196. {
  5197. int listtype = GetInt("ltype");
  5198. DataStruct dStruct = GetPostStruct();
  5199. List<string> lw = new List<string>();
  5200. string tid = GetPostString("tid");
  5201. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5202. string outsid = GetPostString("out_sid");
  5203. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5204. string importer = GetPostString("ImportUserName");
  5205. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5206. string file = GetPostString("import_file");
  5207. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5208. string printman = GetPostString("printman");
  5209. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5210. string date1 = GetPostString("date1");
  5211. string date2 = GetPostString("date2");
  5212. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5213. if (dw.Length > 0) lw.Add(dw);
  5214. string fdate1 = GetPostString("finishdate1");
  5215. string fdate2 = GetPostString("finishdate2");
  5216. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5217. if (fdw.Length > 0) lw.Add(fdw);
  5218. string supplierId = GetPostString("supplierId");
  5219. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5220. if (listtype == 1)
  5221. {
  5222. lw.Add(string.Format("importUserId !=0"));
  5223. }
  5224. string posTag = CurrentUser.UserPost.Post.Code;
  5225. if (posTag == "Supplier")
  5226. {
  5227. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5228. }
  5229. if (dStruct.PageSize != 100000)
  5230. {
  5231. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5232. }
  5233. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5234. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5235. writeGridDataTableJson(dStruct.TotalCount, dt);
  5236. }
  5237. public void set_erp_buchaorderdelivery()
  5238. {
  5239. if (UrlPostParmsCheck("ctid"))
  5240. {
  5241. string eid = GetPostString("ctid");
  5242. CeErpTradeCell entity = null;
  5243. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5244. if (entity != null)
  5245. {
  5246. if (entity.IsSample != 2)
  5247. {
  5248. returnErrorMsg("补差价单才能标记为已发货");
  5249. return;
  5250. }
  5251. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5252. entity.OrderState = 7;
  5253. entity.Update();
  5254. returnSuccessMsg("操作成功!");
  5255. return;
  5256. }
  5257. returnErrorMsg("找不到记录");
  5258. }
  5259. }
  5260. public void get_stdtemplates()
  5261. {
  5262. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5263. //string res = taobaoHelper.test();
  5264. string res = apiHelper.API_PrintTemplate();
  5265. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5266. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5267. {
  5268. int sidx = res.IndexOf("error_code");
  5269. int eidx = res.IndexOf("success");
  5270. string msg = res.Substring(sidx, eidx - sidx);
  5271. returnErrorMsg(msg);
  5272. return;
  5273. }
  5274. if (res.Length <= 0)
  5275. {
  5276. returnErrorMsg("模板数据为空!");
  5277. return;
  5278. }
  5279. ReturnSuccess(res);
  5280. }
  5281. public void cancel_print_order()
  5282. {
  5283. if (UrlPostParmsCheck("ctid"))
  5284. {
  5285. string ctid = GetPostString("ctid");
  5286. CeErpTradeCell entity = null;
  5287. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5288. if (entity != null)
  5289. {
  5290. string res = "";
  5291. string code = entity.LastBillWaybillCode;
  5292. if (code == "")
  5293. {
  5294. code = entity.OutSid;
  5295. }
  5296. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5297. XLog.SaveLog(0, "取消面单" + res);
  5298. }
  5299. }
  5300. }
  5301. public void set_erp_printwaybill()
  5302. {
  5303. if (UrlPostParmsCheck("ctid"))
  5304. {
  5305. string ctid = GetPostString("ctid");
  5306. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5307. string cpName = GetPostString("cpname");
  5308. string isTogether = GetPostString("together");
  5309. //var res_obj = new
  5310. //{
  5311. // restype = 1,
  5312. // 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\"}"
  5313. //};
  5314. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5315. //ReturnSuccess(ro_json);
  5316. //return;
  5317. bool isUseLastWayBillCode = false;
  5318. CeErpTradeCell entity = null;
  5319. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5320. if (entity != null)
  5321. {
  5322. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5323. {
  5324. isUseLastWayBillCode = true;
  5325. }
  5326. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5327. {
  5328. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5329. return;
  5330. }
  5331. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5332. {
  5333. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5334. return;
  5335. }
  5336. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5337. {
  5338. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5339. return;
  5340. }
  5341. }
  5342. string res = "";
  5343. Api_waybill_code_response_Obj fullObj = null;
  5344. string pData_str = "";
  5345. string curUseWayBillCode = "";
  5346. if (isUseLastWayBillCode == false)
  5347. {
  5348. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5349. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5350. if (res.IndexOf("failure") != -1)
  5351. {
  5352. //int idx = res.IndexOf("sub_message");
  5353. //int idx2 = res.IndexOf("flag");
  5354. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5355. string errMsgNeed = commonHelper.KeepChinese(res);
  5356. var res_objd = new
  5357. {
  5358. restype = 0,
  5359. data = "获取面单失败" + errMsgNeed
  5360. };
  5361. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5362. returnSuccess(ro_jsond);
  5363. if (res.IndexOf("停发") != -1)
  5364. {
  5365. entity.UnusualCon = "物流停发";
  5366. entity.Update();
  5367. }
  5368. //returnErrorMsg("获取面单失败,"+emsg);
  5369. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5370. return;
  5371. }
  5372. else if (res.IndexOf("errorMsg") != -1)
  5373. {
  5374. //int idx = res.IndexOf("errorMsg");
  5375. //int idx2 = res.IndexOf("}]}");
  5376. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5377. string errMsgNeed = commonHelper.KeepChinese(res);
  5378. var res_objf = new
  5379. {
  5380. restype = 0,
  5381. data = "获取面单失败2" + errMsgNeed
  5382. };
  5383. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5384. if (res.IndexOf("停发") != -1)
  5385. {
  5386. entity.UnusualCon = "物流停发";
  5387. entity.Update();
  5388. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5389. if (trade != null)
  5390. {
  5391. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5392. }
  5393. }
  5394. returnSuccess(ro_jsonf);
  5395. //returnErrorMsg("获取面单失败," + emsg);
  5396. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5397. return;
  5398. }
  5399. try
  5400. {
  5401. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5402. //res = res.Replace(" ", "");
  5403. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5404. }
  5405. catch (Exception ex)
  5406. {
  5407. XLog.SaveLog(0, "生成fullObj" + res);
  5408. var res_objf = new
  5409. {
  5410. restype = 0,
  5411. data = "生成fullObj发生错误" + ex.Message
  5412. };
  5413. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5414. returnSuccess(ro_jsonf);
  5415. return;
  5416. }
  5417. if (fullObj.response.data.content.Count > 0)
  5418. {
  5419. ContentItem codeObj = fullObj.response.data.content[0];
  5420. if (cpCode.IndexOf("SFFQ-") != -1)
  5421. {
  5422. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5423. }
  5424. else
  5425. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5426. curUseWayBillCode = codeObj.waybillCode;
  5427. }
  5428. else
  5429. {
  5430. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5431. var res_objf = new
  5432. {
  5433. restype = 0,
  5434. data = "生成fullObj找不到快递单号waybillCode"
  5435. };
  5436. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5437. returnSuccess(ro_jsonf);
  5438. return;
  5439. }
  5440. }
  5441. else
  5442. {
  5443. //使用上次打印的快递单号
  5444. if (cpCode == "SFFQ-LY")
  5445. {
  5446. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5447. }
  5448. else
  5449. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5450. curUseWayBillCode = entity.LastBillWaybillCode;
  5451. }
  5452. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5453. {
  5454. var res_obje = new
  5455. {
  5456. restype = 0,
  5457. data = "获取加密打印数据失败"
  5458. };
  5459. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5460. returnSuccess(ro_jsone);
  5461. entity.LastBillCpCode = cpCode;
  5462. entity.LastBillWaybillCode = curUseWayBillCode;
  5463. entity.Update();
  5464. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5465. //returnErrorMsg("获取加密打印数据失败");
  5466. return;
  5467. }
  5468. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5469. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5470. string btnType = "";
  5471. string errorMsg = "";
  5472. if (entity != null)
  5473. {
  5474. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5475. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5476. //cpcode是 YTO-CAINIAO
  5477. //string comCode = cpCode.Split('-')[0].ToString();
  5478. string apires = "";
  5479. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5480. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5481. {
  5482. if (ctid.IndexOf("N") != -1)
  5483. {
  5484. apires = "发货成功";
  5485. }
  5486. else
  5487. {
  5488. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5489. }
  5490. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5491. //打单后发货
  5492. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5493. {
  5494. try
  5495. {
  5496. btnType = "待发货";
  5497. entity.OutSid = curUseWayBillCode;
  5498. entity.OrderState = 7;
  5499. entity.IsUrgency = false;
  5500. entity.LastBillCpCode = "";
  5501. entity.LastBillWaybillCode = "";
  5502. entity.FinishDeliveryTime = DateTime.Now;
  5503. entity.IsReturn = 0;
  5504. entity.MemoOpt = 0;
  5505. entity.UpdateTime = DateTime.Now;
  5506. entity.Update();
  5507. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5508. //还要插入快递信息到 快递信息表
  5509. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5510. exinfo.tid = entity.ctid;
  5511. exinfo.out_sid = curUseWayBillCode;
  5512. exinfo.company_code = cpCode;
  5513. exinfo.company_name = cpName;
  5514. exinfo.supplierUserName = supplierName;
  5515. exinfo.deliveryType = "发货成功";
  5516. exinfo.print_time = DateTime.Now;
  5517. exinfo.printUser = CurrentUser.UserName;
  5518. exinfo.postData = pData_str;
  5519. exinfo.Create();
  5520. commonHelper.UpdateRelationOrder(entity.ctid);
  5521. CeErpSukuraData.createInfo(ctid, 4);
  5522. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5523. if (entity.SupplierId == 64)
  5524. {
  5525. commonHelper.sendCytExpress(exinfo);
  5526. }
  5527. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5528. if (!string.IsNullOrEmpty(isTogether))
  5529. {
  5530. if (Convert.ToInt32(isTogether) > 0)
  5531. {
  5532. StringBuilder sqlsb = new StringBuilder();
  5533. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}' where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5534. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5535. }
  5536. }
  5537. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5538. }
  5539. catch (Exception ex)
  5540. {
  5541. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5542. }
  5543. }
  5544. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5545. {
  5546. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5547. if (entity.OrderState == 6)
  5548. {
  5549. entity.OrderState = 7;
  5550. }
  5551. entity.UpdateTime = DateTime.Now;
  5552. entity.FinishDeliveryTime = DateTime.Now;
  5553. btnType = "已发货";
  5554. entity.Update();
  5555. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5556. exinfo.tid = entity.ctid;
  5557. exinfo.out_sid = curUseWayBillCode;
  5558. exinfo.company_code = cpCode;
  5559. exinfo.company_name = cpName;
  5560. exinfo.supplierUserName = supplierName;
  5561. exinfo.deliveryType = "发货成功";
  5562. exinfo.print_time = DateTime.Now;
  5563. exinfo.printUser = CurrentUser.UserName;
  5564. exinfo.postData = pData_str;
  5565. exinfo.Create();
  5566. commonHelper.UpdateRelationOrder(entity.ctid);
  5567. CeErpSukuraData.createInfo(entity.ctid, 4);
  5568. if (entity.SupplierId == 64)
  5569. {
  5570. commonHelper.sendCytExpress(exinfo);
  5571. }
  5572. if (!string.IsNullOrEmpty(isTogether))
  5573. {
  5574. if (Convert.ToInt32(isTogether) > 0)
  5575. {
  5576. StringBuilder sqlsb = new StringBuilder();
  5577. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}',FinishDeliveryTime=GETDATE(),UpdateTime=GETDATE() where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5578. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5579. }
  5580. }
  5581. //不处理
  5582. }
  5583. else
  5584. {
  5585. entity.UpdateTime = DateTime.Now;
  5586. entity.LastBillCpCode = cpCode;
  5587. entity.LastBillWaybillCode = curUseWayBillCode;
  5588. entity.Update();
  5589. string errmsg = commonHelper.KeepChinese(apires);
  5590. var res_objz = new
  5591. {
  5592. restype = 0,
  5593. data = "打单后发货失败"
  5594. };
  5595. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5596. returnSuccess(ro_jsonz);
  5597. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5598. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5599. return;
  5600. }
  5601. }
  5602. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5603. {
  5604. StringBuilder allSql = new StringBuilder();
  5605. allSql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,tid from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  5606. if (string.IsNullOrEmpty(mainEn.receiverId))
  5607. {
  5608. allSql.AppendFormat(" and (tid='{0}');", entity.tid);
  5609. }
  5610. else
  5611. {
  5612. //查询同车间同状态下的收货地址相同的单子
  5613. allSql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}') );", entity.tid, mainEn.receiverId, entity.IsSF);
  5614. }
  5615. DataTable dt = DbHelper.DbConn.ExecuteDataset(allSql.ToString()).Tables[0];
  5616. List<string> list = new List<string>();
  5617. List<string> send_list = new List<string>();
  5618. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5619. CeErpTrade ceErpTrade = new CeErpTrade();
  5620. foreach (DataRow row in dt.Rows)
  5621. {
  5622. list.Add("'" + row["ctid"] + "'");
  5623. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5624. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5625. if (ctid.IndexOf("N") != -1)
  5626. {
  5627. apires = "发货成功";
  5628. }
  5629. else
  5630. {
  5631. if (!send_list.Contains(ceErpTrade.tid))
  5632. {
  5633. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5634. }
  5635. else
  5636. {
  5637. apires = "发货成功";
  5638. }
  5639. }
  5640. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5641. {
  5642. send_list.Add(ceErpTrade.tid);
  5643. try
  5644. {
  5645. btnType = "待发货";
  5646. ceErpTradeCell.OutSid = curUseWayBillCode;
  5647. ceErpTradeCell.OrderState = 7;
  5648. ceErpTradeCell.IsUrgency = false;
  5649. ceErpTradeCell.LastBillCpCode = "";
  5650. ceErpTradeCell.LastBillWaybillCode = "";
  5651. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5652. ceErpTradeCell.IsReturn = 0;
  5653. ceErpTradeCell.MemoOpt = 0;
  5654. ceErpTradeCell.UpdateTime = DateTime.Now;
  5655. ceErpTradeCell.Update();
  5656. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5657. //还要插入快递信息到 快递信息表
  5658. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5659. exinfo.tid = ceErpTradeCell.ctid;
  5660. exinfo.out_sid = curUseWayBillCode;
  5661. exinfo.company_code = cpCode;
  5662. exinfo.company_name = cpName;
  5663. exinfo.supplierUserName = supplierName;
  5664. exinfo.deliveryType = "发货成功";
  5665. exinfo.print_time = DateTime.Now;
  5666. exinfo.printUser = CurrentUser.UserName;
  5667. exinfo.postData = pData_str;
  5668. exinfo.Create();
  5669. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5670. CeErpSukuraData.createInfo(ctid, 4);
  5671. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5672. if (ceErpTradeCell.SupplierId == 64)
  5673. {
  5674. commonHelper.sendCytExpress(exinfo);
  5675. }
  5676. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5677. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5678. }
  5679. catch (Exception ex)
  5680. {
  5681. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5682. }
  5683. }
  5684. else
  5685. {
  5686. ceErpTradeCell.UpdateTime = DateTime.Now;
  5687. ceErpTradeCell.LastBillCpCode = cpCode;
  5688. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5689. ceErpTradeCell.Update();
  5690. string errmsg = commonHelper.KeepChinese(apires);
  5691. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5692. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5693. }
  5694. }
  5695. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5696. }
  5697. }
  5698. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5699. var res_obj = new
  5700. {
  5701. restype = 1,
  5702. data = pData_str,
  5703. errorMsg
  5704. };
  5705. string ro_json = JsonConvert.SerializeObject(res_obj);
  5706. ReturnSuccess(ro_json);
  5707. return;
  5708. }
  5709. }
  5710. private string GetUTF8String(byte[] vs)
  5711. {
  5712. throw new NotImplementedException();
  5713. }
  5714. public void set_erp_printwaybill_cn()
  5715. {
  5716. if (UrlPostParmsCheck("ctid"))
  5717. {
  5718. string ctid = GetPostString("ctid");
  5719. string cpCode = GetPostString("cpcode");
  5720. string cpName = GetPostString("cpname");
  5721. string tempUrl = GetPostString("tempurl");
  5722. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5723. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5724. //string res = taobaoHelper.test();
  5725. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5726. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5727. {
  5728. int sidx = res.IndexOf("errorMsg");
  5729. int eidx = res.IndexOf("}");
  5730. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5731. var res_objzxx = new
  5732. {
  5733. restype = 0,
  5734. data = msg
  5735. };
  5736. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5737. returnSuccess(ro_jsonzxx);
  5738. //returnErrorMsg(msg);
  5739. return;
  5740. }
  5741. int idx = res.IndexOf("waybillCode");
  5742. int idx2 = res.IndexOf("printData");
  5743. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5744. string eid = GetPostString("ctid");
  5745. CeErpTradeCell entity = null;
  5746. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5747. if (entity != null)
  5748. {
  5749. string osid = entity.OutSid;
  5750. entity.OutSid = osid + "," + outsid;
  5751. entity.FinishDeliveryTime = DateTime.Now;
  5752. entity.OrderState = 7;
  5753. entity.UpdateTime = DateTime.Now;
  5754. entity.IsReturn = 0;
  5755. entity.Update();
  5756. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5757. exinfo.tid = entity.ctid;
  5758. exinfo.out_sid = outsid;
  5759. exinfo.company_code = cpCode;
  5760. exinfo.company_name = cpName;
  5761. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5762. exinfo.deliveryType = "发货成功";
  5763. exinfo.print_time = DateTime.Now;
  5764. exinfo.printUser = CurrentUser.UserName;
  5765. exinfo.Create();
  5766. if (entity.SupplierId == 64)
  5767. {
  5768. commonHelper.sendCytExpress(exinfo);
  5769. }
  5770. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5771. }
  5772. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5773. var res_objz = new
  5774. {
  5775. restype = 1,
  5776. data = res
  5777. };
  5778. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5779. returnSuccess(ro_jsonz);
  5780. //ReturnSuccess(res);
  5781. }
  5782. }
  5783. ////打单,打印面单 获取面单号
  5784. //public void set_erp_printwaybill()
  5785. //{
  5786. // if (UrlPostParmsCheck("ctid"))
  5787. // {
  5788. // string ctid = GetPostString("ctid");
  5789. // string cpCode = GetPostString("cpcode");
  5790. // string tempUrl = GetPostString("tempurl");
  5791. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5792. // //string res = taobaoHelper.test();
  5793. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5794. // if (res.IndexOf("error_response") != -1)
  5795. // {
  5796. // int sidx = res.IndexOf("sub_msg");
  5797. // int eidx = res.IndexOf("request_id");
  5798. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5799. // returnErrorMsg(msg);
  5800. // return;
  5801. // }
  5802. // int idx = res.IndexOf("waybill_code");
  5803. // int idx2 = res.IndexOf("}]}");
  5804. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5805. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5806. // ReturnSuccess(res);
  5807. // }
  5808. //}
  5809. public void cancel_erp_aftersale()
  5810. {
  5811. if (UrlPostParmsCheck("ctid"))
  5812. {
  5813. string eid = GetPostString("ctid");
  5814. CeErpTradeCell entity = null;
  5815. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5816. if (entity != null)
  5817. {
  5818. //有过处理的售后,取消也不能删除 售 字,保留
  5819. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5820. {
  5821. entity.AfterSaleState = 4;
  5822. }
  5823. else
  5824. entity.AfterSaleState = 0;
  5825. entity.UpdateTime = DateTime.Now;
  5826. entity.Update();
  5827. returnSuccessMsg("操作成功!");
  5828. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5829. return;
  5830. }
  5831. returnErrorMsg("找不到订单记录");
  5832. }
  5833. }
  5834. public void get_erp_aftersalelist()
  5835. {
  5836. DataStruct dStruct = GetPostStruct();
  5837. List<string> lw = new List<string>();
  5838. int st = GetInt("st");
  5839. string tid = GetPostString("ctid");
  5840. if (st == 3)
  5841. {
  5842. if (tid.Length > 0)
  5843. {
  5844. string select_tid = getTidByCtid(tid);
  5845. lw.Add(string.Format("tid='{0}'", select_tid));
  5846. }
  5847. }
  5848. else
  5849. {
  5850. if (tid.Length > 0)
  5851. {
  5852. string select_tid = getTidByCtid(tid);
  5853. lw.Add(string.Format("tid='{0}'", select_tid));
  5854. }
  5855. }
  5856. string shopname = GetPostString("shopname");
  5857. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5858. string buyernick = GetPostString("buyer_nick");
  5859. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5860. string sellermemo = GetPostString("seller_memo");
  5861. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5862. string orderState = GetPostString("orderState");
  5863. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5864. string afterState = GetPostString("afterstate");
  5865. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5866. string date1 = GetPostString("date1");
  5867. string date2 = GetPostString("date2");
  5868. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5869. if (dw.Length > 0) lw.Add(dw);
  5870. string price1 = GetPostString("price1");
  5871. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5872. string price2 = GetPostString("price2");
  5873. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5874. //lw.Add(string.Format("IsRefund!={0}", 1));
  5875. string reason = GetPostString("reason");
  5876. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5877. string method = GetPostString("method");
  5878. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5879. string handler = GetPostString("handler");
  5880. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5881. string handledate1 = GetPostString("handledate1");
  5882. string handledate2 = GetPostString("handledate2");
  5883. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5884. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5885. string finish1 = GetPostString("finishdate1");
  5886. string finish2 = GetPostString("finishdate2");
  5887. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5888. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5889. string afterdate1 = GetPostString("afterdate1");
  5890. string afterdate2 = GetPostString("afterdate2");
  5891. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5892. if (afterDate.Length > 0) lw.Add(afterDate);
  5893. string supplier = GetPostString("supplier");
  5894. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5895. string responsible = GetPostString("responsibleman");
  5896. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5897. string customer = GetPostString("customer");
  5898. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5899. string design = GetPostString("design");
  5900. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5901. string afterMemoType = GetPostString("aftermemotype");
  5902. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5903. string posCode = CurrentUser.UserPost.Post.Code;
  5904. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5905. //{
  5906. // string vstate = GetPostString("vstate");
  5907. // if (vstate.Length > 0)
  5908. // {
  5909. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5910. // }
  5911. // if (posCode == "Supplier")
  5912. // {
  5913. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5914. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5915. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5916. // }
  5917. // else
  5918. // {
  5919. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5920. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5921. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5922. // {
  5923. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5924. // }
  5925. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5926. // {
  5927. // int orgid = CurrentUser.UserPost.OrgID;
  5928. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5929. // }
  5930. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5931. // {
  5932. // string shopid = CurrentUser.User.pemShop;
  5933. // lw.Add(string.Format("shopId in ({0})", shopid));
  5934. // }
  5935. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5936. // //{
  5937. // // int org_id = CurrentUser.UserPost.OrgID;
  5938. // // lw.Add(string.Format("OrgID={0}", org_id));
  5939. // //}
  5940. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5941. // }
  5942. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5943. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5944. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5945. //}
  5946. if (st == 5)
  5947. {
  5948. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5949. {
  5950. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5951. {
  5952. string shopid = CurrentUser.User.pemShop;
  5953. lw.Add(string.Format("shopId in ({0})", shopid));
  5954. }
  5955. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5956. {
  5957. int mrOrgid = CurrentUser.UserPost.OrgID;
  5958. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5959. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5960. }
  5961. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5962. //{
  5963. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5964. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5965. //}
  5966. else
  5967. {
  5968. string userIdStr = "";
  5969. if (posCode == "CustomerService")
  5970. {
  5971. userIdStr = CurrentUser.UserID + "_k";
  5972. }
  5973. else if (posCode == "Designer" || posCode == "wxDesigner")
  5974. {
  5975. userIdStr = CurrentUser.UserID + "_s";
  5976. }
  5977. else if (posCode == "Place")
  5978. {
  5979. userIdStr = CurrentUser.UserID + "_x";
  5980. }
  5981. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5982. }
  5983. }
  5984. string placedate1 = GetPostString("placedate1");
  5985. string placedate2 = GetPostString("placedate2");
  5986. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5987. if (dwplace.Length > 0) lw.Add(dwplace);
  5988. string supState = GetPostString("supState");
  5989. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  5990. string searchType = GetPostString("searchType");
  5991. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  5992. {
  5993. lw.Add(string.Format("BackNum>1"));
  5994. }
  5995. lw.Add(string.Format("AfterSaleState>0"));
  5996. if (ex_psize > 0)
  5997. {
  5998. if (CurrentUser.UserPost.Post.Code == "Finance")
  5999. dStruct.Order = "pay_time desc";
  6000. else
  6001. dStruct.Order = "HandleTime desc";
  6002. }
  6003. else
  6004. dStruct.Order = "HandleTime desc";
  6005. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6006. DataTable dt = WebCache.GetData("view_test", dStruct);
  6007. writeGridDataTableJson(dStruct.TotalCount, dt);
  6008. }
  6009. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6010. //{
  6011. // lw.Add(string.Format("AfterSaleState=4"));
  6012. // string code = CurrentUser.UserPost.Post.Code;
  6013. // if (code == "CustomerService")
  6014. // {
  6015. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6016. // }
  6017. // else if (code == "Designer" || code == "DesignerMr")
  6018. // {
  6019. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6020. // }
  6021. // else if (code == "Place" || code == "PlaceMr")
  6022. // {
  6023. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6024. // }
  6025. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6026. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6027. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6028. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6029. //}
  6030. //else //处理中的售后,待处理和处理中合并
  6031. //{
  6032. // if (afterState.Length <= 0)
  6033. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6034. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6035. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6036. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6037. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6038. //}
  6039. }
  6040. public void get_erp_disagreeftersalelist()
  6041. {
  6042. DataStruct dStruct = GetPostStruct();
  6043. List<string> lw = new List<string>();
  6044. int st = 2;
  6045. string tid = GetPostString("ctid");
  6046. if (tid.Length > 0)
  6047. {
  6048. string select_tid = getTidByCtid(tid);
  6049. lw.Add(string.Format("tid='{0}'", select_tid));
  6050. }
  6051. string shopname = GetPostString("shopname");
  6052. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6053. string buyernick = GetPostString("buyer_nick");
  6054. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6055. string sellermemo = GetPostString("seller_memo");
  6056. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6057. string orderState = GetPostString("orderState");
  6058. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6059. string afterState = GetPostString("afterstate");
  6060. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6061. string date1 = GetPostString("date1");
  6062. string date2 = GetPostString("date2");
  6063. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6064. if (dw.Length > 0) lw.Add(dw);
  6065. string price1 = GetPostString("price1");
  6066. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6067. string price2 = GetPostString("price2");
  6068. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6069. //lw.Add(string.Format("IsRefund!={0}", 1));
  6070. string reason = GetPostString("reason");
  6071. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6072. string method = GetPostString("method");
  6073. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6074. string handler = GetPostString("handler");
  6075. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6076. string handledate1 = GetPostString("handledate1");
  6077. string handledate2 = GetPostString("handledate2");
  6078. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6079. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6080. string afterdate1 = GetPostString("afterdate1");
  6081. string afterdate2 = GetPostString("afterdate2");
  6082. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6083. if (afterDate.Length > 0) lw.Add(afterDate);
  6084. string backdate1 = GetPostString("backdate1");
  6085. string backdate2 = GetPostString("backdate2");
  6086. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6087. if (backDate.Length > 0) lw.Add(backDate);
  6088. string supplier = GetPostString("supplier");
  6089. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6090. string responsible = GetPostString("responsibleman");
  6091. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6092. string customer = GetPostString("customer");
  6093. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6094. string design = GetPostString("design");
  6095. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6096. string afterSaleMemo = GetPostString("afterSaleMemo");
  6097. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6098. string afterMemoType = GetPostString("aftermemotype");
  6099. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6100. string aftersakereason = GetPostString("aftersakereason");
  6101. if (aftersakereason.Length > 0)
  6102. {
  6103. if (aftersakereason == "1")
  6104. {
  6105. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6106. }
  6107. if (aftersakereason == "2")
  6108. {
  6109. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6110. }
  6111. }
  6112. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6113. string poscode = CurrentUser.UserPost.Post.Code;
  6114. if (poscode != "SysAdmin")
  6115. {
  6116. string shopid = CurrentUser.User.pemShop;
  6117. lw.Add(string.Format("shopId in ({0})", shopid));
  6118. }
  6119. string searchType = GetPostString("searchType");
  6120. if (searchType == "wait")
  6121. {
  6122. lw.Add(string.Format("HandleTime is null"));
  6123. }
  6124. if (searchType == "handling")
  6125. {
  6126. lw.Add(string.Format("HandleTime is not null "));
  6127. }
  6128. if (searchType == "back" || searchType == "puBack")
  6129. {
  6130. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6131. }
  6132. if (searchType == "reBack")
  6133. {
  6134. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6135. }
  6136. if (searchType == "moreBack")
  6137. {
  6138. lw.Add(string.Format("backNum > 1"));
  6139. }
  6140. lw.Add(string.Format("(AfterSaleState=5)"));
  6141. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6142. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6143. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6144. writeGridDataTableJson(dStruct.TotalCount, dt);
  6145. }
  6146. public void get_erp_handlingaftersalelist()
  6147. {
  6148. DataStruct dStruct = GetPostStruct();
  6149. List<string> lw = new List<string>();
  6150. int st = 2;
  6151. string tid = GetPostString("ctid");
  6152. if (tid.Length > 0)
  6153. {
  6154. string select_tid = getTidByCtid(tid);
  6155. lw.Add(string.Format("tid='{0}'", select_tid));
  6156. }
  6157. string shopname = GetPostString("shopname");
  6158. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6159. string buyernick = GetPostString("buyer_nick");
  6160. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6161. string sellermemo = GetPostString("seller_memo");
  6162. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6163. string orderState = GetPostString("orderState");
  6164. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6165. string afterState = GetPostString("afterstate");
  6166. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6167. string date1 = GetPostString("date1");
  6168. string date2 = GetPostString("date2");
  6169. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6170. if (dw.Length > 0) lw.Add(dw);
  6171. string price1 = GetPostString("price1");
  6172. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6173. string price2 = GetPostString("price2");
  6174. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6175. //lw.Add(string.Format("IsRefund!={0}", 1));
  6176. string reason = GetPostString("reason");
  6177. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6178. string method = GetPostString("method");
  6179. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6180. string handler = GetPostString("handler");
  6181. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6182. string handledate1 = GetPostString("handledate1");
  6183. string handledate2 = GetPostString("handledate2");
  6184. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6185. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6186. string afterdate1 = GetPostString("afterdate1");
  6187. string afterdate2 = GetPostString("afterdate2");
  6188. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6189. if (afterDate.Length > 0) lw.Add(afterDate);
  6190. string supplier = GetPostString("supplier");
  6191. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6192. string responsible = GetPostString("responsibleman");
  6193. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6194. string customer = GetPostString("customer");
  6195. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6196. string design = GetPostString("design");
  6197. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6198. string afterSaleMemo = GetPostString("afterSaleMemo");
  6199. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6200. string afterMemoType = GetPostString("aftermemotype");
  6201. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6202. string afterresult = GetPostString("afterresult");
  6203. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6204. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6205. string poscode = CurrentUser.UserPost.Post.Code;
  6206. if (poscode != "SysAdmin")
  6207. {
  6208. string shopid = CurrentUser.User.pemShop;
  6209. lw.Add(string.Format("shopId in ({0})", shopid));
  6210. }
  6211. string searchType = GetPostString("searchType");
  6212. if (searchType == "wait")
  6213. {
  6214. lw.Add(string.Format("HandleTime is null"));
  6215. }
  6216. if (searchType == "documentary")
  6217. {
  6218. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6219. }
  6220. if (searchType == "handling")
  6221. {
  6222. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6223. }
  6224. if (searchType == "back" || searchType == "puBack")
  6225. {
  6226. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6227. }
  6228. if (searchType == "reBack")
  6229. {
  6230. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6231. }
  6232. if (afterState.Length <= 0)
  6233. {
  6234. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6235. }
  6236. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6237. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6238. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6239. writeGridDataTableJson(dStruct.TotalCount, dt);
  6240. }
  6241. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6242. //public void get_erp_back_handlingaftersalelist()
  6243. //{
  6244. // DataStruct dStruct = GetPostStruct();
  6245. // List<string> lw = new List<string>();
  6246. // string tid = GetPostString("ctid");
  6247. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6248. // string shopname = GetPostString("shopname");
  6249. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6250. // string buyernick = GetPostString("buyer_nick");
  6251. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6252. // string sellermemo = GetPostString("seller_memo");
  6253. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6254. // string orderState = GetPostString("orderState");
  6255. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6256. // string afterState = GetPostString("afterstate");
  6257. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6258. // string date1 = GetPostString("date1");
  6259. // string date2 = GetPostString("date2");
  6260. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6261. // if (dw.Length > 0) lw.Add(dw);
  6262. // string price1 = GetPostString("price1");
  6263. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6264. // string price2 = GetPostString("price2");
  6265. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6266. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6267. // string reason = GetPostString("reason");
  6268. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6269. // string method = GetPostString("method");
  6270. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6271. // string handler = GetPostString("handler");
  6272. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6273. // string handledate1 = GetPostString("handledate1");
  6274. // string handledate2 = GetPostString("handledate2");
  6275. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6276. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6277. // string afterdate1 = GetPostString("afterdate1");
  6278. // string afterdate2 = GetPostString("afterdate2");
  6279. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6280. // if (afterDate.Length > 0) lw.Add(afterDate);
  6281. // string supplier = GetPostString("supplier");
  6282. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6283. // string responsible = GetPostString("responsibleman");
  6284. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6285. // string customer = GetPostString("customer");
  6286. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6287. // string design = GetPostString("design");
  6288. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6289. // string afterMemoType = GetPostString("aftermemotype");
  6290. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6291. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6292. // if (afterState.Length <= 0)
  6293. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6294. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6295. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6296. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6297. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6298. //}
  6299. public void get_erp_aftersaleverifylist()
  6300. {
  6301. DataStruct dStruct = GetPostStruct();
  6302. List<string> lw = new List<string>();
  6303. string tid = GetPostString("ctid");
  6304. if (tid.Length > 0)
  6305. {
  6306. string select_tid = getTidByCtid(tid);
  6307. lw.Add(string.Format("tid='{0}'", select_tid));
  6308. }
  6309. string shopname = GetPostString("shopname");
  6310. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6311. string buyernick = GetPostString("buyer_nick");
  6312. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6313. string sellermemo = GetPostString("seller_memo");
  6314. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6315. string orderState = GetPostString("orderState");
  6316. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6317. //lw.Add(string.Format("IsRefund!={0}", 1));
  6318. string reason = GetPostString("reason");
  6319. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6320. string method = GetPostString("method");
  6321. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6322. string handler = GetPostString("handler");
  6323. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6324. string handledate1 = GetPostString("handledate1");
  6325. string handledate2 = GetPostString("handledate2");
  6326. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6327. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6328. string finish1 = GetPostString("finishdate1");
  6329. string finish2 = GetPostString("finishdate2");
  6330. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6331. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6332. string supplier = GetPostString("supplier");
  6333. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6334. string responsible = GetPostString("responsibleman");
  6335. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6336. string posCode = CurrentUser.UserPost.Post.Code;
  6337. string vstate = GetPostString("vstate");
  6338. if (vstate.Length > 0)
  6339. {
  6340. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6341. }
  6342. if (posCode == "Supplier")
  6343. {
  6344. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6345. lw.Add(string.Format("VerifyState = 0"));
  6346. lw.Add("type = 1");
  6347. lw.Add(string.Format("AfterSaleState={0}", 3));
  6348. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6349. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6350. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6351. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6352. writeGridDataTableJson(dStruct.TotalCount, dt);
  6353. }
  6354. else if (posCode == "logistics")
  6355. {
  6356. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6357. lw.Add(string.Format("VerifyState = 0"));
  6358. lw.Add("type = 2");
  6359. lw.Add(string.Format("AfterSaleState={0}", 3));
  6360. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6361. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6362. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6363. writeGridDataTableJson(dStruct.TotalCount, dt);
  6364. }
  6365. else
  6366. {
  6367. lw.Add(string.Format("(AfterSaleState = 3)"));
  6368. string reasonState = GetPostString("reasonState");
  6369. lw.Add("type = 0");
  6370. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6371. || posCode == "Summarize" || posCode == "Finance")
  6372. {
  6373. if (reasonState == "2")
  6374. {
  6375. lw.Add("VerifyState = 3");
  6376. }
  6377. else if (reasonState == "1")
  6378. {
  6379. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6380. }
  6381. else
  6382. {
  6383. lw.Add("VerifyState in (0,3)");
  6384. }
  6385. //不加条件,可以看全部
  6386. }
  6387. 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")
  6388. {
  6389. int orgid = CurrentUser.UserPost.OrgID;
  6390. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6391. if (string.IsNullOrEmpty(manageOrgId))
  6392. {
  6393. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6394. }
  6395. else
  6396. {
  6397. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6398. }
  6399. if (reasonState == "1")
  6400. {
  6401. lw.Add("VerifyState = 3");
  6402. }
  6403. else if (reasonState == "2")
  6404. {
  6405. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6406. }
  6407. else
  6408. {
  6409. }
  6410. }
  6411. else
  6412. {
  6413. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6414. }
  6415. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6416. //{
  6417. // int org_id = CurrentUser.UserPost.OrgID;
  6418. // lw.Add(string.Format("OrgID={0}", org_id));
  6419. //}
  6420. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6421. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6422. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6423. writeGridDataTableJson(dStruct.TotalCount, dt);
  6424. }
  6425. }
  6426. public void get_erp_finishaftersalelist()
  6427. {
  6428. DataStruct dStruct = GetPostStruct();
  6429. List<string> lw = new List<string>();
  6430. int st = 4;
  6431. string tid = GetPostString("ctid");
  6432. if (tid.Length > 0)
  6433. {
  6434. string select_tid = getTidByCtid(tid);
  6435. lw.Add(string.Format("tid='{0}'", select_tid));
  6436. }
  6437. string shopname = GetPostString("shopname");
  6438. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6439. //lw.Add(string.Format("IsRefund!={0}", 1));
  6440. string reason = GetPostString("reason");
  6441. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6442. string method = GetPostString("method");
  6443. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6444. string buyernick = GetPostString("buyer_nick");
  6445. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6446. string handler = GetPostString("handler");
  6447. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6448. string handledate1 = GetPostString("handledate1");
  6449. string handledate2 = GetPostString("handledate2");
  6450. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6451. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6452. string finish1 = GetPostString("finishdate1");
  6453. string finish2 = GetPostString("finishdate2");
  6454. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6455. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6456. string supplier = GetPostString("supplier");
  6457. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6458. string responsible = GetPostString("responsibleman");
  6459. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6460. string vstate = GetPostString("vstate");
  6461. if (vstate.Length > 0)
  6462. {
  6463. if ("3".Equals(vstate))
  6464. {
  6465. lw.Add(string.Format("IsTem=1"));
  6466. }
  6467. else
  6468. {
  6469. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6470. }
  6471. }
  6472. lw.Add(string.Format("AfterSaleState=4"));
  6473. string code = CurrentUser.UserPost.Post.Code;
  6474. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6475. {
  6476. //不加条件,可以看全部
  6477. }
  6478. else if (code == "Supplier")
  6479. {
  6480. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6481. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6482. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6483. }
  6484. else if (code == "logistics")
  6485. {
  6486. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6487. lw.Add("type = 2");
  6488. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6489. }
  6490. 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")
  6491. {
  6492. int orgid = CurrentUser.UserPost.OrgID;
  6493. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6494. if (string.IsNullOrEmpty(manageOrgIds))
  6495. {
  6496. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6497. }
  6498. else
  6499. {
  6500. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6501. }
  6502. }
  6503. else
  6504. {
  6505. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6506. }
  6507. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6508. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6509. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6510. writeGridDataTableJson(dStruct.TotalCount, dt);
  6511. }
  6512. public void handle_erp_aftersale()
  6513. {
  6514. if (UrlPostParmsCheck("ctid"))
  6515. {
  6516. string eid = GetPostString("ctid");
  6517. string responStr = GetPostString("AfterSaleResponsible");
  6518. if (responStr.Length <= 0)
  6519. {
  6520. returnErrorMsg("售后责任人不能为空");
  6521. return;
  6522. }
  6523. bool isDesign = false;
  6524. double designFree = 0.00;
  6525. int responsibleId = 0;
  6526. CeErpTradeCell entity = null;
  6527. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6528. if (entity != null)
  6529. {
  6530. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6531. string afterMethod = GetPostString("AfterSaleMethod");
  6532. if (isNeedNewOrder == 1)
  6533. {
  6534. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6535. bool ishav = true;
  6536. if (newentity == null)
  6537. {
  6538. newentity = entity.Clone() as CeErpTradeCell;
  6539. ishav = false;
  6540. newentity.ctid = "S_" + entity.ctid;
  6541. newentity.OrderState = 0;
  6542. //唯一标识
  6543. newentity.OrderSn = newentity.ctid;
  6544. string orderSn = dataHelper.getSaleOrderSn();
  6545. if (orderSn != "")
  6546. {
  6547. newentity.OrderSn = orderSn;
  6548. }
  6549. }
  6550. newentity.UpdateTime = DateTime.Now;
  6551. newentity.AfterSaleState = 0;
  6552. newentity.AfterSaleMethod = afterMethod;
  6553. if (!ishav)
  6554. {
  6555. string memo_str = newentity.seller_memo;
  6556. memo_str = memo_str.Replace("(", "(");
  6557. memo_str = memo_str.Replace(")", ")");
  6558. int sIndex = memo_str.IndexOf("(");
  6559. int eIndex = memo_str.IndexOf(")");
  6560. if (sIndex == -1 || eIndex == -1)
  6561. {
  6562. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6563. return;
  6564. }
  6565. string first = memo_str.Substring(0, sIndex + 1);
  6566. string memoCtid = newentity.OrderSn;
  6567. //if (memoCtid.IndexOf("C") != -1)
  6568. //{
  6569. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6570. //if (CIdx.IndexOf("+") != -1)
  6571. //{
  6572. //CIdx = "C" + CIdx.Split('+')[1];
  6573. //}
  6574. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6575. //}
  6576. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6577. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6578. string newMemo = first + memoCtid + last;
  6579. newentity.seller_memo = newMemo;
  6580. newentity.FinishPlaceTime = null;
  6581. newentity.UnusualTag = 0;
  6582. newentity.UnusualCon = "";
  6583. newentity.UnusualTime = null;
  6584. newentity.AfterSaleMemo = "";
  6585. newentity.AfterSaleMethod = afterMethod;
  6586. newentity.AfterSalePreTime = null;
  6587. newentity.AfterSaleReason = "";
  6588. newentity.AfterSaleResponsible = "";
  6589. newentity.AfterSaleState = 0;
  6590. newentity.AfterSaleTime = null;
  6591. newentity.AfterSaleUserId = 0;
  6592. newentity.AfterSaleSupplierState = 0;
  6593. newentity.LastBillWaybillCode = "";
  6594. newentity.LastBillCpCode = "";
  6595. newentity.FinishAfterSaleTime = null;
  6596. newentity.HandleTime = null;
  6597. newentity.IsSF = 0;
  6598. newentity.IsOldCustomer = 0;
  6599. newentity.UrgencyTime = null;
  6600. newentity.ResponsibleUserId = "";
  6601. newentity.IsVerifyToSupplier = false;
  6602. newentity.payment = 0;
  6603. newentity.CheckMemo = "";
  6604. newentity.OutSid = "";
  6605. newentity.CheckOrderTime = null;
  6606. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6607. }
  6608. newentity.isAfterSaleOrder = 1;
  6609. newentity.IsRefund = 0;
  6610. string receiveMobile = GetPostString("receiver_mobile");
  6611. if (receiveMobile.Length > 0)
  6612. {
  6613. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6614. if (trade != null)
  6615. {
  6616. trade.receiver_name = GetPostString("receiver_name");
  6617. trade.receiver_mobile = receiveMobile;
  6618. trade.receiver_state = GetPostString("receiver_state");
  6619. trade.receiver_city = GetPostString("receiver_city");
  6620. trade.receiver_district = GetPostString("receiver_district");
  6621. trade.receiver_address = GetPostString("receiver_address");
  6622. newentity.IsOffLineOrder = 1;
  6623. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6624. }
  6625. }
  6626. string st = GetPostString("ToState");
  6627. if (st.Length > 0)
  6628. {
  6629. if (newentity.OrderState <= 3)
  6630. {
  6631. newentity.WaitDesignTime = DateTime.Now;
  6632. newentity.StartDesignTime = null;
  6633. newentity.FinishDesignTime = null;
  6634. newentity.OrderState = 3;
  6635. if (st == "下单员")
  6636. {
  6637. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6638. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6639. {
  6640. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6641. }
  6642. }
  6643. else
  6644. {
  6645. newentity.WaitDesignTime = DateTime.Now;
  6646. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6647. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6648. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6649. {
  6650. DataRow user = dt1.Rows[0];
  6651. //找主管
  6652. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6653. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6654. if (dt != null && dt.Rows.Count > 0)
  6655. {
  6656. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6657. newentity.DesignUserId = designMr;
  6658. string key = "aftersale_order_" + designMr;
  6659. if (RedisHelper.HasKey(key))
  6660. {
  6661. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6662. list.Add(newentity.ctid);
  6663. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6664. }
  6665. }
  6666. //账号正常
  6667. if (user["State"].ToString() == "0")
  6668. {
  6669. newentity.DesignUserId = entity.DesignUserId;
  6670. string key = "aftersale_order_" + entity.DesignUserId;
  6671. if (RedisHelper.HasKey(key))
  6672. {
  6673. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6674. list.Add(newentity.ctid);
  6675. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6676. }
  6677. }
  6678. }
  6679. }
  6680. }
  6681. if (entity.IsXianHuo == 1)
  6682. {
  6683. newentity.OrderState = 6;
  6684. entity.FinishPlaceTime = DateTime.Now;
  6685. }
  6686. }
  6687. if (ishav)
  6688. {
  6689. newentity.Update();
  6690. }
  6691. else
  6692. {
  6693. newentity.Create();
  6694. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6695. newCellExtend.ctid = newentity.ctid;
  6696. newCellExtend.orderFrom = 20;
  6697. newCellExtend.orderType = 30;
  6698. if (st == "下单员")
  6699. {
  6700. }
  6701. else
  6702. {
  6703. newCellExtend.ReprintTime = DateTime.Now;
  6704. }
  6705. newCellExtend.Create();
  6706. }
  6707. if (st != "下单员")
  6708. {
  6709. designHelper.API_GetPrintData_CreateOrder(newentity);
  6710. }
  6711. }
  6712. //处理售后扩展
  6713. string resIdStr = GetPostString("ResponsibleUserId");
  6714. string refundFees = GetPostString("refundFrees");
  6715. int IsComplain = GetPostInt("isComplain");
  6716. int IsBad = GetPostInt("isBad");
  6717. string IsOriginal = GetPostString("isOriginal");
  6718. double diffResultPrice = GetPostDouble("diffResultPrice");
  6719. string textResult = GetPostString("textResult");
  6720. string supplierResponsible = GetPostString("supplierResponsible");
  6721. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6722. if (ceErpTradeAfterSaleExtend == null)
  6723. {
  6724. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6725. ceErpTradeAfterSaleExtend.tid = eid;
  6726. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6727. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6728. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6729. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6730. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6731. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6732. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6733. ceErpTradeAfterSaleExtend.Create();
  6734. }
  6735. else
  6736. {
  6737. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6738. {
  6739. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6740. }
  6741. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6742. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6743. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6744. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6745. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6746. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6747. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6748. ceErpTradeAfterSaleExtend.Update();
  6749. }
  6750. int gysid = GetPostInt("ResponsibleSupId");
  6751. if (entity.AfterSaleUserId == 0)
  6752. {
  6753. entity.AfterSaleUserId = CurrentUser.UserID;
  6754. }
  6755. entity.ResponsibleUserId = resIdStr;
  6756. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6757. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6758. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6759. {
  6760. CeErpTradeResponsible.DelByTid(eid, -1);
  6761. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6762. int backNum = 0;
  6763. if (number != null)
  6764. {
  6765. backNum = number.BackNum;
  6766. }
  6767. char[] separator = { ',' };
  6768. string[] sArray = resIdStr.Split(separator);
  6769. string[] refundFreeList = { };
  6770. if (refundFees.Length > 0)
  6771. {
  6772. refundFreeList = refundFees.Split(separator);
  6773. }
  6774. int index = -1;
  6775. foreach (string i in sArray)
  6776. {
  6777. index++;
  6778. if (i.Length <= 0) continue;
  6779. char[] separator2 = { '_' };
  6780. string idstr = i.Split(separator2)[0];
  6781. string idtype = i.Split(separator2)[1];
  6782. double refudFree = 0;
  6783. if (refundFreeList.Length > 0)
  6784. {
  6785. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6786. }
  6787. if (idtype == "s")
  6788. {
  6789. isDesign = true;
  6790. designFree = refudFree;
  6791. }
  6792. int userId = Convert.ToInt32(idstr);
  6793. int type = 0;
  6794. if (idtype == "g")
  6795. {
  6796. type = 1;
  6797. }
  6798. if (idtype == "w")
  6799. {
  6800. type = 2;
  6801. }
  6802. if (idtype == "t")
  6803. {
  6804. type = 3;
  6805. }
  6806. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6807. if (ceErpTradeResponsible == null)
  6808. {
  6809. ceErpTradeResponsible = new CeErpTradeResponsible();
  6810. ceErpTradeResponsible.tid = eid;
  6811. ceErpTradeResponsible.UserId = userId;
  6812. ceErpTradeResponsible.createdTime = DateTime.Now;
  6813. ceErpTradeResponsible.type = type;
  6814. if (type == 1)
  6815. {
  6816. ceErpTradeResponsible.IsSup = 1;
  6817. }
  6818. if (type == 2)
  6819. {
  6820. ceErpTradeResponsible.IsFlow = 1;
  6821. }
  6822. }
  6823. ceErpTradeResponsible.RefundFee = refudFree;
  6824. ceErpTradeResponsible.VerifyState = 0;
  6825. if (userId == 2125 || idtype == "w")
  6826. {
  6827. ceErpTradeResponsible.VerifyState = 1;
  6828. }
  6829. if (idtype == "w" && userId == 101)
  6830. {
  6831. ceErpTradeResponsible.VerifyState = 0;
  6832. }
  6833. if (ceErpTradeResponsible.ID > 0)
  6834. {
  6835. ceErpTradeResponsible.Update();
  6836. }
  6837. else
  6838. {
  6839. ceErpTradeResponsible.Create();
  6840. }
  6841. if (isDesign)
  6842. {
  6843. responsibleId = ceErpTradeResponsible.ID;
  6844. }
  6845. }
  6846. CeErpTradeResponsible.NumByTid(backNum, eid);
  6847. }
  6848. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6849. if (ceErpTradeCellExtend != null)
  6850. {
  6851. ceErpTradeCellExtend.returnVisit = 0;
  6852. ceErpTradeCellExtend.Update();
  6853. }
  6854. if (entity.HandleTime != null)
  6855. {
  6856. if (entity.AfterSaleState == 1)
  6857. {
  6858. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6859. }
  6860. else
  6861. {
  6862. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6863. }
  6864. }
  6865. else
  6866. {
  6867. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6868. entity.HandleTime = DateTime.Now;
  6869. }
  6870. bool isCompale = false;
  6871. if (entity.AfterSaleState == 5)
  6872. {
  6873. isCompale = true;
  6874. entity.AfterSaleState = 3;
  6875. }
  6876. entity.AfterSaleSupplierState = 0;
  6877. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6878. {
  6879. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6880. }
  6881. string sImgs = GetPostString("img");
  6882. entity.AfterSaleSupplierImg = sImgs;
  6883. entity.supRefundType = GetPostString("supRefundType");
  6884. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6885. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6886. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6887. entity.AfterSaleMemoType = GetPostString("MemoType");
  6888. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6889. {
  6890. //entity.AfterSaleSupplierState = 2;
  6891. }
  6892. string df = GetPostString("DeductFee");
  6893. if (df == "")
  6894. {
  6895. df = "0";
  6896. }
  6897. string rf = GetPostString("RefundFee");
  6898. if (rf == "")
  6899. {
  6900. rf = "0";
  6901. }
  6902. string pm = GetPostString("AfterSalePayment");
  6903. if (pm == "")
  6904. {
  6905. pm = "0";
  6906. }
  6907. entity.AfterSalePayment = Convert.ToDouble(pm);
  6908. entity.DeductFee = Convert.ToDouble(df);
  6909. entity.RefundFee = Convert.ToDouble(rf);
  6910. entity.UpdateTime = DateTime.Now;
  6911. entity.Update();
  6912. string toState = GetPostString("ToState");
  6913. string original = GetPostString("isOriginal");
  6914. ApiVo apiVo = new ApiVo();
  6915. apiVo.orderNumber = entity.ctid;
  6916. apiVo.actionName = "afterDesign";
  6917. apiVo.orderRemarks = entity.AfterSaleMethod;
  6918. apiVo.reasonRemarks = entity.AfterSaleReason;
  6919. apiVo.isDesign = isDesign;
  6920. apiVo.designFree = designFree;
  6921. apiVo.responsibleId = responsibleId;
  6922. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6923. if (toState == "设计师")
  6924. {
  6925. apiVo.isOriginal = Convert.ToBoolean(original);
  6926. }
  6927. designHelper.API_WorkCore(apiVo);//afterDesign
  6928. CeErpMethod methodSql = new CeErpMethod();
  6929. methodSql.con = entity.AfterSaleMethod;
  6930. methodSql.addTime = DateTime.Now;
  6931. methodSql.Create();
  6932. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6933. CeErpMethod.ExecuteNonQuery(delsql);
  6934. if (isCompale)
  6935. {
  6936. aftersale_data_change(entity.ctid);
  6937. }
  6938. returnSuccessMsg("操作成功!");
  6939. return;
  6940. }
  6941. returnErrorMsg("找不到订单记录");
  6942. }
  6943. }
  6944. public void ins_erp_toresponsible()
  6945. {
  6946. if (UrlPostParmsCheck("ctid"))
  6947. {
  6948. string eid = GetPostString("ctid");
  6949. CeErpTradeCell entity = null;
  6950. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6951. if (entity != null)
  6952. {
  6953. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6954. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6955. {
  6956. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6957. return;
  6958. }
  6959. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6960. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6961. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6962. if (entity.AfterSalePreTime == null)
  6963. {
  6964. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6965. {
  6966. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6967. }
  6968. }
  6969. entity.AfterSalePreTime = DateTime.Now;
  6970. //预完成给售后主管审核客户问题直接完成
  6971. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6972. {
  6973. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6974. {
  6975. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6976. }
  6977. }
  6978. ceErpTradeAfterSaleExtend.Update();
  6979. entity.AfterSaleState = 2;
  6980. entity.UpdateTime = DateTime.Now;
  6981. entity.Update();
  6982. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  6983. aftersale_data_change(entity.ctid);
  6984. returnSuccessMsg("操作成功!");
  6985. return;
  6986. }
  6987. returnErrorMsg("找不到订单记录");
  6988. }
  6989. }
  6990. public void cancel_erp_aftersaleanddelnew()
  6991. {
  6992. if (UrlPostParmsCheck("ctid"))
  6993. {
  6994. string eid = GetPostString("ctid");
  6995. CeErpTradeCell entity = null;
  6996. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6997. if (entity != null)
  6998. {
  6999. entity.AfterSaleState = 0;
  7000. entity.AfterSaleReason = "";
  7001. entity.AfterSaleMethod = "";
  7002. entity.AfterSaleMemo = "";
  7003. entity.AfterSaleResponsible = "";
  7004. entity.ResponsibleUserId = "";
  7005. entity.DeductFee = 0;
  7006. entity.RefundFee = 0;
  7007. entity.IsArbitrate = 0;
  7008. CeErpTradeResponsible.DelByTid(eid, -1);
  7009. entity.Update();
  7010. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7011. if (after != null)
  7012. {
  7013. if (after.OrderState < 5)
  7014. CeErpTradeCell.DelByCtid("S_" + eid);
  7015. }
  7016. returnSuccessMsg("操作成功!");
  7017. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7018. return;
  7019. }
  7020. returnErrorMsg("找不到订单记录");
  7021. }
  7022. }
  7023. public void get_erp_aftersale_pregather()
  7024. {
  7025. List<string> lw = new List<string>();
  7026. int st = GetInt("st");
  7027. string tid = GetPostString("ctid");
  7028. if (tid.Length > 0)
  7029. {
  7030. string select_tid = getTidByCtid(tid);
  7031. lw.Add(string.Format("tid='{0}'", select_tid));
  7032. }
  7033. string shopname = GetPostString("shopname");
  7034. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7035. string buyernick = GetPostString("buyer_nick");
  7036. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7037. string sellermemo = GetPostString("seller_memo");
  7038. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7039. string orderState = GetPostString("orderState");
  7040. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7041. string reason = GetPostString("reason");
  7042. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7043. string method = GetPostString("method");
  7044. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7045. string handler = GetPostString("handler");
  7046. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7047. string handledate1 = GetPostString("handledate1");
  7048. string handledate2 = GetPostString("handledate2");
  7049. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7050. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7051. string supplier = GetPostString("supplier");
  7052. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7053. string responsible = GetPostString("responsibleman");
  7054. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7055. string customer = GetPostString("customer");
  7056. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7057. string design = GetPostString("design");
  7058. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7059. string afterMemoType = GetPostString("aftermemotype");
  7060. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7061. string afterSaleMemo = GetPostString("afterSaleMemo");
  7062. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7063. string afterresult = GetPostString("afterresult");
  7064. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7065. string poscode = CurrentUser.UserPost.Post.Code;
  7066. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7067. {
  7068. string shopid = CurrentUser.User.pemShop;
  7069. lw.Add(string.Format("shopId in ({0})", shopid));
  7070. }
  7071. var mainwhere = string.Join(" and ", lw.ToArray());
  7072. string ro_json = "";
  7073. string type = GetPostString("gather_type");
  7074. int number = 0;
  7075. if (poscode == "AfterSale")
  7076. {
  7077. //处理中
  7078. if (type == "Handling")
  7079. {
  7080. 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) : ""));
  7081. DataTable dt = null;
  7082. try
  7083. {
  7084. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7085. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7086. }
  7087. catch (Exception e)
  7088. {
  7089. dt = new DataTable();
  7090. }
  7091. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7092. return;
  7093. }
  7094. if (type == "Wait")
  7095. {
  7096. //待处理
  7097. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7098. DataTable dt1 = null;
  7099. try
  7100. {
  7101. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7102. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7103. }
  7104. catch (Exception e)
  7105. {
  7106. dt1 = new DataTable();
  7107. }
  7108. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7109. return;
  7110. }
  7111. if (type == "back")
  7112. {
  7113. //打回
  7114. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7115. DataTable dt2 = null;
  7116. try
  7117. {
  7118. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7119. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7120. }
  7121. catch (Exception e)
  7122. {
  7123. dt2 = new DataTable();
  7124. }
  7125. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7126. return;
  7127. }
  7128. if (type == "preCompletion")
  7129. {
  7130. //预完成
  7131. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7132. DataTable dt3 = null;
  7133. try
  7134. {
  7135. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7136. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7137. }
  7138. catch (Exception e)
  7139. {
  7140. dt3 = new DataTable();
  7141. }
  7142. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7143. return;
  7144. }
  7145. if (type == "documentary")
  7146. {
  7147. //跟单中
  7148. 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) : ""));
  7149. DataTable dt4 = null;
  7150. try
  7151. {
  7152. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7153. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7154. }
  7155. catch (Exception e)
  7156. {
  7157. dt4 = new DataTable();
  7158. }
  7159. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7160. return;
  7161. }
  7162. if (type == "reBack")
  7163. {
  7164. //被打回
  7165. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7166. DataTable dt1 = null;
  7167. try
  7168. {
  7169. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7170. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7171. }
  7172. catch (Exception e)
  7173. {
  7174. dt1 = new DataTable();
  7175. }
  7176. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7177. return;
  7178. }
  7179. }
  7180. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7181. {
  7182. if (type == "puBack")
  7183. {
  7184. //退回
  7185. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7186. DataTable dt = null;
  7187. try
  7188. {
  7189. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7190. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7191. }
  7192. catch (Exception e)
  7193. {
  7194. dt = new DataTable();
  7195. }
  7196. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7197. return;
  7198. }
  7199. if (type == "reBack")
  7200. {
  7201. //打回
  7202. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7203. DataTable dt1 = null;
  7204. try
  7205. {
  7206. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7207. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7208. }
  7209. catch (Exception e)
  7210. {
  7211. dt1 = new DataTable();
  7212. }
  7213. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7214. return;
  7215. }
  7216. if (type == "examEd")
  7217. {
  7218. //已审核
  7219. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7220. DataTable dt2 = null;
  7221. try
  7222. {
  7223. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7224. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7225. }
  7226. catch (Exception e)
  7227. {
  7228. dt2 = new DataTable();
  7229. }
  7230. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7231. return;
  7232. }
  7233. if (type == "waitExam")
  7234. {
  7235. //待审核
  7236. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7237. DataTable dt3 = null;
  7238. try
  7239. {
  7240. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7241. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7242. }
  7243. catch (Exception e)
  7244. {
  7245. dt3 = new DataTable();
  7246. }
  7247. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7248. return;
  7249. }
  7250. if (type == "Handling")
  7251. {
  7252. //处理中
  7253. 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) : ""));
  7254. DataTable dt4 = null;
  7255. try
  7256. {
  7257. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7258. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7259. }
  7260. catch (Exception e)
  7261. {
  7262. dt4 = new DataTable();
  7263. }
  7264. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7265. return;
  7266. }
  7267. if (type == "Wait")
  7268. {
  7269. //待处理
  7270. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7271. DataTable dt5 = null;
  7272. try
  7273. {
  7274. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7275. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7276. }
  7277. catch (Exception e)
  7278. {
  7279. dt5 = new DataTable();
  7280. }
  7281. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7282. return;
  7283. }
  7284. if (type == "documentary")
  7285. {
  7286. //跟单中
  7287. 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) : ""));
  7288. DataTable dt6 = null;
  7289. try
  7290. {
  7291. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7292. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7293. }
  7294. catch (Exception e)
  7295. {
  7296. dt6 = new DataTable();
  7297. }
  7298. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7299. return;
  7300. }
  7301. }
  7302. returnSuccess(ro_json);
  7303. }
  7304. public void end_erp_aftersale()
  7305. {
  7306. if (UrlPostParmsCheck("ctid"))
  7307. {
  7308. string eid = GetPostString("ctid");
  7309. CeErpTradeCell entity = null;
  7310. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7311. if (entity != null)
  7312. {
  7313. string stype = GetPostString("stype");
  7314. string typeStr = stype;
  7315. entity.AfterSaleState = 4;
  7316. entity.FinishAfterSaleTime = DateTime.Now;
  7317. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7318. entity.Update();
  7319. ApiVo apiVo = new ApiVo();
  7320. apiVo.orderNumber = entity.ctid;
  7321. apiVo.actionName = "afterOver";
  7322. designHelper.API_WorkCore(apiVo); //afterOver
  7323. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7324. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7325. CeErpSukuraData.createInfo(entity.ctid, 8);
  7326. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7327. returnSuccessMsg("操作成功!");
  7328. return;
  7329. }
  7330. returnErrorMsg("找不到订单记录");
  7331. }
  7332. }
  7333. public void ins_erp_finishaftersale()
  7334. {
  7335. if (UrlPostParmsCheck("id"))
  7336. {
  7337. string eid = GetPostString("id");
  7338. CeErpTradeResponsible entity = null;
  7339. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7340. if (entity != null)
  7341. {
  7342. entity.VerifyState = 1;
  7343. entity.VerifyTime = DateTime.Now;
  7344. entity.Update();
  7345. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7346. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7347. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7348. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7349. if (dt.Rows.Count <= 0)
  7350. {
  7351. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7352. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7353. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7354. CeErpSukuraData.createInfo(entity.tid, 8);
  7355. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7356. {
  7357. CeErpDesignerBill.Del(entity.tid);
  7358. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7359. }
  7360. }
  7361. returnSuccessMsg("操作成功!");
  7362. return;
  7363. }
  7364. returnErrorMsg("找不到订单记录");
  7365. }
  7366. }
  7367. public void upd_erp_arbitrateaftersale()
  7368. {
  7369. if (UrlPostParmsCheck("id"))
  7370. {
  7371. string eid = GetPostString("id");
  7372. CeErpTradeResponsible entity = null;
  7373. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7374. if (entity != null)
  7375. {
  7376. entity.IsArbitrate = 1;
  7377. entity.ArbitradeMemo = GetPostString("reason");
  7378. entity.VerifyState = 2;
  7379. entity.Update();
  7380. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7381. if (tradecell != null)
  7382. {
  7383. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7384. tradecell.IsArbitrate = 1;
  7385. tradecell.Update();
  7386. }
  7387. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7388. returnSuccessMsg("操作成功!");
  7389. return;
  7390. }
  7391. returnErrorMsg("找不到订单记录");
  7392. }
  7393. }
  7394. public void upd_erp_backaftersale()
  7395. {
  7396. if (UrlPostParmsCheck("tid"))
  7397. {
  7398. string eid = GetPostString("tid");
  7399. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7400. int backNum = 0;
  7401. if (number != null)
  7402. {
  7403. backNum = number.BackNum;
  7404. }
  7405. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7406. CeErpTradeCell entity = null;
  7407. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7408. if (entity != null)
  7409. {
  7410. entity.AfterSaleBackReason = GetPostString("backreason");
  7411. entity.AfterSaleState = 1;
  7412. entity.AfterSaleSupplierState = 0;
  7413. entity.UpdateTime = DateTime.Now;
  7414. entity.Update();
  7415. returnSuccessMsg("操作成功!");
  7416. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7417. return;
  7418. }
  7419. returnErrorMsg("找不到订单记录");
  7420. }
  7421. }
  7422. public void get_erp_supplieraftersalelist()
  7423. {
  7424. DataStruct dStruct = GetPostStruct();
  7425. List<string> lw = new List<string>();
  7426. string tid = GetPostString("ctid");
  7427. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7428. string shopname = GetPostString("shopname");
  7429. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7430. string buyernick = GetPostString("buyer_nick");
  7431. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7432. string sellermemo = GetPostString("seller_memo");
  7433. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7434. string orderState = GetPostString("orderState");
  7435. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7436. string afterState = GetPostString("afterstate");
  7437. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7438. string date1 = GetPostString("date1");
  7439. string date2 = GetPostString("date2");
  7440. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7441. if (dw.Length > 0) lw.Add(dw);
  7442. string price1 = GetPostString("price1");
  7443. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7444. string price2 = GetPostString("price2");
  7445. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7446. string reason = GetPostString("reason");
  7447. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7448. string method = GetPostString("method");
  7449. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7450. string handledate1 = GetPostString("handledate1");
  7451. string handledate2 = GetPostString("handledate2");
  7452. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7453. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7454. string handler = GetPostString("handler");
  7455. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7456. string afterdate1 = GetPostString("afterdate1");
  7457. string afterdate2 = GetPostString("afterdate2");
  7458. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7459. if (afterDate.Length > 0) lw.Add(afterDate);
  7460. string customer = GetPostString("customer");
  7461. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7462. string design = GetPostString("design");
  7463. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7464. string afterMemoType = GetPostString("aftermemotype");
  7465. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7466. string vstate = GetPostString("vstate");
  7467. if (vstate.Length > 0)
  7468. {
  7469. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7470. }
  7471. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7472. string supplier = GetPostString("supplier");
  7473. int supid = commonHelper.getSupplierIDByName(supplier);
  7474. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7475. string posCode = CurrentUser.UserPost.Post.Code;
  7476. if (posCode == "Supplier")
  7477. {
  7478. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7479. }
  7480. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7481. {
  7482. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7483. }
  7484. else
  7485. {
  7486. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7487. }
  7488. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7489. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7490. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7491. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7492. writeGridDataTableJson(dStruct.TotalCount, dt);
  7493. }
  7494. public void upd_erp_supverifyaftersale()
  7495. {
  7496. if (UrlPostParmsCheck("id"))
  7497. {
  7498. string id = GetPostString("id");
  7499. int st = GetPostInt("afterstate");
  7500. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7501. CeErpTradeCell entity = null;
  7502. if (ceErpTradeResponsible != null)
  7503. {
  7504. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7505. }
  7506. string afmemo = GetPostString("supmemo");
  7507. string image = GetPostString("image");
  7508. if (entity != null)
  7509. {
  7510. entity.AfterSaleSupplierState = st;
  7511. entity.AfterSaleSupplierMemo = afmemo;
  7512. if (st == 1)
  7513. {
  7514. ceErpTradeResponsible.VerifyState = 1;
  7515. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7516. ceErpTradeResponsible.Update();
  7517. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7518. if (isAll)
  7519. {
  7520. entity.AfterSaleState = 4;
  7521. entity.FinishAfterSaleTime = DateTime.Now;
  7522. }
  7523. }
  7524. else
  7525. {
  7526. CeErpTradeResponsible.dateByTid(entity.ctid);
  7527. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7528. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7529. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7530. if (num <= 1)
  7531. {
  7532. entity.AfterSaleState = 1;
  7533. }
  7534. else
  7535. {
  7536. entity.AfterSaleState = 5;
  7537. }
  7538. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7539. if (ceErpTradeAfterSaleExtend != null)
  7540. {
  7541. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7542. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7543. ceErpTradeAfterSaleExtend.Update();
  7544. }
  7545. else
  7546. {
  7547. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7548. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7549. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7550. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7551. ceErpTradeAfterSaleExtend.Create();
  7552. }
  7553. }
  7554. if (entity.AfterSaleState == 4)
  7555. {
  7556. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7557. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7558. {
  7559. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7560. }
  7561. ApiVo apiVo = new ApiVo();
  7562. apiVo.orderNumber = entity.ctid;
  7563. apiVo.actionName = "afterOver";
  7564. designHelper.API_WorkCore(apiVo); //afterOver
  7565. }
  7566. entity.UpdateTime = DateTime.Now;
  7567. entity.Update();
  7568. returnSuccessMsg("操作成功!");
  7569. CeErpSukuraData.createInfo(entity.ctid, 8);
  7570. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7571. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7572. return;
  7573. }
  7574. returnErrorMsg("找不到订单记录");
  7575. }
  7576. }
  7577. public void upd_erp_masteraftersale()
  7578. {
  7579. if (UrlPostParmsCheck("id"))
  7580. {
  7581. string id = GetPostString("id");
  7582. int st = GetPostInt("afterstate");
  7583. string afmemo = GetPostString("supmemo");
  7584. string image = GetPostString("image");
  7585. string textResult = GetPostString("textResult");
  7586. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7587. if (ceErpTradeResponsible != null)
  7588. {
  7589. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7590. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7591. ceErpTradeResponsible.Update();
  7592. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7593. if (entity != null)
  7594. {
  7595. entity.AfterSaleSupplierState = st;
  7596. entity.AfterSaleSupplierMemo = afmemo;
  7597. if (st == 1)
  7598. {
  7599. }
  7600. else
  7601. {
  7602. CeErpTradeResponsible.dateByTid(entity.ctid);
  7603. //退回到售后
  7604. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7605. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7606. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7607. if (num <= 1)
  7608. {
  7609. entity.AfterSaleState = 1;
  7610. }
  7611. else
  7612. {
  7613. entity.AfterSaleState = 5;
  7614. }
  7615. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7616. if (ceErpTradeAfterSaleExtend != null)
  7617. {
  7618. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7619. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7620. ceErpTradeAfterSaleExtend.Update();
  7621. }
  7622. else
  7623. {
  7624. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7625. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7626. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7627. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7628. ceErpTradeAfterSaleExtend.Create();
  7629. }
  7630. }
  7631. entity.UpdateTime = DateTime.Now;
  7632. entity.Update();
  7633. returnSuccessMsg("操作成功!");
  7634. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7635. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7636. return;
  7637. }
  7638. }
  7639. returnErrorMsg("找不到订单记录");
  7640. }
  7641. }
  7642. public void upd_erp_personaftersale()
  7643. {
  7644. if (UrlPostParmsCheck("id"))
  7645. {
  7646. //林小连
  7647. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7648. {
  7649. upd_erp_masteraftersale();
  7650. return;
  7651. }
  7652. string id = GetPostString("id");
  7653. int st = GetPostInt("afterstate");
  7654. string afmemo = GetPostString("supmemo");
  7655. string image = GetPostString("image");
  7656. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7657. if (ceErpTradeResponsible != null)
  7658. {
  7659. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7660. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7661. ceErpTradeResponsible.Update();
  7662. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7663. if (entity != null)
  7664. {
  7665. entity.AfterSaleSupplierMemo = afmemo;
  7666. entity.AfterSaleSupplierState = st;
  7667. if (st == 1)
  7668. {
  7669. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7670. if (isAll)
  7671. {
  7672. entity.AfterSaleState = 4;
  7673. entity.FinishAfterSaleTime = DateTime.Now;
  7674. }
  7675. }
  7676. else
  7677. {
  7678. CeErpTradeResponsible.dateByTid(entity.ctid);
  7679. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7680. if (ceErpTradeAfterSaleExtend != null)
  7681. {
  7682. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7683. ceErpTradeAfterSaleExtend.Update();
  7684. }
  7685. else
  7686. {
  7687. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7688. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7689. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7690. ceErpTradeAfterSaleExtend.Create();
  7691. }
  7692. //退回到主管
  7693. //entity.AfterSaleState = 2;
  7694. }
  7695. if (entity.AfterSaleState == 4)
  7696. {
  7697. ApiVo apiVo = new ApiVo();
  7698. apiVo.orderNumber = entity.ctid;
  7699. apiVo.actionName = "afterOver";
  7700. designHelper.API_WorkCore(apiVo); //afterOver
  7701. }
  7702. entity.UpdateTime = DateTime.Now;
  7703. entity.Update();
  7704. returnSuccessMsg("操作成功!");
  7705. CeErpSukuraData.createInfo(entity.ctid, 8);
  7706. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7707. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7708. return;
  7709. }
  7710. }
  7711. returnErrorMsg("找不到订单记录");
  7712. }
  7713. }
  7714. public void set_erp_supplierrefundtag()
  7715. {
  7716. if (UrlPostParmsCheck("ctid"))
  7717. {
  7718. string eid = GetPostString("ctid");
  7719. CeErpTradeCell entity = null;
  7720. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7721. if (entity != null)
  7722. {
  7723. entity.IsSupplierRefund = GetPostInt("tag");
  7724. entity.Update();
  7725. returnSuccessMsg("操作成功!");
  7726. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7727. return;
  7728. }
  7729. returnErrorMsg("找不到订单记录");
  7730. }
  7731. }
  7732. public void get_erp_refundlist()
  7733. {
  7734. DataStruct dStruct = GetPostStruct();
  7735. List<string> lw = new List<string>();
  7736. string tid = GetPostString("tid");
  7737. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7738. //string rid = GetPostString("refund_id");
  7739. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7740. string shopname = GetPostString("shopname");
  7741. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7742. string buyernick = GetPostString("buyer_nick");
  7743. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7744. string customer = GetPostString("customer");
  7745. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7746. string design = GetPostString("design");
  7747. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7748. string sellermemo = GetPostString("seller_memo");
  7749. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7750. //string date1 = GetPostString("date1");
  7751. //string date2 = GetPostString("date2");
  7752. //string dateType = GetPostString("dateType");
  7753. //if (dateType.Length > 0)
  7754. //{
  7755. // if (dateType == "1001") dateType = "0";
  7756. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7757. // if (searchDT.Count == 2)
  7758. // {
  7759. // date1 = searchDT[0].ToString();
  7760. // date2 = searchDT[1].ToString();
  7761. // }
  7762. //}
  7763. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7764. //if (dw.Length > 0) lw.Add(dw);
  7765. string redate1 = GetPostString("refunddate1");
  7766. string redate2 = GetPostString("refunddate2");
  7767. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7768. if (dwdate.Length > 0) lw.Add(dwdate);
  7769. string price1 = GetPostString("price1");
  7770. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7771. string price2 = GetPostString("price2");
  7772. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7773. string ispartrefund = GetPostString("ispartrefund");
  7774. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7775. string refundState = GetPostString("refundvstate");
  7776. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7777. int st = GetInt("st");
  7778. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7779. {
  7780. string responsible = GetPostString("responsibleman");
  7781. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7782. lw.Add(string.Format("RefundState>={0}", st));
  7783. string code = CurrentUser.UserPost.Post.Code;
  7784. if (code == "CustomerService")
  7785. {
  7786. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7787. }
  7788. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7789. {
  7790. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7791. }
  7792. else if (code == "Place" || code == "PlaceMr")
  7793. {
  7794. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7795. }
  7796. dStruct.Order = "RefundState asc,created desc";
  7797. }
  7798. else if (st == 10)
  7799. {
  7800. string responsible = GetPostString("responsibleman");
  7801. if (responsible == "空白")
  7802. {
  7803. lw.Add(string.Format("ResponsibleUserName = ''"));
  7804. }
  7805. else if (responsible.Length > 0)
  7806. {
  7807. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7808. }
  7809. lw.Add(string.Format("RefundState>=0"));
  7810. dStruct.Order = "created desc";
  7811. }
  7812. else
  7813. {
  7814. string responsible = GetPostString("responsibleman");
  7815. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7816. lw.Add(string.Format("RefundState={0}", st));
  7817. dStruct.Order = "created desc";
  7818. }
  7819. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7820. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7821. dt.Columns.Add("refund_fees");
  7822. foreach (DataRow dr in dt.Rows)
  7823. {
  7824. String status = dr["status"].ToString();
  7825. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7826. {
  7827. dr["refund_fees"] = dr["refund_fee"];
  7828. }
  7829. else
  7830. {
  7831. dr["refund_fees"] = "0.0";
  7832. }
  7833. }
  7834. writeGridDataTableJson(dStruct.TotalCount, dt);
  7835. }
  7836. public void get_erp_refunddesignlist()
  7837. {
  7838. DataStruct dStruct = GetPostStruct();
  7839. List<string> lw = new List<string>();
  7840. string tid = GetPostString("tid");
  7841. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7842. string shopname = GetPostString("shopname");
  7843. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7844. string buyernick = GetPostString("buyer_nick");
  7845. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7846. string customer = GetPostString("customer");
  7847. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7848. string design = GetPostString("design");
  7849. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7850. string sellermemo = GetPostString("seller_memo");
  7851. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7852. string redate1 = GetPostString("refunddate1");
  7853. string redate2 = GetPostString("refunddate2");
  7854. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7855. if (dwdate.Length > 0) lw.Add(dwdate);
  7856. string price1 = GetPostString("price1");
  7857. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7858. string price2 = GetPostString("price2");
  7859. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7860. string ispartrefund = GetPostString("ispartrefund");
  7861. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7862. string designerorg = GetPostString("designerorg");
  7863. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7864. string refundState = GetPostString("refundState");
  7865. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7866. int myOrgid = CurrentUser.UserPost.OrgID;
  7867. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7868. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7869. {
  7870. if (CurrentUser.User.TeamIds.Length > 0)
  7871. {
  7872. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7873. }
  7874. else
  7875. {
  7876. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7877. }
  7878. }
  7879. else if ("SysAdmin".Equals(myOrgCode))
  7880. {
  7881. }
  7882. else
  7883. {
  7884. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7885. {
  7886. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7887. }
  7888. else
  7889. {
  7890. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7891. }
  7892. }
  7893. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7894. dStruct.Order = "created desc";
  7895. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7896. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7897. dt.Columns.Add("refund_fees");
  7898. foreach (DataRow dr in dt.Rows)
  7899. {
  7900. String status = dr["status"].ToString();
  7901. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7902. {
  7903. dr["refund_fees"] = dr["refund_fee"];
  7904. }
  7905. else
  7906. {
  7907. dr["refund_fees"] = "0.0";
  7908. }
  7909. }
  7910. writeGridDataTableJson(dStruct.TotalCount, dt);
  7911. }
  7912. public void handle_erp_refundtag()
  7913. {
  7914. if (UrlPostParmsCheck("refund_id"))
  7915. {
  7916. string eid = GetPostString("refund_id");
  7917. string respMan = GetPostString("ResponsibleName");
  7918. if (respMan.Length <= 0)
  7919. {
  7920. returnErrorMsg("责任人不能为空");
  7921. return;
  7922. }
  7923. CeErpTradeRefund entity = null;
  7924. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7925. if (entity != null)
  7926. {
  7927. entity.ResponsibleUserName = respMan;
  7928. string userid = GetPostString("ResponsibleUserId");
  7929. if (userid.Length > 0)
  7930. {
  7931. entity.ResponsibleUserId = userid;
  7932. }
  7933. entity.Memo = GetPostString("Memo");
  7934. if (respMan.IndexOf("客服") != -1 ||
  7935. respMan.IndexOf("设计师") != -1 ||
  7936. respMan.IndexOf("下单员") != -1)
  7937. {
  7938. entity.RefundState = 2;
  7939. }
  7940. else
  7941. {
  7942. entity.RefundState = 3;
  7943. }
  7944. entity.modified = DateTime.Now;
  7945. entity.Update();
  7946. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7947. returnSuccessMsg("操作成功!");
  7948. return;
  7949. }
  7950. returnErrorMsg("找不到订单记录");
  7951. }
  7952. }
  7953. public void handle_erp_designrefundtag()
  7954. {
  7955. if (UrlPostParmsCheck("refund_id"))
  7956. {
  7957. string eid = GetPostString("refund_id");
  7958. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7959. if (ceErpTradeCellExtend == null)
  7960. {
  7961. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7962. ceErpTradeCellExtend.ctid = eid;
  7963. }
  7964. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7965. if (ceErpTradeCellExtend.ID > 0)
  7966. {
  7967. ceErpTradeCellExtend.Update();
  7968. }
  7969. else
  7970. {
  7971. ceErpTradeCellExtend.Create();
  7972. }
  7973. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7974. returnSuccessMsg("操作成功!");
  7975. return;
  7976. }
  7977. returnErrorMsg("找不到订单记录");
  7978. }
  7979. public void upd_erp_refundverify()
  7980. {
  7981. if (UrlPostParmsCheck("refund_id"))
  7982. {
  7983. string eid = GetPostString("refund_id");
  7984. CeErpTradeRefund entity = null;
  7985. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7986. if (entity != null)
  7987. {
  7988. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  7989. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  7990. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  7991. {
  7992. entity.RefundState = 2;
  7993. }
  7994. else
  7995. {
  7996. entity.RefundState = 3;
  7997. }
  7998. entity.Update();
  7999. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8000. returnSuccessMsg("操作成功!");
  8001. return;
  8002. }
  8003. returnErrorMsg("找不到订单记录");
  8004. }
  8005. }
  8006. public void upd_erp_refundapprove()
  8007. {
  8008. if (UrlPostParmsCheck("refund_id"))
  8009. {
  8010. string eid = GetPostString("refund_id");
  8011. CeErpTradeRefund entity = null;
  8012. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8013. if (entity != null)
  8014. {
  8015. int apr = GetPostInt("approve");
  8016. if (apr == 0)
  8017. {
  8018. entity.RefundState = 1;
  8019. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8020. }
  8021. else if (apr == 1)
  8022. {
  8023. entity.RefundState = 3;
  8024. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8025. }
  8026. entity.modified = DateTime.Now;
  8027. entity.Update();
  8028. returnSuccessMsg("操作成功!");
  8029. return;
  8030. }
  8031. returnErrorMsg("找不到订单记录");
  8032. }
  8033. }
  8034. public void get_erp_billlist()
  8035. {
  8036. DataStruct dStruct = GetPostStruct();
  8037. List<string> lw = new List<string>();
  8038. string title = GetPostString("title");
  8039. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8040. string tid = GetPostString("tid");
  8041. string tids = GetPostString("tids");
  8042. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8043. if (tids.Length > 0)
  8044. {
  8045. tids = "'" + tids + "'";
  8046. tids = tids.Replace(",", "','");
  8047. lw.Add(string.Format("tid in ({0})", tids));
  8048. }
  8049. string shopname = GetPostString("shopname");
  8050. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8051. string buyernick = GetPostString("buyer_nick");
  8052. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8053. string customer = GetPostString("customer");
  8054. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8055. string date1 = GetPostString("date1");
  8056. string date2 = GetPostString("date2");
  8057. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8058. if (dw.Length > 0) lw.Add(dw);
  8059. string price1 = GetPostString("price1");
  8060. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8061. string price2 = GetPostString("price2");
  8062. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8063. string returndate1 = GetPostString("returndate1");
  8064. string returndate2 = GetPostString("returndate2");
  8065. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8066. if (dw1.Length > 0) lw.Add(dw1);
  8067. string billtype = GetPostString("billtype");
  8068. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8069. string billstate = GetPostString("billstate");
  8070. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8071. string usershop = CurrentUser.User.pemShop;
  8072. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8073. dStruct.Order = "createTime desc";
  8074. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8075. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8076. //foreach (DataRow dr in dt.Rows)
  8077. //{
  8078. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8079. //}
  8080. writeGridDataTableJson(dStruct.TotalCount, dt);
  8081. }
  8082. public void modify_erp_billinfo()
  8083. {
  8084. if (UrlPostParmsCheck("ID"))
  8085. {
  8086. string eid = GetPostString("ID");
  8087. CeErpBill bill_entity = null;
  8088. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8089. if (bill_entity != null)
  8090. {
  8091. bill_entity.tid = GetPostString("tid");
  8092. bill_entity.title = GetPostString("title");
  8093. bill_entity.tax = GetPostString("tax");
  8094. bill_entity.bank = GetPostString("bank");
  8095. bill_entity.bankac = GetPostString("bankac");
  8096. bill_entity.address = GetPostString("address");
  8097. bill_entity.phone = GetPostString("phone");
  8098. bill_entity.price = GetPostString("price");
  8099. bill_entity.productId = GetPostInt("ProductName");
  8100. bill_entity.num = GetPostInt("num");
  8101. bill_entity.unit = GetPostString("unit");
  8102. bill_entity.type = GetPostString("type");
  8103. bill_entity.sendType = GetPostString("SendType");
  8104. bill_entity.email = GetPostString("email");
  8105. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8106. bill_entity.shopName = GetPostString("ShopName");
  8107. bill_entity.applymemo = GetPostString("applymemo");
  8108. bill_entity.modifyTime = DateTime.Now;
  8109. bill_entity.createTime = DateTime.Now;
  8110. bill_entity.state = 0;
  8111. bill_entity.Update();
  8112. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8113. returnSuccessMsg("发票修改成功!");
  8114. return;
  8115. }
  8116. returnErrorMsg("找不到对应记录");
  8117. }
  8118. }
  8119. public void set_erp_invoicing()
  8120. {
  8121. if (UrlPostParmsCheck("id"))
  8122. {
  8123. try
  8124. {
  8125. string eid = GetPostString("id");
  8126. CeErpBill bill_entity = null;
  8127. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8128. if (bill_entity != null)
  8129. {
  8130. int ComId = GetPostInt("ComId");
  8131. //string memo = GetPostString("Memo");
  8132. int allInfo = GetPostInt("allinfo");
  8133. string clert = CurrentUser.User.Name;
  8134. //string detailValue = GetPostString("detailvalue");
  8135. string billId = bill_entity.billOrderId;
  8136. string[] billIdList = billId.Split(',');
  8137. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8138. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8139. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8140. {
  8141. billCount += 1;
  8142. }
  8143. if (billId.Length <= 0 || billIdList.Length != billCount)
  8144. {
  8145. bill_entity.billOrderId = "";
  8146. string prebill = "ltb";
  8147. for (int idx = 1; idx <= billCount; idx++)
  8148. {
  8149. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8150. string billoid = prebill + idx + dtstr;
  8151. bill_entity.billOrderId += billoid;
  8152. if (idx < billCount)
  8153. {
  8154. bill_entity.billOrderId += ",";
  8155. }
  8156. }
  8157. }
  8158. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8159. if (bill_entity.state == 5)
  8160. {
  8161. string errMsg = bill_entity.failerror;
  8162. string[] errlist = errMsg.Split('|');
  8163. string[] errTags = new string[errlist.Length];
  8164. for (int itag = 0; itag < errlist.Length; itag++)
  8165. {
  8166. if (errlist[itag].Length <= 0) continue;
  8167. errTags[itag] = errlist[itag].Split('&')[0];
  8168. }
  8169. for (int iii = 0; iii < errTags.Length; iii++)
  8170. {
  8171. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8172. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8173. if (billOrderList.Length >= erroBillOrderTag)
  8174. {
  8175. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8176. if (needModifyBillId.Length <= 19)
  8177. {
  8178. needModifyBillId = needModifyBillId + "1";
  8179. }
  8180. else
  8181. {
  8182. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8183. last = last + 1;
  8184. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8185. }
  8186. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8187. }
  8188. }
  8189. }
  8190. bool isHaveBillSucces = false;
  8191. string totalRes = "";
  8192. bill_entity.failerror = "";
  8193. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8194. {
  8195. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8196. totalRes += res;
  8197. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8198. {
  8199. isHaveBillSucces = true;
  8200. bill_entity.comId = ComId;
  8201. bill_entity.state = 1;
  8202. bill_entity.executeTime = DateTime.Now;
  8203. bill_entity.executeUser = clert;
  8204. }
  8205. else
  8206. {
  8207. bill_entity.state = 5;
  8208. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8209. }
  8210. }
  8211. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8212. bill_entity.Update();
  8213. if (isHaveBillSucces)
  8214. {
  8215. StringBuilder sql = new StringBuilder();
  8216. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8217. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8218. }
  8219. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8220. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8221. {
  8222. returnErrorMsg("开票失败");
  8223. }
  8224. else
  8225. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8226. return;
  8227. }
  8228. returnErrorMsg("找不到对应记录");
  8229. }
  8230. catch (Exception ex)
  8231. {
  8232. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8233. returnErrorMsg("操作失败");
  8234. }
  8235. }
  8236. }
  8237. public void get_erp_invoicing_back()
  8238. {
  8239. if (UrlPostParmsCheck("id"))
  8240. {
  8241. try
  8242. {
  8243. string id = GetPostString("id");
  8244. CeErpBill entiy = CeErpBill.Get(id);
  8245. if (entiy != null)
  8246. {
  8247. if (entiy.state == 0)
  8248. {
  8249. returnErrorMsg("发票还未开具");
  8250. return;
  8251. }
  8252. string[] billOrderList = entiy.billOrderId.Split(',');
  8253. int iTag = 0;
  8254. entiy.fplsh = "";
  8255. entiy.fpdm = "";
  8256. entiy.fphm = "";
  8257. foreach (string billOrderId in billOrderList)
  8258. {
  8259. iTag++;
  8260. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8261. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8262. {
  8263. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8264. try
  8265. {
  8266. Invoicing_get_response_Obj iObj = null;
  8267. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8268. if (iObj != null)
  8269. {
  8270. entiy.state = 2;
  8271. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8272. entiy.fpdm += iObj.list[0].c_fpdm;
  8273. entiy.fphm += iObj.list[0].c_fphm;
  8274. if (iTag < billOrderList.Length)
  8275. {
  8276. entiy.fplsh += ",";
  8277. entiy.fpdm += ",";
  8278. entiy.fphm += ",";
  8279. }
  8280. entiy.Update();
  8281. }
  8282. StringBuilder sql = new StringBuilder();
  8283. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8284. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8285. returnSuccessMsg("开票成功");
  8286. }
  8287. catch (Exception ex)
  8288. {
  8289. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8290. }
  8291. return;
  8292. }
  8293. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8294. {
  8295. var res_obj = new
  8296. {
  8297. data = "开票中"
  8298. };
  8299. string ro_json = JsonConvert.SerializeObject(res_obj);
  8300. returnSuccess(ro_json);
  8301. return;
  8302. }
  8303. else
  8304. {
  8305. int eidx = res.IndexOf("c_resultmsg");
  8306. int lidx = res.IndexOf("c_status");
  8307. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8308. entiy.state = 5;
  8309. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8310. entiy.Update();
  8311. returnErrorMsg("开票失败");
  8312. return;
  8313. }
  8314. }
  8315. }
  8316. }
  8317. catch (Exception ex)
  8318. {
  8319. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8320. }
  8321. return;
  8322. }
  8323. }
  8324. public void get_erp_invoicing()
  8325. {
  8326. if (UrlPostParmsCheck("id"))
  8327. {
  8328. try
  8329. {
  8330. string id = GetPostString("id");
  8331. CeErpBill entiy = CeErpBill.Get(id);
  8332. if (entiy != null)
  8333. {
  8334. if (entiy.state == 0)
  8335. {
  8336. returnErrorMsg("发票还未开具");
  8337. return;
  8338. }
  8339. if (entiy.sendType == "纸质发票")
  8340. {
  8341. if (entiy.img.Length <= 0)
  8342. {
  8343. returnErrorMsg("查无纸质发票");
  8344. return;
  8345. }
  8346. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8347. returnSuccess(returnres);
  8348. return;
  8349. }
  8350. string[] billOrderList = entiy.billOrderId.Split(',');
  8351. int iTag = 0;
  8352. string fpUrl = "";
  8353. entiy.fplsh = "";
  8354. entiy.fpdm = "";
  8355. entiy.fphm = "";
  8356. foreach (string billOrderId in billOrderList)
  8357. {
  8358. iTag++;
  8359. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8360. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8361. {
  8362. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8363. Invoicing_get_response_Obj iObj = null;
  8364. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8365. if (iObj != null)
  8366. {
  8367. //entiy.state = 2;
  8368. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8369. entiy.fpdm += iObj.list[0].c_fpdm;
  8370. entiy.fphm += iObj.list[0].c_fphm;
  8371. if (iTag < billOrderList.Length)
  8372. {
  8373. entiy.fplsh += ",";
  8374. entiy.fpdm += ",";
  8375. entiy.fphm += ",";
  8376. }
  8377. entiy.Update();
  8378. fpUrl += iObj.list[0].c_url + ",";
  8379. }
  8380. //returnSuccess(res);
  8381. StringBuilder sql = new StringBuilder();
  8382. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8383. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8384. }
  8385. else
  8386. {
  8387. int eidx = res.IndexOf("c_resultmsg");
  8388. //int lidx = res.IndexOf("c_status");
  8389. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8390. //开票失败
  8391. entiy.state = 5;
  8392. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8393. entiy.Update();
  8394. returnErrorMsg("开票失败");
  8395. return;
  8396. }
  8397. }
  8398. var returnObj = new
  8399. {
  8400. data = fpUrl
  8401. };
  8402. string ro_json = JsonConvert.SerializeObject(returnObj);
  8403. returnSuccess(ro_json);
  8404. }
  8405. }
  8406. catch (Exception ex)
  8407. {
  8408. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8409. }
  8410. return;
  8411. }
  8412. }
  8413. public void save_erp_billimg()
  8414. {
  8415. if (UrlPostParmsCheck("id"))
  8416. {
  8417. string eid = GetPostString("id");
  8418. CeErpBill bill_entity = null;
  8419. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8420. if (bill_entity != null)
  8421. {
  8422. bill_entity.img = GetPostString("img");
  8423. bill_entity.executeTime = DateTime.Now;
  8424. bill_entity.state = 2;
  8425. bill_entity.Update();
  8426. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8427. returnSuccessMsg("保存成功");
  8428. }
  8429. return;
  8430. }
  8431. }
  8432. public void upd_erp_billreturnback()
  8433. {
  8434. if (UrlPostParmsCheck("id"))
  8435. {
  8436. int eid = GetPostInt("id");
  8437. CeErpBill bill_entity = null;
  8438. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8439. if (bill_entity != null)
  8440. {
  8441. bill_entity.state = 3;
  8442. bill_entity.returnReason = GetPostString("reason");
  8443. bill_entity.Update();
  8444. returnSuccessMsg("驳回成功!");
  8445. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8446. }
  8447. return;
  8448. }
  8449. }
  8450. public void cancel_erp_bill()
  8451. {
  8452. if (UrlPostParmsCheck("id"))
  8453. {
  8454. int eid = GetPostInt("id");
  8455. int detailValue = GetPostInt("detailvalue");
  8456. CeErpBill bill_entity = null;
  8457. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8458. string cres = "";
  8459. string gres = "";
  8460. if (bill_entity != null)
  8461. {
  8462. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8463. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8464. {
  8465. int iTag = 0;
  8466. bill_entity.fplsh = "";
  8467. bill_entity.fpdm = "";
  8468. bill_entity.fphm = "";
  8469. foreach (string billOrderId in billOrderList)
  8470. {
  8471. iTag++;
  8472. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8473. if (gres.IndexOf("success") != -1)
  8474. {
  8475. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8476. Invoicing_get_response_Obj iObj = null;
  8477. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8478. if (iObj != null)
  8479. {
  8480. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8481. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8482. bill_entity.fphm += iObj.list[0].c_fphm;
  8483. if (iTag < billOrderList.Length)
  8484. {
  8485. bill_entity.fplsh += ",";
  8486. bill_entity.fpdm += ",";
  8487. bill_entity.fphm += ",";
  8488. }
  8489. bill_entity.Update();
  8490. }
  8491. }
  8492. else
  8493. {
  8494. returnErrorMsg(gres);
  8495. return;
  8496. }
  8497. }
  8498. }
  8499. if (bill_entity.sendType == "纸质发票")
  8500. {
  8501. //作废
  8502. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8503. //if (DateTime.Now.Month == extime.Month)
  8504. //{
  8505. //cres = taobaoHelper.cancel_invoicing(eid);
  8506. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8507. //{
  8508. bill_entity.state = 4;//已作废
  8509. bill_entity.Update();
  8510. returnSuccessMsg("发票已作废");
  8511. return;
  8512. //}
  8513. //else
  8514. //{
  8515. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8516. // bill_entity.Update();
  8517. // returnErrorMsg(cres);
  8518. // return;
  8519. //}
  8520. //}
  8521. //else
  8522. //{
  8523. // returnErrorMsg("纸质发票只能作废本月的发票");
  8524. // return;
  8525. //}
  8526. }
  8527. //红冲
  8528. int redTag = 0;
  8529. string[] fpdmList = bill_entity.fpdm.Split(',');
  8530. string[] fphmList = bill_entity.fphm.Split(',');
  8531. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8532. {
  8533. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8534. return;
  8535. }
  8536. foreach (string billOrderId in billOrderList)
  8537. {
  8538. redTag++;
  8539. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8540. cres += onecres;
  8541. cres += ",";
  8542. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8543. {
  8544. bill_entity.state = 4;//已作废
  8545. //bill_entity.Update();
  8546. //returnSuccessMsg("发票已红冲");
  8547. }
  8548. else if (onecres.IndexOf("重复冲红") != -1)
  8549. {
  8550. bill_entity.state = 4;//已作废
  8551. //bill_entity.Update();
  8552. //returnSuccessMsg("发票已红冲");
  8553. }
  8554. else
  8555. {
  8556. string errmsg = commonHelper.KeepChinese(onecres);
  8557. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8558. }
  8559. }
  8560. bill_entity.Update();
  8561. if (cres.IndexOf("失败") != -1)
  8562. returnErrorMsg("红冲失败");
  8563. else
  8564. returnSuccessMsg("发票已红冲");
  8565. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8566. return;
  8567. }
  8568. return;
  8569. }
  8570. }
  8571. public void del_erp_billorder()
  8572. {
  8573. if (UrlPostParmsCheck("id"))
  8574. {
  8575. string eid = GetPostString("id");
  8576. CeErpBill.Del(eid);
  8577. CeErpBill bill = CeErpBill.Get(eid);
  8578. if (bill != null)
  8579. {
  8580. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8581. }
  8582. returnSuccessMsg("删除成功");
  8583. }
  8584. }
  8585. public void finish_erp_bill()
  8586. {
  8587. if (UrlPostParmsCheck("ids"))
  8588. {
  8589. string eids = GetPostString("ids");
  8590. string[] list = eids.Split(',');
  8591. foreach (string eid in list)
  8592. {
  8593. CeErpBill bill = CeErpBill.Get(eid);
  8594. if (bill != null)
  8595. {
  8596. bill.state = 2;
  8597. bill.Update();
  8598. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8599. }
  8600. }
  8601. returnSuccessMsg("操作成功");
  8602. }
  8603. }
  8604. public void get_erp_returncash()
  8605. {
  8606. DataStruct dStruct = GetPostStruct();
  8607. List<string> lw = new List<string>();
  8608. string tid = GetPostString("tid");
  8609. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8610. string shopname = GetPostString("shopname");
  8611. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8612. string buyernick = GetPostString("buyer_nick");
  8613. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8614. string customer = GetPostString("customer");
  8615. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8616. string returndate1 = GetPostString("returndate1");
  8617. string returndate2 = GetPostString("returndate2");
  8618. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8619. if (dw.Length > 0) lw.Add(dw);
  8620. string finishDate1 = GetPostString("finishdate1");
  8621. string finishDate2 = GetPostString("finishdate2");
  8622. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8623. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8624. string returntype = GetPostString("returntype");
  8625. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8626. string returnvstate = GetPostString("returnvstate");
  8627. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8628. dStruct.Order = "created desc";
  8629. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8630. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8631. writeGridDataTableJson(dStruct.TotalCount, dt);
  8632. }
  8633. public void get_erp_staygoods()
  8634. {
  8635. DataStruct dStruct = GetPostStruct();
  8636. List<string> lw = new List<string>();
  8637. string tid = GetPostString("tid");
  8638. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8639. string shopname = GetPostString("shopname");
  8640. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8641. string wangwang = GetPostString("wangwang");
  8642. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8643. string customer = GetPostString("customer");
  8644. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8645. string returndate1 = GetPostString("returndate1");
  8646. string returndate2 = GetPostString("returndate2");
  8647. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8648. if (dw.Length > 0) lw.Add(dw);
  8649. string finishDate1 = GetPostString("finishdate1");
  8650. string finishDate2 = GetPostString("finishdate2");
  8651. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8652. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8653. string returnvstate = GetPostString("returnvstate");
  8654. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8655. string persuadetype = GetPostString("persuadetype");
  8656. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8657. string customerOrg = GetPostString("customerOrg");
  8658. if (customerOrg.Length > 0)
  8659. {
  8660. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8661. }
  8662. dStruct.Order = "creata_time desc";
  8663. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8664. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8665. writeGridDataTableJson(dStruct.TotalCount, dt);
  8666. }
  8667. public void upd_erp_staygoods()
  8668. {
  8669. if (UrlPostParmsCheck("id"))
  8670. {
  8671. int eid = GetPostInt("id");
  8672. CeErpStayGoods entity = null;
  8673. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8674. if (entity != null)
  8675. {
  8676. entity.audit_type = 1;
  8677. entity.audit_time = DateTime.Now;
  8678. entity.audit_u_id = CurrentUser.UserID;
  8679. entity.audit_u_name = CurrentUser.UserName;
  8680. entity.Update();
  8681. returnSuccessMsg("审核成功!");
  8682. return;
  8683. }
  8684. returnErrorMsg("找不到订单记录");
  8685. }
  8686. }
  8687. public void upd_erp_stayGoodsback()
  8688. {
  8689. if (UrlPostParmsCheck("id"))
  8690. {
  8691. int eid = GetPostInt("id");
  8692. CeErpStayGoods entity = null;
  8693. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8694. if (entity != null)
  8695. {
  8696. entity.audit_text = GetPostString("reason");
  8697. entity.audit_type = 2;
  8698. entity.audit_time = DateTime.Now;
  8699. entity.audit_u_id = CurrentUser.UserID;
  8700. entity.audit_u_name = CurrentUser.UserName;
  8701. entity.Update();
  8702. returnSuccessMsg("退回成功!");
  8703. return;
  8704. }
  8705. returnErrorMsg("找不到订单记录");
  8706. }
  8707. }
  8708. public void upd_erp_returncashverify()
  8709. {
  8710. if (UrlPostParmsCheck("ID"))
  8711. {
  8712. int eid = GetPostInt("ID");
  8713. CeErpReturnCash entity = null;
  8714. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8715. if (entity != null)
  8716. {
  8717. entity.cashstate = 1;
  8718. entity.verifytime = DateTime.Now;
  8719. entity.verifyuserid = CurrentUser.UserID;
  8720. entity.Update();
  8721. returnSuccessMsg("审核成功!");
  8722. return;
  8723. }
  8724. returnErrorMsg("找不到订单记录");
  8725. }
  8726. }
  8727. public void upd_all_erp_returncashverify()
  8728. {
  8729. if (UrlPostParmsCheck("ID"))
  8730. {
  8731. String[] list = GetPostString("ID").Split(',');
  8732. CeErpReturnCash entity = null;
  8733. for (int i = 0; i < list.Length; i++)
  8734. {
  8735. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8736. if (entity != null)
  8737. {
  8738. if (entity.cashstate == 1)
  8739. {
  8740. returnErrorMsg("已审核过的订单不需要在审核!");
  8741. return;
  8742. }
  8743. entity.cashstate = 1;
  8744. entity.verifytime = DateTime.Now;
  8745. entity.verifyuserid = CurrentUser.UserID;
  8746. entity.Update();
  8747. }
  8748. }
  8749. returnSuccessMsg("审核成功!");
  8750. return;
  8751. }
  8752. }
  8753. public void upd_erp_returncashback()
  8754. {
  8755. if (UrlPostParmsCheck("ID"))
  8756. {
  8757. int eid = GetPostInt("ID");
  8758. CeErpReturnCash entity = null;
  8759. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8760. if (entity != null)
  8761. {
  8762. entity.backreason = GetPostString("reason");
  8763. entity.cashstate = 2;
  8764. entity.verifytime = DateTime.Now;
  8765. entity.verifyuserid = CurrentUser.UserID;
  8766. entity.Update();
  8767. returnSuccessMsg("退回成功!");
  8768. return;
  8769. }
  8770. returnErrorMsg("找不到订单记录");
  8771. }
  8772. }
  8773. public void upd_erp_returnprice()
  8774. {
  8775. if (UrlPostParmsCheck("ID"))
  8776. {
  8777. int eid = GetPostInt("ID");
  8778. CeErpReturnCash entity = null;
  8779. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8780. if (entity != null)
  8781. {
  8782. if (entity.cashstate == 1)
  8783. {
  8784. returnErrorMsg("审核通过了不能改");
  8785. return;
  8786. }
  8787. entity.returnprice = GetPostDouble("returnprice");
  8788. entity.Update();
  8789. returnSuccessMsg("修改成功!");
  8790. return;
  8791. }
  8792. returnErrorMsg("找不到订单记录");
  8793. }
  8794. }
  8795. public void del_erp_returncash()
  8796. {
  8797. if (UrlPostParmsCheck("ID"))
  8798. {
  8799. int eid = GetPostInt("ID");
  8800. CeErpReturnCash.Del(eid);
  8801. returnSuccessMsg("操作成功");
  8802. return;
  8803. }
  8804. }
  8805. public void test_for_do_sql()
  8806. {
  8807. string sql = GetPostString("sqlstr");
  8808. if (sql.Length > 0)
  8809. {
  8810. try
  8811. {
  8812. DbHelper.DbConn.ExecuteNonQuery(sql);
  8813. var res_obj = new
  8814. {
  8815. data = "成功",
  8816. };
  8817. string ro_json = JsonConvert.SerializeObject(res_obj);
  8818. returnSuccess(ro_json);
  8819. }
  8820. catch (Exception ex)
  8821. {
  8822. var res_obj = new
  8823. {
  8824. data = ex.Message,
  8825. };
  8826. string ro_json = JsonConvert.SerializeObject(res_obj);
  8827. returnSuccess(ro_json);
  8828. }
  8829. }
  8830. }
  8831. public void get_user_info()
  8832. {
  8833. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8834. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8835. }
  8836. public void get_total_data()
  8837. {
  8838. int userId = CurrentUser.UserID;
  8839. string sql = "";
  8840. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8841. {
  8842. 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);
  8843. }
  8844. else
  8845. {
  8846. 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 " +
  8847. "(select ID from CE_ErpUser where ID = {0}) d " +
  8848. "left join " +
  8849. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8850. ") a on d.ID = a.id left join " +
  8851. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8852. ") b on a.id = b.id1 left join" +
  8853. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8854. ") c on a.id = c.id2;", userId);
  8855. }
  8856. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8857. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8858. }
  8859. public void get_date_area_total_data2()
  8860. {
  8861. int userId = CurrentUser.UserID;
  8862. string date_type = GetPostString("timetype");
  8863. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8864. string sql = "";
  8865. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8866. {
  8867. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8868. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8869. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8870. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8871. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8872. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8873. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8874. ") a on e.ID = a.id left join " +
  8875. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8876. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8877. ") b on a.id = b.id1 " +
  8878. "left join " +
  8879. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8880. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8881. ") c on a.id = c.id2 " +
  8882. "left join " +
  8883. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8884. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8885. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8886. }
  8887. else
  8888. {
  8889. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8890. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8891. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8892. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8893. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8894. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8895. ") a on e.ID = a.id left join " +
  8896. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8897. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8898. ") c on a.id = c.id2 " +
  8899. "left join " +
  8900. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8901. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8902. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8903. }
  8904. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8905. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8906. }
  8907. public void get_date_area_total_data()
  8908. {
  8909. int userId = CurrentUser.UserID;
  8910. string date_type = GetPostString("timetype");
  8911. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8912. string date1 = searchDT[0].ToString();
  8913. string date2 = searchDT[1].ToString();
  8914. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8915. {
  8916. SqlParameter[] sqlParameter ={
  8917. new SqlParameter("@userId", SqlDbType.Int,4),
  8918. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8919. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8920. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8921. };
  8922. sqlParameter[0].Value = userId;
  8923. sqlParameter[1].Value = date1;
  8924. sqlParameter[2].Value = date2;
  8925. sqlParameter[3].Direction = ParameterDirection.Output;
  8926. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8927. string res = sqlParameter[3].Value.ToString();
  8928. var res_obj = new
  8929. {
  8930. data = res
  8931. };
  8932. string ro_json = JsonConvert.SerializeObject(res_obj);
  8933. returnSuccess(ro_json);
  8934. }
  8935. else
  8936. {
  8937. SqlParameter[] sqlParameter ={
  8938. new SqlParameter("@userId", SqlDbType.Int,4),
  8939. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8940. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8941. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8942. };
  8943. sqlParameter[0].Value = userId;
  8944. sqlParameter[1].Value = date1;
  8945. sqlParameter[2].Value = date2;
  8946. sqlParameter[3].Direction = ParameterDirection.Output;
  8947. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8948. string res = sqlParameter[3].Value.ToString();
  8949. var res_obj = new
  8950. {
  8951. data = res
  8952. };
  8953. string ro_json = JsonConvert.SerializeObject(res_obj);
  8954. returnSuccess(ro_json);
  8955. }
  8956. //writeGridDataViewJson(dt.Rows.Count, dv);
  8957. }
  8958. public void get_order_list()
  8959. {
  8960. string strFields = GetPostString("paraFields");
  8961. string strOrder = GetPostString("paraOrder");
  8962. string strWhere = GetPostString("paraWhere");
  8963. string strPageSize = GetPostString("paraPageSize");
  8964. DataStruct dStruct = GetPostStruct();
  8965. dStruct.PageSize = int.Parse(strPageSize);
  8966. dStruct.Fileds = strFields;
  8967. dStruct.Order = strOrder;
  8968. dStruct.MainWhere = strWhere;
  8969. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8970. writeGridDataTableJson(dStruct.TotalCount, dt);
  8971. }
  8972. ////获取待开始订单列表
  8973. //public void get_wait_design_order_list()
  8974. //{
  8975. // string date_type = GetPostString("date_type");
  8976. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8977. // DataStruct dStruct = GetPostStruct();
  8978. // dStruct.PageSize = 1000;
  8979. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8980. // List<string> lw = new List<string>();
  8981. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8982. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  8983. // dStruct.Order = "WaitDesignTime asc";
  8984. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8985. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8986. // writeGridDataTableJson(dStruct.TotalCount, dt);
  8987. //}
  8988. //获取完成单量排名
  8989. public void get_finish_order_count_ranking()
  8990. {
  8991. /* string date_type = GetPostString("date_type");
  8992. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8993. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8994. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8995. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  8996. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8997. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8998. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8999. writeGridDataTableJson(0, new DataTable());
  9000. }
  9001. public void get_finish_order_amount_ranking()
  9002. {
  9003. /*string date_type = GetPostString("date_type");
  9004. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9005. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9006. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9007. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9008. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9009. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9010. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9011. writeGridDataTableJson(0, new DataTable());
  9012. }
  9013. public void get_finish_refund_count_ranking()
  9014. {
  9015. string date_type = GetPostString("date_type");
  9016. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9017. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9018. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9019. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9020. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9021. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9022. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9023. writeGridDataTableJson(dt.Rows.Count, dt);
  9024. }
  9025. public void get_finish_refund_amount_ranking()
  9026. {
  9027. string date_type = GetPostString("date_type");
  9028. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9029. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9030. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9031. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9032. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9033. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9034. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9035. writeGridDataTableJson(dt.Rows.Count, dt);
  9036. }
  9037. public void set_erp_finishorder_director()
  9038. {
  9039. if (UrlPostParmsCheck("ctid"))
  9040. {
  9041. string eid = GetPostString("ctid");
  9042. CeErpTradeCell entity = null;
  9043. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9044. if (entity != null)
  9045. {
  9046. entity.OrderState = 8;
  9047. entity.Update();
  9048. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9049. returnSuccessMsg("操作成功!");
  9050. return;
  9051. }
  9052. returnErrorMsg("找不到记录");
  9053. }
  9054. }
  9055. public void get_erp_placeregistlist()
  9056. {
  9057. DataStruct dStruct = GetPostStruct();
  9058. List<string> lw = new List<string>();
  9059. string outsid = GetPostString("outsid");
  9060. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9061. string memo = GetPostString("memo");
  9062. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9063. string filename = GetPostString("filename");
  9064. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9065. string islate = GetPostString("islate");
  9066. if (islate.Length > 0)
  9067. {
  9068. if (islate == "1")
  9069. lw.Add(string.Format("OutLate>0"));
  9070. else
  9071. lw.Add(string.Format("OutLate=0"));
  9072. }
  9073. string placedate1 = GetPostString("placedate1");
  9074. string placedate2 = GetPostString("placedate2");
  9075. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9076. if (dw.Length > 0) lw.Add(dw);
  9077. string deliveryDate1 = GetPostString("deliverydate1");
  9078. string deliveryDate2 = GetPostString("deliverydate2");
  9079. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9080. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9081. dStruct.Order = "ID desc";
  9082. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9083. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9084. writeGridDataTableJson(dStruct.TotalCount, dt);
  9085. }
  9086. public void ins_erp_placeregist()
  9087. {
  9088. if (UrlPostParmsCheck("id"))
  9089. {
  9090. string eid = GetPostString("id");
  9091. CeErpPlaceRegister entity = null;
  9092. if (eid == "0")//新增
  9093. {
  9094. entity = new CeErpPlaceRegister();
  9095. string xdTime = GetPostString("placeTime");
  9096. if (xdTime.Length > 0)
  9097. {
  9098. entity.PlactTime = Convert.ToDateTime(xdTime);
  9099. }
  9100. string fhTime = GetPostString("deliveryTime");
  9101. if (fhTime.Length > 0)
  9102. {
  9103. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9104. }
  9105. string preTime = GetPostString("preOutTime");
  9106. if (preTime.Length > 0)
  9107. {
  9108. entity.PreOutTime = Convert.ToDateTime(preTime);
  9109. }
  9110. entity.DeliveryCount = GetPostInt("deliveryCount");
  9111. entity.ReceiveCount = GetPostInt("receiveCount");
  9112. entity.OutSid = GetPostString("outSid");
  9113. entity.FileName = GetPostString("fileName");
  9114. entity.Memo = GetPostString("memo");
  9115. entity.AddUserId = CurrentUser.UserID;
  9116. entity.CreateTime = DateTime.Now;
  9117. entity.Img = GetPostString("img");
  9118. entity.Supplier = GetPostInt("supplier");
  9119. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9120. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9121. {
  9122. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9123. DateTime dt2 = (DateTime)entity.PreOutTime;
  9124. TimeSpan span = dt1.Subtract(dt2);
  9125. if (span.Days > 0)
  9126. {
  9127. entity.OutLate = span.Days;
  9128. }
  9129. }
  9130. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9131. entity.Create();
  9132. returnSuccessMsg("添加成功!");
  9133. return;
  9134. }
  9135. else //修改
  9136. {
  9137. entity = CeErpPlaceRegister.Get(eid);
  9138. if (entity != null)
  9139. {
  9140. string xdTime = GetPostString("placeTime");
  9141. if (xdTime.Length > 0)
  9142. {
  9143. entity.PlactTime = Convert.ToDateTime(xdTime);
  9144. }
  9145. string fhTime = GetPostString("deliveryTime");
  9146. if (fhTime.Length > 0)
  9147. {
  9148. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9149. }
  9150. string preTime = GetPostString("preOutTime");
  9151. if (preTime.Length > 0)
  9152. {
  9153. entity.PreOutTime = Convert.ToDateTime(preTime);
  9154. }
  9155. entity.DeliveryCount = GetPostInt("deliveryCount");
  9156. entity.ReceiveCount = GetPostInt("receiveCount");
  9157. if (entity.DeliveryCount == entity.ReceiveCount)
  9158. {
  9159. entity.CurState = "已完成";
  9160. }
  9161. else
  9162. {
  9163. entity.CurState = "未完成";
  9164. }
  9165. entity.OutSid = GetPostString("outSid");
  9166. entity.FileName = GetPostString("fileName");
  9167. entity.Memo = GetPostString("memo");
  9168. entity.Img = GetPostString("img");
  9169. entity.Supplier = GetPostInt("supplier");
  9170. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9171. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9172. {
  9173. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9174. DateTime dt2 = (DateTime)entity.PreOutTime;
  9175. TimeSpan span = dt1.Subtract(dt2);
  9176. if (span.Days > 0)
  9177. {
  9178. entity.OutLate = span.Days;
  9179. }
  9180. }
  9181. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9182. entity.Update();
  9183. returnSuccessMsg("修改成功");
  9184. return;
  9185. }
  9186. returnErrorMsg("找不到对应的记录");
  9187. return;
  9188. }
  9189. }
  9190. returnErrorMsg("缺少必要参数");
  9191. }
  9192. public void del_erp_placeregist()
  9193. {
  9194. string eid = GetPostString("id");
  9195. CeErpPlaceRegister.Del(eid);
  9196. returnSuccessMsg("删除成功!");
  9197. return;
  9198. }
  9199. public void ins_erp_placeregistbyorder()
  9200. {
  9201. string ctid = GetPostString("ctid");
  9202. if (ctid.Length > 0)
  9203. {
  9204. StringBuilder sql = new StringBuilder();
  9205. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9206. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9207. if (dt.Rows.Count > 0)
  9208. {
  9209. foreach (DataRow dr in dt.Rows)
  9210. {
  9211. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9212. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9213. entity.AddUserId = CurrentUser.UserID;
  9214. entity.tid = dr["tid"].ToString();
  9215. entity.Did = Convert.ToString(dr["ctid"]);
  9216. entity.splitTag = dr["SplitTag"].ToString();
  9217. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9218. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9219. if (pre_ctid.Length > 0)
  9220. {
  9221. sellmemo = sellmemo.Replace(pre_ctid, "");
  9222. }
  9223. sellmemo = sellmemo.Replace("[", "");
  9224. sellmemo = sellmemo.Replace("]", "");
  9225. entity.FileName = sellmemo;
  9226. string count = dr["ProductCount"].ToString();
  9227. int usecount = commonHelper.getIntCountFromString(count);
  9228. entity.DeliveryCount = usecount;
  9229. entity.CurState = "未完成";
  9230. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9231. {
  9232. entity.Supplier = 24;//dl手提袋定制
  9233. }
  9234. else
  9235. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9236. entity.CreateTime = DateTime.Now;
  9237. entity.Create();
  9238. }
  9239. returnSuccessMsg("操作成功");
  9240. return;
  9241. }
  9242. returnErrorMsg("没有找到对应订单");
  9243. return;
  9244. }
  9245. returnErrorMsg("缺少订单编号");
  9246. return;
  9247. }
  9248. public void get_erp_persuadelist()
  9249. {
  9250. DataStruct dStruct = GetPostStruct();
  9251. List<string> lw = new List<string>();
  9252. string ctid = GetPostString("ctid");
  9253. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9254. string shopname = GetPostString("shopname");
  9255. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9256. string buyernick = GetPostString("buyer_nick");
  9257. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9258. string customer = GetPostString("customer");
  9259. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9260. string returndate1 = GetPostString("returndate1");
  9261. string returndate2 = GetPostString("returndate2");
  9262. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9263. if (dw.Length > 0) lw.Add(dw);
  9264. string finishDate1 = GetPostString("finishdate1");
  9265. string finishDate2 = GetPostString("finishdate2");
  9266. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9267. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9268. string persuadetype = GetPostString("persuadetype");
  9269. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9270. string returnvstate = GetPostString("returnvstate");
  9271. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9272. dStruct.Order = "created desc";
  9273. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9274. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9275. writeGridDataTableJson(dStruct.TotalCount, dt);
  9276. }
  9277. public void upd_erp_returnpersuadeback()
  9278. {
  9279. if (UrlPostParmsCheck("ID"))
  9280. {
  9281. int eid = GetPostInt("ID");
  9282. CeErpPersuade entity = null;
  9283. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9284. if (entity != null)
  9285. {
  9286. entity.backreason = GetPostString("reason");
  9287. entity.pstate = 2;
  9288. entity.verifytime = DateTime.Now;
  9289. entity.verifyuserid = CurrentUser.UserID;
  9290. entity.Update();
  9291. returnSuccessMsg("退回成功!");
  9292. return;
  9293. }
  9294. returnErrorMsg("找不到订单记录");
  9295. }
  9296. }
  9297. public void upd_erp_returnpersuadeverify()
  9298. {
  9299. if (UrlPostParmsCheck("ID"))
  9300. {
  9301. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9302. {
  9303. returnErrorMsg("暂无权限审核");
  9304. return;
  9305. }
  9306. int eid = GetPostInt("ID");
  9307. CeErpPersuade entity = null;
  9308. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9309. if (entity != null)
  9310. {
  9311. entity.pstate = 1;
  9312. entity.verifytime = DateTime.Now;
  9313. entity.verifyuserid = CurrentUser.UserID;
  9314. entity.Update();
  9315. returnSuccessMsg("审核成功!");
  9316. return;
  9317. }
  9318. returnErrorMsg("找不到订单记录");
  9319. }
  9320. }
  9321. public void del_erp_persuade()
  9322. {
  9323. if (UrlPostParmsCheck("ID"))
  9324. {
  9325. int eid = GetPostInt("ID");
  9326. CeErpPersuade.Del(eid);
  9327. returnSuccessMsg("操作成功");
  9328. return;
  9329. }
  9330. }
  9331. public void get_erp_oldcustoupload()
  9332. {
  9333. DataStruct dStruct = GetPostStruct();
  9334. List<string> lw = new List<string>();
  9335. string buyernick = GetPostString("buyer_nick");
  9336. if (buyernick.Length > 0)
  9337. {
  9338. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9339. }
  9340. else
  9341. return;
  9342. dStruct.Order = "pay_time desc";
  9343. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9344. DataTable dt = null;
  9345. dt = WebCache.GetData("view_erptradecell", dStruct);
  9346. writeGridDataTableJson(dStruct.TotalCount, dt);
  9347. }
  9348. public void get_erp_checkorderlist()
  9349. {
  9350. DataStruct dStruct = GetPostStruct();
  9351. List<string> lw = new List<string>();
  9352. string tid = GetPostString("ctid");
  9353. if (tid.Length > 0)
  9354. {
  9355. string select_tid = getTidByCtid(tid);
  9356. lw.Add(string.Format("tid='{0}'", select_tid));
  9357. }
  9358. string shopname = GetPostString("shopname");
  9359. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9360. string buyernick = GetPostString("buyer_nick");
  9361. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9362. string customer = GetPostString("customer");
  9363. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9364. string design = GetPostString("design");
  9365. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9366. string orderState = GetPostString("orderState");
  9367. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9368. string address = GetPostString("address");
  9369. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9370. string sellermemo = GetPostString("seller_memo");
  9371. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9372. string supplier = GetPostString("supplier");
  9373. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9374. {
  9375. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9376. }
  9377. else
  9378. {
  9379. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9380. }
  9381. string date1 = GetPostString("date1");
  9382. string date2 = GetPostString("date2");
  9383. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9384. if (dw.Length > 0) lw.Add(dw);
  9385. string placedate1 = GetPostString("placedate1");
  9386. string placedate2 = GetPostString("placedate2");
  9387. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9388. if (fdw.Length > 0) lw.Add(fdw);
  9389. string price1 = GetPostString("price1");
  9390. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9391. string price2 = GetPostString("price2");
  9392. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9393. string checkst = GetPostString("checkstate");
  9394. if (checkst.Length > 0 && "10".Equals(checkst))
  9395. {
  9396. lw.Add(string.Format("CheckOut>0"));
  9397. }
  9398. else
  9399. {
  9400. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9401. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9402. }
  9403. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9404. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9405. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9406. writeGridDataTableJson(dStruct.TotalCount, dt);
  9407. }
  9408. public void ins_erp_startCheck()
  9409. {
  9410. if (UrlPostParmsCheck("ctid"))
  9411. {
  9412. string eid = GetPostString("ctid");
  9413. CeErpTradeCell entity = null;
  9414. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9415. if (entity != null)
  9416. {
  9417. entity.MemoOpt = 4;
  9418. entity.UpdateTime = DateTime.Now;
  9419. entity.Update();
  9420. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9421. CeErpSukuraData.createInfo(entity.ctid, 6);
  9422. returnSuccessMsg("操作成功!");
  9423. return;
  9424. }
  9425. returnErrorMsg("找不到记录");
  9426. }
  9427. }
  9428. public void upd_erp_sendXlw()
  9429. {
  9430. if (UrlPostParmsCheck("ctid"))
  9431. {
  9432. string eid = GetPostString("ctid");
  9433. CeErpTradeCell entity = null;
  9434. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9435. if (entity != null)
  9436. {
  9437. if (entity.IsSendGift == 1)
  9438. {
  9439. returnErrorMsg("请勿重复标记");
  9440. return;
  9441. }
  9442. entity.IsSendGift = 1;
  9443. entity.Update();
  9444. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9445. returnSuccessMsg("操作成功!");
  9446. return;
  9447. }
  9448. returnErrorMsg("找不到记录");
  9449. }
  9450. }
  9451. public void cancel_sendXlw()
  9452. {
  9453. if (UrlPostParmsCheck("ctid"))
  9454. {
  9455. string eid = GetPostString("ctid");
  9456. CeErpTradeCell entity = null;
  9457. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9458. if (entity != null)
  9459. {
  9460. if (entity.IsSendGift == 0)
  9461. {
  9462. returnErrorMsg("未标记小礼物");
  9463. return;
  9464. }
  9465. entity.IsSendGift = 0;
  9466. entity.Update();
  9467. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9468. returnSuccessMsg("操作成功!");
  9469. return;
  9470. }
  9471. returnErrorMsg("找不到记录");
  9472. }
  9473. }
  9474. public void get_erp_designbill()
  9475. {
  9476. DataStruct dStruct = GetPostStruct();
  9477. List<string> lw = new List<string>();
  9478. int isMy = GetInt("my");
  9479. if (isMy == 1)
  9480. {
  9481. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9482. }
  9483. string tid = GetPostString("tid");
  9484. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9485. string userName = GetPostString("design");
  9486. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9487. string price1 = GetPostString("price1");
  9488. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9489. string price2 = GetPostString("price2");
  9490. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9491. string rePrice1 = GetPostString("rePrice1");
  9492. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9493. string rePrice2 = GetPostString("rePrice2");
  9494. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9495. string designerType = GetPostString("designerType");
  9496. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9497. string orderState = GetPostString("orderState");
  9498. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9499. string endTime1 = GetPostString("endTime1");
  9500. string endTime2 = GetPostString("endTime2");
  9501. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9502. if (dw.Length > 0) lw.Add(dw);
  9503. string isDk = GetPostString("isDk");
  9504. if (isDk == "1")
  9505. {
  9506. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9507. }
  9508. else if (isDk == "0")
  9509. {
  9510. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9511. }
  9512. dStruct.Order = "oid, create_time desc";
  9513. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9514. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9515. writeGridDataTableJson(dStruct.TotalCount, dt);
  9516. }
  9517. public void upd_erp_designerbill()
  9518. {
  9519. if (UrlPostParmsCheck("ID"))
  9520. {
  9521. string eid = GetPostString("ID");
  9522. CeErpDesignerBill entity = null;
  9523. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9524. if (entity != null)
  9525. {
  9526. if (GetPostDouble("designerpirce") > 0)
  9527. {
  9528. entity.realPrice = GetPostDouble("designerpirce");
  9529. entity.update_time = DateTime.Now;
  9530. entity.update_u_id = CurrentUser.UserID;
  9531. entity.update_u_name = CurrentUser.UserName;
  9532. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9533. entity.Update();
  9534. returnSuccessMsg("操作成功!");
  9535. return;
  9536. }
  9537. else
  9538. {
  9539. entity.price = GetPostDouble("price");
  9540. entity.update_time = DateTime.Now;
  9541. entity.update_u_id = CurrentUser.UserID;
  9542. entity.update_u_name = CurrentUser.UserName;
  9543. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9544. entity.Update();
  9545. returnSuccessMsg("操作成功!");
  9546. return;
  9547. }
  9548. }
  9549. returnErrorMsg("找不到记录");
  9550. }
  9551. }
  9552. public void audit_erp_designerbill()
  9553. {
  9554. if (UrlPostParmsCheck("ID"))
  9555. {
  9556. string eid = GetPostString("ID");
  9557. CeErpDesignerBill entity = null;
  9558. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9559. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9560. if (entity != null)
  9561. {
  9562. entity.realPrice = GetPostDouble("designerpirce");
  9563. entity.update_time = DateTime.Now;
  9564. entity.update_u_id = CurrentUser.UserID;
  9565. entity.update_u_name = CurrentUser.UserName;
  9566. entity.isAudit = 1;
  9567. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9568. entity.Update();
  9569. if (orderEntity != null)
  9570. {
  9571. orderEntity.IsReadTag = 3;
  9572. orderEntity.Update();
  9573. }
  9574. returnSuccessMsg("操作成功!");
  9575. return;
  9576. }
  9577. returnErrorMsg("找不到记录");
  9578. }
  9579. }
  9580. public void all_audit_erp_designerbill()
  9581. {
  9582. if (UrlPostParmsCheck("idList"))
  9583. {
  9584. string[] list = GetPostString("idList").Split(',');
  9585. CeErpDesignerBill entity = null;
  9586. for (int i = 0; i < list.Length; i++)
  9587. {
  9588. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9589. if (entity == null) return;
  9590. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9591. if (orderEntity == null) return;
  9592. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9593. entity.update_time = DateTime.Now;
  9594. entity.update_u_id = CurrentUser.UserID;
  9595. entity.update_u_name = CurrentUser.UserName;
  9596. entity.isAudit = 1;
  9597. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9598. entity.Update();
  9599. orderEntity.IsReadTag = 3;
  9600. orderEntity.Update();
  9601. }
  9602. returnSuccessMsg("操作成功!");
  9603. return;
  9604. }
  9605. }
  9606. public void get_erp_sameorders()
  9607. {
  9608. if (UrlPostParmsCheck("ctid"))
  9609. {
  9610. string eid = GetPostString("ctid");
  9611. CeErpTradeCell entity = null;
  9612. entity = CeErpTradeCell.GetByCtid(eid);
  9613. if (entity != null)
  9614. {
  9615. StringBuilder sql = new StringBuilder();
  9616. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9617. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9618. var res = new
  9619. {
  9620. data = dt.Rows.Count
  9621. };
  9622. string ro_jsond = JsonConvert.SerializeObject(res);
  9623. returnSuccess(ro_jsond);
  9624. return;
  9625. }
  9626. returnErrorMsg("未找到订单");
  9627. return;
  9628. }
  9629. returnErrorMsg("缺少必要的参数");
  9630. }
  9631. public void get_erp_islasthavesameorder()
  9632. {
  9633. if (UrlPostParmsCheck("ctid"))
  9634. {
  9635. string eid = GetPostString("ctid");
  9636. string[] ctidList = eid.Split(',');
  9637. StringBuilder sql = new StringBuilder();
  9638. string tisCtid = "";
  9639. foreach (string ctid in ctidList)
  9640. {
  9641. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9642. if (entity != null)
  9643. {
  9644. sql = new StringBuilder();
  9645. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9646. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9647. if (dth.Rows.Count > 0)
  9648. {
  9649. tisCtid += entity.ctid;
  9650. tisCtid += ",";
  9651. }
  9652. }
  9653. }
  9654. if (tisCtid.Length > 0)
  9655. {
  9656. var res = new
  9657. {
  9658. data = tisCtid
  9659. };
  9660. string ro_jsond = JsonConvert.SerializeObject(res);
  9661. returnSuccess(ro_jsond);
  9662. }
  9663. else
  9664. {
  9665. var res = new
  9666. {
  9667. data = ""
  9668. };
  9669. string ro_jsond = JsonConvert.SerializeObject(res);
  9670. returnSuccess(ro_jsond);
  9671. }
  9672. return;
  9673. }
  9674. returnErrorMsg("缺少必要的参数");
  9675. }
  9676. public void file_client_down_url()
  9677. {
  9678. if (!UrlPostParmsCheck("userId"))
  9679. {
  9680. returnErrorMsg("缺少必要的参数");
  9681. }
  9682. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9683. }
  9684. public void checkout_form_data()
  9685. {
  9686. if (!UrlPostParmsCheck("tid"))
  9687. {
  9688. returnErrorMsg("缺少必要的参数");
  9689. }
  9690. string tid = GetPostString("tid");
  9691. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9692. if (ceErpOrderFormData != null)
  9693. {
  9694. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9695. returnSuccess(ro_jsond);
  9696. return;
  9697. }
  9698. returnErrorMsg("尚未有文件!");
  9699. }
  9700. public void back_supplier_audit()
  9701. {
  9702. int userId = CurrentUser.UserID;
  9703. StringBuilder sql = new StringBuilder();
  9704. 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);
  9705. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9706. if (dt.Rows.Count > 0)
  9707. {
  9708. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9709. }
  9710. else
  9711. {
  9712. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9713. }
  9714. }
  9715. public void back_supplier_query()
  9716. {
  9717. string eid = GetPostString("ctid");
  9718. if (eid != "")
  9719. {
  9720. StringBuilder sql = new StringBuilder();
  9721. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9722. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9723. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9724. }
  9725. else
  9726. {
  9727. returnErrorMsg("找不到订单记录");
  9728. return;
  9729. }
  9730. }
  9731. public void verified_to_order()
  9732. {
  9733. int userId = CurrentUser.UserID;
  9734. StringBuilder sql = new StringBuilder();
  9735. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9736. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9737. if (dt.Rows.Count > 0)
  9738. {
  9739. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9740. }
  9741. else
  9742. {
  9743. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9744. }
  9745. }
  9746. public void upd_supplier_audit()
  9747. {
  9748. if (UrlPostParmsCheck("ctid"))
  9749. {
  9750. string eid = GetPostString("ctid");
  9751. string reason = GetPostString("returnreason");
  9752. CeErpTradeCell entity = null;
  9753. CeWithdraw withdraw = null;
  9754. withdraw = CeWithdraw.GetByTid(eid);
  9755. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9756. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9757. {
  9758. if (withdraw != null)
  9759. {
  9760. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9761. {
  9762. returnSuccessMsg("您没有权限操作!");
  9763. return;
  9764. }
  9765. else
  9766. {
  9767. if (reason.Equals("1"))
  9768. {
  9769. if (entity.OrderState == -1)
  9770. {
  9771. if (entity.FinishPlaceTime == null)
  9772. {
  9773. entity.OrderState = 2;
  9774. }
  9775. else
  9776. {
  9777. entity.OrderState = 6;
  9778. }
  9779. }
  9780. entity.Update();
  9781. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9782. if (withdraw != null)
  9783. {
  9784. withdraw.status = int.Parse(reason);
  9785. withdraw.Update();
  9786. }
  9787. returnSuccessMsg("操作成功!");
  9788. return;
  9789. }
  9790. else
  9791. {
  9792. withdraw.status = int.Parse(reason);
  9793. withdraw.acknowledgingtime = DateTime.Now;
  9794. withdraw.Update();
  9795. returnSuccessMsg("查看详细请点击线下订单查询");
  9796. return;
  9797. }
  9798. }
  9799. }
  9800. // 第一个字符是 'N'
  9801. }
  9802. if (eid[0] != 'N')
  9803. {
  9804. }
  9805. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9806. {
  9807. entity.IsVerifyToSupplier = false;
  9808. entity.IsReturn = 1;
  9809. entity.ReturnTime = DateTime.Now;
  9810. entity.ReturnReason = reason;
  9811. if (entity.OrderState == 6)
  9812. {
  9813. entity.OrderState = 5;
  9814. }
  9815. entity.Update();
  9816. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9817. if (withdraw != null)
  9818. {
  9819. withdraw.status = int.Parse(reason);
  9820. withdraw.Update();
  9821. }
  9822. returnSuccessMsg("操作成功!");
  9823. return;
  9824. }
  9825. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9826. {
  9827. ;
  9828. if (withdraw != null)
  9829. {
  9830. withdraw.status = int.Parse(reason);
  9831. withdraw.acknowledgingtime = DateTime.Now;
  9832. withdraw.Update();
  9833. returnSuccessMsg("供应商取消撤回!");
  9834. return;
  9835. }
  9836. }
  9837. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9838. {
  9839. if (entity.OrderState == -1)
  9840. {
  9841. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9842. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9843. {
  9844. returnErrorMsg("订单spu没有确认无法通过审核!");
  9845. return;
  9846. }
  9847. if (entity.FinishPlaceTime == null)
  9848. {
  9849. entity.OrderState = 2;
  9850. }
  9851. else
  9852. {
  9853. entity.OrderState = 3;
  9854. }
  9855. commonHelper.getCytPrice(entity);
  9856. }
  9857. entity.Update();
  9858. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9859. if (withdraw != null)
  9860. {
  9861. withdraw.status = int.Parse(reason);
  9862. withdraw.Update();
  9863. }
  9864. returnSuccessMsg("操作成功!");
  9865. return;
  9866. }
  9867. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9868. {
  9869. if (withdraw == null)
  9870. {
  9871. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9872. return;
  9873. }
  9874. }
  9875. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9876. {
  9877. if (withdraw != null)
  9878. {
  9879. withdraw.status = int.Parse(reason);
  9880. withdraw.acknowledgingtime = DateTime.Now;
  9881. withdraw.Update();
  9882. returnSuccessMsg("查看详细请点击线下订单查询");
  9883. return;
  9884. }
  9885. }
  9886. return;
  9887. }
  9888. }
  9889. //校验报价
  9890. public void refund_order_tip()
  9891. {
  9892. int userid = CurrentUser.UserID;
  9893. int sectionId = CurrentUser.UserPost.OrgID;
  9894. StringBuilder sql = new StringBuilder();
  9895. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9896. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9897. List<string> ids = new List<string>();
  9898. if (dth.Rows.Count > 0)
  9899. {
  9900. foreach (DataRow dr in dth.Rows)
  9901. {
  9902. ids.Add(dr["ID"].ToString());
  9903. }
  9904. try
  9905. {
  9906. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9907. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9908. }
  9909. catch (Exception ex)
  9910. {
  9911. }
  9912. }
  9913. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9914. }
  9915. public void refund_order_Design()
  9916. {
  9917. int userid = CurrentUser.UserID;
  9918. int sectionId = CurrentUser.UserPost.OrgID;
  9919. StringBuilder sql = new StringBuilder();
  9920. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9921. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9922. List<string> ids = new List<string>();
  9923. if (dth.Rows.Count > 0)
  9924. {
  9925. foreach (DataRow dr in dth.Rows)
  9926. {
  9927. ids.Add(dr["ID"].ToString());
  9928. }
  9929. try
  9930. {
  9931. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9932. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9933. }
  9934. catch (Exception ex)
  9935. {
  9936. }
  9937. }
  9938. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9939. }
  9940. public void change_order_info()
  9941. {
  9942. int userid = CurrentUser.UserID;
  9943. StringBuilder sql = new StringBuilder();
  9944. 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);
  9945. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9946. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9947. }
  9948. public void change_win_mome()
  9949. {
  9950. if (UrlPostParmsCheck("id,ctid"))
  9951. {
  9952. string id = GetPostString("id");
  9953. string ctid = GetPostString("ctid");
  9954. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9955. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9956. if (ce == null || ceErpMessageTip == null)
  9957. {
  9958. returnSuccessMsg("未找到对应的订单!");
  9959. return;
  9960. }
  9961. if (ce.OrderState >= 5)
  9962. {
  9963. returnSuccessMsg("已上传文件无法修改!");
  9964. return;
  9965. }
  9966. int type = GetPostInt("type");
  9967. string content = GetPostString("content");
  9968. if (type == 0)
  9969. {
  9970. content = content.Replace("(", "(");
  9971. content = content.Replace(")", ")");
  9972. string check = MidStrEx(content, "(", ")").Trim();
  9973. if (string.IsNullOrEmpty(check))
  9974. {
  9975. returnSuccessMsg("文件名格式不正确");
  9976. return;
  9977. }
  9978. }
  9979. ce.DispatchSort = 0;
  9980. ce.seller_memo = content;
  9981. ce.Update();
  9982. ceErpMessageTip.isVisit = true;
  9983. ceErpMessageTip.Update();
  9984. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  9985. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  9986. ApiVo apiVo = new ApiVo();
  9987. apiVo.orderNumber = ce.ctid;
  9988. apiVo.actionName = "demandDesign";
  9989. apiVo.orderRemarks = content;
  9990. apiVo.demandExamine = type + 1;
  9991. designHelper.API_WorkCore(apiVo);//demandDesign
  9992. returnSuccessMsg("修改成功!");
  9993. }
  9994. }
  9995. public static string MidStrEx(string sourse, string startstr, string endstr)
  9996. {
  9997. string result = string.Empty;
  9998. int startindex, endindex;
  9999. try
  10000. {
  10001. startindex = sourse.IndexOf(startstr);
  10002. if (startindex == -1)
  10003. return result;
  10004. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10005. endindex = tmpstr.IndexOf(endstr);
  10006. if (endindex == -1)
  10007. return result;
  10008. result = tmpstr.Remove(endindex);
  10009. }
  10010. catch (Exception ex)
  10011. {
  10012. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10013. }
  10014. return result;
  10015. }
  10016. public void refund_order_list()
  10017. {
  10018. int userid = CurrentUser.UserID;
  10019. int sectionId = CurrentUser.UserPost.OrgID;
  10020. StringBuilder sql = new StringBuilder();
  10021. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10022. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10023. DataStruct dStruct = GetPostStruct();
  10024. DataTable dt = null;
  10025. List<string> ids = new List<string>();
  10026. List<string> tids = new List<string>();
  10027. if (dth.Rows.Count > 0)
  10028. {
  10029. foreach (DataRow dr in dth.Rows)
  10030. {
  10031. tids.Add("'" + dr["tid"].ToString() + "'");
  10032. ids.Add(dr["id"].ToString());
  10033. }
  10034. try
  10035. {
  10036. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10037. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10038. List<string> lw = new List<string>();
  10039. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10040. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10041. dt = WebCache.GetData("view_orderlist", dStruct);
  10042. }
  10043. catch (Exception ex)
  10044. {
  10045. }
  10046. }
  10047. writeGridDataTableJson(dStruct.TotalCount, dt);
  10048. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10049. }
  10050. //新增
  10051. public void order_batch_downloads()
  10052. {
  10053. string ceid = GetPostString("tid");
  10054. String[] tid = ceid.Split(',');
  10055. order_batch_caiyingtong(tid);
  10056. /* (string success, string errors) = UploadFiles(tid);
  10057. returnSuccessMsg(success + errors);*/
  10058. return;
  10059. }
  10060. //报价接口
  10061. public void Get_To_Quote()
  10062. {
  10063. string ceid = GetPostString("ctid");
  10064. if (ceid != null)
  10065. {
  10066. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10067. if (entity != null)
  10068. {
  10069. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10070. {
  10071. return;
  10072. }
  10073. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10074. double price = 0;
  10075. if (cp == null)
  10076. {
  10077. JObject jsonObject12 = new JObject
  10078. {
  10079. { "UserId", "77886" },
  10080. { "Pwd", "lt666888" },
  10081. { "Filename", entity.seller_memo }
  10082. };
  10083. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10084. JObject jsonObjects1 = JObject.Parse(response1);
  10085. string ms1g = (string)jsonObjects1["msg"];
  10086. if (ms1g == "报价成功")
  10087. {
  10088. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10089. string data = (string)jsonObject1["price"];
  10090. 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 + "');";
  10091. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10092. returnSuccessMsg("获取报价成功:" + data);
  10093. price = Convert.ToDouble(data);
  10094. }
  10095. else
  10096. {
  10097. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10098. return;
  10099. }
  10100. }
  10101. String[] beizhu = entity.seller_memo.Split('-');
  10102. String chanp = "";
  10103. if (beizhu.Length > 0)
  10104. {
  10105. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10106. }
  10107. else
  10108. {
  10109. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10110. }
  10111. JObject jsonObject = new JObject
  10112. {
  10113. { "UserId", "77886" },
  10114. { "Pwd", "lt666888" },
  10115. { "Filename", chanp }
  10116. };
  10117. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10118. JObject jsonObjects = JObject.Parse(response);
  10119. string msg = (string)jsonObjects["msg"];
  10120. if (msg == "报价成功")
  10121. {
  10122. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10123. string data = (string)jsonObject1["price"];
  10124. 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 + "');";
  10125. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10126. returnSuccessMsg("获取报价成功:" + data);
  10127. price = Convert.ToDouble(data);
  10128. }
  10129. else
  10130. {
  10131. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10132. return;
  10133. }
  10134. if (price > 0)
  10135. {
  10136. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10137. if (ceErpTradeCellExtend == null)
  10138. {
  10139. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10140. ceErpTradeCellExtend.ctid = entity.ctid;
  10141. ceErpTradeCellExtend.payment_cyt = price;
  10142. ceErpTradeCellExtend.Create();
  10143. }
  10144. else
  10145. {
  10146. ceErpTradeCellExtend.payment_cyt = price;
  10147. ceErpTradeCellExtend.Update();
  10148. }
  10149. }
  10150. return;
  10151. }
  10152. }
  10153. else
  10154. {
  10155. returnErrorMsg("请至少选择一条数据");
  10156. return;
  10157. }
  10158. }
  10159. //新增
  10160. public void order_To_Supplier()
  10161. {
  10162. string ceid = GetPostString("tid");
  10163. String[] tid = ceid.Split(',');
  10164. if (tid.Length > 0)
  10165. {
  10166. try
  10167. {
  10168. for (int i = 0; i < tid.Length; i++)
  10169. {
  10170. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10171. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10172. entity.SupplierId = suid;
  10173. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10174. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10175. entity.Update();
  10176. }
  10177. }
  10178. catch (Exception ex)
  10179. {
  10180. returnErrorMsg("自动匹配供应商失败");
  10181. return;
  10182. }
  10183. }
  10184. else
  10185. {
  10186. returnErrorMsg("请至少选择一条数据");
  10187. return;
  10188. }
  10189. returnSuccessMsg("自动匹配供应商成功");
  10190. return;
  10191. }
  10192. public (string, string) UploadFiles(string[] urls)
  10193. {
  10194. string success = "";
  10195. string errors = "";
  10196. int userid = CurrentUser.UserID;
  10197. foreach (string url in urls)
  10198. {
  10199. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10200. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10201. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10202. {
  10203. JObject jsonObject = new JObject
  10204. {
  10205. { "Userid", "77886" },
  10206. { "pwd", "cyt86435015" },
  10207. { "content", base64FileContent },
  10208. { "ext", Path.GetExtension(fileName) }
  10209. };
  10210. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10211. JObject jsonObjects = JObject.Parse(response);
  10212. string msg = (string)jsonObjects["msg"];
  10213. if (msg.Equals("上传成功"))
  10214. {
  10215. success += url + " 上传成功";
  10216. }
  10217. else
  10218. {
  10219. errors += url + " 上传失败";
  10220. }
  10221. }
  10222. else
  10223. {
  10224. errors += url + " 格式出现问题";
  10225. }
  10226. }
  10227. if (urls.Length == 0)
  10228. {
  10229. return (success, errors);
  10230. }
  10231. return (success, errors);
  10232. }
  10233. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10234. {
  10235. return true; //总是接受
  10236. }
  10237. public static string HttpPost(string url, string param = null)
  10238. {
  10239. HttpWebRequest request;
  10240. //如果是发送HTTPS请求
  10241. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10242. {
  10243. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10244. request = WebRequest.Create(url) as HttpWebRequest;
  10245. request.ProtocolVersion = HttpVersion.Version10;
  10246. }
  10247. else
  10248. {
  10249. request = WebRequest.Create(url) as HttpWebRequest;
  10250. }
  10251. request.Method = "POST";
  10252. request.ContentType = "application/json";
  10253. request.Accept = "*/*";
  10254. request.Timeout = 120000;
  10255. request.AllowAutoRedirect = false;
  10256. StreamWriter requestStream = null;
  10257. WebResponse response = null;
  10258. string responseStr = null;
  10259. try
  10260. {
  10261. requestStream = new StreamWriter(request.GetRequestStream());
  10262. requestStream.Write(param);
  10263. requestStream.Close();
  10264. response = request.GetResponse();
  10265. if (response != null)
  10266. {
  10267. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10268. responseStr = reader.ReadToEnd();
  10269. reader.Close();
  10270. }
  10271. }
  10272. catch (Exception ex)
  10273. {
  10274. return ex.Message;
  10275. }
  10276. finally
  10277. {
  10278. request = null;
  10279. requestStream = null;
  10280. response = null;
  10281. }
  10282. return responseStr;
  10283. }
  10284. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10285. {
  10286. string base64FileContent;
  10287. string fileName;
  10288. using (WebClient webClient = new WebClient())
  10289. {
  10290. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10291. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10292. {
  10293. using (Stream stream = response.GetResponseStream())
  10294. {
  10295. using (MemoryStream memoryStream = new MemoryStream())
  10296. {
  10297. stream.CopyTo(memoryStream);
  10298. byte[] fileBytes = memoryStream.ToArray();
  10299. base64FileContent = Convert.ToBase64String(fileBytes);
  10300. fileName = response.Headers["Content-Disposition"];
  10301. if (!string.IsNullOrEmpty(fileName))
  10302. {
  10303. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10304. if (index >= 0)
  10305. {
  10306. fileName = fileName.Substring(index + 9).Trim('\"');
  10307. }
  10308. }
  10309. else
  10310. {
  10311. fileName = Path.GetFileName(downloadUrl);
  10312. }
  10313. }
  10314. }
  10315. }
  10316. }
  10317. return (fileName, base64FileContent);
  10318. }
  10319. //新增
  10320. public void order_batch_caiyingtong(string[] downloadUrls)
  10321. {
  10322. try
  10323. {
  10324. //遍历文件
  10325. DataStruct dStruct = GetPostStruct();
  10326. DataTable dt = null;
  10327. int userid = CurrentUser.UserID;
  10328. List<string> ids = new List<string>();//失败组
  10329. List<string> tids = new List<string>();
  10330. using (WebClient webClient = new WebClient())
  10331. {
  10332. foreach (var url in downloadUrls)
  10333. {
  10334. try
  10335. {
  10336. tids.Add("'" + url + "'");
  10337. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10338. if (entity != null)
  10339. {
  10340. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10341. if (cp == null)
  10342. {
  10343. JObject jsonObject = new JObject
  10344. {
  10345. { "Userid", "77886" },
  10346. { "pwd", "lt666888" },
  10347. { "Filename",entity.seller_memo }
  10348. };
  10349. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10350. JObject jsonObjects = JObject.Parse(response);
  10351. string msg = (string)jsonObjects["msg"];
  10352. if (msg == "报价成功")
  10353. {
  10354. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10355. DownloadAndConvertToBase64(url1);
  10356. }
  10357. else
  10358. {
  10359. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10360. }
  10361. }
  10362. else
  10363. {
  10364. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10365. JObject jsonObject = new JObject
  10366. {
  10367. { "Userid", "77886" },
  10368. { "pwd", "lt666888" },
  10369. { "Filename",chanp }
  10370. };
  10371. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10372. JObject jsonObjects = JObject.Parse(response);
  10373. string msg = (string)jsonObjects["msg"];
  10374. if (msg == "报价成功")
  10375. {
  10376. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10377. DownloadAndConvertToBase64(url1);
  10378. }
  10379. else
  10380. {
  10381. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10382. }
  10383. }
  10384. }
  10385. // 上传文件到FTP
  10386. }
  10387. catch (Exception ex)
  10388. {
  10389. Console.WriteLine($"An error occurred: {ex.Message}");
  10390. }
  10391. }
  10392. List<string> lw = new List<string>();
  10393. lw.Add(string.Format("( OrderState < 6 )"));
  10394. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10395. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10396. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10397. if (dt.Rows.Count > 0)
  10398. {
  10399. foreach (DataRow dr in dt.Rows)
  10400. {
  10401. ids.Add(dr["ctid"].ToString());
  10402. }
  10403. }
  10404. String ErrorMsgs = "";
  10405. foreach (String id in ids)
  10406. {
  10407. ErrorMsgs += id + ",";
  10408. }
  10409. if (ErrorMsgs.Length > 1)
  10410. {
  10411. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10412. }
  10413. if (ErrorMsgs.Length < 1)
  10414. {
  10415. ErrorMsgs = "上传成功";
  10416. returnSuccessMsg(ErrorMsgs);
  10417. }
  10418. else
  10419. {
  10420. returnErrorMsg("以下订单" + ErrorMsgs);
  10421. }
  10422. }
  10423. // 删除文件夹及其内容
  10424. /* Directory.Delete(localDirectory, true);*/
  10425. }
  10426. catch { }
  10427. }
  10428. public void get_center_data()
  10429. {
  10430. int userId = CurrentUser.UserID;
  10431. string postCode = CurrentUser.UserPost.Post.Code;
  10432. List<string> lw = new List<string>();
  10433. List<string> ww = new List<string>();
  10434. DateTime currentTime = DateTime.Now;
  10435. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10436. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10437. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10438. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10439. string sql = " SELECT ";
  10440. string startTime = "2023-10-01 11:22:31";
  10441. //设计
  10442. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10443. {
  10444. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10445. 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));
  10446. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10447. 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));
  10448. }
  10449. //客服
  10450. else if (postCode == "CustomerService" || postCode == "Director")
  10451. {
  10452. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10453. 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));
  10454. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10455. 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));
  10456. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10457. 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));
  10458. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10459. 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));
  10460. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10461. 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));
  10462. }
  10463. //售后
  10464. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10465. {
  10466. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10467. 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));
  10468. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10469. 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));
  10470. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10471. 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));
  10472. }
  10473. //下单部
  10474. else if (postCode == "Place" || postCode == "PlaceMr")
  10475. {
  10476. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10477. 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));
  10478. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10479. 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));
  10480. }
  10481. //车间
  10482. else if (postCode == "Supplier")
  10483. {
  10484. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10485. 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));
  10486. }
  10487. DataTable dt = new DataTable();
  10488. if (lw.Count > 0)
  10489. {
  10490. sql += string.Join(" , ", lw);
  10491. sql += " FROM ";
  10492. sql += string.Join(" , ", ww);
  10493. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10494. }
  10495. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10496. }
  10497. public void get_center_data_list()
  10498. {
  10499. int userId = CurrentUser.UserID;
  10500. string postCode = CurrentUser.UserPost.Post.Code;
  10501. string shopIds = CurrentUser.User.pemShop;
  10502. DataStruct dStruct = GetPostStruct();
  10503. List<string> lw = new List<string>();
  10504. DateTime currentTime = DateTime.Now;
  10505. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10506. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10507. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10508. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10509. string startTime = "2023-10-01 11:22:31";
  10510. int order_type = GetPostInt("order_type");
  10511. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10512. {
  10513. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10514. if (order_type == 0)
  10515. {
  10516. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10517. }
  10518. else if (order_type == 3)
  10519. {
  10520. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10521. }
  10522. else
  10523. {
  10524. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10525. }
  10526. }
  10527. //客服
  10528. if (postCode == "CustomerService" || postCode == "Director")
  10529. {
  10530. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10531. if (order_type == 0)
  10532. {
  10533. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10534. }
  10535. else if (order_type == 1)
  10536. {
  10537. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10538. }
  10539. else if (order_type == 2)
  10540. {
  10541. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10542. }
  10543. else if (order_type == 3)
  10544. {
  10545. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10546. }
  10547. else if (order_type == 4)
  10548. {
  10549. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10550. }
  10551. else
  10552. {
  10553. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10554. }
  10555. }
  10556. //售后
  10557. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10558. {
  10559. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10560. if (shopIds != "")
  10561. {
  10562. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10563. }
  10564. if (order_type == 2)
  10565. {
  10566. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10567. }
  10568. else if (order_type == 4)
  10569. {
  10570. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10571. }
  10572. else if (order_type == 5)
  10573. {
  10574. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10575. }
  10576. else
  10577. {
  10578. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10579. }
  10580. }
  10581. //下单部
  10582. if (postCode == "Place" || postCode == "PlaceMr")
  10583. {
  10584. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10585. if (shopIds != "")
  10586. {
  10587. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10588. }
  10589. else if (order_type == 1)
  10590. {
  10591. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10592. }
  10593. else if (order_type == 2)
  10594. {
  10595. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10596. }
  10597. else
  10598. {
  10599. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10600. }
  10601. }
  10602. //车间
  10603. if (postCode == "Supplier")
  10604. {
  10605. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10606. if (order_type == 5)
  10607. {
  10608. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10609. }
  10610. else
  10611. {
  10612. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10613. }
  10614. }
  10615. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10616. dStruct.Fileds = "tid,ctid";
  10617. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10618. writeGridDataTableJson(dStruct.TotalCount, dt);
  10619. }
  10620. public void aftersale_audit_master()
  10621. {
  10622. if (UrlPostParmsCheck("ctid"))
  10623. {
  10624. string ctid = GetPostString("ctid");
  10625. if (ctid.Length > 0)
  10626. {
  10627. bool result = aftersale_data_change(ctid);
  10628. if (result)
  10629. {
  10630. returnSuccessMsg("修改成功!");
  10631. return;
  10632. }
  10633. }
  10634. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10635. }
  10636. }
  10637. public void aftersale_batch_audit_master()
  10638. {
  10639. if (UrlPostParmsCheck("ctids"))
  10640. {
  10641. string ctids = GetPostString("ctids");
  10642. if (ctids.Length > 0)
  10643. {
  10644. List<string> list = new List<string>();
  10645. string[] ctid_list = ctids.Split(',');
  10646. foreach (var item in ctid_list)
  10647. {
  10648. bool result = aftersale_data_change(item);
  10649. if (!result)
  10650. {
  10651. list.Add(item);
  10652. }
  10653. }
  10654. if (list.Count > 0)
  10655. {
  10656. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10657. return;
  10658. }
  10659. returnSuccessMsg("修改成功!");
  10660. return;
  10661. }
  10662. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10663. }
  10664. }
  10665. public bool aftersale_data_change(string ctid)
  10666. {
  10667. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10668. if (ceErpTradeCell != null)
  10669. {
  10670. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10671. ceErpTradeCell.AfterSaleSupplierState = 0;
  10672. StringBuilder sql = new StringBuilder();
  10673. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10674. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10675. CeErpTradeResponsible.DelByTid(ctid, 0);
  10676. 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 == "不理赔")
  10677. {
  10678. CeErpTradeResponsible.DelByTid(ctid, 1);
  10679. ceErpTradeCell.AfterSaleSupplierState = 1;
  10680. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10681. ceErpTradeCell.AfterSaleState = 4;
  10682. }
  10683. else
  10684. {
  10685. ceErpTradeCell.AfterSaleState = 3;
  10686. }
  10687. bool needCyt = false;
  10688. if (dt != null)
  10689. {
  10690. if (dt.Rows.Count == 1)
  10691. {
  10692. bool isEnd = false;
  10693. foreach (DataRow dr in dt.Rows)
  10694. {
  10695. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10696. {
  10697. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10698. isEnd = true;
  10699. }
  10700. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10701. {
  10702. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10703. isEnd = true;
  10704. }
  10705. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10706. {
  10707. needCyt = true;
  10708. }
  10709. }
  10710. if (isEnd)
  10711. {
  10712. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10713. ceErpTradeCell.AfterSaleState = 4;
  10714. ceErpTradeCell.AfterSaleSupplierState = 1;
  10715. }
  10716. }
  10717. else
  10718. {
  10719. bool isAll = true;
  10720. foreach (DataRow dr in dt.Rows)
  10721. {
  10722. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10723. {
  10724. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10725. continue;
  10726. }
  10727. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10728. {
  10729. string path = "";
  10730. int OrgID = 0;
  10731. if (!Convert.IsDBNull(dr["OrgPath"]))
  10732. {
  10733. path = dr["OrgPath"].ToString();
  10734. }
  10735. if (!Convert.IsDBNull(dr["OrgID"]))
  10736. {
  10737. OrgID = Convert.ToInt32(dr["OrgID"]);
  10738. }
  10739. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10740. {
  10741. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10742. continue;
  10743. }
  10744. }
  10745. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10746. {
  10747. needCyt = true;
  10748. }
  10749. isAll = false;
  10750. }
  10751. if (isAll)
  10752. {
  10753. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10754. ceErpTradeCell.AfterSaleState = 4;
  10755. ceErpTradeCell.AfterSaleSupplierState = 1;
  10756. }
  10757. }
  10758. }
  10759. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10760. {
  10761. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10762. }
  10763. if (ceErpTradeCell.AfterSaleState == 4)
  10764. {
  10765. ApiVo apiVo = new ApiVo();
  10766. apiVo.orderNumber = ceErpTradeCell.ctid;
  10767. apiVo.actionName = "afterOver";
  10768. designHelper.API_WorkCore(apiVo); //afterOver
  10769. }
  10770. ceErpTradeCell.Update();
  10771. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10772. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10773. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10774. return true;
  10775. }
  10776. return false;
  10777. }
  10778. public void get_erp_wechatorder()
  10779. {
  10780. DataStruct dStruct = GetPostStruct();
  10781. List<string> lw = new List<string>();
  10782. string tid = GetPostString("tid");
  10783. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10784. string shopname = GetPostString("shopname");
  10785. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10786. string buyernick = GetPostString("buyer_nick");
  10787. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10788. string customer = GetPostString("customer");
  10789. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10790. string returndate1 = GetPostString("returndate1");
  10791. string returndate2 = GetPostString("returndate2");
  10792. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10793. if (dw.Length > 0) lw.Add(dw);
  10794. string finishDate1 = GetPostString("finishdate1");
  10795. string finishDate2 = GetPostString("finishdate2");
  10796. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10797. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10798. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10799. dStruct.Order = "created desc";
  10800. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10801. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10802. writeGridDataTableJson(dStruct.TotalCount, dt);
  10803. }
  10804. public void get_erp_wechatlist_sumprice()
  10805. {
  10806. DataStruct dStruct = GetPostStruct();
  10807. List<string> lw = new List<string>();
  10808. string tid = GetPostString("tid");
  10809. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10810. string shopname = GetPostString("shopname");
  10811. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10812. string buyernick = GetPostString("buyer_nick");
  10813. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10814. string customer = GetPostString("customer");
  10815. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10816. string returndate1 = GetPostString("returndate1");
  10817. string returndate2 = GetPostString("returndate2");
  10818. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10819. if (dw.Length > 0) lw.Add(dw);
  10820. string finishDate1 = GetPostString("finishdate1");
  10821. string finishDate2 = GetPostString("finishdate2");
  10822. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10823. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10824. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10825. string mainWhere = string.Join(" and ", lw.ToArray());
  10826. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10827. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10828. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10829. decimal total = 0;
  10830. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10831. {
  10832. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10833. }
  10834. var res = new
  10835. {
  10836. data = total
  10837. };
  10838. string ro_jsond = JsonConvert.SerializeObject(res);
  10839. returnSuccess(ro_jsond);
  10840. return;
  10841. }
  10842. public void get_erp_qr_waitdeliverylist()
  10843. {
  10844. DataStruct dStruct = GetPostStruct();
  10845. List<string> lw = new List<string>();
  10846. string tid = GetPostString("ctid");
  10847. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10848. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10849. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10850. var res_objz = new
  10851. {
  10852. restype = 1,
  10853. data = dt
  10854. };
  10855. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10856. returnSuccess(ro_jsonz);
  10857. }
  10858. public void get_erp_yield_list()
  10859. {
  10860. DataStruct dStruct = GetPostStruct();
  10861. List<string> lw = new List<string>();
  10862. string tid = GetPostString("ctid");
  10863. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10864. string shopname = GetPostString("shopname");
  10865. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10866. string buyernick = GetPostString("buyer_nick");
  10867. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10868. //if (tid.Length == 0 && buyernick.Length == 0)
  10869. //{
  10870. // lw.Add(string.Format("IsRefund<={0}", 1));
  10871. //}
  10872. string customer = GetPostString("customer");
  10873. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10874. string design = GetPostString("design");
  10875. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10876. string orderState = GetPostString("orderState");
  10877. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10878. string address = GetPostString("address");
  10879. 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));
  10880. string sellermemo = GetPostString("seller_memo");
  10881. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10882. string supplier = GetPostString("supplier");
  10883. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10884. string OrderArea = GetPostString("order_area");
  10885. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10886. string placedate1 = GetPostString("placedate1");
  10887. string placedate2 = GetPostString("placedate2");
  10888. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10889. if (fdw.Length > 0) lw.Add(fdw);
  10890. string price1 = GetPostString("price1");
  10891. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10892. string price2 = GetPostString("price2");
  10893. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10894. string unusualCon = GetPostString("unusualcon");
  10895. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10896. string posTag = CurrentUser.UserPost.Post.Code;
  10897. if (posTag == "Supplier")
  10898. {
  10899. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10900. }
  10901. lw.Add(string.Format("OrderState = 6 "));
  10902. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10903. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10904. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10905. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10906. writeGridDataTableJson(dStruct.TotalCount, dt);
  10907. }
  10908. public void change_erp_sup_state()
  10909. {
  10910. if (UrlPostParmsCheck("ctid"))
  10911. {
  10912. string ctid = GetPostString("ctid");
  10913. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10914. if (ceErpTradeCell != null)
  10915. {
  10916. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10917. if (ceErpTradeCellExtend == null)
  10918. {
  10919. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10920. ceErpTradeCellExtend.ctid = ctid;
  10921. ceErpTradeCellExtend.SupState = 1;
  10922. ceErpTradeCellExtend.Create();
  10923. }
  10924. else
  10925. {
  10926. ceErpTradeCellExtend.SupState = 1;
  10927. ceErpTradeCellExtend.Update();
  10928. }
  10929. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10930. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10931. return;
  10932. }
  10933. returnErrorMsg("找不到订单");
  10934. }
  10935. }
  10936. public void supplier_all_downs()
  10937. {
  10938. if (UrlPostParmsCheck("tids"))
  10939. {
  10940. string tids = GetPostString("tids");
  10941. if (tids != null && tids.Length > 0)
  10942. {
  10943. StringBuilder sql = new StringBuilder();
  10944. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10945. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10946. sql = new StringBuilder();
  10947. 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, "下载设计文件");
  10948. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10949. string[] list = tids.Split(',');
  10950. foreach (string ctid in list)
  10951. {
  10952. CeErpSukuraData.createInfo(ctid, 3);
  10953. }
  10954. designHelper.api_approveDesign(tids); //approveDesign
  10955. returnSuccessMsg("下载成功!");
  10956. return;
  10957. }
  10958. returnErrorMsg("下载订单更新失败");
  10959. }
  10960. }
  10961. public void uploaderFileSuccess()
  10962. {
  10963. if (UrlPostParmsCheck("fileName"))
  10964. {
  10965. string fileName = GetPostString("fileName");
  10966. ApiVo apiVo = new ApiVo();
  10967. apiVo.orderNumber = fileName;
  10968. apiVo.actionName = "finishDesign";
  10969. designHelper.API_WorkCore(apiVo);//finishDesign
  10970. returnSuccessMsg("");
  10971. }
  10972. }
  10973. public void get_sample2_order()
  10974. {
  10975. if (UrlPostParmsCheck("ctid"))
  10976. {
  10977. string ctid = GetPostString("ctid");
  10978. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10979. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10980. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10981. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10982. double total = 0.0;
  10983. double order_price = 0.0;
  10984. if (dt_bu.Rows.Count > 0)
  10985. {
  10986. foreach (DataRow dr in dt_bu.Rows)
  10987. {
  10988. total += Convert.ToDouble(dr["payment"]);
  10989. }
  10990. }
  10991. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  10992. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  10993. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  10994. string tid = ctid.Replace("S_", "");
  10995. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  10996. double paymant = 0.0;
  10997. if (entity != null)
  10998. {
  10999. paymant = entity.payment;
  11000. }
  11001. string return_reason = "";
  11002. if (dt_after != null && dt_after.Rows.Count > 0)
  11003. {
  11004. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11005. }
  11006. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11007. }
  11008. }
  11009. public void get_erp_design_status()
  11010. {
  11011. string designName = GetPostString("designName");
  11012. DataStruct dStruct = GetPostStruct();
  11013. if (designName.Length > 0)
  11014. {
  11015. 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";
  11016. sql_user += " and Name like '%" + designName + "%'";
  11017. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11018. List<string> ids_list = new List<string>();
  11019. if (user_table.Rows.Count > 0)
  11020. {
  11021. foreach (DataRow item in user_table.Rows)
  11022. {
  11023. ids_list.Add(item["id"].ToString());
  11024. string ids_s = item["TeamIds"].ToString();
  11025. if (ids_s.Length > 0)
  11026. {
  11027. ids_list.AddRange(ids_s.Split(','));
  11028. }
  11029. }
  11030. }
  11031. HashSet<string> set = new HashSet<string>(ids_list);
  11032. ids_list = set.ToList();
  11033. if (ids_list.Count > 0)
  11034. {
  11035. 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));
  11036. dStruct.MainWhere = sql;
  11037. DataTable dt = null;
  11038. dt = WebCache.GetData("view_ErpUser", dStruct);
  11039. writeGridDataTableJson(dStruct.TotalCount, dt);
  11040. }
  11041. }
  11042. }
  11043. public void change_erp_order_price()
  11044. {
  11045. string ctid = GetPostString("ctid");
  11046. double price = GetPostDouble("price");
  11047. if (ctid.Length > 0)
  11048. {
  11049. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11050. if (ceErpTradeCellExtend == null)
  11051. {
  11052. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11053. ceErpTradeCellExtend.ctid = ctid;
  11054. ceErpTradeCellExtend.payment_cyt = price;
  11055. ceErpTradeCellExtend.Create();
  11056. }
  11057. else
  11058. {
  11059. ceErpTradeCellExtend.payment_cyt = price;
  11060. ceErpTradeCellExtend.Update();
  11061. }
  11062. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11063. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11064. {
  11065. ceErpDataSendOrderInfo.isSync = false;
  11066. ceErpDataSendOrderInfo.Update();
  11067. }
  11068. if (ceErpDataSendOrderInfo == null)
  11069. {
  11070. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11071. ceErpDataSendOrderInfo.isSync = false;
  11072. ceErpDataSendOrderInfo.ctid = ctid;
  11073. ceErpDataSendOrderInfo.Create();
  11074. }
  11075. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11076. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11077. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11078. if (dth != null && dth.Rows.Count > 0)
  11079. {
  11080. dataSendOrderBean dataSendOrderBean = null;
  11081. foreach (DataRow item in dth.Rows)
  11082. {
  11083. try
  11084. {
  11085. dataSendOrderBean = new dataSendOrderBean();
  11086. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11087. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11088. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11089. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11090. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11091. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11092. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11093. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11094. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11095. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11096. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11097. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11098. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11099. if (result != null)
  11100. {
  11101. if ("0".Equals(result.errcode))
  11102. {
  11103. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11104. }
  11105. else
  11106. {
  11107. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11108. }
  11109. }
  11110. }
  11111. catch (Exception ex)
  11112. {
  11113. }
  11114. }
  11115. }
  11116. returnSuccessMsg("修改成功!");
  11117. return;
  11118. }
  11119. returnErrorMsg("找不到订单");
  11120. }
  11121. public void find_he_together()
  11122. {
  11123. string ctid = GetPostString("ctid");
  11124. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11125. List<string> list = new List<string>();
  11126. if (ceErpTradeCell != null)
  11127. {
  11128. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11129. {
  11130. 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);
  11131. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11132. if (table != null && table.Rows.Count > 0)
  11133. {
  11134. foreach (TableRow row in table.Rows)
  11135. {
  11136. }
  11137. }
  11138. }
  11139. }
  11140. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11141. }
  11142. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11143. {
  11144. //chy----19
  11145. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11146. //GD-CYT-----64
  11147. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11148. //ZHX----3
  11149. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11150. //JK----97
  11151. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11152. //ZT----70
  11153. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11154. //LHCY-----98
  11155. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11156. //XD-----90
  11157. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11158. //CYCY-----14
  11159. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11160. };
  11161. //其他改名
  11162. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11163. {
  11164. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11165. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11166. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11167. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11168. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11169. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11170. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11171. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11172. };
  11173. //不统计
  11174. List<int> no_suppliers = new List<int>()
  11175. {
  11176. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11177. };
  11178. //配件单
  11179. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11180. {
  11181. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11182. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11183. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11184. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11185. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11186. {"旗杆",new List<string>(){ "班旗" } },
  11187. {"牙签",new List<string>(){ "不干胶" } }
  11188. };
  11189. public void get_place_order_data()
  11190. {
  11191. string date1 = GetPostString("date1");
  11192. string date2 = GetPostString("date2");
  11193. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11194. DateTime start = DateTime.Parse(starttime);
  11195. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11196. DateTime end = DateTime.Parse(endtime);
  11197. if (date1 != null && date1.Length > 0)
  11198. {
  11199. DateTime dateTime = DateTime.Parse(date1);
  11200. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11201. start = DateTime.Parse(starttime);
  11202. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11203. end = DateTime.Parse(endtime);
  11204. }
  11205. if (date2 != null && date2.Length > 0)
  11206. {
  11207. DateTime dateTime = DateTime.Parse(date2);
  11208. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11209. end = DateTime.Parse(endtime);
  11210. }
  11211. 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);
  11212. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11213. //不干胶-----1,卡片-----29
  11214. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11215. foreach (DataRow row in data.Rows)
  11216. {
  11217. int productId = Convert.ToInt32(row["ProductId"]);
  11218. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11219. if (no_suppliers.Contains(supplierId))
  11220. {
  11221. continue;
  11222. }
  11223. string seller_memo = row["seller_memo"].ToString();
  11224. bool ispj = false;//是否配件单
  11225. bool isfirst = true;//第一个配
  11226. maps.Keys.ForEach(key =>
  11227. {
  11228. //备注包含配件
  11229. if (seller_memo.Contains(key) && isfirst)
  11230. {
  11231. List<string> list = maps[key];
  11232. ispj = true;
  11233. isfirst = false;
  11234. for (int i = 0; i < list.Count; i++)
  11235. {
  11236. if (seller_memo.Contains(list[i]))
  11237. {
  11238. ispj = false;
  11239. break;
  11240. }
  11241. }
  11242. }
  11243. });
  11244. if (ispj)
  11245. {
  11246. continue;
  11247. }
  11248. seller_memo = seller_memo.Replace("UV", "uv");
  11249. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11250. //吊牌归到卡片
  11251. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11252. seller_memo = seller_memo.Replace("卡套", "卡片");
  11253. seller_memo = seller_memo.Replace("封套", "卡片");
  11254. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11255. seller_memo = seller_memo.Replace("腰封", "卡片");
  11256. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11257. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11258. seller_memo = seller_memo.Replace("横幅", "条幅");
  11259. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11260. string map_key = "";
  11261. string type = "";
  11262. if (supplierMap.ContainsKey(supplierId))
  11263. {
  11264. foreach (var kvp in supplierMap[supplierId])
  11265. {
  11266. if (seller_memo.Contains(kvp.Key))
  11267. {
  11268. map_key = kvp.Value;
  11269. type = kvp.Value;
  11270. break;
  11271. }
  11272. }
  11273. }
  11274. if (map_key == "")
  11275. {
  11276. type = "其他";
  11277. map_key = "其他";
  11278. }
  11279. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11280. {
  11281. map_key = suppliers[supplierId];
  11282. }
  11283. if (supplierId == 70)
  11284. {
  11285. supplierId = 70;
  11286. }
  11287. map_key += "_" + row["SupplierName"].ToString();
  11288. Dictionary<string, int> map = null;
  11289. if (other_map.ContainsKey(map_key))
  11290. {
  11291. other_map.TryGetValue(map_key, out map);
  11292. }
  11293. else
  11294. {
  11295. map = new Dictionary<string, int>();
  11296. map.Add("dayDev", 0);//当天出货
  11297. map.Add("dayTotal", 0);//下单总数
  11298. map.Add("payTotal", 0);//500以上
  11299. map.Add("today", 0);//当天出货数量
  11300. map.Add("unusua", 0);//异常数
  11301. other_map.Add(map_key, map);
  11302. other_map.TryGetValue(map_key, out map);
  11303. }
  11304. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11305. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11306. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11307. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11308. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11309. {
  11310. map["dayTotal"]++;
  11311. if (supplierId == 97)
  11312. {
  11313. supplierId = 97;
  11314. }
  11315. }
  11316. if (Convert.ToDecimal(row["payment"]) >= 500)
  11317. {
  11318. map["payTotal"]++;
  11319. }
  11320. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11321. {
  11322. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11323. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11324. {
  11325. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11326. {
  11327. map["today"]++;
  11328. }
  11329. }
  11330. else
  11331. {
  11332. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11333. {
  11334. map["today"]++;
  11335. }
  11336. else
  11337. {
  11338. if (supplierId == 119)
  11339. {
  11340. Debug.WriteLine(row["seller_memo"].ToString());
  11341. }
  11342. }
  11343. }
  11344. }
  11345. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11346. {
  11347. map["unusua"]++;
  11348. }
  11349. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11350. //GD-CYT-----64
  11351. DateTime two = palceTimeStart.AddHours(14);
  11352. DateTime three = palceTimeStart.AddHours(15);
  11353. DateTime four = palceTimeStart.AddHours(16);
  11354. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11355. {
  11356. //下午四点前 500-1000
  11357. string count = row["ProductCount"].ToString();
  11358. if (count != null && count.Length > 0)
  11359. {
  11360. int productCount = commonHelper.getPlaceProductCount(count);
  11361. if (productCount >= 500 && productCount <= 1000)
  11362. {
  11363. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11364. {
  11365. map["dayDev"]++;
  11366. }
  11367. }
  11368. }
  11369. }
  11370. //UV
  11371. else if ("uv".Equals(type))
  11372. {
  11373. //ZT----70
  11374. //ZHX----3
  11375. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11376. {
  11377. map["dayDev"]++;
  11378. }
  11379. //JK----97
  11380. //HZX----105
  11381. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11382. {
  11383. map["dayDev"]++;
  11384. if (supplierId == 97)
  11385. {
  11386. supplierId = 97;
  11387. }
  11388. }
  11389. }
  11390. //帆布---52|条幅---27
  11391. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11392. {
  11393. //LHCY-----98
  11394. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11395. {
  11396. map["dayDev"]++;
  11397. }
  11398. }
  11399. //条幅
  11400. else if ("条幅".Equals(type))
  11401. {
  11402. //XD-----90
  11403. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11404. {
  11405. map["dayDev"]++;
  11406. }
  11407. }
  11408. //桌布
  11409. else if ("桌布".Equals(type))
  11410. {
  11411. //XD-----90
  11412. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11413. {
  11414. map["dayDev"]++;
  11415. }
  11416. }
  11417. //DL---10
  11418. //AYTW---119
  11419. //FS-CYT-DY ----80
  11420. //JK----97
  11421. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11422. {
  11423. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11424. {
  11425. map["dayDev"]++;
  11426. }
  11427. }
  11428. }
  11429. DataTable dt = new DataTable();
  11430. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11431. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11432. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11433. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11434. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11435. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11436. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11437. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11438. other_map.Keys.ForEach(key =>
  11439. {
  11440. DataRow dr = dt.NewRow();
  11441. Dictionary<string, int> map = other_map[key];
  11442. string[] key_list = key.Split('_');
  11443. dr[0] = key_list[0];
  11444. dr[1] = key_list[1];
  11445. if (key_list.Length > 2)
  11446. {
  11447. dr[1] += "(" + key_list[2] + ")";
  11448. }
  11449. dr[2] = map["dayTotal"];
  11450. dr[3] = map["payTotal"];
  11451. dr[4] = map["today"];
  11452. dr[5] = map["unusua"];
  11453. dr[6] = map["dayDev"];
  11454. double rate = 0.00;
  11455. if (map["dayDev"] > 0)
  11456. {
  11457. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11458. }
  11459. dr[7] = rate.ToString();
  11460. dt.Rows.Add(dr);
  11461. });
  11462. DataView dv = new DataView(dt);
  11463. dv.Sort = "SupplierName";
  11464. //dv.Sort = "AllOrder desc";
  11465. DataTable dtNew = dv.ToTable();
  11466. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11467. }
  11468. public void check_order_desing_info()
  11469. {
  11470. string ctid = GetPostString("ctid");
  11471. if (!string.IsNullOrEmpty(ctid))
  11472. {
  11473. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11474. if (ceErpTradeCell != null)
  11475. {
  11476. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11477. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11478. return;
  11479. }
  11480. returnErrorMsg("找不到订单");
  11481. return;
  11482. }
  11483. returnErrorMsg("找不到订单");
  11484. }
  11485. public void get_timeout_detail()
  11486. {
  11487. string poscode = CurrentUser.UserPost.Post.Code;
  11488. DataStruct dStruct = GetPostStruct();
  11489. List<string> lw = new List<string>();
  11490. string id = GetPostString("id");
  11491. string pay_date1 = GetPostString("pay_date1");
  11492. string pay_date2 = GetPostString("pay_date2");
  11493. int type = GetPostInt("type");
  11494. if (type == 0)
  11495. {
  11496. if (pay_date1.Length > 0)
  11497. {
  11498. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11499. }
  11500. if (pay_date2.Length > 0)
  11501. {
  11502. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11503. }
  11504. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11505. }
  11506. if (type == 1)
  11507. {
  11508. if (pay_date1.Length > 0)
  11509. {
  11510. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11511. }
  11512. if (pay_date2.Length > 0)
  11513. {
  11514. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11515. }
  11516. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11517. }
  11518. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11519. DataTable dt = null;
  11520. dt = WebCache.GetData("view_orderlist", dStruct);
  11521. writeGridDataTableJson(dStruct.TotalCount, dt);
  11522. }
  11523. public void saveUrgentChargePrice()
  11524. {
  11525. string ctid = GetPostString("ctid");
  11526. if (!string.IsNullOrEmpty(ctid))
  11527. {
  11528. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11529. if (ceErpTradeCell != null)
  11530. {
  11531. double price = GetPostDouble("price");
  11532. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11533. if (ceErpTradeCellExtend == null)
  11534. {
  11535. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11536. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11537. }
  11538. ceErpTradeCellExtend.urgentCharge = price;
  11539. if (ceErpTradeCellExtend.ID > 0)
  11540. {
  11541. ceErpTradeCellExtend.Update();
  11542. }
  11543. else
  11544. {
  11545. ceErpTradeCellExtend.Save();
  11546. }
  11547. returnSuccessMsg("修改成功!");
  11548. return;
  11549. }
  11550. returnErrorMsg("找不到订单");
  11551. return;
  11552. }
  11553. returnErrorMsg("找不到订单");
  11554. }
  11555. public void finish_erp_order()
  11556. {
  11557. string ctid = GetPostString("ctid");
  11558. if (!string.IsNullOrEmpty(ctid))
  11559. {
  11560. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11561. {
  11562. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11563. if (ceErpTradeCell != null)
  11564. {
  11565. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11566. ceErpTradeCell.Update();
  11567. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11568. returnSuccessMsg("修改成功!");
  11569. return;
  11570. }
  11571. }
  11572. }
  11573. returnErrorMsg("找不到订单");
  11574. }
  11575. public void get_trade_order_list()
  11576. {
  11577. string tid = GetPostString("tid");
  11578. if (!string.IsNullOrEmpty(tid))
  11579. {
  11580. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11581. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11582. writeGridDataTableJson(data.Rows.Count, data);
  11583. return;
  11584. }
  11585. returnErrorMsg("找不到订单");
  11586. }
  11587. public void save_cell_spu()
  11588. {
  11589. string ctid = GetPostString("ctid");
  11590. string spu_id = GetPostString("spu_id");
  11591. if (!string.IsNullOrEmpty(ctid))
  11592. {
  11593. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11594. if (ceErpTradeCellExtend == null)
  11595. {
  11596. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11597. ceErpTradeCellExtend.ctid = ctid;
  11598. }
  11599. ceErpTradeCellExtend.spu_id = spu_id;
  11600. if (!string.IsNullOrEmpty(spu_id))
  11601. {
  11602. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11603. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  11604. ceErpTradeCellExtend.ToType = result;
  11605. List<int> products = new List<int>() { 13, 2524, 2557, 4, 2554, 57, 19 };
  11606. if (products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  11607. {
  11608. ceErpTradeCellExtend.ToType = "外协";
  11609. }
  11610. }
  11611. if (ceErpTradeCellExtend.ID == 0)
  11612. {
  11613. ceErpTradeCellExtend.Create();
  11614. }
  11615. else
  11616. {
  11617. ceErpTradeCellExtend.Update();
  11618. }
  11619. returnSuccessMsg("修改成功!");
  11620. return;
  11621. }
  11622. returnErrorMsg("找不到订单");
  11623. }
  11624. public void change_express_info()
  11625. {
  11626. string ctid = GetPostString("ctid");
  11627. string transNo = GetPostString("transNo");
  11628. string transCom = GetPostString("transCom");
  11629. if (!string.IsNullOrEmpty(ctid))
  11630. {
  11631. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11632. if (ceErpTradeCellExtend == null)
  11633. {
  11634. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11635. ceErpTradeCellExtend.ctid = ctid;
  11636. }
  11637. ceErpTradeCellExtend.modExpressNo = transNo;
  11638. ceErpTradeCellExtend.modExpressCom = transCom;
  11639. ceErpTradeCellExtend.readMod = 2;
  11640. if (ceErpTradeCellExtend.ID == 0)
  11641. {
  11642. ceErpTradeCellExtend.Create();
  11643. }
  11644. else
  11645. {
  11646. ceErpTradeCellExtend.Update();
  11647. }
  11648. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11649. returnSuccessMsg("修改成功!");
  11650. return;
  11651. }
  11652. returnErrorMsg("找不到订单");
  11653. }
  11654. public void get_change_express_list()
  11655. {
  11656. DataStruct dStruct = GetPostStruct();
  11657. List<string> lw = new List<string>();
  11658. int st = 2;
  11659. string tid = GetPostString("ctid");
  11660. if (tid.Length > 0)
  11661. {
  11662. string select_tid = getTidByCtid(tid);
  11663. lw.Add(string.Format("tid='{0}'", select_tid));
  11664. }
  11665. string shopname = GetPostString("shopname");
  11666. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11667. string buyernick = GetPostString("buyer_nick");
  11668. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11669. string sellermemo = GetPostString("seller_memo");
  11670. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11671. string supplier = GetPostString("supplier");
  11672. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11673. string customer = GetPostString("customer");
  11674. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11675. string design = GetPostString("design");
  11676. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11677. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11678. string poscode = CurrentUser.UserPost.Post.Code;
  11679. if (poscode != "SysAdmin")
  11680. {
  11681. string shopid = CurrentUser.User.pemShop;
  11682. lw.Add(string.Format("shopId in ({0})", shopid));
  11683. }
  11684. lw.Add("readMod = 2");
  11685. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11686. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11687. writeGridDataTableJson(dStruct.TotalCount, dt);
  11688. }
  11689. public void deal_express_complete()
  11690. {
  11691. string ctid = GetPostString("ctid");
  11692. if (!string.IsNullOrEmpty(ctid))
  11693. {
  11694. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11695. if (ceErpTradeCellExtend == null)
  11696. {
  11697. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11698. ceErpTradeCellExtend.ctid = ctid;
  11699. }
  11700. ceErpTradeCellExtend.readMod = 1;
  11701. if (ceErpTradeCellExtend.ID == 0)
  11702. {
  11703. ceErpTradeCellExtend.Create();
  11704. }
  11705. else
  11706. {
  11707. ceErpTradeCellExtend.Update();
  11708. }
  11709. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11710. returnSuccessMsg("修改成功!");
  11711. return;
  11712. }
  11713. returnErrorMsg("找不到订单");
  11714. }
  11715. public void aftersale_return_visit()
  11716. {
  11717. string ctid = GetPostString("ctid");
  11718. if (!string.IsNullOrEmpty(ctid))
  11719. {
  11720. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11721. if (ceErpTradeCellExtend == null)
  11722. {
  11723. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11724. ceErpTradeCellExtend.ctid = ctid;
  11725. }
  11726. ceErpTradeCellExtend.returnVisit = 1;
  11727. if (ceErpTradeCellExtend.ID == 0)
  11728. {
  11729. ceErpTradeCellExtend.Create();
  11730. }
  11731. else
  11732. {
  11733. ceErpTradeCellExtend.Update();
  11734. }
  11735. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11736. if (ceErpTradeAfterSaleExtend != null)
  11737. {
  11738. ceErpTradeAfterSaleExtend.TextResult = "";
  11739. ceErpTradeAfterSaleExtend.Update();
  11740. }
  11741. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11742. returnSuccessMsg("修改成功!");
  11743. return;
  11744. }
  11745. returnErrorMsg("找不到订单");
  11746. }
  11747. public void orderPlaceInfo()
  11748. {
  11749. string ctids = GetPostString("ctids");
  11750. string[] list = ctids.Split(',');
  11751. foreach (string ctid in list)
  11752. {
  11753. CeErpSukuraData.createInfo(ctid, 3);
  11754. }
  11755. StringBuilder sql = new StringBuilder();
  11756. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11757. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11758. designHelper.api_approveDesign(ctids); //approveDesign
  11759. returnSuccessMsg("");
  11760. }
  11761. public void get_issue_list()
  11762. {
  11763. DataStruct dStruct = GetPostStruct();
  11764. List<string> lw = new List<string>();
  11765. int st = 2;
  11766. string tid = GetPostString("ctid");
  11767. if (tid.Length > 0)
  11768. {
  11769. string select_tid = getTidByCtid(tid);
  11770. lw.Add(string.Format("tid='{0}'", select_tid));
  11771. }
  11772. string shopname = GetPostString("shopname");
  11773. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11774. string buyernick = GetPostString("buyer_nick");
  11775. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11776. string sellermemo = GetPostString("seller_memo");
  11777. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11778. string supplier = GetPostString("supplier");
  11779. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11780. string customer = GetPostString("customer");
  11781. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11782. string design = GetPostString("design");
  11783. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11784. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11785. string poscode = CurrentUser.UserPost.Post.Code;
  11786. if (poscode != "SysAdmin")
  11787. {
  11788. string shopid = CurrentUser.User.pemShop;
  11789. lw.Add(string.Format("shopId in ({0})", shopid));
  11790. }
  11791. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11792. {
  11793. lw.Add("IssueState = 1");
  11794. }
  11795. lw.Add("IssueState > 0");
  11796. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11797. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11798. writeGridDataTableJson(dStruct.TotalCount, dt);
  11799. }
  11800. public void saveIssueContent()
  11801. {
  11802. string ctid = GetPostString("ctid");
  11803. if (!string.IsNullOrEmpty(ctid))
  11804. {
  11805. string content = GetPostString("content");
  11806. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11807. if (ceErpTradeAfterSaleExtend == null)
  11808. {
  11809. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11810. ceErpTradeAfterSaleExtend.tid = ctid;
  11811. }
  11812. ceErpTradeAfterSaleExtend.IssueContent = content;
  11813. ceErpTradeAfterSaleExtend.IssueState = 1;
  11814. if (ceErpTradeAfterSaleExtend.ID > 0)
  11815. {
  11816. ceErpTradeAfterSaleExtend.Update();
  11817. }
  11818. else
  11819. {
  11820. ceErpTradeAfterSaleExtend.Create();
  11821. }
  11822. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11823. returnSuccessMsg("添加成功!");
  11824. return;
  11825. }
  11826. returnErrorMsg("找不到订单");
  11827. }
  11828. public void dealIssueContent()
  11829. {
  11830. string ctid = GetPostString("ctid");
  11831. if (!string.IsNullOrEmpty(ctid))
  11832. {
  11833. string content = GetPostString("content");
  11834. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11835. if (ceErpTradeAfterSaleExtend != null)
  11836. {
  11837. ceErpTradeAfterSaleExtend.IssueState = 2;
  11838. ceErpTradeAfterSaleExtend.Update();
  11839. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11840. returnSuccessMsg("修改完成!");
  11841. return;
  11842. }
  11843. }
  11844. returnErrorMsg("找不到订单");
  11845. }
  11846. public void set_tid_attachments()
  11847. {
  11848. string tid = GetPostString("tid");
  11849. string atta = GetPostString("atta");
  11850. if (!string.IsNullOrEmpty(tid))
  11851. {
  11852. if (string.IsNullOrEmpty(atta))
  11853. {
  11854. returnErrorMsg("文件地址为空");
  11855. return;
  11856. }
  11857. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11858. if (ceErpTradeCell != null)
  11859. {
  11860. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11861. if (ceErpTrade == null)
  11862. {
  11863. returnErrorMsg("找不到订单");
  11864. return;
  11865. }
  11866. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11867. bool isSend = false;
  11868. if (dt != null && dt.Rows.Count > 0)
  11869. {
  11870. foreach (DataRow row in dt.Rows)
  11871. {
  11872. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11873. {
  11874. isSend = true;
  11875. }
  11876. }
  11877. if (isSend)
  11878. {
  11879. returnErrorMsg("已发货无法修改");
  11880. return;
  11881. }
  11882. ceErpTrade.Attachments = atta;
  11883. ceErpTrade.Update();
  11884. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11885. returnSuccessMsg("上传成功!");
  11886. return;
  11887. }
  11888. }
  11889. }
  11890. returnErrorMsg("找不到订单");
  11891. }
  11892. public void get_tid_attachments()
  11893. {
  11894. string tid = GetPostString("tid");
  11895. if (!string.IsNullOrEmpty(tid))
  11896. {
  11897. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11898. if (ceErpTradeCell != null)
  11899. {
  11900. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11901. if (ceErpTrade == null)
  11902. {
  11903. returnErrorMsg("找不到订单");
  11904. return;
  11905. }
  11906. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11907. return;
  11908. }
  11909. }
  11910. returnErrorMsg("找不到订单");
  11911. }
  11912. public void check_erp_sameorders()
  11913. {
  11914. if (UrlPostParmsCheck("ctid"))
  11915. {
  11916. string eid = GetPostString("ctid");
  11917. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11918. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11919. if (entity != null && ceErpTrade != null)
  11920. {
  11921. if (entity.OrderState > 6)
  11922. {
  11923. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11924. return;
  11925. }
  11926. StringBuilder sql = new StringBuilder();
  11927. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  11928. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11929. {
  11930. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11931. }
  11932. else
  11933. {
  11934. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11935. }
  11936. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11937. List<string> ids = new List<string>();
  11938. if (dt != null && dt.Rows.Count > 1)
  11939. {
  11940. bool needhe = true;
  11941. foreach (DataRow dr in dt.Rows)
  11942. {
  11943. ids.Add("'" + dr["ctid"] + "'");
  11944. /* //备注有合包
  11945. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11946. {
  11947. needhe = true;
  11948. }
  11949. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11950. {
  11951. needhe = true;
  11952. }
  11953. //顺丰快递
  11954. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11955. {
  11956. needhe = true;
  11957. }*/
  11958. }
  11959. if (!needhe)
  11960. {
  11961. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11962. return;
  11963. }
  11964. sql = new StringBuilder();
  11965. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11966. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11967. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11968. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11969. foreach (DataRow dr in dt.Rows)
  11970. {
  11971. dr["dstate"] = 0;
  11972. dr["dnumber"] = 0;
  11973. foreach (DataRow row in dt1.Rows)
  11974. {
  11975. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  11976. {
  11977. dr["dstate"] = 2;
  11978. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  11979. }
  11980. }
  11981. if (eid.Equals(dr["ctid"].ToString()))
  11982. {
  11983. dr["dstate"] = 1;
  11984. }
  11985. }
  11986. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  11987. return;
  11988. }
  11989. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11990. return;
  11991. }
  11992. returnErrorMsg("未找到订单");
  11993. return;
  11994. }
  11995. returnErrorMsg("缺少必要的参数");
  11996. }
  11997. public void get_mark_number()
  11998. {
  11999. string eid = GetPostString("ctid");
  12000. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12001. if (entity != null)
  12002. {
  12003. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12004. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12005. int current = 1;
  12006. if (ceErpDeliverMark == null)
  12007. {
  12008. StringBuilder sql = new StringBuilder();
  12009. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  12010. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12011. {
  12012. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12013. }
  12014. else
  12015. {
  12016. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12017. }
  12018. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12019. List<string> ids = new List<string>();
  12020. if (dt != null && dt.Rows.Count > 1)
  12021. {
  12022. foreach (DataRow dr in dt.Rows)
  12023. {
  12024. ids.Add("'" + dr["ctid"] + "'");
  12025. }
  12026. //查询已有的编号
  12027. sql = new StringBuilder();
  12028. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12029. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12030. if (dt1 == null || dt1.Rows.Count == 0)
  12031. {
  12032. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12033. List<int> list_number = new List<int>();
  12034. foreach (DataRow row in numbers.Rows)
  12035. {
  12036. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12037. }
  12038. //查询空余编号
  12039. for (int i = 0; i < list_number.Count + 2; i++)
  12040. {
  12041. if (!list_number.Contains(current))
  12042. {
  12043. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12044. //防止查询过程中有新数据生成
  12045. if (ceErpDeliverMark1 == null)
  12046. {
  12047. break;
  12048. }
  12049. }
  12050. current++;
  12051. }
  12052. }
  12053. else
  12054. {
  12055. foreach (DataRow row in dt1.Rows)
  12056. {
  12057. current = Convert.ToInt32(row["markNumber"]);
  12058. }
  12059. }
  12060. ceErpDeliverMark = new CeErpDeliverMark();
  12061. ceErpDeliverMark.ctid = eid;
  12062. ceErpDeliverMark.createtime = DateTime.Now;
  12063. if (ceErpTrade != null)
  12064. {
  12065. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12066. }
  12067. ceErpDeliverMark.markNumber = current;
  12068. ceErpDeliverMark.Create();
  12069. }
  12070. }
  12071. else
  12072. {
  12073. current = ceErpDeliverMark.markNumber;
  12074. }
  12075. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12076. return;
  12077. }
  12078. }
  12079. }
  12080. }