sync.order.cs 636 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760
  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. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\店铺.xlsx");
  56. //apiHelper.Api_SyncOrderByTime("598825");
  57. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  58. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  59. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  60. //banniuApiHelper.sendLogisticsInfo(null);
  61. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  62. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  63. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  64. //int sid = commonHelper.autoDistributeToSupplier(entity);
  65. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  66. //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}");
  67. //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}}");
  68. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  69. List<string> lw = new List<string>();
  70. string tid = GetPostString("ctid");
  71. string date1 = GetPostString("date1");
  72. //12-1 修改
  73. string urgent = GetPostString("urgent");
  74. string back = GetPostString("back");
  75. string offlineSearch = GetPostString("offlineSearch");
  76. int paramsCount = 0;
  77. if (!string.IsNullOrWhiteSpace(urgent))
  78. {
  79. if (urgent.Equals("true"))
  80. {
  81. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  82. }
  83. }
  84. if (!string.IsNullOrWhiteSpace(back))
  85. {
  86. if (back.Equals("true"))
  87. {
  88. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  89. }
  90. }
  91. if (!string.IsNullOrWhiteSpace(offlineSearch))
  92. {
  93. if (offlineSearch.Equals("true"))
  94. {
  95. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  96. }
  97. }
  98. //end
  99. string date2 = GetPostString("date2");
  100. string buyernick = GetPostString("buyer_nick");
  101. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  102. {
  103. if (tid.Length <= 0 && buyernick.Length <= 0)
  104. {
  105. return;
  106. }
  107. }
  108. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  109. {
  110. if (tid.Length > 0)
  111. {
  112. List<string> select_tid = getTidByCtidMore(tid);
  113. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  114. }
  115. if (buyernick.Length > 0)
  116. {
  117. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  118. }
  119. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  120. if (dw.Length > 0)
  121. {
  122. lw.Add(dw);
  123. }
  124. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  125. {
  126. string usershop = CurrentUser.User.pemShop;
  127. lw.Add(string.Format("ShopId in ({0})", usershop));
  128. }
  129. }
  130. else
  131. {
  132. if (ex_psize == 0)
  133. {
  134. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  135. }
  136. if (PKey != "admin")
  137. {
  138. string usershop = CurrentUser.User.pemShop;
  139. lw.Add(string.Format("ShopId in ({0})", usershop));
  140. paramsCount++;
  141. }
  142. }
  143. string uploaddate1 = GetPostString("uploaddate1");
  144. string uploaddate2 = GetPostString("uploaddate2");
  145. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  146. if (update.Length > 0) lw.Add(update);
  147. string deliverydate1 = GetPostString("deliverydate1");
  148. string deliverydate2 = GetPostString("deliverydate2");
  149. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  150. if (deliverydate.Length > 0)
  151. {
  152. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  153. };
  154. string shopname = GetPostString("shopname");
  155. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  156. string addwechat = GetPostString("addwechat");
  157. if (addwechat.Length > 0)
  158. {
  159. int addWt = Convert.ToInt32(addwechat);
  160. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  161. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  162. }
  163. string customer = GetPostString("customer");
  164. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  165. string design = GetPostString("design");
  166. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  167. string orderState = GetPostString("orderState");
  168. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  169. string address = GetPostString("address");
  170. 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));
  171. string sellermemo = GetPostString("seller_memo");
  172. if (sellermemo.Length > 0)
  173. {
  174. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  175. }
  176. string backReason = GetPostString("backReason");
  177. if (backReason.Length > 0)
  178. {
  179. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  180. }
  181. string apdate1 = GetPostString("apdate1");
  182. string apdate2 = GetPostString("apdate2");
  183. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  184. if (dwap.Length > 0) lw.Add(dwap);
  185. string price1 = GetPostString("price1");
  186. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  187. string price2 = GetPostString("price2");
  188. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  189. string isoldcustomer = GetPostString("isoldcus");
  190. string spudata = GetPostString("spudata");
  191. if ("0".Equals(spudata))
  192. {
  193. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  194. }
  195. if ("1".Equals(spudata))
  196. {
  197. lw.Add(string.Format("spu_id <> ''"));
  198. }
  199. string finishdate1 = GetPostString("finishdate1");
  200. string finishdate2 = GetPostString("finishdate2");
  201. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  202. bool isFinish = false;
  203. if (finishdate.Length > 0)
  204. {
  205. lw.Add(finishdate);
  206. isFinish = true;
  207. paramsCount++;
  208. }
  209. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  210. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  211. if (ex_psize > 0)
  212. {
  213. int UserID = CurrentUser.UserID;
  214. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  215. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  216. {
  217. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  218. }
  219. dStruct.Order = "pay_time desc";
  220. }
  221. string isNew = GetPostString("isNew");
  222. if (isNew == "true")
  223. {
  224. lw.Add(string.Format("IsNew = {0}", 1));
  225. }
  226. string overtime = GetPostString("overtime");
  227. if (overtime == "1")
  228. {
  229. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  230. }
  231. String usePost = CurrentUser.UserPost.Post.Code;
  232. if (usePost.Equals("Operation") == true)
  233. {
  234. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  235. }
  236. else
  237. {
  238. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  239. }
  240. //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";
  241. if (dStruct.PageSize == 100000)
  242. {
  243. dStruct.Order = "";
  244. }
  245. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  246. DataTable dt = null;
  247. string tablename = "view_orderlist";
  248. if (isFinish)
  249. {
  250. tablename = "view_orderlist_end";
  251. }
  252. dt = WebCache.GetData(tablename, dStruct);
  253. if (dt != null && dt.Rows.Count > 0)
  254. {
  255. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  256. foreach (DataRow dr in dt.Rows)
  257. {
  258. try
  259. {
  260. if (dr["refund_fees"] != null)
  261. {
  262. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  263. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  264. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  265. if (payment == refund_fees)
  266. {
  267. dr["refund_fees"] = Math.Round(refund_fees, 2);
  268. }
  269. else if (refund_fees == total_fee)
  270. {
  271. dr["refund_fees"] = payment;
  272. }
  273. else
  274. {
  275. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  276. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  277. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  278. }
  279. }
  280. // 对象操作
  281. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  282. ceErpTradeCell.ctid = dr["ctid"].ToString();
  283. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  284. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  285. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  286. if (dStruct.PageSize != 100000)
  287. {
  288. if (dr["DispatchSort"].ToString() == "2")
  289. {
  290. dr["gongchuang"] = 200;
  291. }
  292. else if ("外协".Equals(dr["ToType"].ToString()))
  293. {
  294. dr["gongchuang"] = 200;
  295. }
  296. else if ("内部".Equals(dr["ToType"].ToString()))
  297. {
  298. dr["gongchuang"] = -1;
  299. }
  300. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  301. {
  302. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  303. dr["gongchuang"] = response.code;
  304. }
  305. }
  306. }
  307. catch (NullReferenceException ex)
  308. {
  309. // 处理空引用异常
  310. dr["refund_fees"] = "0.00";
  311. }
  312. }
  313. }
  314. writeGridDataTableJson(dStruct.TotalCount, dt);
  315. }
  316. public void get_erp_orderlist_sumprice()
  317. {
  318. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  319. return;
  320. List<string> lw = new List<string>();
  321. string tid = GetPostString("ctid");
  322. string date1 = GetPostString("date1");
  323. string date2 = GetPostString("date2");
  324. if (tid.Length > 0 || date1.Length > 0)
  325. {
  326. lw.Add(string.Format("ctid like '%{0}%'", tid));
  327. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  328. if (dw.Length > 0) lw.Add(dw);
  329. }
  330. else
  331. {
  332. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  333. }
  334. string shopname = GetPostString("shopname");
  335. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  336. string buyernick = GetPostString("buyer_nick");
  337. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  338. string customer = GetPostString("customer");
  339. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  340. string design = GetPostString("design");
  341. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  342. string orderState = GetPostString("orderState");
  343. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  344. string address = GetPostString("address");
  345. 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));
  346. string sellermemo = GetPostString("seller_memo");
  347. if (sellermemo.Length > 0)
  348. {
  349. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  350. }
  351. string apdate1 = GetPostString("apdate1");
  352. string apdate2 = GetPostString("apdate2");
  353. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  354. if (dwap.Length > 0) lw.Add(dwap);
  355. string price1 = GetPostString("price1");
  356. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  357. string price2 = GetPostString("price2");
  358. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  359. string isoldcustomer = GetPostString("isoldcus");
  360. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  361. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  362. if (PKey != "admin")
  363. {
  364. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  365. lw.Add(string.Format("shopId in ({0})", usershop));
  366. }
  367. //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";
  368. string mainWhere = string.Join(" and ", lw.ToArray());
  369. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  370. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  371. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  372. decimal total = 0;
  373. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  374. {
  375. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  376. }
  377. var res = new
  378. {
  379. data = total
  380. };
  381. string ro_jsond = JsonConvert.SerializeObject(res);
  382. returnSuccess(ro_jsond);
  383. return;
  384. }
  385. public void get_erp_CustomerServiceGather()
  386. {
  387. string userWhere = "", orderWhere = "";
  388. List<string> lw = new List<string>();
  389. string customer = GetPostString("customer");
  390. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  391. string shopname = GetPostString("shopname");
  392. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  393. string date1 = GetPostString("date1");
  394. string date2 = GetPostString("date2");
  395. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  396. if (dw.Length > 0) lw.Add(dw);
  397. orderWhere = string.Join(" and ", lw.ToArray());
  398. 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 " +
  399. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  400. "left join " +
  401. "( " +
  402. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  403. ") as b on a.ID = b.CustomerUserId " +
  404. "left join " +
  405. "( " +
  406. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  407. ") as d on a.ID = d.CustomerUserId " +
  408. "left join " +
  409. "( " +
  410. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  411. ") as e on a.ID = e.CustomerUserId " +
  412. "left join " +
  413. "( " +
  414. " select CustomerUserId, RefundCount, RefundSum from " +
  415. " ( " +
  416. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  417. " from CE_ErpTradeRefund a " +
  418. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  419. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  420. " group by CustomerUserId " +
  421. " ) as a " +
  422. ") as f on a.ID = f.CustomerUserId " +
  423. "where a.PostCode = 'CustomerService'",
  424. userWhere, orderWhere);
  425. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  426. writeGridDataTableJson(dt.Rows.Count, dt);
  427. //writeGridDataTableJson(dt.Rows.Count, dt);
  428. }
  429. //设计汇总
  430. public void get_erp_DesignerGather()
  431. {
  432. string userWhere = "", orderWhere = "";
  433. List<string> lw = new List<string>();
  434. string Designer = GetPostString("designer");
  435. int org = GetPostInt("org");
  436. if (Designer.Length > 0)
  437. {
  438. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  439. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  440. }
  441. else if (org > 0)
  442. {
  443. userWhere = string.Format(" where OrgID ={0}", org);
  444. }
  445. string shopname = GetPostString("shopname");
  446. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  447. string state = GetPostString("state");
  448. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  449. string OrderArea = GetPostString("order_area");
  450. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  451. string date1 = GetPostString("date1");
  452. string date2 = GetPostString("date2");
  453. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  454. if (dw.Length > 0) lw.Add(dw);
  455. string UpDate1 = GetPostString("UpDate1");
  456. string UpDate2 = GetPostString("UpDate2");
  457. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  458. if (dw.Length > 0) lw.Add(dw);
  459. orderWhere = string.Join(" and ", lw.ToArray());
  460. 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 (" +
  461. "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 " +
  462. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  463. "left join " +
  464. "( " +
  465. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  466. ") as b on a.ID = b.DesignUserId " +
  467. "left join " +
  468. "( " +
  469. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  470. ") as d on a.ID = d.DesignUserId " +
  471. "left join " +
  472. "( " +
  473. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  474. ") as e on a.ID = e.DesignUserId " +
  475. "left join " +
  476. "( " +
  477. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  478. ") as g on a.ID = g.DesignUserId " +
  479. "left join " +
  480. "( " +
  481. " select CustomerUserId, RefundCount, RefundSum from " +
  482. " ( " +
  483. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  484. " from CE_ErpTradeRefund a " +
  485. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  486. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  487. " group by CustomerUserId " +
  488. " ) as a " +
  489. ") as f on a.ID = f.CustomerUserId " +
  490. "where a.PostCode = 'Designer') as z",
  491. userWhere, orderWhere);
  492. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  493. writeGridDataTableJson(dt.Rows.Count, dt);
  494. }
  495. //删除tradecell的订单
  496. public void del_erp_cellorder()
  497. {
  498. if (UrlPostParmsCheck("ctid"))
  499. {
  500. string eid = GetPostString("ctid");
  501. CeErpTradeCell.DelByCtid(eid);
  502. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  503. returnSuccessMsg("删除成功");
  504. }
  505. }
  506. public void clear_erp_refundstate()
  507. {
  508. if (UrlPostParmsCheck("ids"))
  509. {
  510. string eids = GetPostString("ids");
  511. string[] ctidList = eids.Split(',');
  512. foreach (string ctid in ctidList)
  513. {
  514. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  515. if (entity != null)
  516. {
  517. entity.IsRefund = 0;
  518. entity.Update();
  519. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  520. }
  521. else
  522. continue;
  523. }
  524. returnSuccessMsg("操作成功");
  525. return;
  526. }
  527. returnErrorMsg("缺少必要参数");
  528. }
  529. public void set_erp_urgency()
  530. {
  531. if (UrlPostParmsCheck("ctid"))
  532. {
  533. string eid = GetPostString("ctid");
  534. CeErpTradeCell entity = null;
  535. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  536. if (entity != null)
  537. {
  538. double prices = commonHelper.calculationPrice(entity);
  539. if (prices <= 100)
  540. {
  541. returnErrorMsg("此订单金额不足100元,无法加急。");
  542. return;
  543. }
  544. string utime = GetPostString("urgencytime");
  545. if (utime.Length > 0)
  546. {
  547. entity.UrgencyTime = Convert.ToDateTime(utime);
  548. }
  549. else
  550. {
  551. returnErrorMsg("请选择加急时间");
  552. return;
  553. }
  554. if (entity.OrderState <= 4)
  555. {
  556. //entity.seller_memo = entity.seller_memo + "-加急";
  557. string smemo = entity.seller_memo;
  558. int kindex = smemo.IndexOf(")");
  559. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  560. if (lastoneStr != "-")
  561. {
  562. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  563. }
  564. string prememo = smemo.Substring(0, kindex + 2);
  565. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  566. int lastkindex = lastmemo.IndexOf("(");
  567. DateTime urgtime = Convert.ToDateTime(utime);
  568. string newlastmemo = "";
  569. if (lastkindex == 0)
  570. {
  571. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  572. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  573. }
  574. else
  575. {
  576. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  577. }
  578. entity.seller_memo = prememo + newlastmemo;
  579. }
  580. entity.IsUrgency = true;
  581. entity.UpdateTime = DateTime.Now;
  582. entity.Update();
  583. ApiVo apiVo = new ApiVo();
  584. apiVo.orderNumber = entity.ctid;
  585. apiVo.actionName = "changeDesign";
  586. apiVo.orderRemarks = entity.seller_memo;
  587. apiVo.remarkSign = 3;
  588. designHelper.API_WorkCore(apiVo); //changeDesign
  589. CeErpSukuraData.createInfo(entity.ctid, 7);
  590. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  591. returnSuccessMsg("设置成功!");
  592. return;
  593. }
  594. returnErrorMsg("找不到记录");
  595. }
  596. }
  597. public void set_erp_reset()
  598. {
  599. if (UrlPostParmsCheck("ctid"))
  600. {
  601. string eid = GetPostString("ctid");
  602. CeErpTradeCell entity = null;
  603. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  604. if (entity != null)
  605. {
  606. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  607. {
  608. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  609. {
  610. returnErrorMsg("财务要求已下单已发货无法重置");
  611. return;
  612. }
  613. }
  614. entity.IsUrgency = false;
  615. entity.seller_memo = "";
  616. entity.OtherMemo = "";
  617. entity.OrderState = 0;
  618. entity.IsReturn = 0;
  619. //entity.IsRefund = 0;
  620. entity.MemoOpt = 0;
  621. entity.AfterSaleState = 0;
  622. entity.AfterSaleResponsible = "";
  623. entity.AfterSaleUserId = 0;
  624. entity.IsNeedBill = 0;
  625. entity.CustomerUserId = 0;
  626. entity.DesignUserId = 0;
  627. entity.SupplierId = 0;
  628. entity.PlaceUserId = 0;
  629. entity.ptid = "";
  630. entity.IsSample = 0;
  631. entity.IsXianHuo = 0;
  632. entity.isDianziOrder = 0;
  633. entity.DispatchSort = 0;
  634. entity.FinishPlaceTime = null;
  635. entity.Update();
  636. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  637. if (trade != null)
  638. {
  639. trade.seller_memo = "";
  640. trade.Update();
  641. }
  642. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  643. returnSuccessMsg("重置成功!");
  644. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  645. if (desginBill != null)
  646. {
  647. desginBill.isDel = 1;
  648. desginBill.Update();
  649. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  650. }
  651. ApiVo apiVo = new ApiVo();
  652. apiVo.orderNumber = entity.ctid;
  653. apiVo.actionName = "resetDesign";
  654. designHelper.API_WorkCore(apiVo);//resetDesign
  655. return;
  656. }
  657. returnErrorMsg("找不到记录");
  658. }
  659. }
  660. public void save_erp_sellermemo()
  661. {
  662. if (UrlPostParmsCheck("ctid"))
  663. {
  664. string ctid = GetPostString("ctid");
  665. CeErpTradeCell entity = null;
  666. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  667. if (entity != null)
  668. {
  669. string memo = GetPostString("seller_memo");
  670. memo = memo.Replace(" ", "");
  671. if (memo.Contains("补差"))
  672. {
  673. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  674. return;
  675. }
  676. List<string> bitList = new List<string>
  677. {
  678. "\\","/",":","*","?", "\"","<" ,">","|"
  679. };
  680. bool isIn = false;
  681. foreach (string bit in bitList)
  682. {
  683. if (memo.Contains(bit))
  684. {
  685. isIn = true;
  686. }
  687. }
  688. if (isIn)
  689. {
  690. returnErrorMsg("不能使用 一些符合作为文件名");
  691. return;
  692. }
  693. if (entity.seller_memo != memo)
  694. {
  695. if (entity.IsSample == 2)
  696. {
  697. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  698. return;
  699. }
  700. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  701. {
  702. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  703. {
  704. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  705. return;
  706. }
  707. /*if (CurrentUser.UserPost.Post.Code != "Place")
  708. {
  709. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  710. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  711. {
  712. returnErrorMsg("售前系统订单无法再此修改!");
  713. return;
  714. }
  715. }*/
  716. }
  717. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  718. }
  719. commonHelper.getCytPrice(entity);
  720. int memoopt = GetPostInt("MemoOpt");
  721. Boolean ismemoopt = false;
  722. if (memoopt > 0)
  723. {
  724. string stropt = "";
  725. if (memoopt == 1)
  726. {
  727. stropt = "“改稿”";
  728. ismemoopt = true;
  729. }
  730. else if (memoopt == 2)
  731. {
  732. stropt = "“定稿”";
  733. }
  734. else if (memoopt == 3)
  735. {
  736. stropt = "“查货”";
  737. CeErpSukuraData.createInfo(entity.ctid, 6);
  738. }
  739. entity.MemoOpt = Convert.ToInt32(memoopt);
  740. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  741. }
  742. if (entity.OrderState < 5)
  743. {
  744. memo = memo.Replace("(", "(");
  745. memo = memo.Replace(")", ")");
  746. }
  747. if (entity.OrderState < 3)
  748. {
  749. entity.DispatchSort = 0;
  750. }
  751. entity.seller_memo = memo;
  752. entity.UpdateTime = DateTime.Now;
  753. entity.Update();
  754. ApiVo apiVo = new ApiVo();
  755. apiVo.orderNumber = entity.ctid;
  756. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  757. apiVo.orderRemarks = memo;
  758. apiVo.remarkSign = memoopt;
  759. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  760. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  761. returnSuccessMsg("保存成功!");
  762. return;
  763. }
  764. returnErrorMsg("找不到记录");
  765. }
  766. }
  767. public void ins_erp_checkorder()
  768. {
  769. if (UrlPostParmsCheck("ctid"))
  770. {
  771. string ctid = GetPostString("ctid");
  772. CeErpTradeCell entity = null;
  773. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  774. if (entity != null)
  775. {
  776. if (entity.OrderState < 6)
  777. {
  778. returnErrorMsg("下单完成后才可查货");
  779. return;
  780. }
  781. /*if (entity.OrderState > 6)
  782. {
  783. returnErrorMsg("订单已发货");
  784. return;
  785. }*/
  786. if (entity.FinishPlaceTime != null)
  787. {
  788. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  789. {
  790. returnErrorMsg("下单时间不足,无法查货");
  791. return;
  792. }
  793. }
  794. entity.MemoOpt = 3;
  795. entity.CheckOrderTime = DateTime.Now;
  796. entity.UpdateTime = DateTime.Now;
  797. entity.Update();
  798. CeErpSukuraData.createInfo(entity.ctid, 6);
  799. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  800. returnSuccessMsg("操作成功!");
  801. return;
  802. }
  803. returnErrorMsg("找不到记录");
  804. }
  805. }
  806. public void save_erp_othermemo()
  807. {
  808. if (UrlPostParmsCheck("ctid"))
  809. {
  810. string ctid = GetPostString("ctid");
  811. CeErpTradeCell entity = null;
  812. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  813. if (entity != null)
  814. {
  815. entity.OtherMemo = GetPostString("otherMemo");
  816. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  817. {
  818. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  819. StringBuilder sql = new StringBuilder();
  820. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  821. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  822. if (dt != null && dt.Rows.Count > 0)
  823. {
  824. foreach (DataRow dr in dt.Rows)
  825. {
  826. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  827. {
  828. //品类一直
  829. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  830. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  831. if (ceErpSampleCustomer == null)
  832. {
  833. ceErpSampleCustomer = new CeErpSampleCustomer();
  834. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  835. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  836. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  837. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  838. ceErpSampleCustomer.shopId = entity.ShopId;
  839. }
  840. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  841. ceErpSampleCustomer.lastTid = entity.tid;
  842. if (ceErpSampleCustomer.ID > 0)
  843. {
  844. ceErpSampleCustomer.Update();
  845. }
  846. else
  847. {
  848. ceErpSampleCustomer.Create();
  849. }
  850. }
  851. }
  852. }
  853. }
  854. //if (entity.IsOldCustomer == 1)
  855. //{
  856. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  857. //{
  858. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  859. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  860. //}
  861. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  862. //{
  863. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  864. // {
  865. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  866. // {
  867. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  868. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  869. // }
  870. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  871. // {
  872. // entity.OrderState = 2;
  873. // entity.DesignUserId = 0;
  874. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  875. // }
  876. // else
  877. // {
  878. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  879. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  880. // }
  881. // }
  882. //}
  883. //}
  884. entity.UpdateTime = DateTime.Now;
  885. entity.Update();
  886. returnSuccessMsg("保存成功!");
  887. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  888. return;
  889. }
  890. returnErrorMsg("找不到记录");
  891. }
  892. }
  893. public void save_erp_customermemo()
  894. {
  895. if (UrlPostParmsCheck("ctid"))
  896. {
  897. string ctid = GetPostString("ctid");
  898. CeErpTradeCell entity = null;
  899. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  900. if (entity != null)
  901. {
  902. entity.UpdateTime = DateTime.Now;
  903. entity.CustomerMemo = GetPostString("CustomerMemo");
  904. entity.Update();
  905. ApiVo apiVo = new ApiVo();
  906. apiVo.orderNumber = entity.ctid;
  907. apiVo.actionName = "followRemarks";
  908. apiVo.orderRemarks = entity.CustomerMemo;
  909. designHelper.API_WorkCore(apiVo);//followRemarks
  910. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  911. returnSuccessMsg("保存成功!");
  912. return;
  913. }
  914. returnErrorMsg("找不到记录");
  915. }
  916. }
  917. public void upd_erp_addmemotag()
  918. {
  919. if (UrlPostParmsCheck("ctid"))
  920. {
  921. ;
  922. string eid = GetPostString("ctid");
  923. string sfTagstr = GetPostString("memotag");
  924. CeErpTradeCell entity = null;
  925. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  926. if (entity != null)
  927. {
  928. ApiVo apiVo = new ApiVo();
  929. if (entity.OrderState == 0)
  930. {
  931. returnErrorMsg("请先领单");
  932. return;
  933. }
  934. //撤销顺丰
  935. if (sfTagstr == "撤销顺丰")
  936. {
  937. entity.IsSF = 0;
  938. string reMsg = "";
  939. string oldmemo = entity.seller_memo;
  940. if (entity.OrderState < 5)
  941. {
  942. oldmemo = oldmemo.Replace("顺丰到付", "");
  943. oldmemo = oldmemo.Replace("顺丰寄付", "");
  944. entity.seller_memo = oldmemo;
  945. }
  946. else
  947. {
  948. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  949. {
  950. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  951. }
  952. }
  953. entity.Update();
  954. apiVo.orderNumber = entity.ctid;
  955. apiVo.actionName = "orderRemarks";
  956. apiVo.orderRemarks = entity.seller_memo;
  957. apiVo.isSf = entity.IsSF.ToString();
  958. designHelper.API_WorkCore(apiVo);//orderRemarks
  959. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  960. returnSuccessMsg("撤销成功!" + reMsg);
  961. return;
  962. }
  963. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  964. {
  965. //string oldmemo = entity.seller_memo;
  966. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  967. string sfStr = GetPostString("memotag");
  968. string smemo = entity.seller_memo;
  969. int kindex = smemo.IndexOf(")");
  970. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  971. if (lastoneStr != "-")
  972. {
  973. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  974. }
  975. string prememo = smemo.Substring(0, kindex + 2);
  976. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  977. int lastkindex = lastmemo.IndexOf("(");
  978. string newlastmemo = "";
  979. if (lastkindex == 0)
  980. {
  981. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  982. newlastmemo = "(" + sfStr + "." + useLastmemo;
  983. }
  984. else
  985. {
  986. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  987. }
  988. entity.seller_memo = prememo + newlastmemo;
  989. }
  990. string sfTagMSg = "";
  991. if (sfTagstr == "顺丰寄付")
  992. {
  993. entity.IsSF = 1;
  994. sfTagMSg = "顺丰寄付";
  995. }
  996. else if (sfTagstr == "顺丰到付")
  997. {
  998. entity.IsSF = 2;
  999. sfTagMSg = "顺丰到付";
  1000. }
  1001. entity.Update();
  1002. apiVo = new ApiVo();
  1003. apiVo.orderNumber = entity.ctid;
  1004. apiVo.actionName = "orderRemarks";
  1005. apiVo.orderRemarks = entity.seller_memo;
  1006. apiVo.isSf = entity.IsSF.ToString();
  1007. designHelper.API_WorkCore(apiVo);//orderRemarks
  1008. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1009. returnSuccessMsg("标记成功!");
  1010. return;
  1011. }
  1012. returnErrorMsg("找不到记录");
  1013. }
  1014. }
  1015. public void upd_erp_ordertag()
  1016. {
  1017. if (UrlPostParmsCheck("ctid"))
  1018. {
  1019. string eid = GetPostString("ctid");
  1020. CeErpTradeCell entity = null;
  1021. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1022. if (entity != null)
  1023. {
  1024. int tag = GetPostInt("wechattag");
  1025. //if(tag==4 && entity.IsSample == 2)
  1026. //{
  1027. // returnErrorMsg("补差价单不能标记微信单");
  1028. // return;
  1029. //}
  1030. entity.wechatTag = tag;
  1031. entity.Update();
  1032. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1033. if (tag == 1)
  1034. {
  1035. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1036. if (cash == null)
  1037. {
  1038. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1039. cash = new CeErpReturnCash();
  1040. cash.tid = entity.tid;
  1041. cash.seller_nick = main.seller_nick;
  1042. cash.payment = trade.payment;
  1043. cash.buyer_nick = main.buyer_nick;
  1044. cash.cashstate = 0;
  1045. cash.rtype = "微信返现";
  1046. cash.returnprice = 0;
  1047. cash.created = DateTime.Now;
  1048. cash.con = "订单标记微信单";
  1049. cash.img = "";
  1050. cash.applyuserid = CurrentUser.UserID;
  1051. cash.Create();
  1052. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1053. }
  1054. else
  1055. {
  1056. cash.cashstate = 0;
  1057. cash.Update();
  1058. }
  1059. CeErpSukuraData.createInfo(entity.ctid, 9);
  1060. }
  1061. else if (tag == 2)
  1062. {
  1063. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1064. if (cash == null)
  1065. {
  1066. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1067. cash = new CeErpReturnCash();
  1068. cash.tid = entity.tid;
  1069. cash.seller_nick = main.seller_nick;
  1070. cash.payment = trade.payment;
  1071. cash.buyer_nick = main.buyer_nick;
  1072. cash.cashstate = 0;
  1073. cash.rtype = "推购返现";
  1074. cash.returnprice = 5;
  1075. cash.created = DateTime.Now;
  1076. cash.con = "订单标记推购单";
  1077. cash.img = "";
  1078. cash.applyuserid = CurrentUser.UserID;
  1079. cash.Create();
  1080. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1081. }
  1082. else
  1083. {
  1084. cash.cashstate = 0;
  1085. cash.Update();
  1086. }
  1087. CeErpSukuraData.createInfo(entity.ctid, 9);
  1088. }
  1089. else if (tag == 3)
  1090. {
  1091. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1092. if (pers == null)
  1093. {
  1094. pers = new CeErpPersuade();
  1095. pers.ctid = entity.ctid;
  1096. pers.pstate = 0;
  1097. pers.created = DateTime.Now;
  1098. pers.applyuserid = CurrentUser.UserID;
  1099. pers.Create();
  1100. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1101. }
  1102. else
  1103. {
  1104. pers.pstate = 0;
  1105. pers.Update();
  1106. }
  1107. }
  1108. else if (tag == 4 || tag == 5)
  1109. {
  1110. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1111. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1112. if (pers == null)
  1113. {
  1114. pers = new CeErpStayGoods();
  1115. pers.t_id = entity.tid;
  1116. pers.status = "待审核";
  1117. pers.audit_type = 0;
  1118. if (tag == 4)
  1119. {
  1120. pers.stay_type = "微信推购";
  1121. }
  1122. else
  1123. {
  1124. pers.stay_type = "旺旺推购";
  1125. }
  1126. if (entity.IsXianHuo == 0)
  1127. {
  1128. pers.product_id = entity.ProductId;
  1129. }
  1130. pers.wangwang = main.buyer_nick;
  1131. pers.shop_name = main.seller_nick;
  1132. pers.creata_time = DateTime.Now;
  1133. pers.create_u_id = CurrentUser.UserID;
  1134. pers.create_u_name = CurrentUser.UserName;
  1135. pers.Create();
  1136. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1137. }
  1138. else
  1139. {
  1140. pers.audit_type = 0;
  1141. pers.Update();
  1142. }
  1143. CeErpSukuraData.createInfo(entity.ctid, 10);
  1144. }
  1145. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1146. returnSuccessMsg("标记成功!");
  1147. return;
  1148. }
  1149. returnErrorMsg("找不到记录");
  1150. }
  1151. }
  1152. public void upd_erp_ordertag_cancel()
  1153. {
  1154. if (UrlPostParmsCheck("ctid"))
  1155. {
  1156. string eid = GetPostString("ctid");
  1157. CeErpTradeCell entity = null;
  1158. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1159. if (entity != null)
  1160. {
  1161. entity.wechatTag = 0;
  1162. entity.Update();
  1163. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1164. if (pers != null)
  1165. {
  1166. pers.status = "取消推购";
  1167. pers.audit_type = 3;
  1168. pers.Update();
  1169. }
  1170. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1171. returnSuccessMsg("标记成功!");
  1172. return;
  1173. }
  1174. returnErrorMsg("找不到记录");
  1175. }
  1176. }
  1177. public void upd_erp_addweichattag()
  1178. {
  1179. if (UrlPostParmsCheck("ctid"))
  1180. {
  1181. ;
  1182. string eid = GetPostString("ctid");
  1183. CeErpTradeCell entity = null;
  1184. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1185. if (entity != null)
  1186. {
  1187. if (entity.IsAddWechat > 0)
  1188. {
  1189. returnErrorMsg("此单已经标记过了");
  1190. return;
  1191. }
  1192. 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);
  1193. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1194. if (dt.Rows.Count > 0)
  1195. {
  1196. entity.IsAddWechat = 2;
  1197. }
  1198. else
  1199. {
  1200. entity.IsAddWechat = 1;
  1201. }
  1202. entity.Update();
  1203. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1204. returnSuccessMsg("标记成功!");
  1205. return;
  1206. }
  1207. returnErrorMsg("找不到记录");
  1208. }
  1209. }
  1210. public void upd_erp_getmyorder()
  1211. {
  1212. if (UrlPostParmsCheck("ctid"))
  1213. {
  1214. ;
  1215. string eid = GetPostString("ctid");
  1216. CeErpTradeCell entity = null;
  1217. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1218. if (entity != null)
  1219. {
  1220. if (entity.ctid.IndexOf("C") != -1)
  1221. {
  1222. StringBuilder sql = new StringBuilder();
  1223. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1224. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1225. if (dt.Rows.Count > 0)
  1226. {
  1227. decimal total = 0;
  1228. foreach (DataRow dr in dt.Rows)
  1229. {
  1230. total += Convert.ToDecimal(dr["payment"]);
  1231. }
  1232. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1233. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1234. {
  1235. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1236. return;
  1237. }
  1238. }
  1239. }
  1240. if (entity.OrderState == -1)
  1241. {
  1242. returnErrorMsg("待审核订单无法领取!");
  1243. return;
  1244. }
  1245. entity.CustomerUserId = CurrentUser.UserID;
  1246. if (entity.OrderState < 2)
  1247. {
  1248. entity.OrderState = 2;
  1249. if (entity.ShopId != 0)
  1250. {
  1251. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1252. }
  1253. }
  1254. entity.UpdateTime = DateTime.Now;
  1255. entity.Update();
  1256. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1257. returnSuccessMsg("领单成功!");
  1258. return;
  1259. }
  1260. returnErrorMsg("找不到记录");
  1261. }
  1262. }
  1263. public void getmyorder_from_init()
  1264. {
  1265. if (UrlPostParmsCheck("ctid"))
  1266. {
  1267. string eid = GetPostString("ctid");
  1268. CeErpTradeCell entity = null;
  1269. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1270. if (entity != null)
  1271. {
  1272. string sellerMemo = GetPostString("sellerMemo");
  1273. if (sellerMemo.Length > 0)
  1274. {
  1275. entity.seller_memo = sellerMemo;
  1276. }
  1277. string oterhMemo = GetPostString("otherMemo");
  1278. if (oterhMemo.Length > 0)
  1279. {
  1280. entity.OtherMemo = oterhMemo;
  1281. }
  1282. int urg = GetPostInt("urgency");
  1283. entity.IsUrgency = (urg == 1 ? true : false);
  1284. int wechat = GetPostInt("wechat");
  1285. int command = GetPostInt("command");
  1286. if (wechat == 1)
  1287. {
  1288. entity.wechatTag = 1;
  1289. }
  1290. if (command == 1)
  1291. {
  1292. entity.wechatTag = 2;
  1293. }
  1294. string pPro = GetPostString("pprofession");
  1295. if (pPro.Length > 0)
  1296. {
  1297. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1298. string spro = GetPostString("profession");
  1299. if (spro.Length > 0)
  1300. {
  1301. entity.ProfessionId = Convert.ToInt32(spro);
  1302. }
  1303. }
  1304. string proId = GetPostString("productId");
  1305. if (proId.Length > 0)
  1306. {
  1307. entity.ProductId = Convert.ToInt32(proId);
  1308. }
  1309. entity.Material = GetPostString("material");
  1310. entity.Craft = GetPostString("craft");
  1311. entity.CustomerUserId = CurrentUser.UserID;
  1312. if (entity.OrderState < 2)
  1313. {
  1314. entity.OrderState = 2;
  1315. if (entity.ShopId != 0)
  1316. {
  1317. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1318. }
  1319. }
  1320. entity.Update();
  1321. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1322. returnSuccessMsg("领单成功!");
  1323. return;
  1324. }
  1325. returnErrorMsg("找不到记录");
  1326. }
  1327. }
  1328. public void upd_erp_setrelationorder()
  1329. {
  1330. if (UrlPostParmsCheck("ctid"))
  1331. {
  1332. ;
  1333. string eid = GetPostString("ctid");
  1334. string ftid = GetPostString("ftid");
  1335. CeErpTradeCell entity = null;
  1336. CeErpTradeCell fentity = null;
  1337. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1338. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1339. if (fentity == null)
  1340. {
  1341. returnErrorMsg("找不到关联的主订单");
  1342. return;
  1343. }
  1344. if (entity != null)
  1345. {
  1346. if (entity.OrderState >= 5)
  1347. {
  1348. returnErrorMsg("本单已经设计完成无法关联");
  1349. return;
  1350. }
  1351. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1352. {
  1353. returnErrorMsg("线下单续审核后才能关联!");
  1354. return;
  1355. }
  1356. entity.ptid = ftid;
  1357. entity.OrderState = fentity.OrderState;
  1358. //entity.status = fentity.status;
  1359. entity.CustomerUserId = fentity.CustomerUserId;
  1360. entity.DesignUserId = fentity.DesignUserId;
  1361. entity.seller_memo = "补差价单:" + ftid;
  1362. entity.IsSample = 2;
  1363. entity.Update();
  1364. ApiVo apiVo = new ApiVo();
  1365. apiVo.orderNumber = ftid;
  1366. apiVo.payment = entity.payment;
  1367. apiVo.actionName = "repairDesign";
  1368. designHelper.API_WorkCore(apiVo);//repairDesign
  1369. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1370. returnSuccessMsg("关联成功!");
  1371. return;
  1372. }
  1373. else
  1374. returnErrorMsg("找不到记录");
  1375. }
  1376. }
  1377. public void download_erp_neworder()
  1378. {
  1379. string seller = GetPostString("seller_nick");
  1380. string tid = GetPostString("tid");
  1381. if (seller.Length <= 0 || tid.Length <= 0)
  1382. {
  1383. returnErrorMsg("数据错误");
  1384. }
  1385. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1386. //{
  1387. // returnErrorMsg("找不到店铺Sessionkey");
  1388. //}
  1389. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1390. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1391. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1392. if (res.IndexOf("refOid") == -1)
  1393. {
  1394. returnErrorMsg("下载订单数据失败");
  1395. return;
  1396. }
  1397. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1398. returnSuccessMsg("下载完成");
  1399. //tmcHelper.createNewOrder(res);
  1400. //CeErpTrade entr = null;
  1401. //entr = CeErpTrade.Get(tid);
  1402. //if (entr != null)
  1403. //{
  1404. // returnSuccess("下载成功");
  1405. // //下载成功之后,Cell表生成对应的订单;
  1406. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1407. //}
  1408. //else
  1409. //{
  1410. // returnErrorMsg("下载失败或者创建订单失败");
  1411. //}
  1412. }
  1413. public void set_erp_atersale()
  1414. {
  1415. if (UrlPostParmsCheck("ctid"))
  1416. {
  1417. string eid = GetPostString("ctid");
  1418. string reason = GetPostString("AfterSaleReason");
  1419. CeErpTradeCell entity = null;
  1420. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1421. if (entity != null)
  1422. {
  1423. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1424. {
  1425. returnErrorMsg("此订单已经在售后");
  1426. return;
  1427. }
  1428. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1429. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1430. entity.AfterSaleTime = DateTime.Now;
  1431. entity.Update();
  1432. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1433. returnSuccessMsg("转售后成功!");
  1434. return;
  1435. }
  1436. returnErrorMsg("找不到记录");
  1437. }
  1438. }
  1439. public void set_erp_withdraw()
  1440. {
  1441. if (UrlPostParmsCheck("ctid"))
  1442. {
  1443. try
  1444. {
  1445. string eid = GetPostString("ctid");//商品id
  1446. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1447. CeWithdraw ceWithdrawSelect = null;
  1448. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1449. if (ceWithdrawSelect != null)
  1450. {
  1451. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1452. {
  1453. ceWithdrawSelect.status = -1;
  1454. ceWithdrawSelect.Update();
  1455. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1456. returnSuccessMsg("重新发起审核成功");
  1457. return;
  1458. }
  1459. else
  1460. {
  1461. returnSuccessMsg("请勿重复申请!");
  1462. return;
  1463. }
  1464. }
  1465. else
  1466. {
  1467. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1468. if (string.IsNullOrEmpty(CustomerUserId))
  1469. {
  1470. CustomerUserId = "-1";
  1471. }
  1472. int Userid = CurrentUser.UserID;//用户id
  1473. CeWithdraw ceWithdraw = new CeWithdraw();
  1474. ceWithdraw.tid = eid;
  1475. ceWithdraw.userid = Userid;
  1476. ceWithdraw.providerid = CustomerUserId;
  1477. ceWithdraw.status = 3;
  1478. ceWithdraw.creationtime = DateTime.Now;
  1479. ceWithdraw.Create();
  1480. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1481. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1482. return;
  1483. }
  1484. }
  1485. catch
  1486. {
  1487. returnErrorMsg("申请撤回订单失败");
  1488. return;
  1489. }
  1490. }
  1491. }
  1492. public void ins_erp_billinfo()
  1493. {
  1494. if (UrlPostParmsCheck("ctid"))
  1495. {
  1496. string eid = GetPostString("ctid");
  1497. CeErpTradeCell entity = null;
  1498. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1499. if (entity != null)
  1500. {
  1501. CeErpBill bill = CeErpBill.GetByTid(eid);
  1502. bool isHave = false;
  1503. if (bill != null)
  1504. {
  1505. isHave = true;
  1506. if (bill.state != 4)
  1507. {
  1508. returnErrorMsg("此单已经申请过发票了");
  1509. return;
  1510. }
  1511. }
  1512. if (entity.IsNeedBill == 0)
  1513. {
  1514. entity.IsNeedBill = 1;
  1515. }
  1516. entity.Update();
  1517. string errjson = "";
  1518. try
  1519. {
  1520. CeErpBill bill_entity = new CeErpBill();
  1521. bill_entity.tid = entity.tid;
  1522. bill_entity.title = GetPostString("title");
  1523. string taxstr = GetPostString("tax");
  1524. taxstr = taxstr.Replace(" ", "");
  1525. bill_entity.tax = taxstr;
  1526. bill_entity.bank = GetPostString("bank");
  1527. string bankacstr = GetPostString("bankac");
  1528. bankacstr = bankacstr.Replace(" ", "");
  1529. bill_entity.bankac = bankacstr;
  1530. bill_entity.address = GetPostString("address");
  1531. bill_entity.phone = GetPostString("phone");
  1532. bill_entity.price = GetPostString("price");
  1533. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1534. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1535. {
  1536. billCount += 1;
  1537. }
  1538. string prebill = "ltb";
  1539. for (int idx = 1; idx <= billCount; idx++)
  1540. {
  1541. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1542. string billoid = prebill + idx + dtstr;
  1543. bill_entity.billOrderId += billoid;
  1544. if (idx < billCount)
  1545. {
  1546. bill_entity.billOrderId += ",";
  1547. }
  1548. }
  1549. bill_entity.productId = GetPostInt("ProductName");
  1550. bill_entity.num = GetPostInt("num");
  1551. bill_entity.unit = GetPostString("unit");
  1552. bill_entity.type = GetPostString("type");
  1553. bill_entity.sendType = GetPostString("SendType");
  1554. bill_entity.email = GetPostString("email");
  1555. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1556. bill_entity.shopName = GetPostString("ShopName");
  1557. bill_entity.applymemo = GetPostString("applyMemo");
  1558. bill_entity.createTime = DateTime.Now;
  1559. bill_entity.state = 0;
  1560. bill_entity.userId = CurrentUser.UserID;
  1561. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1562. bill_entity.Create();
  1563. }
  1564. catch (Exception ex)
  1565. {
  1566. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1567. returnErrorMsg("创建发票出错!");
  1568. return;
  1569. }
  1570. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1571. returnSuccessMsg("发票申请成功!");
  1572. return;
  1573. }
  1574. returnErrorMsg("找不到记录");
  1575. }
  1576. }
  1577. public void ins_erp_neworder()
  1578. {
  1579. if (UrlPostParmsCheck("receiver_name"))
  1580. {
  1581. CeErpTrade entity = new CeErpTrade();
  1582. string plat_form = GetPostString("platform");
  1583. string preStr = "N_";
  1584. if (plat_form == "拼多多")
  1585. {
  1586. preStr = "P_";
  1587. }
  1588. else if (plat_form == "阿里巴巴")
  1589. {
  1590. preStr = "A_";
  1591. }
  1592. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1593. entity.seller_nick = GetPostString("seller_nick");
  1594. entity.buyer_nick = GetPostString("buyer_nick");
  1595. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1596. entity.total_fee = entity.payment;
  1597. entity.pay_time = DateTime.Now;
  1598. entity.status = "NOT_SHIPPED";
  1599. entity.receiver_name = GetPostString("receiver_name");
  1600. entity.receiver_mobile = GetPostString("receiver_mobile");
  1601. entity.receiver_state = GetPostString("receiver_state");
  1602. entity.receiver_city = GetPostString("receiver_city");
  1603. entity.receiver_district = GetPostString("receiver_district");
  1604. entity.receiver_address = GetPostString("receiver_address");
  1605. if (entity.receiver_state == "" || entity.receiver_city == "")
  1606. {
  1607. returnErrorMsg("收件地址不能为空");
  1608. return;
  1609. }
  1610. int shopId = 0;
  1611. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1612. if (nShop != null)
  1613. {
  1614. shopId = nShop.ID;
  1615. }
  1616. if (shopId != 34 && entity.payment == 0)
  1617. {
  1618. returnErrorMsg("公司自用的单金额才能为0");
  1619. return;
  1620. }
  1621. entity.Create();
  1622. CeErpTradeCell entitycell = new CeErpTradeCell();
  1623. entitycell.ctid = entity.tid;
  1624. entitycell.tid = entity.tid;
  1625. entitycell.ShopId = shopId;
  1626. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1627. entitycell.OrderState = 0;
  1628. entitycell.pay_time = entity.pay_time;
  1629. entitycell.IsOffLineOrder = 1;
  1630. entitycell.Create();
  1631. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1632. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1633. return;
  1634. }
  1635. }
  1636. public void ins_erp_neworder2()
  1637. {
  1638. if (UrlPostParmsCheck("receiver_name"))
  1639. {
  1640. //string plat_form = GetPostString("platform");
  1641. string preStr = "X_";
  1642. string memo = GetPostString("memo");
  1643. string productId = GetPostString("productId");
  1644. string primg = GetPostString("proofimg");
  1645. string sellerNick = GetPostString("seller_nick");
  1646. string addFrom = GetPostString("addfrom");
  1647. if (addFrom == "1")
  1648. {
  1649. preStr = "N_";
  1650. }
  1651. int shopId = 0;
  1652. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1653. if (nShop != null)
  1654. {
  1655. shopId = nShop.ID;
  1656. }
  1657. else
  1658. {
  1659. returnErrorMsg("找不到对应店铺");
  1660. return;
  1661. }
  1662. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1663. {
  1664. returnErrorMsg("必须上传付款凭证");
  1665. return;
  1666. }
  1667. CeErpTrade entity = new CeErpTrade();
  1668. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1669. entity.seller_nick = sellerNick;
  1670. entity.buyer_nick = GetPostString("buyer_nick");
  1671. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1672. entity.total_fee = entity.payment;
  1673. entity.pay_time = DateTime.Now;
  1674. entity.status = "NOT_SHIPPED";
  1675. entity.receiver_name = GetPostString("receiver_name");
  1676. entity.receiver_mobile = GetPostString("receiver_mobile");
  1677. entity.receiver_state = GetPostString("receiver_state");
  1678. entity.receiver_city = GetPostString("receiver_city");
  1679. entity.receiver_district = GetPostString("receiver_district");
  1680. entity.receiver_address = GetPostString("receiver_address");
  1681. entity.seller_memo = memo;
  1682. entity.orderFrom = 20;
  1683. entity.orderType = 15;
  1684. if (entity.receiver_state == "" || entity.receiver_city == "")
  1685. {
  1686. returnErrorMsg("收件地址不能为空");
  1687. return;
  1688. }
  1689. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1690. {
  1691. returnErrorMsg("公司自用的单金额才能为0");
  1692. return;
  1693. }
  1694. entity.Create();
  1695. string toWhere = GetPostString("towhere");
  1696. CeErpTradeCell entitycell = new CeErpTradeCell();
  1697. entitycell.ctid = entity.tid;
  1698. //唯一标识
  1699. entitycell.OrderSn = entity.tid;
  1700. string orderSn = dataHelper.getSaleOrderSn();
  1701. if (orderSn != "")
  1702. {
  1703. entitycell.OrderSn = orderSn;
  1704. }
  1705. entitycell.tid = entity.tid;
  1706. //if (preStr == "X_")
  1707. //{
  1708. entitycell.IsOffLineOrder = 1;
  1709. //}
  1710. entitycell.CustomerUserId = CurrentUser.UserID;
  1711. entitycell.PayProofImg = primg;
  1712. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1713. entitycell.ProductId = Convert.ToInt32(productId);
  1714. entitycell.ShopId = shopId;
  1715. entitycell.UpdateTime = DateTime.Now;
  1716. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1717. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1718. {
  1719. entitycell.IsXianHuo = 1;
  1720. }
  1721. entitycell.pay_time = entity.pay_time;
  1722. if (toWhere == "1")
  1723. {
  1724. entitycell.OrderState = 2;
  1725. }
  1726. else
  1727. {
  1728. entitycell.OrderState = 6;
  1729. entitycell.FinishPlaceTime = entitycell.pay_time;
  1730. }
  1731. if (shopId == 94)
  1732. {
  1733. entitycell.OrderState = 4;
  1734. entitycell.WaitDesignTime = entitycell.pay_time;
  1735. entitycell.StartDesignTime = entitycell.pay_time;
  1736. entitycell.DesignUserId = 218;
  1737. }
  1738. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1739. {
  1740. entitycell.OrderState = -1;//修改12-5
  1741. CeWithdraw ceWithdraw = new CeWithdraw();
  1742. ceWithdraw.tid = entity.tid;
  1743. ceWithdraw.providerid = "-1";
  1744. ceWithdraw.status = -1;
  1745. ceWithdraw.creationtime = DateTime.Now;
  1746. ceWithdraw.userid = 1337;
  1747. ceWithdraw.Create();
  1748. }
  1749. entitycell.Create();
  1750. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1751. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1752. {
  1753. addPlaceRegist(entitycell, CurrentUser.UserID);
  1754. }
  1755. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1756. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1757. return;
  1758. }
  1759. }
  1760. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1761. {
  1762. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1763. entity.PlactTime = tradecell.pay_time;
  1764. entity.AddUserId = userid;
  1765. entity.FileName = tradecell.seller_memo;
  1766. entity.Supplier = 24;
  1767. entity.CreateTime = DateTime.Now;
  1768. entity.Did = tradecell.ctid;
  1769. entity.tid = tradecell.tid;
  1770. entity.splitTag = tradecell.SplitTag;
  1771. entity.CurState = "未完成";
  1772. entity.Create();
  1773. }
  1774. public void get_erp_offlinelist()
  1775. {
  1776. DataStruct dStruct = GetPostStruct();
  1777. List<string> lw = new List<string>();
  1778. string tid = GetPostString("ctid");
  1779. string date1 = GetPostString("date1");
  1780. string date2 = GetPostString("date2");
  1781. if (tid.Length > 0 || date1.Length > 0)
  1782. {
  1783. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1784. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1785. if (dw.Length > 0) lw.Add(dw);
  1786. }
  1787. else
  1788. {
  1789. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1790. }
  1791. string shopname = GetPostString("shopname");
  1792. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1793. string buyernick = GetPostString("buyer_nick");
  1794. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1795. string customer = GetPostString("customer");
  1796. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1797. string design = GetPostString("design");
  1798. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1799. string orderState = GetPostString("orderState");
  1800. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1801. string address = GetPostString("address");
  1802. 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));
  1803. string sellermemo = GetPostString("seller_memo");
  1804. if (sellermemo.Length > 0)
  1805. {
  1806. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1807. }
  1808. string price1 = GetPostString("price1");
  1809. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1810. string price2 = GetPostString("price2");
  1811. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1812. //if (PKey != "admin")
  1813. //{
  1814. // string usershop = CurrentUser.User.pemShop;
  1815. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1816. //}
  1817. //if (ex_psize > 0)
  1818. //{
  1819. dStruct.Order = "pay_time desc";
  1820. //}
  1821. //else
  1822. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1823. lw.Add(string.Format("IsOffLineOrder=1"));
  1824. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1825. DataTable dt = null;
  1826. dt = WebCache.GetData("view_erptradecell", dStruct);
  1827. writeGridDataTableJson(dStruct.TotalCount, dt);
  1828. }
  1829. public void get_erp_returncashrecord()
  1830. {
  1831. DataStruct dStruct = GetPostStruct();
  1832. List<string> lw = new List<string>();
  1833. string tid = GetPostString("ctid");
  1834. if (tid.Length > 0)
  1835. {
  1836. lw.Add(string.Format("tid like '%{0}%'", tid));
  1837. dStruct.Order = "id desc";
  1838. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1839. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1840. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1841. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1842. return;
  1843. }
  1844. returnErrorMsg("id数据错误!");
  1845. }
  1846. public void ins_erp_returncashrecord()
  1847. {
  1848. if (UrlPostParmsCheck("tid"))
  1849. {
  1850. string tid = GetPostString("tid");
  1851. string retype = GetPostString("type");
  1852. StringBuilder sql = new StringBuilder();
  1853. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1854. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1855. if (dt.Rows.Count > 0)
  1856. {
  1857. returnErrorMsg("相同返现类型记录已存在");
  1858. return;
  1859. }
  1860. CeErpReturnCash entity = new CeErpReturnCash();
  1861. entity.tid = tid;
  1862. entity.seller_nick = GetPostString("seller_nick");
  1863. string pment = GetPostString("payment");
  1864. if (pment.Length > 0)
  1865. {
  1866. entity.payment = Convert.ToDouble(pment);
  1867. }
  1868. entity.buyer_nick = GetPostString("buyer_nick");
  1869. entity.cashstate = 0;
  1870. entity.rtype = retype;
  1871. string rPrice = GetPostString("returnprice");
  1872. if (rPrice.Length > 0)
  1873. {
  1874. entity.returnprice = Convert.ToDouble(rPrice);
  1875. }
  1876. entity.created = DateTime.Now;
  1877. entity.con = GetPostString("con");
  1878. entity.img = GetPostString("img");
  1879. entity.applyuserid = CurrentUser.UserID;
  1880. entity.Create();
  1881. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1882. returnSuccessMsg("操作成功!");
  1883. return;
  1884. }
  1885. }
  1886. public void set_erp_predelivery()
  1887. {
  1888. if (UrlPostParmsCheck("ctid"))
  1889. {
  1890. string eid = GetPostString("ctid");
  1891. CeErpTradeCell entity = null;
  1892. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1893. if (entity != null)
  1894. {
  1895. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1896. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1897. //{
  1898. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1899. // return;
  1900. //}
  1901. entity.IsPreDelivery = 1;
  1902. entity.Update();
  1903. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1904. returnSuccessMsg("预发货成功!");
  1905. return;
  1906. //string shop = GetPostString("seller_nick");
  1907. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1908. //string comName = GetPostString("comName");
  1909. //string comCode = GetPostString("comCode");
  1910. //string outSid = GetPostString("outSid");//运单号
  1911. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1912. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1913. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1914. //string apires = "";
  1915. //if (deliveryType == "虚拟发货")
  1916. //{
  1917. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1918. //}
  1919. //else
  1920. //{
  1921. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1922. //}
  1923. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1924. ////{
  1925. //if (apires.IndexOf("发货成功") != -1)
  1926. //{
  1927. // if (deliveryType != "虚拟发货")
  1928. // {
  1929. // //还要插入快递信息到 快递信息表
  1930. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1931. // exinfo.tid = eid;
  1932. // exinfo.out_sid = outSid;
  1933. // exinfo.company_code = comCode;
  1934. // exinfo.company_name = comName;
  1935. // exinfo.delivery_memo = deliveryMemo;
  1936. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1937. // exinfo.deliveryType = deliveryType;
  1938. // exinfo.Create();
  1939. // }
  1940. // returnSuccessMsg("发货成功!");
  1941. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1942. //}
  1943. //else
  1944. //{
  1945. // returnErrorMsg("淘宝发货失败!!");
  1946. //}
  1947. //return;
  1948. }
  1949. returnErrorMsg("找不到订单记录");
  1950. }
  1951. }
  1952. public void get_erp_unusuallist()
  1953. {
  1954. DataStruct dStruct = GetPostStruct();
  1955. List<string> lw = new List<string>();
  1956. string tid = GetPostString("ctid");
  1957. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1958. string shopname = GetPostString("shopname");
  1959. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1960. string buyernick = GetPostString("buyer_nick");
  1961. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1962. string ResponsibleMan = GetPostString("responsible");
  1963. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1964. string date1 = GetPostString("date1");
  1965. string date2 = GetPostString("date2");
  1966. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1967. if (dw.Length > 0) lw.Add(dw);
  1968. string price1 = GetPostString("price1");
  1969. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1970. string price2 = GetPostString("price2");
  1971. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1972. string orderState = GetPostString("orderState");
  1973. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1974. string sellermemo = GetPostString("seller_memo");
  1975. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1976. lw.Add(string.Format("UnusualTag > 0"));
  1977. lw.Add(string.Format("IsRefund<={0}", 1));
  1978. dStruct.Order = "pay_time desc";
  1979. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1980. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1981. writeGridDataTableJson(dStruct.TotalCount, dt);
  1982. }
  1983. public void set_erp_unusualtonomal()
  1984. {
  1985. if (UrlPostParmsCheck("ctid"))
  1986. {
  1987. string eid = GetPostString("ctid");
  1988. CeErpTradeCell entity = null;
  1989. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1990. if (entity != null)
  1991. {
  1992. entity.UnusualTag = -1;
  1993. entity.Update();
  1994. returnSuccessMsg("忽略成功!");
  1995. return;
  1996. }
  1997. returnErrorMsg("找不到记录");
  1998. }
  1999. }
  2000. public void ins_erp_unusualreason()
  2001. {
  2002. if (UrlPostParmsCheck("ctid"))
  2003. {
  2004. string eid = GetPostString("ctid");
  2005. CeErpTradeCell entity = null;
  2006. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2007. if (entity != null)
  2008. {
  2009. entity.MemoOpt = 4;
  2010. entity.UnusualCon = GetPostString("con");
  2011. entity.Update();
  2012. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2013. if (trade != null)
  2014. {
  2015. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2016. }
  2017. //查货是否超时
  2018. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2019. if (ceErpTradeCellExtend == null)
  2020. {
  2021. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2022. ceErpTradeCellExtend.ctid = entity.ctid;
  2023. }
  2024. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2025. {
  2026. ceErpTradeCellExtend.CheckOut += 1;
  2027. }
  2028. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2029. if (ceErpTradeCellExtend.ID > 0)
  2030. {
  2031. ceErpTradeCellExtend.Update();
  2032. }
  2033. else
  2034. {
  2035. ceErpTradeCellExtend.Create();
  2036. }
  2037. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2038. returnSuccessMsg("操作成功!");
  2039. return;
  2040. }
  2041. returnErrorMsg("找不到记录");
  2042. }
  2043. }
  2044. public void upd_erp_sampleorder()
  2045. {
  2046. if (UrlPostParmsCheck("ctid"))
  2047. {
  2048. string eid = GetPostString("ctid");
  2049. string[] eArr = eid.Split(',');
  2050. if (eArr.Length > 1)
  2051. {
  2052. List<string> eLst = new List<string>();
  2053. for (int i = 0; i < eArr.Length; i++)
  2054. {
  2055. eLst.Add("'" + eArr[i] + "'");
  2056. }
  2057. eid = string.Join(",", eLst.ToArray());
  2058. }
  2059. else
  2060. {
  2061. eid = "'" + eid + "'";
  2062. }
  2063. StringBuilder sql = new StringBuilder();
  2064. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2065. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2066. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2067. if (dt.Rows.Count > 0)
  2068. {
  2069. string errmsg = "";
  2070. foreach (DataRow dr in dt.Rows)
  2071. {
  2072. StringBuilder sqlsb = new StringBuilder();
  2073. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2074. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2075. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2076. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2077. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2078. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2079. {
  2080. continue;
  2081. }
  2082. else
  2083. {
  2084. string emsg = commonHelper.KeepChinese(apires);
  2085. errmsg += emsg;
  2086. }
  2087. }
  2088. if (errmsg.Length > 0)
  2089. {
  2090. returnErrorMsg(errmsg);
  2091. return;
  2092. }
  2093. returnSuccessMsg("操作成功");
  2094. return;
  2095. }
  2096. returnErrorMsg("找不到记录");
  2097. }
  2098. }
  2099. public void upd_erp_transcustomer()
  2100. {
  2101. if (UrlPostParmsCheck("ctid"))
  2102. {
  2103. string eid = GetPostString("ctid");
  2104. int userid = GetPostInt("CustomerUserId");
  2105. CeErpTradeCell entity = null;
  2106. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2107. if (entity != null)
  2108. {
  2109. //string[] mlist = entity.seller_memo.Split('-');
  2110. //string sql = "select * from view_erpuser where id=" + userid;
  2111. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2112. //if (dt != null && dt.Rows.Count > 0)
  2113. //{
  2114. // string nmemo = "";
  2115. // for(int i = 0; i < mlist.Length - 1; i++)
  2116. // {
  2117. // nmemo += mlist[i];
  2118. // nmemo += "-";
  2119. // }
  2120. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2121. // entity.seller_memo = nmemo;
  2122. //}
  2123. entity.CustomerUserId = userid;
  2124. entity.Update();
  2125. returnSuccessMsg("操作成功!");
  2126. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2127. return;
  2128. }
  2129. returnErrorMsg("找不到记录");
  2130. }
  2131. }
  2132. public void upd_erp_transdesigner()
  2133. {
  2134. if (UrlPostParmsCheck("ctid"))
  2135. {
  2136. string eids = GetPostString("ctid");
  2137. string[] ctidList = eids.Split(',');
  2138. int userid = GetPostInt("DesignUserId");
  2139. foreach (string ctid in ctidList)
  2140. {
  2141. CeErpTradeCell entity = null;
  2142. CeErpDesignerBill entitys = null;
  2143. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2144. entitys = CeErpDesignerBill.GetByTid(ctid);
  2145. if (entity != null)
  2146. {
  2147. if (entity.OrderState > 4)
  2148. {
  2149. continue;
  2150. }
  2151. //存在退款不能流转
  2152. if (entity.IsRefund > 0)
  2153. {
  2154. continue;
  2155. }
  2156. entity.DesignUserId = userid;
  2157. entity.WaitDesignTime = DateTime.Now;
  2158. entity.Update();
  2159. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2160. }
  2161. }
  2162. returnSuccessMsg("操作成功!");
  2163. }
  2164. }
  2165. public void upd_erp_distributedesigner()
  2166. {
  2167. if (UrlPostParmsCheck("ctid"))
  2168. {
  2169. string eid = GetPostString("ctid");
  2170. int userid = GetPostInt("DesignUserId");
  2171. string[] idlist = eid.Split(',');
  2172. if (idlist.Length <= 0)
  2173. {
  2174. returnErrorMsg("订单不能为空");
  2175. return;
  2176. }
  2177. foreach (string ctid in idlist)
  2178. {
  2179. CeErpTradeCell entity = null;
  2180. CeErpDesignerBill entitys = null;
  2181. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2182. else continue;
  2183. if (entity != null)
  2184. {
  2185. if (userid == 2125 || userid == 3542)
  2186. { }
  2187. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2188. {
  2189. returnErrorMsg("金额错误的订单无法指派");
  2190. return;
  2191. }
  2192. if (entity.OrderState >= 5)
  2193. {
  2194. returnErrorMsg("已经设计完成无法指派");
  2195. return;
  2196. }
  2197. if (entity.OrderState == -1)
  2198. {
  2199. returnErrorMsg("审核中的订单无法指派");
  2200. return;
  2201. }
  2202. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2203. {
  2204. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2205. return;
  2206. }
  2207. //157赖橙帆 159林晨 73 静之颖
  2208. 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)
  2209. {
  2210. returnErrorMsg("指派设计共创无法再次指派!");
  2211. return;
  2212. }
  2213. entity.OrderState = 3;
  2214. if (entity.SupplierId == 0)
  2215. {
  2216. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2217. entity.SupplierId = suid;
  2218. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2219. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2220. }
  2221. if (userid == 2125 && entity.seller_memo != "")
  2222. {
  2223. apiDesign.API_GetPrintData_CreateOrder(entity);
  2224. }
  2225. if (userid == 3542 && entity.seller_memo != "")
  2226. {
  2227. string userPost = CurrentUser.UserPost.Post.Code;
  2228. if (CurrentUser.UserID == 73)
  2229. {
  2230. userPost = "SysAdmin";
  2231. }
  2232. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2233. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2234. if (response.msg != "设计共创:成功")
  2235. {
  2236. returnErrorMsg(response.msg);
  2237. return;
  2238. }
  2239. entity.DispatchSort = 2;
  2240. }
  2241. else
  2242. {
  2243. if (entity.DispatchSort == 2)
  2244. {
  2245. ApiVo apiVo = new ApiVo();
  2246. apiVo.actionName = "closeDesign";
  2247. apiVo.orderNumber = entity.ctid;
  2248. designHelper.API_WorkCore(apiVo);//closeDesign
  2249. }
  2250. entity.DispatchSort = 0;
  2251. }
  2252. entity.DesignUserId = userid;
  2253. entity.WaitDesignTime = DateTime.Now;
  2254. entity.UpdateTime = DateTime.Now;
  2255. entity.Update();
  2256. string name = commonHelper.getUserNameById(userid);
  2257. commonHelper.UpdateRelationOrder(entity.ctid);
  2258. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2259. }
  2260. }
  2261. returnSuccessMsg("操作成功!");
  2262. return;
  2263. }
  2264. }
  2265. public string getTidByCtid(string ctid)
  2266. {
  2267. string tid = "";
  2268. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2269. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2270. if (dataTable != null && dataTable.Rows.Count > 0)
  2271. {
  2272. tid = dataTable.Rows[0]["tid"].ToString();
  2273. }
  2274. return tid;
  2275. }
  2276. public List<string> getTidByCtidMore(string ctid)
  2277. {
  2278. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2279. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2280. List<string> list = new List<string>();
  2281. if (dataTable != null && dataTable.Rows.Count > 0)
  2282. {
  2283. foreach (DataRow item in dataTable.Rows)
  2284. {
  2285. list.Add("'" + item["tid"].ToString() + "'");
  2286. }
  2287. }
  2288. return list;
  2289. }
  2290. public List<string> getTidByCtidLike(string ctid)
  2291. {
  2292. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2293. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2294. List<string> list = new List<string>();
  2295. if (dataTable != null && dataTable.Rows.Count > 0)
  2296. {
  2297. foreach (DataRow item in dataTable.Rows)
  2298. {
  2299. list.Add("'" + item["tid"].ToString() + "'");
  2300. }
  2301. }
  2302. return list;
  2303. }
  2304. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2305. {
  2306. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2307. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2308. List<string> list = new List<string>();
  2309. if (dataTable != null && dataTable.Rows.Count > 0)
  2310. {
  2311. foreach (DataRow item in dataTable.Rows)
  2312. {
  2313. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2314. {
  2315. continue;
  2316. }
  2317. list.Add("'" + item["receiverId"].ToString() + "'");
  2318. }
  2319. }
  2320. return list;
  2321. }
  2322. public void get_erp_myorderlist()
  2323. {
  2324. DataStruct dStruct = GetPostStruct();
  2325. List<string> lw = new List<string>();
  2326. string tid = GetPostString("ctid");
  2327. if (tid.Length > 0)
  2328. {
  2329. string select_tid = getTidByCtid(tid);
  2330. lw.Add(string.Format("tid='{0}'", select_tid));
  2331. }
  2332. else
  2333. {
  2334. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2335. }
  2336. //12-1 修改
  2337. string urgent = GetPostString("urgent");
  2338. string back = GetPostString("back");
  2339. string offlineSearch = GetPostString("offlineSearch");
  2340. if (!string.IsNullOrWhiteSpace(urgent))
  2341. {
  2342. if (urgent.Equals("true"))
  2343. {
  2344. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2345. }
  2346. }
  2347. if (!string.IsNullOrWhiteSpace(back))
  2348. {
  2349. if (back.Equals("true"))
  2350. {
  2351. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2352. }
  2353. }
  2354. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2355. {
  2356. if (offlineSearch.Equals("true"))
  2357. {
  2358. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2359. }
  2360. }
  2361. //end
  2362. string shopname = GetPostString("shopname");
  2363. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2364. string buyernick = GetPostString("buyer_nick");
  2365. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2366. string design = GetPostString("design");
  2367. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2368. string orderState = GetPostString("orderState");
  2369. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2370. string sellermemo = GetPostString("seller_memo");
  2371. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2372. string date1 = GetPostString("date1");
  2373. string date2 = GetPostString("date2");
  2374. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2375. if (dw.Length > 0) lw.Add(dw);
  2376. string price1 = GetPostString("price1");
  2377. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2378. string price2 = GetPostString("price2");
  2379. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2380. string urgency = GetPostString("urgency");
  2381. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2382. string after = GetPostString("after");
  2383. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2384. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2385. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2386. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2387. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2388. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2389. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2390. if (dt != null && dt.Rows.Count > 0)
  2391. {
  2392. foreach (DataRow dr in dt.Rows)
  2393. {
  2394. try
  2395. {
  2396. // 对象操作
  2397. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2398. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2399. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2400. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2401. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2402. if (dStruct.PageSize != 100000)
  2403. {
  2404. if (dr["DispatchSort"].ToString() == "2")
  2405. {
  2406. dr["gongchuang"] = 200;
  2407. }
  2408. else if ("外协".Equals(dr["ToType"].ToString()))
  2409. {
  2410. dr["gongchuang"] = 200;
  2411. }
  2412. else if ("内部".Equals(dr["ToType"].ToString()))
  2413. {
  2414. dr["gongchuang"] = -1;
  2415. }
  2416. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2417. {
  2418. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2419. dr["gongchuang"] = response.code;
  2420. }
  2421. }
  2422. }
  2423. catch (NullReferenceException ex)
  2424. {
  2425. }
  2426. }
  2427. }
  2428. writeGridDataTableJson(dStruct.TotalCount, dt);
  2429. }
  2430. public void get_erp_myreturnorderlist()
  2431. {
  2432. DataStruct dStruct = GetPostStruct();
  2433. List<string> lw = new List<string>();
  2434. string tid = GetPostString("ctid");
  2435. if (tid.Length > 0)
  2436. {
  2437. string select_tid = getTidByCtid(tid);
  2438. lw.Add(string.Format("tid='{0}'", select_tid));
  2439. }
  2440. else
  2441. {
  2442. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2443. }
  2444. string shopname = GetPostString("shopname");
  2445. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2446. string buyernick = GetPostString("buyer_nick");
  2447. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2448. string design = GetPostString("design");
  2449. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2450. string orderState = GetPostString("orderState");
  2451. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2452. string sellermemo = GetPostString("seller_memo");
  2453. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2454. string date1 = GetPostString("date1");
  2455. string date2 = GetPostString("date2");
  2456. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2457. if (dw.Length > 0) lw.Add(dw);
  2458. string price1 = GetPostString("price1");
  2459. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2460. string price2 = GetPostString("price2");
  2461. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2462. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2463. {
  2464. lw.Add(string.Format("CusOrgID = 94"));
  2465. }
  2466. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2467. {
  2468. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2469. }
  2470. else
  2471. {
  2472. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2473. }
  2474. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2475. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2476. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2477. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2478. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2479. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2480. if (dt != null && dt.Rows.Count > 0)
  2481. {
  2482. foreach (DataRow dr in dt.Rows)
  2483. {
  2484. try
  2485. {
  2486. // 对象操作
  2487. if (dStruct.PageSize != 100000)
  2488. {
  2489. if (dr["DispatchSort"].ToString() == "2")
  2490. {
  2491. dr["gongchuang"] = 200;
  2492. }
  2493. else if ("外协".Equals(dr["ToType"].ToString()))
  2494. {
  2495. dr["gongchuang"] = 200;
  2496. }
  2497. else if ("内部".Equals(dr["ToType"].ToString()))
  2498. {
  2499. dr["gongchuang"] = -1;
  2500. }
  2501. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2502. {
  2503. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2504. dr["gongchuang"] = response.code;
  2505. }
  2506. }
  2507. }
  2508. catch (NullReferenceException ex)
  2509. {
  2510. // 处理空引用异常
  2511. }
  2512. }
  2513. }
  2514. writeGridDataTableJson(dStruct.TotalCount, dt);
  2515. }
  2516. public void get_erp_myorderlist_pregather()
  2517. {
  2518. string date1 = GetPostString("date1");
  2519. string date2 = GetPostString("date2");
  2520. int userId = CurrentUser.UserID; //客服id
  2521. string orderWhere = "";
  2522. List<string> lw = new List<string>();
  2523. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2524. if (dw.Length > 0) lw.Add(dw);
  2525. lw.Add(string.Format("CustomerUserId={0}", userId));
  2526. lw.Add(string.Format("OrderState<9"));
  2527. orderWhere = string.Join(" and ", lw.ToArray());
  2528. string orderWhere2 = "";
  2529. List<string> lw2 = new List<string>();
  2530. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2531. if (dw2.Length > 0) lw2.Add(dw2);
  2532. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2533. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2534. string sql = string.Format("select *" +
  2535. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2536. "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 " +
  2537. "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 " +
  2538. "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");
  2539. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2540. //writeGridDataTableJson(dt.Rows.Count, dt);
  2541. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2542. }
  2543. public void upd_erp_publishorder()
  2544. {
  2545. if (UrlPostParmsCheck("ctid"))
  2546. {
  2547. string eid = GetPostString("ctid");
  2548. CeErpTradeCell entity = null;
  2549. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2550. if (entity != null)
  2551. {
  2552. entity.OrderState = 0; //发布后,变为待抢单
  2553. entity.Update();
  2554. commonHelper.UpdateRelationOrder(entity.ctid);
  2555. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2556. returnSuccessMsg("发布成功!");
  2557. return;
  2558. }
  2559. returnErrorMsg("找不到记录");
  2560. }
  2561. }
  2562. public void get_erp_my_tiporder()
  2563. {
  2564. StringBuilder sql = new StringBuilder();
  2565. int userId = 0;
  2566. if (CurrentUser != null) userId = CurrentUser.UserID;
  2567. string posCode = CurrentUser.UserPost.Post.Code;
  2568. string isTipedAfterSaleVerify = GetPostString("af");
  2569. DataTable dt = new DataTable();
  2570. if (posCode != "Supplier")
  2571. {
  2572. if (posCode == "CustomerService" || posCode == "Director")
  2573. {
  2574. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2575. }
  2576. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2577. {
  2578. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2579. }
  2580. else
  2581. {
  2582. string teamIds = CurrentUser.User.TeamIds;
  2583. if (teamIds == "")
  2584. {
  2585. teamIds = "0";
  2586. }
  2587. 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);
  2588. }
  2589. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2590. }
  2591. if (dt.Rows.Count <= 0)
  2592. {
  2593. string key = "aftersale_order_" + userId;
  2594. if (RedisHelper.HasKey(key))
  2595. {
  2596. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2597. dt.Columns.Add("ctid", typeof(string));
  2598. dt.Columns.Add("IsReadTag", typeof(int));
  2599. foreach (var i in list)
  2600. {
  2601. DataRow data = dt.NewRow();
  2602. data["ctid"] = i;
  2603. data["IsReadTag"] = 4;
  2604. dt.Rows.Add(data);
  2605. }
  2606. RedisHelper.StringDelete(key);
  2607. }
  2608. }
  2609. if (dt.Rows.Count <= 0)
  2610. {
  2611. sql = new StringBuilder();
  2612. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2613. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2614. }
  2615. if (posCode == "Supplier")
  2616. {
  2617. string ids = CurrentUser.User.pemVend;
  2618. if (ids != null && ids.Length > 0)
  2619. {
  2620. string[] ids_list = ids.Split(',');
  2621. foreach (var item in ids_list)
  2622. {
  2623. string key = "return_order_" + item;
  2624. if (RedisHelper.HasKey(key))
  2625. {
  2626. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2627. dt.Columns.Add("ctid", typeof(string));
  2628. dt.Columns.Add("IsReadTag", typeof(int));
  2629. foreach (var i in list)
  2630. {
  2631. DataRow data = dt.NewRow();
  2632. data["ctid"] = i;
  2633. data["IsReadTag"] = 1;
  2634. dt.Rows.Add(data);
  2635. }
  2636. RedisHelper.StringDelete(key);
  2637. }
  2638. }
  2639. }
  2640. if (dt.Rows.Count <= 0)
  2641. {
  2642. sql = new StringBuilder();
  2643. 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);
  2644. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2645. }
  2646. }
  2647. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2648. }
  2649. public void reset_erp_tiporder()
  2650. {
  2651. string ids = GetPostString("ids");
  2652. string[] ctidList = ids.Split(',');
  2653. foreach (string ctid in ctidList)
  2654. {
  2655. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2656. if (enty != null)
  2657. {
  2658. enty.IsReadTag = 0;
  2659. enty.Update();
  2660. }
  2661. }
  2662. returnSuccessMsg("成功!");
  2663. return;
  2664. }
  2665. public void get_erp_designlist()
  2666. {
  2667. DataStruct dStruct = GetPostStruct();
  2668. List<string> lw = new List<string>();
  2669. string tid = GetPostString("ctid");
  2670. if (tid.Length > 0)
  2671. {
  2672. string select_tid = getTidByCtid(tid);
  2673. lw.Add(string.Format("tid='{0}'", select_tid));
  2674. }
  2675. string shopname = GetPostString("shopname");
  2676. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2677. string buyernick = GetPostString("buyer_nick");
  2678. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2679. string customer = GetPostString("customer");
  2680. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2681. string design = GetPostString("design");
  2682. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2683. string orderState = GetPostString("orderState");
  2684. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2685. lw.Add(string.Format("OrderState<6"));
  2686. string address = GetPostString("address");
  2687. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2688. string sellermemo = GetPostString("seller_memo");
  2689. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2690. string date1 = GetPostString("date1");
  2691. string date2 = GetPostString("date2");
  2692. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2693. if (dw.Length > 0) lw.Add(dw);
  2694. string apdate1 = GetPostString("apdate1");
  2695. string apdate2 = GetPostString("apdate2");
  2696. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2697. if (dwap.Length > 0) lw.Add(dwap);
  2698. string price1 = GetPostString("price1");
  2699. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2700. string price2 = GetPostString("price2");
  2701. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2702. string designTime = GetPostString("designtime");
  2703. if (designTime.Length > 0)
  2704. {
  2705. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2706. }
  2707. string usershop = CurrentUser.User.pemShop;
  2708. if (usershop.Length > 0)
  2709. {
  2710. lw.Add(string.Format("shopId in ({0})", usershop));
  2711. }
  2712. int myOrgid = CurrentUser.UserPost.OrgID;
  2713. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2714. if (myOrgCode.IndexOf("Designer") != -1)
  2715. {
  2716. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2717. {
  2718. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2719. }
  2720. else
  2721. {
  2722. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2723. }
  2724. }
  2725. else
  2726. {
  2727. string orgId = GetPostString("designerhd");
  2728. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2729. }
  2730. if (tid.Length > 0 || buyernick.Length > 0)
  2731. {
  2732. lw.Add(string.Format("OrderState >= 3"));
  2733. }
  2734. else
  2735. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2736. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2737. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2738. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2739. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2740. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2741. if (dt != null && dt.Rows.Count > 0)
  2742. {
  2743. foreach (DataRow dr in dt.Rows)
  2744. {
  2745. try
  2746. {
  2747. // 对象操作
  2748. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2749. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2750. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2751. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2752. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2753. if (dStruct.PageSize != 100000)
  2754. {
  2755. if (dr["DispatchSort"].ToString() == "2")
  2756. {
  2757. dr["gongchuang"] = 200;
  2758. }
  2759. else if ("外协".Equals(dr["ToType"].ToString()))
  2760. {
  2761. dr["gongchuang"] = 200;
  2762. }
  2763. else if ("内部".Equals(dr["ToType"].ToString()))
  2764. {
  2765. dr["gongchuang"] = -1;
  2766. }
  2767. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2768. {
  2769. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2770. dr["gongchuang"] = response.code;
  2771. }
  2772. }
  2773. }
  2774. catch (NullReferenceException ex)
  2775. {
  2776. }
  2777. }
  2778. }
  2779. writeGridDataTableJson(dStruct.TotalCount, dt);
  2780. }
  2781. public void get_erp_mydesignlist()
  2782. {
  2783. DataStruct dStruct = GetPostStruct();
  2784. List<string> lw = new List<string>();
  2785. string tid = GetPostString("ctid");
  2786. if (tid.Length > 0)
  2787. {
  2788. string select_tid = getTidByCtid(tid);
  2789. lw.Add(string.Format("tid='{0}'", select_tid));
  2790. }
  2791. string shopname = GetPostString("shopname");
  2792. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2793. string buyernick = GetPostString("buyer_nick");
  2794. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2795. string customer = GetPostString("customer");
  2796. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2797. string orderState = GetPostString("orderState");
  2798. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2799. //lw.Add(string.Format("OrderState<6"));
  2800. string date1 = GetPostString("date1");
  2801. string date2 = GetPostString("date2");
  2802. string dw = GetDateWhere("pay_time", date1, date2);
  2803. if (dw.Length > 0) lw.Add(dw);
  2804. string apdate1 = GetPostString("apdate1");
  2805. string apdate2 = GetPostString("apdate2");
  2806. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2807. if (dwap.Length > 0) lw.Add(dwap);
  2808. string price1 = GetPostString("price1");
  2809. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2810. string price2 = GetPostString("price2");
  2811. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2812. string olddownload = GetPostString("olddown");
  2813. if (olddownload == "1")
  2814. {
  2815. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2816. }
  2817. else if (olddownload == "2")
  2818. {
  2819. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2820. }
  2821. string sellermemo = GetPostString("seller_memo");
  2822. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2823. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2824. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2825. {
  2826. if (CurrentUser.User.TeamIds.Length > 0)
  2827. {
  2828. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2829. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2830. else
  2831. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2832. }
  2833. else
  2834. {
  2835. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2836. }
  2837. }
  2838. if (tid.Length <= 0)
  2839. {
  2840. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2841. }
  2842. lw.Add(string.Format("IsReturn!=3"));
  2843. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2844. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2845. string teamids = CurrentUser.User.TeamIds.ToString();
  2846. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2847. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2848. if (dt != null && dt.Rows.Count > 0)
  2849. {
  2850. foreach (DataRow dr in dt.Rows)
  2851. {
  2852. try
  2853. {
  2854. // 对象操作
  2855. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2856. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2857. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2858. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2859. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2860. if (dStruct.PageSize != 100000)
  2861. {
  2862. if (dr["DispatchSort"].ToString() == "2")
  2863. {
  2864. dr["gongchuang"] = 200;
  2865. }
  2866. else if ("外协".Equals(dr["ToType"].ToString()))
  2867. {
  2868. dr["gongchuang"] = 200;
  2869. }
  2870. else if ("内部".Equals(dr["ToType"].ToString()))
  2871. {
  2872. dr["gongchuang"] = -1;
  2873. }
  2874. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2875. {
  2876. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2877. dr["gongchuang"] = response.code;
  2878. }
  2879. }
  2880. }
  2881. catch (NullReferenceException ex)
  2882. {
  2883. }
  2884. }
  2885. }
  2886. writeGridDataTableJson(dStruct.TotalCount, dt);
  2887. }
  2888. public void set_erp_startdesign()
  2889. {
  2890. if (UrlPostParmsCheck("ctid"))
  2891. {
  2892. string eid = GetPostString("ctid");
  2893. CeErpTradeCell entity = null;
  2894. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2895. if (entity != null)
  2896. {
  2897. if (entity.OrderState != 3)
  2898. {
  2899. returnErrorMsg("请刷新,订单已经设计了");
  2900. return;
  2901. }
  2902. entity.StartDesignTime = DateTime.Now;
  2903. entity.OrderState = 4;
  2904. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2905. {
  2906. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2907. entity.SupplierId = suid;
  2908. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2909. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2910. }
  2911. entity.UpdateTime = DateTime.Now;
  2912. //entity.MakeSupplier = suname;
  2913. entity.Update();
  2914. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2915. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2916. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2917. commonHelper.getCytPrice(entity);
  2918. returnSuccessMsg("操作成功!");
  2919. return;
  2920. }
  2921. returnErrorMsg("找不到记录");
  2922. }
  2923. }
  2924. public void ins_erp_designselfmemo()
  2925. {
  2926. if (UrlPostParmsCheck("ctid"))
  2927. {
  2928. string eid = GetPostString("ctid");
  2929. string con = GetPostString("con");
  2930. CeErpTradeCell entity = null;
  2931. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2932. if (entity != null)
  2933. {
  2934. entity.DesignSelfMemo = con;
  2935. entity.Update();
  2936. returnSuccessMsg("操作成功!");
  2937. return;
  2938. }
  2939. returnErrorMsg("找不到记录");
  2940. }
  2941. }
  2942. public void ins_erp_designprice()
  2943. {
  2944. if (UrlPostParmsCheck("ctid"))
  2945. {
  2946. string eid = GetPostString("ctid");
  2947. int uid = CurrentUser.UserID;
  2948. string userName = CurrentUser.UserName;
  2949. CeErpTradeCell entity = null;
  2950. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2951. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2952. if (entitys == null)
  2953. {
  2954. entitys = new CeErpDesignerBill();
  2955. }
  2956. if (entity != null)
  2957. {
  2958. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2959. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2960. entity.StartDesignTime = DateTime.Now;
  2961. entity.OrderState = 4;
  2962. string suname = "";
  2963. if (entity.SupplierId == 0)
  2964. {
  2965. int sid = commonHelper.autoDistributeToSupplier(entity);
  2966. entity.SupplierId = sid;
  2967. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2968. }
  2969. entity.Update();
  2970. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2971. if (ceErpUserPost != null)
  2972. {
  2973. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2974. if (ceErpPost != null)
  2975. {
  2976. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2977. {
  2978. entitys.tid = entity.ctid;
  2979. entitys.oid = entity.tid;
  2980. entitys.uid = uid;
  2981. entitys.userName = userName;
  2982. entitys.designerType = 1;
  2983. entitys.designerTypeText = "内部设计师";
  2984. entitys.price = Convert.ToDouble(GetPostString("price"));
  2985. entitys.designNum = GetPostInt("designNum");
  2986. entitys.modifyNum = GetPostInt("modifyNum");
  2987. entitys.designSize = GetPostString("designSize");
  2988. entitys.modifySize = GetPostString("modifySize");
  2989. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2990. {
  2991. entitys.create_time = DateTime.Now;
  2992. entitys.create_u_id = uid;
  2993. entitys.create_u_name = userName;
  2994. entitys.Save();
  2995. }
  2996. else
  2997. {
  2998. entitys.update_time = DateTime.Now;
  2999. entitys.update_u_id = uid;
  3000. entitys.update_u_name = userName;
  3001. entitys.Update();
  3002. }
  3003. }
  3004. }
  3005. }
  3006. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3007. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3008. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3009. if (suname != "")
  3010. {
  3011. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3012. }
  3013. commonHelper.getCytPrice(entity);
  3014. returnSuccessMsg("操作成功!");
  3015. return;
  3016. }
  3017. returnErrorMsg("找不到记录");
  3018. }
  3019. }
  3020. public void upload_erp_filecomplete()
  3021. {
  3022. if (UrlPostParmsCheck("ctid"))
  3023. {
  3024. string eid = GetPostString("ctid");
  3025. CeErpTradeCell entity = null;
  3026. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3027. if (entity != null)
  3028. {
  3029. entity.OrderState = 5; //设计完成
  3030. entity.Update();
  3031. returnSuccessMsg(eid + "上传成功,设计完成!");
  3032. return;
  3033. }
  3034. returnErrorMsg("找不到订单记录");
  3035. }
  3036. }
  3037. public void get_erp_designovertimelist()
  3038. {
  3039. DataStruct dStruct = GetPostStruct();
  3040. List<string> lw = new List<string>();
  3041. string tid = GetPostString("ctid");
  3042. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3043. string shopname = GetPostString("shopname");
  3044. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3045. string buyernick = GetPostString("buyer_nick");
  3046. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3047. string ResponsibleMan = GetPostString("responsible");
  3048. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3049. string date1 = GetPostString("date1");
  3050. string date2 = GetPostString("date2");
  3051. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3052. if (dw.Length > 0) lw.Add(dw);
  3053. string price1 = GetPostString("price1");
  3054. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3055. string price2 = GetPostString("price2");
  3056. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3057. string orderState = GetPostString("orderState");
  3058. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3059. string sellermemo = GetPostString("seller_memo");
  3060. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3061. lw.Add(string.Format("UnusualTag=3"));
  3062. lw.Add(string.Format("IsRefund<={0}", 1));
  3063. dStruct.Order = "WaitDesignTime desc";
  3064. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3065. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3066. writeGridDataTableJson(dStruct.TotalCount, dt);
  3067. }
  3068. //设计管理 获取抢单大厅列表
  3069. public void get_erp_grabinglist()
  3070. {
  3071. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3072. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3073. bool oldOrder = false;
  3074. if (org != null)
  3075. {
  3076. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3077. }
  3078. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3079. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3080. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3081. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3082. //先处理订单数据
  3083. if (dt.Rows.Count > 0)
  3084. {
  3085. Dictionary<string, int> design = null;
  3086. int count = 0;
  3087. foreach (DataRow row in dt.Rows)
  3088. {
  3089. if (map.ContainsKey(row["ShopId"].ToString()))
  3090. {
  3091. map.TryGetValue(row["ShopId"].ToString(), out design);
  3092. }
  3093. else
  3094. {
  3095. design = new Dictionary<string, int>();
  3096. }
  3097. if (design.ContainsKey(row["ProductId"].ToString()))
  3098. {
  3099. design.TryGetValue(row["ProductId"].ToString(), out count);
  3100. }
  3101. count++;
  3102. design[row["ProductId"].ToString()] = count;
  3103. map[row["ShopId"].ToString()] = design;
  3104. }
  3105. }
  3106. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3107. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3108. //把店铺排序和技能排序分类
  3109. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3110. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3111. if (design_dt.Rows.Count > 0)
  3112. {
  3113. Dictionary<string, string> design = null;
  3114. List<string> shopIds = null;
  3115. foreach (DataRow row in design_dt.Rows)
  3116. {
  3117. if ("0".Equals(row["designId"].ToString()))
  3118. {
  3119. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3120. {
  3121. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3122. }
  3123. else
  3124. {
  3125. shopIds = new List<string>();
  3126. }
  3127. shopIds.Add(row["shopId"].ToString());
  3128. shop_orders[row["orders"].ToString()] = shopIds;
  3129. }
  3130. else
  3131. {
  3132. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3133. {
  3134. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3135. }
  3136. else
  3137. {
  3138. design = new Dictionary<string, string>();
  3139. }
  3140. design[row["orders"].ToString()] = row["designId"].ToString();
  3141. design_orders[row["shopId"].ToString()] = design;
  3142. }
  3143. }
  3144. //处理成key value后根据key排序
  3145. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3146. foreach (List<string> val in shop_orders.Values)
  3147. {
  3148. if (val != null)
  3149. {
  3150. foreach (string key in val)
  3151. {
  3152. if (design_orders.ContainsKey(key.ToString()))
  3153. {
  3154. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3155. }
  3156. }
  3157. }
  3158. }
  3159. }
  3160. //校验哪个优先级有订单
  3161. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3162. foreach (string key in shop_orders.Keys)
  3163. {
  3164. List<string> ids = null;
  3165. shop_orders.TryGetValue(key, out ids);
  3166. //id为shopid
  3167. foreach (string id in ids)
  3168. {
  3169. Dictionary<string, int> list = null;
  3170. Dictionary<string, string> desing = null;
  3171. map.TryGetValue(id, out list);
  3172. design_orders.TryGetValue(id, out desing);
  3173. if (list != null && desing != null)
  3174. {
  3175. foreach (var item in desing)
  3176. {
  3177. int count = 0;
  3178. if (list.ContainsKey(item.Value))
  3179. {
  3180. list.TryGetValue(item.Value, out count);
  3181. if (count > 0)
  3182. {
  3183. designIds[id] = item.Value;
  3184. break;
  3185. }
  3186. }
  3187. }
  3188. }
  3189. }
  3190. if (designIds.Count > 0)
  3191. {
  3192. break;
  3193. }
  3194. }
  3195. DataTable table = new DataTable();
  3196. table.Columns.Add("tid", typeof(string));
  3197. table.Columns.Add("ctid", typeof(string));
  3198. table.Columns.Add("seller_nick", typeof(string));
  3199. table.Columns.Add("productName", typeof(string));
  3200. table.Columns.Add("pay_time", typeof(string));
  3201. table.Columns.Add("seller_memo", typeof(string));
  3202. if (designIds.Count > 0)
  3203. {
  3204. string shopId = "";
  3205. string productId = "";
  3206. foreach (var designInfo in designIds)
  3207. {
  3208. shopId = designInfo.Key;
  3209. productId = designInfo.Value;
  3210. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3211. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3212. if (dt.Rows.Count > 0)
  3213. {
  3214. foreach (DataRow row in dt.Rows)
  3215. {
  3216. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3217. {
  3218. DataRow data = table.NewRow();
  3219. data["ctid"] = row["ctid"].ToString();
  3220. data["tid"] = row["tid"].ToString();
  3221. data["seller_nick"] = ceErpShop.ShopName;
  3222. data["pay_time"] = row["pay_time"].ToString();
  3223. data["seller_memo"] = row["seller_memo"].ToString();
  3224. data["productName"] = ceErpProduct.PType;
  3225. table.Rows.Add(data);
  3226. }
  3227. }
  3228. }
  3229. }
  3230. }
  3231. writeGridDataTableJson(table.Rows.Count, table);
  3232. }
  3233. private object rushLockObject = new object();
  3234. public void set_erp_grabingorder()
  3235. {
  3236. if (UrlPostParmsCheck("ctid"))
  3237. {
  3238. int total = CurrentUser.User.Person.Total;
  3239. int userId = CurrentUser.User.ID;
  3240. int noFinish = CurrentUser.User.Person.NoFinish;
  3241. int finalization = CurrentUser.User.Person.Finalization;
  3242. string eids = GetPostString("ctid");
  3243. string key = "RushKey_" + userId;
  3244. int count = 0;
  3245. if (erpRedis.RedisHelper.KeyExists(key))
  3246. {
  3247. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3248. if (redisCount != null)
  3249. {
  3250. count = Convert.ToInt32(redisCount);
  3251. }
  3252. }
  3253. if (count >= total)
  3254. {
  3255. returnErrorMsg("半小时内已经抢" + total + "单");
  3256. return;
  3257. }
  3258. string[] ctidlist = eids.Split(',');
  3259. if (count + ctidlist.Length > total)
  3260. {
  3261. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3262. return;
  3263. }
  3264. int itag = 0;
  3265. lock (rushLockObject)
  3266. {
  3267. if (ctidlist.Length > 0)
  3268. {
  3269. string[] dtList = new string[ctidlist.Length];
  3270. for (int i = 0; i < ctidlist.Length; i++)
  3271. {
  3272. dtList[i] = "'" + ctidlist[i] + "'";
  3273. }
  3274. 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"));
  3275. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3276. if (dt_user.Rows.Count > 0)
  3277. {
  3278. int doing = 0;//未定稿
  3279. int finish = 0;//已完成
  3280. foreach (DataRow dr in dt_user.Rows)
  3281. {
  3282. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3283. {
  3284. doing++;
  3285. }
  3286. else
  3287. {
  3288. finish++;
  3289. }
  3290. }
  3291. if (doing >= noFinish)
  3292. {
  3293. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3294. return;
  3295. }
  3296. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3297. {
  3298. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3299. return;
  3300. }
  3301. }
  3302. //校验选择单子状态
  3303. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3304. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3305. if (dt.Rows.Count > 0)
  3306. {
  3307. List<string> list = new List<string>();
  3308. foreach (DataRow dr in dt.Rows)
  3309. {
  3310. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3311. {
  3312. list.Add(dr["ctid"].ToString());
  3313. }
  3314. }
  3315. if (list.Count > 0)
  3316. {
  3317. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3318. return;
  3319. }
  3320. }
  3321. foreach (string ctid in ctidlist)
  3322. {
  3323. CeErpTradeCell entity = null;
  3324. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3325. if (entity != null)
  3326. {
  3327. entity.OrderState = 3;
  3328. entity.DesignUserId = CurrentUser.UserID;
  3329. entity.WaitDesignTime = DateTime.Now;
  3330. entity.StartDesignTime = DateTime.Now;
  3331. entity.Update();
  3332. commonHelper.UpdateRelationOrder(entity.ctid);
  3333. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3334. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3335. itag++;
  3336. }
  3337. }
  3338. }
  3339. }
  3340. count += ctidlist.Length;
  3341. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3342. if (itag == 0)
  3343. returnErrorMsg("没有找到相关订单");
  3344. else
  3345. returnSuccessMsg("抢单成功!");
  3346. return;
  3347. }
  3348. }
  3349. public void get_erp_waitorderlist()
  3350. {
  3351. DataStruct dStruct = GetPostStruct();
  3352. List<string> lw = new List<string>();
  3353. string tid = GetPostString("ctid");
  3354. if (tid.Length > 0)
  3355. {
  3356. string select_tid = getTidByCtid(tid);
  3357. lw.Add(string.Format("tid='{0}'", select_tid));
  3358. }
  3359. string shopname = GetPostString("shopname");
  3360. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3361. string buyernick = GetPostString("buyer_nick");
  3362. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3363. string customer = GetPostString("customer");
  3364. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3365. string design = GetPostString("design");
  3366. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3367. string orderState = GetPostString("orderState");
  3368. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3369. string supplier = GetPostString("supplier");
  3370. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3371. string sellermemo = GetPostString("seller_memo");
  3372. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3373. string otherMemo = GetPostString("otherMemo");
  3374. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3375. string address = GetPostString("address");
  3376. 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));
  3377. string date1 = GetPostString("date1");
  3378. string date2 = GetPostString("date2");
  3379. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3380. if (dw.Length > 0) lw.Add(dw);
  3381. string price1 = GetPostString("price1");
  3382. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3383. string price2 = GetPostString("price2");
  3384. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3385. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3386. lw.Add(string.Format("IsSample != 2 "));
  3387. lw.Add(string.Format("OrderState = 5 "));
  3388. lw.Add(string.Format("IsRefund<={0}", 1));
  3389. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3390. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3391. string pagesize = GetPostString("pagesize");
  3392. if (pagesize != null)
  3393. {
  3394. dStruct.PageSize = 200;
  3395. }
  3396. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3397. if (dt != null)
  3398. {
  3399. foreach (DataRow dr in dt.Rows)
  3400. {
  3401. 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();
  3402. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3403. {
  3404. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3405. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3406. entity.SupplierId = suid;
  3407. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3408. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3409. entity.Update();
  3410. }
  3411. }
  3412. }
  3413. writeGridDataTableJson(dStruct.TotalCount, dt);
  3414. }
  3415. public void get_erp_supplierwaitorderlist()
  3416. {
  3417. DataStruct dStruct = GetPostStruct();
  3418. List<string> lw = new List<string>();
  3419. string tid = GetPostString("ctid");
  3420. if (tid.Length > 0)
  3421. {
  3422. string select_tid = getTidByCtid(tid);
  3423. lw.Add(string.Format("tid='{0}'", select_tid));
  3424. }
  3425. string shopname = GetPostString("shopname");
  3426. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3427. string sellermemo = GetPostString("seller_memo");
  3428. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3429. string date1 = GetPostString("date1");
  3430. string date2 = GetPostString("date2");
  3431. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3432. if (dw.Length > 0) lw.Add(dw);
  3433. lw.Add(string.Format("OrderState = 5 "));
  3434. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3435. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3436. {
  3437. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3438. }
  3439. string supplier = GetPostString("supplier");
  3440. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3441. {
  3442. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3443. }
  3444. lw.Add(string.Format("IsRefund<={0}", 1));
  3445. dStruct.Order = "FinishDesignTime desc";
  3446. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3447. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3448. if (dt != null)
  3449. {
  3450. foreach (DataRow dr in dt.Rows)
  3451. {
  3452. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3453. }
  3454. }
  3455. writeGridDataTableJson(dStruct.TotalCount, dt);
  3456. }
  3457. public void upd_erp_verifytosupplier()
  3458. {
  3459. if (UrlPostParmsCheck("ctid"))
  3460. {
  3461. string eids = GetPostString("ctid");
  3462. CeErpTradeCell entity = null;
  3463. string[] eidsList = eids.Split(',');
  3464. if (eidsList.Length <= 0)
  3465. {
  3466. returnErrorMsg("订单号不能空");
  3467. return;
  3468. }
  3469. List<string> tLst = new List<string>();
  3470. foreach (string ctidstr in eidsList)
  3471. {
  3472. tLst.Add("'" + ctidstr + "'");
  3473. CeErpDataSendOrderInfo.createObject(ctidstr);
  3474. }
  3475. string needtids = string.Join(",", tLst.ToArray());
  3476. StringBuilder sql = new StringBuilder();
  3477. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3478. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3479. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3480. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3481. returnSuccessMsg("操作成功!");
  3482. return;
  3483. /**foreach (string ctidstr in eidsList)
  3484. {
  3485. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3486. if (entity != null)
  3487. {
  3488. if (entity.SupplierId == 0)
  3489. {
  3490. continue;
  3491. }
  3492. entity.IsVerifyToSupplier = true;
  3493. if (entity.IsReturn == 1) //1是供应商打回
  3494. {
  3495. entity.IsReturn = 0;
  3496. }
  3497. entity.FinishPlaceTime = DateTime.Now;
  3498. entity.PlaceUserId = CurrentUser.UserID;
  3499. entity.Update();
  3500. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3501. }
  3502. }
  3503. returnSuccessMsg("操作成功!");
  3504. return;**/
  3505. }
  3506. }
  3507. public void upd_erp_supplierback()
  3508. {
  3509. if (UrlPostParmsCheck("ctid"))
  3510. {
  3511. string eid = GetPostString("ctid");
  3512. string reason = GetPostString("returnreason");
  3513. CeErpTradeCell entity = null;
  3514. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3515. if (entity != null)
  3516. {
  3517. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3518. {
  3519. string key = "return_order_" + entity.SupplierId;
  3520. List<string> list = new List<string>();
  3521. if (RedisHelper.HasKey(key))
  3522. {
  3523. object data = RedisHelper.StringGet(key);
  3524. list = Convert.ToString(data).Split(',').ToList();
  3525. }
  3526. list.Add(eid);
  3527. RedisHelper.StringSet(key, string.Join(",", list));
  3528. }
  3529. entity.IsVerifyToSupplier = false;
  3530. entity.IsReturn = 1;
  3531. entity.ReturnTime = DateTime.Now;
  3532. entity.ReturnReason = reason;
  3533. if (entity.OrderState == 6)
  3534. {
  3535. entity.OrderState = 5;
  3536. }
  3537. entity.Update();
  3538. CeErpSukuraData.createInfo(entity.ctid, 5);
  3539. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3540. returnSuccessMsg("操作成功!");
  3541. return;
  3542. }
  3543. returnErrorMsg("找不到订单记录");
  3544. }
  3545. }
  3546. public void upd_erp_toaftersaleorder()
  3547. {
  3548. if (UrlPostParmsCheck("ctid"))
  3549. {
  3550. string eid = GetPostString("ctid");
  3551. string reason = GetPostString("returnreason");
  3552. CeErpTradeCell entity = null;
  3553. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3554. if (entity != null)
  3555. {
  3556. if (entity.isAfterSaleOrder != 1)
  3557. {
  3558. returnErrorMsg("带S的售后单才能打回给售后");
  3559. return;
  3560. }
  3561. if (entity.OrderState >= 5)
  3562. {
  3563. returnErrorMsg("已经设计完成了不能打回给售后");
  3564. return;
  3565. }
  3566. entity.OrderState = 0;
  3567. entity.IsReturn = 3;
  3568. entity.ReturnTime = DateTime.Now;
  3569. entity.UpdateTime = DateTime.Now;
  3570. entity.ReturnReason = reason;
  3571. entity.Update();
  3572. CeErpSukuraData.createInfo(entity.ctid, 5);
  3573. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3574. returnSuccessMsg("操作成功!");
  3575. return;
  3576. }
  3577. returnErrorMsg("找不到订单记录");
  3578. }
  3579. }
  3580. public void upd_erp_aftersaletodesign()
  3581. {
  3582. if (UrlPostParmsCheck("ctid"))
  3583. {
  3584. string eid = GetPostString("ctid");
  3585. CeErpTradeCell entity = null;
  3586. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3587. if (entity != null)
  3588. {
  3589. entity.OrderState = 3;
  3590. entity.IsReturn = 0;
  3591. entity.UpdateTime = DateTime.Now;
  3592. entity.Update();
  3593. CeErpSukuraData.createInfo(entity.ctid, 5);
  3594. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3595. returnSuccessMsg("操作成功!");
  3596. return;
  3597. }
  3598. returnErrorMsg("找不到订单记录");
  3599. }
  3600. }
  3601. public void assign_erp_supplier()
  3602. {
  3603. if (UrlPostParmsCheck("ctid"))
  3604. {
  3605. string eids = GetPostString("ctid");
  3606. int sid = GetPostInt("SupplierName");
  3607. string fromTag = GetPostString("tag");
  3608. string[] eidList = eids.Split(',');
  3609. if (eidList.Length <= 0)
  3610. {
  3611. returnErrorMsg("指派不能为空");
  3612. return;
  3613. }
  3614. string errMsg = "";
  3615. string suname = commonHelper.getSupplierNameById(sid);
  3616. foreach (string ctid in eidList)
  3617. {
  3618. CeErpTradeCell entity = null;
  3619. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3620. if (entity != null)
  3621. {
  3622. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3623. {
  3624. errMsg += (ctid + "指派失败!!!");
  3625. continue;
  3626. }
  3627. entity.SupplierId = sid;
  3628. entity.Update();
  3629. commonHelper.UpdateRelationOrder(entity.ctid);
  3630. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3631. if (entity.OrderState >= 6)
  3632. {
  3633. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3634. //{
  3635. // string msl = entity.MakeSupplier;
  3636. // string[] mslist = msl.Split(',');
  3637. // 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);
  3638. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3639. //}
  3640. //else
  3641. //{
  3642. StringBuilder sql = new StringBuilder();
  3643. 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);
  3644. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3645. //}
  3646. }
  3647. }
  3648. else
  3649. {
  3650. continue;
  3651. }
  3652. }
  3653. if (errMsg.Length > 0)
  3654. {
  3655. returnErrorMsg(errMsg);
  3656. return;
  3657. }
  3658. returnSuccessMsg("操作成功!");
  3659. return;
  3660. }
  3661. }
  3662. public void assign_erp_makesupplier()
  3663. {
  3664. if (UrlPostParmsCheck("ctid"))
  3665. {
  3666. string eids = GetPostString("ctid");
  3667. string sname = GetPostString("SupplierName");
  3668. string[] eidList = eids.Split(',');
  3669. if (eidList.Length <= 0)
  3670. {
  3671. returnErrorMsg("指派不能为空");
  3672. return;
  3673. }
  3674. List<string> tLst = new List<string>();
  3675. foreach (string ctid in eidList)
  3676. {
  3677. CeErpTradeCell entity = null;
  3678. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3679. if (entity != null)
  3680. {
  3681. entity.MakeSupplier = sname;
  3682. entity.Update();
  3683. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3684. tLst.Add("'" + ctid + "'");
  3685. }
  3686. else
  3687. {
  3688. continue;
  3689. }
  3690. }
  3691. string ctids = string.Join(",", tLst.ToArray());
  3692. StringBuilder sql2 = new StringBuilder();
  3693. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3694. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3695. returnSuccessMsg("操作成功!");
  3696. return;
  3697. }
  3698. }
  3699. public void ins_erp_returnreason()
  3700. {
  3701. if (UrlPostParmsCheck("ctid"))
  3702. {
  3703. string eid = GetPostString("ctid");
  3704. CeErpTradeCell entity = null;
  3705. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3706. string userpost = CurrentUser.UserPost.Post.Code;
  3707. if (entity != null)
  3708. {
  3709. bool isPlace = false;
  3710. if (entity.OrderState > 6)
  3711. {
  3712. returnErrorMsg("已发货无法打回!");
  3713. return;
  3714. }
  3715. if (entity.OrderState == 6)
  3716. {
  3717. isPlace = true;
  3718. }
  3719. bool isNeedUpdateCell2 = false;
  3720. if (entity.OrderState >= 6)
  3721. {
  3722. isNeedUpdateCell2 = true;
  3723. }
  3724. int returnTag = 2;
  3725. if (userpost == "Supplier")
  3726. {
  3727. returnTag = 1;
  3728. }
  3729. int toType = GetPostInt("totype");
  3730. string fromType = "3";
  3731. if (entity.OrderState < 5)
  3732. {
  3733. fromType = "3";
  3734. }
  3735. else
  3736. {
  3737. fromType = "4";
  3738. }
  3739. if (entity.IsXianHuo == 0)
  3740. {
  3741. if (returnTag == 2)
  3742. {
  3743. if (toType == 1)
  3744. {
  3745. entity.OrderState = 0;
  3746. entity.ReturnUserType = 1;
  3747. string clearman = GetPostString("clearman");
  3748. if (!string.IsNullOrEmpty(clearman))
  3749. {
  3750. entity.DesignUserId = 0;
  3751. }
  3752. }
  3753. else
  3754. {
  3755. entity.OrderState = 3;
  3756. entity.ReturnUserType = 2;
  3757. }
  3758. entity.IsReadTag = 1;
  3759. }
  3760. else if (returnTag == 1)
  3761. {
  3762. entity.OrderState = 5;
  3763. }
  3764. entity.IsVerifyToSupplier = false;
  3765. }
  3766. if (entity.IsXianHuo == 1)
  3767. {
  3768. entity.OrderState = 5;
  3769. }
  3770. entity.UnusualTag = 0;
  3771. entity.UnusualTime = null;
  3772. entity.UnusualCon = "";
  3773. entity.IsReturn = returnTag;
  3774. entity.ReturnTime = DateTime.Now;
  3775. entity.UpdateTime = DateTime.Now;
  3776. entity.ReturnReason = GetPostString("returnreason");
  3777. entity.Update();
  3778. if (entity.OrderState == 3)
  3779. {
  3780. ApiVo apiVo = new ApiVo();
  3781. apiVo.orderNumber = entity.ctid;
  3782. apiVo.actionName = "rebutDesign";
  3783. apiVo.orderRemarks = entity.ReturnReason;
  3784. designHelper.API_WorkCore(apiVo);//rebutDesign
  3785. }
  3786. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3787. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3788. {
  3789. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3790. }
  3791. CeErpSukuraData.createInfo(entity.ctid, 5);
  3792. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3793. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3794. if (isPlace)
  3795. {
  3796. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3797. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3798. if (dth != null && dth.Rows.Count > 0)
  3799. {
  3800. dataSendOrderBean dataSendOrderBean = null;
  3801. foreach (DataRow item in dth.Rows)
  3802. {
  3803. try
  3804. {
  3805. dataSendOrderBean = new dataSendOrderBean();
  3806. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3807. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3808. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3809. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3810. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3811. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3812. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3813. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3814. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3815. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3816. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3817. dataSendOrderBean.Radio1723534706288 = "打回";
  3818. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3819. if (result != null)
  3820. {
  3821. if ("0".Equals(result.errcode))
  3822. {
  3823. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3824. }
  3825. else
  3826. {
  3827. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3828. }
  3829. }
  3830. }
  3831. catch (Exception ex)
  3832. {
  3833. }
  3834. }
  3835. }
  3836. }
  3837. if (isNeedUpdateCell2)
  3838. {
  3839. if (entity.MakeSupplier.IndexOf(",") != -1)
  3840. {
  3841. StringBuilder sql2 = new StringBuilder();
  3842. 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);
  3843. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3844. }
  3845. else
  3846. {
  3847. StringBuilder sql2 = new StringBuilder();
  3848. 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);
  3849. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3850. }
  3851. }
  3852. returnSuccessMsg("操作成功!");
  3853. return;
  3854. }
  3855. returnErrorMsg("找不到订单记录");
  3856. }
  3857. }
  3858. public void cyt_erp_returnreason()
  3859. {
  3860. if (UrlPostParmsCheck("ctid"))
  3861. {
  3862. string eid = GetPostString("ctid");
  3863. CeErpTradeCell entity = null;
  3864. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3865. string userpost = CurrentUser.UserPost.Post.Code;
  3866. if (entity != null)
  3867. {
  3868. if (entity.OrderState > 6)
  3869. {
  3870. returnErrorMsg("已发货无法打回!");
  3871. return;
  3872. }
  3873. JObject jsonObject = new JObject
  3874. {
  3875. { "Userid", "77886" },
  3876. { "Pwd", "lt666888" },
  3877. { "LTOrderId",eid }
  3878. };
  3879. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3880. JObject jsonObjects = JObject.Parse(response);
  3881. string msg = (string)jsonObjects["msg"];
  3882. if (msg != "取消成功")
  3883. {
  3884. returnErrorMsg(msg);
  3885. return;
  3886. }
  3887. bool isNeedUpdateCell2 = false;
  3888. if (entity.OrderState >= 6)
  3889. {
  3890. isNeedUpdateCell2 = true;
  3891. }
  3892. int returnTag = 2;
  3893. if (userpost == "Supplier")
  3894. {
  3895. returnTag = 1;
  3896. }
  3897. if (entity.IsXianHuo == 0)
  3898. {
  3899. if (returnTag == 2)
  3900. {
  3901. int toType = GetPostInt("totype");
  3902. if (toType == 1)
  3903. {
  3904. entity.OrderState = 0;
  3905. entity.ReturnUserType = 1;
  3906. }
  3907. else
  3908. {
  3909. entity.OrderState = 4;
  3910. entity.ReturnUserType = 2;
  3911. }
  3912. entity.IsReadTag = 1;
  3913. }
  3914. else if (returnTag == 1)
  3915. {
  3916. entity.OrderState = 5;
  3917. }
  3918. entity.IsVerifyToSupplier = false;
  3919. }
  3920. entity.UnusualTag = 0;
  3921. entity.UnusualTime = null;
  3922. entity.UnusualCon = "";
  3923. entity.IsReturn = returnTag;
  3924. entity.ReturnTime = DateTime.Now;
  3925. entity.ReturnReason = GetPostString("returnreason");
  3926. entity.Update();
  3927. if (entity.OrderState == 4)
  3928. {
  3929. ApiVo apiVo = new ApiVo();
  3930. apiVo.orderNumber = entity.ctid;
  3931. apiVo.actionName = "rebutDesign";
  3932. apiVo.orderRemarks = entity.ReturnReason;
  3933. designHelper.API_WorkCore(apiVo);//rebutDesign
  3934. }
  3935. CeErpSukuraData.createInfo(entity.ctid, 5);
  3936. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3937. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3938. if (isNeedUpdateCell2)
  3939. {
  3940. if (entity.MakeSupplier.IndexOf(",") != -1)
  3941. {
  3942. StringBuilder sql2 = new StringBuilder();
  3943. 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);
  3944. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3945. }
  3946. else
  3947. {
  3948. StringBuilder sql2 = new StringBuilder();
  3949. 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);
  3950. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3951. }
  3952. }
  3953. returnSuccessMsg("操作成功!");
  3954. return;
  3955. }
  3956. returnErrorMsg("找不到订单记录");
  3957. }
  3958. }
  3959. public void upd_erp_xianhuoreturntag()
  3960. {
  3961. if (UrlPostParmsCheck("ctid"))
  3962. {
  3963. string eids = GetPostString("ctid");
  3964. string[] ctids = eids.Split(',');
  3965. foreach (string ctid in ctids)
  3966. {
  3967. CeErpTradeCell entity = null;
  3968. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3969. if (entity != null)
  3970. {
  3971. entity.IsReturn = 0;
  3972. entity.Update();
  3973. CeErpSukuraData.createInfo(entity.ctid, 5);
  3974. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3975. }
  3976. }
  3977. returnSuccessMsg("操作成功!");
  3978. return;
  3979. }
  3980. }
  3981. public void get_erp_waitdeliverylist()
  3982. {
  3983. DataStruct dStruct = GetPostStruct();
  3984. List<string> lw = new List<string>();
  3985. string tid = GetPostString("ctid");
  3986. if (tid.Length > 0)
  3987. {
  3988. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3989. if (tid.Length > 5)
  3990. {
  3991. List<string> tids = getTidByCtidLike(tid);
  3992. if (tids.Count > 0 && tids.Count < 10)
  3993. {
  3994. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3995. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  3996. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  3997. {
  3998. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  3999. }
  4000. }
  4001. }
  4002. lw.Add(tid_sql);
  4003. }
  4004. string shopname = GetPostString("shopname");
  4005. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4006. string buyernick = GetPostString("buyer_nick");
  4007. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4008. //if (tid.Length == 0 && buyernick.Length == 0)
  4009. //{
  4010. // lw.Add(string.Format("IsRefund<={0}", 1));
  4011. //}
  4012. string customer = GetPostString("customer");
  4013. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4014. string design = GetPostString("design");
  4015. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4016. string orderState = GetPostString("orderState");
  4017. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4018. string address = GetPostString("address");
  4019. 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));
  4020. string sellermemo = GetPostString("seller_memo");
  4021. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4022. string supplier = GetPostString("supplier");
  4023. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4024. string OrderArea = GetPostString("order_area");
  4025. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4026. string placedate1 = GetPostString("placedate1");
  4027. string placedate2 = GetPostString("placedate2");
  4028. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4029. if (fdw.Length > 0) lw.Add(fdw);
  4030. string price1 = GetPostString("price1");
  4031. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4032. string price2 = GetPostString("price2");
  4033. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4034. string unusualCon = GetPostString("unusualcon");
  4035. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4036. string otherMemo = GetPostString("otherMemo");
  4037. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4038. string posTag = CurrentUser.UserPost.Post.Code;
  4039. if (posTag == "Supplier")
  4040. {
  4041. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4042. }
  4043. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4044. lw.Add(string.Format("type != 'PDD' "));
  4045. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4046. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4047. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4048. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4049. writeGridDataTableJson(dStruct.TotalCount, dt);
  4050. }
  4051. public void get_erp_changedeliverylist()
  4052. {
  4053. DataStruct dStruct = GetPostStruct();
  4054. List<string> lw = new List<string>();
  4055. string tid = GetPostString("ctid");
  4056. if (tid.Length > 0)
  4057. {
  4058. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4059. if (tid.Length > 5)
  4060. {
  4061. List<string> tids = getTidByCtidLike(tid);
  4062. if (tids.Count > 0 && tids.Count < 10)
  4063. {
  4064. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4065. }
  4066. }
  4067. lw.Add(tid_sql);
  4068. }
  4069. string shopname = GetPostString("shopname");
  4070. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4071. string buyernick = GetPostString("buyer_nick");
  4072. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4073. //if (tid.Length == 0 && buyernick.Length == 0)
  4074. //{
  4075. // lw.Add(string.Format("IsRefund<={0}", 1));
  4076. //}
  4077. string customer = GetPostString("customer");
  4078. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4079. string design = GetPostString("design");
  4080. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4081. string orderState = GetPostString("orderState");
  4082. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4083. string address = GetPostString("address");
  4084. 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));
  4085. string sellermemo = GetPostString("seller_memo");
  4086. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4087. string supplier = GetPostString("supplier");
  4088. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4089. string OrderArea = GetPostString("order_area");
  4090. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4091. string placedate1 = GetPostString("placedate1");
  4092. string placedate2 = GetPostString("placedate2");
  4093. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4094. if (fdw.Length > 0) lw.Add(fdw);
  4095. string price1 = GetPostString("price1");
  4096. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4097. string price2 = GetPostString("price2");
  4098. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4099. string unusualCon = GetPostString("unusualcon");
  4100. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4101. string otherMemo = GetPostString("otherMemo");
  4102. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4103. string posTag = CurrentUser.UserPost.Post.Code;
  4104. if (posTag == "Supplier")
  4105. {
  4106. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4107. }
  4108. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4109. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4110. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4111. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4112. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4113. /*if (tid.Length > 0)
  4114. {
  4115. List<string> tids = new List<string>();
  4116. if (dt != null && dt.Rows.Count > 0)
  4117. {
  4118. foreach (DataRow item in dt.Rows)
  4119. {
  4120. tids.Add("'" + item["tid"] + "'");
  4121. }
  4122. }
  4123. if (tids.Count > 0)
  4124. {
  4125. lw.RemoveAt(0);
  4126. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4127. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4128. dt = WebCache.GetData("view_erptradecell", dStruct);
  4129. }
  4130. }*/
  4131. writeGridDataTableJson(dStruct.TotalCount, dt);
  4132. }
  4133. public void get_erp_pddderiving()
  4134. {
  4135. DataStruct dStruct = GetPostStruct();
  4136. List<string> lw = new List<string>();
  4137. string tid = GetPostString("ctid");
  4138. if (tid.Length > 0)
  4139. {
  4140. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4141. if (tid.Length > 5)
  4142. {
  4143. List<string> tids = getTidByCtidLike(tid);
  4144. if (tids.Count > 0 && tids.Count < 10)
  4145. {
  4146. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4147. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4148. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4149. {
  4150. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4151. }
  4152. }
  4153. }
  4154. lw.Add(tid_sql);
  4155. }
  4156. string shopname = GetPostString("shopname");
  4157. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4158. string buyernick = GetPostString("buyer_nick");
  4159. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4160. //if (tid.Length == 0 && buyernick.Length == 0)
  4161. //{
  4162. // lw.Add(string.Format("IsRefund<={0}", 1));
  4163. //}
  4164. string customer = GetPostString("customer");
  4165. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4166. string design = GetPostString("design");
  4167. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4168. string orderState = GetPostString("orderState");
  4169. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4170. string address = GetPostString("address");
  4171. 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));
  4172. string sellermemo = GetPostString("seller_memo");
  4173. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4174. string supplier = GetPostString("supplier");
  4175. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4176. string OrderArea = GetPostString("order_area");
  4177. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4178. string placedate1 = GetPostString("placedate1");
  4179. string placedate2 = GetPostString("placedate2");
  4180. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4181. if (fdw.Length > 0) lw.Add(fdw);
  4182. string price1 = GetPostString("price1");
  4183. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4184. string price2 = GetPostString("price2");
  4185. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4186. string unusualCon = GetPostString("unusualcon");
  4187. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4188. string posTag = CurrentUser.UserPost.Post.Code;
  4189. if (posTag == "Supplier")
  4190. {
  4191. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4192. }
  4193. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4194. lw.Add(string.Format("type = 'PDD' "));
  4195. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4196. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4197. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4198. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4199. /*if (tid.Length > 0)
  4200. {
  4201. List<string> tids = new List<string>();
  4202. if (dt != null && dt.Rows.Count > 0)
  4203. {
  4204. foreach (DataRow item in dt.Rows)
  4205. {
  4206. tids.Add("'" + item["tid"] + "'");
  4207. }
  4208. }
  4209. if (tids.Count > 0)
  4210. {
  4211. lw.RemoveAt(0);
  4212. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4213. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4214. dt = WebCache.GetData("view_erptradecell", dStruct);
  4215. }
  4216. }*/
  4217. writeGridDataTableJson(dStruct.TotalCount, dt);
  4218. }
  4219. public void get_erp_jdderiving()
  4220. {
  4221. DataStruct dStruct = GetPostStruct();
  4222. List<string> lw = new List<string>();
  4223. string tid = GetPostString("ctid");
  4224. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4225. string shopname = GetPostString("shopname");
  4226. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4227. string buyernick = GetPostString("buyer_nick");
  4228. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4229. //if (tid.Length == 0 && buyernick.Length == 0)
  4230. //{
  4231. // lw.Add(string.Format("IsRefund<={0}", 1));
  4232. //}
  4233. string customer = GetPostString("customer");
  4234. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4235. string design = GetPostString("design");
  4236. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4237. string orderState = GetPostString("orderState");
  4238. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4239. string address = GetPostString("address");
  4240. 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));
  4241. string sellermemo = GetPostString("seller_memo");
  4242. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4243. string supplier = GetPostString("supplier");
  4244. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4245. string OrderArea = GetPostString("order_area");
  4246. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4247. string placedate1 = GetPostString("placedate1");
  4248. string placedate2 = GetPostString("placedate2");
  4249. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4250. if (fdw.Length > 0) lw.Add(fdw);
  4251. string price1 = GetPostString("price1");
  4252. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4253. string price2 = GetPostString("price2");
  4254. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4255. string unusualCon = GetPostString("unusualcon");
  4256. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4257. string posTag = CurrentUser.UserPost.Post.Code;
  4258. if (posTag == "Supplier")
  4259. {
  4260. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4261. }
  4262. lw.Add(string.Format("OrderState = 6 "));
  4263. lw.Add(string.Format("type = 'JD' "));
  4264. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4265. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4266. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4267. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4268. writeGridDataTableJson(dStruct.TotalCount, dt);
  4269. }
  4270. public void get_erp_demoorderlist()
  4271. {
  4272. DataStruct dStruct = GetPostStruct();
  4273. List<string> lw = new List<string>();
  4274. string tid = GetPostString("ctid");
  4275. if (tid.Length > 0)
  4276. {
  4277. string select_tid = getTidByCtid(tid);
  4278. lw.Add(string.Format("tid='{0}'", select_tid));
  4279. }
  4280. string shopname = GetPostString("shopname");
  4281. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4282. string buyernick = GetPostString("buyer_nick");
  4283. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4284. string customer = GetPostString("customer");
  4285. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4286. string design = GetPostString("design");
  4287. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4288. string orderState = GetPostString("orderState");
  4289. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4290. string address = GetPostString("address");
  4291. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4292. string sellermemo = GetPostString("seller_memo");
  4293. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4294. string supplier = GetPostString("supplier");
  4295. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4296. string OrderArea = GetPostString("order_area");
  4297. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4298. string date1 = GetPostString("date1");
  4299. string date2 = GetPostString("date2");
  4300. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4301. if (dw.Length > 0) lw.Add(dw);
  4302. string price1 = GetPostString("price1");
  4303. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4304. string price2 = GetPostString("price2");
  4305. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4306. string posTag = CurrentUser.UserPost.Post.Code;
  4307. if (posTag == "Supplier")
  4308. {
  4309. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4310. }
  4311. //lw.Add(string.Format("OrderState = 6 "));
  4312. lw.Add(string.Format("IsSample={0}", 3));
  4313. lw.Add(string.Format("IsRefund<={0}", 1));
  4314. dStruct.Order = "pay_time desc";
  4315. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4316. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4317. writeGridDataTableJson(dStruct.TotalCount, dt);
  4318. }
  4319. public void save_erp_checkmemo()
  4320. {
  4321. if (UrlPostParmsCheck("ctid"))
  4322. {
  4323. string ctid = GetPostString("ctid");
  4324. CeErpTradeCell entity = null;
  4325. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4326. if (entity != null)
  4327. {
  4328. entity.CheckMemo = GetPostString("CheckMemo");
  4329. entity.Update();
  4330. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4331. if (trade != null)
  4332. {
  4333. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4334. }
  4335. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4336. returnSuccessMsg("保存成功!");
  4337. return;
  4338. }
  4339. returnErrorMsg("找不到记录");
  4340. }
  4341. }
  4342. public void get_erp_returnlist()
  4343. {
  4344. DataStruct dStruct = GetPostStruct();
  4345. List<string> lw = new List<string>();
  4346. string tid = GetPostString("ctid");
  4347. if (tid.Length > 0)
  4348. {
  4349. string select_tid = getTidByCtid(tid);
  4350. lw.Add(string.Format("tid='{0}'", select_tid));
  4351. }
  4352. string shopname = GetPostString("shopname");
  4353. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4354. string buyernick = GetPostString("buyer_nick");
  4355. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4356. string customer = GetPostString("customer");
  4357. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4358. string design = GetPostString("design");
  4359. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4360. string orderState = GetPostString("orderState");
  4361. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4362. string address = GetPostString("address");
  4363. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4364. string sellermemo = GetPostString("seller_memo");
  4365. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4366. string supplier = GetPostString("supplier");
  4367. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4368. string date1 = GetPostString("date1");
  4369. string date2 = GetPostString("date2");
  4370. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4371. if (dw.Length > 0) lw.Add(dw);
  4372. string bdate1 = GetPostString("backdate1");
  4373. string bdate2 = GetPostString("backdate2");
  4374. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4375. if (dw_back.Length > 0) lw.Add(dw_back);
  4376. string price1 = GetPostString("price1");
  4377. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4378. string price2 = GetPostString("price2");
  4379. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4380. lw.Add(string.Format("IsReturn>0"));
  4381. lw.Add(string.Format("IsXianHuo=0"));
  4382. lw.Add(string.Format("IsReturn!=3"));
  4383. string backtype = GetPostString("backtype");
  4384. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4385. dStruct.Order = "FinishDesignTime desc";
  4386. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4387. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4388. writeGridDataTableJson(dStruct.TotalCount, dt);
  4389. }
  4390. public void get_erp_today_sumreturn()
  4391. {
  4392. DataStruct dStruct = GetPostStruct();
  4393. List<string> lw = new List<string>();
  4394. string bdate1 = GetPostString("returnTimeS");
  4395. string bdate2 = GetPostString("returnTimeE");
  4396. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4397. if (dw_back.Length > 0) lw.Add(dw_back);
  4398. lw.Add(string.Format("IsReturn=0"));
  4399. lw.Add(string.Format("IsXianHuo=0"));
  4400. string mainWhere = string.Join(" and ", lw.ToArray());
  4401. string sql = "";
  4402. if (dw_back.Length > 0)
  4403. {
  4404. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4405. }
  4406. else
  4407. {
  4408. 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 + "'";
  4409. }
  4410. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4411. decimal total = 0, today_finish = 0;
  4412. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4413. {
  4414. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4415. }
  4416. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4417. {
  4418. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4419. }
  4420. var res = new
  4421. {
  4422. data = total,
  4423. data1 = today_finish,
  4424. };
  4425. string ro_jsond = JsonConvert.SerializeObject(res);
  4426. returnSuccess(ro_jsond);
  4427. return;
  4428. }
  4429. public void get_erp_allreturnlist()
  4430. {
  4431. DataStruct dStruct = GetPostStruct();
  4432. List<string> lw = new List<string>();
  4433. string tid = GetPostString("ctid");
  4434. if (tid.Length > 0)
  4435. {
  4436. string select_tid = getTidByCtid(tid);
  4437. lw.Add(string.Format("tid='{0}'", select_tid));
  4438. }
  4439. string shopname = GetPostString("shopname");
  4440. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4441. string buyernick = GetPostString("buyer_nick");
  4442. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4443. string customer = GetPostString("customer");
  4444. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4445. string design = GetPostString("design");
  4446. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4447. string orderState = GetPostString("orderState");
  4448. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4449. string address = GetPostString("address");
  4450. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4451. string sellermemo = GetPostString("seller_memo");
  4452. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4453. string supplier = GetPostString("supplier");
  4454. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4455. string date1 = GetPostString("date1");
  4456. string date2 = GetPostString("date2");
  4457. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4458. if (dw.Length > 0) lw.Add(dw);
  4459. string bdate1 = GetPostString("backdate1");
  4460. string bdate2 = GetPostString("backdate2");
  4461. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4462. if (dw_back.Length > 0) lw.Add(dw_back);
  4463. string price1 = GetPostString("price1");
  4464. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4465. string price2 = GetPostString("price2");
  4466. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4467. string backreason = GetPostString("backreason");
  4468. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4469. lw.Add(string.Format("IsXianHuo=0"));
  4470. lw.Add(string.Format("ReturnTime != ''"));
  4471. string backtype = GetPostString("backtype");
  4472. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4473. dStruct.Order = "FinishDesignTime desc";
  4474. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4475. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4476. writeGridDataTableJson(dStruct.TotalCount, dt);
  4477. }
  4478. public void get_erp_aftersalereturnlist()
  4479. {
  4480. DataStruct dStruct = GetPostStruct();
  4481. List<string> lw = new List<string>();
  4482. string tid = GetPostString("ctid");
  4483. if (tid.Length > 0)
  4484. {
  4485. string select_tid = getTidByCtid(tid);
  4486. lw.Add(string.Format("tid='{0}'", select_tid));
  4487. }
  4488. string shopname = GetPostString("shopname");
  4489. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4490. string buyernick = GetPostString("buyer_nick");
  4491. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4492. string customer = GetPostString("customer");
  4493. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4494. string design = GetPostString("design");
  4495. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4496. string orderState = GetPostString("orderState");
  4497. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4498. string address = GetPostString("address");
  4499. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4500. string sellermemo = GetPostString("seller_memo");
  4501. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4502. string supplier = GetPostString("supplier");
  4503. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4504. string date1 = GetPostString("date1");
  4505. string date2 = GetPostString("date2");
  4506. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4507. if (dw.Length > 0) lw.Add(dw);
  4508. string bdate1 = GetPostString("backdate1");
  4509. string bdate2 = GetPostString("backdate2");
  4510. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4511. if (dw_back.Length > 0) lw.Add(dw_back);
  4512. string price1 = GetPostString("price1");
  4513. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4514. string price2 = GetPostString("price2");
  4515. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4516. lw.Add(string.Format("IsReturn=3"));
  4517. string backtype = GetPostString("backtype");
  4518. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4519. string backreason = GetPostString("backreason");
  4520. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4521. dStruct.Order = "ReturnTime desc";
  4522. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4523. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4524. writeGridDataTableJson(dStruct.TotalCount, dt);
  4525. }
  4526. public void get_erp_xianhuoreturnlist()
  4527. {
  4528. DataStruct dStruct = GetPostStruct();
  4529. List<string> lw = new List<string>();
  4530. string tid = GetPostString("ctid");
  4531. if (tid.Length > 0)
  4532. {
  4533. string select_tid = getTidByCtid(tid);
  4534. lw.Add(string.Format("tid='{0}'", select_tid));
  4535. }
  4536. string shopname = GetPostString("shopname");
  4537. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4538. string buyernick = GetPostString("buyer_nick");
  4539. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4540. string customer = GetPostString("customer");
  4541. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4542. string design = GetPostString("design");
  4543. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4544. string orderState = GetPostString("orderState");
  4545. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4546. string address = GetPostString("address");
  4547. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4548. string sellermemo = GetPostString("seller_memo");
  4549. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4550. string supplier = GetPostString("supplier");
  4551. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4552. string OrderArea = GetPostString("order_area");
  4553. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4554. string date1 = GetPostString("date1");
  4555. string date2 = GetPostString("date2");
  4556. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4557. if (dw.Length > 0) lw.Add(dw);
  4558. string price1 = GetPostString("price1");
  4559. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4560. string price2 = GetPostString("price2");
  4561. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4562. string posTag = CurrentUser.UserPost.Post.Code;
  4563. if (posTag == "Supplier")
  4564. {
  4565. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4566. }
  4567. lw.Add(string.Format("OrderState=6 "));
  4568. lw.Add(string.Format("IsXianHuo=1 "));
  4569. lw.Add(string.Format("IsReturn>0 "));
  4570. lw.Add(string.Format("IsReturn!=3"));
  4571. lw.Add(string.Format("IsRefund<={0}", 1));
  4572. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4573. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4574. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4575. writeGridDataTableJson(dStruct.TotalCount, dt);
  4576. }
  4577. public void set_erp_orderdelivery()
  4578. {
  4579. if (UrlPostParmsCheck("ctid"))
  4580. {
  4581. string eid = GetPostString("ctid");
  4582. CeErpTradeCell entity = null;
  4583. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4584. if (entity != null)
  4585. {
  4586. if (entity.OrderState >= 7)
  4587. {
  4588. returnErrorMsg("此单已发货,无需重复发货");
  4589. return;
  4590. }
  4591. if (entity.OrderState != 6)
  4592. {
  4593. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4594. return;
  4595. }
  4596. string shop = GetPostString("seller_nick");
  4597. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4598. string comName = GetPostString("comName");
  4599. string comCode = GetPostString("comCode");
  4600. string outSid = GetPostString("outSid");
  4601. string deliveryType = GetPostString("deliveryType");
  4602. string deliveryMemo = GetPostString("deliveryMemo");
  4603. outSid = outSid.Trim();
  4604. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4605. if (mainEn == null)
  4606. {
  4607. returnErrorMsg("找不到原始订单记录");
  4608. return;
  4609. }
  4610. bool isInitOrderDeliv = false;
  4611. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4612. {
  4613. isInitOrderDeliv = true;
  4614. }
  4615. string apires = "";
  4616. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4617. 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)
  4618. {
  4619. apires = "发货成功true";
  4620. }
  4621. else
  4622. {
  4623. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4624. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4625. }
  4626. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4627. {
  4628. entity.OrderState = 7;//发货后订单已发货
  4629. entity.OutSid = outSid;
  4630. entity.MemoOpt = 0;
  4631. entity.UpdateTime = DateTime.Now;
  4632. entity.FinishDeliveryTime = DateTime.Now;
  4633. entity.Update();
  4634. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4635. commonHelper.UpdateRelationOrder(entity.ctid);
  4636. //还要插入快递信息到 快递信息表
  4637. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4638. exinfo.tid = eid;
  4639. exinfo.out_sid = outSid;
  4640. exinfo.company_code = comCode;
  4641. exinfo.company_name = comName;
  4642. exinfo.delivery_memo = deliveryMemo;
  4643. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4644. exinfo.deliveryType = deliveryType;
  4645. exinfo.Create();
  4646. returnSuccessMsg("发货操作成功!");
  4647. commonHelper.UpdateRelationOrder(entity.ctid);
  4648. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4649. CeErpSukuraData.createInfo(entity.ctid, 4);
  4650. if (entity.SupplierId == 64)
  4651. {
  4652. commonHelper.sendCytExpress(exinfo);
  4653. }
  4654. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4655. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4656. }
  4657. else
  4658. {
  4659. string errmsg = commonHelper.KeepChinese(apires);
  4660. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4661. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4662. }
  4663. return;
  4664. }
  4665. returnErrorMsg("找不到订单记录");
  4666. }
  4667. }
  4668. public void set_erp_multidelivery()
  4669. {
  4670. string eids = GetPostString("tids");
  4671. string[] eidList = eids.Split(',');
  4672. if (eidList.Length <= 0)
  4673. {
  4674. returnErrorMsg("发货不能为空");
  4675. return;
  4676. }
  4677. foreach (string ctid in eidList)
  4678. {
  4679. if (ctid.Length <= 0) continue;
  4680. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4681. if (expInfo != null)
  4682. {
  4683. StringBuilder sql = new StringBuilder();
  4684. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4685. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4686. if (dt.Rows.Count > 0)
  4687. {
  4688. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4689. {
  4690. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4691. expInfo.state = "异常";
  4692. expInfo.isMultiDelivery = 1;
  4693. expInfo.Update();
  4694. continue;
  4695. }
  4696. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4697. {
  4698. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4699. expInfo.state = "异常";
  4700. expInfo.Update();
  4701. continue;
  4702. }
  4703. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4704. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4705. bool isInitOrderDeliv = false;
  4706. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4707. {
  4708. isInitOrderDeliv = true;
  4709. expInfo.isMultiDelivery = 1;
  4710. }
  4711. if (ctid.IndexOf("N") != -1)
  4712. {
  4713. StringBuilder sqlbucha = new StringBuilder();
  4714. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4715. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4716. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4717. commonHelper.UpdateRelationOrder(ctid);
  4718. expInfo.delivery_memo = "发货成功";
  4719. expInfo.state = "发货成功";
  4720. expInfo.isMultiDelivery = 1;
  4721. expInfo.Update();
  4722. }
  4723. else
  4724. {
  4725. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4726. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4727. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4728. {
  4729. expInfo.delivery_memo = "发货成功";
  4730. expInfo.state = "发货成功";
  4731. expInfo.isMultiDelivery = 1;
  4732. expInfo.Update();
  4733. commonHelper.UpdateRelationOrder(ctid);
  4734. CeErpSukuraData.createInfo(ctid, 4);
  4735. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4736. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4737. }
  4738. else
  4739. {
  4740. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4741. expInfo.state = "异常";
  4742. expInfo.Update();
  4743. }
  4744. }
  4745. }
  4746. }
  4747. }
  4748. returnSuccessMsg("操作完成");
  4749. }
  4750. public void reset_erp_memoopt()
  4751. {
  4752. if (UrlPostParmsCheck("ctid"))
  4753. {
  4754. string eid = GetPostString("ctid");
  4755. CeErpTradeCell entity = null;
  4756. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4757. if (entity != null)
  4758. {
  4759. string stropt = "";
  4760. if (entity.MemoOpt == 1)
  4761. {
  4762. stropt = "“改稿”";
  4763. }
  4764. else if (entity.MemoOpt == 2)
  4765. {
  4766. stropt = "“定稿”";
  4767. }
  4768. else if (entity.MemoOpt == 3)
  4769. {
  4770. stropt = "“完成查货”";
  4771. CeErpSukuraData.createInfo(entity.ctid, 6);
  4772. }
  4773. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4774. entity.UpdateTime = DateTime.Now;
  4775. entity.MemoOpt = 0;
  4776. entity.Update();
  4777. returnSuccessMsg("操作成功!");
  4778. return;
  4779. }
  4780. returnErrorMsg("找不到记录");
  4781. }
  4782. }
  4783. public void get_erp_deliveryunusual()
  4784. {
  4785. DataStruct dStruct = GetPostStruct();
  4786. List<string> lw = new List<string>();
  4787. string tid = GetPostString("ctid");
  4788. if (tid.Length > 0)
  4789. {
  4790. string select_tid = getTidByCtid(tid);
  4791. lw.Add(string.Format("tid='{0}'", select_tid));
  4792. }
  4793. string shopname = GetPostString("shopname");
  4794. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4795. string buyernick = GetPostString("buyer_nick");
  4796. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4797. string customer = GetPostString("customer");
  4798. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4799. string design = GetPostString("design");
  4800. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4801. string sellermemo = GetPostString("seller_memo");
  4802. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4803. string supplier = GetPostString("supplier");
  4804. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4805. string date1 = GetPostString("date1");
  4806. string date2 = GetPostString("date2");
  4807. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4808. if (dw.Length > 0) lw.Add(dw);
  4809. string placedate1 = GetPostString("placedate1");
  4810. string placedate2 = GetPostString("placedate2");
  4811. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4812. if (dw_place.Length > 0) lw.Add(dw_place);
  4813. string price1 = GetPostString("price1");
  4814. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4815. string price2 = GetPostString("price2");
  4816. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4817. string unusualCon = GetPostString("unusualcon");
  4818. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4819. string posTag = CurrentUser.UserPost.Post.Code;
  4820. if (posTag == "Supplier")
  4821. {
  4822. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4823. }
  4824. lw.Add(string.Format("OrderState = 6"));
  4825. lw.Add(string.Format("UnusualTag = 5"));
  4826. lw.Add(string.Format("IsRefund<={0}", 1));
  4827. dStruct.Order = "FinishPlaceTime desc";
  4828. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4829. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4830. writeGridDataTableJson(dStruct.TotalCount, dt);
  4831. }
  4832. public void get_erp_deliveryedlist()
  4833. {
  4834. DataStruct dStruct = GetPostStruct();
  4835. List<string> lw = new List<string>();
  4836. string tid = GetPostString("ctid");
  4837. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4838. string shopname = GetPostString("shopname");
  4839. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4840. string buyernick = GetPostString("buyer_nick");
  4841. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4842. string customer = GetPostString("customer");
  4843. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4844. string design = GetPostString("design");
  4845. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4846. string sellermemo = GetPostString("seller_memo");
  4847. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4848. string logistics = GetPostString("logistics");
  4849. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4850. string date1 = GetPostString("date1");
  4851. string date2 = GetPostString("date2");
  4852. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4853. //if (dw.Length > 0) lw.Add(dw);
  4854. string placedate1 = GetPostString("placedate1");
  4855. string placedate2 = GetPostString("placedate2");
  4856. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4857. if (fdw.Length > 0) lw.Add(fdw);
  4858. string devdate1 = GetPostString("deliverydate1");
  4859. string devdate2 = GetPostString("deliverydate2");
  4860. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4861. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4862. string price1 = GetPostString("price1");
  4863. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4864. string price2 = GetPostString("price2");
  4865. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4866. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4867. {
  4868. if (tid.Length > 0)
  4869. {
  4870. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4871. if (tid.Length > 5)
  4872. {
  4873. List<string> tids = getTidByCtidLike(tid);
  4874. if (tids.Count > 0 && tids.Count < 10)
  4875. {
  4876. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4877. }
  4878. }
  4879. lw.Add(tid_sql);
  4880. }
  4881. if (buyernick.Length > 0)
  4882. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4883. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4884. if (dw.Length > 0) lw.Add(dw);
  4885. }
  4886. else
  4887. {
  4888. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4889. }
  4890. string posTag = CurrentUser.UserPost.Post.Code;
  4891. if (posTag == "Supplier")
  4892. {
  4893. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4894. }
  4895. else
  4896. {
  4897. string supplier = GetPostString("supplier");
  4898. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4899. }
  4900. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4901. lw.Add(string.Format("type != 'PDD' "));
  4902. lw.Add(string.Format("IsRefund!={0}", 2));
  4903. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4904. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4905. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4906. /*if (tid.Length > 0)
  4907. {
  4908. List<string> tids = new List<string>();
  4909. if (dt != null && dt.Rows.Count > 0)
  4910. {
  4911. foreach (DataRow item in dt.Rows)
  4912. {
  4913. tids.Add("'" + item["tid"] + "'");
  4914. }
  4915. }
  4916. if (tids.Count > 0)
  4917. {
  4918. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4919. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4920. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4921. dt = WebCache.GetData("view_erptradecell", dStruct);
  4922. }
  4923. }*/
  4924. if (dt != null)
  4925. {
  4926. foreach (DataRow dr in dt.Rows)
  4927. {
  4928. 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();
  4929. }
  4930. }
  4931. writeGridDataTableJson(dStruct.TotalCount, dt);
  4932. }
  4933. public void get_erp_pdddeliveryed()
  4934. {
  4935. DataStruct dStruct = GetPostStruct();
  4936. List<string> lw = new List<string>();
  4937. string tid = GetPostString("ctid");
  4938. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4939. string shopname = GetPostString("shopname");
  4940. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4941. string buyernick = GetPostString("buyer_nick");
  4942. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4943. string customer = GetPostString("customer");
  4944. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4945. string design = GetPostString("design");
  4946. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4947. string sellermemo = GetPostString("seller_memo");
  4948. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4949. string logistics = GetPostString("logistics");
  4950. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4951. string date1 = GetPostString("date1");
  4952. string date2 = GetPostString("date2");
  4953. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4954. //if (dw.Length > 0) lw.Add(dw);
  4955. string placedate1 = GetPostString("placedate1");
  4956. string placedate2 = GetPostString("placedate2");
  4957. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4958. if (fdw.Length > 0) lw.Add(fdw);
  4959. string devdate1 = GetPostString("deliverydate1");
  4960. string devdate2 = GetPostString("deliverydate2");
  4961. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4962. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4963. string price1 = GetPostString("price1");
  4964. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4965. string price2 = GetPostString("price2");
  4966. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4967. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4968. {
  4969. if (tid.Length > 0)
  4970. {
  4971. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4972. if (tid.Length > 5)
  4973. {
  4974. List<string> tids = getTidByCtidLike(tid);
  4975. if (tids.Count > 0 && tids.Count < 10)
  4976. {
  4977. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4978. }
  4979. }
  4980. lw.Add(tid_sql);
  4981. }
  4982. if (buyernick.Length > 0)
  4983. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4984. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4985. if (dw.Length > 0) lw.Add(dw);
  4986. }
  4987. else
  4988. {
  4989. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  4990. }
  4991. string posTag = CurrentUser.UserPost.Post.Code;
  4992. if (posTag == "Supplier")
  4993. {
  4994. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4995. }
  4996. else
  4997. {
  4998. string supplier = GetPostString("supplier");
  4999. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5000. }
  5001. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5002. lw.Add(string.Format("type = 'PDD' "));
  5003. lw.Add(string.Format("IsRefund!={0}", 2));
  5004. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5005. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5006. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5007. /* if (tid.Length > 0)
  5008. {
  5009. List<string> tids = new List<string>();
  5010. if (dt != null && dt.Rows.Count > 0)
  5011. {
  5012. foreach (DataRow item in dt.Rows)
  5013. {
  5014. tids.Add("'" + item["tid"] + "'");
  5015. }
  5016. }
  5017. if (tids.Count > 0)
  5018. {
  5019. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5020. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5021. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5022. dt = WebCache.GetData("view_erptradecell", dStruct);
  5023. }
  5024. }*/
  5025. foreach (DataRow dr in dt.Rows)
  5026. {
  5027. 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();
  5028. }
  5029. writeGridDataTableJson(dStruct.TotalCount, dt);
  5030. }
  5031. public void get_erp_jddeliveryed()
  5032. {
  5033. DataStruct dStruct = GetPostStruct();
  5034. List<string> lw = new List<string>();
  5035. string tid = GetPostString("ctid");
  5036. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5037. string shopname = GetPostString("shopname");
  5038. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5039. string buyernick = GetPostString("buyer_nick");
  5040. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5041. string customer = GetPostString("customer");
  5042. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5043. string design = GetPostString("design");
  5044. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5045. string sellermemo = GetPostString("seller_memo");
  5046. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5047. string date1 = GetPostString("date1");
  5048. string date2 = GetPostString("date2");
  5049. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5050. //if (dw.Length > 0) lw.Add(dw);
  5051. string placedate1 = GetPostString("placedate1");
  5052. string placedate2 = GetPostString("placedate2");
  5053. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5054. if (fdw.Length > 0) lw.Add(fdw);
  5055. string devdate1 = GetPostString("deliverydate1");
  5056. string devdate2 = GetPostString("deliverydate2");
  5057. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5058. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5059. string price1 = GetPostString("price1");
  5060. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5061. string price2 = GetPostString("price2");
  5062. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5063. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5064. {
  5065. if (tid.Length > 0)
  5066. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5067. if (buyernick.Length > 0)
  5068. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5069. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5070. if (dw.Length > 0) lw.Add(dw);
  5071. }
  5072. else
  5073. {
  5074. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5075. }
  5076. string posTag = CurrentUser.UserPost.Post.Code;
  5077. if (posTag == "Supplier")
  5078. {
  5079. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5080. }
  5081. else
  5082. {
  5083. string supplier = GetPostString("supplier");
  5084. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5085. }
  5086. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5087. lw.Add(string.Format("type = 'JD' "));
  5088. lw.Add(string.Format("IsRefund!={0}", 2));
  5089. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5090. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5091. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5092. foreach (DataRow dr in dt.Rows)
  5093. {
  5094. 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();
  5095. }
  5096. writeGridDataTableJson(dStruct.TotalCount, dt);
  5097. }
  5098. public void get_erp_allplacelist()
  5099. {
  5100. DataStruct dStruct = GetPostStruct();
  5101. List<string> lw = new List<string>();
  5102. string tid = GetPostString("ctid");
  5103. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5104. string shopname = GetPostString("shopname");
  5105. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5106. string buyernick = GetPostString("buyer_nick");
  5107. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5108. string customer = GetPostString("customer");
  5109. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5110. string design = GetPostString("design");
  5111. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5112. string sellermemo = GetPostString("seller_memo");
  5113. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5114. string supplier = GetPostString("supplier");
  5115. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5116. string date1 = GetPostString("date1");
  5117. string date2 = GetPostString("date2");
  5118. string pldate1 = GetPostString("placedate1");
  5119. string pldate2 = GetPostString("placedate2");
  5120. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5121. //if (dw.Length > 0) lw.Add(dw);
  5122. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5123. {
  5124. if (tid.Length > 0)
  5125. {
  5126. string select_tid = getTidByCtid(tid);
  5127. lw.Add(string.Format("tid='{0}'", select_tid));
  5128. }
  5129. if (buyernick.Length > 0)
  5130. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5131. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5132. if (dw.Length > 0) lw.Add(dw);
  5133. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5134. if (dw_place.Length > 0) lw.Add(dw_place);
  5135. }
  5136. else
  5137. {
  5138. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5139. {
  5140. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5141. }
  5142. }
  5143. string price1 = GetPostString("price1");
  5144. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5145. string price2 = GetPostString("price2");
  5146. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5147. string posTag = CurrentUser.UserPost.Post.Code;
  5148. if (posTag == "Supplier")
  5149. {
  5150. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5151. }
  5152. lw.Add(string.Format("OrderState >= 6"));
  5153. lw.Add(string.Format("IsSample != 2 "));
  5154. //lw.Add(string.Format("isDianziOrder = 0 "));
  5155. lw.Add(string.Format("SupplierId > 0 "));
  5156. //lw.Add(string.Format("IsRefund<={0}", 1));
  5157. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5158. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5159. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5160. foreach (DataRow dr in dt.Rows)
  5161. {
  5162. 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();
  5163. }
  5164. writeGridDataTableJson(dStruct.TotalCount, dt);
  5165. }
  5166. public void get_erp_financeallplacelist()
  5167. {
  5168. DataStruct dStruct = GetPostStruct();
  5169. List<string> lw = new List<string>();
  5170. string tid = GetPostString("ctid");
  5171. string shopname = GetPostString("shopname");
  5172. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5173. string buyernick = GetPostString("buyer_nick");
  5174. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5175. string customer = GetPostString("customer");
  5176. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5177. string design = GetPostString("design");
  5178. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5179. string sellermemo = GetPostString("seller_memo");
  5180. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5181. string supplier = GetPostString("supplier");
  5182. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5183. string date1 = GetPostString("date1");
  5184. string date2 = GetPostString("date2");
  5185. string pldate1 = GetPostString("placedate1");
  5186. string pldate2 = GetPostString("placedate2");
  5187. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5188. {
  5189. if (tid.Length > 0)
  5190. {
  5191. string select_tid = getTidByCtid(tid);
  5192. lw.Add(string.Format("tid='{0}'", select_tid));
  5193. }
  5194. if (buyernick.Length > 0)
  5195. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5196. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5197. if (dw.Length > 0) lw.Add(dw);
  5198. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5199. if (dw_place.Length > 0) lw.Add(dw_place);
  5200. }
  5201. else
  5202. {
  5203. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5204. {
  5205. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5206. }
  5207. }
  5208. string price1 = GetPostString("price1");
  5209. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5210. string price2 = GetPostString("price2");
  5211. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5212. string posTag = CurrentUser.UserPost.Post.Code;
  5213. if (posTag == "Supplier")
  5214. {
  5215. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5216. }
  5217. //lw.Add(string.Format("OrderState >= 6"));
  5218. lw.Add(string.Format("IsSample != 2 "));
  5219. lw.Add(string.Format("isDianziOrder = 0 "));
  5220. //lw.Add(string.Format("IsRefund<={0}", 1));
  5221. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5222. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5223. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5224. foreach (DataRow dr in dt.Rows)
  5225. {
  5226. 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();
  5227. }
  5228. writeGridDataTableJson(dStruct.TotalCount, dt);
  5229. }
  5230. public void get_erp_expresslist()
  5231. {
  5232. int listtype = GetInt("ltype");
  5233. DataStruct dStruct = GetPostStruct();
  5234. List<string> lw = new List<string>();
  5235. string tid = GetPostString("tid");
  5236. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5237. string outsid = GetPostString("out_sid");
  5238. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5239. string importer = GetPostString("ImportUserName");
  5240. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5241. string file = GetPostString("import_file");
  5242. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5243. string printman = GetPostString("printman");
  5244. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5245. string date1 = GetPostString("date1");
  5246. string date2 = GetPostString("date2");
  5247. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5248. if (dw.Length > 0) lw.Add(dw);
  5249. string fdate1 = GetPostString("finishdate1");
  5250. string fdate2 = GetPostString("finishdate2");
  5251. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5252. if (fdw.Length > 0) lw.Add(fdw);
  5253. string supplierId = GetPostString("supplierId");
  5254. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5255. if (listtype == 1)
  5256. {
  5257. lw.Add(string.Format("importUserId !=0"));
  5258. }
  5259. string posTag = CurrentUser.UserPost.Post.Code;
  5260. if (posTag == "Supplier")
  5261. {
  5262. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5263. }
  5264. if (dStruct.PageSize != 100000)
  5265. {
  5266. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5267. }
  5268. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5269. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5270. writeGridDataTableJson(dStruct.TotalCount, dt);
  5271. }
  5272. public void set_erp_buchaorderdelivery()
  5273. {
  5274. if (UrlPostParmsCheck("ctid"))
  5275. {
  5276. string eid = GetPostString("ctid");
  5277. CeErpTradeCell entity = null;
  5278. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5279. if (entity != null)
  5280. {
  5281. if (entity.IsSample != 2)
  5282. {
  5283. returnErrorMsg("补差价单才能标记为已发货");
  5284. return;
  5285. }
  5286. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5287. entity.OrderState = 7;
  5288. entity.Update();
  5289. returnSuccessMsg("操作成功!");
  5290. return;
  5291. }
  5292. returnErrorMsg("找不到记录");
  5293. }
  5294. }
  5295. public void get_stdtemplates()
  5296. {
  5297. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5298. //string res = taobaoHelper.test();
  5299. string res = apiHelper.API_PrintTemplate();
  5300. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5301. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5302. {
  5303. int sidx = res.IndexOf("error_code");
  5304. int eidx = res.IndexOf("success");
  5305. string msg = res.Substring(sidx, eidx - sidx);
  5306. returnErrorMsg(msg);
  5307. return;
  5308. }
  5309. if (res.Length <= 0)
  5310. {
  5311. returnErrorMsg("模板数据为空!");
  5312. return;
  5313. }
  5314. ReturnSuccess(res);
  5315. }
  5316. public void cancel_print_order()
  5317. {
  5318. if (UrlPostParmsCheck("ctid"))
  5319. {
  5320. string ctid = GetPostString("ctid");
  5321. CeErpTradeCell entity = null;
  5322. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5323. if (entity != null)
  5324. {
  5325. string res = "";
  5326. string code = entity.LastBillWaybillCode;
  5327. if (code == "")
  5328. {
  5329. code = entity.OutSid;
  5330. }
  5331. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5332. XLog.SaveLog(0, "取消面单" + res);
  5333. }
  5334. }
  5335. }
  5336. public void set_erp_printwaybill()
  5337. {
  5338. if (UrlPostParmsCheck("ctid"))
  5339. {
  5340. string ctid = GetPostString("ctid");
  5341. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5342. string cpName = GetPostString("cpname");
  5343. string isTogether = GetPostString("together");
  5344. //var res_obj = new
  5345. //{
  5346. // restype = 1,
  5347. // 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\"}"
  5348. //};
  5349. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5350. //ReturnSuccess(ro_json);
  5351. //return;
  5352. bool isUseLastWayBillCode = false;
  5353. CeErpTradeCell entity = null;
  5354. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5355. if (entity != null)
  5356. {
  5357. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5358. {
  5359. isUseLastWayBillCode = true;
  5360. }
  5361. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5362. {
  5363. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5364. return;
  5365. }
  5366. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5367. {
  5368. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5369. return;
  5370. }
  5371. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5372. {
  5373. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5374. return;
  5375. }
  5376. }
  5377. string res = "";
  5378. Api_waybill_code_response_Obj fullObj = null;
  5379. string pData_str = "";
  5380. string curUseWayBillCode = "";
  5381. if (isUseLastWayBillCode == false)
  5382. {
  5383. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5384. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5385. if (res.IndexOf("failure") != -1)
  5386. {
  5387. //int idx = res.IndexOf("sub_message");
  5388. //int idx2 = res.IndexOf("flag");
  5389. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5390. string errMsgNeed = commonHelper.KeepChinese(res);
  5391. var res_objd = new
  5392. {
  5393. restype = 0,
  5394. data = "获取面单失败" + errMsgNeed
  5395. };
  5396. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5397. returnSuccess(ro_jsond);
  5398. if (res.IndexOf("停发") != -1)
  5399. {
  5400. entity.UnusualCon = "物流停发";
  5401. entity.Update();
  5402. }
  5403. //returnErrorMsg("获取面单失败,"+emsg);
  5404. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5405. return;
  5406. }
  5407. else if (res.IndexOf("errorMsg") != -1)
  5408. {
  5409. //int idx = res.IndexOf("errorMsg");
  5410. //int idx2 = res.IndexOf("}]}");
  5411. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5412. string errMsgNeed = commonHelper.KeepChinese(res);
  5413. var res_objf = new
  5414. {
  5415. restype = 0,
  5416. data = "获取面单失败2" + errMsgNeed
  5417. };
  5418. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5419. if (res.IndexOf("停发") != -1)
  5420. {
  5421. entity.UnusualCon = "物流停发";
  5422. entity.Update();
  5423. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5424. if (trade != null)
  5425. {
  5426. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5427. }
  5428. }
  5429. returnSuccess(ro_jsonf);
  5430. //returnErrorMsg("获取面单失败," + emsg);
  5431. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5432. return;
  5433. }
  5434. try
  5435. {
  5436. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5437. //res = res.Replace(" ", "");
  5438. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5439. }
  5440. catch (Exception ex)
  5441. {
  5442. XLog.SaveLog(0, "生成fullObj" + res);
  5443. var res_objf = new
  5444. {
  5445. restype = 0,
  5446. data = "生成fullObj发生错误" + ex.Message
  5447. };
  5448. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5449. returnSuccess(ro_jsonf);
  5450. return;
  5451. }
  5452. if (fullObj.response.data.content.Count > 0)
  5453. {
  5454. ContentItem codeObj = fullObj.response.data.content[0];
  5455. if (cpCode.IndexOf("SFFQ-") != -1)
  5456. {
  5457. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5458. }
  5459. else
  5460. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5461. curUseWayBillCode = codeObj.waybillCode;
  5462. }
  5463. else
  5464. {
  5465. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5466. var res_objf = new
  5467. {
  5468. restype = 0,
  5469. data = "生成fullObj找不到快递单号waybillCode"
  5470. };
  5471. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5472. returnSuccess(ro_jsonf);
  5473. return;
  5474. }
  5475. }
  5476. else
  5477. {
  5478. //使用上次打印的快递单号
  5479. if (cpCode == "SFFQ-LY")
  5480. {
  5481. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5482. }
  5483. else
  5484. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5485. curUseWayBillCode = entity.LastBillWaybillCode;
  5486. }
  5487. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5488. {
  5489. var res_obje = new
  5490. {
  5491. restype = 0,
  5492. data = "获取加密打印数据失败"
  5493. };
  5494. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5495. returnSuccess(ro_jsone);
  5496. entity.LastBillCpCode = cpCode;
  5497. entity.LastBillWaybillCode = curUseWayBillCode;
  5498. entity.Update();
  5499. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5500. //returnErrorMsg("获取加密打印数据失败");
  5501. return;
  5502. }
  5503. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5504. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5505. string btnType = "";
  5506. string errorMsg = "";
  5507. if (entity != null)
  5508. {
  5509. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5510. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5511. //cpcode是 YTO-CAINIAO
  5512. //string comCode = cpCode.Split('-')[0].ToString();
  5513. string apires = "";
  5514. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5515. //isTogether=2是新的合包弹窗
  5516. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5517. {
  5518. if (ctid.IndexOf("N") != -1)
  5519. {
  5520. apires = "发货成功";
  5521. }
  5522. else
  5523. {
  5524. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5525. }
  5526. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5527. //打单后发货
  5528. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5529. {
  5530. try
  5531. {
  5532. btnType = "待发货";
  5533. entity.OutSid = curUseWayBillCode;
  5534. entity.OrderState = 7;
  5535. entity.IsUrgency = false;
  5536. entity.LastBillCpCode = "";
  5537. entity.LastBillWaybillCode = "";
  5538. entity.FinishDeliveryTime = DateTime.Now;
  5539. entity.IsReturn = 0;
  5540. entity.MemoOpt = 0;
  5541. entity.UpdateTime = DateTime.Now;
  5542. entity.Update();
  5543. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5544. //还要插入快递信息到 快递信息表
  5545. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5546. exinfo.tid = entity.ctid;
  5547. exinfo.out_sid = curUseWayBillCode;
  5548. exinfo.company_code = cpCode;
  5549. exinfo.company_name = cpName;
  5550. exinfo.supplierUserName = supplierName;
  5551. exinfo.deliveryType = "发货成功";
  5552. exinfo.print_time = DateTime.Now;
  5553. exinfo.printUser = CurrentUser.UserName;
  5554. exinfo.postData = pData_str;
  5555. exinfo.Create();
  5556. commonHelper.UpdateRelationOrder(entity.ctid);
  5557. CeErpSukuraData.createInfo(ctid, 4);
  5558. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5559. if (entity.SupplierId == 64)
  5560. {
  5561. commonHelper.sendCytExpress(exinfo);
  5562. }
  5563. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5564. if (!string.IsNullOrEmpty(isTogether))
  5565. {
  5566. if (Convert.ToInt32(isTogether) > 0)
  5567. {
  5568. StringBuilder sqlsb = new StringBuilder();
  5569. 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);
  5570. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5571. }
  5572. }
  5573. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5574. }
  5575. catch (Exception ex)
  5576. {
  5577. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5578. }
  5579. }
  5580. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5581. {
  5582. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5583. if (entity.OrderState == 6)
  5584. {
  5585. entity.OrderState = 7;
  5586. }
  5587. entity.UpdateTime = DateTime.Now;
  5588. entity.FinishDeliveryTime = DateTime.Now;
  5589. btnType = "已发货";
  5590. entity.Update();
  5591. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5592. exinfo.tid = entity.ctid;
  5593. exinfo.out_sid = curUseWayBillCode;
  5594. exinfo.company_code = cpCode;
  5595. exinfo.company_name = cpName;
  5596. exinfo.supplierUserName = supplierName;
  5597. exinfo.deliveryType = "发货成功";
  5598. exinfo.print_time = DateTime.Now;
  5599. exinfo.printUser = CurrentUser.UserName;
  5600. exinfo.postData = pData_str;
  5601. exinfo.Create();
  5602. commonHelper.UpdateRelationOrder(entity.ctid);
  5603. CeErpSukuraData.createInfo(entity.ctid, 4);
  5604. if (entity.SupplierId == 64)
  5605. {
  5606. commonHelper.sendCytExpress(exinfo);
  5607. }
  5608. if (!string.IsNullOrEmpty(isTogether))
  5609. {
  5610. if (Convert.ToInt32(isTogether) > 0)
  5611. {
  5612. StringBuilder sqlsb = new StringBuilder();
  5613. 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);
  5614. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5615. }
  5616. }
  5617. //不处理
  5618. }
  5619. else
  5620. {
  5621. entity.UpdateTime = DateTime.Now;
  5622. entity.LastBillCpCode = cpCode;
  5623. entity.LastBillWaybillCode = curUseWayBillCode;
  5624. entity.Update();
  5625. string errmsg = commonHelper.KeepChinese(apires);
  5626. var res_objz = new
  5627. {
  5628. restype = 0,
  5629. data = "打单后发货失败"
  5630. };
  5631. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5632. returnSuccess(ro_jsonz);
  5633. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5634. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5635. return;
  5636. }
  5637. }
  5638. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5639. {
  5640. string ctids = GetPostString("ctids");
  5641. DataTable dt = getSameOrderList(entity, mainEn);
  5642. List<string> list = new List<string>();
  5643. List<string> send_list = new List<string>();
  5644. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5645. CeErpTrade ceErpTrade = new CeErpTrade();
  5646. //可合包的合并一起发货
  5647. if (dt == null && string.IsNullOrEmpty(ctids))
  5648. {
  5649. var res_objz = new
  5650. {
  5651. restype = 0,
  5652. data = "打单后发货失败"
  5653. };
  5654. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5655. returnSuccess(ro_jsonz);
  5656. return;
  5657. }
  5658. if (!string.IsNullOrEmpty(ctids))
  5659. {
  5660. StringBuilder sql = new StringBuilder();
  5661. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5662. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5663. }
  5664. foreach (DataRow row in dt.Rows)
  5665. {
  5666. list.Add("'" + row["ctid"] + "'");
  5667. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5668. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5669. if (ctid.IndexOf("N") != -1)
  5670. {
  5671. apires = "发货成功";
  5672. }
  5673. else
  5674. {
  5675. if (!send_list.Contains(ceErpTrade.tid))
  5676. {
  5677. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5678. }
  5679. else
  5680. {
  5681. apires = "发货成功";
  5682. }
  5683. }
  5684. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5685. {
  5686. send_list.Add(ceErpTrade.tid);
  5687. try
  5688. {
  5689. btnType = "待发货";
  5690. ceErpTradeCell.OutSid = curUseWayBillCode;
  5691. ceErpTradeCell.OrderState = 7;
  5692. ceErpTradeCell.IsUrgency = false;
  5693. ceErpTradeCell.LastBillCpCode = "";
  5694. ceErpTradeCell.LastBillWaybillCode = "";
  5695. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5696. ceErpTradeCell.IsReturn = 0;
  5697. ceErpTradeCell.MemoOpt = 0;
  5698. ceErpTradeCell.UpdateTime = DateTime.Now;
  5699. ceErpTradeCell.Update();
  5700. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5701. //还要插入快递信息到 快递信息表
  5702. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5703. exinfo.tid = ceErpTradeCell.ctid;
  5704. exinfo.out_sid = curUseWayBillCode;
  5705. exinfo.company_code = cpCode;
  5706. exinfo.company_name = cpName;
  5707. exinfo.supplierUserName = supplierName;
  5708. exinfo.deliveryType = "发货成功";
  5709. exinfo.print_time = DateTime.Now;
  5710. exinfo.printUser = CurrentUser.UserName;
  5711. exinfo.postData = pData_str;
  5712. exinfo.Create();
  5713. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5714. CeErpSukuraData.createInfo(ctid, 4);
  5715. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5716. if (ceErpTradeCell.SupplierId == 64)
  5717. {
  5718. commonHelper.sendCytExpress(exinfo);
  5719. }
  5720. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5721. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5722. }
  5723. catch (Exception ex)
  5724. {
  5725. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5726. }
  5727. }
  5728. else
  5729. {
  5730. ceErpTradeCell.UpdateTime = DateTime.Now;
  5731. ceErpTradeCell.LastBillCpCode = cpCode;
  5732. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5733. ceErpTradeCell.Update();
  5734. string errmsg = commonHelper.KeepChinese(apires);
  5735. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5736. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5737. }
  5738. }
  5739. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5740. }
  5741. }
  5742. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5743. var res_obj = new
  5744. {
  5745. restype = 1,
  5746. data = pData_str,
  5747. errorMsg
  5748. };
  5749. string ro_json = JsonConvert.SerializeObject(res_obj);
  5750. ReturnSuccess(ro_json);
  5751. return;
  5752. }
  5753. }
  5754. private string GetUTF8String(byte[] vs)
  5755. {
  5756. throw new NotImplementedException();
  5757. }
  5758. public void set_erp_printwaybill_cn()
  5759. {
  5760. if (UrlPostParmsCheck("ctid"))
  5761. {
  5762. string ctid = GetPostString("ctid");
  5763. string cpCode = GetPostString("cpcode");
  5764. string cpName = GetPostString("cpname");
  5765. string tempUrl = GetPostString("tempurl");
  5766. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5767. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5768. //string res = taobaoHelper.test();
  5769. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5770. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5771. {
  5772. int sidx = res.IndexOf("errorMsg");
  5773. int eidx = res.IndexOf("}");
  5774. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5775. var res_objzxx = new
  5776. {
  5777. restype = 0,
  5778. data = msg
  5779. };
  5780. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5781. returnSuccess(ro_jsonzxx);
  5782. //returnErrorMsg(msg);
  5783. return;
  5784. }
  5785. int idx = res.IndexOf("waybillCode");
  5786. int idx2 = res.IndexOf("printData");
  5787. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5788. string eid = GetPostString("ctid");
  5789. CeErpTradeCell entity = null;
  5790. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5791. if (entity != null)
  5792. {
  5793. string osid = entity.OutSid;
  5794. entity.OutSid = osid + "," + outsid;
  5795. entity.FinishDeliveryTime = DateTime.Now;
  5796. entity.OrderState = 7;
  5797. entity.UpdateTime = DateTime.Now;
  5798. entity.IsReturn = 0;
  5799. entity.Update();
  5800. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5801. exinfo.tid = entity.ctid;
  5802. exinfo.out_sid = outsid;
  5803. exinfo.company_code = cpCode;
  5804. exinfo.company_name = cpName;
  5805. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5806. exinfo.deliveryType = "发货成功";
  5807. exinfo.print_time = DateTime.Now;
  5808. exinfo.printUser = CurrentUser.UserName;
  5809. exinfo.Create();
  5810. if (entity.SupplierId == 64)
  5811. {
  5812. commonHelper.sendCytExpress(exinfo);
  5813. }
  5814. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5815. }
  5816. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5817. var res_objz = new
  5818. {
  5819. restype = 1,
  5820. data = res
  5821. };
  5822. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5823. returnSuccess(ro_jsonz);
  5824. //ReturnSuccess(res);
  5825. }
  5826. }
  5827. ////打单,打印面单 获取面单号
  5828. //public void set_erp_printwaybill()
  5829. //{
  5830. // if (UrlPostParmsCheck("ctid"))
  5831. // {
  5832. // string ctid = GetPostString("ctid");
  5833. // string cpCode = GetPostString("cpcode");
  5834. // string tempUrl = GetPostString("tempurl");
  5835. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5836. // //string res = taobaoHelper.test();
  5837. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5838. // if (res.IndexOf("error_response") != -1)
  5839. // {
  5840. // int sidx = res.IndexOf("sub_msg");
  5841. // int eidx = res.IndexOf("request_id");
  5842. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5843. // returnErrorMsg(msg);
  5844. // return;
  5845. // }
  5846. // int idx = res.IndexOf("waybill_code");
  5847. // int idx2 = res.IndexOf("}]}");
  5848. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5849. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5850. // ReturnSuccess(res);
  5851. // }
  5852. //}
  5853. public void cancel_erp_aftersale()
  5854. {
  5855. if (UrlPostParmsCheck("ctid"))
  5856. {
  5857. string eid = GetPostString("ctid");
  5858. CeErpTradeCell entity = null;
  5859. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5860. if (entity != null)
  5861. {
  5862. //有过处理的售后,取消也不能删除 售 字,保留
  5863. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5864. {
  5865. entity.AfterSaleState = 4;
  5866. }
  5867. else
  5868. entity.AfterSaleState = 0;
  5869. entity.UpdateTime = DateTime.Now;
  5870. entity.Update();
  5871. returnSuccessMsg("操作成功!");
  5872. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5873. return;
  5874. }
  5875. returnErrorMsg("找不到订单记录");
  5876. }
  5877. }
  5878. public void get_erp_aftersalelist()
  5879. {
  5880. DataStruct dStruct = GetPostStruct();
  5881. List<string> lw = new List<string>();
  5882. int st = GetInt("st");
  5883. string tid = GetPostString("ctid");
  5884. if (st == 3)
  5885. {
  5886. if (tid.Length > 0)
  5887. {
  5888. string select_tid = getTidByCtid(tid);
  5889. lw.Add(string.Format("tid='{0}'", select_tid));
  5890. }
  5891. }
  5892. else
  5893. {
  5894. if (tid.Length > 0)
  5895. {
  5896. string select_tid = getTidByCtid(tid);
  5897. lw.Add(string.Format("tid='{0}'", select_tid));
  5898. }
  5899. }
  5900. string shopname = GetPostString("shopname");
  5901. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5902. string buyernick = GetPostString("buyer_nick");
  5903. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5904. string sellermemo = GetPostString("seller_memo");
  5905. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5906. string orderState = GetPostString("orderState");
  5907. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5908. string afterState = GetPostString("afterstate");
  5909. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5910. string date1 = GetPostString("date1");
  5911. string date2 = GetPostString("date2");
  5912. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5913. if (dw.Length > 0) lw.Add(dw);
  5914. string price1 = GetPostString("price1");
  5915. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5916. string price2 = GetPostString("price2");
  5917. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5918. //lw.Add(string.Format("IsRefund!={0}", 1));
  5919. string reason = GetPostString("reason");
  5920. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5921. string method = GetPostString("method");
  5922. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5923. string handler = GetPostString("handler");
  5924. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5925. string handledate1 = GetPostString("handledate1");
  5926. string handledate2 = GetPostString("handledate2");
  5927. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5928. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5929. string finish1 = GetPostString("finishdate1");
  5930. string finish2 = GetPostString("finishdate2");
  5931. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5932. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5933. string afterdate1 = GetPostString("afterdate1");
  5934. string afterdate2 = GetPostString("afterdate2");
  5935. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5936. if (afterDate.Length > 0) lw.Add(afterDate);
  5937. string supplier = GetPostString("supplier");
  5938. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5939. string responsible = GetPostString("responsibleman");
  5940. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5941. string customer = GetPostString("customer");
  5942. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5943. string design = GetPostString("design");
  5944. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5945. string afterMemoType = GetPostString("aftermemotype");
  5946. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5947. string posCode = CurrentUser.UserPost.Post.Code;
  5948. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5949. //{
  5950. // string vstate = GetPostString("vstate");
  5951. // if (vstate.Length > 0)
  5952. // {
  5953. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5954. // }
  5955. // if (posCode == "Supplier")
  5956. // {
  5957. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5958. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5959. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5960. // }
  5961. // else
  5962. // {
  5963. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5964. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5965. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5966. // {
  5967. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5968. // }
  5969. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5970. // {
  5971. // int orgid = CurrentUser.UserPost.OrgID;
  5972. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5973. // }
  5974. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5975. // {
  5976. // string shopid = CurrentUser.User.pemShop;
  5977. // lw.Add(string.Format("shopId in ({0})", shopid));
  5978. // }
  5979. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5980. // //{
  5981. // // int org_id = CurrentUser.UserPost.OrgID;
  5982. // // lw.Add(string.Format("OrgID={0}", org_id));
  5983. // //}
  5984. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5985. // }
  5986. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5987. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5988. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5989. //}
  5990. if (st == 5)
  5991. {
  5992. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5993. {
  5994. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5995. {
  5996. string shopid = CurrentUser.User.pemShop;
  5997. lw.Add(string.Format("shopId in ({0})", shopid));
  5998. }
  5999. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6000. {
  6001. int mrOrgid = CurrentUser.UserPost.OrgID;
  6002. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6003. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6004. }
  6005. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6006. //{
  6007. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6008. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6009. //}
  6010. else
  6011. {
  6012. string userIdStr = "";
  6013. if (posCode == "CustomerService")
  6014. {
  6015. userIdStr = CurrentUser.UserID + "_k";
  6016. }
  6017. else if (posCode == "Designer" || posCode == "wxDesigner")
  6018. {
  6019. userIdStr = CurrentUser.UserID + "_s";
  6020. }
  6021. else if (posCode == "Place")
  6022. {
  6023. userIdStr = CurrentUser.UserID + "_x";
  6024. }
  6025. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6026. }
  6027. }
  6028. string placedate1 = GetPostString("placedate1");
  6029. string placedate2 = GetPostString("placedate2");
  6030. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6031. if (dwplace.Length > 0) lw.Add(dwplace);
  6032. string supState = GetPostString("supState");
  6033. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6034. string searchType = GetPostString("searchType");
  6035. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6036. {
  6037. lw.Add(string.Format("BackNum>1"));
  6038. }
  6039. lw.Add(string.Format("AfterSaleState>0"));
  6040. if (ex_psize > 0)
  6041. {
  6042. if (CurrentUser.UserPost.Post.Code == "Finance")
  6043. dStruct.Order = "pay_time desc";
  6044. else
  6045. dStruct.Order = "HandleTime desc";
  6046. }
  6047. else
  6048. dStruct.Order = "HandleTime desc";
  6049. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6050. DataTable dt = WebCache.GetData("view_test", dStruct);
  6051. writeGridDataTableJson(dStruct.TotalCount, dt);
  6052. }
  6053. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6054. //{
  6055. // lw.Add(string.Format("AfterSaleState=4"));
  6056. // string code = CurrentUser.UserPost.Post.Code;
  6057. // if (code == "CustomerService")
  6058. // {
  6059. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6060. // }
  6061. // else if (code == "Designer" || code == "DesignerMr")
  6062. // {
  6063. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6064. // }
  6065. // else if (code == "Place" || code == "PlaceMr")
  6066. // {
  6067. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6068. // }
  6069. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6070. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6071. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6072. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6073. //}
  6074. //else //处理中的售后,待处理和处理中合并
  6075. //{
  6076. // if (afterState.Length <= 0)
  6077. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6078. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6079. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6080. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6081. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6082. //}
  6083. }
  6084. public void get_erp_disagreeftersalelist()
  6085. {
  6086. DataStruct dStruct = GetPostStruct();
  6087. List<string> lw = new List<string>();
  6088. int st = 2;
  6089. string tid = GetPostString("ctid");
  6090. if (tid.Length > 0)
  6091. {
  6092. string select_tid = getTidByCtid(tid);
  6093. lw.Add(string.Format("tid='{0}'", select_tid));
  6094. }
  6095. string shopname = GetPostString("shopname");
  6096. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6097. string buyernick = GetPostString("buyer_nick");
  6098. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6099. string sellermemo = GetPostString("seller_memo");
  6100. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6101. string orderState = GetPostString("orderState");
  6102. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6103. string afterState = GetPostString("afterstate");
  6104. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6105. string date1 = GetPostString("date1");
  6106. string date2 = GetPostString("date2");
  6107. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6108. if (dw.Length > 0) lw.Add(dw);
  6109. string price1 = GetPostString("price1");
  6110. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6111. string price2 = GetPostString("price2");
  6112. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6113. //lw.Add(string.Format("IsRefund!={0}", 1));
  6114. string reason = GetPostString("reason");
  6115. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6116. string method = GetPostString("method");
  6117. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6118. string handler = GetPostString("handler");
  6119. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6120. string handledate1 = GetPostString("handledate1");
  6121. string handledate2 = GetPostString("handledate2");
  6122. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6123. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6124. string afterdate1 = GetPostString("afterdate1");
  6125. string afterdate2 = GetPostString("afterdate2");
  6126. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6127. if (afterDate.Length > 0) lw.Add(afterDate);
  6128. string backdate1 = GetPostString("backdate1");
  6129. string backdate2 = GetPostString("backdate2");
  6130. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6131. if (backDate.Length > 0) lw.Add(backDate);
  6132. string supplier = GetPostString("supplier");
  6133. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6134. string responsible = GetPostString("responsibleman");
  6135. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6136. string customer = GetPostString("customer");
  6137. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6138. string design = GetPostString("design");
  6139. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6140. string afterSaleMemo = GetPostString("afterSaleMemo");
  6141. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6142. string afterMemoType = GetPostString("aftermemotype");
  6143. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6144. string aftersakereason = GetPostString("aftersakereason");
  6145. if (aftersakereason.Length > 0)
  6146. {
  6147. if (aftersakereason == "1")
  6148. {
  6149. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6150. }
  6151. if (aftersakereason == "2")
  6152. {
  6153. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6154. }
  6155. }
  6156. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6157. string poscode = CurrentUser.UserPost.Post.Code;
  6158. if (poscode != "SysAdmin")
  6159. {
  6160. string shopid = CurrentUser.User.pemShop;
  6161. lw.Add(string.Format("shopId in ({0})", shopid));
  6162. }
  6163. string searchType = GetPostString("searchType");
  6164. if (searchType == "wait")
  6165. {
  6166. lw.Add(string.Format("HandleTime is null"));
  6167. }
  6168. if (searchType == "handling")
  6169. {
  6170. lw.Add(string.Format("HandleTime is not null "));
  6171. }
  6172. if (searchType == "back" || searchType == "puBack")
  6173. {
  6174. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6175. }
  6176. if (searchType == "reBack")
  6177. {
  6178. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6179. }
  6180. if (searchType == "moreBack")
  6181. {
  6182. lw.Add(string.Format("backNum > 1"));
  6183. }
  6184. lw.Add(string.Format("(AfterSaleState=5)"));
  6185. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6186. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6187. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6188. writeGridDataTableJson(dStruct.TotalCount, dt);
  6189. }
  6190. public void get_erp_handlingaftersalelist()
  6191. {
  6192. DataStruct dStruct = GetPostStruct();
  6193. List<string> lw = new List<string>();
  6194. int st = 2;
  6195. string tid = GetPostString("ctid");
  6196. if (tid.Length > 0)
  6197. {
  6198. string select_tid = getTidByCtid(tid);
  6199. lw.Add(string.Format("tid='{0}'", select_tid));
  6200. }
  6201. string shopname = GetPostString("shopname");
  6202. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6203. string buyernick = GetPostString("buyer_nick");
  6204. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6205. string sellermemo = GetPostString("seller_memo");
  6206. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6207. string orderState = GetPostString("orderState");
  6208. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6209. string afterState = GetPostString("afterstate");
  6210. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6211. string date1 = GetPostString("date1");
  6212. string date2 = GetPostString("date2");
  6213. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6214. if (dw.Length > 0) lw.Add(dw);
  6215. string price1 = GetPostString("price1");
  6216. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6217. string price2 = GetPostString("price2");
  6218. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6219. //lw.Add(string.Format("IsRefund!={0}", 1));
  6220. string reason = GetPostString("reason");
  6221. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6222. string method = GetPostString("method");
  6223. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6224. string handler = GetPostString("handler");
  6225. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6226. string handledate1 = GetPostString("handledate1");
  6227. string handledate2 = GetPostString("handledate2");
  6228. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6229. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6230. string afterdate1 = GetPostString("afterdate1");
  6231. string afterdate2 = GetPostString("afterdate2");
  6232. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6233. if (afterDate.Length > 0) lw.Add(afterDate);
  6234. string supplier = GetPostString("supplier");
  6235. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6236. string responsible = GetPostString("responsibleman");
  6237. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6238. string customer = GetPostString("customer");
  6239. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6240. string design = GetPostString("design");
  6241. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6242. string afterSaleMemo = GetPostString("afterSaleMemo");
  6243. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6244. string afterMemoType = GetPostString("aftermemotype");
  6245. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6246. string afterresult = GetPostString("afterresult");
  6247. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6248. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6249. string poscode = CurrentUser.UserPost.Post.Code;
  6250. if (poscode != "SysAdmin")
  6251. {
  6252. string shopid = CurrentUser.User.pemShop;
  6253. lw.Add(string.Format("shopId in ({0})", shopid));
  6254. }
  6255. string searchType = GetPostString("searchType");
  6256. if (searchType == "wait")
  6257. {
  6258. lw.Add(string.Format("HandleTime is null"));
  6259. }
  6260. if (searchType == "documentary")
  6261. {
  6262. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6263. }
  6264. if (searchType == "handling")
  6265. {
  6266. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6267. }
  6268. if (searchType == "back" || searchType == "puBack")
  6269. {
  6270. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6271. }
  6272. if (searchType == "reBack")
  6273. {
  6274. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6275. }
  6276. if (afterState.Length <= 0)
  6277. {
  6278. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6279. }
  6280. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6281. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6282. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6283. writeGridDataTableJson(dStruct.TotalCount, dt);
  6284. }
  6285. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6286. //public void get_erp_back_handlingaftersalelist()
  6287. //{
  6288. // DataStruct dStruct = GetPostStruct();
  6289. // List<string> lw = new List<string>();
  6290. // string tid = GetPostString("ctid");
  6291. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6292. // string shopname = GetPostString("shopname");
  6293. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6294. // string buyernick = GetPostString("buyer_nick");
  6295. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6296. // string sellermemo = GetPostString("seller_memo");
  6297. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6298. // string orderState = GetPostString("orderState");
  6299. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6300. // string afterState = GetPostString("afterstate");
  6301. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6302. // string date1 = GetPostString("date1");
  6303. // string date2 = GetPostString("date2");
  6304. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6305. // if (dw.Length > 0) lw.Add(dw);
  6306. // string price1 = GetPostString("price1");
  6307. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6308. // string price2 = GetPostString("price2");
  6309. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6310. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6311. // string reason = GetPostString("reason");
  6312. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6313. // string method = GetPostString("method");
  6314. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6315. // string handler = GetPostString("handler");
  6316. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6317. // string handledate1 = GetPostString("handledate1");
  6318. // string handledate2 = GetPostString("handledate2");
  6319. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6320. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6321. // string afterdate1 = GetPostString("afterdate1");
  6322. // string afterdate2 = GetPostString("afterdate2");
  6323. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6324. // if (afterDate.Length > 0) lw.Add(afterDate);
  6325. // string supplier = GetPostString("supplier");
  6326. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6327. // string responsible = GetPostString("responsibleman");
  6328. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6329. // string customer = GetPostString("customer");
  6330. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6331. // string design = GetPostString("design");
  6332. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6333. // string afterMemoType = GetPostString("aftermemotype");
  6334. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6335. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6336. // if (afterState.Length <= 0)
  6337. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6338. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6339. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6340. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6341. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6342. //}
  6343. public void get_erp_aftersaleverifylist()
  6344. {
  6345. DataStruct dStruct = GetPostStruct();
  6346. List<string> lw = new List<string>();
  6347. string tid = GetPostString("ctid");
  6348. if (tid.Length > 0)
  6349. {
  6350. string select_tid = getTidByCtid(tid);
  6351. lw.Add(string.Format("otid='{0}'", select_tid));
  6352. }
  6353. string shopname = GetPostString("shopname");
  6354. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6355. string buyernick = GetPostString("buyer_nick");
  6356. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6357. string sellermemo = GetPostString("seller_memo");
  6358. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6359. string orderState = GetPostString("orderState");
  6360. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6361. //lw.Add(string.Format("IsRefund!={0}", 1));
  6362. string reason = GetPostString("reason");
  6363. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6364. string method = GetPostString("method");
  6365. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6366. string handler = GetPostString("handler");
  6367. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6368. string handledate1 = GetPostString("handledate1");
  6369. string handledate2 = GetPostString("handledate2");
  6370. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6371. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6372. string finish1 = GetPostString("finishdate1");
  6373. string finish2 = GetPostString("finishdate2");
  6374. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6375. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6376. string supplier = GetPostString("supplier");
  6377. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6378. string responsible = GetPostString("responsibleman");
  6379. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6380. string posCode = CurrentUser.UserPost.Post.Code;
  6381. string vstate = GetPostString("vstate");
  6382. if (vstate.Length > 0)
  6383. {
  6384. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6385. }
  6386. if (posCode == "Supplier")
  6387. {
  6388. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6389. lw.Add(string.Format("VerifyState = 0"));
  6390. lw.Add("type = 1");
  6391. lw.Add(string.Format("AfterSaleState={0}", 3));
  6392. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6393. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6394. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6395. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6396. writeGridDataTableJson(dStruct.TotalCount, dt);
  6397. }
  6398. else if (posCode == "logistics")
  6399. {
  6400. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6401. lw.Add(string.Format("VerifyState = 0"));
  6402. lw.Add("type = 2");
  6403. lw.Add(string.Format("AfterSaleState={0}", 3));
  6404. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6405. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6406. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6407. writeGridDataTableJson(dStruct.TotalCount, dt);
  6408. }
  6409. else
  6410. {
  6411. lw.Add(string.Format("(AfterSaleState = 3)"));
  6412. string reasonState = GetPostString("reasonState");
  6413. lw.Add("type = 0");
  6414. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6415. || posCode == "Summarize" || posCode == "Finance")
  6416. {
  6417. if (reasonState == "2")
  6418. {
  6419. lw.Add("VerifyState = 3");
  6420. }
  6421. else if (reasonState == "1")
  6422. {
  6423. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6424. }
  6425. else
  6426. {
  6427. lw.Add("VerifyState in (0,3)");
  6428. }
  6429. //不加条件,可以看全部
  6430. }
  6431. 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")
  6432. {
  6433. int orgid = CurrentUser.UserPost.OrgID;
  6434. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6435. if (string.IsNullOrEmpty(manageOrgId))
  6436. {
  6437. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6438. }
  6439. else
  6440. {
  6441. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6442. }
  6443. if (reasonState == "1")
  6444. {
  6445. lw.Add("VerifyState = 3");
  6446. }
  6447. else if (reasonState == "2")
  6448. {
  6449. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6450. }
  6451. else
  6452. {
  6453. }
  6454. }
  6455. else
  6456. {
  6457. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6458. }
  6459. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6460. //{
  6461. // int org_id = CurrentUser.UserPost.OrgID;
  6462. // lw.Add(string.Format("OrgID={0}", org_id));
  6463. //}
  6464. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6465. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6466. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6467. writeGridDataTableJson(dStruct.TotalCount, dt);
  6468. }
  6469. }
  6470. public void get_erp_finishaftersalelist()
  6471. {
  6472. DataStruct dStruct = GetPostStruct();
  6473. List<string> lw = new List<string>();
  6474. int st = 4;
  6475. string tid = GetPostString("ctid");
  6476. if (tid.Length > 0)
  6477. {
  6478. string select_tid = getTidByCtid(tid);
  6479. lw.Add(string.Format("otid='{0}'", select_tid));
  6480. }
  6481. string shopname = GetPostString("shopname");
  6482. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6483. //lw.Add(string.Format("IsRefund!={0}", 1));
  6484. string reason = GetPostString("reason");
  6485. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6486. string method = GetPostString("method");
  6487. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6488. string buyernick = GetPostString("buyer_nick");
  6489. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6490. string handler = GetPostString("handler");
  6491. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6492. string handledate1 = GetPostString("handledate1");
  6493. string handledate2 = GetPostString("handledate2");
  6494. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6495. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6496. string finish1 = GetPostString("finishdate1");
  6497. string finish2 = GetPostString("finishdate2");
  6498. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6499. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6500. string supplier = GetPostString("supplier");
  6501. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6502. string responsible = GetPostString("responsibleman");
  6503. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6504. string vstate = GetPostString("vstate");
  6505. if (vstate.Length > 0)
  6506. {
  6507. if ("3".Equals(vstate))
  6508. {
  6509. lw.Add(string.Format("IsTem=1"));
  6510. }
  6511. else
  6512. {
  6513. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6514. }
  6515. }
  6516. lw.Add(string.Format("AfterSaleState=4"));
  6517. string code = CurrentUser.UserPost.Post.Code;
  6518. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6519. {
  6520. //不加条件,可以看全部
  6521. }
  6522. else if (code == "Supplier")
  6523. {
  6524. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6525. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6526. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6527. }
  6528. else if (code == "logistics")
  6529. {
  6530. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6531. lw.Add("type = 2");
  6532. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6533. }
  6534. 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")
  6535. {
  6536. int orgid = CurrentUser.UserPost.OrgID;
  6537. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6538. if (string.IsNullOrEmpty(manageOrgIds))
  6539. {
  6540. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6541. }
  6542. else
  6543. {
  6544. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6545. }
  6546. }
  6547. else
  6548. {
  6549. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6550. }
  6551. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6552. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6553. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6554. writeGridDataTableJson(dStruct.TotalCount, dt);
  6555. }
  6556. public void handle_erp_aftersale()
  6557. {
  6558. if (UrlPostParmsCheck("ctid"))
  6559. {
  6560. string eid = GetPostString("ctid");
  6561. string responStr = GetPostString("AfterSaleResponsible");
  6562. if (responStr.Length <= 0)
  6563. {
  6564. returnErrorMsg("售后责任人不能为空");
  6565. return;
  6566. }
  6567. bool isDesign = false;
  6568. double designFree = 0.00;
  6569. int responsibleId = 0;
  6570. CeErpTradeCell entity = null;
  6571. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6572. if (entity != null)
  6573. {
  6574. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6575. string afterMethod = GetPostString("AfterSaleMethod");
  6576. if (isNeedNewOrder == 1)
  6577. {
  6578. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6579. bool ishav = true;
  6580. if (newentity == null)
  6581. {
  6582. newentity = entity.Clone() as CeErpTradeCell;
  6583. ishav = false;
  6584. newentity.ctid = "S_" + entity.ctid;
  6585. newentity.OrderState = 0;
  6586. //唯一标识
  6587. newentity.OrderSn = newentity.ctid;
  6588. string orderSn = dataHelper.getSaleOrderSn();
  6589. if (orderSn != "")
  6590. {
  6591. newentity.OrderSn = orderSn;
  6592. }
  6593. }
  6594. newentity.UpdateTime = DateTime.Now;
  6595. newentity.AfterSaleState = 0;
  6596. newentity.AfterSaleMethod = afterMethod;
  6597. if (!ishav)
  6598. {
  6599. string memo_str = newentity.seller_memo;
  6600. memo_str = memo_str.Replace("(", "(");
  6601. memo_str = memo_str.Replace(")", ")");
  6602. int sIndex = memo_str.IndexOf("(");
  6603. int eIndex = memo_str.IndexOf(")");
  6604. if (sIndex == -1 || eIndex == -1)
  6605. {
  6606. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6607. return;
  6608. }
  6609. string first = memo_str.Substring(0, sIndex + 1);
  6610. string memoCtid = newentity.OrderSn;
  6611. //if (memoCtid.IndexOf("C") != -1)
  6612. //{
  6613. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6614. //if (CIdx.IndexOf("+") != -1)
  6615. //{
  6616. //CIdx = "C" + CIdx.Split('+')[1];
  6617. //}
  6618. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6619. //}
  6620. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6621. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6622. string newMemo = first + memoCtid + last;
  6623. newentity.seller_memo = newMemo;
  6624. newentity.FinishPlaceTime = null;
  6625. newentity.UnusualTag = 0;
  6626. newentity.UnusualCon = "";
  6627. newentity.UnusualTime = null;
  6628. newentity.AfterSaleMemo = "";
  6629. newentity.AfterSaleMethod = afterMethod;
  6630. newentity.AfterSalePreTime = null;
  6631. newentity.AfterSaleReason = "";
  6632. newentity.AfterSaleResponsible = "";
  6633. newentity.AfterSaleState = 0;
  6634. newentity.AfterSaleTime = null;
  6635. newentity.AfterSaleUserId = 0;
  6636. newentity.AfterSaleSupplierState = 0;
  6637. newentity.LastBillWaybillCode = "";
  6638. newentity.LastBillCpCode = "";
  6639. newentity.FinishAfterSaleTime = null;
  6640. newentity.HandleTime = null;
  6641. newentity.IsSF = 0;
  6642. newentity.IsOldCustomer = 0;
  6643. newentity.UrgencyTime = null;
  6644. newentity.ResponsibleUserId = "";
  6645. newentity.IsVerifyToSupplier = false;
  6646. newentity.payment = 0;
  6647. newentity.CheckMemo = "";
  6648. newentity.OutSid = "";
  6649. newentity.CheckOrderTime = null;
  6650. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6651. }
  6652. newentity.isAfterSaleOrder = 1;
  6653. newentity.IsRefund = 0;
  6654. string receiveMobile = GetPostString("receiver_mobile");
  6655. if (receiveMobile.Length > 0)
  6656. {
  6657. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6658. if (trade != null)
  6659. {
  6660. trade.receiver_name = GetPostString("receiver_name");
  6661. trade.receiver_mobile = receiveMobile;
  6662. trade.receiver_state = GetPostString("receiver_state");
  6663. trade.receiver_city = GetPostString("receiver_city");
  6664. trade.receiver_district = GetPostString("receiver_district");
  6665. trade.receiver_address = GetPostString("receiver_address");
  6666. newentity.IsOffLineOrder = 1;
  6667. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6668. }
  6669. }
  6670. string st = GetPostString("ToState");
  6671. if (st.Length > 0)
  6672. {
  6673. if (newentity.OrderState <= 3)
  6674. {
  6675. newentity.WaitDesignTime = DateTime.Now;
  6676. newentity.StartDesignTime = null;
  6677. newentity.FinishDesignTime = null;
  6678. newentity.OrderState = 3;
  6679. if (st == "下单员")
  6680. {
  6681. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6682. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6683. {
  6684. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6685. }
  6686. }
  6687. else
  6688. {
  6689. newentity.WaitDesignTime = DateTime.Now;
  6690. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6691. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6692. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6693. {
  6694. DataRow user = dt1.Rows[0];
  6695. //找主管
  6696. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6697. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6698. if (dt != null && dt.Rows.Count > 0)
  6699. {
  6700. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6701. newentity.DesignUserId = designMr;
  6702. string key = "aftersale_order_" + designMr;
  6703. if (RedisHelper.HasKey(key))
  6704. {
  6705. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6706. list.Add(newentity.ctid);
  6707. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6708. }
  6709. }
  6710. //账号正常
  6711. if (user["State"].ToString() == "0")
  6712. {
  6713. newentity.DesignUserId = entity.DesignUserId;
  6714. string key = "aftersale_order_" + entity.DesignUserId;
  6715. if (RedisHelper.HasKey(key))
  6716. {
  6717. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6718. list.Add(newentity.ctid);
  6719. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6720. }
  6721. }
  6722. }
  6723. }
  6724. }
  6725. if (entity.IsXianHuo == 1)
  6726. {
  6727. newentity.OrderState = 6;
  6728. entity.FinishPlaceTime = DateTime.Now;
  6729. }
  6730. }
  6731. if (ishav)
  6732. {
  6733. newentity.Update();
  6734. }
  6735. else
  6736. {
  6737. newentity.Create();
  6738. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6739. newCellExtend.ctid = newentity.ctid;
  6740. newCellExtend.orderFrom = 20;
  6741. newCellExtend.orderType = 30;
  6742. if (st == "下单员")
  6743. {
  6744. }
  6745. else
  6746. {
  6747. newCellExtend.ReprintTime = DateTime.Now;
  6748. }
  6749. newCellExtend.Create();
  6750. }
  6751. if (st != "下单员")
  6752. {
  6753. if (entity.DispatchSort == 2)
  6754. {
  6755. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6756. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6757. }
  6758. }
  6759. }
  6760. //处理售后扩展
  6761. string resIdStr = GetPostString("ResponsibleUserId");
  6762. string refundFees = GetPostString("refundFrees");
  6763. int IsComplain = GetPostInt("isComplain");
  6764. int IsBad = GetPostInt("isBad");
  6765. string IsOriginal = GetPostString("isOriginal");
  6766. double diffResultPrice = GetPostDouble("diffResultPrice");
  6767. string textResult = GetPostString("textResult");
  6768. string supplierResponsible = GetPostString("supplierResponsible");
  6769. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6770. if (ceErpTradeAfterSaleExtend == null)
  6771. {
  6772. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6773. ceErpTradeAfterSaleExtend.tid = eid;
  6774. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6775. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6776. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6777. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6778. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6779. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6780. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6781. ceErpTradeAfterSaleExtend.Create();
  6782. }
  6783. else
  6784. {
  6785. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6786. {
  6787. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6788. }
  6789. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6790. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6791. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6792. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6793. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6794. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6795. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6796. ceErpTradeAfterSaleExtend.Update();
  6797. }
  6798. int gysid = GetPostInt("ResponsibleSupId");
  6799. if (entity.AfterSaleUserId == 0)
  6800. {
  6801. entity.AfterSaleUserId = CurrentUser.UserID;
  6802. }
  6803. entity.ResponsibleUserId = resIdStr;
  6804. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6805. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6806. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6807. {
  6808. CeErpTradeResponsible.DelByTid(eid, -1);
  6809. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6810. int backNum = 0;
  6811. if (number != null)
  6812. {
  6813. backNum = number.BackNum;
  6814. }
  6815. char[] separator = { ',' };
  6816. string[] sArray = resIdStr.Split(separator);
  6817. string[] refundFreeList = { };
  6818. if (refundFees.Length > 0)
  6819. {
  6820. refundFreeList = refundFees.Split(separator);
  6821. }
  6822. int index = -1;
  6823. foreach (string i in sArray)
  6824. {
  6825. index++;
  6826. if (i.Length <= 0) continue;
  6827. char[] separator2 = { '_' };
  6828. string idstr = i.Split(separator2)[0];
  6829. string idtype = i.Split(separator2)[1];
  6830. double refudFree = 0;
  6831. if (refundFreeList.Length > 0)
  6832. {
  6833. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6834. }
  6835. if (idtype == "s")
  6836. {
  6837. isDesign = true;
  6838. designFree = refudFree;
  6839. }
  6840. int userId = Convert.ToInt32(idstr);
  6841. int type = 0;
  6842. if (idtype == "g")
  6843. {
  6844. type = 1;
  6845. }
  6846. if (idtype == "w")
  6847. {
  6848. type = 2;
  6849. }
  6850. if (idtype == "t")
  6851. {
  6852. type = 3;
  6853. }
  6854. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6855. if (ceErpTradeResponsible == null)
  6856. {
  6857. ceErpTradeResponsible = new CeErpTradeResponsible();
  6858. ceErpTradeResponsible.tid = eid;
  6859. ceErpTradeResponsible.UserId = userId;
  6860. ceErpTradeResponsible.createdTime = DateTime.Now;
  6861. ceErpTradeResponsible.type = type;
  6862. if (type == 1)
  6863. {
  6864. ceErpTradeResponsible.IsSup = 1;
  6865. }
  6866. if (type == 2)
  6867. {
  6868. ceErpTradeResponsible.IsFlow = 1;
  6869. }
  6870. }
  6871. ceErpTradeResponsible.RefundFee = refudFree;
  6872. ceErpTradeResponsible.VerifyState = 0;
  6873. if (userId == 2125 || idtype == "w")
  6874. {
  6875. ceErpTradeResponsible.VerifyState = 1;
  6876. }
  6877. if (idtype == "w" && userId == 101)
  6878. {
  6879. ceErpTradeResponsible.VerifyState = 0;
  6880. }
  6881. if (ceErpTradeResponsible.ID > 0)
  6882. {
  6883. ceErpTradeResponsible.Update();
  6884. }
  6885. else
  6886. {
  6887. ceErpTradeResponsible.Create();
  6888. }
  6889. if (isDesign)
  6890. {
  6891. responsibleId = ceErpTradeResponsible.ID;
  6892. }
  6893. }
  6894. CeErpTradeResponsible.NumByTid(backNum, eid);
  6895. }
  6896. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6897. if (ceErpTradeCellExtend != null)
  6898. {
  6899. ceErpTradeCellExtend.returnVisit = 0;
  6900. ceErpTradeCellExtend.Update();
  6901. }
  6902. if (entity.HandleTime != null)
  6903. {
  6904. if (entity.AfterSaleState == 1)
  6905. {
  6906. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6907. }
  6908. else
  6909. {
  6910. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6911. }
  6912. }
  6913. else
  6914. {
  6915. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6916. entity.HandleTime = DateTime.Now;
  6917. }
  6918. bool isCompale = false;
  6919. if (entity.AfterSaleState == 5)
  6920. {
  6921. isCompale = true;
  6922. entity.AfterSaleState = 3;
  6923. }
  6924. entity.AfterSaleSupplierState = 0;
  6925. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6926. {
  6927. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6928. }
  6929. string sImgs = GetPostString("img");
  6930. entity.AfterSaleSupplierImg = sImgs;
  6931. entity.supRefundType = GetPostString("supRefundType");
  6932. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6933. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6934. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6935. entity.AfterSaleMemoType = GetPostString("MemoType");
  6936. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6937. {
  6938. //entity.AfterSaleSupplierState = 2;
  6939. }
  6940. string df = GetPostString("DeductFee");
  6941. if (df == "")
  6942. {
  6943. df = "0";
  6944. }
  6945. string rf = GetPostString("RefundFee");
  6946. if (rf == "")
  6947. {
  6948. rf = "0";
  6949. }
  6950. string pm = GetPostString("AfterSalePayment");
  6951. if (pm == "")
  6952. {
  6953. pm = "0";
  6954. }
  6955. entity.AfterSalePayment = Convert.ToDouble(pm);
  6956. entity.DeductFee = Convert.ToDouble(df);
  6957. entity.RefundFee = Convert.ToDouble(rf);
  6958. entity.UpdateTime = DateTime.Now;
  6959. entity.Update();
  6960. string toState = GetPostString("ToState");
  6961. string original = GetPostString("isOriginal");
  6962. ApiVo apiVo = new ApiVo();
  6963. apiVo.orderNumber = entity.ctid;
  6964. apiVo.actionName = "afterDesign";
  6965. apiVo.orderRemarks = entity.AfterSaleMethod;
  6966. apiVo.reasonRemarks = entity.AfterSaleReason;
  6967. apiVo.isDesign = isDesign;
  6968. apiVo.designFree = designFree;
  6969. apiVo.responsibleId = responsibleId;
  6970. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6971. if (toState == "设计师")
  6972. {
  6973. apiVo.isOriginal = Convert.ToBoolean(original);
  6974. }
  6975. designHelper.API_WorkCore(apiVo);//afterDesign
  6976. CeErpMethod methodSql = new CeErpMethod();
  6977. methodSql.con = entity.AfterSaleMethod;
  6978. methodSql.addTime = DateTime.Now;
  6979. methodSql.Create();
  6980. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6981. CeErpMethod.ExecuteNonQuery(delsql);
  6982. if (isCompale)
  6983. {
  6984. aftersale_data_change(entity.ctid);
  6985. }
  6986. returnSuccessMsg("操作成功!");
  6987. return;
  6988. }
  6989. returnErrorMsg("找不到订单记录");
  6990. }
  6991. }
  6992. public void ins_erp_toresponsible()
  6993. {
  6994. if (UrlPostParmsCheck("ctid"))
  6995. {
  6996. string eid = GetPostString("ctid");
  6997. CeErpTradeCell entity = null;
  6998. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6999. if (entity != null)
  7000. {
  7001. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7002. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7003. {
  7004. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7005. return;
  7006. }
  7007. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7008. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7009. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7010. if (entity.AfterSalePreTime == null)
  7011. {
  7012. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7013. {
  7014. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7015. }
  7016. }
  7017. entity.AfterSalePreTime = DateTime.Now;
  7018. //预完成给售后主管审核客户问题直接完成
  7019. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7020. {
  7021. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7022. {
  7023. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7024. }
  7025. }
  7026. ceErpTradeAfterSaleExtend.Update();
  7027. entity.AfterSaleState = 2;
  7028. entity.UpdateTime = DateTime.Now;
  7029. entity.Update();
  7030. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7031. aftersale_data_change(entity.ctid);
  7032. returnSuccessMsg("操作成功!");
  7033. return;
  7034. }
  7035. returnErrorMsg("找不到订单记录");
  7036. }
  7037. }
  7038. public void cancel_erp_aftersaleanddelnew()
  7039. {
  7040. if (UrlPostParmsCheck("ctid"))
  7041. {
  7042. string eid = GetPostString("ctid");
  7043. CeErpTradeCell entity = null;
  7044. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7045. if (entity != null)
  7046. {
  7047. entity.AfterSaleState = 0;
  7048. entity.AfterSaleReason = "";
  7049. entity.AfterSaleMethod = "";
  7050. entity.AfterSaleMemo = "";
  7051. entity.AfterSaleResponsible = "";
  7052. entity.ResponsibleUserId = "";
  7053. entity.DeductFee = 0;
  7054. entity.RefundFee = 0;
  7055. entity.IsArbitrate = 0;
  7056. CeErpTradeResponsible.DelByTid(eid, -1);
  7057. entity.Update();
  7058. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7059. if (after != null)
  7060. {
  7061. if (after.OrderState < 5)
  7062. CeErpTradeCell.DelByCtid("S_" + eid);
  7063. }
  7064. returnSuccessMsg("操作成功!");
  7065. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7066. return;
  7067. }
  7068. returnErrorMsg("找不到订单记录");
  7069. }
  7070. }
  7071. public void get_erp_aftersale_pregather()
  7072. {
  7073. List<string> lw = new List<string>();
  7074. int st = GetInt("st");
  7075. string tid = GetPostString("ctid");
  7076. if (tid.Length > 0)
  7077. {
  7078. string select_tid = getTidByCtid(tid);
  7079. lw.Add(string.Format("tid='{0}'", select_tid));
  7080. }
  7081. string shopname = GetPostString("shopname");
  7082. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7083. string buyernick = GetPostString("buyer_nick");
  7084. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7085. string sellermemo = GetPostString("seller_memo");
  7086. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7087. string orderState = GetPostString("orderState");
  7088. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7089. string reason = GetPostString("reason");
  7090. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7091. string method = GetPostString("method");
  7092. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7093. string handler = GetPostString("handler");
  7094. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7095. string handledate1 = GetPostString("handledate1");
  7096. string handledate2 = GetPostString("handledate2");
  7097. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7098. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7099. string supplier = GetPostString("supplier");
  7100. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7101. string responsible = GetPostString("responsibleman");
  7102. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7103. string customer = GetPostString("customer");
  7104. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7105. string design = GetPostString("design");
  7106. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7107. string afterMemoType = GetPostString("aftermemotype");
  7108. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7109. string afterSaleMemo = GetPostString("afterSaleMemo");
  7110. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7111. string afterresult = GetPostString("afterresult");
  7112. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7113. string poscode = CurrentUser.UserPost.Post.Code;
  7114. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7115. {
  7116. string shopid = CurrentUser.User.pemShop;
  7117. lw.Add(string.Format("shopId in ({0})", shopid));
  7118. }
  7119. var mainwhere = string.Join(" and ", lw.ToArray());
  7120. string ro_json = "";
  7121. string type = GetPostString("gather_type");
  7122. int number = 0;
  7123. if (poscode == "AfterSale")
  7124. {
  7125. //处理中
  7126. if (type == "Handling")
  7127. {
  7128. 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) : ""));
  7129. DataTable dt = null;
  7130. try
  7131. {
  7132. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7133. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7134. }
  7135. catch (Exception e)
  7136. {
  7137. dt = new DataTable();
  7138. }
  7139. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7140. return;
  7141. }
  7142. if (type == "Wait")
  7143. {
  7144. //待处理
  7145. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7146. DataTable dt1 = null;
  7147. try
  7148. {
  7149. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7150. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7151. }
  7152. catch (Exception e)
  7153. {
  7154. dt1 = new DataTable();
  7155. }
  7156. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7157. return;
  7158. }
  7159. if (type == "back")
  7160. {
  7161. //打回
  7162. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7163. DataTable dt2 = null;
  7164. try
  7165. {
  7166. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7167. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7168. }
  7169. catch (Exception e)
  7170. {
  7171. dt2 = new DataTable();
  7172. }
  7173. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7174. return;
  7175. }
  7176. if (type == "preCompletion")
  7177. {
  7178. //预完成
  7179. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7180. DataTable dt3 = null;
  7181. try
  7182. {
  7183. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7184. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7185. }
  7186. catch (Exception e)
  7187. {
  7188. dt3 = new DataTable();
  7189. }
  7190. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7191. return;
  7192. }
  7193. if (type == "documentary")
  7194. {
  7195. //跟单中
  7196. 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) : ""));
  7197. DataTable dt4 = null;
  7198. try
  7199. {
  7200. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7201. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7202. }
  7203. catch (Exception e)
  7204. {
  7205. dt4 = new DataTable();
  7206. }
  7207. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7208. return;
  7209. }
  7210. if (type == "reBack")
  7211. {
  7212. //被打回
  7213. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7214. DataTable dt1 = null;
  7215. try
  7216. {
  7217. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7218. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7219. }
  7220. catch (Exception e)
  7221. {
  7222. dt1 = new DataTable();
  7223. }
  7224. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7225. return;
  7226. }
  7227. }
  7228. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7229. {
  7230. if (type == "puBack")
  7231. {
  7232. //退回
  7233. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7234. DataTable dt = null;
  7235. try
  7236. {
  7237. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7238. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7239. }
  7240. catch (Exception e)
  7241. {
  7242. dt = new DataTable();
  7243. }
  7244. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7245. return;
  7246. }
  7247. if (type == "reBack")
  7248. {
  7249. //打回
  7250. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7251. DataTable dt1 = null;
  7252. try
  7253. {
  7254. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7255. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7256. }
  7257. catch (Exception e)
  7258. {
  7259. dt1 = new DataTable();
  7260. }
  7261. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7262. return;
  7263. }
  7264. if (type == "examEd")
  7265. {
  7266. //已审核
  7267. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7268. DataTable dt2 = null;
  7269. try
  7270. {
  7271. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7272. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7273. }
  7274. catch (Exception e)
  7275. {
  7276. dt2 = new DataTable();
  7277. }
  7278. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7279. return;
  7280. }
  7281. if (type == "waitExam")
  7282. {
  7283. //待审核
  7284. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7285. DataTable dt3 = null;
  7286. try
  7287. {
  7288. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7289. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7290. }
  7291. catch (Exception e)
  7292. {
  7293. dt3 = new DataTable();
  7294. }
  7295. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7296. return;
  7297. }
  7298. if (type == "Handling")
  7299. {
  7300. //处理中
  7301. 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) : ""));
  7302. DataTable dt4 = null;
  7303. try
  7304. {
  7305. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7306. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7307. }
  7308. catch (Exception e)
  7309. {
  7310. dt4 = new DataTable();
  7311. }
  7312. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7313. return;
  7314. }
  7315. if (type == "Wait")
  7316. {
  7317. //待处理
  7318. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7319. DataTable dt5 = null;
  7320. try
  7321. {
  7322. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7323. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7324. }
  7325. catch (Exception e)
  7326. {
  7327. dt5 = new DataTable();
  7328. }
  7329. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7330. return;
  7331. }
  7332. if (type == "documentary")
  7333. {
  7334. //跟单中
  7335. 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) : ""));
  7336. DataTable dt6 = null;
  7337. try
  7338. {
  7339. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7340. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7341. }
  7342. catch (Exception e)
  7343. {
  7344. dt6 = new DataTable();
  7345. }
  7346. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7347. return;
  7348. }
  7349. }
  7350. returnSuccess(ro_json);
  7351. }
  7352. public void end_erp_aftersale()
  7353. {
  7354. if (UrlPostParmsCheck("ctid"))
  7355. {
  7356. string eid = GetPostString("ctid");
  7357. CeErpTradeCell entity = null;
  7358. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7359. if (entity != null)
  7360. {
  7361. string stype = GetPostString("stype");
  7362. string typeStr = stype;
  7363. entity.AfterSaleState = 4;
  7364. entity.FinishAfterSaleTime = DateTime.Now;
  7365. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7366. entity.Update();
  7367. ApiVo apiVo = new ApiVo();
  7368. apiVo.orderNumber = entity.ctid;
  7369. apiVo.actionName = "afterOver";
  7370. designHelper.API_WorkCore(apiVo); //afterOver
  7371. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7372. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7373. CeErpSukuraData.createInfo(entity.ctid, 8);
  7374. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7375. returnSuccessMsg("操作成功!");
  7376. return;
  7377. }
  7378. returnErrorMsg("找不到订单记录");
  7379. }
  7380. }
  7381. public void ins_erp_finishaftersale()
  7382. {
  7383. if (UrlPostParmsCheck("id"))
  7384. {
  7385. string eid = GetPostString("id");
  7386. CeErpTradeResponsible entity = null;
  7387. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7388. if (entity != null)
  7389. {
  7390. entity.VerifyState = 1;
  7391. entity.VerifyTime = DateTime.Now;
  7392. entity.Update();
  7393. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7394. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7395. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7396. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7397. if (dt.Rows.Count <= 0)
  7398. {
  7399. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7400. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7401. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7402. CeErpSukuraData.createInfo(entity.tid, 8);
  7403. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7404. {
  7405. CeErpDesignerBill.Del(entity.tid);
  7406. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7407. }
  7408. }
  7409. returnSuccessMsg("操作成功!");
  7410. return;
  7411. }
  7412. returnErrorMsg("找不到订单记录");
  7413. }
  7414. }
  7415. public void upd_erp_arbitrateaftersale()
  7416. {
  7417. if (UrlPostParmsCheck("id"))
  7418. {
  7419. string eid = GetPostString("id");
  7420. CeErpTradeResponsible entity = null;
  7421. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7422. if (entity != null)
  7423. {
  7424. entity.IsArbitrate = 1;
  7425. entity.ArbitradeMemo = GetPostString("reason");
  7426. entity.VerifyState = 2;
  7427. entity.Update();
  7428. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7429. if (tradecell != null)
  7430. {
  7431. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7432. tradecell.IsArbitrate = 1;
  7433. tradecell.Update();
  7434. }
  7435. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7436. returnSuccessMsg("操作成功!");
  7437. return;
  7438. }
  7439. returnErrorMsg("找不到订单记录");
  7440. }
  7441. }
  7442. public void upd_erp_backaftersale()
  7443. {
  7444. if (UrlPostParmsCheck("tid"))
  7445. {
  7446. string eid = GetPostString("tid");
  7447. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7448. int backNum = 0;
  7449. if (number != null)
  7450. {
  7451. backNum = number.BackNum;
  7452. }
  7453. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7454. CeErpTradeCell entity = null;
  7455. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7456. if (entity != null)
  7457. {
  7458. entity.AfterSaleBackReason = GetPostString("backreason");
  7459. entity.AfterSaleState = 1;
  7460. entity.AfterSaleSupplierState = 0;
  7461. entity.UpdateTime = DateTime.Now;
  7462. entity.Update();
  7463. returnSuccessMsg("操作成功!");
  7464. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7465. return;
  7466. }
  7467. returnErrorMsg("找不到订单记录");
  7468. }
  7469. }
  7470. public void get_erp_supplieraftersalelist()
  7471. {
  7472. DataStruct dStruct = GetPostStruct();
  7473. List<string> lw = new List<string>();
  7474. string tid = GetPostString("ctid");
  7475. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7476. string shopname = GetPostString("shopname");
  7477. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7478. string buyernick = GetPostString("buyer_nick");
  7479. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7480. string sellermemo = GetPostString("seller_memo");
  7481. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7482. string orderState = GetPostString("orderState");
  7483. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7484. string afterState = GetPostString("afterstate");
  7485. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7486. string date1 = GetPostString("date1");
  7487. string date2 = GetPostString("date2");
  7488. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7489. if (dw.Length > 0) lw.Add(dw);
  7490. string price1 = GetPostString("price1");
  7491. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7492. string price2 = GetPostString("price2");
  7493. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7494. string reason = GetPostString("reason");
  7495. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7496. string method = GetPostString("method");
  7497. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7498. string handledate1 = GetPostString("handledate1");
  7499. string handledate2 = GetPostString("handledate2");
  7500. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7501. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7502. string handler = GetPostString("handler");
  7503. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7504. string afterdate1 = GetPostString("afterdate1");
  7505. string afterdate2 = GetPostString("afterdate2");
  7506. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7507. if (afterDate.Length > 0) lw.Add(afterDate);
  7508. string customer = GetPostString("customer");
  7509. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7510. string design = GetPostString("design");
  7511. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7512. string afterMemoType = GetPostString("aftermemotype");
  7513. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7514. string vstate = GetPostString("vstate");
  7515. if (vstate.Length > 0)
  7516. {
  7517. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7518. }
  7519. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7520. string supplier = GetPostString("supplier");
  7521. int supid = commonHelper.getSupplierIDByName(supplier);
  7522. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7523. string posCode = CurrentUser.UserPost.Post.Code;
  7524. if (posCode == "Supplier")
  7525. {
  7526. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7527. }
  7528. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7529. {
  7530. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7531. }
  7532. else
  7533. {
  7534. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7535. }
  7536. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7537. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7538. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7539. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7540. writeGridDataTableJson(dStruct.TotalCount, dt);
  7541. }
  7542. public void upd_erp_supverifyaftersale()
  7543. {
  7544. if (UrlPostParmsCheck("id"))
  7545. {
  7546. string id = GetPostString("id");
  7547. int st = GetPostInt("afterstate");
  7548. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7549. CeErpTradeCell entity = null;
  7550. if (ceErpTradeResponsible != null)
  7551. {
  7552. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7553. }
  7554. string afmemo = GetPostString("supmemo");
  7555. string image = GetPostString("image");
  7556. if (entity != null)
  7557. {
  7558. entity.AfterSaleSupplierState = st;
  7559. entity.AfterSaleSupplierMemo = afmemo;
  7560. if (st == 1)
  7561. {
  7562. ceErpTradeResponsible.VerifyState = 1;
  7563. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7564. ceErpTradeResponsible.Update();
  7565. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7566. if (isAll)
  7567. {
  7568. entity.AfterSaleState = 4;
  7569. entity.FinishAfterSaleTime = DateTime.Now;
  7570. }
  7571. }
  7572. else
  7573. {
  7574. CeErpTradeResponsible.dateByTid(entity.ctid);
  7575. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7576. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7577. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7578. if (num <= 1)
  7579. {
  7580. entity.AfterSaleState = 1;
  7581. }
  7582. else
  7583. {
  7584. entity.AfterSaleState = 5;
  7585. }
  7586. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7587. if (ceErpTradeAfterSaleExtend != null)
  7588. {
  7589. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7590. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7591. ceErpTradeAfterSaleExtend.Update();
  7592. }
  7593. else
  7594. {
  7595. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7596. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7597. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7598. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7599. ceErpTradeAfterSaleExtend.Create();
  7600. }
  7601. }
  7602. if (entity.AfterSaleState == 4)
  7603. {
  7604. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7605. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7606. {
  7607. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7608. }
  7609. ApiVo apiVo = new ApiVo();
  7610. apiVo.orderNumber = entity.ctid;
  7611. apiVo.actionName = "afterOver";
  7612. designHelper.API_WorkCore(apiVo); //afterOver
  7613. }
  7614. entity.UpdateTime = DateTime.Now;
  7615. entity.Update();
  7616. returnSuccessMsg("操作成功!");
  7617. CeErpSukuraData.createInfo(entity.ctid, 8);
  7618. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7619. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7620. return;
  7621. }
  7622. returnErrorMsg("找不到订单记录");
  7623. }
  7624. }
  7625. public void upd_erp_masteraftersale()
  7626. {
  7627. if (UrlPostParmsCheck("id"))
  7628. {
  7629. string id = GetPostString("id");
  7630. int st = GetPostInt("afterstate");
  7631. string afmemo = GetPostString("supmemo");
  7632. string image = GetPostString("image");
  7633. string textResult = GetPostString("textResult");
  7634. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7635. if (ceErpTradeResponsible != null)
  7636. {
  7637. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7638. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7639. ceErpTradeResponsible.Update();
  7640. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7641. if (entity != null)
  7642. {
  7643. entity.AfterSaleSupplierState = st;
  7644. entity.AfterSaleSupplierMemo = afmemo;
  7645. if (st == 1)
  7646. {
  7647. }
  7648. else
  7649. {
  7650. CeErpTradeResponsible.dateByTid(entity.ctid);
  7651. //退回到售后
  7652. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7653. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7654. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7655. if (num <= 1)
  7656. {
  7657. entity.AfterSaleState = 1;
  7658. }
  7659. else
  7660. {
  7661. entity.AfterSaleState = 5;
  7662. }
  7663. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7664. if (ceErpTradeAfterSaleExtend != null)
  7665. {
  7666. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7667. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7668. ceErpTradeAfterSaleExtend.Update();
  7669. }
  7670. else
  7671. {
  7672. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7673. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7674. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7675. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7676. ceErpTradeAfterSaleExtend.Create();
  7677. }
  7678. }
  7679. entity.UpdateTime = DateTime.Now;
  7680. entity.Update();
  7681. returnSuccessMsg("操作成功!");
  7682. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7683. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7684. return;
  7685. }
  7686. }
  7687. returnErrorMsg("找不到订单记录");
  7688. }
  7689. }
  7690. public void upd_erp_personaftersale()
  7691. {
  7692. if (UrlPostParmsCheck("id"))
  7693. {
  7694. //林小连
  7695. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7696. {
  7697. upd_erp_masteraftersale();
  7698. return;
  7699. }
  7700. string id = GetPostString("id");
  7701. int st = GetPostInt("afterstate");
  7702. string afmemo = GetPostString("supmemo");
  7703. string image = GetPostString("image");
  7704. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7705. if (ceErpTradeResponsible != null)
  7706. {
  7707. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7708. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7709. ceErpTradeResponsible.Update();
  7710. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7711. if (entity != null)
  7712. {
  7713. entity.AfterSaleSupplierMemo = afmemo;
  7714. entity.AfterSaleSupplierState = st;
  7715. if (st == 1)
  7716. {
  7717. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7718. if (isAll)
  7719. {
  7720. entity.AfterSaleState = 4;
  7721. entity.FinishAfterSaleTime = DateTime.Now;
  7722. }
  7723. }
  7724. else
  7725. {
  7726. CeErpTradeResponsible.dateByTid(entity.ctid);
  7727. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7728. if (ceErpTradeAfterSaleExtend != null)
  7729. {
  7730. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7731. ceErpTradeAfterSaleExtend.Update();
  7732. }
  7733. else
  7734. {
  7735. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7736. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7737. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7738. ceErpTradeAfterSaleExtend.Create();
  7739. }
  7740. //退回到主管
  7741. //entity.AfterSaleState = 2;
  7742. }
  7743. if (entity.AfterSaleState == 4)
  7744. {
  7745. ApiVo apiVo = new ApiVo();
  7746. apiVo.orderNumber = entity.ctid;
  7747. apiVo.actionName = "afterOver";
  7748. designHelper.API_WorkCore(apiVo); //afterOver
  7749. }
  7750. entity.UpdateTime = DateTime.Now;
  7751. entity.Update();
  7752. returnSuccessMsg("操作成功!");
  7753. CeErpSukuraData.createInfo(entity.ctid, 8);
  7754. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7755. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7756. return;
  7757. }
  7758. }
  7759. returnErrorMsg("找不到订单记录");
  7760. }
  7761. }
  7762. public void set_erp_supplierrefundtag()
  7763. {
  7764. if (UrlPostParmsCheck("ctid"))
  7765. {
  7766. string eid = GetPostString("ctid");
  7767. CeErpTradeCell entity = null;
  7768. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7769. if (entity != null)
  7770. {
  7771. entity.IsSupplierRefund = GetPostInt("tag");
  7772. entity.Update();
  7773. returnSuccessMsg("操作成功!");
  7774. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7775. return;
  7776. }
  7777. returnErrorMsg("找不到订单记录");
  7778. }
  7779. }
  7780. public void get_erp_refundlist()
  7781. {
  7782. DataStruct dStruct = GetPostStruct();
  7783. List<string> lw = new List<string>();
  7784. string tid = GetPostString("tid");
  7785. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7786. //string rid = GetPostString("refund_id");
  7787. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7788. string shopname = GetPostString("shopname");
  7789. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7790. string buyernick = GetPostString("buyer_nick");
  7791. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7792. string customer = GetPostString("customer");
  7793. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7794. string design = GetPostString("design");
  7795. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7796. string sellermemo = GetPostString("seller_memo");
  7797. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7798. //string date1 = GetPostString("date1");
  7799. //string date2 = GetPostString("date2");
  7800. //string dateType = GetPostString("dateType");
  7801. //if (dateType.Length > 0)
  7802. //{
  7803. // if (dateType == "1001") dateType = "0";
  7804. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7805. // if (searchDT.Count == 2)
  7806. // {
  7807. // date1 = searchDT[0].ToString();
  7808. // date2 = searchDT[1].ToString();
  7809. // }
  7810. //}
  7811. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7812. //if (dw.Length > 0) lw.Add(dw);
  7813. string redate1 = GetPostString("refunddate1");
  7814. string redate2 = GetPostString("refunddate2");
  7815. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7816. if (dwdate.Length > 0) lw.Add(dwdate);
  7817. string price1 = GetPostString("price1");
  7818. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7819. string price2 = GetPostString("price2");
  7820. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7821. string ispartrefund = GetPostString("ispartrefund");
  7822. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7823. string refundState = GetPostString("refundvstate");
  7824. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7825. int st = GetInt("st");
  7826. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7827. {
  7828. string responsible = GetPostString("responsibleman");
  7829. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7830. lw.Add(string.Format("RefundState>={0}", st));
  7831. string code = CurrentUser.UserPost.Post.Code;
  7832. if (code == "CustomerService")
  7833. {
  7834. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7835. }
  7836. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7837. {
  7838. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7839. }
  7840. else if (code == "Place" || code == "PlaceMr")
  7841. {
  7842. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7843. }
  7844. dStruct.Order = "RefundState asc,created desc";
  7845. }
  7846. else if (st == 10)
  7847. {
  7848. string responsible = GetPostString("responsibleman");
  7849. if (responsible == "空白")
  7850. {
  7851. lw.Add(string.Format("ResponsibleUserName = ''"));
  7852. }
  7853. else if (responsible.Length > 0)
  7854. {
  7855. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7856. }
  7857. lw.Add(string.Format("RefundState>=0"));
  7858. dStruct.Order = "created desc";
  7859. }
  7860. else
  7861. {
  7862. string responsible = GetPostString("responsibleman");
  7863. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7864. lw.Add(string.Format("RefundState={0}", st));
  7865. dStruct.Order = "created desc";
  7866. }
  7867. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7868. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7869. dt.Columns.Add("refund_fees");
  7870. foreach (DataRow dr in dt.Rows)
  7871. {
  7872. String status = dr["status"].ToString();
  7873. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7874. {
  7875. dr["refund_fees"] = dr["refund_fee"];
  7876. }
  7877. else
  7878. {
  7879. dr["refund_fees"] = "0.0";
  7880. }
  7881. }
  7882. writeGridDataTableJson(dStruct.TotalCount, dt);
  7883. }
  7884. public void get_erp_refunddesignlist()
  7885. {
  7886. DataStruct dStruct = GetPostStruct();
  7887. List<string> lw = new List<string>();
  7888. string tid = GetPostString("tid");
  7889. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7890. string shopname = GetPostString("shopname");
  7891. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7892. string buyernick = GetPostString("buyer_nick");
  7893. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7894. string customer = GetPostString("customer");
  7895. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7896. string design = GetPostString("design");
  7897. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7898. string sellermemo = GetPostString("seller_memo");
  7899. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7900. string redate1 = GetPostString("refunddate1");
  7901. string redate2 = GetPostString("refunddate2");
  7902. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7903. if (dwdate.Length > 0) lw.Add(dwdate);
  7904. string price1 = GetPostString("price1");
  7905. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7906. string price2 = GetPostString("price2");
  7907. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7908. string ispartrefund = GetPostString("ispartrefund");
  7909. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7910. string designerorg = GetPostString("designerorg");
  7911. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7912. string refundState = GetPostString("refundState");
  7913. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7914. int myOrgid = CurrentUser.UserPost.OrgID;
  7915. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7916. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7917. {
  7918. if (CurrentUser.User.TeamIds.Length > 0)
  7919. {
  7920. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7921. }
  7922. else
  7923. {
  7924. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7925. }
  7926. }
  7927. else if ("SysAdmin".Equals(myOrgCode))
  7928. {
  7929. }
  7930. else
  7931. {
  7932. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7933. {
  7934. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7935. }
  7936. else
  7937. {
  7938. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7939. }
  7940. }
  7941. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7942. dStruct.Order = "created desc";
  7943. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7944. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7945. dt.Columns.Add("refund_fees");
  7946. foreach (DataRow dr in dt.Rows)
  7947. {
  7948. String status = dr["status"].ToString();
  7949. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7950. {
  7951. dr["refund_fees"] = dr["refund_fee"];
  7952. }
  7953. else
  7954. {
  7955. dr["refund_fees"] = "0.0";
  7956. }
  7957. }
  7958. writeGridDataTableJson(dStruct.TotalCount, dt);
  7959. }
  7960. public void handle_erp_refundtag()
  7961. {
  7962. if (UrlPostParmsCheck("refund_id"))
  7963. {
  7964. string eid = GetPostString("refund_id");
  7965. string respMan = GetPostString("ResponsibleName");
  7966. if (respMan.Length <= 0)
  7967. {
  7968. returnErrorMsg("责任人不能为空");
  7969. return;
  7970. }
  7971. CeErpTradeRefund entity = null;
  7972. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7973. if (entity != null)
  7974. {
  7975. entity.ResponsibleUserName = respMan;
  7976. string userid = GetPostString("ResponsibleUserId");
  7977. if (userid.Length > 0)
  7978. {
  7979. entity.ResponsibleUserId = userid;
  7980. }
  7981. entity.Memo = GetPostString("Memo");
  7982. if (respMan.IndexOf("客服") != -1 ||
  7983. respMan.IndexOf("设计师") != -1 ||
  7984. respMan.IndexOf("下单员") != -1)
  7985. {
  7986. entity.RefundState = 2;
  7987. }
  7988. else
  7989. {
  7990. entity.RefundState = 3;
  7991. }
  7992. entity.modified = DateTime.Now;
  7993. entity.Update();
  7994. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7995. returnSuccessMsg("操作成功!");
  7996. return;
  7997. }
  7998. returnErrorMsg("找不到订单记录");
  7999. }
  8000. }
  8001. public void handle_erp_designrefundtag()
  8002. {
  8003. if (UrlPostParmsCheck("refund_id"))
  8004. {
  8005. string eid = GetPostString("refund_id");
  8006. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8007. if (ceErpTradeCellExtend == null)
  8008. {
  8009. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8010. ceErpTradeCellExtend.ctid = eid;
  8011. }
  8012. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8013. if (ceErpTradeCellExtend.ID > 0)
  8014. {
  8015. ceErpTradeCellExtend.Update();
  8016. }
  8017. else
  8018. {
  8019. ceErpTradeCellExtend.Create();
  8020. }
  8021. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8022. returnSuccessMsg("操作成功!");
  8023. return;
  8024. }
  8025. returnErrorMsg("找不到订单记录");
  8026. }
  8027. public void upd_erp_refundverify()
  8028. {
  8029. if (UrlPostParmsCheck("refund_id"))
  8030. {
  8031. string eid = GetPostString("refund_id");
  8032. CeErpTradeRefund entity = null;
  8033. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8034. if (entity != null)
  8035. {
  8036. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8037. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8038. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8039. {
  8040. entity.RefundState = 2;
  8041. }
  8042. else
  8043. {
  8044. entity.RefundState = 3;
  8045. }
  8046. entity.Update();
  8047. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8048. returnSuccessMsg("操作成功!");
  8049. return;
  8050. }
  8051. returnErrorMsg("找不到订单记录");
  8052. }
  8053. }
  8054. public void upd_erp_refundapprove()
  8055. {
  8056. if (UrlPostParmsCheck("refund_id"))
  8057. {
  8058. string eid = GetPostString("refund_id");
  8059. CeErpTradeRefund entity = null;
  8060. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8061. if (entity != null)
  8062. {
  8063. int apr = GetPostInt("approve");
  8064. if (apr == 0)
  8065. {
  8066. entity.RefundState = 1;
  8067. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8068. }
  8069. else if (apr == 1)
  8070. {
  8071. entity.RefundState = 3;
  8072. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8073. }
  8074. entity.modified = DateTime.Now;
  8075. entity.Update();
  8076. returnSuccessMsg("操作成功!");
  8077. return;
  8078. }
  8079. returnErrorMsg("找不到订单记录");
  8080. }
  8081. }
  8082. public void get_erp_billlist()
  8083. {
  8084. DataStruct dStruct = GetPostStruct();
  8085. List<string> lw = new List<string>();
  8086. string title = GetPostString("title");
  8087. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8088. string tid = GetPostString("tid");
  8089. string tids = GetPostString("tids");
  8090. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8091. if (tids.Length > 0)
  8092. {
  8093. tids = "'" + tids + "'";
  8094. tids = tids.Replace(",", "','");
  8095. lw.Add(string.Format("tid in ({0})", tids));
  8096. }
  8097. string shopname = GetPostString("shopname");
  8098. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8099. string buyernick = GetPostString("buyer_nick");
  8100. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8101. string customer = GetPostString("customer");
  8102. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8103. string date1 = GetPostString("date1");
  8104. string date2 = GetPostString("date2");
  8105. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8106. if (dw.Length > 0) lw.Add(dw);
  8107. string price1 = GetPostString("price1");
  8108. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8109. string price2 = GetPostString("price2");
  8110. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8111. string returndate1 = GetPostString("returndate1");
  8112. string returndate2 = GetPostString("returndate2");
  8113. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8114. if (dw1.Length > 0) lw.Add(dw1);
  8115. string billtype = GetPostString("billtype");
  8116. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8117. string billstate = GetPostString("billstate");
  8118. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8119. string usershop = CurrentUser.User.pemShop;
  8120. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8121. dStruct.Order = "createTime desc";
  8122. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8123. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8124. //foreach (DataRow dr in dt.Rows)
  8125. //{
  8126. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8127. //}
  8128. writeGridDataTableJson(dStruct.TotalCount, dt);
  8129. }
  8130. public void modify_erp_billinfo()
  8131. {
  8132. if (UrlPostParmsCheck("ID"))
  8133. {
  8134. string eid = GetPostString("ID");
  8135. CeErpBill bill_entity = null;
  8136. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8137. if (bill_entity != null)
  8138. {
  8139. bill_entity.tid = GetPostString("tid");
  8140. bill_entity.title = GetPostString("title");
  8141. bill_entity.tax = GetPostString("tax");
  8142. bill_entity.bank = GetPostString("bank");
  8143. bill_entity.bankac = GetPostString("bankac");
  8144. bill_entity.address = GetPostString("address");
  8145. bill_entity.phone = GetPostString("phone");
  8146. bill_entity.price = GetPostString("price");
  8147. bill_entity.productId = GetPostInt("ProductName");
  8148. bill_entity.num = GetPostInt("num");
  8149. bill_entity.unit = GetPostString("unit");
  8150. bill_entity.type = GetPostString("type");
  8151. bill_entity.sendType = GetPostString("SendType");
  8152. bill_entity.email = GetPostString("email");
  8153. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8154. bill_entity.shopName = GetPostString("ShopName");
  8155. bill_entity.applymemo = GetPostString("applymemo");
  8156. bill_entity.modifyTime = DateTime.Now;
  8157. bill_entity.createTime = DateTime.Now;
  8158. bill_entity.state = 0;
  8159. bill_entity.Update();
  8160. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8161. returnSuccessMsg("发票修改成功!");
  8162. return;
  8163. }
  8164. returnErrorMsg("找不到对应记录");
  8165. }
  8166. }
  8167. public void set_erp_invoicing()
  8168. {
  8169. if (UrlPostParmsCheck("id"))
  8170. {
  8171. try
  8172. {
  8173. string eid = GetPostString("id");
  8174. CeErpBill bill_entity = null;
  8175. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8176. if (bill_entity != null)
  8177. {
  8178. int ComId = GetPostInt("ComId");
  8179. //string memo = GetPostString("Memo");
  8180. int allInfo = GetPostInt("allinfo");
  8181. string clert = CurrentUser.User.Name;
  8182. //string detailValue = GetPostString("detailvalue");
  8183. string billId = bill_entity.billOrderId;
  8184. string[] billIdList = billId.Split(',');
  8185. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8186. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8187. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8188. {
  8189. billCount += 1;
  8190. }
  8191. if (billId.Length <= 0 || billIdList.Length != billCount)
  8192. {
  8193. bill_entity.billOrderId = "";
  8194. string prebill = "ltb";
  8195. for (int idx = 1; idx <= billCount; idx++)
  8196. {
  8197. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8198. string billoid = prebill + idx + dtstr;
  8199. bill_entity.billOrderId += billoid;
  8200. if (idx < billCount)
  8201. {
  8202. bill_entity.billOrderId += ",";
  8203. }
  8204. }
  8205. }
  8206. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8207. if (bill_entity.state == 5)
  8208. {
  8209. string errMsg = bill_entity.failerror;
  8210. string[] errlist = errMsg.Split('|');
  8211. string[] errTags = new string[errlist.Length];
  8212. for (int itag = 0; itag < errlist.Length; itag++)
  8213. {
  8214. if (errlist[itag].Length <= 0) continue;
  8215. errTags[itag] = errlist[itag].Split('&')[0];
  8216. }
  8217. for (int iii = 0; iii < errTags.Length; iii++)
  8218. {
  8219. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8220. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8221. if (billOrderList.Length >= erroBillOrderTag)
  8222. {
  8223. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8224. if (needModifyBillId.Length <= 19)
  8225. {
  8226. needModifyBillId = needModifyBillId + "1";
  8227. }
  8228. else
  8229. {
  8230. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8231. last = last + 1;
  8232. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8233. }
  8234. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8235. }
  8236. }
  8237. }
  8238. bool isHaveBillSucces = false;
  8239. string totalRes = "";
  8240. bill_entity.failerror = "";
  8241. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8242. {
  8243. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8244. totalRes += res;
  8245. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8246. {
  8247. isHaveBillSucces = true;
  8248. bill_entity.comId = ComId;
  8249. bill_entity.state = 1;
  8250. bill_entity.executeTime = DateTime.Now;
  8251. bill_entity.executeUser = clert;
  8252. }
  8253. else
  8254. {
  8255. bill_entity.state = 5;
  8256. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8257. }
  8258. }
  8259. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8260. bill_entity.Update();
  8261. if (isHaveBillSucces)
  8262. {
  8263. StringBuilder sql = new StringBuilder();
  8264. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8265. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8266. }
  8267. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8268. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8269. {
  8270. returnErrorMsg("开票失败");
  8271. }
  8272. else
  8273. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8274. return;
  8275. }
  8276. returnErrorMsg("找不到对应记录");
  8277. }
  8278. catch (Exception ex)
  8279. {
  8280. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8281. returnErrorMsg("操作失败");
  8282. }
  8283. }
  8284. }
  8285. public void get_erp_invoicing_back()
  8286. {
  8287. if (UrlPostParmsCheck("id"))
  8288. {
  8289. try
  8290. {
  8291. string id = GetPostString("id");
  8292. CeErpBill entiy = CeErpBill.Get(id);
  8293. if (entiy != null)
  8294. {
  8295. if (entiy.state == 0)
  8296. {
  8297. returnErrorMsg("发票还未开具");
  8298. return;
  8299. }
  8300. string[] billOrderList = entiy.billOrderId.Split(',');
  8301. int iTag = 0;
  8302. entiy.fplsh = "";
  8303. entiy.fpdm = "";
  8304. entiy.fphm = "";
  8305. foreach (string billOrderId in billOrderList)
  8306. {
  8307. iTag++;
  8308. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8309. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8310. {
  8311. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8312. try
  8313. {
  8314. Invoicing_get_response_Obj iObj = null;
  8315. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8316. if (iObj != null)
  8317. {
  8318. entiy.state = 2;
  8319. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8320. entiy.fpdm += iObj.list[0].c_fpdm;
  8321. entiy.fphm += iObj.list[0].c_fphm;
  8322. if (iTag < billOrderList.Length)
  8323. {
  8324. entiy.fplsh += ",";
  8325. entiy.fpdm += ",";
  8326. entiy.fphm += ",";
  8327. }
  8328. entiy.Update();
  8329. }
  8330. StringBuilder sql = new StringBuilder();
  8331. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8332. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8333. returnSuccessMsg("开票成功");
  8334. }
  8335. catch (Exception ex)
  8336. {
  8337. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8338. }
  8339. return;
  8340. }
  8341. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8342. {
  8343. var res_obj = new
  8344. {
  8345. data = "开票中"
  8346. };
  8347. string ro_json = JsonConvert.SerializeObject(res_obj);
  8348. returnSuccess(ro_json);
  8349. return;
  8350. }
  8351. else
  8352. {
  8353. int eidx = res.IndexOf("c_resultmsg");
  8354. int lidx = res.IndexOf("c_status");
  8355. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8356. entiy.state = 5;
  8357. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8358. entiy.Update();
  8359. returnErrorMsg("开票失败");
  8360. return;
  8361. }
  8362. }
  8363. }
  8364. }
  8365. catch (Exception ex)
  8366. {
  8367. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8368. }
  8369. return;
  8370. }
  8371. }
  8372. public void get_erp_invoicing()
  8373. {
  8374. if (UrlPostParmsCheck("id"))
  8375. {
  8376. try
  8377. {
  8378. string id = GetPostString("id");
  8379. CeErpBill entiy = CeErpBill.Get(id);
  8380. if (entiy != null)
  8381. {
  8382. if (entiy.state == 0)
  8383. {
  8384. returnErrorMsg("发票还未开具");
  8385. return;
  8386. }
  8387. if (entiy.sendType == "纸质发票")
  8388. {
  8389. if (entiy.img.Length <= 0)
  8390. {
  8391. returnErrorMsg("查无纸质发票");
  8392. return;
  8393. }
  8394. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8395. returnSuccess(returnres);
  8396. return;
  8397. }
  8398. string[] billOrderList = entiy.billOrderId.Split(',');
  8399. int iTag = 0;
  8400. string fpUrl = "";
  8401. entiy.fplsh = "";
  8402. entiy.fpdm = "";
  8403. entiy.fphm = "";
  8404. foreach (string billOrderId in billOrderList)
  8405. {
  8406. iTag++;
  8407. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8408. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8409. {
  8410. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8411. Invoicing_get_response_Obj iObj = null;
  8412. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8413. if (iObj != null)
  8414. {
  8415. //entiy.state = 2;
  8416. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8417. entiy.fpdm += iObj.list[0].c_fpdm;
  8418. entiy.fphm += iObj.list[0].c_fphm;
  8419. if (iTag < billOrderList.Length)
  8420. {
  8421. entiy.fplsh += ",";
  8422. entiy.fpdm += ",";
  8423. entiy.fphm += ",";
  8424. }
  8425. entiy.Update();
  8426. fpUrl += iObj.list[0].c_url + ",";
  8427. }
  8428. //returnSuccess(res);
  8429. StringBuilder sql = new StringBuilder();
  8430. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8431. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8432. }
  8433. else
  8434. {
  8435. int eidx = res.IndexOf("c_resultmsg");
  8436. //int lidx = res.IndexOf("c_status");
  8437. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8438. //开票失败
  8439. entiy.state = 5;
  8440. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8441. entiy.Update();
  8442. returnErrorMsg("开票失败");
  8443. return;
  8444. }
  8445. }
  8446. var returnObj = new
  8447. {
  8448. data = fpUrl
  8449. };
  8450. string ro_json = JsonConvert.SerializeObject(returnObj);
  8451. returnSuccess(ro_json);
  8452. }
  8453. }
  8454. catch (Exception ex)
  8455. {
  8456. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8457. }
  8458. return;
  8459. }
  8460. }
  8461. public void save_erp_billimg()
  8462. {
  8463. if (UrlPostParmsCheck("id"))
  8464. {
  8465. string eid = GetPostString("id");
  8466. CeErpBill bill_entity = null;
  8467. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8468. if (bill_entity != null)
  8469. {
  8470. bill_entity.img = GetPostString("img");
  8471. bill_entity.executeTime = DateTime.Now;
  8472. bill_entity.state = 2;
  8473. bill_entity.Update();
  8474. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8475. returnSuccessMsg("保存成功");
  8476. }
  8477. return;
  8478. }
  8479. }
  8480. public void upd_erp_billreturnback()
  8481. {
  8482. if (UrlPostParmsCheck("id"))
  8483. {
  8484. int eid = GetPostInt("id");
  8485. CeErpBill bill_entity = null;
  8486. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8487. if (bill_entity != null)
  8488. {
  8489. bill_entity.state = 3;
  8490. bill_entity.returnReason = GetPostString("reason");
  8491. bill_entity.Update();
  8492. returnSuccessMsg("驳回成功!");
  8493. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8494. }
  8495. return;
  8496. }
  8497. }
  8498. public void cancel_erp_bill()
  8499. {
  8500. if (UrlPostParmsCheck("id"))
  8501. {
  8502. int eid = GetPostInt("id");
  8503. int detailValue = GetPostInt("detailvalue");
  8504. CeErpBill bill_entity = null;
  8505. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8506. string cres = "";
  8507. string gres = "";
  8508. if (bill_entity != null)
  8509. {
  8510. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8511. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8512. {
  8513. int iTag = 0;
  8514. bill_entity.fplsh = "";
  8515. bill_entity.fpdm = "";
  8516. bill_entity.fphm = "";
  8517. foreach (string billOrderId in billOrderList)
  8518. {
  8519. iTag++;
  8520. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8521. if (gres.IndexOf("success") != -1)
  8522. {
  8523. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8524. Invoicing_get_response_Obj iObj = null;
  8525. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8526. if (iObj != null)
  8527. {
  8528. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8529. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8530. bill_entity.fphm += iObj.list[0].c_fphm;
  8531. if (iTag < billOrderList.Length)
  8532. {
  8533. bill_entity.fplsh += ",";
  8534. bill_entity.fpdm += ",";
  8535. bill_entity.fphm += ",";
  8536. }
  8537. bill_entity.Update();
  8538. }
  8539. }
  8540. else
  8541. {
  8542. returnErrorMsg(gres);
  8543. return;
  8544. }
  8545. }
  8546. }
  8547. if (bill_entity.sendType == "纸质发票")
  8548. {
  8549. //作废
  8550. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8551. //if (DateTime.Now.Month == extime.Month)
  8552. //{
  8553. //cres = taobaoHelper.cancel_invoicing(eid);
  8554. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8555. //{
  8556. bill_entity.state = 4;//已作废
  8557. bill_entity.Update();
  8558. returnSuccessMsg("发票已作废");
  8559. return;
  8560. //}
  8561. //else
  8562. //{
  8563. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8564. // bill_entity.Update();
  8565. // returnErrorMsg(cres);
  8566. // return;
  8567. //}
  8568. //}
  8569. //else
  8570. //{
  8571. // returnErrorMsg("纸质发票只能作废本月的发票");
  8572. // return;
  8573. //}
  8574. }
  8575. //红冲
  8576. int redTag = 0;
  8577. string[] fpdmList = bill_entity.fpdm.Split(',');
  8578. string[] fphmList = bill_entity.fphm.Split(',');
  8579. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8580. {
  8581. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8582. return;
  8583. }
  8584. foreach (string billOrderId in billOrderList)
  8585. {
  8586. redTag++;
  8587. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8588. cres += onecres;
  8589. cres += ",";
  8590. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8591. {
  8592. bill_entity.state = 4;//已作废
  8593. //bill_entity.Update();
  8594. //returnSuccessMsg("发票已红冲");
  8595. }
  8596. else if (onecres.IndexOf("重复冲红") != -1)
  8597. {
  8598. bill_entity.state = 4;//已作废
  8599. //bill_entity.Update();
  8600. //returnSuccessMsg("发票已红冲");
  8601. }
  8602. else
  8603. {
  8604. string errmsg = commonHelper.KeepChinese(onecres);
  8605. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8606. }
  8607. }
  8608. bill_entity.Update();
  8609. if (cres.IndexOf("失败") != -1)
  8610. returnErrorMsg("红冲失败");
  8611. else
  8612. returnSuccessMsg("发票已红冲");
  8613. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8614. return;
  8615. }
  8616. return;
  8617. }
  8618. }
  8619. public void del_erp_billorder()
  8620. {
  8621. if (UrlPostParmsCheck("id"))
  8622. {
  8623. string eid = GetPostString("id");
  8624. CeErpBill.Del(eid);
  8625. CeErpBill bill = CeErpBill.Get(eid);
  8626. if (bill != null)
  8627. {
  8628. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8629. }
  8630. returnSuccessMsg("删除成功");
  8631. }
  8632. }
  8633. public void finish_erp_bill()
  8634. {
  8635. if (UrlPostParmsCheck("ids"))
  8636. {
  8637. string eids = GetPostString("ids");
  8638. string[] list = eids.Split(',');
  8639. foreach (string eid in list)
  8640. {
  8641. CeErpBill bill = CeErpBill.Get(eid);
  8642. if (bill != null)
  8643. {
  8644. bill.state = 2;
  8645. bill.Update();
  8646. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8647. }
  8648. }
  8649. returnSuccessMsg("操作成功");
  8650. }
  8651. }
  8652. public void get_erp_returncash()
  8653. {
  8654. DataStruct dStruct = GetPostStruct();
  8655. List<string> lw = new List<string>();
  8656. string tid = GetPostString("tid");
  8657. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8658. string shopname = GetPostString("shopname");
  8659. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8660. string buyernick = GetPostString("buyer_nick");
  8661. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8662. string customer = GetPostString("customer");
  8663. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8664. string returndate1 = GetPostString("returndate1");
  8665. string returndate2 = GetPostString("returndate2");
  8666. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8667. if (dw.Length > 0) lw.Add(dw);
  8668. string finishDate1 = GetPostString("finishdate1");
  8669. string finishDate2 = GetPostString("finishdate2");
  8670. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8671. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8672. string returntype = GetPostString("returntype");
  8673. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8674. string returnvstate = GetPostString("returnvstate");
  8675. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8676. dStruct.Order = "created desc";
  8677. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8678. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8679. writeGridDataTableJson(dStruct.TotalCount, dt);
  8680. }
  8681. public void get_erp_staygoods()
  8682. {
  8683. DataStruct dStruct = GetPostStruct();
  8684. List<string> lw = new List<string>();
  8685. string tid = GetPostString("tid");
  8686. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8687. string shopname = GetPostString("shopname");
  8688. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8689. string wangwang = GetPostString("wangwang");
  8690. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8691. string customer = GetPostString("customer");
  8692. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8693. string returndate1 = GetPostString("returndate1");
  8694. string returndate2 = GetPostString("returndate2");
  8695. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8696. if (dw.Length > 0) lw.Add(dw);
  8697. string finishDate1 = GetPostString("finishdate1");
  8698. string finishDate2 = GetPostString("finishdate2");
  8699. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8700. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8701. string returnvstate = GetPostString("returnvstate");
  8702. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8703. string persuadetype = GetPostString("persuadetype");
  8704. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8705. string customerOrg = GetPostString("customerOrg");
  8706. if (customerOrg.Length > 0)
  8707. {
  8708. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8709. }
  8710. dStruct.Order = "creata_time desc";
  8711. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8712. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8713. writeGridDataTableJson(dStruct.TotalCount, dt);
  8714. }
  8715. public void upd_erp_staygoods()
  8716. {
  8717. if (UrlPostParmsCheck("id"))
  8718. {
  8719. int eid = GetPostInt("id");
  8720. CeErpStayGoods entity = null;
  8721. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8722. if (entity != null)
  8723. {
  8724. entity.audit_type = 1;
  8725. entity.audit_time = DateTime.Now;
  8726. entity.audit_u_id = CurrentUser.UserID;
  8727. entity.audit_u_name = CurrentUser.UserName;
  8728. entity.Update();
  8729. returnSuccessMsg("审核成功!");
  8730. return;
  8731. }
  8732. returnErrorMsg("找不到订单记录");
  8733. }
  8734. }
  8735. public void upd_erp_stayGoodsback()
  8736. {
  8737. if (UrlPostParmsCheck("id"))
  8738. {
  8739. int eid = GetPostInt("id");
  8740. CeErpStayGoods entity = null;
  8741. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8742. if (entity != null)
  8743. {
  8744. entity.audit_text = GetPostString("reason");
  8745. entity.audit_type = 2;
  8746. entity.audit_time = DateTime.Now;
  8747. entity.audit_u_id = CurrentUser.UserID;
  8748. entity.audit_u_name = CurrentUser.UserName;
  8749. entity.Update();
  8750. returnSuccessMsg("退回成功!");
  8751. return;
  8752. }
  8753. returnErrorMsg("找不到订单记录");
  8754. }
  8755. }
  8756. public void upd_erp_returncashverify()
  8757. {
  8758. if (UrlPostParmsCheck("ID"))
  8759. {
  8760. int eid = GetPostInt("ID");
  8761. CeErpReturnCash entity = null;
  8762. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8763. if (entity != null)
  8764. {
  8765. entity.cashstate = 1;
  8766. entity.verifytime = DateTime.Now;
  8767. entity.verifyuserid = CurrentUser.UserID;
  8768. entity.Update();
  8769. returnSuccessMsg("审核成功!");
  8770. return;
  8771. }
  8772. returnErrorMsg("找不到订单记录");
  8773. }
  8774. }
  8775. public void upd_all_erp_returncashverify()
  8776. {
  8777. if (UrlPostParmsCheck("ID"))
  8778. {
  8779. String[] list = GetPostString("ID").Split(',');
  8780. CeErpReturnCash entity = null;
  8781. for (int i = 0; i < list.Length; i++)
  8782. {
  8783. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8784. if (entity != null)
  8785. {
  8786. if (entity.cashstate == 1)
  8787. {
  8788. returnErrorMsg("已审核过的订单不需要在审核!");
  8789. return;
  8790. }
  8791. entity.cashstate = 1;
  8792. entity.verifytime = DateTime.Now;
  8793. entity.verifyuserid = CurrentUser.UserID;
  8794. entity.Update();
  8795. }
  8796. }
  8797. returnSuccessMsg("审核成功!");
  8798. return;
  8799. }
  8800. }
  8801. public void upd_erp_returncashback()
  8802. {
  8803. if (UrlPostParmsCheck("ID"))
  8804. {
  8805. int eid = GetPostInt("ID");
  8806. CeErpReturnCash entity = null;
  8807. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8808. if (entity != null)
  8809. {
  8810. entity.backreason = GetPostString("reason");
  8811. entity.cashstate = 2;
  8812. entity.verifytime = DateTime.Now;
  8813. entity.verifyuserid = CurrentUser.UserID;
  8814. entity.Update();
  8815. returnSuccessMsg("退回成功!");
  8816. return;
  8817. }
  8818. returnErrorMsg("找不到订单记录");
  8819. }
  8820. }
  8821. public void upd_erp_returnprice()
  8822. {
  8823. if (UrlPostParmsCheck("ID"))
  8824. {
  8825. int eid = GetPostInt("ID");
  8826. CeErpReturnCash entity = null;
  8827. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8828. if (entity != null)
  8829. {
  8830. if (entity.cashstate == 1)
  8831. {
  8832. returnErrorMsg("审核通过了不能改");
  8833. return;
  8834. }
  8835. entity.returnprice = GetPostDouble("returnprice");
  8836. entity.Update();
  8837. returnSuccessMsg("修改成功!");
  8838. return;
  8839. }
  8840. returnErrorMsg("找不到订单记录");
  8841. }
  8842. }
  8843. public void del_erp_returncash()
  8844. {
  8845. if (UrlPostParmsCheck("ID"))
  8846. {
  8847. int eid = GetPostInt("ID");
  8848. CeErpReturnCash.Del(eid);
  8849. returnSuccessMsg("操作成功");
  8850. return;
  8851. }
  8852. }
  8853. public void test_for_do_sql()
  8854. {
  8855. string sql = GetPostString("sqlstr");
  8856. if (sql.Length > 0)
  8857. {
  8858. try
  8859. {
  8860. DbHelper.DbConn.ExecuteNonQuery(sql);
  8861. var res_obj = new
  8862. {
  8863. data = "成功",
  8864. };
  8865. string ro_json = JsonConvert.SerializeObject(res_obj);
  8866. returnSuccess(ro_json);
  8867. }
  8868. catch (Exception ex)
  8869. {
  8870. var res_obj = new
  8871. {
  8872. data = ex.Message,
  8873. };
  8874. string ro_json = JsonConvert.SerializeObject(res_obj);
  8875. returnSuccess(ro_json);
  8876. }
  8877. }
  8878. }
  8879. public void get_user_info()
  8880. {
  8881. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8882. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8883. }
  8884. public void get_total_data()
  8885. {
  8886. int userId = CurrentUser.UserID;
  8887. string sql = "";
  8888. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8889. {
  8890. 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);
  8891. }
  8892. else
  8893. {
  8894. 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 " +
  8895. "(select ID from CE_ErpUser where ID = {0}) d " +
  8896. "left join " +
  8897. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8898. ") a on d.ID = a.id left join " +
  8899. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8900. ") b on a.id = b.id1 left join" +
  8901. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8902. ") c on a.id = c.id2;", userId);
  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_data2()
  8908. {
  8909. int userId = CurrentUser.UserID;
  8910. string date_type = GetPostString("timetype");
  8911. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8912. string sql = "";
  8913. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8914. {
  8915. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8916. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8917. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8918. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8919. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8920. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8921. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8922. ") a on e.ID = a.id left join " +
  8923. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8924. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8925. ") b on a.id = b.id1 " +
  8926. "left join " +
  8927. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8928. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8929. ") c on a.id = c.id2 " +
  8930. "left join " +
  8931. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8932. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8933. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8934. }
  8935. else
  8936. {
  8937. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8938. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8939. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8940. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8941. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8942. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8943. ") a on e.ID = a.id left join " +
  8944. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8945. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8946. ") c on a.id = c.id2 " +
  8947. "left join " +
  8948. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8949. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8950. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8951. }
  8952. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8953. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8954. }
  8955. public void get_date_area_total_data()
  8956. {
  8957. int userId = CurrentUser.UserID;
  8958. string date_type = GetPostString("timetype");
  8959. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8960. string date1 = searchDT[0].ToString();
  8961. string date2 = searchDT[1].ToString();
  8962. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8963. {
  8964. SqlParameter[] sqlParameter ={
  8965. new SqlParameter("@userId", SqlDbType.Int,4),
  8966. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8967. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8968. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8969. };
  8970. sqlParameter[0].Value = userId;
  8971. sqlParameter[1].Value = date1;
  8972. sqlParameter[2].Value = date2;
  8973. sqlParameter[3].Direction = ParameterDirection.Output;
  8974. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8975. string res = sqlParameter[3].Value.ToString();
  8976. var res_obj = new
  8977. {
  8978. data = res
  8979. };
  8980. string ro_json = JsonConvert.SerializeObject(res_obj);
  8981. returnSuccess(ro_json);
  8982. }
  8983. else
  8984. {
  8985. SqlParameter[] sqlParameter ={
  8986. new SqlParameter("@userId", SqlDbType.Int,4),
  8987. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8988. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8989. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8990. };
  8991. sqlParameter[0].Value = userId;
  8992. sqlParameter[1].Value = date1;
  8993. sqlParameter[2].Value = date2;
  8994. sqlParameter[3].Direction = ParameterDirection.Output;
  8995. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8996. string res = sqlParameter[3].Value.ToString();
  8997. var res_obj = new
  8998. {
  8999. data = res
  9000. };
  9001. string ro_json = JsonConvert.SerializeObject(res_obj);
  9002. returnSuccess(ro_json);
  9003. }
  9004. //writeGridDataViewJson(dt.Rows.Count, dv);
  9005. }
  9006. public void get_order_list()
  9007. {
  9008. string strFields = GetPostString("paraFields");
  9009. string strOrder = GetPostString("paraOrder");
  9010. string strWhere = GetPostString("paraWhere");
  9011. string strPageSize = GetPostString("paraPageSize");
  9012. DataStruct dStruct = GetPostStruct();
  9013. dStruct.PageSize = int.Parse(strPageSize);
  9014. dStruct.Fileds = strFields;
  9015. dStruct.Order = strOrder;
  9016. dStruct.MainWhere = strWhere;
  9017. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9018. writeGridDataTableJson(dStruct.TotalCount, dt);
  9019. }
  9020. ////获取待开始订单列表
  9021. //public void get_wait_design_order_list()
  9022. //{
  9023. // string date_type = GetPostString("date_type");
  9024. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9025. // DataStruct dStruct = GetPostStruct();
  9026. // dStruct.PageSize = 1000;
  9027. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9028. // List<string> lw = new List<string>();
  9029. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9030. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9031. // dStruct.Order = "WaitDesignTime asc";
  9032. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9033. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9034. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9035. //}
  9036. //获取完成单量排名
  9037. public void get_finish_order_count_ranking()
  9038. {
  9039. /* string date_type = GetPostString("date_type");
  9040. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9041. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9042. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9043. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9044. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9045. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9046. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9047. writeGridDataTableJson(0, new DataTable());
  9048. }
  9049. public void get_finish_order_amount_ranking()
  9050. {
  9051. /*string date_type = GetPostString("date_type");
  9052. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9053. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9054. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9055. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9056. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9057. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9058. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9059. writeGridDataTableJson(0, new DataTable());
  9060. }
  9061. public void get_finish_refund_count_ranking()
  9062. {
  9063. string date_type = GetPostString("date_type");
  9064. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9065. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9066. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9067. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9068. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9069. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9070. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9071. writeGridDataTableJson(dt.Rows.Count, dt);
  9072. }
  9073. public void get_finish_refund_amount_ranking()
  9074. {
  9075. string date_type = GetPostString("date_type");
  9076. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9077. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9078. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9079. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9080. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9081. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9082. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9083. writeGridDataTableJson(dt.Rows.Count, dt);
  9084. }
  9085. public void set_erp_finishorder_director()
  9086. {
  9087. if (UrlPostParmsCheck("ctid"))
  9088. {
  9089. string eid = GetPostString("ctid");
  9090. CeErpTradeCell entity = null;
  9091. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9092. if (entity != null)
  9093. {
  9094. entity.OrderState = 8;
  9095. entity.Update();
  9096. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9097. returnSuccessMsg("操作成功!");
  9098. return;
  9099. }
  9100. returnErrorMsg("找不到记录");
  9101. }
  9102. }
  9103. public void get_erp_placeregistlist()
  9104. {
  9105. DataStruct dStruct = GetPostStruct();
  9106. List<string> lw = new List<string>();
  9107. string outsid = GetPostString("outsid");
  9108. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9109. string memo = GetPostString("memo");
  9110. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9111. string filename = GetPostString("filename");
  9112. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9113. string islate = GetPostString("islate");
  9114. if (islate.Length > 0)
  9115. {
  9116. if (islate == "1")
  9117. lw.Add(string.Format("OutLate>0"));
  9118. else
  9119. lw.Add(string.Format("OutLate=0"));
  9120. }
  9121. string placedate1 = GetPostString("placedate1");
  9122. string placedate2 = GetPostString("placedate2");
  9123. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9124. if (dw.Length > 0) lw.Add(dw);
  9125. string deliveryDate1 = GetPostString("deliverydate1");
  9126. string deliveryDate2 = GetPostString("deliverydate2");
  9127. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9128. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9129. dStruct.Order = "ID desc";
  9130. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9131. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9132. writeGridDataTableJson(dStruct.TotalCount, dt);
  9133. }
  9134. public void ins_erp_placeregist()
  9135. {
  9136. if (UrlPostParmsCheck("id"))
  9137. {
  9138. string eid = GetPostString("id");
  9139. CeErpPlaceRegister entity = null;
  9140. if (eid == "0")//新增
  9141. {
  9142. entity = new CeErpPlaceRegister();
  9143. string xdTime = GetPostString("placeTime");
  9144. if (xdTime.Length > 0)
  9145. {
  9146. entity.PlactTime = Convert.ToDateTime(xdTime);
  9147. }
  9148. string fhTime = GetPostString("deliveryTime");
  9149. if (fhTime.Length > 0)
  9150. {
  9151. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9152. }
  9153. string preTime = GetPostString("preOutTime");
  9154. if (preTime.Length > 0)
  9155. {
  9156. entity.PreOutTime = Convert.ToDateTime(preTime);
  9157. }
  9158. entity.DeliveryCount = GetPostInt("deliveryCount");
  9159. entity.ReceiveCount = GetPostInt("receiveCount");
  9160. entity.OutSid = GetPostString("outSid");
  9161. entity.FileName = GetPostString("fileName");
  9162. entity.Memo = GetPostString("memo");
  9163. entity.AddUserId = CurrentUser.UserID;
  9164. entity.CreateTime = DateTime.Now;
  9165. entity.Img = GetPostString("img");
  9166. entity.Supplier = GetPostInt("supplier");
  9167. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9168. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9169. {
  9170. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9171. DateTime dt2 = (DateTime)entity.PreOutTime;
  9172. TimeSpan span = dt1.Subtract(dt2);
  9173. if (span.Days > 0)
  9174. {
  9175. entity.OutLate = span.Days;
  9176. }
  9177. }
  9178. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9179. entity.Create();
  9180. returnSuccessMsg("添加成功!");
  9181. return;
  9182. }
  9183. else //修改
  9184. {
  9185. entity = CeErpPlaceRegister.Get(eid);
  9186. if (entity != null)
  9187. {
  9188. string xdTime = GetPostString("placeTime");
  9189. if (xdTime.Length > 0)
  9190. {
  9191. entity.PlactTime = Convert.ToDateTime(xdTime);
  9192. }
  9193. string fhTime = GetPostString("deliveryTime");
  9194. if (fhTime.Length > 0)
  9195. {
  9196. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9197. }
  9198. string preTime = GetPostString("preOutTime");
  9199. if (preTime.Length > 0)
  9200. {
  9201. entity.PreOutTime = Convert.ToDateTime(preTime);
  9202. }
  9203. entity.DeliveryCount = GetPostInt("deliveryCount");
  9204. entity.ReceiveCount = GetPostInt("receiveCount");
  9205. if (entity.DeliveryCount == entity.ReceiveCount)
  9206. {
  9207. entity.CurState = "已完成";
  9208. }
  9209. else
  9210. {
  9211. entity.CurState = "未完成";
  9212. }
  9213. entity.OutSid = GetPostString("outSid");
  9214. entity.FileName = GetPostString("fileName");
  9215. entity.Memo = GetPostString("memo");
  9216. entity.Img = GetPostString("img");
  9217. entity.Supplier = GetPostInt("supplier");
  9218. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9219. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9220. {
  9221. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9222. DateTime dt2 = (DateTime)entity.PreOutTime;
  9223. TimeSpan span = dt1.Subtract(dt2);
  9224. if (span.Days > 0)
  9225. {
  9226. entity.OutLate = span.Days;
  9227. }
  9228. }
  9229. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9230. entity.Update();
  9231. returnSuccessMsg("修改成功");
  9232. return;
  9233. }
  9234. returnErrorMsg("找不到对应的记录");
  9235. return;
  9236. }
  9237. }
  9238. returnErrorMsg("缺少必要参数");
  9239. }
  9240. public void del_erp_placeregist()
  9241. {
  9242. string eid = GetPostString("id");
  9243. CeErpPlaceRegister.Del(eid);
  9244. returnSuccessMsg("删除成功!");
  9245. return;
  9246. }
  9247. public void ins_erp_placeregistbyorder()
  9248. {
  9249. string ctid = GetPostString("ctid");
  9250. if (ctid.Length > 0)
  9251. {
  9252. StringBuilder sql = new StringBuilder();
  9253. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9254. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9255. if (dt.Rows.Count > 0)
  9256. {
  9257. foreach (DataRow dr in dt.Rows)
  9258. {
  9259. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9260. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9261. entity.AddUserId = CurrentUser.UserID;
  9262. entity.tid = dr["tid"].ToString();
  9263. entity.Did = Convert.ToString(dr["ctid"]);
  9264. entity.splitTag = dr["SplitTag"].ToString();
  9265. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9266. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9267. if (pre_ctid.Length > 0)
  9268. {
  9269. sellmemo = sellmemo.Replace(pre_ctid, "");
  9270. }
  9271. sellmemo = sellmemo.Replace("[", "");
  9272. sellmemo = sellmemo.Replace("]", "");
  9273. entity.FileName = sellmemo;
  9274. string count = dr["ProductCount"].ToString();
  9275. int usecount = commonHelper.getIntCountFromString(count);
  9276. entity.DeliveryCount = usecount;
  9277. entity.CurState = "未完成";
  9278. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9279. {
  9280. entity.Supplier = 24;//dl手提袋定制
  9281. }
  9282. else
  9283. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9284. entity.CreateTime = DateTime.Now;
  9285. entity.Create();
  9286. }
  9287. returnSuccessMsg("操作成功");
  9288. return;
  9289. }
  9290. returnErrorMsg("没有找到对应订单");
  9291. return;
  9292. }
  9293. returnErrorMsg("缺少订单编号");
  9294. return;
  9295. }
  9296. public void get_erp_persuadelist()
  9297. {
  9298. DataStruct dStruct = GetPostStruct();
  9299. List<string> lw = new List<string>();
  9300. string ctid = GetPostString("ctid");
  9301. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9302. string shopname = GetPostString("shopname");
  9303. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9304. string buyernick = GetPostString("buyer_nick");
  9305. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9306. string customer = GetPostString("customer");
  9307. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9308. string returndate1 = GetPostString("returndate1");
  9309. string returndate2 = GetPostString("returndate2");
  9310. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9311. if (dw.Length > 0) lw.Add(dw);
  9312. string finishDate1 = GetPostString("finishdate1");
  9313. string finishDate2 = GetPostString("finishdate2");
  9314. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9315. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9316. string persuadetype = GetPostString("persuadetype");
  9317. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9318. string returnvstate = GetPostString("returnvstate");
  9319. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9320. dStruct.Order = "created desc";
  9321. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9322. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9323. writeGridDataTableJson(dStruct.TotalCount, dt);
  9324. }
  9325. public void upd_erp_returnpersuadeback()
  9326. {
  9327. if (UrlPostParmsCheck("ID"))
  9328. {
  9329. int eid = GetPostInt("ID");
  9330. CeErpPersuade entity = null;
  9331. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9332. if (entity != null)
  9333. {
  9334. entity.backreason = GetPostString("reason");
  9335. entity.pstate = 2;
  9336. entity.verifytime = DateTime.Now;
  9337. entity.verifyuserid = CurrentUser.UserID;
  9338. entity.Update();
  9339. returnSuccessMsg("退回成功!");
  9340. return;
  9341. }
  9342. returnErrorMsg("找不到订单记录");
  9343. }
  9344. }
  9345. public void upd_erp_returnpersuadeverify()
  9346. {
  9347. if (UrlPostParmsCheck("ID"))
  9348. {
  9349. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9350. {
  9351. returnErrorMsg("暂无权限审核");
  9352. return;
  9353. }
  9354. int eid = GetPostInt("ID");
  9355. CeErpPersuade entity = null;
  9356. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9357. if (entity != null)
  9358. {
  9359. entity.pstate = 1;
  9360. entity.verifytime = DateTime.Now;
  9361. entity.verifyuserid = CurrentUser.UserID;
  9362. entity.Update();
  9363. returnSuccessMsg("审核成功!");
  9364. return;
  9365. }
  9366. returnErrorMsg("找不到订单记录");
  9367. }
  9368. }
  9369. public void del_erp_persuade()
  9370. {
  9371. if (UrlPostParmsCheck("ID"))
  9372. {
  9373. int eid = GetPostInt("ID");
  9374. CeErpPersuade.Del(eid);
  9375. returnSuccessMsg("操作成功");
  9376. return;
  9377. }
  9378. }
  9379. public void get_erp_oldcustoupload()
  9380. {
  9381. DataStruct dStruct = GetPostStruct();
  9382. List<string> lw = new List<string>();
  9383. string buyernick = GetPostString("buyer_nick");
  9384. if (buyernick.Length > 0)
  9385. {
  9386. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9387. }
  9388. else
  9389. return;
  9390. dStruct.Order = "pay_time desc";
  9391. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9392. DataTable dt = null;
  9393. dt = WebCache.GetData("view_erptradecell", dStruct);
  9394. writeGridDataTableJson(dStruct.TotalCount, dt);
  9395. }
  9396. public void get_erp_checkorderlist()
  9397. {
  9398. DataStruct dStruct = GetPostStruct();
  9399. List<string> lw = new List<string>();
  9400. string tid = GetPostString("ctid");
  9401. if (tid.Length > 0)
  9402. {
  9403. string select_tid = getTidByCtid(tid);
  9404. lw.Add(string.Format("tid='{0}'", select_tid));
  9405. }
  9406. string shopname = GetPostString("shopname");
  9407. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9408. string buyernick = GetPostString("buyer_nick");
  9409. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9410. string customer = GetPostString("customer");
  9411. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9412. string design = GetPostString("design");
  9413. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9414. string orderState = GetPostString("orderState");
  9415. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9416. string address = GetPostString("address");
  9417. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9418. string sellermemo = GetPostString("seller_memo");
  9419. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9420. string supplier = GetPostString("supplier");
  9421. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9422. {
  9423. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9424. }
  9425. else
  9426. {
  9427. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9428. }
  9429. string date1 = GetPostString("date1");
  9430. string date2 = GetPostString("date2");
  9431. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9432. if (dw.Length > 0) lw.Add(dw);
  9433. string placedate1 = GetPostString("placedate1");
  9434. string placedate2 = GetPostString("placedate2");
  9435. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9436. if (fdw.Length > 0) lw.Add(fdw);
  9437. string price1 = GetPostString("price1");
  9438. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9439. string price2 = GetPostString("price2");
  9440. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9441. string checkst = GetPostString("checkstate");
  9442. if (checkst.Length > 0 && "10".Equals(checkst))
  9443. {
  9444. lw.Add(string.Format("CheckOut>0"));
  9445. }
  9446. else
  9447. {
  9448. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9449. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9450. }
  9451. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9452. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9453. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9454. writeGridDataTableJson(dStruct.TotalCount, dt);
  9455. }
  9456. public void ins_erp_startCheck()
  9457. {
  9458. if (UrlPostParmsCheck("ctid"))
  9459. {
  9460. string eid = GetPostString("ctid");
  9461. CeErpTradeCell entity = null;
  9462. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9463. if (entity != null)
  9464. {
  9465. entity.MemoOpt = 4;
  9466. entity.UpdateTime = DateTime.Now;
  9467. entity.Update();
  9468. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9469. CeErpSukuraData.createInfo(entity.ctid, 6);
  9470. returnSuccessMsg("操作成功!");
  9471. return;
  9472. }
  9473. returnErrorMsg("找不到记录");
  9474. }
  9475. }
  9476. public void upd_erp_sendXlw()
  9477. {
  9478. if (UrlPostParmsCheck("ctid"))
  9479. {
  9480. string eid = GetPostString("ctid");
  9481. CeErpTradeCell entity = null;
  9482. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9483. if (entity != null)
  9484. {
  9485. if (entity.IsSendGift == 1)
  9486. {
  9487. returnErrorMsg("请勿重复标记");
  9488. return;
  9489. }
  9490. entity.IsSendGift = 1;
  9491. entity.Update();
  9492. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9493. returnSuccessMsg("操作成功!");
  9494. return;
  9495. }
  9496. returnErrorMsg("找不到记录");
  9497. }
  9498. }
  9499. public void cancel_sendXlw()
  9500. {
  9501. if (UrlPostParmsCheck("ctid"))
  9502. {
  9503. string eid = GetPostString("ctid");
  9504. CeErpTradeCell entity = null;
  9505. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9506. if (entity != null)
  9507. {
  9508. if (entity.IsSendGift == 0)
  9509. {
  9510. returnErrorMsg("未标记小礼物");
  9511. return;
  9512. }
  9513. entity.IsSendGift = 0;
  9514. entity.Update();
  9515. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9516. returnSuccessMsg("操作成功!");
  9517. return;
  9518. }
  9519. returnErrorMsg("找不到记录");
  9520. }
  9521. }
  9522. public void get_erp_designbill()
  9523. {
  9524. DataStruct dStruct = GetPostStruct();
  9525. List<string> lw = new List<string>();
  9526. int isMy = GetInt("my");
  9527. if (isMy == 1)
  9528. {
  9529. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9530. }
  9531. string tid = GetPostString("tid");
  9532. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9533. string userName = GetPostString("design");
  9534. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9535. string price1 = GetPostString("price1");
  9536. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9537. string price2 = GetPostString("price2");
  9538. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9539. string rePrice1 = GetPostString("rePrice1");
  9540. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9541. string rePrice2 = GetPostString("rePrice2");
  9542. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9543. string designerType = GetPostString("designerType");
  9544. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9545. string orderState = GetPostString("orderState");
  9546. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9547. string endTime1 = GetPostString("endTime1");
  9548. string endTime2 = GetPostString("endTime2");
  9549. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9550. if (dw.Length > 0) lw.Add(dw);
  9551. string isDk = GetPostString("isDk");
  9552. if (isDk == "1")
  9553. {
  9554. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9555. }
  9556. else if (isDk == "0")
  9557. {
  9558. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9559. }
  9560. dStruct.Order = "oid, create_time desc";
  9561. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9562. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9563. writeGridDataTableJson(dStruct.TotalCount, dt);
  9564. }
  9565. public void upd_erp_designerbill()
  9566. {
  9567. if (UrlPostParmsCheck("ID"))
  9568. {
  9569. string eid = GetPostString("ID");
  9570. CeErpDesignerBill entity = null;
  9571. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9572. if (entity != null)
  9573. {
  9574. if (GetPostDouble("designerpirce") > 0)
  9575. {
  9576. entity.realPrice = GetPostDouble("designerpirce");
  9577. entity.update_time = DateTime.Now;
  9578. entity.update_u_id = CurrentUser.UserID;
  9579. entity.update_u_name = CurrentUser.UserName;
  9580. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9581. entity.Update();
  9582. returnSuccessMsg("操作成功!");
  9583. return;
  9584. }
  9585. else
  9586. {
  9587. entity.price = GetPostDouble("price");
  9588. entity.update_time = DateTime.Now;
  9589. entity.update_u_id = CurrentUser.UserID;
  9590. entity.update_u_name = CurrentUser.UserName;
  9591. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9592. entity.Update();
  9593. returnSuccessMsg("操作成功!");
  9594. return;
  9595. }
  9596. }
  9597. returnErrorMsg("找不到记录");
  9598. }
  9599. }
  9600. public void audit_erp_designerbill()
  9601. {
  9602. if (UrlPostParmsCheck("ID"))
  9603. {
  9604. string eid = GetPostString("ID");
  9605. CeErpDesignerBill entity = null;
  9606. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9607. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9608. if (entity != null)
  9609. {
  9610. entity.realPrice = GetPostDouble("designerpirce");
  9611. entity.update_time = DateTime.Now;
  9612. entity.update_u_id = CurrentUser.UserID;
  9613. entity.update_u_name = CurrentUser.UserName;
  9614. entity.isAudit = 1;
  9615. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9616. entity.Update();
  9617. if (orderEntity != null)
  9618. {
  9619. orderEntity.IsReadTag = 3;
  9620. orderEntity.Update();
  9621. }
  9622. returnSuccessMsg("操作成功!");
  9623. return;
  9624. }
  9625. returnErrorMsg("找不到记录");
  9626. }
  9627. }
  9628. public void all_audit_erp_designerbill()
  9629. {
  9630. if (UrlPostParmsCheck("idList"))
  9631. {
  9632. string[] list = GetPostString("idList").Split(',');
  9633. CeErpDesignerBill entity = null;
  9634. for (int i = 0; i < list.Length; i++)
  9635. {
  9636. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9637. if (entity == null) return;
  9638. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9639. if (orderEntity == null) return;
  9640. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9641. entity.update_time = DateTime.Now;
  9642. entity.update_u_id = CurrentUser.UserID;
  9643. entity.update_u_name = CurrentUser.UserName;
  9644. entity.isAudit = 1;
  9645. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9646. entity.Update();
  9647. orderEntity.IsReadTag = 3;
  9648. orderEntity.Update();
  9649. }
  9650. returnSuccessMsg("操作成功!");
  9651. return;
  9652. }
  9653. }
  9654. public void get_erp_sameorders()
  9655. {
  9656. if (UrlPostParmsCheck("ctid"))
  9657. {
  9658. string eid = GetPostString("ctid");
  9659. CeErpTradeCell entity = null;
  9660. entity = CeErpTradeCell.GetByCtid(eid);
  9661. if (entity != null)
  9662. {
  9663. StringBuilder sql = new StringBuilder();
  9664. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9665. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9666. var res = new
  9667. {
  9668. data = dt.Rows.Count
  9669. };
  9670. string ro_jsond = JsonConvert.SerializeObject(res);
  9671. returnSuccess(ro_jsond);
  9672. return;
  9673. }
  9674. returnErrorMsg("未找到订单");
  9675. return;
  9676. }
  9677. returnErrorMsg("缺少必要的参数");
  9678. }
  9679. public void get_erp_islasthavesameorder()
  9680. {
  9681. if (UrlPostParmsCheck("ctid"))
  9682. {
  9683. string eid = GetPostString("ctid");
  9684. string[] ctidList = eid.Split(',');
  9685. StringBuilder sql = new StringBuilder();
  9686. string tisCtid = "";
  9687. foreach (string ctid in ctidList)
  9688. {
  9689. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9690. if (entity != null)
  9691. {
  9692. sql = new StringBuilder();
  9693. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9694. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9695. if (dth.Rows.Count > 0)
  9696. {
  9697. tisCtid += entity.ctid;
  9698. tisCtid += ",";
  9699. }
  9700. }
  9701. }
  9702. if (tisCtid.Length > 0)
  9703. {
  9704. var res = new
  9705. {
  9706. data = tisCtid
  9707. };
  9708. string ro_jsond = JsonConvert.SerializeObject(res);
  9709. returnSuccess(ro_jsond);
  9710. }
  9711. else
  9712. {
  9713. var res = new
  9714. {
  9715. data = ""
  9716. };
  9717. string ro_jsond = JsonConvert.SerializeObject(res);
  9718. returnSuccess(ro_jsond);
  9719. }
  9720. return;
  9721. }
  9722. returnErrorMsg("缺少必要的参数");
  9723. }
  9724. public void file_client_down_url()
  9725. {
  9726. if (!UrlPostParmsCheck("userId"))
  9727. {
  9728. returnErrorMsg("缺少必要的参数");
  9729. }
  9730. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9731. }
  9732. public void checkout_form_data()
  9733. {
  9734. if (!UrlPostParmsCheck("tid"))
  9735. {
  9736. returnErrorMsg("缺少必要的参数");
  9737. }
  9738. string tid = GetPostString("tid");
  9739. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9740. if (ceErpOrderFormData != null)
  9741. {
  9742. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9743. returnSuccess(ro_jsond);
  9744. return;
  9745. }
  9746. returnErrorMsg("尚未有文件!");
  9747. }
  9748. public void back_supplier_audit()
  9749. {
  9750. int userId = CurrentUser.UserID;
  9751. StringBuilder sql = new StringBuilder();
  9752. 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);
  9753. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9754. if (dt.Rows.Count > 0)
  9755. {
  9756. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9757. }
  9758. else
  9759. {
  9760. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9761. }
  9762. }
  9763. public void back_supplier_query()
  9764. {
  9765. string eid = GetPostString("ctid");
  9766. if (eid != "")
  9767. {
  9768. StringBuilder sql = new StringBuilder();
  9769. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9770. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9771. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9772. }
  9773. else
  9774. {
  9775. returnErrorMsg("找不到订单记录");
  9776. return;
  9777. }
  9778. }
  9779. public void verified_to_order()
  9780. {
  9781. int userId = CurrentUser.UserID;
  9782. StringBuilder sql = new StringBuilder();
  9783. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9784. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9785. if (dt.Rows.Count > 0)
  9786. {
  9787. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9788. }
  9789. else
  9790. {
  9791. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9792. }
  9793. }
  9794. public void upd_supplier_audit()
  9795. {
  9796. if (UrlPostParmsCheck("ctid"))
  9797. {
  9798. string eid = GetPostString("ctid");
  9799. string reason = GetPostString("returnreason");
  9800. CeErpTradeCell entity = null;
  9801. CeWithdraw withdraw = null;
  9802. withdraw = CeWithdraw.GetByTid(eid);
  9803. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9804. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9805. {
  9806. if (withdraw != null)
  9807. {
  9808. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9809. {
  9810. returnSuccessMsg("您没有权限操作!");
  9811. return;
  9812. }
  9813. else
  9814. {
  9815. if (reason.Equals("1"))
  9816. {
  9817. if (entity.OrderState == -1)
  9818. {
  9819. if (entity.FinishPlaceTime == null)
  9820. {
  9821. entity.OrderState = 2;
  9822. }
  9823. else
  9824. {
  9825. entity.OrderState = 6;
  9826. }
  9827. }
  9828. entity.Update();
  9829. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9830. if (withdraw != null)
  9831. {
  9832. withdraw.status = int.Parse(reason);
  9833. withdraw.Update();
  9834. }
  9835. returnSuccessMsg("操作成功!");
  9836. return;
  9837. }
  9838. else
  9839. {
  9840. withdraw.status = int.Parse(reason);
  9841. withdraw.acknowledgingtime = DateTime.Now;
  9842. withdraw.Update();
  9843. returnSuccessMsg("查看详细请点击线下订单查询");
  9844. return;
  9845. }
  9846. }
  9847. }
  9848. // 第一个字符是 'N'
  9849. }
  9850. if (eid[0] != 'N')
  9851. {
  9852. }
  9853. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9854. {
  9855. entity.IsVerifyToSupplier = false;
  9856. entity.IsReturn = 1;
  9857. entity.ReturnTime = DateTime.Now;
  9858. entity.ReturnReason = reason;
  9859. if (entity.OrderState == 6)
  9860. {
  9861. entity.OrderState = 5;
  9862. }
  9863. entity.Update();
  9864. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9865. if (withdraw != null)
  9866. {
  9867. withdraw.status = int.Parse(reason);
  9868. withdraw.Update();
  9869. }
  9870. returnSuccessMsg("操作成功!");
  9871. return;
  9872. }
  9873. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9874. {
  9875. ;
  9876. if (withdraw != null)
  9877. {
  9878. withdraw.status = int.Parse(reason);
  9879. withdraw.acknowledgingtime = DateTime.Now;
  9880. withdraw.Update();
  9881. returnSuccessMsg("供应商取消撤回!");
  9882. return;
  9883. }
  9884. }
  9885. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9886. {
  9887. if (entity.OrderState == -1)
  9888. {
  9889. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9890. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9891. {
  9892. returnErrorMsg("订单spu没有确认无法通过审核!");
  9893. return;
  9894. }
  9895. if (entity.FinishPlaceTime == null)
  9896. {
  9897. entity.OrderState = 2;
  9898. }
  9899. else
  9900. {
  9901. entity.OrderState = 3;
  9902. }
  9903. commonHelper.getCytPrice(entity);
  9904. }
  9905. entity.Update();
  9906. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9907. if (withdraw != null)
  9908. {
  9909. withdraw.status = int.Parse(reason);
  9910. withdraw.Update();
  9911. }
  9912. returnSuccessMsg("操作成功!");
  9913. return;
  9914. }
  9915. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9916. {
  9917. if (withdraw == null)
  9918. {
  9919. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9920. return;
  9921. }
  9922. }
  9923. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9924. {
  9925. if (withdraw != null)
  9926. {
  9927. withdraw.status = int.Parse(reason);
  9928. withdraw.acknowledgingtime = DateTime.Now;
  9929. withdraw.Update();
  9930. returnSuccessMsg("查看详细请点击线下订单查询");
  9931. return;
  9932. }
  9933. }
  9934. return;
  9935. }
  9936. }
  9937. //校验报价
  9938. public void refund_order_tip()
  9939. {
  9940. int userid = CurrentUser.UserID;
  9941. int sectionId = CurrentUser.UserPost.OrgID;
  9942. StringBuilder sql = new StringBuilder();
  9943. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9944. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9945. List<string> ids = new List<string>();
  9946. if (dth.Rows.Count > 0)
  9947. {
  9948. foreach (DataRow dr in dth.Rows)
  9949. {
  9950. ids.Add(dr["ID"].ToString());
  9951. }
  9952. try
  9953. {
  9954. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9955. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9956. }
  9957. catch (Exception ex)
  9958. {
  9959. }
  9960. }
  9961. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9962. }
  9963. public void refund_order_Design()
  9964. {
  9965. int userid = CurrentUser.UserID;
  9966. int sectionId = CurrentUser.UserPost.OrgID;
  9967. StringBuilder sql = new StringBuilder();
  9968. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9969. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9970. List<string> ids = new List<string>();
  9971. if (dth.Rows.Count > 0)
  9972. {
  9973. foreach (DataRow dr in dth.Rows)
  9974. {
  9975. ids.Add(dr["ID"].ToString());
  9976. }
  9977. try
  9978. {
  9979. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9980. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9981. }
  9982. catch (Exception ex)
  9983. {
  9984. }
  9985. }
  9986. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9987. }
  9988. public void change_order_info()
  9989. {
  9990. int userid = CurrentUser.UserID;
  9991. StringBuilder sql = new StringBuilder();
  9992. 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);
  9993. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9994. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9995. }
  9996. public void change_win_mome()
  9997. {
  9998. if (UrlPostParmsCheck("id,ctid"))
  9999. {
  10000. string id = GetPostString("id");
  10001. string ctid = GetPostString("ctid");
  10002. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10003. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10004. if (ce == null || ceErpMessageTip == null)
  10005. {
  10006. returnSuccessMsg("未找到对应的订单!");
  10007. return;
  10008. }
  10009. if (ce.OrderState >= 5)
  10010. {
  10011. returnSuccessMsg("已上传文件无法修改!");
  10012. return;
  10013. }
  10014. int type = GetPostInt("type");
  10015. string content = GetPostString("content");
  10016. if (type == 0)
  10017. {
  10018. content = content.Replace("(", "(");
  10019. content = content.Replace(")", ")");
  10020. string check = MidStrEx(content, "(", ")").Trim();
  10021. if (string.IsNullOrEmpty(check))
  10022. {
  10023. returnSuccessMsg("文件名格式不正确");
  10024. return;
  10025. }
  10026. }
  10027. ce.seller_memo = content;
  10028. ce.Update();
  10029. ceErpMessageTip.isVisit = true;
  10030. ceErpMessageTip.Update();
  10031. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10032. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10033. ApiVo apiVo = new ApiVo();
  10034. apiVo.orderNumber = ce.ctid;
  10035. apiVo.actionName = "demandDesign";
  10036. apiVo.orderRemarks = content;
  10037. apiVo.demandExamine = type + 1;
  10038. designHelper.API_WorkCore(apiVo);//demandDesign
  10039. returnSuccessMsg("修改成功!");
  10040. }
  10041. }
  10042. public static string MidStrEx(string sourse, string startstr, string endstr)
  10043. {
  10044. string result = string.Empty;
  10045. int startindex, endindex;
  10046. try
  10047. {
  10048. startindex = sourse.IndexOf(startstr);
  10049. if (startindex == -1)
  10050. return result;
  10051. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10052. endindex = tmpstr.IndexOf(endstr);
  10053. if (endindex == -1)
  10054. return result;
  10055. result = tmpstr.Remove(endindex);
  10056. }
  10057. catch (Exception ex)
  10058. {
  10059. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10060. }
  10061. return result;
  10062. }
  10063. public void refund_order_list()
  10064. {
  10065. int userid = CurrentUser.UserID;
  10066. int sectionId = CurrentUser.UserPost.OrgID;
  10067. StringBuilder sql = new StringBuilder();
  10068. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10069. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10070. DataStruct dStruct = GetPostStruct();
  10071. DataTable dt = null;
  10072. List<string> ids = new List<string>();
  10073. List<string> tids = new List<string>();
  10074. if (dth.Rows.Count > 0)
  10075. {
  10076. foreach (DataRow dr in dth.Rows)
  10077. {
  10078. tids.Add("'" + dr["tid"].ToString() + "'");
  10079. ids.Add(dr["id"].ToString());
  10080. }
  10081. try
  10082. {
  10083. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10084. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10085. List<string> lw = new List<string>();
  10086. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10087. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10088. dt = WebCache.GetData("view_orderlist", dStruct);
  10089. }
  10090. catch (Exception ex)
  10091. {
  10092. }
  10093. }
  10094. writeGridDataTableJson(dStruct.TotalCount, dt);
  10095. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10096. }
  10097. //新增
  10098. public void order_batch_downloads()
  10099. {
  10100. string ceid = GetPostString("tid");
  10101. String[] tid = ceid.Split(',');
  10102. order_batch_caiyingtong(tid);
  10103. /* (string success, string errors) = UploadFiles(tid);
  10104. returnSuccessMsg(success + errors);*/
  10105. return;
  10106. }
  10107. //报价接口
  10108. public void Get_To_Quote()
  10109. {
  10110. string ceid = GetPostString("ctid");
  10111. if (ceid != null)
  10112. {
  10113. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10114. if (entity != null)
  10115. {
  10116. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10117. {
  10118. return;
  10119. }
  10120. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10121. double price = 0;
  10122. if (cp == null)
  10123. {
  10124. JObject jsonObject12 = new JObject
  10125. {
  10126. { "UserId", "77886" },
  10127. { "Pwd", "lt666888" },
  10128. { "Filename", entity.seller_memo }
  10129. };
  10130. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10131. JObject jsonObjects1 = JObject.Parse(response1);
  10132. string ms1g = (string)jsonObjects1["msg"];
  10133. if (ms1g == "报价成功")
  10134. {
  10135. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10136. string data = (string)jsonObject1["price"];
  10137. 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 + "');";
  10138. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10139. returnSuccessMsg("获取报价成功:" + data);
  10140. price = Convert.ToDouble(data);
  10141. }
  10142. else
  10143. {
  10144. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10145. return;
  10146. }
  10147. }
  10148. String[] beizhu = entity.seller_memo.Split('-');
  10149. String chanp = "";
  10150. if (beizhu.Length > 0)
  10151. {
  10152. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10153. }
  10154. else
  10155. {
  10156. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10157. }
  10158. JObject jsonObject = new JObject
  10159. {
  10160. { "UserId", "77886" },
  10161. { "Pwd", "lt666888" },
  10162. { "Filename", chanp }
  10163. };
  10164. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10165. JObject jsonObjects = JObject.Parse(response);
  10166. string msg = (string)jsonObjects["msg"];
  10167. if (msg == "报价成功")
  10168. {
  10169. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10170. string data = (string)jsonObject1["price"];
  10171. 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 + "');";
  10172. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10173. returnSuccessMsg("获取报价成功:" + data);
  10174. price = Convert.ToDouble(data);
  10175. }
  10176. else
  10177. {
  10178. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10179. return;
  10180. }
  10181. if (price > 0)
  10182. {
  10183. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10184. if (ceErpTradeCellExtend == null)
  10185. {
  10186. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10187. ceErpTradeCellExtend.ctid = entity.ctid;
  10188. ceErpTradeCellExtend.payment_cyt = price;
  10189. ceErpTradeCellExtend.Create();
  10190. }
  10191. else
  10192. {
  10193. ceErpTradeCellExtend.payment_cyt = price;
  10194. ceErpTradeCellExtend.Update();
  10195. }
  10196. }
  10197. return;
  10198. }
  10199. }
  10200. else
  10201. {
  10202. returnErrorMsg("请至少选择一条数据");
  10203. return;
  10204. }
  10205. }
  10206. //新增
  10207. public void order_To_Supplier()
  10208. {
  10209. string ceid = GetPostString("tid");
  10210. String[] tid = ceid.Split(',');
  10211. if (tid.Length > 0)
  10212. {
  10213. try
  10214. {
  10215. for (int i = 0; i < tid.Length; i++)
  10216. {
  10217. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10218. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10219. entity.SupplierId = suid;
  10220. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10221. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10222. entity.Update();
  10223. }
  10224. }
  10225. catch (Exception ex)
  10226. {
  10227. returnErrorMsg("自动匹配供应商失败");
  10228. return;
  10229. }
  10230. }
  10231. else
  10232. {
  10233. returnErrorMsg("请至少选择一条数据");
  10234. return;
  10235. }
  10236. returnSuccessMsg("自动匹配供应商成功");
  10237. return;
  10238. }
  10239. public (string, string) UploadFiles(string[] urls)
  10240. {
  10241. string success = "";
  10242. string errors = "";
  10243. int userid = CurrentUser.UserID;
  10244. foreach (string url in urls)
  10245. {
  10246. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10247. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10248. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10249. {
  10250. JObject jsonObject = new JObject
  10251. {
  10252. { "Userid", "77886" },
  10253. { "pwd", "cyt86435015" },
  10254. { "content", base64FileContent },
  10255. { "ext", Path.GetExtension(fileName) }
  10256. };
  10257. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10258. JObject jsonObjects = JObject.Parse(response);
  10259. string msg = (string)jsonObjects["msg"];
  10260. if (msg.Equals("上传成功"))
  10261. {
  10262. success += url + " 上传成功";
  10263. }
  10264. else
  10265. {
  10266. errors += url + " 上传失败";
  10267. }
  10268. }
  10269. else
  10270. {
  10271. errors += url + " 格式出现问题";
  10272. }
  10273. }
  10274. if (urls.Length == 0)
  10275. {
  10276. return (success, errors);
  10277. }
  10278. return (success, errors);
  10279. }
  10280. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10281. {
  10282. return true; //总是接受
  10283. }
  10284. public static string HttpPost(string url, string param = null)
  10285. {
  10286. HttpWebRequest request;
  10287. //如果是发送HTTPS请求
  10288. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10289. {
  10290. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10291. request = WebRequest.Create(url) as HttpWebRequest;
  10292. request.ProtocolVersion = HttpVersion.Version10;
  10293. }
  10294. else
  10295. {
  10296. request = WebRequest.Create(url) as HttpWebRequest;
  10297. }
  10298. request.Method = "POST";
  10299. request.ContentType = "application/json";
  10300. request.Accept = "*/*";
  10301. request.Timeout = 120000;
  10302. request.AllowAutoRedirect = false;
  10303. StreamWriter requestStream = null;
  10304. WebResponse response = null;
  10305. string responseStr = null;
  10306. try
  10307. {
  10308. requestStream = new StreamWriter(request.GetRequestStream());
  10309. requestStream.Write(param);
  10310. requestStream.Close();
  10311. response = request.GetResponse();
  10312. if (response != null)
  10313. {
  10314. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10315. responseStr = reader.ReadToEnd();
  10316. reader.Close();
  10317. }
  10318. }
  10319. catch (Exception ex)
  10320. {
  10321. return ex.Message;
  10322. }
  10323. finally
  10324. {
  10325. request = null;
  10326. requestStream = null;
  10327. response = null;
  10328. }
  10329. return responseStr;
  10330. }
  10331. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10332. {
  10333. string base64FileContent;
  10334. string fileName;
  10335. using (WebClient webClient = new WebClient())
  10336. {
  10337. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10338. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10339. {
  10340. using (Stream stream = response.GetResponseStream())
  10341. {
  10342. using (MemoryStream memoryStream = new MemoryStream())
  10343. {
  10344. stream.CopyTo(memoryStream);
  10345. byte[] fileBytes = memoryStream.ToArray();
  10346. base64FileContent = Convert.ToBase64String(fileBytes);
  10347. fileName = response.Headers["Content-Disposition"];
  10348. if (!string.IsNullOrEmpty(fileName))
  10349. {
  10350. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10351. if (index >= 0)
  10352. {
  10353. fileName = fileName.Substring(index + 9).Trim('\"');
  10354. }
  10355. }
  10356. else
  10357. {
  10358. fileName = Path.GetFileName(downloadUrl);
  10359. }
  10360. }
  10361. }
  10362. }
  10363. }
  10364. return (fileName, base64FileContent);
  10365. }
  10366. //新增
  10367. public void order_batch_caiyingtong(string[] downloadUrls)
  10368. {
  10369. try
  10370. {
  10371. //遍历文件
  10372. DataStruct dStruct = GetPostStruct();
  10373. DataTable dt = null;
  10374. int userid = CurrentUser.UserID;
  10375. List<string> ids = new List<string>();//失败组
  10376. List<string> tids = new List<string>();
  10377. using (WebClient webClient = new WebClient())
  10378. {
  10379. foreach (var url in downloadUrls)
  10380. {
  10381. try
  10382. {
  10383. tids.Add("'" + url + "'");
  10384. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10385. if (entity != null)
  10386. {
  10387. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10388. if (cp == null)
  10389. {
  10390. JObject jsonObject = new JObject
  10391. {
  10392. { "Userid", "77886" },
  10393. { "pwd", "lt666888" },
  10394. { "Filename",entity.seller_memo }
  10395. };
  10396. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10397. JObject jsonObjects = JObject.Parse(response);
  10398. string msg = (string)jsonObjects["msg"];
  10399. if (msg == "报价成功")
  10400. {
  10401. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10402. DownloadAndConvertToBase64(url1);
  10403. }
  10404. else
  10405. {
  10406. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10407. }
  10408. }
  10409. else
  10410. {
  10411. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10412. JObject jsonObject = new JObject
  10413. {
  10414. { "Userid", "77886" },
  10415. { "pwd", "lt666888" },
  10416. { "Filename",chanp }
  10417. };
  10418. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10419. JObject jsonObjects = JObject.Parse(response);
  10420. string msg = (string)jsonObjects["msg"];
  10421. if (msg == "报价成功")
  10422. {
  10423. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10424. DownloadAndConvertToBase64(url1);
  10425. }
  10426. else
  10427. {
  10428. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10429. }
  10430. }
  10431. }
  10432. // 上传文件到FTP
  10433. }
  10434. catch (Exception ex)
  10435. {
  10436. Console.WriteLine($"An error occurred: {ex.Message}");
  10437. }
  10438. }
  10439. List<string> lw = new List<string>();
  10440. lw.Add(string.Format("( OrderState < 6 )"));
  10441. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10442. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10443. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10444. if (dt.Rows.Count > 0)
  10445. {
  10446. foreach (DataRow dr in dt.Rows)
  10447. {
  10448. ids.Add(dr["ctid"].ToString());
  10449. }
  10450. }
  10451. String ErrorMsgs = "";
  10452. foreach (String id in ids)
  10453. {
  10454. ErrorMsgs += id + ",";
  10455. }
  10456. if (ErrorMsgs.Length > 1)
  10457. {
  10458. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10459. }
  10460. if (ErrorMsgs.Length < 1)
  10461. {
  10462. ErrorMsgs = "上传成功";
  10463. returnSuccessMsg(ErrorMsgs);
  10464. }
  10465. else
  10466. {
  10467. returnErrorMsg("以下订单" + ErrorMsgs);
  10468. }
  10469. }
  10470. // 删除文件夹及其内容
  10471. /* Directory.Delete(localDirectory, true);*/
  10472. }
  10473. catch { }
  10474. }
  10475. public void get_center_data()
  10476. {
  10477. int userId = CurrentUser.UserID;
  10478. string postCode = CurrentUser.UserPost.Post.Code;
  10479. List<string> lw = new List<string>();
  10480. List<string> ww = new List<string>();
  10481. DateTime currentTime = DateTime.Now;
  10482. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10483. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10484. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10485. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10486. string sql = " SELECT ";
  10487. string startTime = "2023-10-01 11:22:31";
  10488. //设计
  10489. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10490. {
  10491. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10492. 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));
  10493. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10494. 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));
  10495. }
  10496. //客服
  10497. else if (postCode == "CustomerService" || postCode == "Director")
  10498. {
  10499. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10500. 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));
  10501. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10502. 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));
  10503. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10504. 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));
  10505. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10506. 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));
  10507. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10508. 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));
  10509. }
  10510. //售后
  10511. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10512. {
  10513. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10514. 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));
  10515. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10516. 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));
  10517. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10518. 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));
  10519. }
  10520. //下单部
  10521. else if (postCode == "Place" || postCode == "PlaceMr")
  10522. {
  10523. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10524. 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));
  10525. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10526. 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));
  10527. }
  10528. //车间
  10529. else if (postCode == "Supplier")
  10530. {
  10531. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10532. 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));
  10533. }
  10534. DataTable dt = new DataTable();
  10535. if (lw.Count > 0)
  10536. {
  10537. sql += string.Join(" , ", lw);
  10538. sql += " FROM ";
  10539. sql += string.Join(" , ", ww);
  10540. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10541. }
  10542. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10543. }
  10544. public void get_center_data_list()
  10545. {
  10546. int userId = CurrentUser.UserID;
  10547. string postCode = CurrentUser.UserPost.Post.Code;
  10548. string shopIds = CurrentUser.User.pemShop;
  10549. DataStruct dStruct = GetPostStruct();
  10550. List<string> lw = new List<string>();
  10551. DateTime currentTime = DateTime.Now;
  10552. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10553. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10554. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10555. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10556. string startTime = "2023-10-01 11:22:31";
  10557. int order_type = GetPostInt("order_type");
  10558. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10559. {
  10560. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10561. if (order_type == 0)
  10562. {
  10563. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10564. }
  10565. else if (order_type == 3)
  10566. {
  10567. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10568. }
  10569. else
  10570. {
  10571. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10572. }
  10573. }
  10574. //客服
  10575. if (postCode == "CustomerService" || postCode == "Director")
  10576. {
  10577. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10578. if (order_type == 0)
  10579. {
  10580. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10581. }
  10582. else if (order_type == 1)
  10583. {
  10584. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10585. }
  10586. else if (order_type == 2)
  10587. {
  10588. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10589. }
  10590. else if (order_type == 3)
  10591. {
  10592. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10593. }
  10594. else if (order_type == 4)
  10595. {
  10596. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10597. }
  10598. else
  10599. {
  10600. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10601. }
  10602. }
  10603. //售后
  10604. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10605. {
  10606. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10607. if (shopIds != "")
  10608. {
  10609. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10610. }
  10611. if (order_type == 2)
  10612. {
  10613. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10614. }
  10615. else if (order_type == 4)
  10616. {
  10617. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10618. }
  10619. else if (order_type == 5)
  10620. {
  10621. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10622. }
  10623. else
  10624. {
  10625. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10626. }
  10627. }
  10628. //下单部
  10629. if (postCode == "Place" || postCode == "PlaceMr")
  10630. {
  10631. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10632. if (shopIds != "")
  10633. {
  10634. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10635. }
  10636. else if (order_type == 1)
  10637. {
  10638. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10639. }
  10640. else if (order_type == 2)
  10641. {
  10642. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10643. }
  10644. else
  10645. {
  10646. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10647. }
  10648. }
  10649. //车间
  10650. if (postCode == "Supplier")
  10651. {
  10652. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10653. if (order_type == 5)
  10654. {
  10655. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10656. }
  10657. else
  10658. {
  10659. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10660. }
  10661. }
  10662. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10663. dStruct.Fileds = "tid,ctid";
  10664. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10665. writeGridDataTableJson(dStruct.TotalCount, dt);
  10666. }
  10667. public void aftersale_audit_master()
  10668. {
  10669. if (UrlPostParmsCheck("ctid"))
  10670. {
  10671. string ctid = GetPostString("ctid");
  10672. if (ctid.Length > 0)
  10673. {
  10674. bool result = aftersale_data_change(ctid);
  10675. if (result)
  10676. {
  10677. returnSuccessMsg("修改成功!");
  10678. return;
  10679. }
  10680. }
  10681. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10682. }
  10683. }
  10684. public void aftersale_batch_audit_master()
  10685. {
  10686. if (UrlPostParmsCheck("ctids"))
  10687. {
  10688. string ctids = GetPostString("ctids");
  10689. if (ctids.Length > 0)
  10690. {
  10691. List<string> list = new List<string>();
  10692. string[] ctid_list = ctids.Split(',');
  10693. foreach (var item in ctid_list)
  10694. {
  10695. bool result = aftersale_data_change(item);
  10696. if (!result)
  10697. {
  10698. list.Add(item);
  10699. }
  10700. }
  10701. if (list.Count > 0)
  10702. {
  10703. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10704. return;
  10705. }
  10706. returnSuccessMsg("修改成功!");
  10707. return;
  10708. }
  10709. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10710. }
  10711. }
  10712. public bool aftersale_data_change(string ctid)
  10713. {
  10714. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10715. if (ceErpTradeCell != null)
  10716. {
  10717. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10718. ceErpTradeCell.AfterSaleSupplierState = 0;
  10719. StringBuilder sql = new StringBuilder();
  10720. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10721. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10722. CeErpTradeResponsible.DelByTid(ctid, 0);
  10723. 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 == "不理赔")
  10724. {
  10725. CeErpTradeResponsible.DelByTid(ctid, 1);
  10726. ceErpTradeCell.AfterSaleSupplierState = 1;
  10727. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10728. ceErpTradeCell.AfterSaleState = 4;
  10729. }
  10730. else
  10731. {
  10732. ceErpTradeCell.AfterSaleState = 3;
  10733. }
  10734. bool needCyt = false;
  10735. if (dt != null)
  10736. {
  10737. if (dt.Rows.Count == 1)
  10738. {
  10739. bool isEnd = false;
  10740. foreach (DataRow dr in dt.Rows)
  10741. {
  10742. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10743. {
  10744. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10745. isEnd = true;
  10746. }
  10747. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10748. {
  10749. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10750. isEnd = true;
  10751. }
  10752. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10753. {
  10754. needCyt = true;
  10755. }
  10756. }
  10757. if (isEnd)
  10758. {
  10759. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10760. ceErpTradeCell.AfterSaleState = 4;
  10761. ceErpTradeCell.AfterSaleSupplierState = 1;
  10762. }
  10763. }
  10764. else
  10765. {
  10766. bool isAll = true;
  10767. foreach (DataRow dr in dt.Rows)
  10768. {
  10769. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10770. {
  10771. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10772. continue;
  10773. }
  10774. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10775. {
  10776. string path = "";
  10777. int OrgID = 0;
  10778. if (!Convert.IsDBNull(dr["OrgPath"]))
  10779. {
  10780. path = dr["OrgPath"].ToString();
  10781. }
  10782. if (!Convert.IsDBNull(dr["OrgID"]))
  10783. {
  10784. OrgID = Convert.ToInt32(dr["OrgID"]);
  10785. }
  10786. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10787. {
  10788. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10789. continue;
  10790. }
  10791. }
  10792. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10793. {
  10794. needCyt = true;
  10795. }
  10796. isAll = false;
  10797. }
  10798. if (isAll)
  10799. {
  10800. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10801. ceErpTradeCell.AfterSaleState = 4;
  10802. ceErpTradeCell.AfterSaleSupplierState = 1;
  10803. }
  10804. }
  10805. }
  10806. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10807. {
  10808. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10809. }
  10810. if (ceErpTradeCell.AfterSaleState == 4)
  10811. {
  10812. ApiVo apiVo = new ApiVo();
  10813. apiVo.orderNumber = ceErpTradeCell.ctid;
  10814. apiVo.actionName = "afterOver";
  10815. designHelper.API_WorkCore(apiVo); //afterOver
  10816. }
  10817. ceErpTradeCell.Update();
  10818. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10819. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10820. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10821. return true;
  10822. }
  10823. return false;
  10824. }
  10825. public void get_erp_wechatorder()
  10826. {
  10827. DataStruct dStruct = GetPostStruct();
  10828. List<string> lw = new List<string>();
  10829. string tid = GetPostString("tid");
  10830. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10831. string shopname = GetPostString("shopname");
  10832. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10833. string buyernick = GetPostString("buyer_nick");
  10834. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10835. string customer = GetPostString("customer");
  10836. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10837. string returndate1 = GetPostString("returndate1");
  10838. string returndate2 = GetPostString("returndate2");
  10839. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10840. if (dw.Length > 0) lw.Add(dw);
  10841. string finishDate1 = GetPostString("finishdate1");
  10842. string finishDate2 = GetPostString("finishdate2");
  10843. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10844. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10845. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10846. dStruct.Order = "created desc";
  10847. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10848. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10849. writeGridDataTableJson(dStruct.TotalCount, dt);
  10850. }
  10851. public void get_erp_wechatlist_sumprice()
  10852. {
  10853. DataStruct dStruct = GetPostStruct();
  10854. List<string> lw = new List<string>();
  10855. string tid = GetPostString("tid");
  10856. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10857. string shopname = GetPostString("shopname");
  10858. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10859. string buyernick = GetPostString("buyer_nick");
  10860. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10861. string customer = GetPostString("customer");
  10862. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10863. string returndate1 = GetPostString("returndate1");
  10864. string returndate2 = GetPostString("returndate2");
  10865. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10866. if (dw.Length > 0) lw.Add(dw);
  10867. string finishDate1 = GetPostString("finishdate1");
  10868. string finishDate2 = GetPostString("finishdate2");
  10869. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10870. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10871. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10872. string mainWhere = string.Join(" and ", lw.ToArray());
  10873. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10874. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10875. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10876. decimal total = 0;
  10877. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10878. {
  10879. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10880. }
  10881. var res = new
  10882. {
  10883. data = total
  10884. };
  10885. string ro_jsond = JsonConvert.SerializeObject(res);
  10886. returnSuccess(ro_jsond);
  10887. return;
  10888. }
  10889. public void get_erp_qr_waitdeliverylist()
  10890. {
  10891. DataStruct dStruct = GetPostStruct();
  10892. List<string> lw = new List<string>();
  10893. string tid = GetPostString("ctid");
  10894. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10895. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10896. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10897. var res_objz = new
  10898. {
  10899. restype = 1,
  10900. data = dt
  10901. };
  10902. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10903. returnSuccess(ro_jsonz);
  10904. }
  10905. public void get_erp_yield_list()
  10906. {
  10907. DataStruct dStruct = GetPostStruct();
  10908. List<string> lw = new List<string>();
  10909. string tid = GetPostString("ctid");
  10910. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10911. string shopname = GetPostString("shopname");
  10912. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10913. string buyernick = GetPostString("buyer_nick");
  10914. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10915. //if (tid.Length == 0 && buyernick.Length == 0)
  10916. //{
  10917. // lw.Add(string.Format("IsRefund<={0}", 1));
  10918. //}
  10919. string customer = GetPostString("customer");
  10920. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10921. string design = GetPostString("design");
  10922. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10923. string orderState = GetPostString("orderState");
  10924. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10925. string address = GetPostString("address");
  10926. 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));
  10927. string sellermemo = GetPostString("seller_memo");
  10928. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10929. string supplier = GetPostString("supplier");
  10930. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10931. string OrderArea = GetPostString("order_area");
  10932. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10933. string placedate1 = GetPostString("placedate1");
  10934. string placedate2 = GetPostString("placedate2");
  10935. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10936. if (fdw.Length > 0) lw.Add(fdw);
  10937. string price1 = GetPostString("price1");
  10938. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10939. string price2 = GetPostString("price2");
  10940. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10941. string unusualCon = GetPostString("unusualcon");
  10942. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10943. string posTag = CurrentUser.UserPost.Post.Code;
  10944. if (posTag == "Supplier")
  10945. {
  10946. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10947. }
  10948. lw.Add(string.Format("OrderState = 6 "));
  10949. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10950. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10951. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10952. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10953. writeGridDataTableJson(dStruct.TotalCount, dt);
  10954. }
  10955. public void change_erp_sup_state()
  10956. {
  10957. if (UrlPostParmsCheck("ctid"))
  10958. {
  10959. string ctid = GetPostString("ctid");
  10960. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10961. if (ceErpTradeCell != null)
  10962. {
  10963. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10964. if (ceErpTradeCellExtend == null)
  10965. {
  10966. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10967. ceErpTradeCellExtend.ctid = ctid;
  10968. ceErpTradeCellExtend.SupState = 1;
  10969. ceErpTradeCellExtend.Create();
  10970. }
  10971. else
  10972. {
  10973. ceErpTradeCellExtend.SupState = 1;
  10974. ceErpTradeCellExtend.Update();
  10975. }
  10976. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10977. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10978. return;
  10979. }
  10980. returnErrorMsg("找不到订单");
  10981. }
  10982. }
  10983. public void supplier_all_downs()
  10984. {
  10985. if (UrlPostParmsCheck("tids"))
  10986. {
  10987. string tids = GetPostString("tids");
  10988. if (tids != null && tids.Length > 0)
  10989. {
  10990. StringBuilder sql = new StringBuilder();
  10991. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10992. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10993. sql = new StringBuilder();
  10994. 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, "下载设计文件");
  10995. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10996. string[] list = tids.Split(',');
  10997. foreach (string ctid in list)
  10998. {
  10999. CeErpSukuraData.createInfo(ctid, 3);
  11000. }
  11001. designHelper.api_approveDesign(tids); //approveDesign
  11002. returnSuccessMsg("下载成功!");
  11003. return;
  11004. }
  11005. returnErrorMsg("下载订单更新失败");
  11006. }
  11007. }
  11008. public void uploaderFileSuccess()
  11009. {
  11010. if (UrlPostParmsCheck("fileName"))
  11011. {
  11012. string fileName = GetPostString("fileName");
  11013. ApiVo apiVo = new ApiVo();
  11014. apiVo.orderNumber = fileName;
  11015. apiVo.actionName = "finishDesign";
  11016. designHelper.API_WorkCore(apiVo);//finishDesign
  11017. returnSuccessMsg("");
  11018. }
  11019. }
  11020. public void get_sample2_order()
  11021. {
  11022. if (UrlPostParmsCheck("ctid"))
  11023. {
  11024. string ctid = GetPostString("ctid");
  11025. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11026. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11027. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11028. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11029. double total = 0.0;
  11030. double order_price = 0.0;
  11031. if (dt_bu.Rows.Count > 0)
  11032. {
  11033. foreach (DataRow dr in dt_bu.Rows)
  11034. {
  11035. total += Convert.ToDouble(dr["payment"]);
  11036. }
  11037. }
  11038. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11039. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11040. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11041. string tid = ctid.Replace("S_", "");
  11042. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11043. double paymant = 0.0;
  11044. if (entity != null)
  11045. {
  11046. paymant = entity.payment;
  11047. }
  11048. string return_reason = "";
  11049. if (dt_after != null && dt_after.Rows.Count > 0)
  11050. {
  11051. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11052. }
  11053. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11054. }
  11055. }
  11056. public void get_erp_design_status()
  11057. {
  11058. string designName = GetPostString("designName");
  11059. DataStruct dStruct = GetPostStruct();
  11060. if (designName.Length > 0)
  11061. {
  11062. 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";
  11063. sql_user += " and Name like '%" + designName + "%'";
  11064. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11065. List<string> ids_list = new List<string>();
  11066. if (user_table.Rows.Count > 0)
  11067. {
  11068. foreach (DataRow item in user_table.Rows)
  11069. {
  11070. ids_list.Add(item["id"].ToString());
  11071. string ids_s = item["TeamIds"].ToString();
  11072. if (ids_s.Length > 0)
  11073. {
  11074. ids_list.AddRange(ids_s.Split(','));
  11075. }
  11076. }
  11077. }
  11078. HashSet<string> set = new HashSet<string>(ids_list);
  11079. ids_list = set.ToList();
  11080. if (ids_list.Count > 0)
  11081. {
  11082. 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));
  11083. dStruct.MainWhere = sql;
  11084. DataTable dt = null;
  11085. dt = WebCache.GetData("view_ErpUser", dStruct);
  11086. writeGridDataTableJson(dStruct.TotalCount, dt);
  11087. }
  11088. }
  11089. }
  11090. public void change_erp_order_price()
  11091. {
  11092. string ctid = GetPostString("ctid");
  11093. double price = GetPostDouble("price");
  11094. if (ctid.Length > 0)
  11095. {
  11096. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11097. if (ceErpTradeCellExtend == null)
  11098. {
  11099. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11100. ceErpTradeCellExtend.ctid = ctid;
  11101. ceErpTradeCellExtend.payment_cyt = price;
  11102. ceErpTradeCellExtend.Create();
  11103. }
  11104. else
  11105. {
  11106. ceErpTradeCellExtend.payment_cyt = price;
  11107. ceErpTradeCellExtend.Update();
  11108. }
  11109. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11110. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11111. {
  11112. ceErpDataSendOrderInfo.isSync = false;
  11113. ceErpDataSendOrderInfo.Update();
  11114. }
  11115. if (ceErpDataSendOrderInfo == null)
  11116. {
  11117. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11118. ceErpDataSendOrderInfo.isSync = false;
  11119. ceErpDataSendOrderInfo.ctid = ctid;
  11120. ceErpDataSendOrderInfo.Create();
  11121. }
  11122. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11123. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11124. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11125. if (dth != null && dth.Rows.Count > 0)
  11126. {
  11127. dataSendOrderBean dataSendOrderBean = null;
  11128. foreach (DataRow item in dth.Rows)
  11129. {
  11130. try
  11131. {
  11132. dataSendOrderBean = new dataSendOrderBean();
  11133. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11134. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11135. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11136. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11137. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11138. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11139. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11140. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11141. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11142. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11143. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11144. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11145. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11146. if (result != null)
  11147. {
  11148. if ("0".Equals(result.errcode))
  11149. {
  11150. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11151. }
  11152. else
  11153. {
  11154. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11155. }
  11156. }
  11157. }
  11158. catch (Exception ex)
  11159. {
  11160. }
  11161. }
  11162. }
  11163. returnSuccessMsg("修改成功!");
  11164. return;
  11165. }
  11166. returnErrorMsg("找不到订单");
  11167. }
  11168. public void find_he_together()
  11169. {
  11170. string ctid = GetPostString("ctid");
  11171. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11172. List<string> list = new List<string>();
  11173. if (ceErpTradeCell != null)
  11174. {
  11175. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11176. {
  11177. 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);
  11178. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11179. if (table != null && table.Rows.Count > 0)
  11180. {
  11181. foreach (TableRow row in table.Rows)
  11182. {
  11183. }
  11184. }
  11185. }
  11186. }
  11187. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11188. }
  11189. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11190. {
  11191. //chy----19
  11192. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11193. //GD-CYT-----64
  11194. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11195. //ZHX----3
  11196. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11197. //JK----97
  11198. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11199. //ZT----70
  11200. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11201. //LHCY-----98
  11202. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11203. //XD-----90
  11204. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11205. //CYCY-----14
  11206. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11207. };
  11208. //其他改名
  11209. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11210. {
  11211. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11212. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11213. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11214. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11215. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11216. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11217. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11218. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11219. };
  11220. //不统计
  11221. List<int> no_suppliers = new List<int>()
  11222. {
  11223. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11224. };
  11225. //配件单
  11226. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11227. {
  11228. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11229. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11230. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11231. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11232. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11233. {"旗杆",new List<string>(){ "班旗" } },
  11234. {"牙签",new List<string>(){ "不干胶" } }
  11235. };
  11236. public void get_place_order_data()
  11237. {
  11238. string date1 = GetPostString("date1");
  11239. string date2 = GetPostString("date2");
  11240. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11241. DateTime start = DateTime.Parse(starttime);
  11242. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11243. DateTime end = DateTime.Parse(endtime);
  11244. if (date1 != null && date1.Length > 0)
  11245. {
  11246. DateTime dateTime = DateTime.Parse(date1);
  11247. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11248. start = DateTime.Parse(starttime);
  11249. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11250. end = DateTime.Parse(endtime);
  11251. }
  11252. if (date2 != null && date2.Length > 0)
  11253. {
  11254. DateTime dateTime = DateTime.Parse(date2);
  11255. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11256. end = DateTime.Parse(endtime);
  11257. }
  11258. 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);
  11259. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11260. //不干胶-----1,卡片-----29
  11261. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11262. foreach (DataRow row in data.Rows)
  11263. {
  11264. int productId = Convert.ToInt32(row["ProductId"]);
  11265. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11266. if (no_suppliers.Contains(supplierId))
  11267. {
  11268. continue;
  11269. }
  11270. string seller_memo = row["seller_memo"].ToString();
  11271. bool ispj = false;//是否配件单
  11272. bool isfirst = true;//第一个配
  11273. maps.Keys.ForEach(key =>
  11274. {
  11275. //备注包含配件
  11276. if (seller_memo.Contains(key) && isfirst)
  11277. {
  11278. List<string> list = maps[key];
  11279. ispj = true;
  11280. isfirst = false;
  11281. for (int i = 0; i < list.Count; i++)
  11282. {
  11283. if (seller_memo.Contains(list[i]))
  11284. {
  11285. ispj = false;
  11286. break;
  11287. }
  11288. }
  11289. }
  11290. });
  11291. if (ispj)
  11292. {
  11293. continue;
  11294. }
  11295. seller_memo = seller_memo.Replace("UV", "uv");
  11296. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11297. //吊牌归到卡片
  11298. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11299. seller_memo = seller_memo.Replace("卡套", "卡片");
  11300. seller_memo = seller_memo.Replace("封套", "卡片");
  11301. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11302. seller_memo = seller_memo.Replace("腰封", "卡片");
  11303. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11304. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11305. seller_memo = seller_memo.Replace("横幅", "条幅");
  11306. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11307. string map_key = "";
  11308. string type = "";
  11309. if (supplierMap.ContainsKey(supplierId))
  11310. {
  11311. foreach (var kvp in supplierMap[supplierId])
  11312. {
  11313. if (seller_memo.Contains(kvp.Key))
  11314. {
  11315. map_key = kvp.Value;
  11316. type = kvp.Value;
  11317. break;
  11318. }
  11319. }
  11320. }
  11321. if (map_key == "")
  11322. {
  11323. type = "其他";
  11324. map_key = "其他";
  11325. }
  11326. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11327. {
  11328. map_key = suppliers[supplierId];
  11329. }
  11330. if (supplierId == 70)
  11331. {
  11332. supplierId = 70;
  11333. }
  11334. map_key += "_" + row["SupplierName"].ToString();
  11335. Dictionary<string, int> map = null;
  11336. if (other_map.ContainsKey(map_key))
  11337. {
  11338. other_map.TryGetValue(map_key, out map);
  11339. }
  11340. else
  11341. {
  11342. map = new Dictionary<string, int>();
  11343. map.Add("dayDev", 0);//当天出货
  11344. map.Add("dayTotal", 0);//下单总数
  11345. map.Add("payTotal", 0);//500以上
  11346. map.Add("today", 0);//当天出货数量
  11347. map.Add("unusua", 0);//异常数
  11348. other_map.Add(map_key, map);
  11349. other_map.TryGetValue(map_key, out map);
  11350. }
  11351. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11352. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11353. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11354. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11355. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11356. {
  11357. map["dayTotal"]++;
  11358. if (supplierId == 97)
  11359. {
  11360. supplierId = 97;
  11361. }
  11362. }
  11363. if (Convert.ToDecimal(row["payment"]) >= 500)
  11364. {
  11365. map["payTotal"]++;
  11366. }
  11367. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11368. {
  11369. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11370. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11371. {
  11372. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11373. {
  11374. map["today"]++;
  11375. }
  11376. }
  11377. else
  11378. {
  11379. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11380. {
  11381. map["today"]++;
  11382. }
  11383. else
  11384. {
  11385. if (supplierId == 119)
  11386. {
  11387. Debug.WriteLine(row["seller_memo"].ToString());
  11388. }
  11389. }
  11390. }
  11391. }
  11392. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11393. {
  11394. map["unusua"]++;
  11395. }
  11396. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11397. //GD-CYT-----64
  11398. DateTime two = palceTimeStart.AddHours(14);
  11399. DateTime three = palceTimeStart.AddHours(15);
  11400. DateTime four = palceTimeStart.AddHours(16);
  11401. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11402. {
  11403. //下午四点前 500-1000
  11404. string count = row["ProductCount"].ToString();
  11405. if (count != null && count.Length > 0)
  11406. {
  11407. int productCount = commonHelper.getPlaceProductCount(count);
  11408. if (productCount >= 500 && productCount <= 1000)
  11409. {
  11410. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11411. {
  11412. map["dayDev"]++;
  11413. }
  11414. }
  11415. }
  11416. }
  11417. //UV
  11418. else if ("uv".Equals(type))
  11419. {
  11420. //ZT----70
  11421. //ZHX----3
  11422. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11423. {
  11424. map["dayDev"]++;
  11425. }
  11426. //JK----97
  11427. //HZX----105
  11428. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11429. {
  11430. map["dayDev"]++;
  11431. if (supplierId == 97)
  11432. {
  11433. supplierId = 97;
  11434. }
  11435. }
  11436. }
  11437. //帆布---52|条幅---27
  11438. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11439. {
  11440. //LHCY-----98
  11441. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11442. {
  11443. map["dayDev"]++;
  11444. }
  11445. }
  11446. //条幅
  11447. else if ("条幅".Equals(type))
  11448. {
  11449. //XD-----90
  11450. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11451. {
  11452. map["dayDev"]++;
  11453. }
  11454. }
  11455. //桌布
  11456. else if ("桌布".Equals(type))
  11457. {
  11458. //XD-----90
  11459. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11460. {
  11461. map["dayDev"]++;
  11462. }
  11463. }
  11464. //DL---10
  11465. //AYTW---119
  11466. //FS-CYT-DY ----80
  11467. //JK----97
  11468. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11469. {
  11470. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11471. {
  11472. map["dayDev"]++;
  11473. }
  11474. }
  11475. }
  11476. DataTable dt = new DataTable();
  11477. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11478. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11479. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11480. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11481. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11482. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11483. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11484. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11485. other_map.Keys.ForEach(key =>
  11486. {
  11487. DataRow dr = dt.NewRow();
  11488. Dictionary<string, int> map = other_map[key];
  11489. string[] key_list = key.Split('_');
  11490. dr[0] = key_list[0];
  11491. dr[1] = key_list[1];
  11492. if (key_list.Length > 2)
  11493. {
  11494. dr[1] += "(" + key_list[2] + ")";
  11495. }
  11496. dr[2] = map["dayTotal"];
  11497. dr[3] = map["payTotal"];
  11498. dr[4] = map["today"];
  11499. dr[5] = map["unusua"];
  11500. dr[6] = map["dayDev"];
  11501. double rate = 0.00;
  11502. if (map["dayDev"] > 0)
  11503. {
  11504. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11505. }
  11506. dr[7] = rate.ToString();
  11507. dt.Rows.Add(dr);
  11508. });
  11509. DataView dv = new DataView(dt);
  11510. dv.Sort = "SupplierName";
  11511. //dv.Sort = "AllOrder desc";
  11512. DataTable dtNew = dv.ToTable();
  11513. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11514. }
  11515. public void check_order_desing_info()
  11516. {
  11517. string ctid = GetPostString("ctid");
  11518. if (!string.IsNullOrEmpty(ctid))
  11519. {
  11520. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11521. if (ceErpTradeCell != null)
  11522. {
  11523. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11524. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11525. return;
  11526. }
  11527. returnErrorMsg("找不到订单");
  11528. return;
  11529. }
  11530. returnErrorMsg("找不到订单");
  11531. }
  11532. public void get_timeout_detail()
  11533. {
  11534. string poscode = CurrentUser.UserPost.Post.Code;
  11535. DataStruct dStruct = GetPostStruct();
  11536. List<string> lw = new List<string>();
  11537. string id = GetPostString("id");
  11538. string pay_date1 = GetPostString("pay_date1");
  11539. string pay_date2 = GetPostString("pay_date2");
  11540. int type = GetPostInt("type");
  11541. if (type == 0)
  11542. {
  11543. if (pay_date1.Length > 0)
  11544. {
  11545. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11546. }
  11547. if (pay_date2.Length > 0)
  11548. {
  11549. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11550. }
  11551. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11552. }
  11553. if (type == 1)
  11554. {
  11555. if (pay_date1.Length > 0)
  11556. {
  11557. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11558. }
  11559. if (pay_date2.Length > 0)
  11560. {
  11561. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11562. }
  11563. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11564. }
  11565. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11566. DataTable dt = null;
  11567. dt = WebCache.GetData("view_orderlist", dStruct);
  11568. writeGridDataTableJson(dStruct.TotalCount, dt);
  11569. }
  11570. public void saveUrgentChargePrice()
  11571. {
  11572. string ctid = GetPostString("ctid");
  11573. if (!string.IsNullOrEmpty(ctid))
  11574. {
  11575. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11576. if (ceErpTradeCell != null)
  11577. {
  11578. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11579. if (prices <= 100)
  11580. {
  11581. returnErrorMsg("此订单金额不足100元,无法加急。");
  11582. return;
  11583. }
  11584. double price = GetPostDouble("price");
  11585. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11586. if (ceErpTradeCellExtend == null)
  11587. {
  11588. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11589. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11590. }
  11591. ceErpTradeCellExtend.urgentCharge = price;
  11592. if (ceErpTradeCellExtend.ID > 0)
  11593. {
  11594. ceErpTradeCellExtend.Update();
  11595. }
  11596. else
  11597. {
  11598. ceErpTradeCellExtend.Save();
  11599. }
  11600. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11601. returnSuccessMsg("修改成功!");
  11602. return;
  11603. }
  11604. returnErrorMsg("找不到订单");
  11605. return;
  11606. }
  11607. returnErrorMsg("找不到订单");
  11608. }
  11609. public void finish_erp_order()
  11610. {
  11611. string ctid = GetPostString("ctid");
  11612. if (!string.IsNullOrEmpty(ctid))
  11613. {
  11614. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11615. {
  11616. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11617. if (ceErpTradeCell != null)
  11618. {
  11619. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11620. ceErpTradeCell.Update();
  11621. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11622. returnSuccessMsg("修改成功!");
  11623. return;
  11624. }
  11625. }
  11626. }
  11627. returnErrorMsg("找不到订单");
  11628. }
  11629. public void get_trade_order_list()
  11630. {
  11631. string tid = GetPostString("tid");
  11632. if (!string.IsNullOrEmpty(tid))
  11633. {
  11634. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11635. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11636. writeGridDataTableJson(data.Rows.Count, data);
  11637. return;
  11638. }
  11639. returnErrorMsg("找不到订单");
  11640. }
  11641. public void save_cell_spu()
  11642. {
  11643. string ctid = GetPostString("ctid");
  11644. string spu_id = GetPostString("spu_id");
  11645. if (!string.IsNullOrEmpty(ctid))
  11646. {
  11647. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11648. if (ceErpTradeCellExtend == null)
  11649. {
  11650. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11651. ceErpTradeCellExtend.ctid = ctid;
  11652. }
  11653. ceErpTradeCellExtend.spu_id = spu_id;
  11654. if (!string.IsNullOrEmpty(spu_id))
  11655. {
  11656. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11657. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  11658. ceErpTradeCellExtend.ToType = result;
  11659. List<int> products = new List<int>() { 4, 13, 19, 24, 28, 32, 40, 51, 57, 1971, 2319, 2377, 2521, 2524, 2533, 2538, 2542, 2554, 2556, 2557, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2568, 2569, 2570, 2571, 2572, 2619, 2625, 2634, 2636, 2637, 2638, 2645, 2646 };
  11660. List<int> shopIds = new List<int>() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 18, 24, 27, 28, 31, 32, 56, 61 };
  11661. if (products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  11662. {
  11663. ceErpTradeCellExtend.ToType = "外协";
  11664. }
  11665. if ((ceErpTradeCell.seller_memo.Contains("改稿") || ceErpTradeCell.OtherMemo.Contains("改稿")) && shopIds.Contains(ceErpTradeCell.ShopId))
  11666. {
  11667. ceErpTradeCellExtend.ToType = "内部";
  11668. }
  11669. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  11670. {
  11671. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  11672. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  11673. }
  11674. }
  11675. if (ceErpTradeCellExtend.ID == 0)
  11676. {
  11677. ceErpTradeCellExtend.Create();
  11678. }
  11679. else
  11680. {
  11681. ceErpTradeCellExtend.Update();
  11682. }
  11683. returnSuccessMsg("修改成功!");
  11684. return;
  11685. }
  11686. returnErrorMsg("找不到订单");
  11687. }
  11688. public void change_express_info()
  11689. {
  11690. string ctid = GetPostString("ctid");
  11691. string transNo = GetPostString("transNo");
  11692. string transCom = GetPostString("transCom");
  11693. if (!string.IsNullOrEmpty(ctid))
  11694. {
  11695. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11696. if (ceErpTradeCellExtend == null)
  11697. {
  11698. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11699. ceErpTradeCellExtend.ctid = ctid;
  11700. }
  11701. ceErpTradeCellExtend.modExpressNo = transNo;
  11702. ceErpTradeCellExtend.modExpressCom = transCom;
  11703. ceErpTradeCellExtend.readMod = 2;
  11704. if (ceErpTradeCellExtend.ID == 0)
  11705. {
  11706. ceErpTradeCellExtend.Create();
  11707. }
  11708. else
  11709. {
  11710. ceErpTradeCellExtend.Update();
  11711. }
  11712. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11713. returnSuccessMsg("修改成功!");
  11714. return;
  11715. }
  11716. returnErrorMsg("找不到订单");
  11717. }
  11718. public void get_change_express_list()
  11719. {
  11720. DataStruct dStruct = GetPostStruct();
  11721. List<string> lw = new List<string>();
  11722. int st = 2;
  11723. string tid = GetPostString("ctid");
  11724. if (tid.Length > 0)
  11725. {
  11726. string select_tid = getTidByCtid(tid);
  11727. lw.Add(string.Format("tid='{0}'", select_tid));
  11728. }
  11729. string shopname = GetPostString("shopname");
  11730. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11731. string buyernick = GetPostString("buyer_nick");
  11732. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11733. string sellermemo = GetPostString("seller_memo");
  11734. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11735. string supplier = GetPostString("supplier");
  11736. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11737. string customer = GetPostString("customer");
  11738. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11739. string design = GetPostString("design");
  11740. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11741. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11742. string poscode = CurrentUser.UserPost.Post.Code;
  11743. if (poscode != "SysAdmin")
  11744. {
  11745. string shopid = CurrentUser.User.pemShop;
  11746. lw.Add(string.Format("shopId in ({0})", shopid));
  11747. }
  11748. lw.Add("readMod = 2");
  11749. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11750. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11751. writeGridDataTableJson(dStruct.TotalCount, dt);
  11752. }
  11753. public void deal_express_complete()
  11754. {
  11755. string ctid = GetPostString("ctid");
  11756. if (!string.IsNullOrEmpty(ctid))
  11757. {
  11758. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11759. if (ceErpTradeCellExtend == null)
  11760. {
  11761. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11762. ceErpTradeCellExtend.ctid = ctid;
  11763. }
  11764. ceErpTradeCellExtend.readMod = 1;
  11765. if (ceErpTradeCellExtend.ID == 0)
  11766. {
  11767. ceErpTradeCellExtend.Create();
  11768. }
  11769. else
  11770. {
  11771. ceErpTradeCellExtend.Update();
  11772. }
  11773. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11774. returnSuccessMsg("修改成功!");
  11775. return;
  11776. }
  11777. returnErrorMsg("找不到订单");
  11778. }
  11779. public void aftersale_return_visit()
  11780. {
  11781. string ctid = GetPostString("ctid");
  11782. if (!string.IsNullOrEmpty(ctid))
  11783. {
  11784. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11785. if (ceErpTradeCellExtend == null)
  11786. {
  11787. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11788. ceErpTradeCellExtend.ctid = ctid;
  11789. }
  11790. ceErpTradeCellExtend.returnVisit = 1;
  11791. if (ceErpTradeCellExtend.ID == 0)
  11792. {
  11793. ceErpTradeCellExtend.Create();
  11794. }
  11795. else
  11796. {
  11797. ceErpTradeCellExtend.Update();
  11798. }
  11799. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11800. if (ceErpTradeAfterSaleExtend != null)
  11801. {
  11802. ceErpTradeAfterSaleExtend.TextResult = "";
  11803. ceErpTradeAfterSaleExtend.Update();
  11804. }
  11805. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11806. returnSuccessMsg("修改成功!");
  11807. return;
  11808. }
  11809. returnErrorMsg("找不到订单");
  11810. }
  11811. public void orderPlaceInfo()
  11812. {
  11813. string ctids = GetPostString("ctids");
  11814. string[] list = ctids.Split(',');
  11815. foreach (string ctid in list)
  11816. {
  11817. CeErpSukuraData.createInfo(ctid, 3);
  11818. }
  11819. StringBuilder sql = new StringBuilder();
  11820. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11821. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11822. designHelper.api_approveDesign(ctids); //approveDesign
  11823. returnSuccessMsg("");
  11824. }
  11825. public void get_issue_list()
  11826. {
  11827. DataStruct dStruct = GetPostStruct();
  11828. List<string> lw = new List<string>();
  11829. int st = 2;
  11830. string tid = GetPostString("ctid");
  11831. if (tid.Length > 0)
  11832. {
  11833. string select_tid = getTidByCtid(tid);
  11834. lw.Add(string.Format("tid='{0}'", select_tid));
  11835. }
  11836. string shopname = GetPostString("shopname");
  11837. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11838. string buyernick = GetPostString("buyer_nick");
  11839. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11840. string sellermemo = GetPostString("seller_memo");
  11841. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11842. string supplier = GetPostString("supplier");
  11843. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11844. string customer = GetPostString("customer");
  11845. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11846. string design = GetPostString("design");
  11847. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11848. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11849. string poscode = CurrentUser.UserPost.Post.Code;
  11850. if (poscode != "SysAdmin")
  11851. {
  11852. string shopid = CurrentUser.User.pemShop;
  11853. lw.Add(string.Format("shopId in ({0})", shopid));
  11854. }
  11855. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11856. {
  11857. lw.Add("IssueState = 1");
  11858. }
  11859. lw.Add("IssueState > 0");
  11860. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11861. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11862. writeGridDataTableJson(dStruct.TotalCount, dt);
  11863. }
  11864. public void saveIssueContent()
  11865. {
  11866. string ctid = GetPostString("ctid");
  11867. if (!string.IsNullOrEmpty(ctid))
  11868. {
  11869. string content = GetPostString("content");
  11870. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11871. if (ceErpTradeAfterSaleExtend == null)
  11872. {
  11873. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11874. ceErpTradeAfterSaleExtend.tid = ctid;
  11875. }
  11876. ceErpTradeAfterSaleExtend.IssueContent = content;
  11877. ceErpTradeAfterSaleExtend.IssueState = 1;
  11878. if (ceErpTradeAfterSaleExtend.ID > 0)
  11879. {
  11880. ceErpTradeAfterSaleExtend.Update();
  11881. }
  11882. else
  11883. {
  11884. ceErpTradeAfterSaleExtend.Create();
  11885. }
  11886. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11887. returnSuccessMsg("添加成功!");
  11888. return;
  11889. }
  11890. returnErrorMsg("找不到订单");
  11891. }
  11892. public void dealIssueContent()
  11893. {
  11894. string ctid = GetPostString("ctid");
  11895. if (!string.IsNullOrEmpty(ctid))
  11896. {
  11897. string content = GetPostString("content");
  11898. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11899. if (ceErpTradeAfterSaleExtend != null)
  11900. {
  11901. ceErpTradeAfterSaleExtend.IssueState = 2;
  11902. ceErpTradeAfterSaleExtend.Update();
  11903. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11904. returnSuccessMsg("修改完成!");
  11905. return;
  11906. }
  11907. }
  11908. returnErrorMsg("找不到订单");
  11909. }
  11910. public void set_tid_attachments()
  11911. {
  11912. string tid = GetPostString("tid");
  11913. string atta = GetPostString("atta");
  11914. if (!string.IsNullOrEmpty(tid))
  11915. {
  11916. if (string.IsNullOrEmpty(atta))
  11917. {
  11918. returnErrorMsg("文件地址为空");
  11919. return;
  11920. }
  11921. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11922. if (ceErpTradeCell != null)
  11923. {
  11924. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11925. if (ceErpTrade == null)
  11926. {
  11927. returnErrorMsg("找不到订单");
  11928. return;
  11929. }
  11930. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11931. bool isSend = false;
  11932. if (dt != null && dt.Rows.Count > 0)
  11933. {
  11934. foreach (DataRow row in dt.Rows)
  11935. {
  11936. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11937. {
  11938. isSend = true;
  11939. }
  11940. }
  11941. if (isSend)
  11942. {
  11943. returnErrorMsg("已发货无法修改");
  11944. return;
  11945. }
  11946. ceErpTrade.Attachments = atta;
  11947. ceErpTrade.Update();
  11948. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  11949. returnSuccessMsg("上传成功!");
  11950. return;
  11951. }
  11952. }
  11953. }
  11954. returnErrorMsg("找不到订单");
  11955. }
  11956. public void get_tid_attachments()
  11957. {
  11958. string tid = GetPostString("tid");
  11959. if (!string.IsNullOrEmpty(tid))
  11960. {
  11961. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11962. if (ceErpTradeCell != null)
  11963. {
  11964. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11965. if (ceErpTrade == null)
  11966. {
  11967. returnErrorMsg("找不到订单");
  11968. return;
  11969. }
  11970. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11971. return;
  11972. }
  11973. }
  11974. returnErrorMsg("找不到订单");
  11975. }
  11976. public void check_erp_sameorders()
  11977. {
  11978. if (UrlPostParmsCheck("ctid"))
  11979. {
  11980. string eid = GetPostString("ctid");
  11981. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11982. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11983. if (entity != null && ceErpTrade != null)
  11984. {
  11985. if (entity.OrderState > 6)
  11986. {
  11987. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11988. return;
  11989. }
  11990. DataTable dt = getSameOrderList(entity, ceErpTrade);
  11991. List<string> ids = new List<string>();
  11992. if (dt != null && dt.Rows.Count > 1)
  11993. {
  11994. bool needhe = true;
  11995. foreach (DataRow dr in dt.Rows)
  11996. {
  11997. ids.Add("'" + dr["ctid"] + "'");
  11998. /* //备注有合包
  11999. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12000. {
  12001. needhe = true;
  12002. }
  12003. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12004. {
  12005. needhe = true;
  12006. }
  12007. //顺丰快递
  12008. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12009. {
  12010. needhe = true;
  12011. }*/
  12012. }
  12013. if (!needhe)
  12014. {
  12015. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12016. return;
  12017. }
  12018. StringBuilder sql = new StringBuilder();
  12019. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12020. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12021. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12022. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12023. foreach (DataRow dr in dt.Rows)
  12024. {
  12025. dr["dstate"] = 0;
  12026. dr["dnumber"] = 0;
  12027. foreach (DataRow row in dt1.Rows)
  12028. {
  12029. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12030. {
  12031. dr["dstate"] = 2;
  12032. //dr["default"] = 1;
  12033. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12034. }
  12035. }
  12036. if (eid.Equals(dr["ctid"].ToString()))
  12037. {
  12038. dr["dstate"] = 1;
  12039. //dr["default"] = 1;
  12040. }
  12041. }
  12042. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12043. return;
  12044. }
  12045. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12046. return;
  12047. }
  12048. returnErrorMsg("未找到订单");
  12049. return;
  12050. }
  12051. returnErrorMsg("缺少必要的参数");
  12052. }
  12053. private DataTable getSameOrderList(CeErpTradeCell entity, CeErpTrade ceErpTrade)
  12054. {
  12055. StringBuilder sql = new StringBuilder();
  12056. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0", entity.SupplierId);
  12057. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12058. {
  12059. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12060. }
  12061. else
  12062. {
  12063. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12064. }
  12065. DataTable dt = null;
  12066. try
  12067. {
  12068. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12069. return dt;
  12070. StringBuilder timerSql = new StringBuilder();
  12071. timerSql.AppendFormat("SELECT * FROM CE_ErpSupplierProductTime WHERE supplierId={0}", entity.SupplierId);
  12072. DataTable timerTable = DbHelper.DbConn.ExecuteDataset(timerSql.ToString()).Tables[0];
  12073. //没有设置时间则不判断
  12074. if (timerTable == null || timerTable.Rows.Count == 0)
  12075. {
  12076. return dt;
  12077. }
  12078. dt.Columns.Add(new DataColumn("default", typeof(int)));
  12079. foreach (DataRow dr in dt.Rows)
  12080. {
  12081. dr["default"] = 0;
  12082. //当前订单
  12083. if (entity.ctid.Equals(dr["ctid"]))
  12084. {
  12085. continue;
  12086. }
  12087. //已经标记过发货
  12088. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(dr["ctid"].ToString());
  12089. if (ceErpDeliverMark != null)
  12090. {
  12091. dr["default"] = 1;
  12092. continue;
  12093. }
  12094. string[] productIds = null;
  12095. string productId = dr["productId"].ToString();
  12096. string finishPlaceTime = dr["FinishPlaceTime"].ToString();
  12097. string sellmer_mome = dr["seller_memo"].ToString();
  12098. string txtCount = dr["ProductCount"].ToString();
  12099. DateTime placeTime = DateTime.Now;
  12100. //没有品类
  12101. if (string.IsNullOrEmpty(productId) || "0".Equals(productId))
  12102. {
  12103. continue;
  12104. }
  12105. if (string.IsNullOrEmpty(finishPlaceTime))
  12106. {
  12107. continue;
  12108. }
  12109. placeTime = DateTime.Parse(finishPlaceTime);
  12110. foreach (DataRow row in timerTable.Rows)
  12111. {
  12112. string txtIds = row["productId"].ToString();
  12113. string[] crafts = { };
  12114. int count = Convert.ToUInt16(row["quantity"]);
  12115. if (string.IsNullOrEmpty(txtIds))
  12116. {
  12117. continue;
  12118. }
  12119. if (count > 0)
  12120. {
  12121. int quantity = commonHelper.handleProductCount(txtCount, true);
  12122. //订单数量大于写入的数量则跳过
  12123. if (quantity > count)
  12124. {
  12125. continue;
  12126. }
  12127. }
  12128. productIds = txtIds.Split(',');
  12129. if (productIds.Contains(productId))
  12130. {
  12131. string textCraft = row["craft"].ToString();
  12132. textCraft = textCraft.Replace(",", ",");//统一格式
  12133. if (!string.IsNullOrEmpty(textCraft))
  12134. {
  12135. crafts = textCraft.Split(',');
  12136. }
  12137. if (crafts.Length > 0)
  12138. {
  12139. bool isinCraft = false;
  12140. for (int i = 0; i < crafts.Length; i++)
  12141. {
  12142. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12143. {
  12144. isinCraft = true;
  12145. break;
  12146. }
  12147. }
  12148. //有写工艺并且备注中没匹配中则跳过
  12149. if (!isinCraft)
  12150. {
  12151. continue;
  12152. }
  12153. }
  12154. DateTime deadLine = DateTime.Parse(row["deadLine"].ToString());
  12155. DateTime dayDeadLine = DateTime.Parse(row["dayDeadLine"].ToString());
  12156. int sendDay = Convert.ToInt16(row["sendDay"]);
  12157. //下单时间小于当日发货时间则不用判断
  12158. //当日发货必须发货
  12159. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12160. {
  12161. dr["default"] = 1;
  12162. break;
  12163. }
  12164. //在截稿时间之前下单的可以减去一天时间
  12165. /*if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12166. {
  12167. sendDay = Math.Max(1, sendDay - 1);
  12168. }
  12169. DateTime sendtime = placeTime.AddDays(sendDay);
  12170. //判断有没有到发货日期
  12171. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) > 0)
  12172. {
  12173. break;
  12174. }*/
  12175. }
  12176. }
  12177. }
  12178. }
  12179. catch (Exception ex)
  12180. {
  12181. }
  12182. return dt;
  12183. }
  12184. public void get_mark_number()
  12185. {
  12186. string eid = GetPostString("ctid");
  12187. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12188. if (entity != null)
  12189. {
  12190. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12191. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12192. int current = 1;
  12193. if (ceErpDeliverMark == null)
  12194. {
  12195. DataTable dt = getSameOrderList(entity, ceErpTrade);
  12196. List<string> ids = new List<string>();
  12197. if (dt != null && dt.Rows.Count > 1)
  12198. {
  12199. foreach (DataRow dr in dt.Rows)
  12200. {
  12201. ids.Add("'" + dr["ctid"] + "'");
  12202. }
  12203. //查询已有的编号
  12204. StringBuilder sql = new StringBuilder();
  12205. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12206. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12207. if (dt1 == null || dt1.Rows.Count == 0)
  12208. {
  12209. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12210. List<int> list_number = new List<int>();
  12211. foreach (DataRow row in numbers.Rows)
  12212. {
  12213. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12214. }
  12215. //查询空余编号
  12216. for (int i = 0; i < list_number.Count + 2; i++)
  12217. {
  12218. if (!list_number.Contains(current))
  12219. {
  12220. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12221. //防止查询过程中有新数据生成
  12222. if (ceErpDeliverMark1 == null)
  12223. {
  12224. break;
  12225. }
  12226. }
  12227. current++;
  12228. }
  12229. }
  12230. else
  12231. {
  12232. foreach (DataRow row in dt1.Rows)
  12233. {
  12234. current = Convert.ToInt32(row["markNumber"]);
  12235. }
  12236. }
  12237. ceErpDeliverMark = new CeErpDeliverMark();
  12238. ceErpDeliverMark.ctid = eid;
  12239. ceErpDeliverMark.createtime = DateTime.Now;
  12240. if (ceErpTrade != null)
  12241. {
  12242. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12243. }
  12244. ceErpDeliverMark.markNumber = current;
  12245. ceErpDeliverMark.Create();
  12246. }
  12247. }
  12248. else
  12249. {
  12250. current = ceErpDeliverMark.markNumber;
  12251. }
  12252. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12253. return;
  12254. }
  12255. }
  12256. public void aftersaleCytSend()
  12257. {
  12258. string ctid = GetPostString("ctid");
  12259. if (!string.IsNullOrEmpty(ctid))
  12260. {
  12261. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12262. if (ceErpTradeCell != null)
  12263. {
  12264. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12265. }
  12266. returnSuccessMsg("推送成功");
  12267. return;
  12268. }
  12269. returnErrorMsg("缺少必要的参数");
  12270. }
  12271. public void packOrderInfo()
  12272. {
  12273. string ctids = GetPostString("ctids");
  12274. if (!string.IsNullOrEmpty(ctids))
  12275. {
  12276. string[] ctid_list = ctids.Split(',');
  12277. if (ctid_list.Length > 20)
  12278. {
  12279. returnErrorMsg("单次下载次数不能超过20个");
  12280. return;
  12281. }
  12282. StringBuilder sql = new StringBuilder();
  12283. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  12284. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12285. int supplierId = 0;
  12286. StringBuilder insterSql = new StringBuilder();
  12287. for (int i = 0; i < dt.Rows.Count; i++)
  12288. {
  12289. DataRow row = dt.Rows[i];
  12290. if (i == 0)
  12291. {
  12292. supplierId = Convert.ToInt32(row["SupplierId"]);
  12293. }
  12294. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12295. {
  12296. returnErrorMsg("同车间的订单才能一起打包");
  12297. return;
  12298. }
  12299. int orderState = Convert.ToInt32(row["OrderState"]);
  12300. if (orderState != 5)
  12301. {
  12302. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12303. return;
  12304. }
  12305. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12306. }
  12307. CeErpPackData ceErpPackData = new CeErpPackData();
  12308. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip";
  12309. ceErpPackData.supplierId = supplierId;
  12310. ceErpPackData.createtime = DateTime.Now;
  12311. ceErpPackData.createBy = CurrentUser.UserID;
  12312. ceErpPackData.createName = CurrentUser.UserName;
  12313. ceErpPackData.Create();
  12314. if (ceErpPackData.ID > 0)
  12315. {
  12316. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12317. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12318. }
  12319. returnSuccessMsg("打包成功");
  12320. return;
  12321. }
  12322. returnErrorMsg("缺少必要的参数");
  12323. }
  12324. public void get_pack_list()
  12325. {
  12326. DataStruct dStruct = GetPostStruct();
  12327. List<string> lw = new List<string>();
  12328. string supplier = GetPostString("supplier");
  12329. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12330. string posTag = CurrentUser.UserPost.Post.Code;
  12331. if (posTag == "Supplier")
  12332. {
  12333. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12334. }
  12335. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12336. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12337. writeGridDataTableJson(dStruct.TotalCount, dt);
  12338. }
  12339. public void get_supplier_product_time_list()
  12340. {
  12341. DataStruct dStruct = GetPostStruct();
  12342. List<string> lw = new List<string>();
  12343. string supplier = GetPostString("supplier");
  12344. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12345. string posTag = CurrentUser.UserPost.Post.Code;
  12346. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12347. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12348. writeGridDataTableJson(dStruct.TotalCount, dt);
  12349. }
  12350. public void saveSupplierProductTime()
  12351. {
  12352. string productId = GetPostString("productId");
  12353. if (string.IsNullOrEmpty(productId))
  12354. {
  12355. returnErrorMsg("缺少必要的参数");
  12356. return;
  12357. }
  12358. string productName = GetPostString("productName");
  12359. int supplierId = GetPostInt("supplierId");
  12360. if (supplierId == 0)
  12361. {
  12362. returnErrorMsg("缺少必要的参数");
  12363. return;
  12364. }
  12365. int quantity = GetPostInt("quantity");
  12366. int sendDay = GetPostInt("sendTime");
  12367. string supplierName = GetPostString("supplierName");
  12368. string craft = GetPostString("craft");
  12369. string deadLine = GetPostString("deadLine");
  12370. string dayDeadLine = GetPostString("dayDeadLine");
  12371. try
  12372. {
  12373. int eid = GetPostInt("eid");
  12374. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12375. if (ceErpSupplierProductTime == null)
  12376. {
  12377. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12378. }
  12379. ceErpSupplierProductTime.productId = productId;
  12380. ceErpSupplierProductTime.productName = productName;
  12381. ceErpSupplierProductTime.supplierId = supplierId;
  12382. ceErpSupplierProductTime.supplierName = supplierName;
  12383. ceErpSupplierProductTime.craft = craft;
  12384. ceErpSupplierProductTime.sendDay = sendDay;
  12385. ceErpSupplierProductTime.quantity = quantity;
  12386. if (!string.IsNullOrEmpty(deadLine))
  12387. {
  12388. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12389. }
  12390. if (!string.IsNullOrEmpty(dayDeadLine))
  12391. {
  12392. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12393. }
  12394. if (ceErpSupplierProductTime.ID == 0)
  12395. {
  12396. ceErpSupplierProductTime.Save();
  12397. }
  12398. else
  12399. {
  12400. ceErpSupplierProductTime.Update();
  12401. }
  12402. }
  12403. catch (Exception e)
  12404. {
  12405. }
  12406. returnSuccessMsg("保存成功");
  12407. return;
  12408. }
  12409. public void delSupplierProductTime()
  12410. {
  12411. int eid = GetPostInt("eid");
  12412. if (eid > 0)
  12413. {
  12414. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12415. if (ceErpSupplierProductTime == null)
  12416. {
  12417. returnErrorMsg("查无数据");
  12418. return;
  12419. }
  12420. ceErpSupplierProductTime.Delete();
  12421. returnSuccessMsg("保存成功");
  12422. return;
  12423. }
  12424. returnErrorMsg("缺少必要的参数");
  12425. }
  12426. public void getExpressInfo()
  12427. {
  12428. string ctid = GetPostString("ctid");
  12429. if (!string.IsNullOrEmpty(ctid))
  12430. {
  12431. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12432. if (ceErpTradeCell != null)
  12433. {
  12434. string outSid = ceErpTradeCell.OutSid;
  12435. if (outSid.Length > 0)
  12436. {
  12437. string sql = string.Format("SELECT out_sid FROM [dbo].[CE_ErpExpressInfo] WHERE (out_sid in ({0}) or tid = '{1}') and ISNULL(DATALENGTH(postData), 0)>0;", "'" + outSid.Replace(",", "','") + "'", ceErpTradeCell.tid);
  12438. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12439. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12440. return;
  12441. }
  12442. }
  12443. returnErrorMsg("查无记录");
  12444. return;
  12445. }
  12446. returnErrorMsg("缺少必要的参数");
  12447. }
  12448. public void getExpressPostData()
  12449. {
  12450. string express = GetPostString("express");
  12451. if (!string.IsNullOrEmpty(express))
  12452. {
  12453. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12454. if (ceErpExpressInfo != null)
  12455. {
  12456. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12457. return;
  12458. }
  12459. }
  12460. returnErrorMsg("缺少必要的参数");
  12461. }
  12462. }
  12463. }