sync.order.cs 637 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763
  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. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  113. if (ceErpTradeCell != null)
  114. {
  115. tid = ceErpTradeCell.tid;
  116. }
  117. List<string> select_tid = getTidByCtidMore(tid);
  118. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  119. }
  120. if (buyernick.Length > 0)
  121. {
  122. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  123. }
  124. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  125. if (dw.Length > 0)
  126. {
  127. lw.Add(dw);
  128. }
  129. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  130. {
  131. string usershop = CurrentUser.User.pemShop;
  132. lw.Add(string.Format("ShopId in ({0})", usershop));
  133. }
  134. }
  135. else
  136. {
  137. if (ex_psize == 0)
  138. {
  139. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  140. }
  141. if (PKey != "admin")
  142. {
  143. string usershop = CurrentUser.User.pemShop;
  144. lw.Add(string.Format("ShopId in ({0})", usershop));
  145. paramsCount++;
  146. }
  147. }
  148. string uploaddate1 = GetPostString("uploaddate1");
  149. string uploaddate2 = GetPostString("uploaddate2");
  150. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  151. if (update.Length > 0) lw.Add(update);
  152. string deliverydate1 = GetPostString("deliverydate1");
  153. string deliverydate2 = GetPostString("deliverydate2");
  154. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  155. if (deliverydate.Length > 0)
  156. {
  157. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  158. };
  159. string shopname = GetPostString("shopname");
  160. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  161. string addwechat = GetPostString("addwechat");
  162. if (addwechat.Length > 0)
  163. {
  164. int addWt = Convert.ToInt32(addwechat);
  165. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  166. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  167. }
  168. string customer = GetPostString("customer");
  169. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  170. string design = GetPostString("design");
  171. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  172. string orderState = GetPostString("orderState");
  173. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  174. string address = GetPostString("address");
  175. 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));
  176. string sellermemo = GetPostString("seller_memo");
  177. if (sellermemo.Length > 0)
  178. {
  179. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  180. }
  181. string backReason = GetPostString("backReason");
  182. if (backReason.Length > 0)
  183. {
  184. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  185. }
  186. string apdate1 = GetPostString("apdate1");
  187. string apdate2 = GetPostString("apdate2");
  188. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  189. if (dwap.Length > 0) lw.Add(dwap);
  190. string price1 = GetPostString("price1");
  191. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  192. string price2 = GetPostString("price2");
  193. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  194. string isoldcustomer = GetPostString("isoldcus");
  195. string spudata = GetPostString("spudata");
  196. if ("0".Equals(spudata))
  197. {
  198. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  199. }
  200. if ("1".Equals(spudata))
  201. {
  202. lw.Add(string.Format("spu_id <> ''"));
  203. }
  204. string finishdate1 = GetPostString("finishdate1");
  205. string finishdate2 = GetPostString("finishdate2");
  206. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  207. bool isFinish = false;
  208. if (finishdate.Length > 0)
  209. {
  210. lw.Add(finishdate);
  211. isFinish = true;
  212. paramsCount++;
  213. }
  214. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  215. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  216. if (ex_psize > 0)
  217. {
  218. int UserID = CurrentUser.UserID;
  219. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  220. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  221. {
  222. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  223. }
  224. dStruct.Order = "pay_time desc";
  225. }
  226. string isNew = GetPostString("isNew");
  227. if (isNew == "true")
  228. {
  229. lw.Add(string.Format("IsNew = {0}", 1));
  230. }
  231. string overtime = GetPostString("overtime");
  232. if (overtime == "1")
  233. {
  234. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  235. }
  236. String usePost = CurrentUser.UserPost.Post.Code;
  237. if (usePost.Equals("Operation") == true)
  238. {
  239. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  240. }
  241. else
  242. {
  243. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  244. }
  245. //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";
  246. if (dStruct.PageSize == 100000)
  247. {
  248. dStruct.Order = "";
  249. }
  250. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  251. DataTable dt = null;
  252. string tablename = "view_orderlist";
  253. if (isFinish)
  254. {
  255. tablename = "view_orderlist_end";
  256. }
  257. dt = WebCache.GetData(tablename, dStruct);
  258. if (dt != null && dt.Rows.Count > 0)
  259. {
  260. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  261. foreach (DataRow dr in dt.Rows)
  262. {
  263. try
  264. {
  265. if (dr["refund_fees"] != null)
  266. {
  267. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  268. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  269. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  270. if (payment == refund_fees)
  271. {
  272. dr["refund_fees"] = Math.Round(refund_fees, 2);
  273. }
  274. else if (refund_fees == total_fee)
  275. {
  276. dr["refund_fees"] = payment;
  277. }
  278. else
  279. {
  280. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  281. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  282. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  283. }
  284. }
  285. // 对象操作
  286. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  287. ceErpTradeCell.ctid = dr["ctid"].ToString();
  288. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  289. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  290. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  291. if (dStruct.PageSize != 100000)
  292. {
  293. if (dr["DispatchSort"].ToString() == "2")
  294. {
  295. dr["gongchuang"] = 200;
  296. }
  297. else if ("外协".Equals(dr["ToType"].ToString()))
  298. {
  299. dr["gongchuang"] = 200;
  300. }
  301. else if ("内部".Equals(dr["ToType"].ToString()))
  302. {
  303. dr["gongchuang"] = -1;
  304. }
  305. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  306. {
  307. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  308. dr["gongchuang"] = response.code;
  309. }
  310. }
  311. }
  312. catch (NullReferenceException ex)
  313. {
  314. // 处理空引用异常
  315. dr["refund_fees"] = "0.00";
  316. }
  317. }
  318. }
  319. writeGridDataTableJson(dStruct.TotalCount, dt);
  320. }
  321. public void get_erp_orderlist_sumprice()
  322. {
  323. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  324. return;
  325. List<string> lw = new List<string>();
  326. string tid = GetPostString("ctid");
  327. string date1 = GetPostString("date1");
  328. string date2 = GetPostString("date2");
  329. if (tid.Length > 0 || date1.Length > 0)
  330. {
  331. lw.Add(string.Format("ctid like '%{0}%'", tid));
  332. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  333. if (dw.Length > 0) lw.Add(dw);
  334. }
  335. else
  336. {
  337. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  338. }
  339. string shopname = GetPostString("shopname");
  340. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  341. string buyernick = GetPostString("buyer_nick");
  342. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  343. string customer = GetPostString("customer");
  344. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  345. string design = GetPostString("design");
  346. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  347. string orderState = GetPostString("orderState");
  348. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  349. string address = GetPostString("address");
  350. 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));
  351. string sellermemo = GetPostString("seller_memo");
  352. if (sellermemo.Length > 0)
  353. {
  354. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  355. }
  356. string apdate1 = GetPostString("apdate1");
  357. string apdate2 = GetPostString("apdate2");
  358. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  359. if (dwap.Length > 0) lw.Add(dwap);
  360. string price1 = GetPostString("price1");
  361. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  362. string price2 = GetPostString("price2");
  363. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  364. string isoldcustomer = GetPostString("isoldcus");
  365. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  366. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  367. if (PKey != "admin")
  368. {
  369. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  370. lw.Add(string.Format("shopId in ({0})", usershop));
  371. }
  372. //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";
  373. string mainWhere = string.Join(" and ", lw.ToArray());
  374. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  375. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  376. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  377. decimal total = 0;
  378. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  379. {
  380. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  381. }
  382. var res = new
  383. {
  384. data = total
  385. };
  386. string ro_jsond = JsonConvert.SerializeObject(res);
  387. returnSuccess(ro_jsond);
  388. return;
  389. }
  390. public void get_erp_CustomerServiceGather()
  391. {
  392. string userWhere = "", orderWhere = "";
  393. List<string> lw = new List<string>();
  394. string customer = GetPostString("customer");
  395. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  396. string shopname = GetPostString("shopname");
  397. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  398. string date1 = GetPostString("date1");
  399. string date2 = GetPostString("date2");
  400. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  401. if (dw.Length > 0) lw.Add(dw);
  402. orderWhere = string.Join(" and ", lw.ToArray());
  403. 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 " +
  404. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  405. "left join " +
  406. "( " +
  407. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  408. ") as b on a.ID = b.CustomerUserId " +
  409. "left join " +
  410. "( " +
  411. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  412. ") as d on a.ID = d.CustomerUserId " +
  413. "left join " +
  414. "( " +
  415. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  416. ") as e on a.ID = e.CustomerUserId " +
  417. "left join " +
  418. "( " +
  419. " select CustomerUserId, RefundCount, RefundSum from " +
  420. " ( " +
  421. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  422. " from CE_ErpTradeRefund a " +
  423. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  424. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  425. " group by CustomerUserId " +
  426. " ) as a " +
  427. ") as f on a.ID = f.CustomerUserId " +
  428. "where a.PostCode = 'CustomerService'",
  429. userWhere, orderWhere);
  430. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  431. writeGridDataTableJson(dt.Rows.Count, dt);
  432. //writeGridDataTableJson(dt.Rows.Count, dt);
  433. }
  434. //设计汇总
  435. public void get_erp_DesignerGather()
  436. {
  437. string userWhere = "", orderWhere = "";
  438. List<string> lw = new List<string>();
  439. string Designer = GetPostString("designer");
  440. int org = GetPostInt("org");
  441. if (Designer.Length > 0)
  442. {
  443. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  444. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  445. }
  446. else if (org > 0)
  447. {
  448. userWhere = string.Format(" where OrgID ={0}", org);
  449. }
  450. string shopname = GetPostString("shopname");
  451. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  452. string state = GetPostString("state");
  453. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  454. string OrderArea = GetPostString("order_area");
  455. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  456. string date1 = GetPostString("date1");
  457. string date2 = GetPostString("date2");
  458. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  459. if (dw.Length > 0) lw.Add(dw);
  460. string UpDate1 = GetPostString("UpDate1");
  461. string UpDate2 = GetPostString("UpDate2");
  462. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  463. if (dw.Length > 0) lw.Add(dw);
  464. orderWhere = string.Join(" and ", lw.ToArray());
  465. 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 (" +
  466. "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 " +
  467. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  468. "left join " +
  469. "( " +
  470. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  471. ") as b on a.ID = b.DesignUserId " +
  472. "left join " +
  473. "( " +
  474. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  475. ") as d on a.ID = d.DesignUserId " +
  476. "left join " +
  477. "( " +
  478. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  479. ") as e on a.ID = e.DesignUserId " +
  480. "left join " +
  481. "( " +
  482. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  483. ") as g on a.ID = g.DesignUserId " +
  484. "left join " +
  485. "( " +
  486. " select CustomerUserId, RefundCount, RefundSum from " +
  487. " ( " +
  488. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  489. " from CE_ErpTradeRefund a " +
  490. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  491. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  492. " group by CustomerUserId " +
  493. " ) as a " +
  494. ") as f on a.ID = f.CustomerUserId " +
  495. "where a.PostCode = 'Designer') as z",
  496. userWhere, orderWhere);
  497. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  498. writeGridDataTableJson(dt.Rows.Count, dt);
  499. }
  500. //删除tradecell的订单
  501. public void del_erp_cellorder()
  502. {
  503. if (UrlPostParmsCheck("ctid"))
  504. {
  505. string eid = GetPostString("ctid");
  506. CeErpTradeCell.DelByCtid(eid);
  507. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  508. returnSuccessMsg("删除成功");
  509. }
  510. }
  511. public void clear_erp_refundstate()
  512. {
  513. if (UrlPostParmsCheck("ids"))
  514. {
  515. string eids = GetPostString("ids");
  516. string[] ctidList = eids.Split(',');
  517. foreach (string ctid in ctidList)
  518. {
  519. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  520. if (entity != null)
  521. {
  522. entity.IsRefund = 0;
  523. entity.Update();
  524. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  525. }
  526. else
  527. continue;
  528. }
  529. returnSuccessMsg("操作成功");
  530. return;
  531. }
  532. returnErrorMsg("缺少必要参数");
  533. }
  534. public void set_erp_urgency()
  535. {
  536. if (UrlPostParmsCheck("ctid"))
  537. {
  538. string eid = GetPostString("ctid");
  539. CeErpTradeCell entity = null;
  540. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  541. if (entity != null)
  542. {
  543. double prices = commonHelper.calculationPrice(entity);
  544. if (prices <= 100)
  545. {
  546. returnErrorMsg("此订单金额不足100元,无法加急。");
  547. return;
  548. }
  549. string utime = GetPostString("urgencytime");
  550. if (utime.Length > 0)
  551. {
  552. entity.UrgencyTime = Convert.ToDateTime(utime);
  553. }
  554. else
  555. {
  556. returnErrorMsg("请选择加急时间");
  557. return;
  558. }
  559. if (entity.OrderState <= 4)
  560. {
  561. //entity.seller_memo = entity.seller_memo + "-加急";
  562. string smemo = entity.seller_memo;
  563. int kindex = smemo.IndexOf(")");
  564. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  565. if (lastoneStr != "-")
  566. {
  567. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  568. }
  569. string prememo = smemo.Substring(0, kindex + 2);
  570. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  571. int lastkindex = lastmemo.IndexOf("(");
  572. DateTime urgtime = Convert.ToDateTime(utime);
  573. string newlastmemo = "";
  574. if (lastkindex == 0)
  575. {
  576. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  577. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  578. }
  579. else
  580. {
  581. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  582. }
  583. entity.seller_memo = prememo + newlastmemo;
  584. }
  585. entity.IsUrgency = true;
  586. entity.UpdateTime = DateTime.Now;
  587. entity.Update();
  588. ApiVo apiVo = new ApiVo();
  589. apiVo.orderNumber = entity.ctid;
  590. apiVo.actionName = "changeDesign";
  591. apiVo.orderRemarks = entity.seller_memo;
  592. apiVo.remarkSign = 3;
  593. designHelper.API_WorkCore(apiVo); //changeDesign
  594. CeErpSukuraData.createInfo(entity.ctid, 7);
  595. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  596. returnSuccessMsg("设置成功!");
  597. return;
  598. }
  599. returnErrorMsg("找不到记录");
  600. }
  601. }
  602. public void set_erp_reset()
  603. {
  604. if (UrlPostParmsCheck("ctid"))
  605. {
  606. string eid = GetPostString("ctid");
  607. CeErpTradeCell entity = null;
  608. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  609. if (entity != null)
  610. {
  611. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  612. {
  613. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  614. {
  615. returnErrorMsg("财务要求已下单已发货无法重置");
  616. return;
  617. }
  618. }
  619. entity.IsUrgency = false;
  620. entity.seller_memo = "";
  621. entity.OtherMemo = "";
  622. entity.OrderState = 0;
  623. entity.IsReturn = 0;
  624. //entity.IsRefund = 0;
  625. entity.MemoOpt = 0;
  626. entity.AfterSaleState = 0;
  627. entity.AfterSaleResponsible = "";
  628. entity.AfterSaleUserId = 0;
  629. entity.IsNeedBill = 0;
  630. entity.CustomerUserId = 0;
  631. entity.DesignUserId = 0;
  632. entity.SupplierId = 0;
  633. entity.PlaceUserId = 0;
  634. entity.ptid = "";
  635. entity.IsSample = 0;
  636. entity.IsXianHuo = 0;
  637. entity.isDianziOrder = 0;
  638. entity.DispatchSort = 0;
  639. entity.FinishPlaceTime = null;
  640. entity.Update();
  641. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  642. if (trade != null)
  643. {
  644. trade.seller_memo = "";
  645. trade.Update();
  646. }
  647. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  648. returnSuccessMsg("重置成功!");
  649. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  650. if (desginBill != null)
  651. {
  652. desginBill.isDel = 1;
  653. desginBill.Update();
  654. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  655. }
  656. ApiVo apiVo = new ApiVo();
  657. apiVo.orderNumber = entity.ctid;
  658. apiVo.actionName = "resetDesign";
  659. designHelper.API_WorkCore(apiVo);//resetDesign
  660. return;
  661. }
  662. returnErrorMsg("找不到记录");
  663. }
  664. }
  665. public void save_erp_sellermemo()
  666. {
  667. if (UrlPostParmsCheck("ctid"))
  668. {
  669. string ctid = GetPostString("ctid");
  670. CeErpTradeCell entity = null;
  671. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  672. if (entity != null)
  673. {
  674. string memo = GetPostString("seller_memo");
  675. memo = memo.Replace(" ", "");
  676. if (memo.Contains("补差"))
  677. {
  678. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  679. return;
  680. }
  681. List<string> bitList = new List<string>
  682. {
  683. "\\","/",":","*","?", "\"","<" ,">","|"
  684. };
  685. bool isIn = false;
  686. foreach (string bit in bitList)
  687. {
  688. if (memo.Contains(bit))
  689. {
  690. isIn = true;
  691. }
  692. }
  693. if (isIn)
  694. {
  695. returnErrorMsg("不能使用 一些符合作为文件名");
  696. return;
  697. }
  698. if (entity.seller_memo != memo)
  699. {
  700. if (entity.IsSample == 2)
  701. {
  702. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  703. return;
  704. }
  705. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  706. {
  707. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  708. {
  709. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  710. return;
  711. }
  712. /*if (CurrentUser.UserPost.Post.Code != "Place")
  713. {
  714. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  715. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  716. {
  717. returnErrorMsg("售前系统订单无法再此修改!");
  718. return;
  719. }
  720. }*/
  721. }
  722. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  723. }
  724. commonHelper.getCytPrice(entity);
  725. int memoopt = GetPostInt("MemoOpt");
  726. Boolean ismemoopt = false;
  727. if (memoopt > 0)
  728. {
  729. string stropt = "";
  730. if (memoopt == 1)
  731. {
  732. stropt = "“改稿”";
  733. ismemoopt = true;
  734. }
  735. else if (memoopt == 2)
  736. {
  737. stropt = "“定稿”";
  738. }
  739. else if (memoopt == 3)
  740. {
  741. stropt = "“查货”";
  742. CeErpSukuraData.createInfo(entity.ctid, 6);
  743. }
  744. entity.MemoOpt = Convert.ToInt32(memoopt);
  745. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  746. }
  747. if (entity.OrderState < 5)
  748. {
  749. memo = memo.Replace("(", "(");
  750. memo = memo.Replace(")", ")");
  751. }
  752. if (entity.OrderState < 3)
  753. {
  754. entity.DispatchSort = 0;
  755. }
  756. entity.seller_memo = memo;
  757. entity.UpdateTime = DateTime.Now;
  758. entity.Update();
  759. ApiVo apiVo = new ApiVo();
  760. apiVo.orderNumber = entity.ctid;
  761. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  762. apiVo.orderRemarks = memo;
  763. apiVo.remarkSign = memoopt;
  764. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  765. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  766. returnSuccessMsg("保存成功!");
  767. return;
  768. }
  769. returnErrorMsg("找不到记录");
  770. }
  771. }
  772. public void ins_erp_checkorder()
  773. {
  774. if (UrlPostParmsCheck("ctid"))
  775. {
  776. string ctid = GetPostString("ctid");
  777. CeErpTradeCell entity = null;
  778. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  779. if (entity != null)
  780. {
  781. if (entity.OrderState < 6)
  782. {
  783. returnErrorMsg("下单完成后才可查货");
  784. return;
  785. }
  786. /*if (entity.OrderState > 6)
  787. {
  788. returnErrorMsg("订单已发货");
  789. return;
  790. }*/
  791. if (entity.FinishPlaceTime != null)
  792. {
  793. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  794. {
  795. returnErrorMsg("下单时间不足,无法查货");
  796. return;
  797. }
  798. }
  799. entity.MemoOpt = 3;
  800. entity.CheckOrderTime = DateTime.Now;
  801. entity.UpdateTime = DateTime.Now;
  802. entity.Update();
  803. CeErpSukuraData.createInfo(entity.ctid, 6);
  804. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  805. returnSuccessMsg("操作成功!");
  806. return;
  807. }
  808. returnErrorMsg("找不到记录");
  809. }
  810. }
  811. public void save_erp_othermemo()
  812. {
  813. if (UrlPostParmsCheck("ctid"))
  814. {
  815. string ctid = GetPostString("ctid");
  816. CeErpTradeCell entity = null;
  817. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  818. if (entity != null)
  819. {
  820. entity.OtherMemo = GetPostString("otherMemo");
  821. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  822. {
  823. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  824. StringBuilder sql = new StringBuilder();
  825. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  826. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  827. if (dt != null && dt.Rows.Count > 0)
  828. {
  829. foreach (DataRow dr in dt.Rows)
  830. {
  831. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  832. {
  833. //品类一直
  834. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  835. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  836. if (ceErpSampleCustomer == null)
  837. {
  838. ceErpSampleCustomer = new CeErpSampleCustomer();
  839. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  840. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  841. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  842. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  843. ceErpSampleCustomer.shopId = entity.ShopId;
  844. }
  845. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  846. ceErpSampleCustomer.lastTid = entity.tid;
  847. if (ceErpSampleCustomer.ID > 0)
  848. {
  849. ceErpSampleCustomer.Update();
  850. }
  851. else
  852. {
  853. ceErpSampleCustomer.Create();
  854. }
  855. }
  856. }
  857. }
  858. }
  859. //if (entity.IsOldCustomer == 1)
  860. //{
  861. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  862. //{
  863. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  864. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  865. //}
  866. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  867. //{
  868. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  869. // {
  870. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  871. // {
  872. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  873. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  874. // }
  875. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  876. // {
  877. // entity.OrderState = 2;
  878. // entity.DesignUserId = 0;
  879. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  880. // }
  881. // else
  882. // {
  883. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  884. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  885. // }
  886. // }
  887. //}
  888. //}
  889. entity.UpdateTime = DateTime.Now;
  890. entity.Update();
  891. returnSuccessMsg("保存成功!");
  892. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  893. return;
  894. }
  895. returnErrorMsg("找不到记录");
  896. }
  897. }
  898. public void save_erp_customermemo()
  899. {
  900. if (UrlPostParmsCheck("ctid"))
  901. {
  902. string ctid = GetPostString("ctid");
  903. CeErpTradeCell entity = null;
  904. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  905. if (entity != null)
  906. {
  907. entity.UpdateTime = DateTime.Now;
  908. entity.CustomerMemo = GetPostString("CustomerMemo");
  909. entity.Update();
  910. ApiVo apiVo = new ApiVo();
  911. apiVo.orderNumber = entity.ctid;
  912. apiVo.actionName = "followRemarks";
  913. apiVo.orderRemarks = entity.CustomerMemo;
  914. designHelper.API_WorkCore(apiVo);//followRemarks
  915. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  916. returnSuccessMsg("保存成功!");
  917. return;
  918. }
  919. returnErrorMsg("找不到记录");
  920. }
  921. }
  922. public void upd_erp_addmemotag()
  923. {
  924. if (UrlPostParmsCheck("ctid"))
  925. {
  926. ;
  927. string eid = GetPostString("ctid");
  928. string sfTagstr = GetPostString("memotag");
  929. CeErpTradeCell entity = null;
  930. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  931. if (entity != null)
  932. {
  933. ApiVo apiVo = new ApiVo();
  934. if (entity.OrderState == 0)
  935. {
  936. returnErrorMsg("请先领单");
  937. return;
  938. }
  939. //撤销顺丰
  940. if (sfTagstr == "撤销顺丰")
  941. {
  942. entity.IsSF = 0;
  943. string reMsg = "";
  944. string oldmemo = entity.seller_memo;
  945. if (entity.OrderState < 5)
  946. {
  947. oldmemo = oldmemo.Replace("顺丰到付", "");
  948. oldmemo = oldmemo.Replace("顺丰寄付", "");
  949. entity.seller_memo = oldmemo;
  950. }
  951. else
  952. {
  953. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  954. {
  955. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  956. }
  957. }
  958. entity.Update();
  959. apiVo.orderNumber = entity.ctid;
  960. apiVo.actionName = "orderRemarks";
  961. apiVo.orderRemarks = entity.seller_memo;
  962. apiVo.isSf = entity.IsSF.ToString();
  963. designHelper.API_WorkCore(apiVo);//orderRemarks
  964. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  965. returnSuccessMsg("撤销成功!" + reMsg);
  966. return;
  967. }
  968. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  969. {
  970. //string oldmemo = entity.seller_memo;
  971. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  972. string sfStr = GetPostString("memotag");
  973. string smemo = entity.seller_memo;
  974. int kindex = smemo.IndexOf(")");
  975. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  976. if (lastoneStr != "-")
  977. {
  978. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  979. }
  980. string prememo = smemo.Substring(0, kindex + 2);
  981. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  982. int lastkindex = lastmemo.IndexOf("(");
  983. string newlastmemo = "";
  984. if (lastkindex == 0)
  985. {
  986. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  987. newlastmemo = "(" + sfStr + "." + useLastmemo;
  988. }
  989. else
  990. {
  991. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  992. }
  993. entity.seller_memo = prememo + newlastmemo;
  994. }
  995. string sfTagMSg = "";
  996. if (sfTagstr == "顺丰寄付")
  997. {
  998. entity.IsSF = 1;
  999. sfTagMSg = "顺丰寄付";
  1000. }
  1001. else if (sfTagstr == "顺丰到付")
  1002. {
  1003. entity.IsSF = 2;
  1004. sfTagMSg = "顺丰到付";
  1005. }
  1006. entity.Update();
  1007. apiVo = new ApiVo();
  1008. apiVo.orderNumber = entity.ctid;
  1009. apiVo.actionName = "orderRemarks";
  1010. apiVo.orderRemarks = entity.seller_memo;
  1011. apiVo.isSf = entity.IsSF.ToString();
  1012. designHelper.API_WorkCore(apiVo);//orderRemarks
  1013. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1014. returnSuccessMsg("标记成功!");
  1015. return;
  1016. }
  1017. returnErrorMsg("找不到记录");
  1018. }
  1019. }
  1020. public void upd_erp_ordertag()
  1021. {
  1022. if (UrlPostParmsCheck("ctid"))
  1023. {
  1024. string eid = GetPostString("ctid");
  1025. CeErpTradeCell entity = null;
  1026. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1027. if (entity != null)
  1028. {
  1029. int tag = GetPostInt("wechattag");
  1030. //if(tag==4 && entity.IsSample == 2)
  1031. //{
  1032. // returnErrorMsg("补差价单不能标记微信单");
  1033. // return;
  1034. //}
  1035. entity.wechatTag = tag;
  1036. entity.Update();
  1037. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1038. if (tag == 1)
  1039. {
  1040. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1041. if (cash == null)
  1042. {
  1043. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1044. cash = new CeErpReturnCash();
  1045. cash.tid = entity.tid;
  1046. cash.seller_nick = main.seller_nick;
  1047. cash.payment = trade.payment;
  1048. cash.buyer_nick = main.buyer_nick;
  1049. cash.cashstate = 0;
  1050. cash.rtype = "微信返现";
  1051. cash.returnprice = 0;
  1052. cash.created = DateTime.Now;
  1053. cash.con = "订单标记微信单";
  1054. cash.img = "";
  1055. cash.applyuserid = CurrentUser.UserID;
  1056. cash.Create();
  1057. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1058. }
  1059. else
  1060. {
  1061. cash.cashstate = 0;
  1062. cash.Update();
  1063. }
  1064. CeErpSukuraData.createInfo(entity.ctid, 9);
  1065. }
  1066. else if (tag == 2)
  1067. {
  1068. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1069. if (cash == null)
  1070. {
  1071. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1072. cash = new CeErpReturnCash();
  1073. cash.tid = entity.tid;
  1074. cash.seller_nick = main.seller_nick;
  1075. cash.payment = trade.payment;
  1076. cash.buyer_nick = main.buyer_nick;
  1077. cash.cashstate = 0;
  1078. cash.rtype = "推购返现";
  1079. cash.returnprice = 5;
  1080. cash.created = DateTime.Now;
  1081. cash.con = "订单标记推购单";
  1082. cash.img = "";
  1083. cash.applyuserid = CurrentUser.UserID;
  1084. cash.Create();
  1085. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1086. }
  1087. else
  1088. {
  1089. cash.cashstate = 0;
  1090. cash.Update();
  1091. }
  1092. CeErpSukuraData.createInfo(entity.ctid, 9);
  1093. }
  1094. else if (tag == 3)
  1095. {
  1096. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1097. if (pers == null)
  1098. {
  1099. pers = new CeErpPersuade();
  1100. pers.ctid = entity.ctid;
  1101. pers.pstate = 0;
  1102. pers.created = DateTime.Now;
  1103. pers.applyuserid = CurrentUser.UserID;
  1104. pers.Create();
  1105. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1106. }
  1107. else
  1108. {
  1109. pers.pstate = 0;
  1110. pers.Update();
  1111. }
  1112. }
  1113. else if (tag == 4 || tag == 5)
  1114. {
  1115. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1116. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1117. if (pers == null)
  1118. {
  1119. pers = new CeErpStayGoods();
  1120. pers.t_id = entity.tid;
  1121. pers.status = "待审核";
  1122. pers.audit_type = 0;
  1123. if (tag == 4)
  1124. {
  1125. pers.stay_type = "微信推购";
  1126. }
  1127. else
  1128. {
  1129. pers.stay_type = "旺旺推购";
  1130. }
  1131. if (entity.IsXianHuo == 0)
  1132. {
  1133. pers.product_id = entity.ProductId;
  1134. }
  1135. pers.wangwang = main.buyer_nick;
  1136. pers.shop_name = main.seller_nick;
  1137. pers.creata_time = DateTime.Now;
  1138. pers.create_u_id = CurrentUser.UserID;
  1139. pers.create_u_name = CurrentUser.UserName;
  1140. pers.Create();
  1141. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1142. }
  1143. else
  1144. {
  1145. pers.audit_type = 0;
  1146. pers.Update();
  1147. }
  1148. CeErpSukuraData.createInfo(entity.ctid, 10);
  1149. }
  1150. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1151. returnSuccessMsg("标记成功!");
  1152. return;
  1153. }
  1154. returnErrorMsg("找不到记录");
  1155. }
  1156. }
  1157. public void upd_erp_ordertag_cancel()
  1158. {
  1159. if (UrlPostParmsCheck("ctid"))
  1160. {
  1161. string eid = GetPostString("ctid");
  1162. CeErpTradeCell entity = null;
  1163. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1164. if (entity != null)
  1165. {
  1166. entity.wechatTag = 0;
  1167. entity.Update();
  1168. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1169. if (pers != null)
  1170. {
  1171. pers.status = "取消推购";
  1172. pers.audit_type = 3;
  1173. pers.Update();
  1174. }
  1175. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1176. returnSuccessMsg("标记成功!");
  1177. return;
  1178. }
  1179. returnErrorMsg("找不到记录");
  1180. }
  1181. }
  1182. public void upd_erp_addweichattag()
  1183. {
  1184. if (UrlPostParmsCheck("ctid"))
  1185. {
  1186. ;
  1187. string eid = GetPostString("ctid");
  1188. CeErpTradeCell entity = null;
  1189. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1190. if (entity != null)
  1191. {
  1192. if (entity.IsAddWechat > 0)
  1193. {
  1194. returnErrorMsg("此单已经标记过了");
  1195. return;
  1196. }
  1197. 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);
  1198. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1199. if (dt.Rows.Count > 0)
  1200. {
  1201. entity.IsAddWechat = 2;
  1202. }
  1203. else
  1204. {
  1205. entity.IsAddWechat = 1;
  1206. }
  1207. entity.Update();
  1208. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1209. returnSuccessMsg("标记成功!");
  1210. return;
  1211. }
  1212. returnErrorMsg("找不到记录");
  1213. }
  1214. }
  1215. public void upd_erp_getmyorder()
  1216. {
  1217. if (UrlPostParmsCheck("ctid"))
  1218. {
  1219. ;
  1220. string eid = GetPostString("ctid");
  1221. CeErpTradeCell entity = null;
  1222. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1223. if (entity != null)
  1224. {
  1225. if (entity.ctid.IndexOf("C") != -1)
  1226. {
  1227. StringBuilder sql = new StringBuilder();
  1228. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1229. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1230. if (dt.Rows.Count > 0)
  1231. {
  1232. decimal total = 0;
  1233. foreach (DataRow dr in dt.Rows)
  1234. {
  1235. total += Convert.ToDecimal(dr["payment"]);
  1236. }
  1237. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1238. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1239. {
  1240. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1241. return;
  1242. }
  1243. }
  1244. }
  1245. if (entity.OrderState == -1)
  1246. {
  1247. returnErrorMsg("待审核订单无法领取!");
  1248. return;
  1249. }
  1250. entity.CustomerUserId = CurrentUser.UserID;
  1251. if (entity.OrderState < 2)
  1252. {
  1253. entity.OrderState = 2;
  1254. if (entity.ShopId != 0)
  1255. {
  1256. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1257. }
  1258. }
  1259. entity.UpdateTime = DateTime.Now;
  1260. entity.Update();
  1261. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1262. returnSuccessMsg("领单成功!");
  1263. return;
  1264. }
  1265. returnErrorMsg("找不到记录");
  1266. }
  1267. }
  1268. public void getmyorder_from_init()
  1269. {
  1270. if (UrlPostParmsCheck("ctid"))
  1271. {
  1272. string eid = GetPostString("ctid");
  1273. CeErpTradeCell entity = null;
  1274. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1275. if (entity != null)
  1276. {
  1277. string sellerMemo = GetPostString("sellerMemo");
  1278. if (sellerMemo.Length > 0)
  1279. {
  1280. entity.seller_memo = sellerMemo;
  1281. }
  1282. string oterhMemo = GetPostString("otherMemo");
  1283. if (oterhMemo.Length > 0)
  1284. {
  1285. entity.OtherMemo = oterhMemo;
  1286. }
  1287. int urg = GetPostInt("urgency");
  1288. entity.IsUrgency = (urg == 1 ? true : false);
  1289. int wechat = GetPostInt("wechat");
  1290. int command = GetPostInt("command");
  1291. if (wechat == 1)
  1292. {
  1293. entity.wechatTag = 1;
  1294. }
  1295. if (command == 1)
  1296. {
  1297. entity.wechatTag = 2;
  1298. }
  1299. string pPro = GetPostString("pprofession");
  1300. if (pPro.Length > 0)
  1301. {
  1302. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1303. string spro = GetPostString("profession");
  1304. if (spro.Length > 0)
  1305. {
  1306. entity.ProfessionId = Convert.ToInt32(spro);
  1307. }
  1308. }
  1309. string proId = GetPostString("productId");
  1310. if (proId.Length > 0)
  1311. {
  1312. entity.ProductId = Convert.ToInt32(proId);
  1313. }
  1314. entity.Material = GetPostString("material");
  1315. entity.Craft = GetPostString("craft");
  1316. entity.CustomerUserId = CurrentUser.UserID;
  1317. if (entity.OrderState < 2)
  1318. {
  1319. entity.OrderState = 2;
  1320. if (entity.ShopId != 0)
  1321. {
  1322. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1323. }
  1324. }
  1325. entity.Update();
  1326. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1327. returnSuccessMsg("领单成功!");
  1328. return;
  1329. }
  1330. returnErrorMsg("找不到记录");
  1331. }
  1332. }
  1333. public void upd_erp_setrelationorder()
  1334. {
  1335. if (UrlPostParmsCheck("ctid"))
  1336. {
  1337. ;
  1338. string eid = GetPostString("ctid");
  1339. string ftid = GetPostString("ftid");
  1340. CeErpTradeCell entity = null;
  1341. CeErpTradeCell fentity = null;
  1342. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1343. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1344. if (fentity == null)
  1345. {
  1346. returnErrorMsg("找不到关联的主订单");
  1347. return;
  1348. }
  1349. if (entity != null)
  1350. {
  1351. if (entity.OrderState >= 5)
  1352. {
  1353. returnErrorMsg("本单已经设计完成无法关联");
  1354. return;
  1355. }
  1356. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1357. {
  1358. returnErrorMsg("线下单续审核后才能关联!");
  1359. return;
  1360. }
  1361. entity.ptid = ftid;
  1362. entity.OrderState = fentity.OrderState;
  1363. //entity.status = fentity.status;
  1364. entity.CustomerUserId = fentity.CustomerUserId;
  1365. entity.DesignUserId = fentity.DesignUserId;
  1366. entity.seller_memo = "补差价单:" + ftid;
  1367. entity.IsSample = 2;
  1368. entity.Update();
  1369. ApiVo apiVo = new ApiVo();
  1370. apiVo.orderNumber = ftid;
  1371. apiVo.payment = entity.payment;
  1372. apiVo.actionName = "repairDesign";
  1373. designHelper.API_WorkCore(apiVo);//repairDesign
  1374. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1375. returnSuccessMsg("关联成功!");
  1376. return;
  1377. }
  1378. else
  1379. returnErrorMsg("找不到记录");
  1380. }
  1381. }
  1382. public void download_erp_neworder()
  1383. {
  1384. string seller = GetPostString("seller_nick");
  1385. string tid = GetPostString("tid");
  1386. if (seller.Length <= 0 || tid.Length <= 0)
  1387. {
  1388. returnErrorMsg("数据错误");
  1389. }
  1390. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1391. //{
  1392. // returnErrorMsg("找不到店铺Sessionkey");
  1393. //}
  1394. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1395. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1396. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1397. if (res.IndexOf("refOid") == -1)
  1398. {
  1399. returnErrorMsg("下载订单数据失败");
  1400. return;
  1401. }
  1402. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1403. returnSuccessMsg("下载完成");
  1404. //tmcHelper.createNewOrder(res);
  1405. //CeErpTrade entr = null;
  1406. //entr = CeErpTrade.Get(tid);
  1407. //if (entr != null)
  1408. //{
  1409. // returnSuccess("下载成功");
  1410. // //下载成功之后,Cell表生成对应的订单;
  1411. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1412. //}
  1413. //else
  1414. //{
  1415. // returnErrorMsg("下载失败或者创建订单失败");
  1416. //}
  1417. }
  1418. public void set_erp_atersale()
  1419. {
  1420. if (UrlPostParmsCheck("ctid"))
  1421. {
  1422. string eid = GetPostString("ctid");
  1423. string reason = GetPostString("AfterSaleReason");
  1424. CeErpTradeCell entity = null;
  1425. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1426. if (entity != null)
  1427. {
  1428. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1429. {
  1430. returnErrorMsg("此订单已经在售后");
  1431. return;
  1432. }
  1433. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1434. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1435. entity.AfterSaleTime = DateTime.Now;
  1436. entity.Update();
  1437. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1438. returnSuccessMsg("转售后成功!");
  1439. return;
  1440. }
  1441. returnErrorMsg("找不到记录");
  1442. }
  1443. }
  1444. public void set_erp_withdraw()
  1445. {
  1446. if (UrlPostParmsCheck("ctid"))
  1447. {
  1448. try
  1449. {
  1450. string eid = GetPostString("ctid");//商品id
  1451. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1452. CeWithdraw ceWithdrawSelect = null;
  1453. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1454. if (ceWithdrawSelect != null)
  1455. {
  1456. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1457. {
  1458. ceWithdrawSelect.status = -1;
  1459. ceWithdrawSelect.Update();
  1460. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1461. returnSuccessMsg("重新发起审核成功");
  1462. return;
  1463. }
  1464. else
  1465. {
  1466. returnSuccessMsg("请勿重复申请!");
  1467. return;
  1468. }
  1469. }
  1470. else
  1471. {
  1472. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1473. if (string.IsNullOrEmpty(CustomerUserId))
  1474. {
  1475. CustomerUserId = "-1";
  1476. }
  1477. int Userid = CurrentUser.UserID;//用户id
  1478. CeWithdraw ceWithdraw = new CeWithdraw();
  1479. ceWithdraw.tid = eid;
  1480. ceWithdraw.userid = Userid;
  1481. ceWithdraw.providerid = CustomerUserId;
  1482. ceWithdraw.status = 3;
  1483. ceWithdraw.creationtime = DateTime.Now;
  1484. ceWithdraw.Create();
  1485. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1486. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1487. return;
  1488. }
  1489. }
  1490. catch
  1491. {
  1492. returnErrorMsg("申请撤回订单失败");
  1493. return;
  1494. }
  1495. }
  1496. }
  1497. public void ins_erp_billinfo()
  1498. {
  1499. if (UrlPostParmsCheck("ctid"))
  1500. {
  1501. string eid = GetPostString("ctid");
  1502. CeErpTradeCell entity = null;
  1503. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1504. if (entity != null)
  1505. {
  1506. CeErpBill bill = CeErpBill.GetByTid(eid);
  1507. bool isHave = false;
  1508. if (bill != null)
  1509. {
  1510. isHave = true;
  1511. if (bill.state != 4)
  1512. {
  1513. returnErrorMsg("此单已经申请过发票了");
  1514. return;
  1515. }
  1516. }
  1517. if (entity.IsNeedBill == 0)
  1518. {
  1519. entity.IsNeedBill = 1;
  1520. }
  1521. entity.Update();
  1522. string errjson = "";
  1523. try
  1524. {
  1525. CeErpBill bill_entity = new CeErpBill();
  1526. bill_entity.tid = entity.tid;
  1527. bill_entity.title = GetPostString("title");
  1528. string taxstr = GetPostString("tax");
  1529. taxstr = taxstr.Replace(" ", "");
  1530. bill_entity.tax = taxstr;
  1531. bill_entity.bank = GetPostString("bank");
  1532. string bankacstr = GetPostString("bankac");
  1533. bankacstr = bankacstr.Replace(" ", "");
  1534. bill_entity.bankac = bankacstr;
  1535. bill_entity.address = GetPostString("address");
  1536. bill_entity.phone = GetPostString("phone");
  1537. bill_entity.price = GetPostString("price");
  1538. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1539. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1540. {
  1541. billCount += 1;
  1542. }
  1543. string prebill = "ltb";
  1544. for (int idx = 1; idx <= billCount; idx++)
  1545. {
  1546. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1547. string billoid = prebill + idx + dtstr;
  1548. bill_entity.billOrderId += billoid;
  1549. if (idx < billCount)
  1550. {
  1551. bill_entity.billOrderId += ",";
  1552. }
  1553. }
  1554. bill_entity.productId = GetPostInt("ProductName");
  1555. bill_entity.num = GetPostInt("num");
  1556. bill_entity.unit = GetPostString("unit");
  1557. bill_entity.type = GetPostString("type");
  1558. bill_entity.sendType = GetPostString("SendType");
  1559. bill_entity.email = GetPostString("email");
  1560. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1561. bill_entity.shopName = GetPostString("ShopName");
  1562. bill_entity.applymemo = GetPostString("applyMemo");
  1563. bill_entity.createTime = DateTime.Now;
  1564. bill_entity.state = 0;
  1565. bill_entity.userId = CurrentUser.UserID;
  1566. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1567. bill_entity.Create();
  1568. }
  1569. catch (Exception ex)
  1570. {
  1571. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1572. returnErrorMsg("创建发票出错!");
  1573. return;
  1574. }
  1575. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1576. returnSuccessMsg("发票申请成功!");
  1577. return;
  1578. }
  1579. returnErrorMsg("找不到记录");
  1580. }
  1581. }
  1582. public void ins_erp_neworder()
  1583. {
  1584. if (UrlPostParmsCheck("receiver_name"))
  1585. {
  1586. CeErpTrade entity = new CeErpTrade();
  1587. string plat_form = GetPostString("platform");
  1588. string preStr = "N_";
  1589. if (plat_form == "拼多多")
  1590. {
  1591. preStr = "P_";
  1592. }
  1593. else if (plat_form == "阿里巴巴")
  1594. {
  1595. preStr = "A_";
  1596. }
  1597. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1598. entity.seller_nick = GetPostString("seller_nick");
  1599. entity.buyer_nick = GetPostString("buyer_nick");
  1600. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1601. entity.total_fee = entity.payment;
  1602. entity.pay_time = DateTime.Now;
  1603. entity.status = "NOT_SHIPPED";
  1604. entity.receiver_name = GetPostString("receiver_name");
  1605. entity.receiver_mobile = GetPostString("receiver_mobile");
  1606. entity.receiver_state = GetPostString("receiver_state");
  1607. entity.receiver_city = GetPostString("receiver_city");
  1608. entity.receiver_district = GetPostString("receiver_district");
  1609. entity.receiver_address = GetPostString("receiver_address");
  1610. if (entity.receiver_state == "" || entity.receiver_city == "")
  1611. {
  1612. returnErrorMsg("收件地址不能为空");
  1613. return;
  1614. }
  1615. int shopId = 0;
  1616. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1617. if (nShop != null)
  1618. {
  1619. shopId = nShop.ID;
  1620. }
  1621. if (shopId != 34 && entity.payment == 0)
  1622. {
  1623. returnErrorMsg("公司自用的单金额才能为0");
  1624. return;
  1625. }
  1626. entity.Create();
  1627. CeErpTradeCell entitycell = new CeErpTradeCell();
  1628. entitycell.ctid = entity.tid;
  1629. entitycell.tid = entity.tid;
  1630. entitycell.ShopId = shopId;
  1631. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1632. entitycell.OrderState = 0;
  1633. entitycell.pay_time = entity.pay_time;
  1634. entitycell.IsOffLineOrder = 1;
  1635. entitycell.Create();
  1636. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1637. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1638. return;
  1639. }
  1640. }
  1641. public void ins_erp_neworder2()
  1642. {
  1643. if (UrlPostParmsCheck("receiver_name"))
  1644. {
  1645. //string plat_form = GetPostString("platform");
  1646. string preStr = "X_";
  1647. string memo = GetPostString("memo");
  1648. string productId = GetPostString("productId");
  1649. string primg = GetPostString("proofimg");
  1650. string sellerNick = GetPostString("seller_nick");
  1651. string addFrom = GetPostString("addfrom");
  1652. if (addFrom == "1")
  1653. {
  1654. preStr = "N_";
  1655. }
  1656. int shopId = 0;
  1657. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1658. if (nShop != null)
  1659. {
  1660. shopId = nShop.ID;
  1661. }
  1662. else
  1663. {
  1664. returnErrorMsg("找不到对应店铺");
  1665. return;
  1666. }
  1667. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1668. {
  1669. returnErrorMsg("必须上传付款凭证");
  1670. return;
  1671. }
  1672. CeErpTrade entity = new CeErpTrade();
  1673. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1674. entity.seller_nick = sellerNick;
  1675. entity.buyer_nick = GetPostString("buyer_nick");
  1676. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1677. entity.total_fee = entity.payment;
  1678. entity.pay_time = DateTime.Now;
  1679. entity.status = "NOT_SHIPPED";
  1680. entity.receiver_name = GetPostString("receiver_name");
  1681. entity.receiver_mobile = GetPostString("receiver_mobile");
  1682. entity.receiver_state = GetPostString("receiver_state");
  1683. entity.receiver_city = GetPostString("receiver_city");
  1684. entity.receiver_district = GetPostString("receiver_district");
  1685. entity.receiver_address = GetPostString("receiver_address");
  1686. entity.seller_memo = memo;
  1687. entity.orderFrom = 20;
  1688. entity.orderType = 15;
  1689. if (entity.receiver_state == "" || entity.receiver_city == "")
  1690. {
  1691. returnErrorMsg("收件地址不能为空");
  1692. return;
  1693. }
  1694. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1695. {
  1696. returnErrorMsg("公司自用的单金额才能为0");
  1697. return;
  1698. }
  1699. entity.Create();
  1700. string toWhere = GetPostString("towhere");
  1701. CeErpTradeCell entitycell = new CeErpTradeCell();
  1702. entitycell.ctid = entity.tid;
  1703. //唯一标识
  1704. entitycell.OrderSn = entity.tid;
  1705. string orderSn = dataHelper.getSaleOrderSn();
  1706. if (orderSn != "")
  1707. {
  1708. entitycell.OrderSn = orderSn;
  1709. }
  1710. entitycell.tid = entity.tid;
  1711. //if (preStr == "X_")
  1712. //{
  1713. entitycell.IsOffLineOrder = 1;
  1714. //}
  1715. entitycell.CustomerUserId = CurrentUser.UserID;
  1716. entitycell.PayProofImg = primg;
  1717. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1718. entitycell.ProductId = Convert.ToInt32(productId);
  1719. entitycell.ShopId = shopId;
  1720. entitycell.UpdateTime = DateTime.Now;
  1721. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1722. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1723. {
  1724. entitycell.IsXianHuo = 1;
  1725. }
  1726. entitycell.pay_time = entity.pay_time;
  1727. if (toWhere == "1")
  1728. {
  1729. entitycell.OrderState = 2;
  1730. }
  1731. else
  1732. {
  1733. entitycell.OrderState = 6;
  1734. entitycell.FinishPlaceTime = entitycell.pay_time;
  1735. }
  1736. if (shopId == 94)
  1737. {
  1738. entitycell.OrderState = 4;
  1739. entitycell.WaitDesignTime = entitycell.pay_time;
  1740. entitycell.StartDesignTime = entitycell.pay_time;
  1741. entitycell.DesignUserId = 218;
  1742. }
  1743. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1744. {
  1745. entitycell.OrderState = -1;//修改12-5
  1746. CeWithdraw ceWithdraw = new CeWithdraw();
  1747. ceWithdraw.tid = entity.tid;
  1748. ceWithdraw.providerid = "-1";
  1749. ceWithdraw.status = -1;
  1750. ceWithdraw.creationtime = DateTime.Now;
  1751. ceWithdraw.userid = 1337;
  1752. ceWithdraw.Create();
  1753. }
  1754. entitycell.Create();
  1755. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1756. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1757. {
  1758. addPlaceRegist(entitycell, CurrentUser.UserID);
  1759. }
  1760. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1761. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1762. return;
  1763. }
  1764. }
  1765. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1766. {
  1767. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1768. entity.PlactTime = tradecell.pay_time;
  1769. entity.AddUserId = userid;
  1770. entity.FileName = tradecell.seller_memo;
  1771. entity.Supplier = 24;
  1772. entity.CreateTime = DateTime.Now;
  1773. entity.Did = tradecell.ctid;
  1774. entity.tid = tradecell.tid;
  1775. entity.splitTag = tradecell.SplitTag;
  1776. entity.CurState = "未完成";
  1777. entity.Create();
  1778. }
  1779. public void get_erp_offlinelist()
  1780. {
  1781. DataStruct dStruct = GetPostStruct();
  1782. List<string> lw = new List<string>();
  1783. string tid = GetPostString("ctid");
  1784. string date1 = GetPostString("date1");
  1785. string date2 = GetPostString("date2");
  1786. if (tid.Length > 0 || date1.Length > 0)
  1787. {
  1788. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1789. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1790. if (dw.Length > 0) lw.Add(dw);
  1791. }
  1792. else
  1793. {
  1794. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1795. }
  1796. string shopname = GetPostString("shopname");
  1797. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1798. string buyernick = GetPostString("buyer_nick");
  1799. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1800. string customer = GetPostString("customer");
  1801. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1802. string design = GetPostString("design");
  1803. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1804. string orderState = GetPostString("orderState");
  1805. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1806. string address = GetPostString("address");
  1807. 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));
  1808. string sellermemo = GetPostString("seller_memo");
  1809. if (sellermemo.Length > 0)
  1810. {
  1811. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1812. }
  1813. string price1 = GetPostString("price1");
  1814. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1815. string price2 = GetPostString("price2");
  1816. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1817. //if (PKey != "admin")
  1818. //{
  1819. // string usershop = CurrentUser.User.pemShop;
  1820. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1821. //}
  1822. //if (ex_psize > 0)
  1823. //{
  1824. dStruct.Order = "pay_time desc";
  1825. //}
  1826. //else
  1827. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1828. lw.Add(string.Format("IsOffLineOrder=1"));
  1829. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1830. DataTable dt = null;
  1831. dt = WebCache.GetData("view_erptradecell", dStruct);
  1832. writeGridDataTableJson(dStruct.TotalCount, dt);
  1833. }
  1834. public void get_erp_returncashrecord()
  1835. {
  1836. DataStruct dStruct = GetPostStruct();
  1837. List<string> lw = new List<string>();
  1838. string tid = GetPostString("ctid");
  1839. if (tid.Length > 0)
  1840. {
  1841. lw.Add(string.Format("tid like '%{0}%'", tid));
  1842. dStruct.Order = "id desc";
  1843. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1844. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1845. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1846. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1847. return;
  1848. }
  1849. returnErrorMsg("id数据错误!");
  1850. }
  1851. public void ins_erp_returncashrecord()
  1852. {
  1853. if (UrlPostParmsCheck("tid"))
  1854. {
  1855. string tid = GetPostString("tid");
  1856. string retype = GetPostString("type");
  1857. StringBuilder sql = new StringBuilder();
  1858. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1859. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1860. if (dt.Rows.Count > 0)
  1861. {
  1862. returnErrorMsg("相同返现类型记录已存在");
  1863. return;
  1864. }
  1865. CeErpReturnCash entity = new CeErpReturnCash();
  1866. entity.tid = tid;
  1867. entity.seller_nick = GetPostString("seller_nick");
  1868. string pment = GetPostString("payment");
  1869. if (pment.Length > 0)
  1870. {
  1871. entity.payment = Convert.ToDouble(pment);
  1872. }
  1873. entity.buyer_nick = GetPostString("buyer_nick");
  1874. entity.cashstate = 0;
  1875. entity.rtype = retype;
  1876. string rPrice = GetPostString("returnprice");
  1877. if (rPrice.Length > 0)
  1878. {
  1879. entity.returnprice = Convert.ToDouble(rPrice);
  1880. }
  1881. entity.created = DateTime.Now;
  1882. entity.con = GetPostString("con");
  1883. entity.img = GetPostString("img");
  1884. entity.applyuserid = CurrentUser.UserID;
  1885. entity.Create();
  1886. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1887. returnSuccessMsg("操作成功!");
  1888. return;
  1889. }
  1890. }
  1891. public void set_erp_predelivery()
  1892. {
  1893. if (UrlPostParmsCheck("ctid"))
  1894. {
  1895. string eid = GetPostString("ctid");
  1896. CeErpTradeCell entity = null;
  1897. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1898. if (entity != null)
  1899. {
  1900. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1901. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1902. //{
  1903. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1904. // return;
  1905. //}
  1906. entity.IsPreDelivery = 1;
  1907. entity.Update();
  1908. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1909. returnSuccessMsg("预发货成功!");
  1910. return;
  1911. //string shop = GetPostString("seller_nick");
  1912. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1913. //string comName = GetPostString("comName");
  1914. //string comCode = GetPostString("comCode");
  1915. //string outSid = GetPostString("outSid");//运单号
  1916. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1917. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1918. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1919. //string apires = "";
  1920. //if (deliveryType == "虚拟发货")
  1921. //{
  1922. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1923. //}
  1924. //else
  1925. //{
  1926. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1927. //}
  1928. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1929. ////{
  1930. //if (apires.IndexOf("发货成功") != -1)
  1931. //{
  1932. // if (deliveryType != "虚拟发货")
  1933. // {
  1934. // //还要插入快递信息到 快递信息表
  1935. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1936. // exinfo.tid = eid;
  1937. // exinfo.out_sid = outSid;
  1938. // exinfo.company_code = comCode;
  1939. // exinfo.company_name = comName;
  1940. // exinfo.delivery_memo = deliveryMemo;
  1941. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1942. // exinfo.deliveryType = deliveryType;
  1943. // exinfo.Create();
  1944. // }
  1945. // returnSuccessMsg("发货成功!");
  1946. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1947. //}
  1948. //else
  1949. //{
  1950. // returnErrorMsg("淘宝发货失败!!");
  1951. //}
  1952. //return;
  1953. }
  1954. returnErrorMsg("找不到订单记录");
  1955. }
  1956. }
  1957. public void get_erp_unusuallist()
  1958. {
  1959. DataStruct dStruct = GetPostStruct();
  1960. List<string> lw = new List<string>();
  1961. string tid = GetPostString("ctid");
  1962. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1963. string shopname = GetPostString("shopname");
  1964. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1965. string buyernick = GetPostString("buyer_nick");
  1966. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1967. string ResponsibleMan = GetPostString("responsible");
  1968. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1969. string date1 = GetPostString("date1");
  1970. string date2 = GetPostString("date2");
  1971. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1972. if (dw.Length > 0) lw.Add(dw);
  1973. string price1 = GetPostString("price1");
  1974. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1975. string price2 = GetPostString("price2");
  1976. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1977. string orderState = GetPostString("orderState");
  1978. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1979. string sellermemo = GetPostString("seller_memo");
  1980. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1981. lw.Add(string.Format("UnusualTag > 0"));
  1982. lw.Add(string.Format("IsRefund<={0}", 1));
  1983. dStruct.Order = "pay_time desc";
  1984. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1985. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1986. writeGridDataTableJson(dStruct.TotalCount, dt);
  1987. }
  1988. public void set_erp_unusualtonomal()
  1989. {
  1990. if (UrlPostParmsCheck("ctid"))
  1991. {
  1992. string eid = GetPostString("ctid");
  1993. CeErpTradeCell entity = null;
  1994. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1995. if (entity != null)
  1996. {
  1997. entity.UnusualTag = -1;
  1998. entity.Update();
  1999. returnSuccessMsg("忽略成功!");
  2000. return;
  2001. }
  2002. returnErrorMsg("找不到记录");
  2003. }
  2004. }
  2005. public void ins_erp_unusualreason()
  2006. {
  2007. if (UrlPostParmsCheck("ctid"))
  2008. {
  2009. string eid = GetPostString("ctid");
  2010. CeErpTradeCell entity = null;
  2011. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2012. if (entity != null)
  2013. {
  2014. entity.MemoOpt = 4;
  2015. entity.UnusualCon = GetPostString("con");
  2016. entity.Update();
  2017. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2018. if (trade != null)
  2019. {
  2020. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2021. }
  2022. //查货是否超时
  2023. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2024. if (ceErpTradeCellExtend == null)
  2025. {
  2026. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2027. ceErpTradeCellExtend.ctid = entity.ctid;
  2028. }
  2029. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2030. {
  2031. ceErpTradeCellExtend.CheckOut += 1;
  2032. }
  2033. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2034. if (ceErpTradeCellExtend.ID > 0)
  2035. {
  2036. ceErpTradeCellExtend.Update();
  2037. }
  2038. else
  2039. {
  2040. ceErpTradeCellExtend.Create();
  2041. }
  2042. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2043. returnSuccessMsg("操作成功!");
  2044. return;
  2045. }
  2046. returnErrorMsg("找不到记录");
  2047. }
  2048. }
  2049. public void upd_erp_sampleorder()
  2050. {
  2051. if (UrlPostParmsCheck("ctid"))
  2052. {
  2053. string eid = GetPostString("ctid");
  2054. string[] eArr = eid.Split(',');
  2055. if (eArr.Length > 1)
  2056. {
  2057. List<string> eLst = new List<string>();
  2058. for (int i = 0; i < eArr.Length; i++)
  2059. {
  2060. eLst.Add("'" + eArr[i] + "'");
  2061. }
  2062. eid = string.Join(",", eLst.ToArray());
  2063. }
  2064. else
  2065. {
  2066. eid = "'" + eid + "'";
  2067. }
  2068. StringBuilder sql = new StringBuilder();
  2069. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2070. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2071. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2072. if (dt.Rows.Count > 0)
  2073. {
  2074. string errmsg = "";
  2075. foreach (DataRow dr in dt.Rows)
  2076. {
  2077. StringBuilder sqlsb = new StringBuilder();
  2078. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2079. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2080. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2081. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2082. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2083. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2084. {
  2085. continue;
  2086. }
  2087. else
  2088. {
  2089. string emsg = commonHelper.KeepChinese(apires);
  2090. errmsg += emsg;
  2091. }
  2092. }
  2093. if (errmsg.Length > 0)
  2094. {
  2095. returnErrorMsg(errmsg);
  2096. return;
  2097. }
  2098. returnSuccessMsg("操作成功");
  2099. return;
  2100. }
  2101. returnErrorMsg("找不到记录");
  2102. }
  2103. }
  2104. public void upd_erp_transcustomer()
  2105. {
  2106. if (UrlPostParmsCheck("ctid"))
  2107. {
  2108. string eid = GetPostString("ctid");
  2109. int userid = GetPostInt("CustomerUserId");
  2110. CeErpTradeCell entity = null;
  2111. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2112. if (entity != null)
  2113. {
  2114. //string[] mlist = entity.seller_memo.Split('-');
  2115. //string sql = "select * from view_erpuser where id=" + userid;
  2116. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2117. //if (dt != null && dt.Rows.Count > 0)
  2118. //{
  2119. // string nmemo = "";
  2120. // for(int i = 0; i < mlist.Length - 1; i++)
  2121. // {
  2122. // nmemo += mlist[i];
  2123. // nmemo += "-";
  2124. // }
  2125. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2126. // entity.seller_memo = nmemo;
  2127. //}
  2128. entity.CustomerUserId = userid;
  2129. entity.Update();
  2130. returnSuccessMsg("操作成功!");
  2131. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2132. return;
  2133. }
  2134. returnErrorMsg("找不到记录");
  2135. }
  2136. }
  2137. public void upd_erp_transdesigner()
  2138. {
  2139. if (UrlPostParmsCheck("ctid"))
  2140. {
  2141. string eids = GetPostString("ctid");
  2142. string[] ctidList = eids.Split(',');
  2143. int userid = GetPostInt("DesignUserId");
  2144. foreach (string ctid in ctidList)
  2145. {
  2146. CeErpTradeCell entity = null;
  2147. CeErpDesignerBill entitys = null;
  2148. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2149. entitys = CeErpDesignerBill.GetByTid(ctid);
  2150. if (entity != null)
  2151. {
  2152. if (entity.OrderState > 4)
  2153. {
  2154. continue;
  2155. }
  2156. //存在退款不能流转
  2157. if (entity.IsRefund > 0)
  2158. {
  2159. continue;
  2160. }
  2161. entity.DesignUserId = userid;
  2162. entity.WaitDesignTime = DateTime.Now;
  2163. entity.Update();
  2164. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2165. }
  2166. }
  2167. returnSuccessMsg("操作成功!");
  2168. }
  2169. }
  2170. public void upd_erp_distributedesigner()
  2171. {
  2172. if (UrlPostParmsCheck("ctid"))
  2173. {
  2174. string eid = GetPostString("ctid");
  2175. int userid = GetPostInt("DesignUserId");
  2176. string[] idlist = eid.Split(',');
  2177. if (idlist.Length <= 0)
  2178. {
  2179. returnErrorMsg("订单不能为空");
  2180. return;
  2181. }
  2182. foreach (string ctid in idlist)
  2183. {
  2184. CeErpTradeCell entity = null;
  2185. CeErpDesignerBill entitys = null;
  2186. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2187. else continue;
  2188. if (entity != null)
  2189. {
  2190. if (userid == 2125 || userid == 3542)
  2191. { }
  2192. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2193. {
  2194. returnErrorMsg("金额错误的订单无法指派");
  2195. return;
  2196. }
  2197. if (entity.OrderState >= 5)
  2198. {
  2199. returnErrorMsg("已经设计完成无法指派");
  2200. return;
  2201. }
  2202. if (entity.OrderState == -1)
  2203. {
  2204. returnErrorMsg("审核中的订单无法指派");
  2205. return;
  2206. }
  2207. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2208. {
  2209. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2210. return;
  2211. }
  2212. //157赖橙帆 159林晨 73 静之颖
  2213. 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)
  2214. {
  2215. returnErrorMsg("指派设计共创无法再次指派!");
  2216. return;
  2217. }
  2218. entity.OrderState = 3;
  2219. if (entity.SupplierId == 0)
  2220. {
  2221. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2222. entity.SupplierId = suid;
  2223. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2224. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2225. }
  2226. if (userid == 2125 && entity.seller_memo != "")
  2227. {
  2228. apiDesign.API_GetPrintData_CreateOrder(entity);
  2229. }
  2230. if (userid == 3542 && entity.seller_memo != "")
  2231. {
  2232. string userPost = CurrentUser.UserPost.Post.Code;
  2233. if (CurrentUser.UserID == 73)
  2234. {
  2235. userPost = "SysAdmin";
  2236. }
  2237. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2238. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2239. if (response.msg != "设计共创:成功")
  2240. {
  2241. returnErrorMsg(response.msg);
  2242. return;
  2243. }
  2244. entity.DispatchSort = 2;
  2245. }
  2246. else
  2247. {
  2248. if (entity.DispatchSort == 2)
  2249. {
  2250. ApiVo apiVo = new ApiVo();
  2251. apiVo.actionName = "closeDesign";
  2252. apiVo.orderNumber = entity.ctid;
  2253. designHelper.API_WorkCore(apiVo);//closeDesign
  2254. }
  2255. entity.DispatchSort = 0;
  2256. }
  2257. entity.DesignUserId = userid;
  2258. entity.WaitDesignTime = DateTime.Now;
  2259. entity.UpdateTime = DateTime.Now;
  2260. entity.Update();
  2261. string name = commonHelper.getUserNameById(userid);
  2262. commonHelper.UpdateRelationOrder(entity.ctid);
  2263. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2264. }
  2265. }
  2266. returnSuccessMsg("操作成功!");
  2267. return;
  2268. }
  2269. }
  2270. public string getTidByCtid(string ctid)
  2271. {
  2272. string tid = "";
  2273. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2274. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2275. if (dataTable != null && dataTable.Rows.Count > 0)
  2276. {
  2277. tid = dataTable.Rows[0]["tid"].ToString();
  2278. }
  2279. return tid;
  2280. }
  2281. public List<string> getTidByCtidMore(string ctid)
  2282. {
  2283. 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);
  2284. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2285. List<string> list = new List<string>();
  2286. if (dataTable != null && dataTable.Rows.Count > 0)
  2287. {
  2288. foreach (DataRow item in dataTable.Rows)
  2289. {
  2290. list.Add("'" + item["tid"].ToString() + "'");
  2291. }
  2292. }
  2293. return list;
  2294. }
  2295. public List<string> getTidByCtidLike(string ctid)
  2296. {
  2297. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2298. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2299. List<string> list = new List<string>();
  2300. if (dataTable != null && dataTable.Rows.Count > 0)
  2301. {
  2302. foreach (DataRow item in dataTable.Rows)
  2303. {
  2304. list.Add("'" + item["tid"].ToString() + "'");
  2305. }
  2306. }
  2307. return list;
  2308. }
  2309. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2310. {
  2311. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2312. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2313. List<string> list = new List<string>();
  2314. if (dataTable != null && dataTable.Rows.Count > 0)
  2315. {
  2316. foreach (DataRow item in dataTable.Rows)
  2317. {
  2318. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2319. {
  2320. continue;
  2321. }
  2322. list.Add("'" + item["receiverId"].ToString() + "'");
  2323. }
  2324. }
  2325. return list;
  2326. }
  2327. public void get_erp_myorderlist()
  2328. {
  2329. DataStruct dStruct = GetPostStruct();
  2330. List<string> lw = new List<string>();
  2331. string tid = GetPostString("ctid");
  2332. if (tid.Length > 0)
  2333. {
  2334. string select_tid = getTidByCtid(tid);
  2335. lw.Add(string.Format("tid='{0}'", select_tid));
  2336. }
  2337. else
  2338. {
  2339. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2340. }
  2341. //12-1 修改
  2342. string urgent = GetPostString("urgent");
  2343. string back = GetPostString("back");
  2344. string offlineSearch = GetPostString("offlineSearch");
  2345. if (!string.IsNullOrWhiteSpace(urgent))
  2346. {
  2347. if (urgent.Equals("true"))
  2348. {
  2349. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2350. }
  2351. }
  2352. if (!string.IsNullOrWhiteSpace(back))
  2353. {
  2354. if (back.Equals("true"))
  2355. {
  2356. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2357. }
  2358. }
  2359. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2360. {
  2361. if (offlineSearch.Equals("true"))
  2362. {
  2363. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2364. }
  2365. }
  2366. //end
  2367. string shopname = GetPostString("shopname");
  2368. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2369. string buyernick = GetPostString("buyer_nick");
  2370. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2371. string design = GetPostString("design");
  2372. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2373. string orderState = GetPostString("orderState");
  2374. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2375. string sellermemo = GetPostString("seller_memo");
  2376. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2377. string date1 = GetPostString("date1");
  2378. string date2 = GetPostString("date2");
  2379. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2380. if (dw.Length > 0) lw.Add(dw);
  2381. string price1 = GetPostString("price1");
  2382. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2383. string price2 = GetPostString("price2");
  2384. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2385. string urgency = GetPostString("urgency");
  2386. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2387. string after = GetPostString("after");
  2388. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2389. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2390. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2391. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2392. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2393. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2394. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2395. if (dt != null && dt.Rows.Count > 0)
  2396. {
  2397. foreach (DataRow dr in dt.Rows)
  2398. {
  2399. try
  2400. {
  2401. // 对象操作
  2402. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2403. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2404. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2405. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2406. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2407. if (dStruct.PageSize != 100000)
  2408. {
  2409. if (dr["DispatchSort"].ToString() == "2")
  2410. {
  2411. dr["gongchuang"] = 200;
  2412. }
  2413. else if ("外协".Equals(dr["ToType"].ToString()))
  2414. {
  2415. dr["gongchuang"] = 200;
  2416. }
  2417. else if ("内部".Equals(dr["ToType"].ToString()))
  2418. {
  2419. dr["gongchuang"] = -1;
  2420. }
  2421. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2422. {
  2423. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2424. dr["gongchuang"] = response.code;
  2425. }
  2426. }
  2427. }
  2428. catch (NullReferenceException ex)
  2429. {
  2430. }
  2431. }
  2432. }
  2433. writeGridDataTableJson(dStruct.TotalCount, dt);
  2434. }
  2435. public void get_erp_myreturnorderlist()
  2436. {
  2437. DataStruct dStruct = GetPostStruct();
  2438. List<string> lw = new List<string>();
  2439. string tid = GetPostString("ctid");
  2440. if (tid.Length > 0)
  2441. {
  2442. string select_tid = getTidByCtid(tid);
  2443. lw.Add(string.Format("tid='{0}'", select_tid));
  2444. }
  2445. else
  2446. {
  2447. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2448. }
  2449. string shopname = GetPostString("shopname");
  2450. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2451. string buyernick = GetPostString("buyer_nick");
  2452. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2453. string design = GetPostString("design");
  2454. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2455. string orderState = GetPostString("orderState");
  2456. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2457. string sellermemo = GetPostString("seller_memo");
  2458. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2459. string date1 = GetPostString("date1");
  2460. string date2 = GetPostString("date2");
  2461. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2462. if (dw.Length > 0) lw.Add(dw);
  2463. string price1 = GetPostString("price1");
  2464. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2465. string price2 = GetPostString("price2");
  2466. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2467. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2468. {
  2469. lw.Add(string.Format("CusOrgID = 94"));
  2470. }
  2471. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2472. {
  2473. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2474. }
  2475. else
  2476. {
  2477. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2478. }
  2479. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2480. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2481. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2482. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2483. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2484. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2485. if (dt != null && dt.Rows.Count > 0)
  2486. {
  2487. foreach (DataRow dr in dt.Rows)
  2488. {
  2489. try
  2490. {
  2491. // 对象操作
  2492. if (dStruct.PageSize != 100000)
  2493. {
  2494. if (dr["DispatchSort"].ToString() == "2")
  2495. {
  2496. dr["gongchuang"] = 200;
  2497. }
  2498. else if ("外协".Equals(dr["ToType"].ToString()))
  2499. {
  2500. dr["gongchuang"] = 200;
  2501. }
  2502. else if ("内部".Equals(dr["ToType"].ToString()))
  2503. {
  2504. dr["gongchuang"] = -1;
  2505. }
  2506. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2507. {
  2508. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2509. dr["gongchuang"] = response.code;
  2510. }
  2511. }
  2512. }
  2513. catch (NullReferenceException ex)
  2514. {
  2515. // 处理空引用异常
  2516. }
  2517. }
  2518. }
  2519. writeGridDataTableJson(dStruct.TotalCount, dt);
  2520. }
  2521. public void get_erp_myorderlist_pregather()
  2522. {
  2523. string date1 = GetPostString("date1");
  2524. string date2 = GetPostString("date2");
  2525. int userId = CurrentUser.UserID; //客服id
  2526. string orderWhere = "";
  2527. List<string> lw = new List<string>();
  2528. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2529. if (dw.Length > 0) lw.Add(dw);
  2530. lw.Add(string.Format("CustomerUserId={0}", userId));
  2531. lw.Add(string.Format("OrderState<9"));
  2532. orderWhere = string.Join(" and ", lw.ToArray());
  2533. string orderWhere2 = "";
  2534. List<string> lw2 = new List<string>();
  2535. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2536. if (dw2.Length > 0) lw2.Add(dw2);
  2537. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2538. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2539. string sql = string.Format("select *" +
  2540. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2541. "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 " +
  2542. "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 " +
  2543. "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");
  2544. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2545. //writeGridDataTableJson(dt.Rows.Count, dt);
  2546. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2547. }
  2548. public void upd_erp_publishorder()
  2549. {
  2550. if (UrlPostParmsCheck("ctid"))
  2551. {
  2552. string eid = GetPostString("ctid");
  2553. CeErpTradeCell entity = null;
  2554. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2555. if (entity != null)
  2556. {
  2557. entity.OrderState = 0; //发布后,变为待抢单
  2558. entity.Update();
  2559. commonHelper.UpdateRelationOrder(entity.ctid);
  2560. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2561. returnSuccessMsg("发布成功!");
  2562. return;
  2563. }
  2564. returnErrorMsg("找不到记录");
  2565. }
  2566. }
  2567. public void get_erp_my_tiporder()
  2568. {
  2569. StringBuilder sql = new StringBuilder();
  2570. int userId = 0;
  2571. if (CurrentUser != null) userId = CurrentUser.UserID;
  2572. string posCode = CurrentUser.UserPost.Post.Code;
  2573. string isTipedAfterSaleVerify = GetPostString("af");
  2574. DataTable dt = new DataTable();
  2575. if (posCode != "Supplier")
  2576. {
  2577. if (posCode == "CustomerService" || posCode == "Director")
  2578. {
  2579. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2580. }
  2581. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2582. {
  2583. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2584. }
  2585. else
  2586. {
  2587. string teamIds = CurrentUser.User.TeamIds;
  2588. if (teamIds == "")
  2589. {
  2590. teamIds = "0";
  2591. }
  2592. 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);
  2593. }
  2594. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2595. }
  2596. if (dt.Rows.Count <= 0)
  2597. {
  2598. string key = "aftersale_order_" + userId;
  2599. if (RedisHelper.HasKey(key))
  2600. {
  2601. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2602. dt.Columns.Add("ctid", typeof(string));
  2603. dt.Columns.Add("IsReadTag", typeof(int));
  2604. foreach (var i in list)
  2605. {
  2606. DataRow data = dt.NewRow();
  2607. data["ctid"] = i;
  2608. data["IsReadTag"] = 4;
  2609. dt.Rows.Add(data);
  2610. }
  2611. RedisHelper.StringDelete(key);
  2612. }
  2613. }
  2614. if (dt.Rows.Count <= 0)
  2615. {
  2616. sql = new StringBuilder();
  2617. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2618. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2619. }
  2620. if (posCode == "Supplier")
  2621. {
  2622. string ids = CurrentUser.User.pemVend;
  2623. if (ids != null && ids.Length > 0)
  2624. {
  2625. string[] ids_list = ids.Split(',');
  2626. foreach (var item in ids_list)
  2627. {
  2628. string key = "return_order_" + item;
  2629. if (RedisHelper.HasKey(key))
  2630. {
  2631. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2632. dt.Columns.Add("ctid", typeof(string));
  2633. dt.Columns.Add("IsReadTag", typeof(int));
  2634. foreach (var i in list)
  2635. {
  2636. DataRow data = dt.NewRow();
  2637. data["ctid"] = i;
  2638. data["IsReadTag"] = 1;
  2639. dt.Rows.Add(data);
  2640. }
  2641. RedisHelper.StringDelete(key);
  2642. }
  2643. }
  2644. }
  2645. if (dt.Rows.Count <= 0)
  2646. {
  2647. sql = new StringBuilder();
  2648. 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);
  2649. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2650. }
  2651. }
  2652. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2653. }
  2654. public void reset_erp_tiporder()
  2655. {
  2656. string ids = GetPostString("ids");
  2657. string[] ctidList = ids.Split(',');
  2658. foreach (string ctid in ctidList)
  2659. {
  2660. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2661. if (enty != null)
  2662. {
  2663. enty.IsReadTag = 0;
  2664. enty.Update();
  2665. }
  2666. }
  2667. returnSuccessMsg("成功!");
  2668. return;
  2669. }
  2670. public void get_erp_designlist()
  2671. {
  2672. DataStruct dStruct = GetPostStruct();
  2673. List<string> lw = new List<string>();
  2674. string tid = GetPostString("ctid");
  2675. if (tid.Length > 0)
  2676. {
  2677. string select_tid = getTidByCtid(tid);
  2678. lw.Add(string.Format("tid='{0}'", select_tid));
  2679. }
  2680. string shopname = GetPostString("shopname");
  2681. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2682. string buyernick = GetPostString("buyer_nick");
  2683. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2684. string customer = GetPostString("customer");
  2685. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2686. string design = GetPostString("design");
  2687. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2688. string orderState = GetPostString("orderState");
  2689. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2690. lw.Add(string.Format("OrderState<6"));
  2691. string address = GetPostString("address");
  2692. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2693. string sellermemo = GetPostString("seller_memo");
  2694. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2695. string date1 = GetPostString("date1");
  2696. string date2 = GetPostString("date2");
  2697. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2698. if (dw.Length > 0) lw.Add(dw);
  2699. string apdate1 = GetPostString("apdate1");
  2700. string apdate2 = GetPostString("apdate2");
  2701. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2702. if (dwap.Length > 0) lw.Add(dwap);
  2703. string price1 = GetPostString("price1");
  2704. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2705. string price2 = GetPostString("price2");
  2706. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2707. string designTime = GetPostString("designtime");
  2708. if (designTime.Length > 0)
  2709. {
  2710. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2711. }
  2712. string usershop = CurrentUser.User.pemShop;
  2713. if (usershop.Length > 0)
  2714. {
  2715. lw.Add(string.Format("shopId in ({0})", usershop));
  2716. }
  2717. int myOrgid = CurrentUser.UserPost.OrgID;
  2718. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2719. if (myOrgCode.IndexOf("Designer") != -1)
  2720. {
  2721. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2722. {
  2723. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2724. }
  2725. else
  2726. {
  2727. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2728. }
  2729. }
  2730. else
  2731. {
  2732. string orgId = GetPostString("designerhd");
  2733. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2734. }
  2735. if (tid.Length > 0 || buyernick.Length > 0)
  2736. {
  2737. lw.Add(string.Format("OrderState >= 3"));
  2738. }
  2739. else
  2740. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2741. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2742. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2743. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2744. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2745. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2746. if (dt != null && dt.Rows.Count > 0)
  2747. {
  2748. foreach (DataRow dr in dt.Rows)
  2749. {
  2750. try
  2751. {
  2752. // 对象操作
  2753. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2754. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2755. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2756. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2757. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2758. if (dStruct.PageSize != 100000)
  2759. {
  2760. if (dr["DispatchSort"].ToString() == "2")
  2761. {
  2762. dr["gongchuang"] = 200;
  2763. }
  2764. else if ("外协".Equals(dr["ToType"].ToString()))
  2765. {
  2766. dr["gongchuang"] = 200;
  2767. }
  2768. else if ("内部".Equals(dr["ToType"].ToString()))
  2769. {
  2770. dr["gongchuang"] = -1;
  2771. }
  2772. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2773. {
  2774. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2775. dr["gongchuang"] = response.code;
  2776. }
  2777. }
  2778. }
  2779. catch (NullReferenceException ex)
  2780. {
  2781. }
  2782. }
  2783. }
  2784. writeGridDataTableJson(dStruct.TotalCount, dt);
  2785. }
  2786. public void get_erp_mydesignlist()
  2787. {
  2788. DataStruct dStruct = GetPostStruct();
  2789. List<string> lw = new List<string>();
  2790. string tid = GetPostString("ctid");
  2791. if (tid.Length > 0)
  2792. {
  2793. string select_tid = getTidByCtid(tid);
  2794. lw.Add(string.Format("tid='{0}'", select_tid));
  2795. }
  2796. string shopname = GetPostString("shopname");
  2797. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2798. string buyernick = GetPostString("buyer_nick");
  2799. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2800. string customer = GetPostString("customer");
  2801. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2802. string orderState = GetPostString("orderState");
  2803. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2804. //lw.Add(string.Format("OrderState<6"));
  2805. string date1 = GetPostString("date1");
  2806. string date2 = GetPostString("date2");
  2807. string dw = GetDateWhere("pay_time", date1, date2);
  2808. if (dw.Length > 0) lw.Add(dw);
  2809. string apdate1 = GetPostString("apdate1");
  2810. string apdate2 = GetPostString("apdate2");
  2811. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2812. if (dwap.Length > 0) lw.Add(dwap);
  2813. string price1 = GetPostString("price1");
  2814. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2815. string price2 = GetPostString("price2");
  2816. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2817. string olddownload = GetPostString("olddown");
  2818. if (olddownload == "1")
  2819. {
  2820. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2821. }
  2822. else if (olddownload == "2")
  2823. {
  2824. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2825. }
  2826. string sellermemo = GetPostString("seller_memo");
  2827. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2828. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2829. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2830. {
  2831. if (CurrentUser.User.TeamIds.Length > 0)
  2832. {
  2833. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2834. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2835. else
  2836. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2837. }
  2838. else
  2839. {
  2840. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2841. }
  2842. }
  2843. if (tid.Length <= 0)
  2844. {
  2845. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2846. }
  2847. lw.Add(string.Format("IsReturn!=3"));
  2848. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2849. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2850. string teamids = CurrentUser.User.TeamIds.ToString();
  2851. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2852. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2853. if (dt != null && dt.Rows.Count > 0)
  2854. {
  2855. foreach (DataRow dr in dt.Rows)
  2856. {
  2857. try
  2858. {
  2859. // 对象操作
  2860. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2861. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2862. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2863. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2864. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2865. if (dStruct.PageSize != 100000)
  2866. {
  2867. if (dr["DispatchSort"].ToString() == "2")
  2868. {
  2869. dr["gongchuang"] = 200;
  2870. }
  2871. else if ("外协".Equals(dr["ToType"].ToString()))
  2872. {
  2873. dr["gongchuang"] = 200;
  2874. }
  2875. else if ("内部".Equals(dr["ToType"].ToString()))
  2876. {
  2877. dr["gongchuang"] = -1;
  2878. }
  2879. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2880. {
  2881. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2882. dr["gongchuang"] = response.code;
  2883. }
  2884. }
  2885. }
  2886. catch (NullReferenceException ex)
  2887. {
  2888. }
  2889. }
  2890. }
  2891. writeGridDataTableJson(dStruct.TotalCount, dt);
  2892. }
  2893. public void set_erp_startdesign()
  2894. {
  2895. if (UrlPostParmsCheck("ctid"))
  2896. {
  2897. string eid = GetPostString("ctid");
  2898. CeErpTradeCell entity = null;
  2899. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2900. if (entity != null)
  2901. {
  2902. if (entity.OrderState != 3)
  2903. {
  2904. returnErrorMsg("请刷新,订单已经设计了");
  2905. return;
  2906. }
  2907. entity.StartDesignTime = DateTime.Now;
  2908. entity.OrderState = 4;
  2909. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2910. {
  2911. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2912. entity.SupplierId = suid;
  2913. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2914. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2915. }
  2916. entity.UpdateTime = DateTime.Now;
  2917. //entity.MakeSupplier = suname;
  2918. entity.Update();
  2919. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2920. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2921. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2922. commonHelper.getCytPrice(entity);
  2923. returnSuccessMsg("操作成功!");
  2924. return;
  2925. }
  2926. returnErrorMsg("找不到记录");
  2927. }
  2928. }
  2929. public void ins_erp_designselfmemo()
  2930. {
  2931. if (UrlPostParmsCheck("ctid"))
  2932. {
  2933. string eid = GetPostString("ctid");
  2934. string con = GetPostString("con");
  2935. CeErpTradeCell entity = null;
  2936. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2937. if (entity != null)
  2938. {
  2939. entity.DesignSelfMemo = con;
  2940. entity.Update();
  2941. returnSuccessMsg("操作成功!");
  2942. return;
  2943. }
  2944. returnErrorMsg("找不到记录");
  2945. }
  2946. }
  2947. public void ins_erp_designprice()
  2948. {
  2949. if (UrlPostParmsCheck("ctid"))
  2950. {
  2951. string eid = GetPostString("ctid");
  2952. int uid = CurrentUser.UserID;
  2953. string userName = CurrentUser.UserName;
  2954. CeErpTradeCell entity = null;
  2955. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2956. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2957. if (entitys == null)
  2958. {
  2959. entitys = new CeErpDesignerBill();
  2960. }
  2961. if (entity != null)
  2962. {
  2963. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2964. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2965. entity.StartDesignTime = DateTime.Now;
  2966. entity.OrderState = 4;
  2967. string suname = "";
  2968. if (entity.SupplierId == 0)
  2969. {
  2970. int sid = commonHelper.autoDistributeToSupplier(entity);
  2971. entity.SupplierId = sid;
  2972. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2973. }
  2974. entity.Update();
  2975. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2976. if (ceErpUserPost != null)
  2977. {
  2978. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2979. if (ceErpPost != null)
  2980. {
  2981. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2982. {
  2983. entitys.tid = entity.ctid;
  2984. entitys.oid = entity.tid;
  2985. entitys.uid = uid;
  2986. entitys.userName = userName;
  2987. entitys.designerType = 1;
  2988. entitys.designerTypeText = "内部设计师";
  2989. entitys.price = Convert.ToDouble(GetPostString("price"));
  2990. entitys.designNum = GetPostInt("designNum");
  2991. entitys.modifyNum = GetPostInt("modifyNum");
  2992. entitys.designSize = GetPostString("designSize");
  2993. entitys.modifySize = GetPostString("modifySize");
  2994. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2995. {
  2996. entitys.create_time = DateTime.Now;
  2997. entitys.create_u_id = uid;
  2998. entitys.create_u_name = userName;
  2999. entitys.Save();
  3000. }
  3001. else
  3002. {
  3003. entitys.update_time = DateTime.Now;
  3004. entitys.update_u_id = uid;
  3005. entitys.update_u_name = userName;
  3006. entitys.Update();
  3007. }
  3008. }
  3009. }
  3010. }
  3011. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3012. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3013. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3014. if (suname != "")
  3015. {
  3016. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3017. }
  3018. commonHelper.getCytPrice(entity);
  3019. returnSuccessMsg("操作成功!");
  3020. return;
  3021. }
  3022. returnErrorMsg("找不到记录");
  3023. }
  3024. }
  3025. public void upload_erp_filecomplete()
  3026. {
  3027. if (UrlPostParmsCheck("ctid"))
  3028. {
  3029. string eid = GetPostString("ctid");
  3030. CeErpTradeCell entity = null;
  3031. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3032. if (entity != null)
  3033. {
  3034. entity.OrderState = 5; //设计完成
  3035. entity.Update();
  3036. returnSuccessMsg(eid + "上传成功,设计完成!");
  3037. return;
  3038. }
  3039. returnErrorMsg("找不到订单记录");
  3040. }
  3041. }
  3042. public void get_erp_designovertimelist()
  3043. {
  3044. DataStruct dStruct = GetPostStruct();
  3045. List<string> lw = new List<string>();
  3046. string tid = GetPostString("ctid");
  3047. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3048. string shopname = GetPostString("shopname");
  3049. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3050. string buyernick = GetPostString("buyer_nick");
  3051. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3052. string ResponsibleMan = GetPostString("responsible");
  3053. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3054. string date1 = GetPostString("date1");
  3055. string date2 = GetPostString("date2");
  3056. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3057. if (dw.Length > 0) lw.Add(dw);
  3058. string price1 = GetPostString("price1");
  3059. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3060. string price2 = GetPostString("price2");
  3061. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3062. string orderState = GetPostString("orderState");
  3063. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3064. string sellermemo = GetPostString("seller_memo");
  3065. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3066. lw.Add(string.Format("UnusualTag=3"));
  3067. lw.Add(string.Format("IsRefund<={0}", 1));
  3068. dStruct.Order = "WaitDesignTime desc";
  3069. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3070. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3071. writeGridDataTableJson(dStruct.TotalCount, dt);
  3072. }
  3073. //设计管理 获取抢单大厅列表
  3074. public void get_erp_grabinglist()
  3075. {
  3076. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3077. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3078. bool oldOrder = false;
  3079. if (org != null)
  3080. {
  3081. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3082. }
  3083. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3084. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3085. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3086. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3087. //先处理订单数据
  3088. if (dt.Rows.Count > 0)
  3089. {
  3090. Dictionary<string, int> design = null;
  3091. int count = 0;
  3092. foreach (DataRow row in dt.Rows)
  3093. {
  3094. if (map.ContainsKey(row["ShopId"].ToString()))
  3095. {
  3096. map.TryGetValue(row["ShopId"].ToString(), out design);
  3097. }
  3098. else
  3099. {
  3100. design = new Dictionary<string, int>();
  3101. }
  3102. if (design.ContainsKey(row["ProductId"].ToString()))
  3103. {
  3104. design.TryGetValue(row["ProductId"].ToString(), out count);
  3105. }
  3106. count++;
  3107. design[row["ProductId"].ToString()] = count;
  3108. map[row["ShopId"].ToString()] = design;
  3109. }
  3110. }
  3111. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3112. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3113. //把店铺排序和技能排序分类
  3114. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3115. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3116. if (design_dt.Rows.Count > 0)
  3117. {
  3118. Dictionary<string, string> design = null;
  3119. List<string> shopIds = null;
  3120. foreach (DataRow row in design_dt.Rows)
  3121. {
  3122. if ("0".Equals(row["designId"].ToString()))
  3123. {
  3124. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3125. {
  3126. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3127. }
  3128. else
  3129. {
  3130. shopIds = new List<string>();
  3131. }
  3132. shopIds.Add(row["shopId"].ToString());
  3133. shop_orders[row["orders"].ToString()] = shopIds;
  3134. }
  3135. else
  3136. {
  3137. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3138. {
  3139. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3140. }
  3141. else
  3142. {
  3143. design = new Dictionary<string, string>();
  3144. }
  3145. design[row["orders"].ToString()] = row["designId"].ToString();
  3146. design_orders[row["shopId"].ToString()] = design;
  3147. }
  3148. }
  3149. //处理成key value后根据key排序
  3150. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3151. foreach (List<string> val in shop_orders.Values)
  3152. {
  3153. if (val != null)
  3154. {
  3155. foreach (string key in val)
  3156. {
  3157. if (design_orders.ContainsKey(key.ToString()))
  3158. {
  3159. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3160. }
  3161. }
  3162. }
  3163. }
  3164. }
  3165. //校验哪个优先级有订单
  3166. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3167. foreach (string key in shop_orders.Keys)
  3168. {
  3169. List<string> ids = null;
  3170. shop_orders.TryGetValue(key, out ids);
  3171. //id为shopid
  3172. foreach (string id in ids)
  3173. {
  3174. Dictionary<string, int> list = null;
  3175. Dictionary<string, string> desing = null;
  3176. map.TryGetValue(id, out list);
  3177. design_orders.TryGetValue(id, out desing);
  3178. if (list != null && desing != null)
  3179. {
  3180. foreach (var item in desing)
  3181. {
  3182. int count = 0;
  3183. if (list.ContainsKey(item.Value))
  3184. {
  3185. list.TryGetValue(item.Value, out count);
  3186. if (count > 0)
  3187. {
  3188. designIds[id] = item.Value;
  3189. break;
  3190. }
  3191. }
  3192. }
  3193. }
  3194. }
  3195. if (designIds.Count > 0)
  3196. {
  3197. break;
  3198. }
  3199. }
  3200. DataTable table = new DataTable();
  3201. table.Columns.Add("tid", typeof(string));
  3202. table.Columns.Add("ctid", typeof(string));
  3203. table.Columns.Add("seller_nick", typeof(string));
  3204. table.Columns.Add("productName", typeof(string));
  3205. table.Columns.Add("pay_time", typeof(string));
  3206. table.Columns.Add("seller_memo", typeof(string));
  3207. if (designIds.Count > 0)
  3208. {
  3209. string shopId = "";
  3210. string productId = "";
  3211. foreach (var designInfo in designIds)
  3212. {
  3213. shopId = designInfo.Key;
  3214. productId = designInfo.Value;
  3215. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3216. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3217. if (dt.Rows.Count > 0)
  3218. {
  3219. foreach (DataRow row in dt.Rows)
  3220. {
  3221. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3222. {
  3223. DataRow data = table.NewRow();
  3224. data["ctid"] = row["ctid"].ToString();
  3225. data["tid"] = row["tid"].ToString();
  3226. data["seller_nick"] = ceErpShop.ShopName;
  3227. data["pay_time"] = row["pay_time"].ToString();
  3228. data["seller_memo"] = row["seller_memo"].ToString();
  3229. data["productName"] = ceErpProduct.PType;
  3230. table.Rows.Add(data);
  3231. }
  3232. }
  3233. }
  3234. }
  3235. }
  3236. writeGridDataTableJson(table.Rows.Count, table);
  3237. }
  3238. private object rushLockObject = new object();
  3239. public void set_erp_grabingorder()
  3240. {
  3241. if (UrlPostParmsCheck("ctid"))
  3242. {
  3243. int total = CurrentUser.User.Person.Total;
  3244. int userId = CurrentUser.User.ID;
  3245. int noFinish = CurrentUser.User.Person.NoFinish;
  3246. int finalization = CurrentUser.User.Person.Finalization;
  3247. string eids = GetPostString("ctid");
  3248. string key = "RushKey_" + userId;
  3249. int count = 0;
  3250. if (erpRedis.RedisHelper.KeyExists(key))
  3251. {
  3252. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3253. if (redisCount != null)
  3254. {
  3255. count = Convert.ToInt32(redisCount);
  3256. }
  3257. }
  3258. if (count >= total)
  3259. {
  3260. returnErrorMsg("半小时内已经抢" + total + "单");
  3261. return;
  3262. }
  3263. string[] ctidlist = eids.Split(',');
  3264. if (count + ctidlist.Length > total)
  3265. {
  3266. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3267. return;
  3268. }
  3269. int itag = 0;
  3270. lock (rushLockObject)
  3271. {
  3272. if (ctidlist.Length > 0)
  3273. {
  3274. string[] dtList = new string[ctidlist.Length];
  3275. for (int i = 0; i < ctidlist.Length; i++)
  3276. {
  3277. dtList[i] = "'" + ctidlist[i] + "'";
  3278. }
  3279. 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"));
  3280. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3281. if (dt_user.Rows.Count > 0)
  3282. {
  3283. int doing = 0;//未定稿
  3284. int finish = 0;//已完成
  3285. foreach (DataRow dr in dt_user.Rows)
  3286. {
  3287. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3288. {
  3289. doing++;
  3290. }
  3291. else
  3292. {
  3293. finish++;
  3294. }
  3295. }
  3296. if (doing >= noFinish)
  3297. {
  3298. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3299. return;
  3300. }
  3301. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3302. {
  3303. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3304. return;
  3305. }
  3306. }
  3307. //校验选择单子状态
  3308. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3309. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3310. if (dt.Rows.Count > 0)
  3311. {
  3312. List<string> list = new List<string>();
  3313. foreach (DataRow dr in dt.Rows)
  3314. {
  3315. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3316. {
  3317. list.Add(dr["ctid"].ToString());
  3318. }
  3319. }
  3320. if (list.Count > 0)
  3321. {
  3322. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3323. return;
  3324. }
  3325. }
  3326. foreach (string ctid in ctidlist)
  3327. {
  3328. CeErpTradeCell entity = null;
  3329. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3330. if (entity != null)
  3331. {
  3332. entity.OrderState = 3;
  3333. entity.DesignUserId = CurrentUser.UserID;
  3334. entity.WaitDesignTime = DateTime.Now;
  3335. entity.StartDesignTime = DateTime.Now;
  3336. entity.Update();
  3337. commonHelper.UpdateRelationOrder(entity.ctid);
  3338. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3339. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3340. itag++;
  3341. }
  3342. }
  3343. }
  3344. }
  3345. count += ctidlist.Length;
  3346. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3347. if (itag == 0)
  3348. returnErrorMsg("没有找到相关订单");
  3349. else
  3350. returnSuccessMsg("抢单成功!");
  3351. return;
  3352. }
  3353. }
  3354. public void get_erp_waitorderlist()
  3355. {
  3356. DataStruct dStruct = GetPostStruct();
  3357. List<string> lw = new List<string>();
  3358. string tid = GetPostString("ctid");
  3359. if (tid.Length > 0)
  3360. {
  3361. string select_tid = getTidByCtid(tid);
  3362. lw.Add(string.Format("tid='{0}'", select_tid));
  3363. }
  3364. string shopname = GetPostString("shopname");
  3365. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3366. string buyernick = GetPostString("buyer_nick");
  3367. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3368. string customer = GetPostString("customer");
  3369. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3370. string design = GetPostString("design");
  3371. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3372. string orderState = GetPostString("orderState");
  3373. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3374. string supplier = GetPostString("supplier");
  3375. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3376. string sellermemo = GetPostString("seller_memo");
  3377. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3378. string otherMemo = GetPostString("otherMemo");
  3379. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3380. string address = GetPostString("address");
  3381. 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));
  3382. string date1 = GetPostString("date1");
  3383. string date2 = GetPostString("date2");
  3384. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3385. if (dw.Length > 0) lw.Add(dw);
  3386. string price1 = GetPostString("price1");
  3387. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3388. string price2 = GetPostString("price2");
  3389. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3390. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3391. lw.Add(string.Format("IsSample != 2 "));
  3392. lw.Add(string.Format("OrderState = 5 "));
  3393. lw.Add(string.Format("IsRefund<={0}", 1));
  3394. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3395. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3396. string pagesize = GetPostString("pagesize");
  3397. if (pagesize != null)
  3398. {
  3399. dStruct.PageSize = 200;
  3400. }
  3401. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3402. if (dt != null)
  3403. {
  3404. foreach (DataRow dr in dt.Rows)
  3405. {
  3406. 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();
  3407. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3408. {
  3409. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3410. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3411. entity.SupplierId = suid;
  3412. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3413. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3414. entity.Update();
  3415. }
  3416. }
  3417. }
  3418. writeGridDataTableJson(dStruct.TotalCount, dt);
  3419. }
  3420. public void get_erp_supplierwaitorderlist()
  3421. {
  3422. DataStruct dStruct = GetPostStruct();
  3423. List<string> lw = new List<string>();
  3424. string tid = GetPostString("ctid");
  3425. if (tid.Length > 0)
  3426. {
  3427. string select_tid = getTidByCtid(tid);
  3428. lw.Add(string.Format("tid='{0}'", select_tid));
  3429. }
  3430. string shopname = GetPostString("shopname");
  3431. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3432. string sellermemo = GetPostString("seller_memo");
  3433. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3434. string date1 = GetPostString("date1");
  3435. string date2 = GetPostString("date2");
  3436. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3437. if (dw.Length > 0) lw.Add(dw);
  3438. lw.Add(string.Format("OrderState = 5 "));
  3439. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3440. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3441. {
  3442. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3443. }
  3444. string supplier = GetPostString("supplier");
  3445. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3446. {
  3447. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3448. }
  3449. lw.Add(string.Format("IsRefund<={0}", 1));
  3450. dStruct.Order = "FinishDesignTime desc";
  3451. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3452. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3453. if (dt != null)
  3454. {
  3455. foreach (DataRow dr in dt.Rows)
  3456. {
  3457. 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();
  3458. }
  3459. }
  3460. writeGridDataTableJson(dStruct.TotalCount, dt);
  3461. }
  3462. public void upd_erp_verifytosupplier()
  3463. {
  3464. if (UrlPostParmsCheck("ctid"))
  3465. {
  3466. string eids = GetPostString("ctid");
  3467. CeErpTradeCell entity = null;
  3468. string[] eidsList = eids.Split(',');
  3469. if (eidsList.Length <= 0)
  3470. {
  3471. returnErrorMsg("订单号不能空");
  3472. return;
  3473. }
  3474. List<string> tLst = new List<string>();
  3475. foreach (string ctidstr in eidsList)
  3476. {
  3477. tLst.Add("'" + ctidstr + "'");
  3478. CeErpDataSendOrderInfo.createObject(ctidstr);
  3479. }
  3480. string needtids = string.Join(",", tLst.ToArray());
  3481. StringBuilder sql = new StringBuilder();
  3482. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3483. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3484. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3485. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3486. returnSuccessMsg("操作成功!");
  3487. return;
  3488. /**foreach (string ctidstr in eidsList)
  3489. {
  3490. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3491. if (entity != null)
  3492. {
  3493. if (entity.SupplierId == 0)
  3494. {
  3495. continue;
  3496. }
  3497. entity.IsVerifyToSupplier = true;
  3498. if (entity.IsReturn == 1) //1是供应商打回
  3499. {
  3500. entity.IsReturn = 0;
  3501. }
  3502. entity.FinishPlaceTime = DateTime.Now;
  3503. entity.PlaceUserId = CurrentUser.UserID;
  3504. entity.Update();
  3505. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3506. }
  3507. }
  3508. returnSuccessMsg("操作成功!");
  3509. return;**/
  3510. }
  3511. }
  3512. public void upd_erp_supplierback()
  3513. {
  3514. if (UrlPostParmsCheck("ctid"))
  3515. {
  3516. string eid = GetPostString("ctid");
  3517. string reason = GetPostString("returnreason");
  3518. CeErpTradeCell entity = null;
  3519. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3520. if (entity != null)
  3521. {
  3522. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3523. {
  3524. string key = "return_order_" + entity.SupplierId;
  3525. List<string> list = new List<string>();
  3526. if (RedisHelper.HasKey(key))
  3527. {
  3528. object data = RedisHelper.StringGet(key);
  3529. list = Convert.ToString(data).Split(',').ToList();
  3530. }
  3531. list.Add(eid);
  3532. RedisHelper.StringSet(key, string.Join(",", list));
  3533. }
  3534. entity.IsVerifyToSupplier = false;
  3535. entity.IsReturn = 1;
  3536. entity.ReturnTime = DateTime.Now;
  3537. entity.ReturnReason = reason;
  3538. if (entity.OrderState == 6)
  3539. {
  3540. entity.OrderState = 5;
  3541. }
  3542. entity.Update();
  3543. CeErpSukuraData.createInfo(entity.ctid, 5);
  3544. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3545. returnSuccessMsg("操作成功!");
  3546. return;
  3547. }
  3548. returnErrorMsg("找不到订单记录");
  3549. }
  3550. }
  3551. public void upd_erp_toaftersaleorder()
  3552. {
  3553. if (UrlPostParmsCheck("ctid"))
  3554. {
  3555. string eid = GetPostString("ctid");
  3556. string reason = GetPostString("returnreason");
  3557. CeErpTradeCell entity = null;
  3558. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3559. if (entity != null)
  3560. {
  3561. if (entity.isAfterSaleOrder != 1)
  3562. {
  3563. returnErrorMsg("带S的售后单才能打回给售后");
  3564. return;
  3565. }
  3566. if (entity.OrderState >= 5)
  3567. {
  3568. returnErrorMsg("已经设计完成了不能打回给售后");
  3569. return;
  3570. }
  3571. entity.OrderState = 0;
  3572. entity.IsReturn = 3;
  3573. entity.ReturnTime = DateTime.Now;
  3574. entity.UpdateTime = DateTime.Now;
  3575. entity.ReturnReason = reason;
  3576. entity.Update();
  3577. CeErpSukuraData.createInfo(entity.ctid, 5);
  3578. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3579. returnSuccessMsg("操作成功!");
  3580. return;
  3581. }
  3582. returnErrorMsg("找不到订单记录");
  3583. }
  3584. }
  3585. public void upd_erp_aftersaletodesign()
  3586. {
  3587. if (UrlPostParmsCheck("ctid"))
  3588. {
  3589. string eid = GetPostString("ctid");
  3590. CeErpTradeCell entity = null;
  3591. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3592. if (entity != null)
  3593. {
  3594. entity.OrderState = 3;
  3595. entity.IsReturn = 0;
  3596. entity.UpdateTime = DateTime.Now;
  3597. entity.Update();
  3598. CeErpSukuraData.createInfo(entity.ctid, 5);
  3599. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3600. returnSuccessMsg("操作成功!");
  3601. return;
  3602. }
  3603. returnErrorMsg("找不到订单记录");
  3604. }
  3605. }
  3606. public void assign_erp_supplier()
  3607. {
  3608. if (UrlPostParmsCheck("ctid"))
  3609. {
  3610. string eids = GetPostString("ctid");
  3611. int sid = GetPostInt("SupplierName");
  3612. string fromTag = GetPostString("tag");
  3613. string[] eidList = eids.Split(',');
  3614. if (eidList.Length <= 0)
  3615. {
  3616. returnErrorMsg("指派不能为空");
  3617. return;
  3618. }
  3619. string errMsg = "";
  3620. string suname = commonHelper.getSupplierNameById(sid);
  3621. foreach (string ctid in eidList)
  3622. {
  3623. CeErpTradeCell entity = null;
  3624. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3625. if (entity != null)
  3626. {
  3627. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3628. {
  3629. errMsg += (ctid + "指派失败!!!");
  3630. continue;
  3631. }
  3632. entity.SupplierId = sid;
  3633. entity.Update();
  3634. commonHelper.UpdateRelationOrder(entity.ctid);
  3635. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3636. if (entity.OrderState >= 6)
  3637. {
  3638. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3639. //{
  3640. // string msl = entity.MakeSupplier;
  3641. // string[] mslist = msl.Split(',');
  3642. // 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);
  3643. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3644. //}
  3645. //else
  3646. //{
  3647. StringBuilder sql = new StringBuilder();
  3648. 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);
  3649. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3650. //}
  3651. }
  3652. }
  3653. else
  3654. {
  3655. continue;
  3656. }
  3657. }
  3658. if (errMsg.Length > 0)
  3659. {
  3660. returnErrorMsg(errMsg);
  3661. return;
  3662. }
  3663. returnSuccessMsg("操作成功!");
  3664. return;
  3665. }
  3666. }
  3667. public void assign_erp_makesupplier()
  3668. {
  3669. if (UrlPostParmsCheck("ctid"))
  3670. {
  3671. string eids = GetPostString("ctid");
  3672. string sname = GetPostString("SupplierName");
  3673. string[] eidList = eids.Split(',');
  3674. if (eidList.Length <= 0)
  3675. {
  3676. returnErrorMsg("指派不能为空");
  3677. return;
  3678. }
  3679. List<string> tLst = new List<string>();
  3680. foreach (string ctid in eidList)
  3681. {
  3682. CeErpTradeCell entity = null;
  3683. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3684. if (entity != null)
  3685. {
  3686. entity.MakeSupplier = sname;
  3687. entity.Update();
  3688. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3689. tLst.Add("'" + ctid + "'");
  3690. }
  3691. else
  3692. {
  3693. continue;
  3694. }
  3695. }
  3696. string ctids = string.Join(",", tLst.ToArray());
  3697. StringBuilder sql2 = new StringBuilder();
  3698. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3699. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3700. returnSuccessMsg("操作成功!");
  3701. return;
  3702. }
  3703. }
  3704. public void ins_erp_returnreason()
  3705. {
  3706. if (UrlPostParmsCheck("ctid"))
  3707. {
  3708. string eid = GetPostString("ctid");
  3709. CeErpTradeCell entity = null;
  3710. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3711. string userpost = CurrentUser.UserPost.Post.Code;
  3712. if (entity != null)
  3713. {
  3714. bool isPlace = false;
  3715. if (entity.OrderState > 6)
  3716. {
  3717. returnErrorMsg("已发货无法打回!");
  3718. return;
  3719. }
  3720. if (entity.OrderState == 6)
  3721. {
  3722. isPlace = true;
  3723. }
  3724. bool isNeedUpdateCell2 = false;
  3725. if (entity.OrderState >= 6)
  3726. {
  3727. isNeedUpdateCell2 = true;
  3728. }
  3729. int returnTag = 2;
  3730. if (userpost == "Supplier")
  3731. {
  3732. returnTag = 1;
  3733. }
  3734. int toType = GetPostInt("totype");
  3735. string fromType = "3";
  3736. if (entity.OrderState < 5)
  3737. {
  3738. fromType = "3";
  3739. }
  3740. else
  3741. {
  3742. fromType = "4";
  3743. }
  3744. if (entity.IsXianHuo == 0)
  3745. {
  3746. if (returnTag == 2)
  3747. {
  3748. if (toType == 1)
  3749. {
  3750. entity.OrderState = 0;
  3751. entity.ReturnUserType = 1;
  3752. string clearman = GetPostString("clearman");
  3753. if (!string.IsNullOrEmpty(clearman))
  3754. {
  3755. entity.DesignUserId = 0;
  3756. }
  3757. }
  3758. else
  3759. {
  3760. entity.OrderState = 3;
  3761. entity.ReturnUserType = 2;
  3762. }
  3763. entity.IsReadTag = 1;
  3764. }
  3765. else if (returnTag == 1)
  3766. {
  3767. entity.OrderState = 5;
  3768. }
  3769. entity.IsVerifyToSupplier = false;
  3770. }
  3771. if (entity.IsXianHuo == 1)
  3772. {
  3773. entity.OrderState = 5;
  3774. }
  3775. entity.UnusualTag = 0;
  3776. entity.UnusualTime = null;
  3777. entity.UnusualCon = "";
  3778. entity.IsReturn = returnTag;
  3779. entity.ReturnTime = DateTime.Now;
  3780. entity.UpdateTime = DateTime.Now;
  3781. entity.ReturnReason = GetPostString("returnreason");
  3782. entity.Update();
  3783. if (entity.OrderState == 3)
  3784. {
  3785. ApiVo apiVo = new ApiVo();
  3786. apiVo.orderNumber = entity.ctid;
  3787. apiVo.actionName = "rebutDesign";
  3788. apiVo.orderRemarks = entity.ReturnReason;
  3789. designHelper.API_WorkCore(apiVo);//rebutDesign
  3790. }
  3791. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3792. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3793. {
  3794. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3795. }
  3796. CeErpSukuraData.createInfo(entity.ctid, 5);
  3797. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3798. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3799. if (isPlace)
  3800. {
  3801. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3802. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3803. if (dth != null && dth.Rows.Count > 0)
  3804. {
  3805. dataSendOrderBean dataSendOrderBean = null;
  3806. foreach (DataRow item in dth.Rows)
  3807. {
  3808. try
  3809. {
  3810. dataSendOrderBean = new dataSendOrderBean();
  3811. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3812. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3813. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3814. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3815. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3816. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3817. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3818. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3819. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3820. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3821. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3822. dataSendOrderBean.Radio1723534706288 = "打回";
  3823. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3824. if (result != null)
  3825. {
  3826. if ("0".Equals(result.errcode))
  3827. {
  3828. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3829. }
  3830. else
  3831. {
  3832. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3833. }
  3834. }
  3835. }
  3836. catch (Exception ex)
  3837. {
  3838. }
  3839. }
  3840. }
  3841. }
  3842. if (isNeedUpdateCell2)
  3843. {
  3844. if (entity.MakeSupplier.IndexOf(",") != -1)
  3845. {
  3846. StringBuilder sql2 = new StringBuilder();
  3847. 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);
  3848. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3849. }
  3850. else
  3851. {
  3852. StringBuilder sql2 = new StringBuilder();
  3853. 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);
  3854. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3855. }
  3856. }
  3857. returnSuccessMsg("操作成功!");
  3858. return;
  3859. }
  3860. returnErrorMsg("找不到订单记录");
  3861. }
  3862. }
  3863. public void cyt_erp_returnreason()
  3864. {
  3865. if (UrlPostParmsCheck("ctid"))
  3866. {
  3867. string eid = GetPostString("ctid");
  3868. CeErpTradeCell entity = null;
  3869. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3870. string userpost = CurrentUser.UserPost.Post.Code;
  3871. if (entity != null)
  3872. {
  3873. if (entity.OrderState > 6)
  3874. {
  3875. returnErrorMsg("已发货无法打回!");
  3876. return;
  3877. }
  3878. JObject jsonObject = new JObject
  3879. {
  3880. { "Userid", "77886" },
  3881. { "Pwd", "lt666888" },
  3882. { "LTOrderId",eid }
  3883. };
  3884. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3885. JObject jsonObjects = JObject.Parse(response);
  3886. string msg = (string)jsonObjects["msg"];
  3887. if (msg != "取消成功")
  3888. {
  3889. returnErrorMsg(msg);
  3890. return;
  3891. }
  3892. bool isNeedUpdateCell2 = false;
  3893. if (entity.OrderState >= 6)
  3894. {
  3895. isNeedUpdateCell2 = true;
  3896. }
  3897. int returnTag = 2;
  3898. if (userpost == "Supplier")
  3899. {
  3900. returnTag = 1;
  3901. }
  3902. if (entity.IsXianHuo == 0)
  3903. {
  3904. if (returnTag == 2)
  3905. {
  3906. int toType = GetPostInt("totype");
  3907. if (toType == 1)
  3908. {
  3909. entity.OrderState = 0;
  3910. entity.ReturnUserType = 1;
  3911. }
  3912. else
  3913. {
  3914. entity.OrderState = 4;
  3915. entity.ReturnUserType = 2;
  3916. }
  3917. entity.IsReadTag = 1;
  3918. }
  3919. else if (returnTag == 1)
  3920. {
  3921. entity.OrderState = 5;
  3922. }
  3923. entity.IsVerifyToSupplier = false;
  3924. }
  3925. entity.UnusualTag = 0;
  3926. entity.UnusualTime = null;
  3927. entity.UnusualCon = "";
  3928. entity.IsReturn = returnTag;
  3929. entity.ReturnTime = DateTime.Now;
  3930. entity.ReturnReason = GetPostString("returnreason");
  3931. entity.Update();
  3932. if (entity.OrderState == 4)
  3933. {
  3934. ApiVo apiVo = new ApiVo();
  3935. apiVo.orderNumber = entity.ctid;
  3936. apiVo.actionName = "rebutDesign";
  3937. apiVo.orderRemarks = entity.ReturnReason;
  3938. designHelper.API_WorkCore(apiVo);//rebutDesign
  3939. }
  3940. CeErpSukuraData.createInfo(entity.ctid, 5);
  3941. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3942. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3943. if (isNeedUpdateCell2)
  3944. {
  3945. if (entity.MakeSupplier.IndexOf(",") != -1)
  3946. {
  3947. StringBuilder sql2 = new StringBuilder();
  3948. 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);
  3949. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3950. }
  3951. else
  3952. {
  3953. StringBuilder sql2 = new StringBuilder();
  3954. 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);
  3955. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3956. }
  3957. }
  3958. returnSuccessMsg("操作成功!");
  3959. return;
  3960. }
  3961. returnErrorMsg("找不到订单记录");
  3962. }
  3963. }
  3964. public void upd_erp_xianhuoreturntag()
  3965. {
  3966. if (UrlPostParmsCheck("ctid"))
  3967. {
  3968. string eids = GetPostString("ctid");
  3969. string[] ctids = eids.Split(',');
  3970. foreach (string ctid in ctids)
  3971. {
  3972. CeErpTradeCell entity = null;
  3973. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3974. if (entity != null)
  3975. {
  3976. entity.IsReturn = 0;
  3977. entity.Update();
  3978. CeErpSukuraData.createInfo(entity.ctid, 5);
  3979. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3980. }
  3981. }
  3982. returnSuccessMsg("操作成功!");
  3983. return;
  3984. }
  3985. }
  3986. public void get_erp_waitdeliverylist()
  3987. {
  3988. DataStruct dStruct = GetPostStruct();
  3989. List<string> lw = new List<string>();
  3990. string tid = GetPostString("ctid");
  3991. if (tid.Length > 0)
  3992. {
  3993. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3994. if (tid.Length > 5)
  3995. {
  3996. List<string> tids = getTidByCtidLike(tid);
  3997. if (tids.Count > 0 && tids.Count < 10)
  3998. {
  3999. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4000. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4001. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4002. {
  4003. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4004. }
  4005. }
  4006. }
  4007. lw.Add(tid_sql);
  4008. }
  4009. string shopname = GetPostString("shopname");
  4010. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4011. string buyernick = GetPostString("buyer_nick");
  4012. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4013. //if (tid.Length == 0 && buyernick.Length == 0)
  4014. //{
  4015. // lw.Add(string.Format("IsRefund<={0}", 1));
  4016. //}
  4017. string customer = GetPostString("customer");
  4018. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4019. string design = GetPostString("design");
  4020. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4021. string orderState = GetPostString("orderState");
  4022. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4023. string address = GetPostString("address");
  4024. 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));
  4025. string sellermemo = GetPostString("seller_memo");
  4026. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4027. string supplier = GetPostString("supplier");
  4028. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4029. string OrderArea = GetPostString("order_area");
  4030. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4031. string placedate1 = GetPostString("placedate1");
  4032. string placedate2 = GetPostString("placedate2");
  4033. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4034. if (fdw.Length > 0) lw.Add(fdw);
  4035. string price1 = GetPostString("price1");
  4036. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4037. string price2 = GetPostString("price2");
  4038. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4039. string unusualCon = GetPostString("unusualcon");
  4040. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4041. string otherMemo = GetPostString("otherMemo");
  4042. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4043. string posTag = CurrentUser.UserPost.Post.Code;
  4044. if (posTag == "Supplier")
  4045. {
  4046. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4047. }
  4048. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4049. lw.Add(string.Format("type != 'PDD' "));
  4050. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4051. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4052. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4053. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4054. writeGridDataTableJson(dStruct.TotalCount, dt);
  4055. }
  4056. public void get_erp_changedeliverylist()
  4057. {
  4058. DataStruct dStruct = GetPostStruct();
  4059. List<string> lw = new List<string>();
  4060. string tid = GetPostString("ctid");
  4061. if (tid.Length > 0)
  4062. {
  4063. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4064. if (tid.Length > 5)
  4065. {
  4066. List<string> tids = getTidByCtidLike(tid);
  4067. if (tids.Count > 0 && tids.Count < 10)
  4068. {
  4069. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4070. }
  4071. }
  4072. lw.Add(tid_sql);
  4073. }
  4074. string shopname = GetPostString("shopname");
  4075. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4076. string buyernick = GetPostString("buyer_nick");
  4077. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4078. //if (tid.Length == 0 && buyernick.Length == 0)
  4079. //{
  4080. // lw.Add(string.Format("IsRefund<={0}", 1));
  4081. //}
  4082. string customer = GetPostString("customer");
  4083. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4084. string design = GetPostString("design");
  4085. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4086. string orderState = GetPostString("orderState");
  4087. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4088. string address = GetPostString("address");
  4089. 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));
  4090. string sellermemo = GetPostString("seller_memo");
  4091. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4092. string supplier = GetPostString("supplier");
  4093. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4094. string OrderArea = GetPostString("order_area");
  4095. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4096. string placedate1 = GetPostString("placedate1");
  4097. string placedate2 = GetPostString("placedate2");
  4098. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4099. if (fdw.Length > 0) lw.Add(fdw);
  4100. string price1 = GetPostString("price1");
  4101. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4102. string price2 = GetPostString("price2");
  4103. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4104. string unusualCon = GetPostString("unusualcon");
  4105. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4106. string otherMemo = GetPostString("otherMemo");
  4107. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4108. string posTag = CurrentUser.UserPost.Post.Code;
  4109. if (posTag == "Supplier")
  4110. {
  4111. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4112. }
  4113. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4114. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4115. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4116. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4117. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4118. /*if (tid.Length > 0)
  4119. {
  4120. List<string> tids = new List<string>();
  4121. if (dt != null && dt.Rows.Count > 0)
  4122. {
  4123. foreach (DataRow item in dt.Rows)
  4124. {
  4125. tids.Add("'" + item["tid"] + "'");
  4126. }
  4127. }
  4128. if (tids.Count > 0)
  4129. {
  4130. lw.RemoveAt(0);
  4131. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4132. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4133. dt = WebCache.GetData("view_erptradecell", dStruct);
  4134. }
  4135. }*/
  4136. writeGridDataTableJson(dStruct.TotalCount, dt);
  4137. }
  4138. public void get_erp_pddderiving()
  4139. {
  4140. DataStruct dStruct = GetPostStruct();
  4141. List<string> lw = new List<string>();
  4142. string tid = GetPostString("ctid");
  4143. if (tid.Length > 0)
  4144. {
  4145. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4146. if (tid.Length > 5)
  4147. {
  4148. List<string> tids = getTidByCtidLike(tid);
  4149. if (tids.Count > 0 && tids.Count < 10)
  4150. {
  4151. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4152. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4153. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4154. {
  4155. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4156. }
  4157. }
  4158. }
  4159. lw.Add(tid_sql);
  4160. }
  4161. string shopname = GetPostString("shopname");
  4162. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4163. string buyernick = GetPostString("buyer_nick");
  4164. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4165. //if (tid.Length == 0 && buyernick.Length == 0)
  4166. //{
  4167. // lw.Add(string.Format("IsRefund<={0}", 1));
  4168. //}
  4169. string customer = GetPostString("customer");
  4170. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4171. string design = GetPostString("design");
  4172. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4173. string orderState = GetPostString("orderState");
  4174. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4175. string address = GetPostString("address");
  4176. 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));
  4177. string sellermemo = GetPostString("seller_memo");
  4178. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4179. string supplier = GetPostString("supplier");
  4180. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4181. string OrderArea = GetPostString("order_area");
  4182. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4183. string placedate1 = GetPostString("placedate1");
  4184. string placedate2 = GetPostString("placedate2");
  4185. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4186. if (fdw.Length > 0) lw.Add(fdw);
  4187. string price1 = GetPostString("price1");
  4188. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4189. string price2 = GetPostString("price2");
  4190. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4191. string unusualCon = GetPostString("unusualcon");
  4192. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4193. string posTag = CurrentUser.UserPost.Post.Code;
  4194. if (posTag == "Supplier")
  4195. {
  4196. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4197. }
  4198. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4199. lw.Add(string.Format("type = 'PDD' "));
  4200. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4201. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4202. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4203. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4204. /*if (tid.Length > 0)
  4205. {
  4206. List<string> tids = new List<string>();
  4207. if (dt != null && dt.Rows.Count > 0)
  4208. {
  4209. foreach (DataRow item in dt.Rows)
  4210. {
  4211. tids.Add("'" + item["tid"] + "'");
  4212. }
  4213. }
  4214. if (tids.Count > 0)
  4215. {
  4216. lw.RemoveAt(0);
  4217. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4218. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4219. dt = WebCache.GetData("view_erptradecell", dStruct);
  4220. }
  4221. }*/
  4222. writeGridDataTableJson(dStruct.TotalCount, dt);
  4223. }
  4224. public void get_erp_jdderiving()
  4225. {
  4226. DataStruct dStruct = GetPostStruct();
  4227. List<string> lw = new List<string>();
  4228. string tid = GetPostString("ctid");
  4229. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4230. string shopname = GetPostString("shopname");
  4231. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4232. string buyernick = GetPostString("buyer_nick");
  4233. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4234. //if (tid.Length == 0 && buyernick.Length == 0)
  4235. //{
  4236. // lw.Add(string.Format("IsRefund<={0}", 1));
  4237. //}
  4238. string customer = GetPostString("customer");
  4239. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4240. string design = GetPostString("design");
  4241. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4242. string orderState = GetPostString("orderState");
  4243. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4244. string address = GetPostString("address");
  4245. 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));
  4246. string sellermemo = GetPostString("seller_memo");
  4247. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4248. string supplier = GetPostString("supplier");
  4249. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4250. string OrderArea = GetPostString("order_area");
  4251. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4252. string placedate1 = GetPostString("placedate1");
  4253. string placedate2 = GetPostString("placedate2");
  4254. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4255. if (fdw.Length > 0) lw.Add(fdw);
  4256. string price1 = GetPostString("price1");
  4257. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4258. string price2 = GetPostString("price2");
  4259. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4260. string unusualCon = GetPostString("unusualcon");
  4261. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4262. string posTag = CurrentUser.UserPost.Post.Code;
  4263. if (posTag == "Supplier")
  4264. {
  4265. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4266. }
  4267. lw.Add(string.Format("OrderState = 6 "));
  4268. lw.Add(string.Format("type = 'JD' "));
  4269. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4270. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4271. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4272. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4273. writeGridDataTableJson(dStruct.TotalCount, dt);
  4274. }
  4275. public void get_erp_demoorderlist()
  4276. {
  4277. DataStruct dStruct = GetPostStruct();
  4278. List<string> lw = new List<string>();
  4279. string tid = GetPostString("ctid");
  4280. if (tid.Length > 0)
  4281. {
  4282. string select_tid = getTidByCtid(tid);
  4283. lw.Add(string.Format("tid='{0}'", select_tid));
  4284. }
  4285. string shopname = GetPostString("shopname");
  4286. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4287. string buyernick = GetPostString("buyer_nick");
  4288. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4289. string customer = GetPostString("customer");
  4290. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4291. string design = GetPostString("design");
  4292. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4293. string orderState = GetPostString("orderState");
  4294. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4295. string address = GetPostString("address");
  4296. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4297. string sellermemo = GetPostString("seller_memo");
  4298. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4299. string supplier = GetPostString("supplier");
  4300. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4301. string OrderArea = GetPostString("order_area");
  4302. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4303. string date1 = GetPostString("date1");
  4304. string date2 = GetPostString("date2");
  4305. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4306. if (dw.Length > 0) lw.Add(dw);
  4307. string price1 = GetPostString("price1");
  4308. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4309. string price2 = GetPostString("price2");
  4310. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4311. string posTag = CurrentUser.UserPost.Post.Code;
  4312. if (posTag == "Supplier")
  4313. {
  4314. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4315. }
  4316. //lw.Add(string.Format("OrderState = 6 "));
  4317. lw.Add(string.Format("IsSample={0}", 3));
  4318. lw.Add(string.Format("IsRefund<={0}", 1));
  4319. dStruct.Order = "pay_time desc";
  4320. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4321. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4322. writeGridDataTableJson(dStruct.TotalCount, dt);
  4323. }
  4324. public void save_erp_checkmemo()
  4325. {
  4326. if (UrlPostParmsCheck("ctid"))
  4327. {
  4328. string ctid = GetPostString("ctid");
  4329. CeErpTradeCell entity = null;
  4330. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4331. if (entity != null)
  4332. {
  4333. entity.CheckMemo = GetPostString("CheckMemo");
  4334. entity.Update();
  4335. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4336. if (trade != null)
  4337. {
  4338. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4339. }
  4340. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4341. returnSuccessMsg("保存成功!");
  4342. return;
  4343. }
  4344. returnErrorMsg("找不到记录");
  4345. }
  4346. }
  4347. public void get_erp_returnlist()
  4348. {
  4349. DataStruct dStruct = GetPostStruct();
  4350. List<string> lw = new List<string>();
  4351. string tid = GetPostString("ctid");
  4352. if (tid.Length > 0)
  4353. {
  4354. string select_tid = getTidByCtid(tid);
  4355. lw.Add(string.Format("tid='{0}'", select_tid));
  4356. }
  4357. string shopname = GetPostString("shopname");
  4358. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4359. string buyernick = GetPostString("buyer_nick");
  4360. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4361. string customer = GetPostString("customer");
  4362. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4363. string design = GetPostString("design");
  4364. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4365. string orderState = GetPostString("orderState");
  4366. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4367. string address = GetPostString("address");
  4368. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4369. string sellermemo = GetPostString("seller_memo");
  4370. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4371. string supplier = GetPostString("supplier");
  4372. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4373. string date1 = GetPostString("date1");
  4374. string date2 = GetPostString("date2");
  4375. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4376. if (dw.Length > 0) lw.Add(dw);
  4377. string bdate1 = GetPostString("backdate1");
  4378. string bdate2 = GetPostString("backdate2");
  4379. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4380. if (dw_back.Length > 0) lw.Add(dw_back);
  4381. string price1 = GetPostString("price1");
  4382. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4383. string price2 = GetPostString("price2");
  4384. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4385. lw.Add(string.Format("IsReturn>0"));
  4386. lw.Add(string.Format("IsXianHuo=0"));
  4387. lw.Add(string.Format("IsReturn!=3"));
  4388. string backtype = GetPostString("backtype");
  4389. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4390. dStruct.Order = "FinishDesignTime desc";
  4391. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4392. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4393. writeGridDataTableJson(dStruct.TotalCount, dt);
  4394. }
  4395. public void get_erp_today_sumreturn()
  4396. {
  4397. DataStruct dStruct = GetPostStruct();
  4398. List<string> lw = new List<string>();
  4399. string bdate1 = GetPostString("returnTimeS");
  4400. string bdate2 = GetPostString("returnTimeE");
  4401. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4402. if (dw_back.Length > 0) lw.Add(dw_back);
  4403. lw.Add(string.Format("IsReturn=0"));
  4404. lw.Add(string.Format("IsXianHuo=0"));
  4405. string mainWhere = string.Join(" and ", lw.ToArray());
  4406. string sql = "";
  4407. if (dw_back.Length > 0)
  4408. {
  4409. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4410. }
  4411. else
  4412. {
  4413. 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 + "'";
  4414. }
  4415. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4416. decimal total = 0, today_finish = 0;
  4417. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4418. {
  4419. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4420. }
  4421. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4422. {
  4423. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4424. }
  4425. var res = new
  4426. {
  4427. data = total,
  4428. data1 = today_finish,
  4429. };
  4430. string ro_jsond = JsonConvert.SerializeObject(res);
  4431. returnSuccess(ro_jsond);
  4432. return;
  4433. }
  4434. public void get_erp_allreturnlist()
  4435. {
  4436. DataStruct dStruct = GetPostStruct();
  4437. List<string> lw = new List<string>();
  4438. string tid = GetPostString("ctid");
  4439. if (tid.Length > 0)
  4440. {
  4441. string select_tid = getTidByCtid(tid);
  4442. lw.Add(string.Format("tid='{0}'", select_tid));
  4443. }
  4444. string shopname = GetPostString("shopname");
  4445. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4446. string buyernick = GetPostString("buyer_nick");
  4447. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4448. string customer = GetPostString("customer");
  4449. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4450. string design = GetPostString("design");
  4451. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4452. string orderState = GetPostString("orderState");
  4453. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4454. string address = GetPostString("address");
  4455. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4456. string sellermemo = GetPostString("seller_memo");
  4457. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4458. string supplier = GetPostString("supplier");
  4459. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4460. string date1 = GetPostString("date1");
  4461. string date2 = GetPostString("date2");
  4462. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4463. if (dw.Length > 0) lw.Add(dw);
  4464. string bdate1 = GetPostString("backdate1");
  4465. string bdate2 = GetPostString("backdate2");
  4466. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4467. if (dw_back.Length > 0) lw.Add(dw_back);
  4468. string price1 = GetPostString("price1");
  4469. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4470. string price2 = GetPostString("price2");
  4471. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4472. string backreason = GetPostString("backreason");
  4473. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4474. lw.Add(string.Format("IsXianHuo=0"));
  4475. lw.Add(string.Format("ReturnTime != ''"));
  4476. string backtype = GetPostString("backtype");
  4477. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4478. dStruct.Order = "FinishDesignTime desc";
  4479. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4480. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4481. writeGridDataTableJson(dStruct.TotalCount, dt);
  4482. }
  4483. public void get_erp_aftersalereturnlist()
  4484. {
  4485. DataStruct dStruct = GetPostStruct();
  4486. List<string> lw = new List<string>();
  4487. string tid = GetPostString("ctid");
  4488. if (tid.Length > 0)
  4489. {
  4490. string select_tid = getTidByCtid(tid);
  4491. lw.Add(string.Format("tid='{0}'", select_tid));
  4492. }
  4493. string shopname = GetPostString("shopname");
  4494. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4495. string buyernick = GetPostString("buyer_nick");
  4496. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4497. string customer = GetPostString("customer");
  4498. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4499. string design = GetPostString("design");
  4500. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4501. string orderState = GetPostString("orderState");
  4502. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4503. string address = GetPostString("address");
  4504. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4505. string sellermemo = GetPostString("seller_memo");
  4506. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4507. string supplier = GetPostString("supplier");
  4508. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4509. string date1 = GetPostString("date1");
  4510. string date2 = GetPostString("date2");
  4511. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4512. if (dw.Length > 0) lw.Add(dw);
  4513. string bdate1 = GetPostString("backdate1");
  4514. string bdate2 = GetPostString("backdate2");
  4515. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4516. if (dw_back.Length > 0) lw.Add(dw_back);
  4517. string price1 = GetPostString("price1");
  4518. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4519. string price2 = GetPostString("price2");
  4520. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4521. lw.Add(string.Format("IsReturn=3"));
  4522. string backtype = GetPostString("backtype");
  4523. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4524. string backreason = GetPostString("backreason");
  4525. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4526. dStruct.Order = "ReturnTime desc";
  4527. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4528. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4529. writeGridDataTableJson(dStruct.TotalCount, dt);
  4530. }
  4531. public void get_erp_xianhuoreturnlist()
  4532. {
  4533. DataStruct dStruct = GetPostStruct();
  4534. List<string> lw = new List<string>();
  4535. string tid = GetPostString("ctid");
  4536. if (tid.Length > 0)
  4537. {
  4538. string select_tid = getTidByCtid(tid);
  4539. lw.Add(string.Format("tid='{0}'", select_tid));
  4540. }
  4541. string shopname = GetPostString("shopname");
  4542. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4543. string buyernick = GetPostString("buyer_nick");
  4544. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4545. string customer = GetPostString("customer");
  4546. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4547. string design = GetPostString("design");
  4548. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4549. string orderState = GetPostString("orderState");
  4550. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4551. string address = GetPostString("address");
  4552. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4553. string sellermemo = GetPostString("seller_memo");
  4554. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4555. string supplier = GetPostString("supplier");
  4556. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4557. string OrderArea = GetPostString("order_area");
  4558. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4559. string date1 = GetPostString("date1");
  4560. string date2 = GetPostString("date2");
  4561. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4562. if (dw.Length > 0) lw.Add(dw);
  4563. string price1 = GetPostString("price1");
  4564. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4565. string price2 = GetPostString("price2");
  4566. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4567. string posTag = CurrentUser.UserPost.Post.Code;
  4568. if (posTag == "Supplier")
  4569. {
  4570. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4571. }
  4572. lw.Add(string.Format("OrderState=6 "));
  4573. lw.Add(string.Format("IsXianHuo=1 "));
  4574. lw.Add(string.Format("IsReturn>0 "));
  4575. lw.Add(string.Format("IsReturn!=3"));
  4576. lw.Add(string.Format("IsRefund<={0}", 1));
  4577. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4578. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4579. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4580. writeGridDataTableJson(dStruct.TotalCount, dt);
  4581. }
  4582. public void set_erp_orderdelivery()
  4583. {
  4584. if (UrlPostParmsCheck("ctid"))
  4585. {
  4586. string eid = GetPostString("ctid");
  4587. CeErpTradeCell entity = null;
  4588. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4589. if (entity != null)
  4590. {
  4591. if (entity.OrderState >= 7)
  4592. {
  4593. returnErrorMsg("此单已发货,无需重复发货");
  4594. return;
  4595. }
  4596. if (entity.OrderState != 6)
  4597. {
  4598. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4599. return;
  4600. }
  4601. string shop = GetPostString("seller_nick");
  4602. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4603. string comName = GetPostString("comName");
  4604. string comCode = GetPostString("comCode");
  4605. string outSid = GetPostString("outSid");
  4606. string deliveryType = GetPostString("deliveryType");
  4607. string deliveryMemo = GetPostString("deliveryMemo");
  4608. outSid = outSid.Trim();
  4609. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4610. if (mainEn == null)
  4611. {
  4612. returnErrorMsg("找不到原始订单记录");
  4613. return;
  4614. }
  4615. bool isInitOrderDeliv = false;
  4616. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4617. {
  4618. isInitOrderDeliv = true;
  4619. }
  4620. string apires = "";
  4621. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4622. 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)
  4623. {
  4624. apires = "发货成功true";
  4625. }
  4626. else
  4627. {
  4628. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4629. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4630. }
  4631. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4632. {
  4633. entity.OrderState = 7;//发货后订单已发货
  4634. entity.OutSid = outSid;
  4635. entity.MemoOpt = 0;
  4636. entity.UpdateTime = DateTime.Now;
  4637. entity.FinishDeliveryTime = DateTime.Now;
  4638. entity.Update();
  4639. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4640. commonHelper.UpdateRelationOrder(entity.ctid);
  4641. //还要插入快递信息到 快递信息表
  4642. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4643. exinfo.tid = eid;
  4644. exinfo.out_sid = outSid;
  4645. exinfo.company_code = comCode;
  4646. exinfo.company_name = comName;
  4647. exinfo.delivery_memo = deliveryMemo;
  4648. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4649. exinfo.deliveryType = deliveryType;
  4650. exinfo.Create();
  4651. returnSuccessMsg("发货操作成功!");
  4652. commonHelper.UpdateRelationOrder(entity.ctid);
  4653. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4654. CeErpSukuraData.createInfo(entity.ctid, 4);
  4655. if (entity.SupplierId == 64)
  4656. {
  4657. commonHelper.sendCytExpress(exinfo);
  4658. }
  4659. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4660. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4661. }
  4662. else
  4663. {
  4664. string errmsg = commonHelper.KeepChinese(apires);
  4665. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4666. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4667. }
  4668. return;
  4669. }
  4670. returnErrorMsg("找不到订单记录");
  4671. }
  4672. }
  4673. public void set_erp_multidelivery()
  4674. {
  4675. string eids = GetPostString("tids");
  4676. string[] eidList = eids.Split(',');
  4677. if (eidList.Length <= 0)
  4678. {
  4679. returnErrorMsg("发货不能为空");
  4680. return;
  4681. }
  4682. foreach (string ctid in eidList)
  4683. {
  4684. if (ctid.Length <= 0) continue;
  4685. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4686. if (expInfo != null)
  4687. {
  4688. StringBuilder sql = new StringBuilder();
  4689. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4690. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4691. if (dt.Rows.Count > 0)
  4692. {
  4693. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4694. {
  4695. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4696. expInfo.state = "异常";
  4697. expInfo.isMultiDelivery = 1;
  4698. expInfo.Update();
  4699. continue;
  4700. }
  4701. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4702. {
  4703. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4704. expInfo.state = "异常";
  4705. expInfo.Update();
  4706. continue;
  4707. }
  4708. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4709. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4710. bool isInitOrderDeliv = false;
  4711. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4712. {
  4713. isInitOrderDeliv = true;
  4714. expInfo.isMultiDelivery = 1;
  4715. }
  4716. if (ctid.IndexOf("N") != -1)
  4717. {
  4718. StringBuilder sqlbucha = new StringBuilder();
  4719. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4720. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4721. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4722. commonHelper.UpdateRelationOrder(ctid);
  4723. expInfo.delivery_memo = "发货成功";
  4724. expInfo.state = "发货成功";
  4725. expInfo.isMultiDelivery = 1;
  4726. expInfo.Update();
  4727. }
  4728. else
  4729. {
  4730. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4731. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4732. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4733. {
  4734. expInfo.delivery_memo = "发货成功";
  4735. expInfo.state = "发货成功";
  4736. expInfo.isMultiDelivery = 1;
  4737. expInfo.Update();
  4738. commonHelper.UpdateRelationOrder(ctid);
  4739. CeErpSukuraData.createInfo(ctid, 4);
  4740. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4741. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4742. }
  4743. else
  4744. {
  4745. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4746. expInfo.state = "异常";
  4747. expInfo.Update();
  4748. }
  4749. }
  4750. }
  4751. }
  4752. }
  4753. returnSuccessMsg("操作完成");
  4754. }
  4755. public void reset_erp_memoopt()
  4756. {
  4757. if (UrlPostParmsCheck("ctid"))
  4758. {
  4759. string eid = GetPostString("ctid");
  4760. CeErpTradeCell entity = null;
  4761. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4762. if (entity != null)
  4763. {
  4764. string stropt = "";
  4765. if (entity.MemoOpt == 1)
  4766. {
  4767. stropt = "“改稿”";
  4768. }
  4769. else if (entity.MemoOpt == 2)
  4770. {
  4771. stropt = "“定稿”";
  4772. }
  4773. else if (entity.MemoOpt == 3)
  4774. {
  4775. stropt = "“完成查货”";
  4776. CeErpSukuraData.createInfo(entity.ctid, 6);
  4777. }
  4778. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4779. entity.UpdateTime = DateTime.Now;
  4780. entity.MemoOpt = 0;
  4781. entity.Update();
  4782. returnSuccessMsg("操作成功!");
  4783. return;
  4784. }
  4785. returnErrorMsg("找不到记录");
  4786. }
  4787. }
  4788. public void get_erp_deliveryunusual()
  4789. {
  4790. DataStruct dStruct = GetPostStruct();
  4791. List<string> lw = new List<string>();
  4792. string tid = GetPostString("ctid");
  4793. if (tid.Length > 0)
  4794. {
  4795. string select_tid = getTidByCtid(tid);
  4796. lw.Add(string.Format("tid='{0}'", select_tid));
  4797. }
  4798. string shopname = GetPostString("shopname");
  4799. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4800. string buyernick = GetPostString("buyer_nick");
  4801. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4802. string customer = GetPostString("customer");
  4803. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4804. string design = GetPostString("design");
  4805. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4806. string sellermemo = GetPostString("seller_memo");
  4807. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4808. string supplier = GetPostString("supplier");
  4809. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4810. string date1 = GetPostString("date1");
  4811. string date2 = GetPostString("date2");
  4812. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4813. if (dw.Length > 0) lw.Add(dw);
  4814. string placedate1 = GetPostString("placedate1");
  4815. string placedate2 = GetPostString("placedate2");
  4816. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4817. if (dw_place.Length > 0) lw.Add(dw_place);
  4818. string price1 = GetPostString("price1");
  4819. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4820. string price2 = GetPostString("price2");
  4821. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4822. string unusualCon = GetPostString("unusualcon");
  4823. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4824. string posTag = CurrentUser.UserPost.Post.Code;
  4825. if (posTag == "Supplier")
  4826. {
  4827. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4828. }
  4829. lw.Add(string.Format("OrderState = 6"));
  4830. lw.Add(string.Format("UnusualTag = 5"));
  4831. lw.Add(string.Format("IsRefund<={0}", 1));
  4832. dStruct.Order = "FinishPlaceTime desc";
  4833. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4834. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4835. writeGridDataTableJson(dStruct.TotalCount, dt);
  4836. }
  4837. public void get_erp_deliveryedlist()
  4838. {
  4839. DataStruct dStruct = GetPostStruct();
  4840. List<string> lw = new List<string>();
  4841. string tid = GetPostString("ctid");
  4842. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4843. string shopname = GetPostString("shopname");
  4844. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4845. string buyernick = GetPostString("buyer_nick");
  4846. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4847. string customer = GetPostString("customer");
  4848. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4849. string design = GetPostString("design");
  4850. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4851. string sellermemo = GetPostString("seller_memo");
  4852. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4853. string logistics = GetPostString("logistics");
  4854. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4855. string date1 = GetPostString("date1");
  4856. string date2 = GetPostString("date2");
  4857. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4858. //if (dw.Length > 0) lw.Add(dw);
  4859. string placedate1 = GetPostString("placedate1");
  4860. string placedate2 = GetPostString("placedate2");
  4861. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4862. if (fdw.Length > 0) lw.Add(fdw);
  4863. string devdate1 = GetPostString("deliverydate1");
  4864. string devdate2 = GetPostString("deliverydate2");
  4865. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4866. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4867. string price1 = GetPostString("price1");
  4868. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4869. string price2 = GetPostString("price2");
  4870. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4871. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4872. {
  4873. if (tid.Length > 0)
  4874. {
  4875. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4876. if (tid.Length > 5)
  4877. {
  4878. List<string> tids = getTidByCtidLike(tid);
  4879. if (tids.Count > 0 && tids.Count < 10)
  4880. {
  4881. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4882. }
  4883. }
  4884. lw.Add(tid_sql);
  4885. }
  4886. if (buyernick.Length > 0)
  4887. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4888. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4889. if (dw.Length > 0) lw.Add(dw);
  4890. }
  4891. else
  4892. {
  4893. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4894. }
  4895. string posTag = CurrentUser.UserPost.Post.Code;
  4896. if (posTag == "Supplier")
  4897. {
  4898. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4899. }
  4900. else
  4901. {
  4902. string supplier = GetPostString("supplier");
  4903. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4904. }
  4905. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4906. lw.Add(string.Format("type != 'PDD' "));
  4907. lw.Add(string.Format("IsRefund!={0}", 2));
  4908. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4909. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4910. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4911. /*if (tid.Length > 0)
  4912. {
  4913. List<string> tids = new List<string>();
  4914. if (dt != null && dt.Rows.Count > 0)
  4915. {
  4916. foreach (DataRow item in dt.Rows)
  4917. {
  4918. tids.Add("'" + item["tid"] + "'");
  4919. }
  4920. }
  4921. if (tids.Count > 0)
  4922. {
  4923. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4924. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4925. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4926. dt = WebCache.GetData("view_erptradecell", dStruct);
  4927. }
  4928. }*/
  4929. if (dt != null)
  4930. {
  4931. foreach (DataRow dr in dt.Rows)
  4932. {
  4933. 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();
  4934. }
  4935. }
  4936. writeGridDataTableJson(dStruct.TotalCount, dt);
  4937. }
  4938. public void get_erp_pdddeliveryed()
  4939. {
  4940. DataStruct dStruct = GetPostStruct();
  4941. List<string> lw = new List<string>();
  4942. string tid = GetPostString("ctid");
  4943. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4944. string shopname = GetPostString("shopname");
  4945. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4946. string buyernick = GetPostString("buyer_nick");
  4947. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4948. string customer = GetPostString("customer");
  4949. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4950. string design = GetPostString("design");
  4951. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4952. string sellermemo = GetPostString("seller_memo");
  4953. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4954. string logistics = GetPostString("logistics");
  4955. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4956. string date1 = GetPostString("date1");
  4957. string date2 = GetPostString("date2");
  4958. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4959. //if (dw.Length > 0) lw.Add(dw);
  4960. string placedate1 = GetPostString("placedate1");
  4961. string placedate2 = GetPostString("placedate2");
  4962. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4963. if (fdw.Length > 0) lw.Add(fdw);
  4964. string devdate1 = GetPostString("deliverydate1");
  4965. string devdate2 = GetPostString("deliverydate2");
  4966. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4967. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4968. string price1 = GetPostString("price1");
  4969. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4970. string price2 = GetPostString("price2");
  4971. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4972. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4973. {
  4974. if (tid.Length > 0)
  4975. {
  4976. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4977. if (tid.Length > 5)
  4978. {
  4979. List<string> tids = getTidByCtidLike(tid);
  4980. if (tids.Count > 0 && tids.Count < 10)
  4981. {
  4982. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4983. }
  4984. }
  4985. lw.Add(tid_sql);
  4986. }
  4987. if (buyernick.Length > 0)
  4988. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4989. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4990. if (dw.Length > 0) lw.Add(dw);
  4991. }
  4992. else
  4993. {
  4994. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  4995. }
  4996. string posTag = CurrentUser.UserPost.Post.Code;
  4997. if (posTag == "Supplier")
  4998. {
  4999. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5000. }
  5001. else
  5002. {
  5003. string supplier = GetPostString("supplier");
  5004. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5005. }
  5006. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5007. lw.Add(string.Format("type = 'PDD' "));
  5008. lw.Add(string.Format("IsRefund!={0}", 2));
  5009. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5010. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5011. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5012. /* if (tid.Length > 0)
  5013. {
  5014. List<string> tids = new List<string>();
  5015. if (dt != null && dt.Rows.Count > 0)
  5016. {
  5017. foreach (DataRow item in dt.Rows)
  5018. {
  5019. tids.Add("'" + item["tid"] + "'");
  5020. }
  5021. }
  5022. if (tids.Count > 0)
  5023. {
  5024. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5025. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5026. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5027. dt = WebCache.GetData("view_erptradecell", dStruct);
  5028. }
  5029. }*/
  5030. foreach (DataRow dr in dt.Rows)
  5031. {
  5032. 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();
  5033. }
  5034. writeGridDataTableJson(dStruct.TotalCount, dt);
  5035. }
  5036. public void get_erp_jddeliveryed()
  5037. {
  5038. DataStruct dStruct = GetPostStruct();
  5039. List<string> lw = new List<string>();
  5040. string tid = GetPostString("ctid");
  5041. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5042. string shopname = GetPostString("shopname");
  5043. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5044. string buyernick = GetPostString("buyer_nick");
  5045. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5046. string customer = GetPostString("customer");
  5047. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5048. string design = GetPostString("design");
  5049. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5050. string sellermemo = GetPostString("seller_memo");
  5051. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5052. string date1 = GetPostString("date1");
  5053. string date2 = GetPostString("date2");
  5054. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5055. //if (dw.Length > 0) lw.Add(dw);
  5056. string placedate1 = GetPostString("placedate1");
  5057. string placedate2 = GetPostString("placedate2");
  5058. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5059. if (fdw.Length > 0) lw.Add(fdw);
  5060. string devdate1 = GetPostString("deliverydate1");
  5061. string devdate2 = GetPostString("deliverydate2");
  5062. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5063. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5064. string price1 = GetPostString("price1");
  5065. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5066. string price2 = GetPostString("price2");
  5067. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5068. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5069. {
  5070. if (tid.Length > 0)
  5071. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5072. if (buyernick.Length > 0)
  5073. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5074. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5075. if (dw.Length > 0) lw.Add(dw);
  5076. }
  5077. else
  5078. {
  5079. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5080. }
  5081. string posTag = CurrentUser.UserPost.Post.Code;
  5082. if (posTag == "Supplier")
  5083. {
  5084. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5085. }
  5086. else
  5087. {
  5088. string supplier = GetPostString("supplier");
  5089. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5090. }
  5091. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5092. lw.Add(string.Format("type = 'JD' "));
  5093. lw.Add(string.Format("IsRefund!={0}", 2));
  5094. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5095. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5096. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5097. foreach (DataRow dr in dt.Rows)
  5098. {
  5099. 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();
  5100. }
  5101. writeGridDataTableJson(dStruct.TotalCount, dt);
  5102. }
  5103. public void get_erp_allplacelist()
  5104. {
  5105. DataStruct dStruct = GetPostStruct();
  5106. List<string> lw = new List<string>();
  5107. string tid = GetPostString("ctid");
  5108. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5109. string shopname = GetPostString("shopname");
  5110. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5111. string buyernick = GetPostString("buyer_nick");
  5112. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5113. string customer = GetPostString("customer");
  5114. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5115. string design = GetPostString("design");
  5116. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5117. string sellermemo = GetPostString("seller_memo");
  5118. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5119. string supplier = GetPostString("supplier");
  5120. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5121. string date1 = GetPostString("date1");
  5122. string date2 = GetPostString("date2");
  5123. string pldate1 = GetPostString("placedate1");
  5124. string pldate2 = GetPostString("placedate2");
  5125. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5126. //if (dw.Length > 0) lw.Add(dw);
  5127. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5128. {
  5129. if (tid.Length > 0)
  5130. {
  5131. string select_tid = getTidByCtid(tid);
  5132. lw.Add(string.Format("tid='{0}'", select_tid));
  5133. }
  5134. if (buyernick.Length > 0)
  5135. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5136. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5137. if (dw.Length > 0) lw.Add(dw);
  5138. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5139. if (dw_place.Length > 0) lw.Add(dw_place);
  5140. }
  5141. else
  5142. {
  5143. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5144. {
  5145. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5146. }
  5147. }
  5148. string price1 = GetPostString("price1");
  5149. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5150. string price2 = GetPostString("price2");
  5151. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5152. string posTag = CurrentUser.UserPost.Post.Code;
  5153. if (posTag == "Supplier")
  5154. {
  5155. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5156. }
  5157. lw.Add(string.Format("OrderState >= 6"));
  5158. lw.Add(string.Format("IsSample != 2 "));
  5159. //lw.Add(string.Format("isDianziOrder = 0 "));
  5160. lw.Add(string.Format("SupplierId > 0 "));
  5161. //lw.Add(string.Format("IsRefund<={0}", 1));
  5162. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5163. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5164. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5165. foreach (DataRow dr in dt.Rows)
  5166. {
  5167. 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();
  5168. }
  5169. writeGridDataTableJson(dStruct.TotalCount, dt);
  5170. }
  5171. public void get_erp_financeallplacelist()
  5172. {
  5173. DataStruct dStruct = GetPostStruct();
  5174. List<string> lw = new List<string>();
  5175. string tid = GetPostString("ctid");
  5176. string shopname = GetPostString("shopname");
  5177. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5178. string buyernick = GetPostString("buyer_nick");
  5179. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5180. string customer = GetPostString("customer");
  5181. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5182. string design = GetPostString("design");
  5183. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5184. string sellermemo = GetPostString("seller_memo");
  5185. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5186. string supplier = GetPostString("supplier");
  5187. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5188. string date1 = GetPostString("date1");
  5189. string date2 = GetPostString("date2");
  5190. string pldate1 = GetPostString("placedate1");
  5191. string pldate2 = GetPostString("placedate2");
  5192. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5193. {
  5194. if (tid.Length > 0)
  5195. {
  5196. string select_tid = getTidByCtid(tid);
  5197. lw.Add(string.Format("tid='{0}'", select_tid));
  5198. }
  5199. if (buyernick.Length > 0)
  5200. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5201. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5202. if (dw.Length > 0) lw.Add(dw);
  5203. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5204. if (dw_place.Length > 0) lw.Add(dw_place);
  5205. }
  5206. else
  5207. {
  5208. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5209. {
  5210. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5211. }
  5212. }
  5213. string price1 = GetPostString("price1");
  5214. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5215. string price2 = GetPostString("price2");
  5216. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5217. string posTag = CurrentUser.UserPost.Post.Code;
  5218. if (posTag == "Supplier")
  5219. {
  5220. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5221. }
  5222. //lw.Add(string.Format("OrderState >= 6"));
  5223. lw.Add(string.Format("IsSample != 2 "));
  5224. lw.Add(string.Format("isDianziOrder = 0 "));
  5225. //lw.Add(string.Format("IsRefund<={0}", 1));
  5226. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5227. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5228. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5229. foreach (DataRow dr in dt.Rows)
  5230. {
  5231. 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();
  5232. }
  5233. writeGridDataTableJson(dStruct.TotalCount, dt);
  5234. }
  5235. public void get_erp_expresslist()
  5236. {
  5237. int listtype = GetInt("ltype");
  5238. DataStruct dStruct = GetPostStruct();
  5239. List<string> lw = new List<string>();
  5240. string tid = GetPostString("tid");
  5241. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5242. string outsid = GetPostString("out_sid");
  5243. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5244. string importer = GetPostString("ImportUserName");
  5245. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5246. string file = GetPostString("import_file");
  5247. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5248. string printman = GetPostString("printman");
  5249. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5250. string date1 = GetPostString("date1");
  5251. string date2 = GetPostString("date2");
  5252. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5253. if (dw.Length > 0) lw.Add(dw);
  5254. string fdate1 = GetPostString("finishdate1");
  5255. string fdate2 = GetPostString("finishdate2");
  5256. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5257. if (fdw.Length > 0) lw.Add(fdw);
  5258. string supplierId = GetPostString("supplierId");
  5259. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5260. if (listtype == 1)
  5261. {
  5262. lw.Add(string.Format("importUserId !=0"));
  5263. }
  5264. string posTag = CurrentUser.UserPost.Post.Code;
  5265. if (posTag == "Supplier")
  5266. {
  5267. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5268. }
  5269. if (dStruct.PageSize != 100000)
  5270. {
  5271. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5272. }
  5273. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5274. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5275. writeGridDataTableJson(dStruct.TotalCount, dt);
  5276. }
  5277. public void set_erp_buchaorderdelivery()
  5278. {
  5279. if (UrlPostParmsCheck("ctid"))
  5280. {
  5281. string eid = GetPostString("ctid");
  5282. CeErpTradeCell entity = null;
  5283. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5284. if (entity != null)
  5285. {
  5286. if (entity.IsSample != 2)
  5287. {
  5288. returnErrorMsg("补差价单才能标记为已发货");
  5289. return;
  5290. }
  5291. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5292. entity.OrderState = 7;
  5293. entity.Update();
  5294. returnSuccessMsg("操作成功!");
  5295. return;
  5296. }
  5297. returnErrorMsg("找不到记录");
  5298. }
  5299. }
  5300. public void get_stdtemplates()
  5301. {
  5302. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5303. //string res = taobaoHelper.test();
  5304. string res = apiHelper.API_PrintTemplate();
  5305. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5306. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5307. {
  5308. int sidx = res.IndexOf("error_code");
  5309. int eidx = res.IndexOf("success");
  5310. string msg = res.Substring(sidx, eidx - sidx);
  5311. returnErrorMsg(msg);
  5312. return;
  5313. }
  5314. if (res.Length <= 0)
  5315. {
  5316. returnErrorMsg("模板数据为空!");
  5317. return;
  5318. }
  5319. ReturnSuccess(res);
  5320. }
  5321. public void cancel_print_order()
  5322. {
  5323. if (UrlPostParmsCheck("ctid"))
  5324. {
  5325. string ctid = GetPostString("ctid");
  5326. CeErpTradeCell entity = null;
  5327. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5328. if (entity != null)
  5329. {
  5330. string res = "";
  5331. string code = entity.LastBillWaybillCode;
  5332. if (code == "")
  5333. {
  5334. code = entity.OutSid;
  5335. }
  5336. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5337. XLog.SaveLog(0, "取消面单" + res);
  5338. }
  5339. }
  5340. }
  5341. public void set_erp_printwaybill()
  5342. {
  5343. if (UrlPostParmsCheck("ctid"))
  5344. {
  5345. string ctid = GetPostString("ctid");
  5346. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5347. string cpName = GetPostString("cpname");
  5348. string isTogether = GetPostString("together");
  5349. //var res_obj = new
  5350. //{
  5351. // restype = 1,
  5352. // 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\"}"
  5353. //};
  5354. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5355. //ReturnSuccess(ro_json);
  5356. //return;
  5357. bool isUseLastWayBillCode = false;
  5358. CeErpTradeCell entity = null;
  5359. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5360. if (entity != null)
  5361. {
  5362. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5363. {
  5364. isUseLastWayBillCode = true;
  5365. }
  5366. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5367. {
  5368. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5369. return;
  5370. }
  5371. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5372. {
  5373. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5374. return;
  5375. }
  5376. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5377. {
  5378. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5379. return;
  5380. }
  5381. }
  5382. string res = "";
  5383. Api_waybill_code_response_Obj fullObj = null;
  5384. string pData_str = "";
  5385. string curUseWayBillCode = "";
  5386. if (isUseLastWayBillCode == false)
  5387. {
  5388. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5389. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5390. if (res.IndexOf("failure") != -1)
  5391. {
  5392. //int idx = res.IndexOf("sub_message");
  5393. //int idx2 = res.IndexOf("flag");
  5394. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5395. string errMsgNeed = commonHelper.KeepChinese(res);
  5396. var res_objd = new
  5397. {
  5398. restype = 0,
  5399. data = "获取面单失败" + errMsgNeed
  5400. };
  5401. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5402. returnSuccess(ro_jsond);
  5403. if (res.IndexOf("停发") != -1)
  5404. {
  5405. entity.UnusualCon = "物流停发";
  5406. entity.Update();
  5407. }
  5408. //returnErrorMsg("获取面单失败,"+emsg);
  5409. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5410. return;
  5411. }
  5412. else if (res.IndexOf("errorMsg") != -1)
  5413. {
  5414. //int idx = res.IndexOf("errorMsg");
  5415. //int idx2 = res.IndexOf("}]}");
  5416. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5417. string errMsgNeed = commonHelper.KeepChinese(res);
  5418. var res_objf = new
  5419. {
  5420. restype = 0,
  5421. data = "获取面单失败2" + errMsgNeed
  5422. };
  5423. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5424. if (res.IndexOf("停发") != -1)
  5425. {
  5426. entity.UnusualCon = "物流停发";
  5427. entity.Update();
  5428. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5429. if (trade != null)
  5430. {
  5431. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5432. }
  5433. }
  5434. returnSuccess(ro_jsonf);
  5435. //returnErrorMsg("获取面单失败," + emsg);
  5436. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5437. return;
  5438. }
  5439. try
  5440. {
  5441. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5442. //res = res.Replace(" ", "");
  5443. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5444. }
  5445. catch (Exception ex)
  5446. {
  5447. XLog.SaveLog(0, "生成fullObj" + res);
  5448. var res_objf = new
  5449. {
  5450. restype = 0,
  5451. data = "生成fullObj发生错误" + ex.Message
  5452. };
  5453. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5454. returnSuccess(ro_jsonf);
  5455. return;
  5456. }
  5457. if (fullObj.response.data.content.Count > 0)
  5458. {
  5459. ContentItem codeObj = fullObj.response.data.content[0];
  5460. if (cpCode.IndexOf("SFFQ-") != -1)
  5461. {
  5462. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5463. }
  5464. else
  5465. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5466. curUseWayBillCode = codeObj.waybillCode;
  5467. }
  5468. else
  5469. {
  5470. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5471. var res_objf = new
  5472. {
  5473. restype = 0,
  5474. data = "生成fullObj找不到快递单号waybillCode"
  5475. };
  5476. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5477. returnSuccess(ro_jsonf);
  5478. return;
  5479. }
  5480. }
  5481. else
  5482. {
  5483. //使用上次打印的快递单号
  5484. if (cpCode == "SFFQ-LY")
  5485. {
  5486. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5487. }
  5488. else
  5489. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5490. curUseWayBillCode = entity.LastBillWaybillCode;
  5491. }
  5492. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5493. {
  5494. var res_obje = new
  5495. {
  5496. restype = 0,
  5497. data = "获取加密打印数据失败"
  5498. };
  5499. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5500. returnSuccess(ro_jsone);
  5501. entity.LastBillCpCode = cpCode;
  5502. entity.LastBillWaybillCode = curUseWayBillCode;
  5503. entity.Update();
  5504. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5505. //returnErrorMsg("获取加密打印数据失败");
  5506. return;
  5507. }
  5508. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5509. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5510. string btnType = "";
  5511. string errorMsg = "";
  5512. if (entity != null)
  5513. {
  5514. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5515. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5516. //cpcode是 YTO-CAINIAO
  5517. //string comCode = cpCode.Split('-')[0].ToString();
  5518. string apires = "";
  5519. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5520. //isTogether=2是新的合包弹窗
  5521. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5522. {
  5523. if (ctid.IndexOf("N") != -1)
  5524. {
  5525. apires = "发货成功";
  5526. }
  5527. else
  5528. {
  5529. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5530. }
  5531. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5532. //打单后发货
  5533. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5534. {
  5535. try
  5536. {
  5537. btnType = "待发货";
  5538. entity.OutSid = curUseWayBillCode;
  5539. entity.OrderState = 7;
  5540. entity.IsUrgency = false;
  5541. entity.LastBillCpCode = "";
  5542. entity.LastBillWaybillCode = "";
  5543. entity.FinishDeliveryTime = DateTime.Now;
  5544. entity.IsReturn = 0;
  5545. entity.MemoOpt = 0;
  5546. entity.UpdateTime = DateTime.Now;
  5547. entity.Update();
  5548. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5549. //还要插入快递信息到 快递信息表
  5550. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5551. exinfo.tid = entity.ctid;
  5552. exinfo.out_sid = curUseWayBillCode;
  5553. exinfo.company_code = cpCode;
  5554. exinfo.company_name = cpName;
  5555. exinfo.supplierUserName = supplierName;
  5556. exinfo.deliveryType = "发货成功";
  5557. exinfo.print_time = DateTime.Now;
  5558. exinfo.printUser = CurrentUser.UserName;
  5559. exinfo.postData = pData_str;
  5560. exinfo.Create();
  5561. commonHelper.UpdateRelationOrder(entity.ctid);
  5562. CeErpSukuraData.createInfo(ctid, 4);
  5563. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5564. if (entity.SupplierId == 64)
  5565. {
  5566. commonHelper.sendCytExpress(exinfo);
  5567. }
  5568. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5569. if (!string.IsNullOrEmpty(isTogether))
  5570. {
  5571. if (Convert.ToInt32(isTogether) > 0)
  5572. {
  5573. StringBuilder sqlsb = new StringBuilder();
  5574. 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);
  5575. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5576. }
  5577. }
  5578. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5579. }
  5580. catch (Exception ex)
  5581. {
  5582. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5583. }
  5584. }
  5585. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5586. {
  5587. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5588. if (entity.OrderState == 6)
  5589. {
  5590. entity.OrderState = 7;
  5591. }
  5592. entity.UpdateTime = DateTime.Now;
  5593. entity.FinishDeliveryTime = DateTime.Now;
  5594. btnType = "已发货";
  5595. entity.Update();
  5596. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5597. exinfo.tid = entity.ctid;
  5598. exinfo.out_sid = curUseWayBillCode;
  5599. exinfo.company_code = cpCode;
  5600. exinfo.company_name = cpName;
  5601. exinfo.supplierUserName = supplierName;
  5602. exinfo.deliveryType = "发货成功";
  5603. exinfo.print_time = DateTime.Now;
  5604. exinfo.printUser = CurrentUser.UserName;
  5605. exinfo.postData = pData_str;
  5606. exinfo.Create();
  5607. commonHelper.UpdateRelationOrder(entity.ctid);
  5608. CeErpSukuraData.createInfo(entity.ctid, 4);
  5609. if (entity.SupplierId == 64)
  5610. {
  5611. commonHelper.sendCytExpress(exinfo);
  5612. }
  5613. if (!string.IsNullOrEmpty(isTogether))
  5614. {
  5615. if (Convert.ToInt32(isTogether) > 0)
  5616. {
  5617. StringBuilder sqlsb = new StringBuilder();
  5618. 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);
  5619. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5620. }
  5621. }
  5622. //不处理
  5623. }
  5624. else
  5625. {
  5626. entity.UpdateTime = DateTime.Now;
  5627. entity.LastBillCpCode = cpCode;
  5628. entity.LastBillWaybillCode = curUseWayBillCode;
  5629. entity.Update();
  5630. string errmsg = commonHelper.KeepChinese(apires);
  5631. var res_objz = new
  5632. {
  5633. restype = 0,
  5634. data = "打单后发货失败"
  5635. };
  5636. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5637. returnSuccess(ro_jsonz);
  5638. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5639. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5640. return;
  5641. }
  5642. }
  5643. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5644. {
  5645. string ctids = GetPostString("ctids");
  5646. DataTable dt = getSameOrderList(entity, mainEn);
  5647. List<string> list = new List<string>();
  5648. List<string> send_list = new List<string>();
  5649. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5650. CeErpTrade ceErpTrade = new CeErpTrade();
  5651. //可合包的合并一起发货
  5652. if (dt == null && string.IsNullOrEmpty(ctids))
  5653. {
  5654. var res_objz = new
  5655. {
  5656. restype = 0,
  5657. data = "打单后发货失败"
  5658. };
  5659. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5660. returnSuccess(ro_jsonz);
  5661. return;
  5662. }
  5663. if (!string.IsNullOrEmpty(ctids))
  5664. {
  5665. StringBuilder sql = new StringBuilder();
  5666. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5667. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5668. }
  5669. foreach (DataRow row in dt.Rows)
  5670. {
  5671. list.Add("'" + row["ctid"] + "'");
  5672. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5673. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5674. if (ctid.IndexOf("N") != -1)
  5675. {
  5676. apires = "发货成功";
  5677. }
  5678. else
  5679. {
  5680. if (!send_list.Contains(ceErpTrade.tid))
  5681. {
  5682. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5683. }
  5684. else
  5685. {
  5686. apires = "发货成功";
  5687. }
  5688. }
  5689. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5690. {
  5691. send_list.Add(ceErpTrade.tid);
  5692. try
  5693. {
  5694. btnType = "待发货";
  5695. ceErpTradeCell.OutSid = curUseWayBillCode;
  5696. ceErpTradeCell.OrderState = 7;
  5697. ceErpTradeCell.IsUrgency = false;
  5698. ceErpTradeCell.LastBillCpCode = "";
  5699. ceErpTradeCell.LastBillWaybillCode = "";
  5700. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5701. ceErpTradeCell.IsReturn = 0;
  5702. ceErpTradeCell.MemoOpt = 0;
  5703. ceErpTradeCell.UpdateTime = DateTime.Now;
  5704. ceErpTradeCell.Update();
  5705. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5706. //还要插入快递信息到 快递信息表
  5707. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5708. exinfo.tid = ceErpTradeCell.ctid;
  5709. exinfo.out_sid = curUseWayBillCode;
  5710. exinfo.company_code = cpCode;
  5711. exinfo.company_name = cpName;
  5712. exinfo.supplierUserName = supplierName;
  5713. exinfo.deliveryType = "发货成功";
  5714. exinfo.print_time = DateTime.Now;
  5715. exinfo.printUser = CurrentUser.UserName;
  5716. exinfo.postData = pData_str;
  5717. exinfo.Create();
  5718. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5719. CeErpSukuraData.createInfo(ctid, 4);
  5720. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5721. if (ceErpTradeCell.SupplierId == 64)
  5722. {
  5723. commonHelper.sendCytExpress(exinfo);
  5724. }
  5725. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5726. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5727. }
  5728. catch (Exception ex)
  5729. {
  5730. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5731. }
  5732. }
  5733. else
  5734. {
  5735. ceErpTradeCell.UpdateTime = DateTime.Now;
  5736. ceErpTradeCell.LastBillCpCode = cpCode;
  5737. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5738. ceErpTradeCell.Update();
  5739. string errmsg = commonHelper.KeepChinese(apires);
  5740. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5741. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5742. }
  5743. }
  5744. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5745. }
  5746. }
  5747. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5748. var res_obj = new
  5749. {
  5750. restype = 1,
  5751. data = pData_str,
  5752. errorMsg
  5753. };
  5754. string ro_json = JsonConvert.SerializeObject(res_obj);
  5755. ReturnSuccess(ro_json);
  5756. return;
  5757. }
  5758. }
  5759. private string GetUTF8String(byte[] vs)
  5760. {
  5761. throw new NotImplementedException();
  5762. }
  5763. public void set_erp_printwaybill_cn()
  5764. {
  5765. if (UrlPostParmsCheck("ctid"))
  5766. {
  5767. string ctid = GetPostString("ctid");
  5768. string cpCode = GetPostString("cpcode");
  5769. string cpName = GetPostString("cpname");
  5770. string tempUrl = GetPostString("tempurl");
  5771. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5772. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5773. //string res = taobaoHelper.test();
  5774. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5775. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5776. {
  5777. int sidx = res.IndexOf("errorMsg");
  5778. int eidx = res.IndexOf("}");
  5779. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5780. var res_objzxx = new
  5781. {
  5782. restype = 0,
  5783. data = msg
  5784. };
  5785. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5786. returnSuccess(ro_jsonzxx);
  5787. //returnErrorMsg(msg);
  5788. return;
  5789. }
  5790. int idx = res.IndexOf("waybillCode");
  5791. int idx2 = res.IndexOf("printData");
  5792. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5793. string eid = GetPostString("ctid");
  5794. CeErpTradeCell entity = null;
  5795. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5796. if (entity != null)
  5797. {
  5798. string osid = entity.OutSid;
  5799. entity.OutSid = osid + "," + outsid;
  5800. entity.FinishDeliveryTime = DateTime.Now;
  5801. entity.OrderState = 7;
  5802. entity.UpdateTime = DateTime.Now;
  5803. entity.IsReturn = 0;
  5804. entity.Update();
  5805. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5806. exinfo.tid = entity.ctid;
  5807. exinfo.out_sid = outsid;
  5808. exinfo.company_code = cpCode;
  5809. exinfo.company_name = cpName;
  5810. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5811. exinfo.deliveryType = "发货成功";
  5812. exinfo.print_time = DateTime.Now;
  5813. exinfo.printUser = CurrentUser.UserName;
  5814. exinfo.Create();
  5815. if (entity.SupplierId == 64)
  5816. {
  5817. commonHelper.sendCytExpress(exinfo);
  5818. }
  5819. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5820. }
  5821. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5822. var res_objz = new
  5823. {
  5824. restype = 1,
  5825. data = res
  5826. };
  5827. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5828. returnSuccess(ro_jsonz);
  5829. //ReturnSuccess(res);
  5830. }
  5831. }
  5832. ////打单,打印面单 获取面单号
  5833. //public void set_erp_printwaybill()
  5834. //{
  5835. // if (UrlPostParmsCheck("ctid"))
  5836. // {
  5837. // string ctid = GetPostString("ctid");
  5838. // string cpCode = GetPostString("cpcode");
  5839. // string tempUrl = GetPostString("tempurl");
  5840. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5841. // //string res = taobaoHelper.test();
  5842. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5843. // if (res.IndexOf("error_response") != -1)
  5844. // {
  5845. // int sidx = res.IndexOf("sub_msg");
  5846. // int eidx = res.IndexOf("request_id");
  5847. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5848. // returnErrorMsg(msg);
  5849. // return;
  5850. // }
  5851. // int idx = res.IndexOf("waybill_code");
  5852. // int idx2 = res.IndexOf("}]}");
  5853. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5854. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5855. // ReturnSuccess(res);
  5856. // }
  5857. //}
  5858. public void cancel_erp_aftersale()
  5859. {
  5860. if (UrlPostParmsCheck("ctid"))
  5861. {
  5862. string eid = GetPostString("ctid");
  5863. CeErpTradeCell entity = null;
  5864. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5865. if (entity != null)
  5866. {
  5867. //有过处理的售后,取消也不能删除 售 字,保留
  5868. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5869. {
  5870. entity.AfterSaleState = 4;
  5871. }
  5872. else
  5873. entity.AfterSaleState = 0;
  5874. entity.UpdateTime = DateTime.Now;
  5875. entity.Update();
  5876. returnSuccessMsg("操作成功!");
  5877. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5878. return;
  5879. }
  5880. returnErrorMsg("找不到订单记录");
  5881. }
  5882. }
  5883. public void get_erp_aftersalelist()
  5884. {
  5885. DataStruct dStruct = GetPostStruct();
  5886. List<string> lw = new List<string>();
  5887. int st = GetInt("st");
  5888. string tid = GetPostString("ctid");
  5889. if (st == 3)
  5890. {
  5891. if (tid.Length > 0)
  5892. {
  5893. string select_tid = getTidByCtid(tid);
  5894. lw.Add(string.Format("tid='{0}'", select_tid));
  5895. }
  5896. }
  5897. else
  5898. {
  5899. if (tid.Length > 0)
  5900. {
  5901. string select_tid = getTidByCtid(tid);
  5902. lw.Add(string.Format("tid='{0}'", select_tid));
  5903. }
  5904. }
  5905. string shopname = GetPostString("shopname");
  5906. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5907. string buyernick = GetPostString("buyer_nick");
  5908. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5909. string sellermemo = GetPostString("seller_memo");
  5910. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5911. string orderState = GetPostString("orderState");
  5912. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5913. string afterState = GetPostString("afterstate");
  5914. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5915. string date1 = GetPostString("date1");
  5916. string date2 = GetPostString("date2");
  5917. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5918. if (dw.Length > 0) lw.Add(dw);
  5919. string price1 = GetPostString("price1");
  5920. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5921. string price2 = GetPostString("price2");
  5922. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5923. //lw.Add(string.Format("IsRefund!={0}", 1));
  5924. string reason = GetPostString("reason");
  5925. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5926. string method = GetPostString("method");
  5927. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5928. string handler = GetPostString("handler");
  5929. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5930. string handledate1 = GetPostString("handledate1");
  5931. string handledate2 = GetPostString("handledate2");
  5932. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5933. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5934. string finish1 = GetPostString("finishdate1");
  5935. string finish2 = GetPostString("finishdate2");
  5936. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5937. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5938. string afterdate1 = GetPostString("afterdate1");
  5939. string afterdate2 = GetPostString("afterdate2");
  5940. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5941. if (afterDate.Length > 0) lw.Add(afterDate);
  5942. string supplier = GetPostString("supplier");
  5943. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5944. string responsible = GetPostString("responsibleman");
  5945. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5946. string customer = GetPostString("customer");
  5947. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5948. string design = GetPostString("design");
  5949. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5950. string afterMemoType = GetPostString("aftermemotype");
  5951. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5952. string posCode = CurrentUser.UserPost.Post.Code;
  5953. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5954. //{
  5955. // string vstate = GetPostString("vstate");
  5956. // if (vstate.Length > 0)
  5957. // {
  5958. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5959. // }
  5960. // if (posCode == "Supplier")
  5961. // {
  5962. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5963. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5964. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5965. // }
  5966. // else
  5967. // {
  5968. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5969. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5970. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5971. // {
  5972. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5973. // }
  5974. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5975. // {
  5976. // int orgid = CurrentUser.UserPost.OrgID;
  5977. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5978. // }
  5979. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5980. // {
  5981. // string shopid = CurrentUser.User.pemShop;
  5982. // lw.Add(string.Format("shopId in ({0})", shopid));
  5983. // }
  5984. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5985. // //{
  5986. // // int org_id = CurrentUser.UserPost.OrgID;
  5987. // // lw.Add(string.Format("OrgID={0}", org_id));
  5988. // //}
  5989. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5990. // }
  5991. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5992. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5993. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5994. //}
  5995. if (st == 5)
  5996. {
  5997. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5998. {
  5999. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6000. {
  6001. string shopid = CurrentUser.User.pemShop;
  6002. lw.Add(string.Format("shopId in ({0})", shopid));
  6003. }
  6004. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6005. {
  6006. int mrOrgid = CurrentUser.UserPost.OrgID;
  6007. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6008. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6009. }
  6010. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6011. //{
  6012. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6013. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6014. //}
  6015. else
  6016. {
  6017. string userIdStr = "";
  6018. if (posCode == "CustomerService")
  6019. {
  6020. userIdStr = CurrentUser.UserID + "_k";
  6021. }
  6022. else if (posCode == "Designer" || posCode == "wxDesigner")
  6023. {
  6024. userIdStr = CurrentUser.UserID + "_s";
  6025. }
  6026. else if (posCode == "Place")
  6027. {
  6028. userIdStr = CurrentUser.UserID + "_x";
  6029. }
  6030. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6031. }
  6032. }
  6033. string placedate1 = GetPostString("placedate1");
  6034. string placedate2 = GetPostString("placedate2");
  6035. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6036. if (dwplace.Length > 0) lw.Add(dwplace);
  6037. string supState = GetPostString("supState");
  6038. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6039. string searchType = GetPostString("searchType");
  6040. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6041. {
  6042. lw.Add(string.Format("BackNum>1"));
  6043. }
  6044. lw.Add(string.Format("AfterSaleState>0"));
  6045. if (ex_psize > 0)
  6046. {
  6047. if (CurrentUser.UserPost.Post.Code == "Finance")
  6048. dStruct.Order = "pay_time desc";
  6049. else
  6050. dStruct.Order = "HandleTime desc";
  6051. }
  6052. else
  6053. dStruct.Order = "HandleTime desc";
  6054. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6055. DataTable dt = WebCache.GetData("view_test", dStruct);
  6056. writeGridDataTableJson(dStruct.TotalCount, dt);
  6057. }
  6058. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6059. //{
  6060. // lw.Add(string.Format("AfterSaleState=4"));
  6061. // string code = CurrentUser.UserPost.Post.Code;
  6062. // if (code == "CustomerService")
  6063. // {
  6064. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6065. // }
  6066. // else if (code == "Designer" || code == "DesignerMr")
  6067. // {
  6068. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6069. // }
  6070. // else if (code == "Place" || code == "PlaceMr")
  6071. // {
  6072. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6073. // }
  6074. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6075. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6076. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6077. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6078. //}
  6079. //else //处理中的售后,待处理和处理中合并
  6080. //{
  6081. // if (afterState.Length <= 0)
  6082. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6083. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6084. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6085. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6086. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6087. //}
  6088. }
  6089. public void get_erp_disagreeftersalelist()
  6090. {
  6091. DataStruct dStruct = GetPostStruct();
  6092. List<string> lw = new List<string>();
  6093. int st = 2;
  6094. string tid = GetPostString("ctid");
  6095. if (tid.Length > 0)
  6096. {
  6097. string select_tid = getTidByCtid(tid);
  6098. lw.Add(string.Format("tid='{0}'", select_tid));
  6099. }
  6100. string shopname = GetPostString("shopname");
  6101. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6102. string buyernick = GetPostString("buyer_nick");
  6103. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6104. string sellermemo = GetPostString("seller_memo");
  6105. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6106. string orderState = GetPostString("orderState");
  6107. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6108. string afterState = GetPostString("afterstate");
  6109. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6110. string date1 = GetPostString("date1");
  6111. string date2 = GetPostString("date2");
  6112. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6113. if (dw.Length > 0) lw.Add(dw);
  6114. string price1 = GetPostString("price1");
  6115. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6116. string price2 = GetPostString("price2");
  6117. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6118. //lw.Add(string.Format("IsRefund!={0}", 1));
  6119. string reason = GetPostString("reason");
  6120. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6121. string method = GetPostString("method");
  6122. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6123. string handler = GetPostString("handler");
  6124. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6125. string handledate1 = GetPostString("handledate1");
  6126. string handledate2 = GetPostString("handledate2");
  6127. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6128. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6129. string afterdate1 = GetPostString("afterdate1");
  6130. string afterdate2 = GetPostString("afterdate2");
  6131. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6132. if (afterDate.Length > 0) lw.Add(afterDate);
  6133. string backdate1 = GetPostString("backdate1");
  6134. string backdate2 = GetPostString("backdate2");
  6135. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6136. if (backDate.Length > 0) lw.Add(backDate);
  6137. string supplier = GetPostString("supplier");
  6138. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6139. string responsible = GetPostString("responsibleman");
  6140. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6141. string customer = GetPostString("customer");
  6142. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6143. string design = GetPostString("design");
  6144. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6145. string afterSaleMemo = GetPostString("afterSaleMemo");
  6146. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6147. string afterMemoType = GetPostString("aftermemotype");
  6148. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6149. string aftersakereason = GetPostString("aftersakereason");
  6150. if (aftersakereason.Length > 0)
  6151. {
  6152. if (aftersakereason == "1")
  6153. {
  6154. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6155. }
  6156. if (aftersakereason == "2")
  6157. {
  6158. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6159. }
  6160. }
  6161. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6162. string poscode = CurrentUser.UserPost.Post.Code;
  6163. if (poscode != "SysAdmin")
  6164. {
  6165. string shopid = CurrentUser.User.pemShop;
  6166. lw.Add(string.Format("shopId in ({0})", shopid));
  6167. }
  6168. string searchType = GetPostString("searchType");
  6169. if (searchType == "wait")
  6170. {
  6171. lw.Add(string.Format("HandleTime is null"));
  6172. }
  6173. if (searchType == "handling")
  6174. {
  6175. lw.Add(string.Format("HandleTime is not null "));
  6176. }
  6177. if (searchType == "back" || searchType == "puBack")
  6178. {
  6179. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6180. }
  6181. if (searchType == "reBack")
  6182. {
  6183. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6184. }
  6185. if (searchType == "moreBack")
  6186. {
  6187. lw.Add(string.Format("backNum > 1"));
  6188. }
  6189. lw.Add(string.Format("(AfterSaleState=5)"));
  6190. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6191. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6192. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6193. writeGridDataTableJson(dStruct.TotalCount, dt);
  6194. }
  6195. public void get_erp_handlingaftersalelist()
  6196. {
  6197. DataStruct dStruct = GetPostStruct();
  6198. List<string> lw = new List<string>();
  6199. int st = 2;
  6200. string tid = GetPostString("ctid");
  6201. if (tid.Length > 0)
  6202. {
  6203. string select_tid = getTidByCtid(tid);
  6204. lw.Add(string.Format("tid='{0}'", select_tid));
  6205. }
  6206. string shopname = GetPostString("shopname");
  6207. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6208. string buyernick = GetPostString("buyer_nick");
  6209. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6210. string sellermemo = GetPostString("seller_memo");
  6211. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6212. string orderState = GetPostString("orderState");
  6213. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6214. string afterState = GetPostString("afterstate");
  6215. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6216. string date1 = GetPostString("date1");
  6217. string date2 = GetPostString("date2");
  6218. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6219. if (dw.Length > 0) lw.Add(dw);
  6220. string price1 = GetPostString("price1");
  6221. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6222. string price2 = GetPostString("price2");
  6223. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6224. //lw.Add(string.Format("IsRefund!={0}", 1));
  6225. string reason = GetPostString("reason");
  6226. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6227. string method = GetPostString("method");
  6228. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6229. string handler = GetPostString("handler");
  6230. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6231. string handledate1 = GetPostString("handledate1");
  6232. string handledate2 = GetPostString("handledate2");
  6233. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6234. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6235. string afterdate1 = GetPostString("afterdate1");
  6236. string afterdate2 = GetPostString("afterdate2");
  6237. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6238. if (afterDate.Length > 0) lw.Add(afterDate);
  6239. string supplier = GetPostString("supplier");
  6240. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6241. string responsible = GetPostString("responsibleman");
  6242. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6243. string customer = GetPostString("customer");
  6244. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6245. string design = GetPostString("design");
  6246. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6247. string afterSaleMemo = GetPostString("afterSaleMemo");
  6248. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6249. string afterMemoType = GetPostString("aftermemotype");
  6250. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6251. string afterresult = GetPostString("afterresult");
  6252. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6253. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6254. string poscode = CurrentUser.UserPost.Post.Code;
  6255. if (poscode != "SysAdmin")
  6256. {
  6257. string shopid = CurrentUser.User.pemShop;
  6258. lw.Add(string.Format("shopId in ({0})", shopid));
  6259. }
  6260. string searchType = GetPostString("searchType");
  6261. if (searchType == "wait")
  6262. {
  6263. lw.Add(string.Format("HandleTime is null"));
  6264. }
  6265. if (searchType == "documentary")
  6266. {
  6267. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6268. }
  6269. if (searchType == "handling")
  6270. {
  6271. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6272. }
  6273. if (searchType == "back" || searchType == "puBack")
  6274. {
  6275. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6276. }
  6277. if (searchType == "reBack")
  6278. {
  6279. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6280. }
  6281. if (afterState.Length <= 0)
  6282. {
  6283. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6284. }
  6285. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6286. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6287. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6288. writeGridDataTableJson(dStruct.TotalCount, dt);
  6289. }
  6290. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6291. //public void get_erp_back_handlingaftersalelist()
  6292. //{
  6293. // DataStruct dStruct = GetPostStruct();
  6294. // List<string> lw = new List<string>();
  6295. // string tid = GetPostString("ctid");
  6296. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6297. // string shopname = GetPostString("shopname");
  6298. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6299. // string buyernick = GetPostString("buyer_nick");
  6300. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6301. // string sellermemo = GetPostString("seller_memo");
  6302. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6303. // string orderState = GetPostString("orderState");
  6304. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6305. // string afterState = GetPostString("afterstate");
  6306. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6307. // string date1 = GetPostString("date1");
  6308. // string date2 = GetPostString("date2");
  6309. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6310. // if (dw.Length > 0) lw.Add(dw);
  6311. // string price1 = GetPostString("price1");
  6312. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6313. // string price2 = GetPostString("price2");
  6314. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6315. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6316. // string reason = GetPostString("reason");
  6317. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6318. // string method = GetPostString("method");
  6319. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6320. // string handler = GetPostString("handler");
  6321. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6322. // string handledate1 = GetPostString("handledate1");
  6323. // string handledate2 = GetPostString("handledate2");
  6324. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6325. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6326. // string afterdate1 = GetPostString("afterdate1");
  6327. // string afterdate2 = GetPostString("afterdate2");
  6328. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6329. // if (afterDate.Length > 0) lw.Add(afterDate);
  6330. // string supplier = GetPostString("supplier");
  6331. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6332. // string responsible = GetPostString("responsibleman");
  6333. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6334. // string customer = GetPostString("customer");
  6335. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6336. // string design = GetPostString("design");
  6337. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6338. // string afterMemoType = GetPostString("aftermemotype");
  6339. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6340. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6341. // if (afterState.Length <= 0)
  6342. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6343. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6344. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6345. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6346. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6347. //}
  6348. public void get_erp_aftersaleverifylist()
  6349. {
  6350. DataStruct dStruct = GetPostStruct();
  6351. List<string> lw = new List<string>();
  6352. string tid = GetPostString("ctid");
  6353. if (tid.Length > 0)
  6354. {
  6355. string select_tid = getTidByCtid(tid);
  6356. lw.Add(string.Format("otid='{0}'", select_tid));
  6357. }
  6358. string shopname = GetPostString("shopname");
  6359. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6360. string buyernick = GetPostString("buyer_nick");
  6361. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6362. string sellermemo = GetPostString("seller_memo");
  6363. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6364. string orderState = GetPostString("orderState");
  6365. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6366. //lw.Add(string.Format("IsRefund!={0}", 1));
  6367. string reason = GetPostString("reason");
  6368. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6369. string method = GetPostString("method");
  6370. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6371. string handler = GetPostString("handler");
  6372. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6373. string handledate1 = GetPostString("handledate1");
  6374. string handledate2 = GetPostString("handledate2");
  6375. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6376. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6377. string finish1 = GetPostString("finishdate1");
  6378. string finish2 = GetPostString("finishdate2");
  6379. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6380. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6381. string supplier = GetPostString("supplier");
  6382. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6383. string responsible = GetPostString("responsibleman");
  6384. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6385. string posCode = CurrentUser.UserPost.Post.Code;
  6386. string vstate = GetPostString("vstate");
  6387. if (vstate.Length > 0)
  6388. {
  6389. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6390. }
  6391. if (posCode == "Supplier")
  6392. {
  6393. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6394. lw.Add(string.Format("VerifyState = 0"));
  6395. lw.Add("type = 1");
  6396. lw.Add(string.Format("AfterSaleState={0}", 3));
  6397. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6398. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6399. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6400. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6401. writeGridDataTableJson(dStruct.TotalCount, dt);
  6402. }
  6403. else if (posCode == "logistics")
  6404. {
  6405. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6406. lw.Add(string.Format("VerifyState = 0"));
  6407. lw.Add("type = 2");
  6408. lw.Add(string.Format("AfterSaleState={0}", 3));
  6409. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6410. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6411. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6412. writeGridDataTableJson(dStruct.TotalCount, dt);
  6413. }
  6414. else
  6415. {
  6416. lw.Add(string.Format("(AfterSaleState = 3)"));
  6417. string reasonState = GetPostString("reasonState");
  6418. lw.Add("type = 0");
  6419. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6420. || posCode == "Summarize" || posCode == "Finance")
  6421. {
  6422. if (reasonState == "2")
  6423. {
  6424. lw.Add("VerifyState = 3");
  6425. }
  6426. else if (reasonState == "1")
  6427. {
  6428. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6429. }
  6430. else
  6431. {
  6432. lw.Add("VerifyState in (0,3)");
  6433. }
  6434. //不加条件,可以看全部
  6435. }
  6436. 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")
  6437. {
  6438. int orgid = CurrentUser.UserPost.OrgID;
  6439. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6440. if (string.IsNullOrEmpty(manageOrgId))
  6441. {
  6442. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6443. }
  6444. else
  6445. {
  6446. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6447. }
  6448. if (reasonState == "1")
  6449. {
  6450. lw.Add("VerifyState = 3");
  6451. }
  6452. else if (reasonState == "2")
  6453. {
  6454. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6455. }
  6456. else
  6457. {
  6458. }
  6459. }
  6460. else
  6461. {
  6462. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6463. }
  6464. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6465. //{
  6466. // int org_id = CurrentUser.UserPost.OrgID;
  6467. // lw.Add(string.Format("OrgID={0}", org_id));
  6468. //}
  6469. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6470. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6471. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6472. writeGridDataTableJson(dStruct.TotalCount, dt);
  6473. }
  6474. }
  6475. public void get_erp_finishaftersalelist()
  6476. {
  6477. DataStruct dStruct = GetPostStruct();
  6478. List<string> lw = new List<string>();
  6479. int st = 4;
  6480. string tid = GetPostString("ctid");
  6481. if (tid.Length > 0)
  6482. {
  6483. string select_tid = getTidByCtid(tid);
  6484. lw.Add(string.Format("otid='{0}'", select_tid));
  6485. }
  6486. string shopname = GetPostString("shopname");
  6487. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6488. //lw.Add(string.Format("IsRefund!={0}", 1));
  6489. string reason = GetPostString("reason");
  6490. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6491. string method = GetPostString("method");
  6492. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6493. string buyernick = GetPostString("buyer_nick");
  6494. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6495. string handler = GetPostString("handler");
  6496. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6497. string handledate1 = GetPostString("handledate1");
  6498. string handledate2 = GetPostString("handledate2");
  6499. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6500. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6501. string finish1 = GetPostString("finishdate1");
  6502. string finish2 = GetPostString("finishdate2");
  6503. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6504. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6505. string supplier = GetPostString("supplier");
  6506. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6507. string responsible = GetPostString("responsibleman");
  6508. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6509. string vstate = GetPostString("vstate");
  6510. if (vstate.Length > 0)
  6511. {
  6512. if ("3".Equals(vstate))
  6513. {
  6514. lw.Add(string.Format("IsTem=1"));
  6515. }
  6516. else
  6517. {
  6518. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6519. }
  6520. }
  6521. lw.Add(string.Format("AfterSaleState=4"));
  6522. string code = CurrentUser.UserPost.Post.Code;
  6523. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6524. {
  6525. //不加条件,可以看全部
  6526. }
  6527. else if (code == "Supplier")
  6528. {
  6529. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6530. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6531. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6532. }
  6533. else if (code == "logistics")
  6534. {
  6535. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6536. lw.Add("type = 2");
  6537. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6538. }
  6539. 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")
  6540. {
  6541. int orgid = CurrentUser.UserPost.OrgID;
  6542. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6543. if (string.IsNullOrEmpty(manageOrgIds))
  6544. {
  6545. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6546. }
  6547. else
  6548. {
  6549. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6550. }
  6551. }
  6552. else
  6553. {
  6554. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6555. }
  6556. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6557. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6558. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6559. writeGridDataTableJson(dStruct.TotalCount, dt);
  6560. }
  6561. public void handle_erp_aftersale()
  6562. {
  6563. if (UrlPostParmsCheck("ctid"))
  6564. {
  6565. string eid = GetPostString("ctid");
  6566. string responStr = GetPostString("AfterSaleResponsible");
  6567. if (responStr.Length <= 0)
  6568. {
  6569. returnErrorMsg("售后责任人不能为空");
  6570. return;
  6571. }
  6572. bool isDesign = false;
  6573. double designFree = 0.00;
  6574. int responsibleId = 0;
  6575. CeErpTradeCell entity = null;
  6576. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6577. if (entity != null)
  6578. {
  6579. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6580. string afterMethod = GetPostString("AfterSaleMethod");
  6581. if (isNeedNewOrder == 1)
  6582. {
  6583. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6584. bool ishav = true;
  6585. if (newentity == null)
  6586. {
  6587. newentity = entity.Clone() as CeErpTradeCell;
  6588. ishav = false;
  6589. newentity.ctid = "S_" + entity.ctid;
  6590. newentity.OrderState = 0;
  6591. //唯一标识
  6592. newentity.OrderSn = newentity.ctid;
  6593. string orderSn = dataHelper.getSaleOrderSn();
  6594. if (orderSn != "")
  6595. {
  6596. newentity.OrderSn = orderSn;
  6597. }
  6598. }
  6599. newentity.UpdateTime = DateTime.Now;
  6600. newentity.AfterSaleState = 0;
  6601. newentity.AfterSaleMethod = afterMethod;
  6602. if (!ishav)
  6603. {
  6604. string memo_str = newentity.seller_memo;
  6605. memo_str = memo_str.Replace("(", "(");
  6606. memo_str = memo_str.Replace(")", ")");
  6607. int sIndex = memo_str.IndexOf("(");
  6608. int eIndex = memo_str.IndexOf(")");
  6609. if (sIndex == -1 || eIndex == -1)
  6610. {
  6611. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6612. return;
  6613. }
  6614. string first = memo_str.Substring(0, sIndex + 1);
  6615. string memoCtid = newentity.OrderSn;
  6616. //if (memoCtid.IndexOf("C") != -1)
  6617. //{
  6618. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6619. //if (CIdx.IndexOf("+") != -1)
  6620. //{
  6621. //CIdx = "C" + CIdx.Split('+')[1];
  6622. //}
  6623. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6624. //}
  6625. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6626. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6627. string newMemo = first + memoCtid + last;
  6628. newentity.seller_memo = newMemo;
  6629. newentity.FinishPlaceTime = null;
  6630. newentity.UnusualTag = 0;
  6631. newentity.UnusualCon = "";
  6632. newentity.UnusualTime = null;
  6633. newentity.AfterSaleMemo = "";
  6634. newentity.AfterSaleMethod = afterMethod;
  6635. newentity.AfterSalePreTime = null;
  6636. newentity.AfterSaleReason = "";
  6637. newentity.AfterSaleResponsible = "";
  6638. newentity.AfterSaleState = 0;
  6639. newentity.AfterSaleTime = null;
  6640. newentity.AfterSaleUserId = 0;
  6641. newentity.AfterSaleSupplierState = 0;
  6642. newentity.LastBillWaybillCode = "";
  6643. newentity.LastBillCpCode = "";
  6644. newentity.FinishAfterSaleTime = null;
  6645. newentity.HandleTime = null;
  6646. newentity.IsSF = 0;
  6647. newentity.IsOldCustomer = 0;
  6648. newentity.UrgencyTime = null;
  6649. newentity.ResponsibleUserId = "";
  6650. newentity.IsVerifyToSupplier = false;
  6651. newentity.payment = 0;
  6652. newentity.CheckMemo = "";
  6653. newentity.OutSid = "";
  6654. newentity.CheckOrderTime = null;
  6655. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6656. }
  6657. newentity.isAfterSaleOrder = 1;
  6658. newentity.IsRefund = 0;
  6659. string receiveMobile = GetPostString("receiver_mobile");
  6660. if (receiveMobile.Length > 0)
  6661. {
  6662. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6663. if (trade != null)
  6664. {
  6665. trade.receiver_name = GetPostString("receiver_name");
  6666. trade.receiver_mobile = receiveMobile;
  6667. trade.receiver_state = GetPostString("receiver_state");
  6668. trade.receiver_city = GetPostString("receiver_city");
  6669. trade.receiver_district = GetPostString("receiver_district");
  6670. trade.receiver_address = GetPostString("receiver_address");
  6671. newentity.IsOffLineOrder = 1;
  6672. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6673. }
  6674. }
  6675. string st = GetPostString("ToState");
  6676. if (st.Length > 0)
  6677. {
  6678. if (newentity.OrderState <= 3)
  6679. {
  6680. newentity.WaitDesignTime = DateTime.Now;
  6681. newentity.StartDesignTime = null;
  6682. newentity.FinishDesignTime = null;
  6683. newentity.OrderState = 3;
  6684. if (st == "下单员")
  6685. {
  6686. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6687. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6688. {
  6689. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6690. }
  6691. }
  6692. else
  6693. {
  6694. newentity.WaitDesignTime = DateTime.Now;
  6695. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6696. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6697. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6698. {
  6699. DataRow user = dt1.Rows[0];
  6700. //找主管
  6701. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6702. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6703. if (dt != null && dt.Rows.Count > 0)
  6704. {
  6705. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6706. newentity.DesignUserId = designMr;
  6707. string key = "aftersale_order_" + designMr;
  6708. if (RedisHelper.HasKey(key))
  6709. {
  6710. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6711. list.Add(newentity.ctid);
  6712. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6713. }
  6714. }
  6715. //账号正常
  6716. if (user["State"].ToString() == "0")
  6717. {
  6718. newentity.DesignUserId = entity.DesignUserId;
  6719. string key = "aftersale_order_" + entity.DesignUserId;
  6720. if (RedisHelper.HasKey(key))
  6721. {
  6722. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6723. list.Add(newentity.ctid);
  6724. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6725. }
  6726. }
  6727. }
  6728. }
  6729. }
  6730. if (entity.IsXianHuo == 1)
  6731. {
  6732. newentity.OrderState = 6;
  6733. entity.FinishPlaceTime = DateTime.Now;
  6734. }
  6735. }
  6736. if (ishav)
  6737. {
  6738. newentity.Update();
  6739. }
  6740. else
  6741. {
  6742. newentity.Create();
  6743. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6744. newCellExtend.ctid = newentity.ctid;
  6745. newCellExtend.orderFrom = 20;
  6746. newCellExtend.orderType = 30;
  6747. if (st == "下单员")
  6748. {
  6749. }
  6750. else
  6751. {
  6752. newCellExtend.ReprintTime = DateTime.Now;
  6753. }
  6754. newCellExtend.Create();
  6755. }
  6756. if (st != "下单员")
  6757. {
  6758. if (entity.DispatchSort == 2)
  6759. {
  6760. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6761. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6762. }
  6763. }
  6764. }
  6765. //处理售后扩展
  6766. string resIdStr = GetPostString("ResponsibleUserId");
  6767. string refundFees = GetPostString("refundFrees");
  6768. int IsComplain = GetPostInt("isComplain");
  6769. int IsBad = GetPostInt("isBad");
  6770. string IsOriginal = GetPostString("isOriginal");
  6771. double diffResultPrice = GetPostDouble("diffResultPrice");
  6772. string textResult = GetPostString("textResult");
  6773. string supplierResponsible = GetPostString("supplierResponsible");
  6774. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6775. if (ceErpTradeAfterSaleExtend == null)
  6776. {
  6777. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6778. ceErpTradeAfterSaleExtend.tid = eid;
  6779. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6780. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6781. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6782. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6783. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6784. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6785. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6786. ceErpTradeAfterSaleExtend.Create();
  6787. }
  6788. else
  6789. {
  6790. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6791. {
  6792. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6793. }
  6794. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6795. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6796. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6797. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6798. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6799. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6800. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6801. ceErpTradeAfterSaleExtend.Update();
  6802. }
  6803. int gysid = GetPostInt("ResponsibleSupId");
  6804. if (entity.AfterSaleUserId == 0)
  6805. {
  6806. entity.AfterSaleUserId = CurrentUser.UserID;
  6807. }
  6808. entity.ResponsibleUserId = resIdStr;
  6809. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6810. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6811. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6812. {
  6813. CeErpTradeResponsible.DelByTid(eid, -1);
  6814. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6815. int backNum = 0;
  6816. if (number != null)
  6817. {
  6818. backNum = number.BackNum;
  6819. }
  6820. char[] separator = { ',' };
  6821. string[] sArray = resIdStr.Split(separator);
  6822. string[] refundFreeList = { };
  6823. if (refundFees.Length > 0)
  6824. {
  6825. refundFreeList = refundFees.Split(separator);
  6826. }
  6827. int index = -1;
  6828. foreach (string i in sArray)
  6829. {
  6830. index++;
  6831. if (i.Length <= 0) continue;
  6832. char[] separator2 = { '_' };
  6833. string idstr = i.Split(separator2)[0];
  6834. string idtype = i.Split(separator2)[1];
  6835. double refudFree = 0;
  6836. if (refundFreeList.Length > 0)
  6837. {
  6838. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6839. }
  6840. if (idtype == "s")
  6841. {
  6842. isDesign = true;
  6843. designFree = refudFree;
  6844. }
  6845. int userId = Convert.ToInt32(idstr);
  6846. int type = 0;
  6847. if (idtype == "g")
  6848. {
  6849. type = 1;
  6850. }
  6851. if (idtype == "w")
  6852. {
  6853. type = 2;
  6854. }
  6855. if (idtype == "t")
  6856. {
  6857. type = 3;
  6858. }
  6859. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6860. if (ceErpTradeResponsible == null)
  6861. {
  6862. ceErpTradeResponsible = new CeErpTradeResponsible();
  6863. ceErpTradeResponsible.tid = eid;
  6864. ceErpTradeResponsible.UserId = userId;
  6865. ceErpTradeResponsible.createdTime = DateTime.Now;
  6866. ceErpTradeResponsible.type = type;
  6867. if (type == 1)
  6868. {
  6869. ceErpTradeResponsible.IsSup = 1;
  6870. }
  6871. if (type == 2)
  6872. {
  6873. ceErpTradeResponsible.IsFlow = 1;
  6874. }
  6875. }
  6876. ceErpTradeResponsible.RefundFee = refudFree;
  6877. ceErpTradeResponsible.VerifyState = 0;
  6878. if (userId == 2125 || idtype == "w")
  6879. {
  6880. ceErpTradeResponsible.VerifyState = 1;
  6881. }
  6882. if (idtype == "w" && userId == 101)
  6883. {
  6884. ceErpTradeResponsible.VerifyState = 0;
  6885. }
  6886. if (ceErpTradeResponsible.ID > 0)
  6887. {
  6888. ceErpTradeResponsible.Update();
  6889. }
  6890. else
  6891. {
  6892. ceErpTradeResponsible.Create();
  6893. }
  6894. if (isDesign)
  6895. {
  6896. responsibleId = ceErpTradeResponsible.ID;
  6897. }
  6898. }
  6899. CeErpTradeResponsible.NumByTid(backNum, eid);
  6900. }
  6901. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6902. if (ceErpTradeCellExtend != null)
  6903. {
  6904. ceErpTradeCellExtend.returnVisit = 0;
  6905. ceErpTradeCellExtend.Update();
  6906. }
  6907. if (entity.HandleTime != null)
  6908. {
  6909. if (entity.AfterSaleState == 1)
  6910. {
  6911. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6912. }
  6913. else
  6914. {
  6915. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6916. }
  6917. }
  6918. else
  6919. {
  6920. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6921. entity.HandleTime = DateTime.Now;
  6922. }
  6923. bool isCompale = false;
  6924. if (entity.AfterSaleState == 5)
  6925. {
  6926. isCompale = true;
  6927. entity.AfterSaleState = 3;
  6928. }
  6929. entity.AfterSaleSupplierState = 0;
  6930. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6931. {
  6932. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6933. }
  6934. string sImgs = GetPostString("img");
  6935. entity.AfterSaleSupplierImg = sImgs;
  6936. entity.supRefundType = GetPostString("supRefundType");
  6937. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6938. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6939. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6940. entity.AfterSaleMemoType = GetPostString("MemoType");
  6941. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6942. {
  6943. //entity.AfterSaleSupplierState = 2;
  6944. }
  6945. string df = GetPostString("DeductFee");
  6946. if (df == "")
  6947. {
  6948. df = "0";
  6949. }
  6950. string rf = GetPostString("RefundFee");
  6951. if (rf == "")
  6952. {
  6953. rf = "0";
  6954. }
  6955. string pm = GetPostString("AfterSalePayment");
  6956. if (pm == "")
  6957. {
  6958. pm = "0";
  6959. }
  6960. entity.AfterSalePayment = Convert.ToDouble(pm);
  6961. entity.DeductFee = Convert.ToDouble(df);
  6962. entity.RefundFee = Convert.ToDouble(rf);
  6963. entity.UpdateTime = DateTime.Now;
  6964. entity.Update();
  6965. string toState = GetPostString("ToState");
  6966. string original = GetPostString("isOriginal");
  6967. ApiVo apiVo = new ApiVo();
  6968. apiVo.orderNumber = entity.ctid;
  6969. apiVo.actionName = "afterDesign";
  6970. apiVo.orderRemarks = entity.AfterSaleMethod;
  6971. apiVo.reasonRemarks = entity.AfterSaleReason;
  6972. apiVo.isDesign = isDesign;
  6973. apiVo.designFree = designFree;
  6974. apiVo.responsibleId = responsibleId;
  6975. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6976. if (toState == "设计师")
  6977. {
  6978. apiVo.isOriginal = Convert.ToBoolean(original);
  6979. }
  6980. designHelper.API_WorkCore(apiVo);//afterDesign
  6981. CeErpMethod methodSql = new CeErpMethod();
  6982. methodSql.con = entity.AfterSaleMethod;
  6983. methodSql.addTime = DateTime.Now;
  6984. methodSql.Create();
  6985. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6986. CeErpMethod.ExecuteNonQuery(delsql);
  6987. if (isCompale)
  6988. {
  6989. aftersale_data_change(entity.ctid);
  6990. }
  6991. returnSuccessMsg("操作成功!");
  6992. return;
  6993. }
  6994. returnErrorMsg("找不到订单记录");
  6995. }
  6996. }
  6997. public void ins_erp_toresponsible()
  6998. {
  6999. if (UrlPostParmsCheck("ctid"))
  7000. {
  7001. string eid = GetPostString("ctid");
  7002. CeErpTradeCell entity = null;
  7003. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7004. if (entity != null)
  7005. {
  7006. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7007. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7008. {
  7009. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7010. return;
  7011. }
  7012. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7013. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7014. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7015. if (entity.AfterSalePreTime == null)
  7016. {
  7017. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7018. {
  7019. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7020. }
  7021. }
  7022. entity.AfterSalePreTime = DateTime.Now;
  7023. //预完成给售后主管审核客户问题直接完成
  7024. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7025. {
  7026. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7027. {
  7028. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7029. }
  7030. }
  7031. ceErpTradeAfterSaleExtend.Update();
  7032. entity.AfterSaleState = 2;
  7033. entity.UpdateTime = DateTime.Now;
  7034. entity.Update();
  7035. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7036. aftersale_data_change(entity.ctid);
  7037. returnSuccessMsg("操作成功!");
  7038. return;
  7039. }
  7040. returnErrorMsg("找不到订单记录");
  7041. }
  7042. }
  7043. public void cancel_erp_aftersaleanddelnew()
  7044. {
  7045. if (UrlPostParmsCheck("ctid"))
  7046. {
  7047. string eid = GetPostString("ctid");
  7048. CeErpTradeCell entity = null;
  7049. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7050. if (entity != null)
  7051. {
  7052. entity.AfterSaleState = 0;
  7053. entity.AfterSaleReason = "";
  7054. entity.AfterSaleMethod = "";
  7055. entity.AfterSaleMemo = "";
  7056. entity.AfterSaleResponsible = "";
  7057. entity.ResponsibleUserId = "";
  7058. entity.DeductFee = 0;
  7059. entity.RefundFee = 0;
  7060. entity.IsArbitrate = 0;
  7061. CeErpTradeResponsible.DelByTid(eid, -1);
  7062. entity.Update();
  7063. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7064. if (after != null)
  7065. {
  7066. if (after.OrderState < 5)
  7067. CeErpTradeCell.DelByCtid("S_" + eid);
  7068. }
  7069. returnSuccessMsg("操作成功!");
  7070. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7071. return;
  7072. }
  7073. returnErrorMsg("找不到订单记录");
  7074. }
  7075. }
  7076. public void get_erp_aftersale_pregather()
  7077. {
  7078. List<string> lw = new List<string>();
  7079. int st = GetInt("st");
  7080. string tid = GetPostString("ctid");
  7081. if (tid.Length > 0)
  7082. {
  7083. string select_tid = getTidByCtid(tid);
  7084. lw.Add(string.Format("tid='{0}'", select_tid));
  7085. }
  7086. string shopname = GetPostString("shopname");
  7087. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7088. string buyernick = GetPostString("buyer_nick");
  7089. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7090. string sellermemo = GetPostString("seller_memo");
  7091. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7092. string orderState = GetPostString("orderState");
  7093. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7094. string reason = GetPostString("reason");
  7095. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7096. string method = GetPostString("method");
  7097. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7098. string handler = GetPostString("handler");
  7099. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7100. string handledate1 = GetPostString("handledate1");
  7101. string handledate2 = GetPostString("handledate2");
  7102. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7103. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7104. string supplier = GetPostString("supplier");
  7105. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7106. string responsible = GetPostString("responsibleman");
  7107. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7108. string customer = GetPostString("customer");
  7109. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7110. string design = GetPostString("design");
  7111. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7112. string afterMemoType = GetPostString("aftermemotype");
  7113. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7114. string afterSaleMemo = GetPostString("afterSaleMemo");
  7115. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7116. string afterresult = GetPostString("afterresult");
  7117. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7118. string poscode = CurrentUser.UserPost.Post.Code;
  7119. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7120. {
  7121. string shopid = CurrentUser.User.pemShop;
  7122. lw.Add(string.Format("shopId in ({0})", shopid));
  7123. }
  7124. var mainwhere = string.Join(" and ", lw.ToArray());
  7125. string ro_json = "";
  7126. string type = GetPostString("gather_type");
  7127. int number = 0;
  7128. if (poscode == "AfterSale")
  7129. {
  7130. //处理中
  7131. if (type == "Handling")
  7132. {
  7133. 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) : ""));
  7134. DataTable dt = null;
  7135. try
  7136. {
  7137. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7138. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7139. }
  7140. catch (Exception e)
  7141. {
  7142. dt = new DataTable();
  7143. }
  7144. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7145. return;
  7146. }
  7147. if (type == "Wait")
  7148. {
  7149. //待处理
  7150. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7151. DataTable dt1 = null;
  7152. try
  7153. {
  7154. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7155. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7156. }
  7157. catch (Exception e)
  7158. {
  7159. dt1 = new DataTable();
  7160. }
  7161. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7162. return;
  7163. }
  7164. if (type == "back")
  7165. {
  7166. //打回
  7167. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7168. DataTable dt2 = null;
  7169. try
  7170. {
  7171. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7172. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7173. }
  7174. catch (Exception e)
  7175. {
  7176. dt2 = new DataTable();
  7177. }
  7178. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7179. return;
  7180. }
  7181. if (type == "preCompletion")
  7182. {
  7183. //预完成
  7184. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7185. DataTable dt3 = null;
  7186. try
  7187. {
  7188. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7189. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7190. }
  7191. catch (Exception e)
  7192. {
  7193. dt3 = new DataTable();
  7194. }
  7195. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7196. return;
  7197. }
  7198. if (type == "documentary")
  7199. {
  7200. //跟单中
  7201. 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) : ""));
  7202. DataTable dt4 = null;
  7203. try
  7204. {
  7205. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7206. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7207. }
  7208. catch (Exception e)
  7209. {
  7210. dt4 = new DataTable();
  7211. }
  7212. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7213. return;
  7214. }
  7215. if (type == "reBack")
  7216. {
  7217. //被打回
  7218. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7219. DataTable dt1 = null;
  7220. try
  7221. {
  7222. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7223. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7224. }
  7225. catch (Exception e)
  7226. {
  7227. dt1 = new DataTable();
  7228. }
  7229. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7230. return;
  7231. }
  7232. }
  7233. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7234. {
  7235. if (type == "puBack")
  7236. {
  7237. //退回
  7238. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7239. DataTable dt = null;
  7240. try
  7241. {
  7242. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7243. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7244. }
  7245. catch (Exception e)
  7246. {
  7247. dt = new DataTable();
  7248. }
  7249. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7250. return;
  7251. }
  7252. if (type == "reBack")
  7253. {
  7254. //打回
  7255. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7256. DataTable dt1 = null;
  7257. try
  7258. {
  7259. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7260. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7261. }
  7262. catch (Exception e)
  7263. {
  7264. dt1 = new DataTable();
  7265. }
  7266. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7267. return;
  7268. }
  7269. if (type == "examEd")
  7270. {
  7271. //已审核
  7272. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7273. DataTable dt2 = null;
  7274. try
  7275. {
  7276. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7277. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7278. }
  7279. catch (Exception e)
  7280. {
  7281. dt2 = new DataTable();
  7282. }
  7283. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7284. return;
  7285. }
  7286. if (type == "waitExam")
  7287. {
  7288. //待审核
  7289. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7290. DataTable dt3 = null;
  7291. try
  7292. {
  7293. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7294. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7295. }
  7296. catch (Exception e)
  7297. {
  7298. dt3 = new DataTable();
  7299. }
  7300. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7301. return;
  7302. }
  7303. if (type == "Handling")
  7304. {
  7305. //处理中
  7306. 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) : ""));
  7307. DataTable dt4 = null;
  7308. try
  7309. {
  7310. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7311. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7312. }
  7313. catch (Exception e)
  7314. {
  7315. dt4 = new DataTable();
  7316. }
  7317. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7318. return;
  7319. }
  7320. if (type == "Wait")
  7321. {
  7322. //待处理
  7323. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7324. DataTable dt5 = null;
  7325. try
  7326. {
  7327. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7328. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7329. }
  7330. catch (Exception e)
  7331. {
  7332. dt5 = new DataTable();
  7333. }
  7334. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7335. return;
  7336. }
  7337. if (type == "documentary")
  7338. {
  7339. //跟单中
  7340. 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) : ""));
  7341. DataTable dt6 = null;
  7342. try
  7343. {
  7344. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7345. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7346. }
  7347. catch (Exception e)
  7348. {
  7349. dt6 = new DataTable();
  7350. }
  7351. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7352. return;
  7353. }
  7354. }
  7355. returnSuccess(ro_json);
  7356. }
  7357. public void end_erp_aftersale()
  7358. {
  7359. if (UrlPostParmsCheck("ctid"))
  7360. {
  7361. string eid = GetPostString("ctid");
  7362. CeErpTradeCell entity = null;
  7363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7364. if (entity != null)
  7365. {
  7366. string stype = GetPostString("stype");
  7367. string typeStr = stype;
  7368. entity.AfterSaleState = 4;
  7369. entity.FinishAfterSaleTime = DateTime.Now;
  7370. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7371. entity.Update();
  7372. ApiVo apiVo = new ApiVo();
  7373. apiVo.orderNumber = entity.ctid;
  7374. apiVo.actionName = "afterOver";
  7375. designHelper.API_WorkCore(apiVo); //afterOver
  7376. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7377. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7378. CeErpSukuraData.createInfo(entity.ctid, 8);
  7379. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7380. returnSuccessMsg("操作成功!");
  7381. return;
  7382. }
  7383. returnErrorMsg("找不到订单记录");
  7384. }
  7385. }
  7386. public void ins_erp_finishaftersale()
  7387. {
  7388. if (UrlPostParmsCheck("id"))
  7389. {
  7390. string eid = GetPostString("id");
  7391. CeErpTradeResponsible entity = null;
  7392. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7393. if (entity != null)
  7394. {
  7395. entity.VerifyState = 1;
  7396. entity.VerifyTime = DateTime.Now;
  7397. entity.Update();
  7398. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7399. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7400. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7401. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7402. if (dt.Rows.Count <= 0)
  7403. {
  7404. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7405. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7406. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7407. CeErpSukuraData.createInfo(entity.tid, 8);
  7408. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7409. {
  7410. CeErpDesignerBill.Del(entity.tid);
  7411. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7412. }
  7413. }
  7414. returnSuccessMsg("操作成功!");
  7415. return;
  7416. }
  7417. returnErrorMsg("找不到订单记录");
  7418. }
  7419. }
  7420. public void upd_erp_arbitrateaftersale()
  7421. {
  7422. if (UrlPostParmsCheck("id"))
  7423. {
  7424. string eid = GetPostString("id");
  7425. CeErpTradeResponsible entity = null;
  7426. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7427. if (entity != null)
  7428. {
  7429. entity.IsArbitrate = 1;
  7430. entity.ArbitradeMemo = GetPostString("reason");
  7431. entity.VerifyState = 2;
  7432. entity.Update();
  7433. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7434. if (tradecell != null)
  7435. {
  7436. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7437. tradecell.IsArbitrate = 1;
  7438. tradecell.Update();
  7439. }
  7440. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7441. returnSuccessMsg("操作成功!");
  7442. return;
  7443. }
  7444. returnErrorMsg("找不到订单记录");
  7445. }
  7446. }
  7447. public void upd_erp_backaftersale()
  7448. {
  7449. if (UrlPostParmsCheck("tid"))
  7450. {
  7451. string eid = GetPostString("tid");
  7452. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7453. int backNum = 0;
  7454. if (number != null)
  7455. {
  7456. backNum = number.BackNum;
  7457. }
  7458. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7459. CeErpTradeCell entity = null;
  7460. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7461. if (entity != null)
  7462. {
  7463. entity.AfterSaleBackReason = GetPostString("backreason");
  7464. entity.AfterSaleState = 1;
  7465. entity.AfterSaleSupplierState = 0;
  7466. entity.UpdateTime = DateTime.Now;
  7467. entity.Update();
  7468. returnSuccessMsg("操作成功!");
  7469. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7470. return;
  7471. }
  7472. returnErrorMsg("找不到订单记录");
  7473. }
  7474. }
  7475. public void get_erp_supplieraftersalelist()
  7476. {
  7477. DataStruct dStruct = GetPostStruct();
  7478. List<string> lw = new List<string>();
  7479. string tid = GetPostString("ctid");
  7480. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7481. string shopname = GetPostString("shopname");
  7482. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7483. string buyernick = GetPostString("buyer_nick");
  7484. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7485. string sellermemo = GetPostString("seller_memo");
  7486. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7487. string orderState = GetPostString("orderState");
  7488. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7489. string afterState = GetPostString("afterstate");
  7490. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7491. string date1 = GetPostString("date1");
  7492. string date2 = GetPostString("date2");
  7493. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7494. if (dw.Length > 0) lw.Add(dw);
  7495. string price1 = GetPostString("price1");
  7496. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7497. string price2 = GetPostString("price2");
  7498. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7499. string reason = GetPostString("reason");
  7500. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7501. string method = GetPostString("method");
  7502. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7503. string handledate1 = GetPostString("handledate1");
  7504. string handledate2 = GetPostString("handledate2");
  7505. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7506. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7507. string handler = GetPostString("handler");
  7508. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7509. string afterdate1 = GetPostString("afterdate1");
  7510. string afterdate2 = GetPostString("afterdate2");
  7511. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7512. if (afterDate.Length > 0) lw.Add(afterDate);
  7513. string customer = GetPostString("customer");
  7514. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7515. string design = GetPostString("design");
  7516. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7517. string afterMemoType = GetPostString("aftermemotype");
  7518. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7519. string vstate = GetPostString("vstate");
  7520. if (vstate.Length > 0)
  7521. {
  7522. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7523. }
  7524. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7525. string supplier = GetPostString("supplier");
  7526. int supid = commonHelper.getSupplierIDByName(supplier);
  7527. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7528. string posCode = CurrentUser.UserPost.Post.Code;
  7529. if (posCode == "Supplier")
  7530. {
  7531. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7532. }
  7533. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7534. {
  7535. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7536. }
  7537. else
  7538. {
  7539. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7540. }
  7541. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7542. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7543. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7544. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7545. writeGridDataTableJson(dStruct.TotalCount, dt);
  7546. }
  7547. public void upd_erp_supverifyaftersale()
  7548. {
  7549. if (UrlPostParmsCheck("id"))
  7550. {
  7551. string id = GetPostString("id");
  7552. int st = GetPostInt("afterstate");
  7553. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7554. CeErpTradeCell entity = null;
  7555. if (ceErpTradeResponsible != null)
  7556. {
  7557. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7558. }
  7559. string afmemo = GetPostString("supmemo");
  7560. string image = GetPostString("image");
  7561. if (entity != null)
  7562. {
  7563. entity.AfterSaleSupplierState = st;
  7564. entity.AfterSaleSupplierMemo = afmemo;
  7565. if (st == 1)
  7566. {
  7567. ceErpTradeResponsible.VerifyState = 1;
  7568. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7569. ceErpTradeResponsible.Update();
  7570. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7571. if (isAll)
  7572. {
  7573. entity.AfterSaleState = 4;
  7574. entity.FinishAfterSaleTime = DateTime.Now;
  7575. }
  7576. }
  7577. else
  7578. {
  7579. CeErpTradeResponsible.dateByTid(entity.ctid);
  7580. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7581. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7582. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7583. if (num <= 1)
  7584. {
  7585. entity.AfterSaleState = 1;
  7586. }
  7587. else
  7588. {
  7589. entity.AfterSaleState = 5;
  7590. }
  7591. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7592. if (ceErpTradeAfterSaleExtend != null)
  7593. {
  7594. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7595. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7596. ceErpTradeAfterSaleExtend.Update();
  7597. }
  7598. else
  7599. {
  7600. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7601. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7602. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7603. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7604. ceErpTradeAfterSaleExtend.Create();
  7605. }
  7606. }
  7607. if (entity.AfterSaleState == 4)
  7608. {
  7609. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7610. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7611. {
  7612. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7613. }
  7614. ApiVo apiVo = new ApiVo();
  7615. apiVo.orderNumber = entity.ctid;
  7616. apiVo.actionName = "afterOver";
  7617. designHelper.API_WorkCore(apiVo); //afterOver
  7618. }
  7619. entity.UpdateTime = DateTime.Now;
  7620. entity.Update();
  7621. returnSuccessMsg("操作成功!");
  7622. CeErpSukuraData.createInfo(entity.ctid, 8);
  7623. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7624. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7625. return;
  7626. }
  7627. returnErrorMsg("找不到订单记录");
  7628. }
  7629. }
  7630. public void upd_erp_masteraftersale()
  7631. {
  7632. if (UrlPostParmsCheck("id"))
  7633. {
  7634. string id = GetPostString("id");
  7635. int st = GetPostInt("afterstate");
  7636. string afmemo = GetPostString("supmemo");
  7637. string image = GetPostString("image");
  7638. string textResult = GetPostString("textResult");
  7639. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7640. if (ceErpTradeResponsible != null)
  7641. {
  7642. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7643. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7644. ceErpTradeResponsible.Update();
  7645. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7646. if (entity != null)
  7647. {
  7648. entity.AfterSaleSupplierState = st;
  7649. entity.AfterSaleSupplierMemo = afmemo;
  7650. if (st == 1)
  7651. {
  7652. }
  7653. else
  7654. {
  7655. CeErpTradeResponsible.dateByTid(entity.ctid);
  7656. //退回到售后
  7657. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7658. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7659. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7660. if (num <= 1)
  7661. {
  7662. entity.AfterSaleState = 1;
  7663. }
  7664. else
  7665. {
  7666. entity.AfterSaleState = 5;
  7667. }
  7668. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7669. if (ceErpTradeAfterSaleExtend != null)
  7670. {
  7671. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7672. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7673. ceErpTradeAfterSaleExtend.Update();
  7674. }
  7675. else
  7676. {
  7677. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7678. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7679. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7680. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7681. ceErpTradeAfterSaleExtend.Create();
  7682. }
  7683. }
  7684. entity.UpdateTime = DateTime.Now;
  7685. entity.Update();
  7686. returnSuccessMsg("操作成功!");
  7687. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7688. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7689. return;
  7690. }
  7691. }
  7692. returnErrorMsg("找不到订单记录");
  7693. }
  7694. }
  7695. public void upd_erp_personaftersale()
  7696. {
  7697. if (UrlPostParmsCheck("id"))
  7698. {
  7699. //林小连
  7700. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7701. {
  7702. upd_erp_masteraftersale();
  7703. return;
  7704. }
  7705. string id = GetPostString("id");
  7706. int st = GetPostInt("afterstate");
  7707. string afmemo = GetPostString("supmemo");
  7708. string image = GetPostString("image");
  7709. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7710. if (ceErpTradeResponsible != null)
  7711. {
  7712. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7713. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7714. ceErpTradeResponsible.Update();
  7715. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7716. if (entity != null)
  7717. {
  7718. entity.AfterSaleSupplierMemo = afmemo;
  7719. entity.AfterSaleSupplierState = st;
  7720. if (st == 1)
  7721. {
  7722. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7723. if (isAll)
  7724. {
  7725. entity.AfterSaleState = 4;
  7726. entity.FinishAfterSaleTime = DateTime.Now;
  7727. }
  7728. }
  7729. else
  7730. {
  7731. CeErpTradeResponsible.dateByTid(entity.ctid);
  7732. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7733. if (ceErpTradeAfterSaleExtend != null)
  7734. {
  7735. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7736. ceErpTradeAfterSaleExtend.Update();
  7737. }
  7738. else
  7739. {
  7740. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7741. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7742. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7743. ceErpTradeAfterSaleExtend.Create();
  7744. }
  7745. //退回到主管
  7746. //entity.AfterSaleState = 2;
  7747. }
  7748. if (entity.AfterSaleState == 4)
  7749. {
  7750. ApiVo apiVo = new ApiVo();
  7751. apiVo.orderNumber = entity.ctid;
  7752. apiVo.actionName = "afterOver";
  7753. designHelper.API_WorkCore(apiVo); //afterOver
  7754. }
  7755. entity.UpdateTime = DateTime.Now;
  7756. entity.Update();
  7757. returnSuccessMsg("操作成功!");
  7758. CeErpSukuraData.createInfo(entity.ctid, 8);
  7759. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7760. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7761. return;
  7762. }
  7763. }
  7764. returnErrorMsg("找不到订单记录");
  7765. }
  7766. }
  7767. public void set_erp_supplierrefundtag()
  7768. {
  7769. if (UrlPostParmsCheck("ctid"))
  7770. {
  7771. string eid = GetPostString("ctid");
  7772. CeErpTradeCell entity = null;
  7773. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7774. if (entity != null)
  7775. {
  7776. entity.IsSupplierRefund = GetPostInt("tag");
  7777. entity.Update();
  7778. returnSuccessMsg("操作成功!");
  7779. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7780. return;
  7781. }
  7782. returnErrorMsg("找不到订单记录");
  7783. }
  7784. }
  7785. public void get_erp_refundlist()
  7786. {
  7787. DataStruct dStruct = GetPostStruct();
  7788. List<string> lw = new List<string>();
  7789. string tid = GetPostString("tid");
  7790. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7791. //string rid = GetPostString("refund_id");
  7792. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7793. string shopname = GetPostString("shopname");
  7794. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7795. string buyernick = GetPostString("buyer_nick");
  7796. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7797. string customer = GetPostString("customer");
  7798. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7799. string design = GetPostString("design");
  7800. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7801. string sellermemo = GetPostString("seller_memo");
  7802. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7803. //string date1 = GetPostString("date1");
  7804. //string date2 = GetPostString("date2");
  7805. //string dateType = GetPostString("dateType");
  7806. //if (dateType.Length > 0)
  7807. //{
  7808. // if (dateType == "1001") dateType = "0";
  7809. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7810. // if (searchDT.Count == 2)
  7811. // {
  7812. // date1 = searchDT[0].ToString();
  7813. // date2 = searchDT[1].ToString();
  7814. // }
  7815. //}
  7816. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7817. //if (dw.Length > 0) lw.Add(dw);
  7818. string redate1 = GetPostString("refunddate1");
  7819. string redate2 = GetPostString("refunddate2");
  7820. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7821. if (dwdate.Length > 0) lw.Add(dwdate);
  7822. string price1 = GetPostString("price1");
  7823. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7824. string price2 = GetPostString("price2");
  7825. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7826. string ispartrefund = GetPostString("ispartrefund");
  7827. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7828. string refundState = GetPostString("refundvstate");
  7829. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7830. int st = GetInt("st");
  7831. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7832. {
  7833. string responsible = GetPostString("responsibleman");
  7834. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7835. lw.Add(string.Format("RefundState>={0}", st));
  7836. string code = CurrentUser.UserPost.Post.Code;
  7837. if (code == "CustomerService")
  7838. {
  7839. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7840. }
  7841. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7842. {
  7843. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7844. }
  7845. else if (code == "Place" || code == "PlaceMr")
  7846. {
  7847. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7848. }
  7849. dStruct.Order = "RefundState asc,created desc";
  7850. }
  7851. else if (st == 10)
  7852. {
  7853. string responsible = GetPostString("responsibleman");
  7854. if (responsible == "空白")
  7855. {
  7856. lw.Add(string.Format("ResponsibleUserName = ''"));
  7857. }
  7858. else if (responsible.Length > 0)
  7859. {
  7860. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7861. }
  7862. lw.Add(string.Format("RefundState>=0"));
  7863. dStruct.Order = "created desc";
  7864. }
  7865. else
  7866. {
  7867. string responsible = GetPostString("responsibleman");
  7868. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7869. lw.Add(string.Format("RefundState={0}", st));
  7870. dStruct.Order = "created desc";
  7871. }
  7872. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7873. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7874. dt.Columns.Add("refund_fees");
  7875. foreach (DataRow dr in dt.Rows)
  7876. {
  7877. String status = dr["status"].ToString();
  7878. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7879. {
  7880. dr["refund_fees"] = dr["refund_fee"];
  7881. }
  7882. else
  7883. {
  7884. dr["refund_fees"] = "0.0";
  7885. }
  7886. }
  7887. writeGridDataTableJson(dStruct.TotalCount, dt);
  7888. }
  7889. public void get_erp_refunddesignlist()
  7890. {
  7891. DataStruct dStruct = GetPostStruct();
  7892. List<string> lw = new List<string>();
  7893. string tid = GetPostString("tid");
  7894. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7895. string shopname = GetPostString("shopname");
  7896. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7897. string buyernick = GetPostString("buyer_nick");
  7898. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7899. string customer = GetPostString("customer");
  7900. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7901. string design = GetPostString("design");
  7902. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7903. string sellermemo = GetPostString("seller_memo");
  7904. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7905. string redate1 = GetPostString("refunddate1");
  7906. string redate2 = GetPostString("refunddate2");
  7907. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7908. if (dwdate.Length > 0) lw.Add(dwdate);
  7909. string price1 = GetPostString("price1");
  7910. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7911. string price2 = GetPostString("price2");
  7912. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7913. string ispartrefund = GetPostString("ispartrefund");
  7914. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7915. string designerorg = GetPostString("designerorg");
  7916. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7917. string refundState = GetPostString("refundState");
  7918. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7919. int myOrgid = CurrentUser.UserPost.OrgID;
  7920. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7921. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7922. {
  7923. if (CurrentUser.User.TeamIds.Length > 0)
  7924. {
  7925. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7926. }
  7927. else
  7928. {
  7929. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7930. }
  7931. }
  7932. else if ("SysAdmin".Equals(myOrgCode))
  7933. {
  7934. }
  7935. else
  7936. {
  7937. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7938. {
  7939. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7940. }
  7941. else
  7942. {
  7943. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7944. }
  7945. }
  7946. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7947. dStruct.Order = "created desc";
  7948. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7949. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7950. dt.Columns.Add("refund_fees");
  7951. foreach (DataRow dr in dt.Rows)
  7952. {
  7953. String status = dr["status"].ToString();
  7954. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7955. {
  7956. dr["refund_fees"] = dr["refund_fee"];
  7957. }
  7958. else
  7959. {
  7960. dr["refund_fees"] = "0.0";
  7961. }
  7962. }
  7963. writeGridDataTableJson(dStruct.TotalCount, dt);
  7964. }
  7965. public void handle_erp_refundtag()
  7966. {
  7967. if (UrlPostParmsCheck("refund_id"))
  7968. {
  7969. string eid = GetPostString("refund_id");
  7970. string respMan = GetPostString("ResponsibleName");
  7971. if (respMan.Length <= 0)
  7972. {
  7973. returnErrorMsg("责任人不能为空");
  7974. return;
  7975. }
  7976. CeErpTradeRefund entity = null;
  7977. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7978. if (entity != null)
  7979. {
  7980. entity.ResponsibleUserName = respMan;
  7981. string userid = GetPostString("ResponsibleUserId");
  7982. if (userid.Length > 0)
  7983. {
  7984. entity.ResponsibleUserId = userid;
  7985. }
  7986. entity.Memo = GetPostString("Memo");
  7987. if (respMan.IndexOf("客服") != -1 ||
  7988. respMan.IndexOf("设计师") != -1 ||
  7989. respMan.IndexOf("下单员") != -1)
  7990. {
  7991. entity.RefundState = 2;
  7992. }
  7993. else
  7994. {
  7995. entity.RefundState = 3;
  7996. }
  7997. entity.modified = DateTime.Now;
  7998. entity.Update();
  7999. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8000. returnSuccessMsg("操作成功!");
  8001. return;
  8002. }
  8003. returnErrorMsg("找不到订单记录");
  8004. }
  8005. }
  8006. public void handle_erp_designrefundtag()
  8007. {
  8008. if (UrlPostParmsCheck("refund_id"))
  8009. {
  8010. string eid = GetPostString("refund_id");
  8011. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8012. if (ceErpTradeCellExtend == null)
  8013. {
  8014. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8015. ceErpTradeCellExtend.ctid = eid;
  8016. }
  8017. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8018. if (ceErpTradeCellExtend.ID > 0)
  8019. {
  8020. ceErpTradeCellExtend.Update();
  8021. }
  8022. else
  8023. {
  8024. ceErpTradeCellExtend.Create();
  8025. }
  8026. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8027. returnSuccessMsg("操作成功!");
  8028. return;
  8029. }
  8030. returnErrorMsg("找不到订单记录");
  8031. }
  8032. public void upd_erp_refundverify()
  8033. {
  8034. if (UrlPostParmsCheck("refund_id"))
  8035. {
  8036. string eid = GetPostString("refund_id");
  8037. CeErpTradeRefund entity = null;
  8038. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8039. if (entity != null)
  8040. {
  8041. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8042. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8043. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8044. {
  8045. entity.RefundState = 2;
  8046. }
  8047. else
  8048. {
  8049. entity.RefundState = 3;
  8050. }
  8051. entity.Update();
  8052. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8053. returnSuccessMsg("操作成功!");
  8054. return;
  8055. }
  8056. returnErrorMsg("找不到订单记录");
  8057. }
  8058. }
  8059. public void upd_erp_refundapprove()
  8060. {
  8061. if (UrlPostParmsCheck("refund_id"))
  8062. {
  8063. string eid = GetPostString("refund_id");
  8064. CeErpTradeRefund entity = null;
  8065. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8066. if (entity != null)
  8067. {
  8068. int apr = GetPostInt("approve");
  8069. if (apr == 0)
  8070. {
  8071. entity.RefundState = 1;
  8072. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8073. }
  8074. else if (apr == 1)
  8075. {
  8076. entity.RefundState = 3;
  8077. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8078. }
  8079. entity.modified = DateTime.Now;
  8080. entity.Update();
  8081. returnSuccessMsg("操作成功!");
  8082. return;
  8083. }
  8084. returnErrorMsg("找不到订单记录");
  8085. }
  8086. }
  8087. public void get_erp_billlist()
  8088. {
  8089. DataStruct dStruct = GetPostStruct();
  8090. List<string> lw = new List<string>();
  8091. string title = GetPostString("title");
  8092. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8093. string tid = GetPostString("tid");
  8094. string tids = GetPostString("tids");
  8095. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8096. if (tids.Length > 0)
  8097. {
  8098. tids = "'" + tids + "'";
  8099. tids = tids.Replace(",", "','");
  8100. lw.Add(string.Format("tid in ({0})", tids));
  8101. }
  8102. string shopname = GetPostString("shopname");
  8103. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8104. string buyernick = GetPostString("buyer_nick");
  8105. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8106. string customer = GetPostString("customer");
  8107. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8108. string date1 = GetPostString("date1");
  8109. string date2 = GetPostString("date2");
  8110. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8111. if (dw.Length > 0) lw.Add(dw);
  8112. string price1 = GetPostString("price1");
  8113. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8114. string price2 = GetPostString("price2");
  8115. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8116. string returndate1 = GetPostString("returndate1");
  8117. string returndate2 = GetPostString("returndate2");
  8118. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8119. if (dw1.Length > 0) lw.Add(dw1);
  8120. string billtype = GetPostString("billtype");
  8121. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8122. string billstate = GetPostString("billstate");
  8123. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8124. string usershop = CurrentUser.User.pemShop;
  8125. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8126. dStruct.Order = "createTime desc";
  8127. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8128. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8129. //foreach (DataRow dr in dt.Rows)
  8130. //{
  8131. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8132. //}
  8133. writeGridDataTableJson(dStruct.TotalCount, dt);
  8134. }
  8135. public void modify_erp_billinfo()
  8136. {
  8137. if (UrlPostParmsCheck("ID"))
  8138. {
  8139. string eid = GetPostString("ID");
  8140. CeErpBill bill_entity = null;
  8141. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8142. if (bill_entity != null)
  8143. {
  8144. bill_entity.tid = GetPostString("tid");
  8145. bill_entity.title = GetPostString("title");
  8146. bill_entity.tax = GetPostString("tax");
  8147. bill_entity.bank = GetPostString("bank");
  8148. bill_entity.bankac = GetPostString("bankac");
  8149. bill_entity.address = GetPostString("address");
  8150. bill_entity.phone = GetPostString("phone");
  8151. bill_entity.price = GetPostString("price");
  8152. bill_entity.productId = GetPostInt("ProductName");
  8153. bill_entity.num = GetPostInt("num");
  8154. bill_entity.unit = GetPostString("unit");
  8155. bill_entity.type = GetPostString("type");
  8156. bill_entity.sendType = GetPostString("SendType");
  8157. bill_entity.email = GetPostString("email");
  8158. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8159. bill_entity.shopName = GetPostString("ShopName");
  8160. bill_entity.applymemo = GetPostString("applymemo");
  8161. bill_entity.modifyTime = DateTime.Now;
  8162. bill_entity.createTime = DateTime.Now;
  8163. bill_entity.state = 0;
  8164. bill_entity.Update();
  8165. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8166. returnSuccessMsg("发票修改成功!");
  8167. return;
  8168. }
  8169. returnErrorMsg("找不到对应记录");
  8170. }
  8171. }
  8172. public void set_erp_invoicing()
  8173. {
  8174. if (UrlPostParmsCheck("id"))
  8175. {
  8176. try
  8177. {
  8178. string eid = GetPostString("id");
  8179. CeErpBill bill_entity = null;
  8180. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8181. if (bill_entity != null)
  8182. {
  8183. int ComId = GetPostInt("ComId");
  8184. //string memo = GetPostString("Memo");
  8185. int allInfo = GetPostInt("allinfo");
  8186. string clert = CurrentUser.User.Name;
  8187. //string detailValue = GetPostString("detailvalue");
  8188. string billId = bill_entity.billOrderId;
  8189. string[] billIdList = billId.Split(',');
  8190. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8191. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8192. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8193. {
  8194. billCount += 1;
  8195. }
  8196. if (billId.Length <= 0 || billIdList.Length != billCount)
  8197. {
  8198. bill_entity.billOrderId = "";
  8199. string prebill = "ltb";
  8200. for (int idx = 1; idx <= billCount; idx++)
  8201. {
  8202. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8203. string billoid = prebill + idx + dtstr;
  8204. bill_entity.billOrderId += billoid;
  8205. if (idx < billCount)
  8206. {
  8207. bill_entity.billOrderId += ",";
  8208. }
  8209. }
  8210. }
  8211. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8212. if (bill_entity.state == 5)
  8213. {
  8214. string errMsg = bill_entity.failerror;
  8215. string[] errlist = errMsg.Split('|');
  8216. string[] errTags = new string[errlist.Length];
  8217. for (int itag = 0; itag < errlist.Length; itag++)
  8218. {
  8219. if (errlist[itag].Length <= 0) continue;
  8220. errTags[itag] = errlist[itag].Split('&')[0];
  8221. }
  8222. for (int iii = 0; iii < errTags.Length; iii++)
  8223. {
  8224. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8225. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8226. if (billOrderList.Length >= erroBillOrderTag)
  8227. {
  8228. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8229. if (needModifyBillId.Length <= 19)
  8230. {
  8231. needModifyBillId = needModifyBillId + "1";
  8232. }
  8233. else
  8234. {
  8235. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8236. last = last + 1;
  8237. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8238. }
  8239. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8240. }
  8241. }
  8242. }
  8243. bool isHaveBillSucces = false;
  8244. string totalRes = "";
  8245. bill_entity.failerror = "";
  8246. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8247. {
  8248. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8249. totalRes += res;
  8250. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8251. {
  8252. isHaveBillSucces = true;
  8253. bill_entity.comId = ComId;
  8254. bill_entity.state = 1;
  8255. bill_entity.executeTime = DateTime.Now;
  8256. bill_entity.executeUser = clert;
  8257. }
  8258. else
  8259. {
  8260. bill_entity.state = 5;
  8261. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8262. }
  8263. }
  8264. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8265. bill_entity.Update();
  8266. if (isHaveBillSucces)
  8267. {
  8268. StringBuilder sql = new StringBuilder();
  8269. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8270. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8271. }
  8272. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8273. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8274. {
  8275. returnErrorMsg("开票失败");
  8276. }
  8277. else
  8278. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8279. return;
  8280. }
  8281. returnErrorMsg("找不到对应记录");
  8282. }
  8283. catch (Exception ex)
  8284. {
  8285. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8286. returnErrorMsg("操作失败");
  8287. }
  8288. }
  8289. }
  8290. public void get_erp_invoicing_back()
  8291. {
  8292. if (UrlPostParmsCheck("id"))
  8293. {
  8294. try
  8295. {
  8296. string id = GetPostString("id");
  8297. CeErpBill entiy = CeErpBill.Get(id);
  8298. if (entiy != null)
  8299. {
  8300. if (entiy.state == 0)
  8301. {
  8302. returnErrorMsg("发票还未开具");
  8303. return;
  8304. }
  8305. string[] billOrderList = entiy.billOrderId.Split(',');
  8306. int iTag = 0;
  8307. entiy.fplsh = "";
  8308. entiy.fpdm = "";
  8309. entiy.fphm = "";
  8310. foreach (string billOrderId in billOrderList)
  8311. {
  8312. iTag++;
  8313. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8314. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8315. {
  8316. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8317. try
  8318. {
  8319. Invoicing_get_response_Obj iObj = null;
  8320. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8321. if (iObj != null)
  8322. {
  8323. entiy.state = 2;
  8324. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8325. entiy.fpdm += iObj.list[0].c_fpdm;
  8326. entiy.fphm += iObj.list[0].c_fphm;
  8327. if (iTag < billOrderList.Length)
  8328. {
  8329. entiy.fplsh += ",";
  8330. entiy.fpdm += ",";
  8331. entiy.fphm += ",";
  8332. }
  8333. entiy.Update();
  8334. }
  8335. StringBuilder sql = new StringBuilder();
  8336. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8337. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8338. returnSuccessMsg("开票成功");
  8339. }
  8340. catch (Exception ex)
  8341. {
  8342. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8343. }
  8344. return;
  8345. }
  8346. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8347. {
  8348. var res_obj = new
  8349. {
  8350. data = "开票中"
  8351. };
  8352. string ro_json = JsonConvert.SerializeObject(res_obj);
  8353. returnSuccess(ro_json);
  8354. return;
  8355. }
  8356. else
  8357. {
  8358. int eidx = res.IndexOf("c_resultmsg");
  8359. int lidx = res.IndexOf("c_status");
  8360. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8361. entiy.state = 5;
  8362. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8363. entiy.Update();
  8364. returnErrorMsg("开票失败");
  8365. return;
  8366. }
  8367. }
  8368. }
  8369. }
  8370. catch (Exception ex)
  8371. {
  8372. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8373. }
  8374. return;
  8375. }
  8376. }
  8377. public void get_erp_invoicing()
  8378. {
  8379. if (UrlPostParmsCheck("id"))
  8380. {
  8381. try
  8382. {
  8383. string id = GetPostString("id");
  8384. CeErpBill entiy = CeErpBill.Get(id);
  8385. if (entiy != null)
  8386. {
  8387. if (entiy.state == 0)
  8388. {
  8389. returnErrorMsg("发票还未开具");
  8390. return;
  8391. }
  8392. if (entiy.sendType == "纸质发票")
  8393. {
  8394. if (entiy.img.Length <= 0)
  8395. {
  8396. returnErrorMsg("查无纸质发票");
  8397. return;
  8398. }
  8399. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8400. returnSuccess(returnres);
  8401. return;
  8402. }
  8403. string[] billOrderList = entiy.billOrderId.Split(',');
  8404. int iTag = 0;
  8405. string fpUrl = "";
  8406. entiy.fplsh = "";
  8407. entiy.fpdm = "";
  8408. entiy.fphm = "";
  8409. foreach (string billOrderId in billOrderList)
  8410. {
  8411. iTag++;
  8412. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8413. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8414. {
  8415. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8416. Invoicing_get_response_Obj iObj = null;
  8417. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8418. if (iObj != null)
  8419. {
  8420. //entiy.state = 2;
  8421. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8422. entiy.fpdm += iObj.list[0].c_fpdm;
  8423. entiy.fphm += iObj.list[0].c_fphm;
  8424. if (iTag < billOrderList.Length)
  8425. {
  8426. entiy.fplsh += ",";
  8427. entiy.fpdm += ",";
  8428. entiy.fphm += ",";
  8429. }
  8430. entiy.Update();
  8431. fpUrl += iObj.list[0].c_url + ",";
  8432. }
  8433. //returnSuccess(res);
  8434. StringBuilder sql = new StringBuilder();
  8435. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8436. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8437. }
  8438. else
  8439. {
  8440. int eidx = res.IndexOf("c_resultmsg");
  8441. //int lidx = res.IndexOf("c_status");
  8442. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8443. //开票失败
  8444. entiy.state = 5;
  8445. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8446. entiy.Update();
  8447. returnErrorMsg("开票失败");
  8448. return;
  8449. }
  8450. }
  8451. var returnObj = new
  8452. {
  8453. data = fpUrl
  8454. };
  8455. string ro_json = JsonConvert.SerializeObject(returnObj);
  8456. returnSuccess(ro_json);
  8457. }
  8458. }
  8459. catch (Exception ex)
  8460. {
  8461. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8462. }
  8463. return;
  8464. }
  8465. }
  8466. public void save_erp_billimg()
  8467. {
  8468. if (UrlPostParmsCheck("id"))
  8469. {
  8470. string eid = GetPostString("id");
  8471. CeErpBill bill_entity = null;
  8472. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8473. if (bill_entity != null)
  8474. {
  8475. bill_entity.img = GetPostString("img");
  8476. bill_entity.executeTime = DateTime.Now;
  8477. bill_entity.state = 2;
  8478. bill_entity.Update();
  8479. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8480. returnSuccessMsg("保存成功");
  8481. }
  8482. return;
  8483. }
  8484. }
  8485. public void upd_erp_billreturnback()
  8486. {
  8487. if (UrlPostParmsCheck("id"))
  8488. {
  8489. int eid = GetPostInt("id");
  8490. CeErpBill bill_entity = null;
  8491. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8492. if (bill_entity != null)
  8493. {
  8494. bill_entity.state = 3;
  8495. bill_entity.returnReason = GetPostString("reason");
  8496. bill_entity.Update();
  8497. returnSuccessMsg("驳回成功!");
  8498. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8499. }
  8500. return;
  8501. }
  8502. }
  8503. public void cancel_erp_bill()
  8504. {
  8505. if (UrlPostParmsCheck("id"))
  8506. {
  8507. int eid = GetPostInt("id");
  8508. int detailValue = GetPostInt("detailvalue");
  8509. CeErpBill bill_entity = null;
  8510. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8511. string cres = "";
  8512. string gres = "";
  8513. if (bill_entity != null)
  8514. {
  8515. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8516. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8517. {
  8518. int iTag = 0;
  8519. bill_entity.fplsh = "";
  8520. bill_entity.fpdm = "";
  8521. bill_entity.fphm = "";
  8522. foreach (string billOrderId in billOrderList)
  8523. {
  8524. iTag++;
  8525. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8526. if (gres.IndexOf("success") != -1)
  8527. {
  8528. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8529. Invoicing_get_response_Obj iObj = null;
  8530. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8531. if (iObj != null)
  8532. {
  8533. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8534. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8535. bill_entity.fphm += iObj.list[0].c_fphm;
  8536. if (iTag < billOrderList.Length)
  8537. {
  8538. bill_entity.fplsh += ",";
  8539. bill_entity.fpdm += ",";
  8540. bill_entity.fphm += ",";
  8541. }
  8542. bill_entity.Update();
  8543. }
  8544. }
  8545. else
  8546. {
  8547. returnErrorMsg(gres);
  8548. return;
  8549. }
  8550. }
  8551. }
  8552. if (bill_entity.sendType == "纸质发票")
  8553. {
  8554. //作废
  8555. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8556. //if (DateTime.Now.Month == extime.Month)
  8557. //{
  8558. //cres = taobaoHelper.cancel_invoicing(eid);
  8559. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8560. //{
  8561. bill_entity.state = 4;//已作废
  8562. bill_entity.Update();
  8563. returnSuccessMsg("发票已作废");
  8564. return;
  8565. //}
  8566. //else
  8567. //{
  8568. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8569. // bill_entity.Update();
  8570. // returnErrorMsg(cres);
  8571. // return;
  8572. //}
  8573. //}
  8574. //else
  8575. //{
  8576. // returnErrorMsg("纸质发票只能作废本月的发票");
  8577. // return;
  8578. //}
  8579. }
  8580. //红冲
  8581. int redTag = 0;
  8582. string[] fpdmList = bill_entity.fpdm.Split(',');
  8583. string[] fphmList = bill_entity.fphm.Split(',');
  8584. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8585. {
  8586. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8587. return;
  8588. }
  8589. foreach (string billOrderId in billOrderList)
  8590. {
  8591. redTag++;
  8592. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8593. cres += onecres;
  8594. cres += ",";
  8595. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8596. {
  8597. bill_entity.state = 4;//已作废
  8598. //bill_entity.Update();
  8599. //returnSuccessMsg("发票已红冲");
  8600. }
  8601. else if (onecres.IndexOf("重复冲红") != -1)
  8602. {
  8603. bill_entity.state = 4;//已作废
  8604. //bill_entity.Update();
  8605. //returnSuccessMsg("发票已红冲");
  8606. }
  8607. else
  8608. {
  8609. string errmsg = commonHelper.KeepChinese(onecres);
  8610. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8611. }
  8612. }
  8613. bill_entity.Update();
  8614. if (cres.IndexOf("失败") != -1)
  8615. returnErrorMsg("红冲失败");
  8616. else
  8617. returnSuccessMsg("发票已红冲");
  8618. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8619. return;
  8620. }
  8621. return;
  8622. }
  8623. }
  8624. public void del_erp_billorder()
  8625. {
  8626. if (UrlPostParmsCheck("id"))
  8627. {
  8628. string eid = GetPostString("id");
  8629. CeErpBill.Del(eid);
  8630. CeErpBill bill = CeErpBill.Get(eid);
  8631. if (bill != null)
  8632. {
  8633. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8634. }
  8635. returnSuccessMsg("删除成功");
  8636. }
  8637. }
  8638. public void finish_erp_bill()
  8639. {
  8640. if (UrlPostParmsCheck("ids"))
  8641. {
  8642. string eids = GetPostString("ids");
  8643. string[] list = eids.Split(',');
  8644. foreach (string eid in list)
  8645. {
  8646. CeErpBill bill = CeErpBill.Get(eid);
  8647. if (bill != null)
  8648. {
  8649. bill.state = 2;
  8650. bill.Update();
  8651. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8652. }
  8653. }
  8654. returnSuccessMsg("操作成功");
  8655. }
  8656. }
  8657. public void get_erp_returncash()
  8658. {
  8659. DataStruct dStruct = GetPostStruct();
  8660. List<string> lw = new List<string>();
  8661. string tid = GetPostString("tid");
  8662. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8663. string shopname = GetPostString("shopname");
  8664. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8665. string buyernick = GetPostString("buyer_nick");
  8666. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8667. string customer = GetPostString("customer");
  8668. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8669. string returndate1 = GetPostString("returndate1");
  8670. string returndate2 = GetPostString("returndate2");
  8671. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8672. if (dw.Length > 0) lw.Add(dw);
  8673. string finishDate1 = GetPostString("finishdate1");
  8674. string finishDate2 = GetPostString("finishdate2");
  8675. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8676. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8677. string returntype = GetPostString("returntype");
  8678. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8679. string returnvstate = GetPostString("returnvstate");
  8680. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8681. dStruct.Order = "created desc";
  8682. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8683. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8684. writeGridDataTableJson(dStruct.TotalCount, dt);
  8685. }
  8686. public void get_erp_staygoods()
  8687. {
  8688. DataStruct dStruct = GetPostStruct();
  8689. List<string> lw = new List<string>();
  8690. string tid = GetPostString("tid");
  8691. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8692. string shopname = GetPostString("shopname");
  8693. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8694. string wangwang = GetPostString("wangwang");
  8695. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8696. string customer = GetPostString("customer");
  8697. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8698. string returndate1 = GetPostString("returndate1");
  8699. string returndate2 = GetPostString("returndate2");
  8700. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8701. if (dw.Length > 0) lw.Add(dw);
  8702. string finishDate1 = GetPostString("finishdate1");
  8703. string finishDate2 = GetPostString("finishdate2");
  8704. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8705. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8706. string returnvstate = GetPostString("returnvstate");
  8707. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8708. string persuadetype = GetPostString("persuadetype");
  8709. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8710. string customerOrg = GetPostString("customerOrg");
  8711. if (customerOrg.Length > 0)
  8712. {
  8713. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8714. }
  8715. dStruct.Order = "creata_time desc";
  8716. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8717. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8718. writeGridDataTableJson(dStruct.TotalCount, dt);
  8719. }
  8720. public void upd_erp_staygoods()
  8721. {
  8722. if (UrlPostParmsCheck("id"))
  8723. {
  8724. int eid = GetPostInt("id");
  8725. CeErpStayGoods entity = null;
  8726. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8727. if (entity != null)
  8728. {
  8729. entity.audit_type = 1;
  8730. entity.audit_time = DateTime.Now;
  8731. entity.audit_u_id = CurrentUser.UserID;
  8732. entity.audit_u_name = CurrentUser.UserName;
  8733. entity.Update();
  8734. returnSuccessMsg("审核成功!");
  8735. return;
  8736. }
  8737. returnErrorMsg("找不到订单记录");
  8738. }
  8739. }
  8740. public void upd_erp_stayGoodsback()
  8741. {
  8742. if (UrlPostParmsCheck("id"))
  8743. {
  8744. int eid = GetPostInt("id");
  8745. CeErpStayGoods entity = null;
  8746. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8747. if (entity != null)
  8748. {
  8749. entity.audit_text = GetPostString("reason");
  8750. entity.audit_type = 2;
  8751. entity.audit_time = DateTime.Now;
  8752. entity.audit_u_id = CurrentUser.UserID;
  8753. entity.audit_u_name = CurrentUser.UserName;
  8754. entity.Update();
  8755. returnSuccessMsg("退回成功!");
  8756. return;
  8757. }
  8758. returnErrorMsg("找不到订单记录");
  8759. }
  8760. }
  8761. public void upd_erp_returncashverify()
  8762. {
  8763. if (UrlPostParmsCheck("ID"))
  8764. {
  8765. int eid = GetPostInt("ID");
  8766. CeErpReturnCash entity = null;
  8767. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8768. if (entity != null)
  8769. {
  8770. entity.cashstate = 1;
  8771. entity.verifytime = DateTime.Now;
  8772. entity.verifyuserid = CurrentUser.UserID;
  8773. entity.Update();
  8774. returnSuccessMsg("审核成功!");
  8775. return;
  8776. }
  8777. returnErrorMsg("找不到订单记录");
  8778. }
  8779. }
  8780. public void upd_all_erp_returncashverify()
  8781. {
  8782. if (UrlPostParmsCheck("ID"))
  8783. {
  8784. String[] list = GetPostString("ID").Split(',');
  8785. CeErpReturnCash entity = null;
  8786. for (int i = 0; i < list.Length; i++)
  8787. {
  8788. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8789. if (entity != null)
  8790. {
  8791. if (entity.cashstate == 1)
  8792. {
  8793. returnErrorMsg("已审核过的订单不需要在审核!");
  8794. return;
  8795. }
  8796. entity.cashstate = 1;
  8797. entity.verifytime = DateTime.Now;
  8798. entity.verifyuserid = CurrentUser.UserID;
  8799. entity.Update();
  8800. }
  8801. }
  8802. returnSuccessMsg("审核成功!");
  8803. return;
  8804. }
  8805. }
  8806. public void upd_erp_returncashback()
  8807. {
  8808. if (UrlPostParmsCheck("ID"))
  8809. {
  8810. int eid = GetPostInt("ID");
  8811. CeErpReturnCash entity = null;
  8812. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8813. if (entity != null)
  8814. {
  8815. entity.backreason = GetPostString("reason");
  8816. entity.cashstate = 2;
  8817. entity.verifytime = DateTime.Now;
  8818. entity.verifyuserid = CurrentUser.UserID;
  8819. entity.Update();
  8820. returnSuccessMsg("退回成功!");
  8821. return;
  8822. }
  8823. returnErrorMsg("找不到订单记录");
  8824. }
  8825. }
  8826. public void upd_erp_returnprice()
  8827. {
  8828. if (UrlPostParmsCheck("ID"))
  8829. {
  8830. int eid = GetPostInt("ID");
  8831. CeErpReturnCash entity = null;
  8832. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8833. if (entity != null)
  8834. {
  8835. if (entity.cashstate == 1)
  8836. {
  8837. returnErrorMsg("审核通过了不能改");
  8838. return;
  8839. }
  8840. entity.returnprice = GetPostDouble("returnprice");
  8841. entity.Update();
  8842. returnSuccessMsg("修改成功!");
  8843. return;
  8844. }
  8845. returnErrorMsg("找不到订单记录");
  8846. }
  8847. }
  8848. public void del_erp_returncash()
  8849. {
  8850. if (UrlPostParmsCheck("ID"))
  8851. {
  8852. int eid = GetPostInt("ID");
  8853. CeErpReturnCash.Del(eid);
  8854. returnSuccessMsg("操作成功");
  8855. return;
  8856. }
  8857. }
  8858. public void test_for_do_sql()
  8859. {
  8860. string sql = GetPostString("sqlstr");
  8861. if (sql.Length > 0)
  8862. {
  8863. try
  8864. {
  8865. DbHelper.DbConn.ExecuteNonQuery(sql);
  8866. var res_obj = new
  8867. {
  8868. data = "成功",
  8869. };
  8870. string ro_json = JsonConvert.SerializeObject(res_obj);
  8871. returnSuccess(ro_json);
  8872. }
  8873. catch (Exception ex)
  8874. {
  8875. var res_obj = new
  8876. {
  8877. data = ex.Message,
  8878. };
  8879. string ro_json = JsonConvert.SerializeObject(res_obj);
  8880. returnSuccess(ro_json);
  8881. }
  8882. }
  8883. }
  8884. public void get_user_info()
  8885. {
  8886. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8887. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8888. }
  8889. public void get_total_data()
  8890. {
  8891. int userId = CurrentUser.UserID;
  8892. string sql = "";
  8893. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8894. {
  8895. 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);
  8896. }
  8897. else
  8898. {
  8899. 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 " +
  8900. "(select ID from CE_ErpUser where ID = {0}) d " +
  8901. "left join " +
  8902. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8903. ") a on d.ID = a.id left join " +
  8904. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8905. ") b on a.id = b.id1 left join" +
  8906. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8907. ") c on a.id = c.id2;", userId);
  8908. }
  8909. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8910. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8911. }
  8912. public void get_date_area_total_data2()
  8913. {
  8914. int userId = CurrentUser.UserID;
  8915. string date_type = GetPostString("timetype");
  8916. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8917. string sql = "";
  8918. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8919. {
  8920. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8921. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8922. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8923. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8924. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8925. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8926. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8927. ") a on e.ID = a.id left join " +
  8928. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8929. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8930. ") b on a.id = b.id1 " +
  8931. "left join " +
  8932. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8933. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8934. ") c on a.id = c.id2 " +
  8935. "left join " +
  8936. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8937. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8938. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8939. }
  8940. else
  8941. {
  8942. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8943. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8944. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8945. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8946. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8947. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8948. ") a on e.ID = a.id left join " +
  8949. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8950. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8951. ") c on a.id = c.id2 " +
  8952. "left join " +
  8953. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8954. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8955. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8956. }
  8957. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8958. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8959. }
  8960. public void get_date_area_total_data()
  8961. {
  8962. int userId = CurrentUser.UserID;
  8963. string date_type = GetPostString("timetype");
  8964. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8965. string date1 = searchDT[0].ToString();
  8966. string date2 = searchDT[1].ToString();
  8967. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8968. {
  8969. SqlParameter[] sqlParameter ={
  8970. new SqlParameter("@userId", SqlDbType.Int,4),
  8971. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8972. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8973. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8974. };
  8975. sqlParameter[0].Value = userId;
  8976. sqlParameter[1].Value = date1;
  8977. sqlParameter[2].Value = date2;
  8978. sqlParameter[3].Direction = ParameterDirection.Output;
  8979. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8980. string res = sqlParameter[3].Value.ToString();
  8981. var res_obj = new
  8982. {
  8983. data = res
  8984. };
  8985. string ro_json = JsonConvert.SerializeObject(res_obj);
  8986. returnSuccess(ro_json);
  8987. }
  8988. else
  8989. {
  8990. SqlParameter[] sqlParameter ={
  8991. new SqlParameter("@userId", SqlDbType.Int,4),
  8992. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8993. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8994. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8995. };
  8996. sqlParameter[0].Value = userId;
  8997. sqlParameter[1].Value = date1;
  8998. sqlParameter[2].Value = date2;
  8999. sqlParameter[3].Direction = ParameterDirection.Output;
  9000. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9001. string res = sqlParameter[3].Value.ToString();
  9002. var res_obj = new
  9003. {
  9004. data = res
  9005. };
  9006. string ro_json = JsonConvert.SerializeObject(res_obj);
  9007. returnSuccess(ro_json);
  9008. }
  9009. //writeGridDataViewJson(dt.Rows.Count, dv);
  9010. }
  9011. public void get_order_list()
  9012. {
  9013. string strFields = GetPostString("paraFields");
  9014. string strOrder = GetPostString("paraOrder");
  9015. string strWhere = GetPostString("paraWhere");
  9016. string strPageSize = GetPostString("paraPageSize");
  9017. DataStruct dStruct = GetPostStruct();
  9018. dStruct.PageSize = int.Parse(strPageSize);
  9019. dStruct.Fileds = strFields;
  9020. dStruct.Order = strOrder;
  9021. dStruct.MainWhere = strWhere;
  9022. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9023. writeGridDataTableJson(dStruct.TotalCount, dt);
  9024. }
  9025. ////获取待开始订单列表
  9026. //public void get_wait_design_order_list()
  9027. //{
  9028. // string date_type = GetPostString("date_type");
  9029. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9030. // DataStruct dStruct = GetPostStruct();
  9031. // dStruct.PageSize = 1000;
  9032. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9033. // List<string> lw = new List<string>();
  9034. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9035. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9036. // dStruct.Order = "WaitDesignTime asc";
  9037. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9038. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9039. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9040. //}
  9041. //获取完成单量排名
  9042. public void get_finish_order_count_ranking()
  9043. {
  9044. /* string date_type = GetPostString("date_type");
  9045. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9046. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9047. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9048. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9049. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9050. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9051. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9052. writeGridDataTableJson(0, new DataTable());
  9053. }
  9054. public void get_finish_order_amount_ranking()
  9055. {
  9056. /*string date_type = GetPostString("date_type");
  9057. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9058. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9059. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9060. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9061. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9062. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9063. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9064. writeGridDataTableJson(0, new DataTable());
  9065. }
  9066. public void get_finish_refund_count_ranking()
  9067. {
  9068. string date_type = GetPostString("date_type");
  9069. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9070. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9071. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9072. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9073. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9074. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9075. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9076. writeGridDataTableJson(dt.Rows.Count, dt);
  9077. }
  9078. public void get_finish_refund_amount_ranking()
  9079. {
  9080. string date_type = GetPostString("date_type");
  9081. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9082. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9083. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9084. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9085. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9086. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9087. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9088. writeGridDataTableJson(dt.Rows.Count, dt);
  9089. }
  9090. public void set_erp_finishorder_director()
  9091. {
  9092. if (UrlPostParmsCheck("ctid"))
  9093. {
  9094. string eid = GetPostString("ctid");
  9095. CeErpTradeCell entity = null;
  9096. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9097. if (entity != null)
  9098. {
  9099. entity.OrderState = 8;
  9100. entity.Update();
  9101. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9102. returnSuccessMsg("操作成功!");
  9103. return;
  9104. }
  9105. returnErrorMsg("找不到记录");
  9106. }
  9107. }
  9108. public void get_erp_placeregistlist()
  9109. {
  9110. DataStruct dStruct = GetPostStruct();
  9111. List<string> lw = new List<string>();
  9112. string outsid = GetPostString("outsid");
  9113. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9114. string memo = GetPostString("memo");
  9115. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9116. string filename = GetPostString("filename");
  9117. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9118. string islate = GetPostString("islate");
  9119. if (islate.Length > 0)
  9120. {
  9121. if (islate == "1")
  9122. lw.Add(string.Format("OutLate>0"));
  9123. else
  9124. lw.Add(string.Format("OutLate=0"));
  9125. }
  9126. string placedate1 = GetPostString("placedate1");
  9127. string placedate2 = GetPostString("placedate2");
  9128. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9129. if (dw.Length > 0) lw.Add(dw);
  9130. string deliveryDate1 = GetPostString("deliverydate1");
  9131. string deliveryDate2 = GetPostString("deliverydate2");
  9132. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9133. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9134. dStruct.Order = "ID desc";
  9135. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9136. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9137. writeGridDataTableJson(dStruct.TotalCount, dt);
  9138. }
  9139. public void ins_erp_placeregist()
  9140. {
  9141. if (UrlPostParmsCheck("id"))
  9142. {
  9143. string eid = GetPostString("id");
  9144. CeErpPlaceRegister entity = null;
  9145. if (eid == "0")//新增
  9146. {
  9147. entity = new CeErpPlaceRegister();
  9148. string xdTime = GetPostString("placeTime");
  9149. if (xdTime.Length > 0)
  9150. {
  9151. entity.PlactTime = Convert.ToDateTime(xdTime);
  9152. }
  9153. string fhTime = GetPostString("deliveryTime");
  9154. if (fhTime.Length > 0)
  9155. {
  9156. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9157. }
  9158. string preTime = GetPostString("preOutTime");
  9159. if (preTime.Length > 0)
  9160. {
  9161. entity.PreOutTime = Convert.ToDateTime(preTime);
  9162. }
  9163. entity.DeliveryCount = GetPostInt("deliveryCount");
  9164. entity.ReceiveCount = GetPostInt("receiveCount");
  9165. entity.OutSid = GetPostString("outSid");
  9166. entity.FileName = GetPostString("fileName");
  9167. entity.Memo = GetPostString("memo");
  9168. entity.AddUserId = CurrentUser.UserID;
  9169. entity.CreateTime = DateTime.Now;
  9170. entity.Img = GetPostString("img");
  9171. entity.Supplier = GetPostInt("supplier");
  9172. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9173. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9174. {
  9175. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9176. DateTime dt2 = (DateTime)entity.PreOutTime;
  9177. TimeSpan span = dt1.Subtract(dt2);
  9178. if (span.Days > 0)
  9179. {
  9180. entity.OutLate = span.Days;
  9181. }
  9182. }
  9183. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9184. entity.Create();
  9185. returnSuccessMsg("添加成功!");
  9186. return;
  9187. }
  9188. else //修改
  9189. {
  9190. entity = CeErpPlaceRegister.Get(eid);
  9191. if (entity != null)
  9192. {
  9193. string xdTime = GetPostString("placeTime");
  9194. if (xdTime.Length > 0)
  9195. {
  9196. entity.PlactTime = Convert.ToDateTime(xdTime);
  9197. }
  9198. string fhTime = GetPostString("deliveryTime");
  9199. if (fhTime.Length > 0)
  9200. {
  9201. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9202. }
  9203. string preTime = GetPostString("preOutTime");
  9204. if (preTime.Length > 0)
  9205. {
  9206. entity.PreOutTime = Convert.ToDateTime(preTime);
  9207. }
  9208. entity.DeliveryCount = GetPostInt("deliveryCount");
  9209. entity.ReceiveCount = GetPostInt("receiveCount");
  9210. if (entity.DeliveryCount == entity.ReceiveCount)
  9211. {
  9212. entity.CurState = "已完成";
  9213. }
  9214. else
  9215. {
  9216. entity.CurState = "未完成";
  9217. }
  9218. entity.OutSid = GetPostString("outSid");
  9219. entity.FileName = GetPostString("fileName");
  9220. entity.Memo = GetPostString("memo");
  9221. entity.Img = GetPostString("img");
  9222. entity.Supplier = GetPostInt("supplier");
  9223. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9224. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9225. {
  9226. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9227. DateTime dt2 = (DateTime)entity.PreOutTime;
  9228. TimeSpan span = dt1.Subtract(dt2);
  9229. if (span.Days > 0)
  9230. {
  9231. entity.OutLate = span.Days;
  9232. }
  9233. }
  9234. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9235. entity.Update();
  9236. returnSuccessMsg("修改成功");
  9237. return;
  9238. }
  9239. returnErrorMsg("找不到对应的记录");
  9240. return;
  9241. }
  9242. }
  9243. returnErrorMsg("缺少必要参数");
  9244. }
  9245. public void del_erp_placeregist()
  9246. {
  9247. string eid = GetPostString("id");
  9248. CeErpPlaceRegister.Del(eid);
  9249. returnSuccessMsg("删除成功!");
  9250. return;
  9251. }
  9252. public void ins_erp_placeregistbyorder()
  9253. {
  9254. string ctid = GetPostString("ctid");
  9255. if (ctid.Length > 0)
  9256. {
  9257. StringBuilder sql = new StringBuilder();
  9258. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9259. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9260. if (dt.Rows.Count > 0)
  9261. {
  9262. foreach (DataRow dr in dt.Rows)
  9263. {
  9264. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9265. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9266. entity.AddUserId = CurrentUser.UserID;
  9267. entity.tid = dr["tid"].ToString();
  9268. entity.Did = Convert.ToString(dr["ctid"]);
  9269. entity.splitTag = dr["SplitTag"].ToString();
  9270. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9271. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9272. if (pre_ctid.Length > 0)
  9273. {
  9274. sellmemo = sellmemo.Replace(pre_ctid, "");
  9275. }
  9276. sellmemo = sellmemo.Replace("[", "");
  9277. sellmemo = sellmemo.Replace("]", "");
  9278. entity.FileName = sellmemo;
  9279. string count = dr["ProductCount"].ToString();
  9280. int usecount = commonHelper.getIntCountFromString(count);
  9281. entity.DeliveryCount = usecount;
  9282. entity.CurState = "未完成";
  9283. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9284. {
  9285. entity.Supplier = 24;//dl手提袋定制
  9286. }
  9287. else
  9288. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9289. entity.CreateTime = DateTime.Now;
  9290. entity.Create();
  9291. }
  9292. returnSuccessMsg("操作成功");
  9293. return;
  9294. }
  9295. returnErrorMsg("没有找到对应订单");
  9296. return;
  9297. }
  9298. returnErrorMsg("缺少订单编号");
  9299. return;
  9300. }
  9301. public void get_erp_persuadelist()
  9302. {
  9303. DataStruct dStruct = GetPostStruct();
  9304. List<string> lw = new List<string>();
  9305. string ctid = GetPostString("ctid");
  9306. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9307. string shopname = GetPostString("shopname");
  9308. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9309. string buyernick = GetPostString("buyer_nick");
  9310. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9311. string customer = GetPostString("customer");
  9312. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9313. string returndate1 = GetPostString("returndate1");
  9314. string returndate2 = GetPostString("returndate2");
  9315. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9316. if (dw.Length > 0) lw.Add(dw);
  9317. string finishDate1 = GetPostString("finishdate1");
  9318. string finishDate2 = GetPostString("finishdate2");
  9319. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9320. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9321. string persuadetype = GetPostString("persuadetype");
  9322. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9323. string returnvstate = GetPostString("returnvstate");
  9324. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9325. dStruct.Order = "created desc";
  9326. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9327. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9328. writeGridDataTableJson(dStruct.TotalCount, dt);
  9329. }
  9330. public void upd_erp_returnpersuadeback()
  9331. {
  9332. if (UrlPostParmsCheck("ID"))
  9333. {
  9334. int eid = GetPostInt("ID");
  9335. CeErpPersuade entity = null;
  9336. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9337. if (entity != null)
  9338. {
  9339. entity.backreason = GetPostString("reason");
  9340. entity.pstate = 2;
  9341. entity.verifytime = DateTime.Now;
  9342. entity.verifyuserid = CurrentUser.UserID;
  9343. entity.Update();
  9344. returnSuccessMsg("退回成功!");
  9345. return;
  9346. }
  9347. returnErrorMsg("找不到订单记录");
  9348. }
  9349. }
  9350. public void upd_erp_returnpersuadeverify()
  9351. {
  9352. if (UrlPostParmsCheck("ID"))
  9353. {
  9354. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9355. {
  9356. returnErrorMsg("暂无权限审核");
  9357. return;
  9358. }
  9359. int eid = GetPostInt("ID");
  9360. CeErpPersuade entity = null;
  9361. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9362. if (entity != null)
  9363. {
  9364. entity.pstate = 1;
  9365. entity.verifytime = DateTime.Now;
  9366. entity.verifyuserid = CurrentUser.UserID;
  9367. entity.Update();
  9368. returnSuccessMsg("审核成功!");
  9369. return;
  9370. }
  9371. returnErrorMsg("找不到订单记录");
  9372. }
  9373. }
  9374. public void del_erp_persuade()
  9375. {
  9376. if (UrlPostParmsCheck("ID"))
  9377. {
  9378. int eid = GetPostInt("ID");
  9379. CeErpPersuade.Del(eid);
  9380. returnSuccessMsg("操作成功");
  9381. return;
  9382. }
  9383. }
  9384. public void get_erp_oldcustoupload()
  9385. {
  9386. DataStruct dStruct = GetPostStruct();
  9387. List<string> lw = new List<string>();
  9388. string buyernick = GetPostString("buyer_nick");
  9389. if (buyernick.Length > 0)
  9390. {
  9391. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9392. }
  9393. else
  9394. return;
  9395. dStruct.Order = "pay_time desc";
  9396. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9397. DataTable dt = null;
  9398. dt = WebCache.GetData("view_erptradecell", dStruct);
  9399. writeGridDataTableJson(dStruct.TotalCount, dt);
  9400. }
  9401. public void get_erp_checkorderlist()
  9402. {
  9403. DataStruct dStruct = GetPostStruct();
  9404. List<string> lw = new List<string>();
  9405. string tid = GetPostString("ctid");
  9406. if (tid.Length > 0)
  9407. {
  9408. string select_tid = getTidByCtid(tid);
  9409. lw.Add(string.Format("tid='{0}'", select_tid));
  9410. }
  9411. string shopname = GetPostString("shopname");
  9412. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9413. string buyernick = GetPostString("buyer_nick");
  9414. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9415. string customer = GetPostString("customer");
  9416. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9417. string design = GetPostString("design");
  9418. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9419. string orderState = GetPostString("orderState");
  9420. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9421. string address = GetPostString("address");
  9422. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9423. string sellermemo = GetPostString("seller_memo");
  9424. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9425. string supplier = GetPostString("supplier");
  9426. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9427. {
  9428. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9429. }
  9430. else
  9431. {
  9432. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9433. }
  9434. string date1 = GetPostString("date1");
  9435. string date2 = GetPostString("date2");
  9436. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9437. if (dw.Length > 0) lw.Add(dw);
  9438. string placedate1 = GetPostString("placedate1");
  9439. string placedate2 = GetPostString("placedate2");
  9440. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9441. if (fdw.Length > 0) lw.Add(fdw);
  9442. string price1 = GetPostString("price1");
  9443. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9444. string price2 = GetPostString("price2");
  9445. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9446. string checkst = GetPostString("checkstate");
  9447. if (checkst.Length > 0 && "10".Equals(checkst))
  9448. {
  9449. lw.Add(string.Format("CheckOut>0"));
  9450. }
  9451. else
  9452. {
  9453. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9454. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9455. }
  9456. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9457. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9458. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9459. writeGridDataTableJson(dStruct.TotalCount, dt);
  9460. }
  9461. public void ins_erp_startCheck()
  9462. {
  9463. if (UrlPostParmsCheck("ctid"))
  9464. {
  9465. string eid = GetPostString("ctid");
  9466. CeErpTradeCell entity = null;
  9467. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9468. if (entity != null)
  9469. {
  9470. entity.MemoOpt = 4;
  9471. entity.UpdateTime = DateTime.Now;
  9472. entity.Update();
  9473. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9474. CeErpSukuraData.createInfo(entity.ctid, 6);
  9475. returnSuccessMsg("操作成功!");
  9476. return;
  9477. }
  9478. returnErrorMsg("找不到记录");
  9479. }
  9480. }
  9481. public void upd_erp_sendXlw()
  9482. {
  9483. if (UrlPostParmsCheck("ctid"))
  9484. {
  9485. string eid = GetPostString("ctid");
  9486. CeErpTradeCell entity = null;
  9487. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9488. if (entity != null)
  9489. {
  9490. if (entity.IsSendGift == 1)
  9491. {
  9492. returnErrorMsg("请勿重复标记");
  9493. return;
  9494. }
  9495. entity.IsSendGift = 1;
  9496. entity.Update();
  9497. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9498. returnSuccessMsg("操作成功!");
  9499. return;
  9500. }
  9501. returnErrorMsg("找不到记录");
  9502. }
  9503. }
  9504. public void cancel_sendXlw()
  9505. {
  9506. if (UrlPostParmsCheck("ctid"))
  9507. {
  9508. string eid = GetPostString("ctid");
  9509. CeErpTradeCell entity = null;
  9510. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9511. if (entity != null)
  9512. {
  9513. if (entity.IsSendGift == 0)
  9514. {
  9515. returnErrorMsg("未标记小礼物");
  9516. return;
  9517. }
  9518. entity.IsSendGift = 0;
  9519. entity.Update();
  9520. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9521. returnSuccessMsg("操作成功!");
  9522. return;
  9523. }
  9524. returnErrorMsg("找不到记录");
  9525. }
  9526. }
  9527. public void get_erp_designbill()
  9528. {
  9529. DataStruct dStruct = GetPostStruct();
  9530. List<string> lw = new List<string>();
  9531. int isMy = GetInt("my");
  9532. if (isMy == 1)
  9533. {
  9534. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9535. }
  9536. string tid = GetPostString("tid");
  9537. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9538. string userName = GetPostString("design");
  9539. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9540. string price1 = GetPostString("price1");
  9541. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9542. string price2 = GetPostString("price2");
  9543. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9544. string rePrice1 = GetPostString("rePrice1");
  9545. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9546. string rePrice2 = GetPostString("rePrice2");
  9547. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9548. string designerType = GetPostString("designerType");
  9549. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9550. string orderState = GetPostString("orderState");
  9551. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9552. string endTime1 = GetPostString("endTime1");
  9553. string endTime2 = GetPostString("endTime2");
  9554. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9555. if (dw.Length > 0) lw.Add(dw);
  9556. string isDk = GetPostString("isDk");
  9557. if (isDk == "1")
  9558. {
  9559. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9560. }
  9561. else if (isDk == "0")
  9562. {
  9563. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9564. }
  9565. dStruct.Order = "oid, create_time desc";
  9566. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9567. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9568. writeGridDataTableJson(dStruct.TotalCount, dt);
  9569. }
  9570. public void upd_erp_designerbill()
  9571. {
  9572. if (UrlPostParmsCheck("ID"))
  9573. {
  9574. string eid = GetPostString("ID");
  9575. CeErpDesignerBill entity = null;
  9576. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9577. if (entity != null)
  9578. {
  9579. if (GetPostDouble("designerpirce") > 0)
  9580. {
  9581. entity.realPrice = GetPostDouble("designerpirce");
  9582. entity.update_time = DateTime.Now;
  9583. entity.update_u_id = CurrentUser.UserID;
  9584. entity.update_u_name = CurrentUser.UserName;
  9585. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9586. entity.Update();
  9587. returnSuccessMsg("操作成功!");
  9588. return;
  9589. }
  9590. else
  9591. {
  9592. entity.price = GetPostDouble("price");
  9593. entity.update_time = DateTime.Now;
  9594. entity.update_u_id = CurrentUser.UserID;
  9595. entity.update_u_name = CurrentUser.UserName;
  9596. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9597. entity.Update();
  9598. returnSuccessMsg("操作成功!");
  9599. return;
  9600. }
  9601. }
  9602. returnErrorMsg("找不到记录");
  9603. }
  9604. }
  9605. public void audit_erp_designerbill()
  9606. {
  9607. if (UrlPostParmsCheck("ID"))
  9608. {
  9609. string eid = GetPostString("ID");
  9610. CeErpDesignerBill entity = null;
  9611. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9612. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9613. if (entity != null)
  9614. {
  9615. entity.realPrice = GetPostDouble("designerpirce");
  9616. entity.update_time = DateTime.Now;
  9617. entity.update_u_id = CurrentUser.UserID;
  9618. entity.update_u_name = CurrentUser.UserName;
  9619. entity.isAudit = 1;
  9620. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9621. entity.Update();
  9622. if (orderEntity != null)
  9623. {
  9624. orderEntity.IsReadTag = 3;
  9625. orderEntity.Update();
  9626. }
  9627. returnSuccessMsg("操作成功!");
  9628. return;
  9629. }
  9630. returnErrorMsg("找不到记录");
  9631. }
  9632. }
  9633. public void all_audit_erp_designerbill()
  9634. {
  9635. if (UrlPostParmsCheck("idList"))
  9636. {
  9637. string[] list = GetPostString("idList").Split(',');
  9638. CeErpDesignerBill entity = null;
  9639. for (int i = 0; i < list.Length; i++)
  9640. {
  9641. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9642. if (entity == null) return;
  9643. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9644. if (orderEntity == null) return;
  9645. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9646. entity.update_time = DateTime.Now;
  9647. entity.update_u_id = CurrentUser.UserID;
  9648. entity.update_u_name = CurrentUser.UserName;
  9649. entity.isAudit = 1;
  9650. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9651. entity.Update();
  9652. orderEntity.IsReadTag = 3;
  9653. orderEntity.Update();
  9654. }
  9655. returnSuccessMsg("操作成功!");
  9656. return;
  9657. }
  9658. }
  9659. public void get_erp_sameorders()
  9660. {
  9661. if (UrlPostParmsCheck("ctid"))
  9662. {
  9663. string eid = GetPostString("ctid");
  9664. CeErpTradeCell entity = null;
  9665. entity = CeErpTradeCell.GetByCtid(eid);
  9666. if (entity != null)
  9667. {
  9668. StringBuilder sql = new StringBuilder();
  9669. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9670. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9671. var res = new
  9672. {
  9673. data = dt.Rows.Count
  9674. };
  9675. string ro_jsond = JsonConvert.SerializeObject(res);
  9676. returnSuccess(ro_jsond);
  9677. return;
  9678. }
  9679. returnErrorMsg("未找到订单");
  9680. return;
  9681. }
  9682. returnErrorMsg("缺少必要的参数");
  9683. }
  9684. public void get_erp_islasthavesameorder()
  9685. {
  9686. if (UrlPostParmsCheck("ctid"))
  9687. {
  9688. string eid = GetPostString("ctid");
  9689. string[] ctidList = eid.Split(',');
  9690. StringBuilder sql = new StringBuilder();
  9691. string tisCtid = "";
  9692. foreach (string ctid in ctidList)
  9693. {
  9694. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9695. if (entity != null)
  9696. {
  9697. sql = new StringBuilder();
  9698. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9699. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9700. if (dth.Rows.Count > 0)
  9701. {
  9702. tisCtid += entity.ctid;
  9703. tisCtid += ",";
  9704. }
  9705. }
  9706. }
  9707. if (tisCtid.Length > 0)
  9708. {
  9709. var res = new
  9710. {
  9711. data = tisCtid
  9712. };
  9713. string ro_jsond = JsonConvert.SerializeObject(res);
  9714. returnSuccess(ro_jsond);
  9715. }
  9716. else
  9717. {
  9718. var res = new
  9719. {
  9720. data = ""
  9721. };
  9722. string ro_jsond = JsonConvert.SerializeObject(res);
  9723. returnSuccess(ro_jsond);
  9724. }
  9725. return;
  9726. }
  9727. returnErrorMsg("缺少必要的参数");
  9728. }
  9729. public void file_client_down_url()
  9730. {
  9731. if (!UrlPostParmsCheck("userId"))
  9732. {
  9733. returnErrorMsg("缺少必要的参数");
  9734. }
  9735. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9736. }
  9737. public void checkout_form_data()
  9738. {
  9739. if (!UrlPostParmsCheck("tid"))
  9740. {
  9741. returnErrorMsg("缺少必要的参数");
  9742. }
  9743. string tid = GetPostString("tid");
  9744. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9745. if (ceErpOrderFormData != null)
  9746. {
  9747. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9748. returnSuccess(ro_jsond);
  9749. return;
  9750. }
  9751. returnErrorMsg("尚未有文件!");
  9752. }
  9753. public void back_supplier_audit()
  9754. {
  9755. int userId = CurrentUser.UserID;
  9756. StringBuilder sql = new StringBuilder();
  9757. 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);
  9758. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9759. if (dt.Rows.Count > 0)
  9760. {
  9761. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9762. }
  9763. else
  9764. {
  9765. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9766. }
  9767. }
  9768. public void back_supplier_query()
  9769. {
  9770. string eid = GetPostString("ctid");
  9771. if (eid != "")
  9772. {
  9773. StringBuilder sql = new StringBuilder();
  9774. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9775. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9776. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9777. }
  9778. else
  9779. {
  9780. returnErrorMsg("找不到订单记录");
  9781. return;
  9782. }
  9783. }
  9784. public void verified_to_order()
  9785. {
  9786. int userId = CurrentUser.UserID;
  9787. StringBuilder sql = new StringBuilder();
  9788. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9789. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9790. if (dt.Rows.Count > 0)
  9791. {
  9792. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9793. }
  9794. else
  9795. {
  9796. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9797. }
  9798. }
  9799. public void upd_supplier_audit()
  9800. {
  9801. if (UrlPostParmsCheck("ctid"))
  9802. {
  9803. string eid = GetPostString("ctid");
  9804. string reason = GetPostString("returnreason");
  9805. CeErpTradeCell entity = null;
  9806. CeWithdraw withdraw = null;
  9807. withdraw = CeWithdraw.GetByTid(eid);
  9808. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9809. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9810. {
  9811. if (withdraw != null)
  9812. {
  9813. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9814. {
  9815. returnSuccessMsg("您没有权限操作!");
  9816. return;
  9817. }
  9818. else
  9819. {
  9820. if (reason.Equals("1"))
  9821. {
  9822. if (entity.OrderState == -1)
  9823. {
  9824. if (entity.FinishPlaceTime == null)
  9825. {
  9826. entity.OrderState = 2;
  9827. }
  9828. else
  9829. {
  9830. entity.OrderState = 6;
  9831. }
  9832. }
  9833. entity.Update();
  9834. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9835. if (withdraw != null)
  9836. {
  9837. withdraw.status = int.Parse(reason);
  9838. withdraw.Update();
  9839. }
  9840. returnSuccessMsg("操作成功!");
  9841. return;
  9842. }
  9843. else
  9844. {
  9845. withdraw.status = int.Parse(reason);
  9846. withdraw.acknowledgingtime = DateTime.Now;
  9847. withdraw.Update();
  9848. returnSuccessMsg("查看详细请点击线下订单查询");
  9849. return;
  9850. }
  9851. }
  9852. }
  9853. // 第一个字符是 'N'
  9854. }
  9855. if (eid[0] != 'N')
  9856. {
  9857. }
  9858. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9859. {
  9860. entity.IsVerifyToSupplier = false;
  9861. entity.IsReturn = 1;
  9862. entity.ReturnTime = DateTime.Now;
  9863. entity.ReturnReason = reason;
  9864. if (entity.OrderState == 6)
  9865. {
  9866. entity.OrderState = 5;
  9867. }
  9868. entity.Update();
  9869. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9870. if (withdraw != null)
  9871. {
  9872. withdraw.status = int.Parse(reason);
  9873. withdraw.Update();
  9874. }
  9875. returnSuccessMsg("操作成功!");
  9876. return;
  9877. }
  9878. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9879. {
  9880. ;
  9881. if (withdraw != null)
  9882. {
  9883. withdraw.status = int.Parse(reason);
  9884. withdraw.acknowledgingtime = DateTime.Now;
  9885. withdraw.Update();
  9886. returnSuccessMsg("供应商取消撤回!");
  9887. return;
  9888. }
  9889. }
  9890. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9891. {
  9892. if (entity.OrderState == -1)
  9893. {
  9894. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9895. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9896. {
  9897. returnErrorMsg("订单spu没有确认无法通过审核!");
  9898. return;
  9899. }
  9900. if (entity.FinishPlaceTime == null)
  9901. {
  9902. entity.OrderState = 2;
  9903. }
  9904. else
  9905. {
  9906. entity.OrderState = 3;
  9907. }
  9908. commonHelper.getCytPrice(entity);
  9909. }
  9910. entity.Update();
  9911. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9912. if (withdraw != null)
  9913. {
  9914. withdraw.status = int.Parse(reason);
  9915. withdraw.Update();
  9916. }
  9917. returnSuccessMsg("操作成功!");
  9918. return;
  9919. }
  9920. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9921. {
  9922. if (withdraw == null)
  9923. {
  9924. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9925. return;
  9926. }
  9927. }
  9928. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9929. {
  9930. if (withdraw != null)
  9931. {
  9932. withdraw.status = int.Parse(reason);
  9933. withdraw.acknowledgingtime = DateTime.Now;
  9934. withdraw.Update();
  9935. returnSuccessMsg("查看详细请点击线下订单查询");
  9936. return;
  9937. }
  9938. }
  9939. return;
  9940. }
  9941. }
  9942. //校验报价
  9943. public void refund_order_tip()
  9944. {
  9945. int userid = CurrentUser.UserID;
  9946. int sectionId = CurrentUser.UserPost.OrgID;
  9947. StringBuilder sql = new StringBuilder();
  9948. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9949. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9950. List<string> ids = new List<string>();
  9951. if (dth.Rows.Count > 0)
  9952. {
  9953. foreach (DataRow dr in dth.Rows)
  9954. {
  9955. ids.Add(dr["ID"].ToString());
  9956. }
  9957. try
  9958. {
  9959. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9960. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9961. }
  9962. catch (Exception ex)
  9963. {
  9964. }
  9965. }
  9966. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9967. }
  9968. public void refund_order_Design()
  9969. {
  9970. int userid = CurrentUser.UserID;
  9971. int sectionId = CurrentUser.UserPost.OrgID;
  9972. StringBuilder sql = new StringBuilder();
  9973. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9974. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9975. List<string> ids = new List<string>();
  9976. if (dth.Rows.Count > 0)
  9977. {
  9978. foreach (DataRow dr in dth.Rows)
  9979. {
  9980. ids.Add(dr["ID"].ToString());
  9981. }
  9982. try
  9983. {
  9984. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9985. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9986. }
  9987. catch (Exception ex)
  9988. {
  9989. }
  9990. }
  9991. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9992. }
  9993. public void change_order_info()
  9994. {
  9995. int userid = CurrentUser.UserID;
  9996. StringBuilder sql = new StringBuilder();
  9997. 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);
  9998. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9999. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10000. }
  10001. public void change_win_mome()
  10002. {
  10003. if (UrlPostParmsCheck("id,ctid"))
  10004. {
  10005. string id = GetPostString("id");
  10006. string ctid = GetPostString("ctid");
  10007. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10008. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10009. if (ce == null || ceErpMessageTip == null)
  10010. {
  10011. returnSuccessMsg("未找到对应的订单!");
  10012. return;
  10013. }
  10014. if (ce.OrderState >= 5)
  10015. {
  10016. returnSuccessMsg("已上传文件无法修改!");
  10017. return;
  10018. }
  10019. int type = GetPostInt("type");
  10020. string content = GetPostString("content");
  10021. if (type == 0)
  10022. {
  10023. content = content.Replace("(", "(");
  10024. content = content.Replace(")", ")");
  10025. string check = MidStrEx(content, "(", ")").Trim();
  10026. if (string.IsNullOrEmpty(check))
  10027. {
  10028. returnSuccessMsg("文件名格式不正确");
  10029. return;
  10030. }
  10031. }
  10032. ce.seller_memo = content;
  10033. ce.Update();
  10034. ceErpMessageTip.isVisit = true;
  10035. ceErpMessageTip.Update();
  10036. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10037. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10038. ApiVo apiVo = new ApiVo();
  10039. apiVo.orderNumber = ce.ctid;
  10040. apiVo.actionName = "demandDesign";
  10041. apiVo.orderRemarks = content;
  10042. apiVo.demandExamine = type + 1;
  10043. designHelper.API_WorkCore(apiVo);//demandDesign
  10044. returnSuccessMsg("修改成功!");
  10045. }
  10046. }
  10047. public static string MidStrEx(string sourse, string startstr, string endstr)
  10048. {
  10049. string result = string.Empty;
  10050. int startindex, endindex;
  10051. try
  10052. {
  10053. startindex = sourse.IndexOf(startstr);
  10054. if (startindex == -1)
  10055. return result;
  10056. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10057. endindex = tmpstr.IndexOf(endstr);
  10058. if (endindex == -1)
  10059. return result;
  10060. result = tmpstr.Remove(endindex);
  10061. }
  10062. catch (Exception ex)
  10063. {
  10064. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10065. }
  10066. return result;
  10067. }
  10068. public void refund_order_list()
  10069. {
  10070. int userid = CurrentUser.UserID;
  10071. int sectionId = CurrentUser.UserPost.OrgID;
  10072. StringBuilder sql = new StringBuilder();
  10073. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10074. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10075. DataStruct dStruct = GetPostStruct();
  10076. DataTable dt = null;
  10077. List<string> ids = new List<string>();
  10078. List<string> tids = new List<string>();
  10079. if (dth.Rows.Count > 0)
  10080. {
  10081. foreach (DataRow dr in dth.Rows)
  10082. {
  10083. tids.Add("'" + dr["tid"].ToString() + "'");
  10084. ids.Add(dr["id"].ToString());
  10085. }
  10086. try
  10087. {
  10088. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10089. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10090. List<string> lw = new List<string>();
  10091. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10092. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10093. dt = WebCache.GetData("view_orderlist", dStruct);
  10094. }
  10095. catch (Exception ex)
  10096. {
  10097. }
  10098. }
  10099. writeGridDataTableJson(dStruct.TotalCount, dt);
  10100. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10101. }
  10102. //新增
  10103. public void order_batch_downloads()
  10104. {
  10105. string ceid = GetPostString("tid");
  10106. String[] tid = ceid.Split(',');
  10107. order_batch_caiyingtong(tid);
  10108. /* (string success, string errors) = UploadFiles(tid);
  10109. returnSuccessMsg(success + errors);*/
  10110. return;
  10111. }
  10112. //报价接口
  10113. public void Get_To_Quote()
  10114. {
  10115. string ceid = GetPostString("ctid");
  10116. if (ceid != null)
  10117. {
  10118. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10119. if (entity != null)
  10120. {
  10121. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10122. {
  10123. return;
  10124. }
  10125. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10126. double price = 0;
  10127. if (cp == null)
  10128. {
  10129. JObject jsonObject12 = new JObject
  10130. {
  10131. { "UserId", "77886" },
  10132. { "Pwd", "lt666888" },
  10133. { "Filename", entity.seller_memo }
  10134. };
  10135. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10136. JObject jsonObjects1 = JObject.Parse(response1);
  10137. string ms1g = (string)jsonObjects1["msg"];
  10138. if (ms1g == "报价成功")
  10139. {
  10140. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10141. string data = (string)jsonObject1["price"];
  10142. 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 + "');";
  10143. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10144. returnSuccessMsg("获取报价成功:" + data);
  10145. price = Convert.ToDouble(data);
  10146. }
  10147. else
  10148. {
  10149. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10150. return;
  10151. }
  10152. }
  10153. String[] beizhu = entity.seller_memo.Split('-');
  10154. String chanp = "";
  10155. if (beizhu.Length > 0)
  10156. {
  10157. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10158. }
  10159. else
  10160. {
  10161. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10162. }
  10163. JObject jsonObject = new JObject
  10164. {
  10165. { "UserId", "77886" },
  10166. { "Pwd", "lt666888" },
  10167. { "Filename", chanp }
  10168. };
  10169. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10170. JObject jsonObjects = JObject.Parse(response);
  10171. string msg = (string)jsonObjects["msg"];
  10172. if (msg == "报价成功")
  10173. {
  10174. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10175. string data = (string)jsonObject1["price"];
  10176. 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 + "');";
  10177. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10178. returnSuccessMsg("获取报价成功:" + data);
  10179. price = Convert.ToDouble(data);
  10180. }
  10181. else
  10182. {
  10183. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10184. return;
  10185. }
  10186. if (price > 0)
  10187. {
  10188. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10189. if (ceErpTradeCellExtend == null)
  10190. {
  10191. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10192. ceErpTradeCellExtend.ctid = entity.ctid;
  10193. ceErpTradeCellExtend.payment_cyt = price;
  10194. ceErpTradeCellExtend.Create();
  10195. }
  10196. else
  10197. {
  10198. ceErpTradeCellExtend.payment_cyt = price;
  10199. ceErpTradeCellExtend.Update();
  10200. }
  10201. }
  10202. return;
  10203. }
  10204. }
  10205. else
  10206. {
  10207. returnErrorMsg("请至少选择一条数据");
  10208. return;
  10209. }
  10210. }
  10211. //新增
  10212. public void order_To_Supplier()
  10213. {
  10214. string ceid = GetPostString("tid");
  10215. String[] tid = ceid.Split(',');
  10216. if (tid.Length > 0)
  10217. {
  10218. try
  10219. {
  10220. for (int i = 0; i < tid.Length; i++)
  10221. {
  10222. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10223. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10224. entity.SupplierId = suid;
  10225. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10226. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10227. entity.Update();
  10228. }
  10229. }
  10230. catch (Exception ex)
  10231. {
  10232. returnErrorMsg("自动匹配供应商失败");
  10233. return;
  10234. }
  10235. }
  10236. else
  10237. {
  10238. returnErrorMsg("请至少选择一条数据");
  10239. return;
  10240. }
  10241. returnSuccessMsg("自动匹配供应商成功");
  10242. return;
  10243. }
  10244. public (string, string) UploadFiles(string[] urls)
  10245. {
  10246. string success = "";
  10247. string errors = "";
  10248. int userid = CurrentUser.UserID;
  10249. foreach (string url in urls)
  10250. {
  10251. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10252. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10253. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10254. {
  10255. JObject jsonObject = new JObject
  10256. {
  10257. { "Userid", "77886" },
  10258. { "pwd", "cyt86435015" },
  10259. { "content", base64FileContent },
  10260. { "ext", Path.GetExtension(fileName) }
  10261. };
  10262. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10263. JObject jsonObjects = JObject.Parse(response);
  10264. string msg = (string)jsonObjects["msg"];
  10265. if (msg.Equals("上传成功"))
  10266. {
  10267. success += url + " 上传成功";
  10268. }
  10269. else
  10270. {
  10271. errors += url + " 上传失败";
  10272. }
  10273. }
  10274. else
  10275. {
  10276. errors += url + " 格式出现问题";
  10277. }
  10278. }
  10279. if (urls.Length == 0)
  10280. {
  10281. return (success, errors);
  10282. }
  10283. return (success, errors);
  10284. }
  10285. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10286. {
  10287. return true; //总是接受
  10288. }
  10289. public static string HttpPost(string url, string param = null)
  10290. {
  10291. HttpWebRequest request;
  10292. //如果是发送HTTPS请求
  10293. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10294. {
  10295. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10296. request = WebRequest.Create(url) as HttpWebRequest;
  10297. request.ProtocolVersion = HttpVersion.Version10;
  10298. }
  10299. else
  10300. {
  10301. request = WebRequest.Create(url) as HttpWebRequest;
  10302. }
  10303. request.Method = "POST";
  10304. request.ContentType = "application/json";
  10305. request.Accept = "*/*";
  10306. request.Timeout = 120000;
  10307. request.AllowAutoRedirect = false;
  10308. StreamWriter requestStream = null;
  10309. WebResponse response = null;
  10310. string responseStr = null;
  10311. try
  10312. {
  10313. requestStream = new StreamWriter(request.GetRequestStream());
  10314. requestStream.Write(param);
  10315. requestStream.Close();
  10316. response = request.GetResponse();
  10317. if (response != null)
  10318. {
  10319. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10320. responseStr = reader.ReadToEnd();
  10321. reader.Close();
  10322. }
  10323. }
  10324. catch (Exception ex)
  10325. {
  10326. return ex.Message;
  10327. }
  10328. finally
  10329. {
  10330. request = null;
  10331. requestStream = null;
  10332. response = null;
  10333. }
  10334. return responseStr;
  10335. }
  10336. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10337. {
  10338. string base64FileContent;
  10339. string fileName;
  10340. using (WebClient webClient = new WebClient())
  10341. {
  10342. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10343. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10344. {
  10345. using (Stream stream = response.GetResponseStream())
  10346. {
  10347. using (MemoryStream memoryStream = new MemoryStream())
  10348. {
  10349. stream.CopyTo(memoryStream);
  10350. byte[] fileBytes = memoryStream.ToArray();
  10351. base64FileContent = Convert.ToBase64String(fileBytes);
  10352. fileName = response.Headers["Content-Disposition"];
  10353. if (!string.IsNullOrEmpty(fileName))
  10354. {
  10355. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10356. if (index >= 0)
  10357. {
  10358. fileName = fileName.Substring(index + 9).Trim('\"');
  10359. }
  10360. }
  10361. else
  10362. {
  10363. fileName = Path.GetFileName(downloadUrl);
  10364. }
  10365. }
  10366. }
  10367. }
  10368. }
  10369. return (fileName, base64FileContent);
  10370. }
  10371. //新增
  10372. public void order_batch_caiyingtong(string[] downloadUrls)
  10373. {
  10374. try
  10375. {
  10376. //遍历文件
  10377. DataStruct dStruct = GetPostStruct();
  10378. DataTable dt = null;
  10379. int userid = CurrentUser.UserID;
  10380. List<string> ids = new List<string>();//失败组
  10381. List<string> tids = new List<string>();
  10382. using (WebClient webClient = new WebClient())
  10383. {
  10384. foreach (var url in downloadUrls)
  10385. {
  10386. try
  10387. {
  10388. tids.Add("'" + url + "'");
  10389. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10390. if (entity != null)
  10391. {
  10392. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10393. if (cp == null)
  10394. {
  10395. JObject jsonObject = new JObject
  10396. {
  10397. { "Userid", "77886" },
  10398. { "pwd", "lt666888" },
  10399. { "Filename",entity.seller_memo }
  10400. };
  10401. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10402. JObject jsonObjects = JObject.Parse(response);
  10403. string msg = (string)jsonObjects["msg"];
  10404. if (msg == "报价成功")
  10405. {
  10406. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10407. DownloadAndConvertToBase64(url1);
  10408. }
  10409. else
  10410. {
  10411. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10412. }
  10413. }
  10414. else
  10415. {
  10416. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10417. JObject jsonObject = new JObject
  10418. {
  10419. { "Userid", "77886" },
  10420. { "pwd", "lt666888" },
  10421. { "Filename",chanp }
  10422. };
  10423. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10424. JObject jsonObjects = JObject.Parse(response);
  10425. string msg = (string)jsonObjects["msg"];
  10426. if (msg == "报价成功")
  10427. {
  10428. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10429. DownloadAndConvertToBase64(url1);
  10430. }
  10431. else
  10432. {
  10433. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10434. }
  10435. }
  10436. }
  10437. // 上传文件到FTP
  10438. }
  10439. catch (Exception ex)
  10440. {
  10441. Console.WriteLine($"An error occurred: {ex.Message}");
  10442. }
  10443. }
  10444. List<string> lw = new List<string>();
  10445. lw.Add(string.Format("( OrderState < 6 )"));
  10446. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10447. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10448. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10449. if (dt.Rows.Count > 0)
  10450. {
  10451. foreach (DataRow dr in dt.Rows)
  10452. {
  10453. ids.Add(dr["ctid"].ToString());
  10454. }
  10455. }
  10456. String ErrorMsgs = "";
  10457. foreach (String id in ids)
  10458. {
  10459. ErrorMsgs += id + ",";
  10460. }
  10461. if (ErrorMsgs.Length > 1)
  10462. {
  10463. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10464. }
  10465. if (ErrorMsgs.Length < 1)
  10466. {
  10467. ErrorMsgs = "上传成功";
  10468. returnSuccessMsg(ErrorMsgs);
  10469. }
  10470. else
  10471. {
  10472. returnErrorMsg("以下订单" + ErrorMsgs);
  10473. }
  10474. }
  10475. // 删除文件夹及其内容
  10476. /* Directory.Delete(localDirectory, true);*/
  10477. }
  10478. catch { }
  10479. }
  10480. public void get_center_data()
  10481. {
  10482. int userId = CurrentUser.UserID;
  10483. string postCode = CurrentUser.UserPost.Post.Code;
  10484. List<string> lw = new List<string>();
  10485. List<string> ww = new List<string>();
  10486. DateTime currentTime = DateTime.Now;
  10487. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10488. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10489. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10490. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10491. string sql = " SELECT ";
  10492. string startTime = "2023-10-01 11:22:31";
  10493. //设计
  10494. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10495. {
  10496. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10497. 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));
  10498. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10499. 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));
  10500. }
  10501. //客服
  10502. else if (postCode == "CustomerService" || postCode == "Director")
  10503. {
  10504. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10505. 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));
  10506. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10507. 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));
  10508. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10509. 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));
  10510. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10511. 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));
  10512. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10513. 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));
  10514. }
  10515. //售后
  10516. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10517. {
  10518. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10519. 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));
  10520. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10521. 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));
  10522. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10523. 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));
  10524. }
  10525. //下单部
  10526. else if (postCode == "Place" || postCode == "PlaceMr")
  10527. {
  10528. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10529. 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));
  10530. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10531. 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));
  10532. }
  10533. //车间
  10534. else if (postCode == "Supplier")
  10535. {
  10536. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10537. 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));
  10538. }
  10539. DataTable dt = new DataTable();
  10540. if (lw.Count > 0)
  10541. {
  10542. sql += string.Join(" , ", lw);
  10543. sql += " FROM ";
  10544. sql += string.Join(" , ", ww);
  10545. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10546. }
  10547. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10548. }
  10549. public void get_center_data_list()
  10550. {
  10551. int userId = CurrentUser.UserID;
  10552. string postCode = CurrentUser.UserPost.Post.Code;
  10553. string shopIds = CurrentUser.User.pemShop;
  10554. DataStruct dStruct = GetPostStruct();
  10555. List<string> lw = new List<string>();
  10556. DateTime currentTime = DateTime.Now;
  10557. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10558. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10559. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10560. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10561. string startTime = "2023-10-01 11:22:31";
  10562. int order_type = GetPostInt("order_type");
  10563. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10564. {
  10565. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10566. if (order_type == 0)
  10567. {
  10568. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10569. }
  10570. else if (order_type == 3)
  10571. {
  10572. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10573. }
  10574. else
  10575. {
  10576. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10577. }
  10578. }
  10579. //客服
  10580. if (postCode == "CustomerService" || postCode == "Director")
  10581. {
  10582. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10583. if (order_type == 0)
  10584. {
  10585. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10586. }
  10587. else if (order_type == 1)
  10588. {
  10589. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10590. }
  10591. else if (order_type == 2)
  10592. {
  10593. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10594. }
  10595. else if (order_type == 3)
  10596. {
  10597. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10598. }
  10599. else if (order_type == 4)
  10600. {
  10601. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10602. }
  10603. else
  10604. {
  10605. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10606. }
  10607. }
  10608. //售后
  10609. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10610. {
  10611. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10612. if (shopIds != "")
  10613. {
  10614. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10615. }
  10616. if (order_type == 2)
  10617. {
  10618. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10619. }
  10620. else if (order_type == 4)
  10621. {
  10622. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10623. }
  10624. else if (order_type == 5)
  10625. {
  10626. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10627. }
  10628. else
  10629. {
  10630. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10631. }
  10632. }
  10633. //下单部
  10634. if (postCode == "Place" || postCode == "PlaceMr")
  10635. {
  10636. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10637. if (shopIds != "")
  10638. {
  10639. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10640. }
  10641. else if (order_type == 1)
  10642. {
  10643. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10644. }
  10645. else if (order_type == 2)
  10646. {
  10647. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10648. }
  10649. else
  10650. {
  10651. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10652. }
  10653. }
  10654. //车间
  10655. if (postCode == "Supplier")
  10656. {
  10657. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10658. if (order_type == 5)
  10659. {
  10660. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10661. }
  10662. else
  10663. {
  10664. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10665. }
  10666. }
  10667. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10668. dStruct.Fileds = "tid,ctid";
  10669. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10670. writeGridDataTableJson(dStruct.TotalCount, dt);
  10671. }
  10672. public void aftersale_audit_master()
  10673. {
  10674. if (UrlPostParmsCheck("ctid"))
  10675. {
  10676. string ctid = GetPostString("ctid");
  10677. if (ctid.Length > 0)
  10678. {
  10679. bool result = aftersale_data_change(ctid);
  10680. if (result)
  10681. {
  10682. returnSuccessMsg("修改成功!");
  10683. return;
  10684. }
  10685. }
  10686. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10687. }
  10688. }
  10689. public void aftersale_batch_audit_master()
  10690. {
  10691. if (UrlPostParmsCheck("ctids"))
  10692. {
  10693. string ctids = GetPostString("ctids");
  10694. if (ctids.Length > 0)
  10695. {
  10696. List<string> list = new List<string>();
  10697. string[] ctid_list = ctids.Split(',');
  10698. foreach (var item in ctid_list)
  10699. {
  10700. bool result = aftersale_data_change(item);
  10701. if (!result)
  10702. {
  10703. list.Add(item);
  10704. }
  10705. }
  10706. if (list.Count > 0)
  10707. {
  10708. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10709. return;
  10710. }
  10711. returnSuccessMsg("修改成功!");
  10712. return;
  10713. }
  10714. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10715. }
  10716. }
  10717. public bool aftersale_data_change(string ctid)
  10718. {
  10719. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10720. if (ceErpTradeCell != null)
  10721. {
  10722. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10723. ceErpTradeCell.AfterSaleSupplierState = 0;
  10724. StringBuilder sql = new StringBuilder();
  10725. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10726. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10727. CeErpTradeResponsible.DelByTid(ctid, 0);
  10728. 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 == "不理赔")
  10729. {
  10730. CeErpTradeResponsible.DelByTid(ctid, 1);
  10731. ceErpTradeCell.AfterSaleSupplierState = 1;
  10732. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10733. ceErpTradeCell.AfterSaleState = 4;
  10734. }
  10735. else
  10736. {
  10737. ceErpTradeCell.AfterSaleState = 3;
  10738. }
  10739. bool needCyt = false;
  10740. if (dt != null)
  10741. {
  10742. if (dt.Rows.Count == 1)
  10743. {
  10744. bool isEnd = false;
  10745. foreach (DataRow dr in dt.Rows)
  10746. {
  10747. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10748. {
  10749. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10750. isEnd = true;
  10751. }
  10752. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10753. {
  10754. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10755. isEnd = true;
  10756. }
  10757. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10758. {
  10759. needCyt = true;
  10760. }
  10761. }
  10762. if (isEnd)
  10763. {
  10764. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10765. ceErpTradeCell.AfterSaleState = 4;
  10766. ceErpTradeCell.AfterSaleSupplierState = 1;
  10767. }
  10768. }
  10769. else
  10770. {
  10771. bool isAll = true;
  10772. foreach (DataRow dr in dt.Rows)
  10773. {
  10774. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10775. {
  10776. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10777. continue;
  10778. }
  10779. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10780. {
  10781. string path = "";
  10782. int OrgID = 0;
  10783. if (!Convert.IsDBNull(dr["OrgPath"]))
  10784. {
  10785. path = dr["OrgPath"].ToString();
  10786. }
  10787. if (!Convert.IsDBNull(dr["OrgID"]))
  10788. {
  10789. OrgID = Convert.ToInt32(dr["OrgID"]);
  10790. }
  10791. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10792. {
  10793. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10794. continue;
  10795. }
  10796. }
  10797. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10798. {
  10799. needCyt = true;
  10800. }
  10801. isAll = false;
  10802. }
  10803. if (isAll)
  10804. {
  10805. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10806. ceErpTradeCell.AfterSaleState = 4;
  10807. ceErpTradeCell.AfterSaleSupplierState = 1;
  10808. }
  10809. }
  10810. }
  10811. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10812. {
  10813. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10814. }
  10815. if (ceErpTradeCell.AfterSaleState == 4)
  10816. {
  10817. ApiVo apiVo = new ApiVo();
  10818. apiVo.orderNumber = ceErpTradeCell.ctid;
  10819. apiVo.actionName = "afterOver";
  10820. designHelper.API_WorkCore(apiVo); //afterOver
  10821. }
  10822. ceErpTradeCell.Update();
  10823. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10824. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10825. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10826. return true;
  10827. }
  10828. return false;
  10829. }
  10830. public void get_erp_wechatorder()
  10831. {
  10832. DataStruct dStruct = GetPostStruct();
  10833. List<string> lw = new List<string>();
  10834. string tid = GetPostString("tid");
  10835. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10836. string shopname = GetPostString("shopname");
  10837. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10838. string buyernick = GetPostString("buyer_nick");
  10839. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10840. string customer = GetPostString("customer");
  10841. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10842. string returndate1 = GetPostString("returndate1");
  10843. string returndate2 = GetPostString("returndate2");
  10844. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10845. if (dw.Length > 0) lw.Add(dw);
  10846. string finishDate1 = GetPostString("finishdate1");
  10847. string finishDate2 = GetPostString("finishdate2");
  10848. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10849. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10850. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10851. dStruct.Order = "created desc";
  10852. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10853. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10854. writeGridDataTableJson(dStruct.TotalCount, dt);
  10855. }
  10856. public void get_erp_wechatlist_sumprice()
  10857. {
  10858. DataStruct dStruct = GetPostStruct();
  10859. List<string> lw = new List<string>();
  10860. string tid = GetPostString("tid");
  10861. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10862. string shopname = GetPostString("shopname");
  10863. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10864. string buyernick = GetPostString("buyer_nick");
  10865. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10866. string customer = GetPostString("customer");
  10867. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10868. string returndate1 = GetPostString("returndate1");
  10869. string returndate2 = GetPostString("returndate2");
  10870. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10871. if (dw.Length > 0) lw.Add(dw);
  10872. string finishDate1 = GetPostString("finishdate1");
  10873. string finishDate2 = GetPostString("finishdate2");
  10874. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10875. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10876. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10877. string mainWhere = string.Join(" and ", lw.ToArray());
  10878. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10879. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10880. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10881. decimal total = 0;
  10882. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10883. {
  10884. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10885. }
  10886. var res = new
  10887. {
  10888. data = total
  10889. };
  10890. string ro_jsond = JsonConvert.SerializeObject(res);
  10891. returnSuccess(ro_jsond);
  10892. return;
  10893. }
  10894. public void get_erp_qr_waitdeliverylist()
  10895. {
  10896. DataStruct dStruct = GetPostStruct();
  10897. List<string> lw = new List<string>();
  10898. string tid = GetPostString("ctid");
  10899. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10900. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10901. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10902. var res_objz = new
  10903. {
  10904. restype = 1,
  10905. data = dt
  10906. };
  10907. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10908. returnSuccess(ro_jsonz);
  10909. }
  10910. public void get_erp_yield_list()
  10911. {
  10912. DataStruct dStruct = GetPostStruct();
  10913. List<string> lw = new List<string>();
  10914. string tid = GetPostString("ctid");
  10915. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10916. string shopname = GetPostString("shopname");
  10917. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10918. string buyernick = GetPostString("buyer_nick");
  10919. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10920. //if (tid.Length == 0 && buyernick.Length == 0)
  10921. //{
  10922. // lw.Add(string.Format("IsRefund<={0}", 1));
  10923. //}
  10924. string customer = GetPostString("customer");
  10925. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10926. string design = GetPostString("design");
  10927. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10928. string orderState = GetPostString("orderState");
  10929. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10930. string address = GetPostString("address");
  10931. 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));
  10932. string sellermemo = GetPostString("seller_memo");
  10933. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10934. string supplier = GetPostString("supplier");
  10935. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10936. string OrderArea = GetPostString("order_area");
  10937. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10938. string placedate1 = GetPostString("placedate1");
  10939. string placedate2 = GetPostString("placedate2");
  10940. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10941. if (fdw.Length > 0) lw.Add(fdw);
  10942. string price1 = GetPostString("price1");
  10943. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10944. string price2 = GetPostString("price2");
  10945. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10946. string unusualCon = GetPostString("unusualcon");
  10947. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10948. string posTag = CurrentUser.UserPost.Post.Code;
  10949. if (posTag == "Supplier")
  10950. {
  10951. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10952. }
  10953. lw.Add(string.Format("OrderState = 6 "));
  10954. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10955. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10956. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10957. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10958. writeGridDataTableJson(dStruct.TotalCount, dt);
  10959. }
  10960. public void change_erp_sup_state()
  10961. {
  10962. if (UrlPostParmsCheck("ctid"))
  10963. {
  10964. string ctid = GetPostString("ctid");
  10965. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10966. if (ceErpTradeCell != null)
  10967. {
  10968. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10969. if (ceErpTradeCellExtend == null)
  10970. {
  10971. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10972. ceErpTradeCellExtend.ctid = ctid;
  10973. ceErpTradeCellExtend.SupState = 1;
  10974. ceErpTradeCellExtend.Create();
  10975. }
  10976. else
  10977. {
  10978. ceErpTradeCellExtend.SupState = 1;
  10979. ceErpTradeCellExtend.Update();
  10980. }
  10981. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10982. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10983. return;
  10984. }
  10985. returnErrorMsg("找不到订单");
  10986. }
  10987. }
  10988. public void supplier_all_downs()
  10989. {
  10990. if (UrlPostParmsCheck("tids"))
  10991. {
  10992. string tids = GetPostString("tids");
  10993. if (tids != null && tids.Length > 0)
  10994. {
  10995. StringBuilder sql = new StringBuilder();
  10996. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10997. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10998. sql = new StringBuilder();
  10999. 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, "下载设计文件");
  11000. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11001. string[] list = tids.Split(',');
  11002. foreach (string ctid in list)
  11003. {
  11004. CeErpSukuraData.createInfo(ctid, 3);
  11005. }
  11006. designHelper.api_approveDesign(tids); //approveDesign
  11007. returnSuccessMsg("下载成功!");
  11008. return;
  11009. }
  11010. returnErrorMsg("下载订单更新失败");
  11011. }
  11012. }
  11013. public void uploaderFileSuccess()
  11014. {
  11015. if (UrlPostParmsCheck("fileName"))
  11016. {
  11017. string fileName = GetPostString("fileName");
  11018. ApiVo apiVo = new ApiVo();
  11019. apiVo.orderNumber = fileName;
  11020. apiVo.actionName = "finishDesign";
  11021. designHelper.API_WorkCore(apiVo);//finishDesign
  11022. returnSuccessMsg("");
  11023. }
  11024. }
  11025. public void get_sample2_order()
  11026. {
  11027. if (UrlPostParmsCheck("ctid"))
  11028. {
  11029. string ctid = GetPostString("ctid");
  11030. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11031. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11032. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11033. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11034. double total = 0.0;
  11035. double order_price = 0.0;
  11036. if (dt_bu.Rows.Count > 0)
  11037. {
  11038. foreach (DataRow dr in dt_bu.Rows)
  11039. {
  11040. total += Convert.ToDouble(dr["payment"]);
  11041. }
  11042. }
  11043. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11044. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11045. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11046. string tid = ctid.Replace("S_", "");
  11047. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11048. double paymant = 0.0;
  11049. if (entity != null)
  11050. {
  11051. paymant = entity.payment;
  11052. }
  11053. string return_reason = "";
  11054. if (dt_after != null && dt_after.Rows.Count > 0)
  11055. {
  11056. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11057. }
  11058. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11059. }
  11060. }
  11061. public void get_erp_design_status()
  11062. {
  11063. string designName = GetPostString("designName");
  11064. DataStruct dStruct = GetPostStruct();
  11065. if (designName.Length > 0)
  11066. {
  11067. 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";
  11068. sql_user += " and Name like '%" + designName + "%'";
  11069. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11070. List<string> ids_list = new List<string>();
  11071. if (user_table.Rows.Count > 0)
  11072. {
  11073. foreach (DataRow item in user_table.Rows)
  11074. {
  11075. ids_list.Add(item["id"].ToString());
  11076. string ids_s = item["TeamIds"].ToString();
  11077. if (ids_s.Length > 0)
  11078. {
  11079. ids_list.AddRange(ids_s.Split(','));
  11080. }
  11081. }
  11082. }
  11083. HashSet<string> set = new HashSet<string>(ids_list);
  11084. ids_list = set.ToList();
  11085. if (ids_list.Count > 0)
  11086. {
  11087. 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));
  11088. dStruct.MainWhere = sql;
  11089. DataTable dt = null;
  11090. dt = WebCache.GetData("view_ErpUser", dStruct);
  11091. writeGridDataTableJson(dStruct.TotalCount, dt);
  11092. }
  11093. }
  11094. }
  11095. public void change_erp_order_price()
  11096. {
  11097. string ctid = GetPostString("ctid");
  11098. double price = GetPostDouble("price");
  11099. if (ctid.Length > 0)
  11100. {
  11101. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11102. if (ceErpTradeCellExtend == null)
  11103. {
  11104. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11105. ceErpTradeCellExtend.ctid = ctid;
  11106. ceErpTradeCellExtend.payment_cyt = price;
  11107. ceErpTradeCellExtend.Create();
  11108. }
  11109. else
  11110. {
  11111. ceErpTradeCellExtend.payment_cyt = price;
  11112. ceErpTradeCellExtend.Update();
  11113. }
  11114. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11115. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11116. {
  11117. ceErpDataSendOrderInfo.isSync = false;
  11118. ceErpDataSendOrderInfo.Update();
  11119. }
  11120. if (ceErpDataSendOrderInfo == null)
  11121. {
  11122. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11123. ceErpDataSendOrderInfo.isSync = false;
  11124. ceErpDataSendOrderInfo.ctid = ctid;
  11125. ceErpDataSendOrderInfo.Create();
  11126. }
  11127. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11128. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11129. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11130. if (dth != null && dth.Rows.Count > 0)
  11131. {
  11132. dataSendOrderBean dataSendOrderBean = null;
  11133. foreach (DataRow item in dth.Rows)
  11134. {
  11135. try
  11136. {
  11137. dataSendOrderBean = new dataSendOrderBean();
  11138. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11139. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11140. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11141. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11142. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11143. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11144. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11145. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11146. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11147. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11148. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11149. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11150. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11151. if (result != null)
  11152. {
  11153. if ("0".Equals(result.errcode))
  11154. {
  11155. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11156. }
  11157. else
  11158. {
  11159. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11160. }
  11161. }
  11162. }
  11163. catch (Exception ex)
  11164. {
  11165. }
  11166. }
  11167. }
  11168. returnSuccessMsg("修改成功!");
  11169. return;
  11170. }
  11171. returnErrorMsg("找不到订单");
  11172. }
  11173. public void find_he_together()
  11174. {
  11175. string ctid = GetPostString("ctid");
  11176. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11177. List<string> list = new List<string>();
  11178. if (ceErpTradeCell != null)
  11179. {
  11180. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11181. {
  11182. 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);
  11183. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11184. if (table != null && table.Rows.Count > 0)
  11185. {
  11186. foreach (TableRow row in table.Rows)
  11187. {
  11188. }
  11189. }
  11190. }
  11191. }
  11192. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11193. }
  11194. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11195. {
  11196. //chy----19
  11197. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11198. //GD-CYT-----64
  11199. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11200. //ZHX----3
  11201. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11202. //JK----97
  11203. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11204. //ZT----70
  11205. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11206. //LHCY-----98
  11207. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11208. //XD-----90
  11209. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11210. //CYCY-----14
  11211. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11212. };
  11213. //其他改名
  11214. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11215. {
  11216. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11217. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11218. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11219. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11220. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11221. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11222. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11223. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11224. };
  11225. //不统计
  11226. List<int> no_suppliers = new List<int>()
  11227. {
  11228. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11229. };
  11230. //配件单
  11231. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11232. {
  11233. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11234. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11235. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11236. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11237. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11238. {"旗杆",new List<string>(){ "班旗" } },
  11239. {"牙签",new List<string>(){ "不干胶" } }
  11240. };
  11241. public void get_place_order_data()
  11242. {
  11243. string date1 = GetPostString("date1");
  11244. string date2 = GetPostString("date2");
  11245. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11246. DateTime start = DateTime.Parse(starttime);
  11247. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11248. DateTime end = DateTime.Parse(endtime);
  11249. if (date1 != null && date1.Length > 0)
  11250. {
  11251. DateTime dateTime = DateTime.Parse(date1);
  11252. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11253. start = DateTime.Parse(starttime);
  11254. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11255. end = DateTime.Parse(endtime);
  11256. }
  11257. if (date2 != null && date2.Length > 0)
  11258. {
  11259. DateTime dateTime = DateTime.Parse(date2);
  11260. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11261. end = DateTime.Parse(endtime);
  11262. }
  11263. 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);
  11264. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11265. //不干胶-----1,卡片-----29
  11266. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11267. foreach (DataRow row in data.Rows)
  11268. {
  11269. int productId = Convert.ToInt32(row["ProductId"]);
  11270. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11271. if (no_suppliers.Contains(supplierId))
  11272. {
  11273. continue;
  11274. }
  11275. string seller_memo = row["seller_memo"].ToString();
  11276. bool ispj = false;//是否配件单
  11277. bool isfirst = true;//第一个配
  11278. maps.Keys.ForEach(key =>
  11279. {
  11280. //备注包含配件
  11281. if (seller_memo.Contains(key) && isfirst)
  11282. {
  11283. List<string> list = maps[key];
  11284. ispj = true;
  11285. isfirst = false;
  11286. for (int i = 0; i < list.Count; i++)
  11287. {
  11288. if (seller_memo.Contains(list[i]))
  11289. {
  11290. ispj = false;
  11291. break;
  11292. }
  11293. }
  11294. }
  11295. });
  11296. if (ispj)
  11297. {
  11298. continue;
  11299. }
  11300. seller_memo = seller_memo.Replace("UV", "uv");
  11301. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11302. //吊牌归到卡片
  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. seller_memo = seller_memo.Replace("腰封", "卡片");
  11308. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11309. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11310. seller_memo = seller_memo.Replace("横幅", "条幅");
  11311. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11312. string map_key = "";
  11313. string type = "";
  11314. if (supplierMap.ContainsKey(supplierId))
  11315. {
  11316. foreach (var kvp in supplierMap[supplierId])
  11317. {
  11318. if (seller_memo.Contains(kvp.Key))
  11319. {
  11320. map_key = kvp.Value;
  11321. type = kvp.Value;
  11322. break;
  11323. }
  11324. }
  11325. }
  11326. if (map_key == "")
  11327. {
  11328. type = "其他";
  11329. map_key = "其他";
  11330. }
  11331. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11332. {
  11333. map_key = suppliers[supplierId];
  11334. }
  11335. if (supplierId == 70)
  11336. {
  11337. supplierId = 70;
  11338. }
  11339. map_key += "_" + row["SupplierName"].ToString();
  11340. Dictionary<string, int> map = null;
  11341. if (other_map.ContainsKey(map_key))
  11342. {
  11343. other_map.TryGetValue(map_key, out map);
  11344. }
  11345. else
  11346. {
  11347. map = new Dictionary<string, int>();
  11348. map.Add("dayDev", 0);//当天出货
  11349. map.Add("dayTotal", 0);//下单总数
  11350. map.Add("payTotal", 0);//500以上
  11351. map.Add("today", 0);//当天出货数量
  11352. map.Add("unusua", 0);//异常数
  11353. other_map.Add(map_key, map);
  11354. other_map.TryGetValue(map_key, out map);
  11355. }
  11356. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11357. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11358. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11359. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11360. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11361. {
  11362. map["dayTotal"]++;
  11363. if (supplierId == 97)
  11364. {
  11365. supplierId = 97;
  11366. }
  11367. }
  11368. if (Convert.ToDecimal(row["payment"]) >= 500)
  11369. {
  11370. map["payTotal"]++;
  11371. }
  11372. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11373. {
  11374. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11375. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11376. {
  11377. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11378. {
  11379. map["today"]++;
  11380. }
  11381. }
  11382. else
  11383. {
  11384. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11385. {
  11386. map["today"]++;
  11387. }
  11388. else
  11389. {
  11390. if (supplierId == 119)
  11391. {
  11392. Debug.WriteLine(row["seller_memo"].ToString());
  11393. }
  11394. }
  11395. }
  11396. }
  11397. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11398. {
  11399. map["unusua"]++;
  11400. }
  11401. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11402. //GD-CYT-----64
  11403. DateTime two = palceTimeStart.AddHours(14);
  11404. DateTime three = palceTimeStart.AddHours(15);
  11405. DateTime four = palceTimeStart.AddHours(16);
  11406. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11407. {
  11408. //下午四点前 500-1000
  11409. string count = row["ProductCount"].ToString();
  11410. if (count != null && count.Length > 0)
  11411. {
  11412. int productCount = commonHelper.getPlaceProductCount(count);
  11413. if (productCount >= 500 && productCount <= 1000)
  11414. {
  11415. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11416. {
  11417. map["dayDev"]++;
  11418. }
  11419. }
  11420. }
  11421. }
  11422. //UV
  11423. else if ("uv".Equals(type))
  11424. {
  11425. //ZT----70
  11426. //ZHX----3
  11427. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11428. {
  11429. map["dayDev"]++;
  11430. }
  11431. //JK----97
  11432. //HZX----105
  11433. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11434. {
  11435. map["dayDev"]++;
  11436. if (supplierId == 97)
  11437. {
  11438. supplierId = 97;
  11439. }
  11440. }
  11441. }
  11442. //帆布---52|条幅---27
  11443. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11444. {
  11445. //LHCY-----98
  11446. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11447. {
  11448. map["dayDev"]++;
  11449. }
  11450. }
  11451. //条幅
  11452. else if ("条幅".Equals(type))
  11453. {
  11454. //XD-----90
  11455. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11456. {
  11457. map["dayDev"]++;
  11458. }
  11459. }
  11460. //桌布
  11461. else if ("桌布".Equals(type))
  11462. {
  11463. //XD-----90
  11464. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11465. {
  11466. map["dayDev"]++;
  11467. }
  11468. }
  11469. //DL---10
  11470. //AYTW---119
  11471. //FS-CYT-DY ----80
  11472. //JK----97
  11473. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11474. {
  11475. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11476. {
  11477. map["dayDev"]++;
  11478. }
  11479. }
  11480. }
  11481. DataTable dt = new DataTable();
  11482. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11483. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11484. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11485. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11486. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11487. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11488. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11489. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11490. other_map.Keys.ForEach(key =>
  11491. {
  11492. DataRow dr = dt.NewRow();
  11493. Dictionary<string, int> map = other_map[key];
  11494. string[] key_list = key.Split('_');
  11495. dr[0] = key_list[0];
  11496. dr[1] = key_list[1];
  11497. if (key_list.Length > 2)
  11498. {
  11499. dr[1] += "(" + key_list[2] + ")";
  11500. }
  11501. dr[2] = map["dayTotal"];
  11502. dr[3] = map["payTotal"];
  11503. dr[4] = map["today"];
  11504. dr[5] = map["unusua"];
  11505. dr[6] = map["dayDev"];
  11506. double rate = 0.00;
  11507. if (map["dayDev"] > 0)
  11508. {
  11509. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11510. }
  11511. dr[7] = rate.ToString();
  11512. dt.Rows.Add(dr);
  11513. });
  11514. DataView dv = new DataView(dt);
  11515. dv.Sort = "SupplierName";
  11516. //dv.Sort = "AllOrder desc";
  11517. DataTable dtNew = dv.ToTable();
  11518. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11519. }
  11520. public void check_order_desing_info()
  11521. {
  11522. string ctid = GetPostString("ctid");
  11523. if (!string.IsNullOrEmpty(ctid))
  11524. {
  11525. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11526. if (ceErpTradeCell != null)
  11527. {
  11528. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11529. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11530. return;
  11531. }
  11532. returnErrorMsg("找不到订单");
  11533. return;
  11534. }
  11535. returnErrorMsg("找不到订单");
  11536. }
  11537. public void get_timeout_detail()
  11538. {
  11539. string poscode = CurrentUser.UserPost.Post.Code;
  11540. DataStruct dStruct = GetPostStruct();
  11541. List<string> lw = new List<string>();
  11542. string id = GetPostString("id");
  11543. string pay_date1 = GetPostString("pay_date1");
  11544. string pay_date2 = GetPostString("pay_date2");
  11545. int type = GetPostInt("type");
  11546. if (type == 0)
  11547. {
  11548. if (pay_date1.Length > 0)
  11549. {
  11550. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11551. }
  11552. if (pay_date2.Length > 0)
  11553. {
  11554. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11555. }
  11556. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11557. }
  11558. if (type == 1)
  11559. {
  11560. if (pay_date1.Length > 0)
  11561. {
  11562. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11563. }
  11564. if (pay_date2.Length > 0)
  11565. {
  11566. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11567. }
  11568. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11569. }
  11570. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11571. DataTable dt = null;
  11572. dt = WebCache.GetData("view_orderlist", dStruct);
  11573. writeGridDataTableJson(dStruct.TotalCount, dt);
  11574. }
  11575. public void saveUrgentChargePrice()
  11576. {
  11577. string ctid = GetPostString("ctid");
  11578. if (!string.IsNullOrEmpty(ctid))
  11579. {
  11580. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11581. if (ceErpTradeCell != null)
  11582. {
  11583. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11584. if (prices <= 100)
  11585. {
  11586. returnErrorMsg("此订单金额不足100元,无法加急。");
  11587. return;
  11588. }
  11589. double price = GetPostDouble("price");
  11590. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11591. if (ceErpTradeCellExtend == null)
  11592. {
  11593. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11594. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11595. }
  11596. ceErpTradeCellExtend.urgentCharge = price;
  11597. if (ceErpTradeCellExtend.ID > 0)
  11598. {
  11599. ceErpTradeCellExtend.Update();
  11600. }
  11601. else
  11602. {
  11603. ceErpTradeCellExtend.Save();
  11604. }
  11605. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11606. returnSuccessMsg("修改成功!");
  11607. return;
  11608. }
  11609. returnErrorMsg("找不到订单");
  11610. return;
  11611. }
  11612. returnErrorMsg("找不到订单");
  11613. }
  11614. public void finish_erp_order()
  11615. {
  11616. string ctid = GetPostString("ctid");
  11617. if (!string.IsNullOrEmpty(ctid))
  11618. {
  11619. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11620. {
  11621. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11622. if (ceErpTradeCell != null)
  11623. {
  11624. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11625. ceErpTradeCell.Update();
  11626. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11627. returnSuccessMsg("修改成功!");
  11628. return;
  11629. }
  11630. }
  11631. }
  11632. returnErrorMsg("找不到订单");
  11633. }
  11634. public void get_trade_order_list()
  11635. {
  11636. string tid = GetPostString("tid");
  11637. if (!string.IsNullOrEmpty(tid))
  11638. {
  11639. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11640. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11641. writeGridDataTableJson(data.Rows.Count, data);
  11642. return;
  11643. }
  11644. returnErrorMsg("找不到订单");
  11645. }
  11646. public void save_cell_spu()
  11647. {
  11648. string ctid = GetPostString("ctid");
  11649. string spu_id = GetPostString("spu_id");
  11650. if (!string.IsNullOrEmpty(ctid))
  11651. {
  11652. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11653. if (ceErpTradeCellExtend == null)
  11654. {
  11655. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11656. ceErpTradeCellExtend.ctid = ctid;
  11657. }
  11658. ceErpTradeCellExtend.spu_id = spu_id;
  11659. if (!string.IsNullOrEmpty(spu_id))
  11660. {
  11661. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11662. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  11663. ceErpTradeCellExtend.ToType = result;
  11664. 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 };
  11665. List<int> shopIds = new List<int>() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 18, 24, 27, 28, 31, 32, 56, 61 };
  11666. if (products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  11667. {
  11668. ceErpTradeCellExtend.ToType = "外协";
  11669. }
  11670. if ((ceErpTradeCell.seller_memo.Contains("改稿") || ceErpTradeCell.OtherMemo.Contains("改稿")) && shopIds.Contains(ceErpTradeCell.ShopId))
  11671. {
  11672. ceErpTradeCellExtend.ToType = "内部";
  11673. }
  11674. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  11675. {
  11676. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  11677. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  11678. }
  11679. }
  11680. if (ceErpTradeCellExtend.ID == 0)
  11681. {
  11682. ceErpTradeCellExtend.Create();
  11683. }
  11684. else
  11685. {
  11686. ceErpTradeCellExtend.Update();
  11687. }
  11688. returnSuccessMsg("修改成功!");
  11689. return;
  11690. }
  11691. returnErrorMsg("找不到订单");
  11692. }
  11693. public void change_express_info()
  11694. {
  11695. string ctid = GetPostString("ctid");
  11696. string transNo = GetPostString("transNo");
  11697. string transCom = GetPostString("transCom");
  11698. if (!string.IsNullOrEmpty(ctid))
  11699. {
  11700. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11701. if (ceErpTradeCellExtend == null)
  11702. {
  11703. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11704. ceErpTradeCellExtend.ctid = ctid;
  11705. }
  11706. ceErpTradeCellExtend.modExpressNo = transNo;
  11707. ceErpTradeCellExtend.modExpressCom = transCom;
  11708. ceErpTradeCellExtend.readMod = 2;
  11709. if (ceErpTradeCellExtend.ID == 0)
  11710. {
  11711. ceErpTradeCellExtend.Create();
  11712. }
  11713. else
  11714. {
  11715. ceErpTradeCellExtend.Update();
  11716. }
  11717. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11718. returnSuccessMsg("修改成功!");
  11719. return;
  11720. }
  11721. returnErrorMsg("找不到订单");
  11722. }
  11723. public void get_change_express_list()
  11724. {
  11725. DataStruct dStruct = GetPostStruct();
  11726. List<string> lw = new List<string>();
  11727. int st = 2;
  11728. string tid = GetPostString("ctid");
  11729. if (tid.Length > 0)
  11730. {
  11731. string select_tid = getTidByCtid(tid);
  11732. lw.Add(string.Format("tid='{0}'", select_tid));
  11733. }
  11734. string shopname = GetPostString("shopname");
  11735. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11736. string buyernick = GetPostString("buyer_nick");
  11737. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11738. string sellermemo = GetPostString("seller_memo");
  11739. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11740. string supplier = GetPostString("supplier");
  11741. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11742. string customer = GetPostString("customer");
  11743. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11744. string design = GetPostString("design");
  11745. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11746. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11747. string poscode = CurrentUser.UserPost.Post.Code;
  11748. if (poscode != "SysAdmin")
  11749. {
  11750. string shopid = CurrentUser.User.pemShop;
  11751. lw.Add(string.Format("shopId in ({0})", shopid));
  11752. }
  11753. lw.Add("readMod = 2");
  11754. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11755. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11756. writeGridDataTableJson(dStruct.TotalCount, dt);
  11757. }
  11758. public void deal_express_complete()
  11759. {
  11760. string ctid = GetPostString("ctid");
  11761. if (!string.IsNullOrEmpty(ctid))
  11762. {
  11763. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11764. if (ceErpTradeCellExtend == null)
  11765. {
  11766. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11767. ceErpTradeCellExtend.ctid = ctid;
  11768. }
  11769. ceErpTradeCellExtend.readMod = 1;
  11770. if (ceErpTradeCellExtend.ID == 0)
  11771. {
  11772. ceErpTradeCellExtend.Create();
  11773. }
  11774. else
  11775. {
  11776. ceErpTradeCellExtend.Update();
  11777. }
  11778. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11779. returnSuccessMsg("修改成功!");
  11780. return;
  11781. }
  11782. returnErrorMsg("找不到订单");
  11783. }
  11784. public void aftersale_return_visit()
  11785. {
  11786. string ctid = GetPostString("ctid");
  11787. if (!string.IsNullOrEmpty(ctid))
  11788. {
  11789. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11790. if (ceErpTradeCellExtend == null)
  11791. {
  11792. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11793. ceErpTradeCellExtend.ctid = ctid;
  11794. }
  11795. ceErpTradeCellExtend.returnVisit = 1;
  11796. if (ceErpTradeCellExtend.ID == 0)
  11797. {
  11798. ceErpTradeCellExtend.Create();
  11799. }
  11800. else
  11801. {
  11802. ceErpTradeCellExtend.Update();
  11803. }
  11804. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11805. if (ceErpTradeAfterSaleExtend != null)
  11806. {
  11807. ceErpTradeAfterSaleExtend.TextResult = "";
  11808. ceErpTradeAfterSaleExtend.Update();
  11809. }
  11810. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11811. returnSuccessMsg("修改成功!");
  11812. return;
  11813. }
  11814. returnErrorMsg("找不到订单");
  11815. }
  11816. public void orderPlaceInfo()
  11817. {
  11818. string ctids = GetPostString("ctids");
  11819. string[] list = ctids.Split(',');
  11820. foreach (string ctid in list)
  11821. {
  11822. CeErpSukuraData.createInfo(ctid, 3);
  11823. }
  11824. StringBuilder sql = new StringBuilder();
  11825. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11826. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11827. designHelper.api_approveDesign(ctids); //approveDesign
  11828. returnSuccessMsg("");
  11829. }
  11830. public void get_issue_list()
  11831. {
  11832. DataStruct dStruct = GetPostStruct();
  11833. List<string> lw = new List<string>();
  11834. int st = 2;
  11835. string tid = GetPostString("ctid");
  11836. if (tid.Length > 0)
  11837. {
  11838. string select_tid = getTidByCtid(tid);
  11839. lw.Add(string.Format("tid='{0}'", select_tid));
  11840. }
  11841. string shopname = GetPostString("shopname");
  11842. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11843. string buyernick = GetPostString("buyer_nick");
  11844. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11845. string sellermemo = GetPostString("seller_memo");
  11846. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11847. string supplier = GetPostString("supplier");
  11848. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11849. string customer = GetPostString("customer");
  11850. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11851. string design = GetPostString("design");
  11852. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11853. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11854. string poscode = CurrentUser.UserPost.Post.Code;
  11855. if (poscode != "SysAdmin")
  11856. {
  11857. string shopid = CurrentUser.User.pemShop;
  11858. lw.Add(string.Format("shopId in ({0})", shopid));
  11859. }
  11860. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11861. {
  11862. lw.Add("IssueState = 1");
  11863. }
  11864. lw.Add("IssueState > 0");
  11865. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11866. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11867. writeGridDataTableJson(dStruct.TotalCount, dt);
  11868. }
  11869. public void saveIssueContent()
  11870. {
  11871. string ctid = GetPostString("ctid");
  11872. if (!string.IsNullOrEmpty(ctid))
  11873. {
  11874. string content = GetPostString("content");
  11875. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11876. if (ceErpTradeAfterSaleExtend == null)
  11877. {
  11878. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11879. ceErpTradeAfterSaleExtend.tid = ctid;
  11880. }
  11881. ceErpTradeAfterSaleExtend.IssueContent = content;
  11882. ceErpTradeAfterSaleExtend.IssueState = 1;
  11883. if (ceErpTradeAfterSaleExtend.ID > 0)
  11884. {
  11885. ceErpTradeAfterSaleExtend.Update();
  11886. }
  11887. else
  11888. {
  11889. ceErpTradeAfterSaleExtend.Create();
  11890. }
  11891. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11892. returnSuccessMsg("添加成功!");
  11893. return;
  11894. }
  11895. returnErrorMsg("找不到订单");
  11896. }
  11897. public void dealIssueContent()
  11898. {
  11899. string ctid = GetPostString("ctid");
  11900. if (!string.IsNullOrEmpty(ctid))
  11901. {
  11902. string content = GetPostString("content");
  11903. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11904. if (ceErpTradeAfterSaleExtend != null)
  11905. {
  11906. ceErpTradeAfterSaleExtend.IssueState = 2;
  11907. ceErpTradeAfterSaleExtend.Update();
  11908. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11909. returnSuccessMsg("修改完成!");
  11910. return;
  11911. }
  11912. }
  11913. returnErrorMsg("找不到订单");
  11914. }
  11915. public void set_tid_attachments()
  11916. {
  11917. string tid = GetPostString("tid");
  11918. string atta = GetPostString("atta");
  11919. if (!string.IsNullOrEmpty(tid))
  11920. {
  11921. if (string.IsNullOrEmpty(atta))
  11922. {
  11923. returnErrorMsg("文件地址为空");
  11924. return;
  11925. }
  11926. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11927. if (ceErpTradeCell != null)
  11928. {
  11929. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11930. if (ceErpTrade == null)
  11931. {
  11932. returnErrorMsg("找不到订单");
  11933. return;
  11934. }
  11935. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11936. bool isSend = false;
  11937. if (dt != null && dt.Rows.Count > 0)
  11938. {
  11939. foreach (DataRow row in dt.Rows)
  11940. {
  11941. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11942. {
  11943. isSend = true;
  11944. }
  11945. }
  11946. if (isSend)
  11947. {
  11948. returnErrorMsg("已发货无法修改");
  11949. return;
  11950. }
  11951. ceErpTrade.Attachments = atta;
  11952. ceErpTrade.Update();
  11953. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  11954. returnSuccessMsg("上传成功!");
  11955. return;
  11956. }
  11957. }
  11958. }
  11959. returnErrorMsg("找不到订单");
  11960. }
  11961. public void get_tid_attachments()
  11962. {
  11963. string tid = GetPostString("tid");
  11964. if (!string.IsNullOrEmpty(tid))
  11965. {
  11966. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11967. if (ceErpTradeCell != null)
  11968. {
  11969. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11970. if (ceErpTrade == null)
  11971. {
  11972. returnErrorMsg("找不到订单");
  11973. return;
  11974. }
  11975. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11976. return;
  11977. }
  11978. }
  11979. returnErrorMsg("找不到订单");
  11980. }
  11981. public void check_erp_sameorders()
  11982. {
  11983. if (UrlPostParmsCheck("ctid"))
  11984. {
  11985. string eid = GetPostString("ctid");
  11986. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11987. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11988. if (entity != null && ceErpTrade != null)
  11989. {
  11990. if (entity.OrderState > 6)
  11991. {
  11992. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11993. return;
  11994. }
  11995. DataTable dt = getSameOrderList(entity, ceErpTrade);
  11996. List<string> ids = new List<string>();
  11997. if (dt != null && dt.Rows.Count > 1)
  11998. {
  11999. bool needhe = true;
  12000. foreach (DataRow dr in dt.Rows)
  12001. {
  12002. ids.Add("'" + dr["ctid"] + "'");
  12003. /* //备注有合包
  12004. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12005. {
  12006. needhe = true;
  12007. }
  12008. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12009. {
  12010. needhe = true;
  12011. }
  12012. //顺丰快递
  12013. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12014. {
  12015. needhe = true;
  12016. }*/
  12017. }
  12018. if (!needhe)
  12019. {
  12020. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12021. return;
  12022. }
  12023. StringBuilder sql = new StringBuilder();
  12024. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12025. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12026. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12027. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12028. foreach (DataRow dr in dt.Rows)
  12029. {
  12030. dr["dstate"] = 0;
  12031. dr["dnumber"] = 0;
  12032. foreach (DataRow row in dt1.Rows)
  12033. {
  12034. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12035. {
  12036. dr["dstate"] = 2;
  12037. dr["default"] = 1;
  12038. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12039. }
  12040. }
  12041. if (eid.Equals(dr["ctid"].ToString()))
  12042. {
  12043. dr["dstate"] = 1;
  12044. dr["default"] = 1;
  12045. }
  12046. }
  12047. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12048. return;
  12049. }
  12050. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12051. return;
  12052. }
  12053. returnErrorMsg("未找到订单");
  12054. return;
  12055. }
  12056. returnErrorMsg("缺少必要的参数");
  12057. }
  12058. private DataTable getSameOrderList(CeErpTradeCell entity, CeErpTrade ceErpTrade)
  12059. {
  12060. StringBuilder sql = new StringBuilder();
  12061. 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);
  12062. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12063. {
  12064. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12065. }
  12066. else
  12067. {
  12068. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12069. }
  12070. DataTable dt = null;
  12071. try
  12072. {
  12073. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12074. StringBuilder timerSql = new StringBuilder();
  12075. timerSql.AppendFormat("SELECT * FROM CE_ErpSupplierProductTime WHERE supplierId={0}", entity.SupplierId);
  12076. DataTable timerTable = DbHelper.DbConn.ExecuteDataset(timerSql.ToString()).Tables[0];
  12077. //没有设置时间则不判断
  12078. if (timerTable == null || timerTable.Rows.Count == 0)
  12079. {
  12080. return dt;
  12081. }
  12082. dt.Columns.Add(new DataColumn("default", typeof(int)));
  12083. foreach (DataRow dr in dt.Rows)
  12084. {
  12085. dr["default"] = 0;
  12086. //当前订单
  12087. if (entity.ctid.Equals(dr["ctid"]))
  12088. {
  12089. continue;
  12090. }
  12091. //已经标记过发货
  12092. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(dr["ctid"].ToString());
  12093. if (ceErpDeliverMark != null)
  12094. {
  12095. dr["default"] = 1;
  12096. continue;
  12097. }
  12098. string[] productIds = null;
  12099. string productId = dr["productId"].ToString();
  12100. string finishPlaceTime = dr["FinishPlaceTime"].ToString();
  12101. string sellmer_mome = dr["seller_memo"].ToString();
  12102. string txtCount = dr["ProductCount"].ToString();
  12103. DateTime placeTime = DateTime.Now;
  12104. //没有品类
  12105. if (string.IsNullOrEmpty(productId) || "0".Equals(productId))
  12106. {
  12107. continue;
  12108. }
  12109. if (string.IsNullOrEmpty(finishPlaceTime))
  12110. {
  12111. continue;
  12112. }
  12113. placeTime = DateTime.Parse(finishPlaceTime);
  12114. foreach (DataRow row in timerTable.Rows)
  12115. {
  12116. string txtIds = row["productId"].ToString();
  12117. string[] crafts = { };
  12118. int count = Convert.ToUInt16(row["quantity"]);
  12119. if (string.IsNullOrEmpty(txtIds))
  12120. {
  12121. continue;
  12122. }
  12123. if (count > 0)
  12124. {
  12125. int quantity = commonHelper.handleProductCount(txtCount, true);
  12126. //订单数量大于写入的数量则跳过
  12127. if (quantity > count)
  12128. {
  12129. continue;
  12130. }
  12131. }
  12132. productIds = txtIds.Split(',');
  12133. if (productIds.Contains(productId))
  12134. {
  12135. string textCraft = row["craft"].ToString();
  12136. textCraft = textCraft.Replace(",", ",");//统一格式
  12137. if (!string.IsNullOrEmpty(textCraft))
  12138. {
  12139. crafts = textCraft.Split(',');
  12140. }
  12141. if (crafts.Length > 0)
  12142. {
  12143. bool isinCraft = false;
  12144. for (int i = 0; i < crafts.Length; i++)
  12145. {
  12146. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12147. {
  12148. isinCraft = true;
  12149. break;
  12150. }
  12151. }
  12152. //有写工艺并且备注中没匹配中则跳过
  12153. if (!isinCraft)
  12154. {
  12155. continue;
  12156. }
  12157. }
  12158. DateTime deadLine = DateTime.Parse(row["deadLine"].ToString());
  12159. DateTime dayDeadLine = DateTime.Parse(row["dayDeadLine"].ToString());
  12160. int sendDay = Convert.ToInt16(row["sendDay"]);
  12161. //下单时间小于当日发货时间则不用判断
  12162. //当日发货必须发货
  12163. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12164. {
  12165. dr["default"] = 1;
  12166. break;
  12167. }
  12168. //在截稿时间之前下单的可以减去一天时间
  12169. /*if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12170. {
  12171. sendDay = Math.Max(1, sendDay - 1);
  12172. }
  12173. DateTime sendtime = placeTime.AddDays(sendDay);
  12174. //判断有没有到发货日期
  12175. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) > 0)
  12176. {
  12177. break;
  12178. }*/
  12179. }
  12180. }
  12181. }
  12182. }
  12183. catch (Exception ex)
  12184. {
  12185. }
  12186. return dt;
  12187. }
  12188. public void get_mark_number()
  12189. {
  12190. string eid = GetPostString("ctid");
  12191. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12192. if (entity != null)
  12193. {
  12194. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12195. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12196. int current = 1;
  12197. if (ceErpDeliverMark == null)
  12198. {
  12199. DataTable dt = getSameOrderList(entity, ceErpTrade);
  12200. List<string> ids = new List<string>();
  12201. if (dt != null && dt.Rows.Count > 1)
  12202. {
  12203. foreach (DataRow dr in dt.Rows)
  12204. {
  12205. ids.Add("'" + dr["ctid"] + "'");
  12206. }
  12207. //查询已有的编号
  12208. StringBuilder sql = new StringBuilder();
  12209. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12210. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12211. if (dt1 == null || dt1.Rows.Count == 0)
  12212. {
  12213. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12214. List<int> list_number = new List<int>();
  12215. foreach (DataRow row in numbers.Rows)
  12216. {
  12217. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12218. }
  12219. //查询空余编号
  12220. for (int i = 0; i < list_number.Count + 2; i++)
  12221. {
  12222. if (!list_number.Contains(current))
  12223. {
  12224. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12225. //防止查询过程中有新数据生成
  12226. if (ceErpDeliverMark1 == null)
  12227. {
  12228. break;
  12229. }
  12230. }
  12231. current++;
  12232. }
  12233. }
  12234. else
  12235. {
  12236. foreach (DataRow row in dt1.Rows)
  12237. {
  12238. current = Convert.ToInt32(row["markNumber"]);
  12239. }
  12240. }
  12241. ceErpDeliverMark = new CeErpDeliverMark();
  12242. ceErpDeliverMark.ctid = eid;
  12243. ceErpDeliverMark.createtime = DateTime.Now;
  12244. if (ceErpTrade != null)
  12245. {
  12246. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12247. }
  12248. ceErpDeliverMark.markNumber = current;
  12249. ceErpDeliverMark.Create();
  12250. }
  12251. }
  12252. else
  12253. {
  12254. current = ceErpDeliverMark.markNumber;
  12255. }
  12256. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12257. return;
  12258. }
  12259. }
  12260. public void aftersaleCytSend()
  12261. {
  12262. string ctid = GetPostString("ctid");
  12263. if (!string.IsNullOrEmpty(ctid))
  12264. {
  12265. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12266. if (ceErpTradeCell != null)
  12267. {
  12268. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12269. }
  12270. returnSuccessMsg("推送成功");
  12271. return;
  12272. }
  12273. returnErrorMsg("缺少必要的参数");
  12274. }
  12275. public void packOrderInfo()
  12276. {
  12277. string ctids = GetPostString("ctids");
  12278. if (!string.IsNullOrEmpty(ctids))
  12279. {
  12280. string[] ctid_list = ctids.Split(',');
  12281. if (ctid_list.Length > 20)
  12282. {
  12283. returnErrorMsg("单次下载次数不能超过20个");
  12284. return;
  12285. }
  12286. StringBuilder sql = new StringBuilder();
  12287. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  12288. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12289. int supplierId = 0;
  12290. StringBuilder insterSql = new StringBuilder();
  12291. for (int i = 0; i < dt.Rows.Count; i++)
  12292. {
  12293. DataRow row = dt.Rows[i];
  12294. if (i == 0)
  12295. {
  12296. supplierId = Convert.ToInt32(row["SupplierId"]);
  12297. }
  12298. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12299. {
  12300. returnErrorMsg("同车间的订单才能一起打包");
  12301. return;
  12302. }
  12303. int orderState = Convert.ToInt32(row["OrderState"]);
  12304. if (orderState != 5)
  12305. {
  12306. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12307. return;
  12308. }
  12309. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12310. }
  12311. CeErpPackData ceErpPackData = new CeErpPackData();
  12312. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip";
  12313. ceErpPackData.supplierId = supplierId;
  12314. ceErpPackData.createtime = DateTime.Now;
  12315. ceErpPackData.createBy = CurrentUser.UserID;
  12316. ceErpPackData.createName = CurrentUser.UserName;
  12317. ceErpPackData.Create();
  12318. if (ceErpPackData.ID > 0)
  12319. {
  12320. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12321. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12322. }
  12323. returnSuccessMsg("打包成功");
  12324. return;
  12325. }
  12326. returnErrorMsg("缺少必要的参数");
  12327. }
  12328. public void get_pack_list()
  12329. {
  12330. DataStruct dStruct = GetPostStruct();
  12331. List<string> lw = new List<string>();
  12332. string supplier = GetPostString("supplier");
  12333. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12334. string posTag = CurrentUser.UserPost.Post.Code;
  12335. if (posTag == "Supplier")
  12336. {
  12337. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12338. }
  12339. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12340. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12341. writeGridDataTableJson(dStruct.TotalCount, dt);
  12342. }
  12343. public void get_supplier_product_time_list()
  12344. {
  12345. DataStruct dStruct = GetPostStruct();
  12346. List<string> lw = new List<string>();
  12347. string supplier = GetPostString("supplier");
  12348. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12349. string posTag = CurrentUser.UserPost.Post.Code;
  12350. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12351. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12352. writeGridDataTableJson(dStruct.TotalCount, dt);
  12353. }
  12354. public void saveSupplierProductTime()
  12355. {
  12356. string productId = GetPostString("productId");
  12357. if (string.IsNullOrEmpty(productId))
  12358. {
  12359. returnErrorMsg("缺少必要的参数");
  12360. return;
  12361. }
  12362. string productName = GetPostString("productName");
  12363. int supplierId = GetPostInt("supplierId");
  12364. if (supplierId == 0)
  12365. {
  12366. returnErrorMsg("缺少必要的参数");
  12367. return;
  12368. }
  12369. int quantity = GetPostInt("quantity");
  12370. int sendDay = GetPostInt("sendTime");
  12371. string supplierName = GetPostString("supplierName");
  12372. string craft = GetPostString("craft");
  12373. string deadLine = GetPostString("deadLine");
  12374. string dayDeadLine = GetPostString("dayDeadLine");
  12375. try
  12376. {
  12377. int eid = GetPostInt("eid");
  12378. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12379. if (ceErpSupplierProductTime == null)
  12380. {
  12381. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12382. }
  12383. ceErpSupplierProductTime.productId = productId;
  12384. ceErpSupplierProductTime.productName = productName;
  12385. ceErpSupplierProductTime.supplierId = supplierId;
  12386. ceErpSupplierProductTime.supplierName = supplierName;
  12387. ceErpSupplierProductTime.craft = craft;
  12388. ceErpSupplierProductTime.sendDay = sendDay;
  12389. ceErpSupplierProductTime.quantity = quantity;
  12390. if (!string.IsNullOrEmpty(deadLine))
  12391. {
  12392. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12393. }
  12394. if (!string.IsNullOrEmpty(dayDeadLine))
  12395. {
  12396. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12397. }
  12398. if (ceErpSupplierProductTime.ID == 0)
  12399. {
  12400. ceErpSupplierProductTime.Save();
  12401. }
  12402. else
  12403. {
  12404. ceErpSupplierProductTime.Update();
  12405. }
  12406. }
  12407. catch (Exception e)
  12408. {
  12409. }
  12410. returnSuccessMsg("保存成功");
  12411. return;
  12412. }
  12413. public void delSupplierProductTime()
  12414. {
  12415. int eid = GetPostInt("eid");
  12416. if (eid > 0)
  12417. {
  12418. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12419. if (ceErpSupplierProductTime == null)
  12420. {
  12421. returnErrorMsg("查无数据");
  12422. return;
  12423. }
  12424. ceErpSupplierProductTime.Delete();
  12425. returnSuccessMsg("保存成功");
  12426. return;
  12427. }
  12428. returnErrorMsg("缺少必要的参数");
  12429. }
  12430. public void getExpressInfo()
  12431. {
  12432. string ctid = GetPostString("ctid");
  12433. if (!string.IsNullOrEmpty(ctid))
  12434. {
  12435. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12436. if (ceErpTradeCell != null)
  12437. {
  12438. string outSid = ceErpTradeCell.OutSid;
  12439. if (outSid.Length > 0)
  12440. {
  12441. 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);
  12442. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12443. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12444. return;
  12445. }
  12446. }
  12447. returnErrorMsg("查无记录");
  12448. return;
  12449. }
  12450. returnErrorMsg("缺少必要的参数");
  12451. }
  12452. public void getExpressPostData()
  12453. {
  12454. string express = GetPostString("express");
  12455. if (!string.IsNullOrEmpty(express))
  12456. {
  12457. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12458. if (ceErpExpressInfo != null)
  12459. {
  12460. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12461. return;
  12462. }
  12463. }
  12464. returnErrorMsg("缺少必要的参数");
  12465. }
  12466. }
  12467. }