sync.order.cs 638 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796
  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\\CE_ErpProduct(3).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. newentity.MemoOpt = 0;
  6656. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6657. }
  6658. newentity.isAfterSaleOrder = 1;
  6659. newentity.IsRefund = 0;
  6660. string receiveMobile = GetPostString("receiver_mobile");
  6661. if (receiveMobile.Length > 0)
  6662. {
  6663. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6664. if (trade != null)
  6665. {
  6666. trade.receiver_name = GetPostString("receiver_name");
  6667. trade.receiver_mobile = receiveMobile;
  6668. trade.receiver_state = GetPostString("receiver_state");
  6669. trade.receiver_city = GetPostString("receiver_city");
  6670. trade.receiver_district = GetPostString("receiver_district");
  6671. trade.receiver_address = GetPostString("receiver_address");
  6672. newentity.IsOffLineOrder = 1;
  6673. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6674. }
  6675. }
  6676. string st = GetPostString("ToState");
  6677. if (st.Length > 0)
  6678. {
  6679. if (newentity.OrderState <= 3)
  6680. {
  6681. newentity.WaitDesignTime = DateTime.Now;
  6682. newentity.StartDesignTime = null;
  6683. newentity.FinishDesignTime = null;
  6684. newentity.OrderState = 3;
  6685. if (st == "下单员")
  6686. {
  6687. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6688. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6689. {
  6690. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6691. }
  6692. }
  6693. else
  6694. {
  6695. newentity.WaitDesignTime = DateTime.Now;
  6696. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6697. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6698. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6699. {
  6700. DataRow user = dt1.Rows[0];
  6701. //找主管
  6702. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6703. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6704. if (dt != null && dt.Rows.Count > 0)
  6705. {
  6706. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6707. newentity.DesignUserId = designMr;
  6708. string key = "aftersale_order_" + designMr;
  6709. if (RedisHelper.HasKey(key))
  6710. {
  6711. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6712. list.Add(newentity.ctid);
  6713. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6714. }
  6715. }
  6716. //账号正常
  6717. if (user["State"].ToString() == "0")
  6718. {
  6719. newentity.DesignUserId = entity.DesignUserId;
  6720. string key = "aftersale_order_" + entity.DesignUserId;
  6721. if (RedisHelper.HasKey(key))
  6722. {
  6723. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6724. list.Add(newentity.ctid);
  6725. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6726. }
  6727. }
  6728. }
  6729. }
  6730. }
  6731. if (entity.IsXianHuo == 1)
  6732. {
  6733. newentity.OrderState = 6;
  6734. entity.FinishPlaceTime = DateTime.Now;
  6735. }
  6736. }
  6737. if (ishav)
  6738. {
  6739. newentity.Update();
  6740. }
  6741. else
  6742. {
  6743. newentity.Create();
  6744. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6745. newCellExtend.ctid = newentity.ctid;
  6746. newCellExtend.orderFrom = 20;
  6747. newCellExtend.orderType = 30;
  6748. if (st == "下单员")
  6749. {
  6750. }
  6751. else
  6752. {
  6753. newCellExtend.ReprintTime = DateTime.Now;
  6754. }
  6755. newCellExtend.Create();
  6756. }
  6757. if (st != "下单员")
  6758. {
  6759. if (entity.DispatchSort == 2)
  6760. {
  6761. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6762. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6763. }
  6764. }
  6765. }
  6766. //处理售后扩展
  6767. string resIdStr = GetPostString("ResponsibleUserId");
  6768. string refundFees = GetPostString("refundFrees");
  6769. int IsComplain = GetPostInt("isComplain");
  6770. int IsBad = GetPostInt("isBad");
  6771. string IsOriginal = GetPostString("isOriginal");
  6772. double diffResultPrice = GetPostDouble("diffResultPrice");
  6773. string textResult = GetPostString("textResult");
  6774. string supplierResponsible = GetPostString("supplierResponsible");
  6775. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6776. if (ceErpTradeAfterSaleExtend == null)
  6777. {
  6778. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6779. ceErpTradeAfterSaleExtend.tid = eid;
  6780. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6781. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6782. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6783. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6784. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6785. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6786. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6787. ceErpTradeAfterSaleExtend.Create();
  6788. }
  6789. else
  6790. {
  6791. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6792. {
  6793. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6794. }
  6795. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6796. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6797. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6798. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6799. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6800. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6801. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6802. ceErpTradeAfterSaleExtend.Update();
  6803. }
  6804. int gysid = GetPostInt("ResponsibleSupId");
  6805. if (entity.AfterSaleUserId == 0)
  6806. {
  6807. entity.AfterSaleUserId = CurrentUser.UserID;
  6808. }
  6809. entity.ResponsibleUserId = resIdStr;
  6810. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6811. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6812. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6813. {
  6814. CeErpTradeResponsible.DelByTid(eid, -1);
  6815. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6816. int backNum = 0;
  6817. if (number != null)
  6818. {
  6819. backNum = number.BackNum;
  6820. }
  6821. char[] separator = { ',' };
  6822. string[] sArray = resIdStr.Split(separator);
  6823. string[] refundFreeList = { };
  6824. if (refundFees.Length > 0)
  6825. {
  6826. refundFreeList = refundFees.Split(separator);
  6827. }
  6828. int index = -1;
  6829. foreach (string i in sArray)
  6830. {
  6831. index++;
  6832. if (i.Length <= 0) continue;
  6833. char[] separator2 = { '_' };
  6834. string idstr = i.Split(separator2)[0];
  6835. string idtype = i.Split(separator2)[1];
  6836. double refudFree = 0;
  6837. if (refundFreeList.Length > 0)
  6838. {
  6839. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6840. }
  6841. if (idtype == "s")
  6842. {
  6843. isDesign = true;
  6844. designFree = refudFree;
  6845. }
  6846. int userId = Convert.ToInt32(idstr);
  6847. int type = 0;
  6848. if (idtype == "g")
  6849. {
  6850. type = 1;
  6851. }
  6852. if (idtype == "w")
  6853. {
  6854. type = 2;
  6855. }
  6856. if (idtype == "t")
  6857. {
  6858. type = 3;
  6859. }
  6860. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6861. if (ceErpTradeResponsible == null)
  6862. {
  6863. ceErpTradeResponsible = new CeErpTradeResponsible();
  6864. ceErpTradeResponsible.tid = eid;
  6865. ceErpTradeResponsible.UserId = userId;
  6866. ceErpTradeResponsible.createdTime = DateTime.Now;
  6867. ceErpTradeResponsible.type = type;
  6868. if (type == 1)
  6869. {
  6870. ceErpTradeResponsible.IsSup = 1;
  6871. }
  6872. if (type == 2)
  6873. {
  6874. ceErpTradeResponsible.IsFlow = 1;
  6875. }
  6876. }
  6877. ceErpTradeResponsible.RefundFee = refudFree;
  6878. ceErpTradeResponsible.VerifyState = 0;
  6879. if (userId == 2125 || idtype == "w")
  6880. {
  6881. ceErpTradeResponsible.VerifyState = 1;
  6882. }
  6883. if (idtype == "w" && userId == 101)
  6884. {
  6885. ceErpTradeResponsible.VerifyState = 0;
  6886. }
  6887. if (ceErpTradeResponsible.ID > 0)
  6888. {
  6889. ceErpTradeResponsible.Update();
  6890. }
  6891. else
  6892. {
  6893. ceErpTradeResponsible.Create();
  6894. }
  6895. if (isDesign)
  6896. {
  6897. responsibleId = ceErpTradeResponsible.ID;
  6898. }
  6899. }
  6900. CeErpTradeResponsible.NumByTid(backNum, eid);
  6901. }
  6902. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6903. if (ceErpTradeCellExtend != null)
  6904. {
  6905. ceErpTradeCellExtend.returnVisit = 0;
  6906. ceErpTradeCellExtend.Update();
  6907. }
  6908. if (entity.HandleTime != null)
  6909. {
  6910. if (entity.AfterSaleState == 1)
  6911. {
  6912. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6913. }
  6914. else
  6915. {
  6916. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6917. }
  6918. }
  6919. else
  6920. {
  6921. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6922. entity.HandleTime = DateTime.Now;
  6923. }
  6924. bool isCompale = false;
  6925. if (entity.AfterSaleState == 5)
  6926. {
  6927. isCompale = true;
  6928. entity.AfterSaleState = 3;
  6929. }
  6930. entity.AfterSaleSupplierState = 0;
  6931. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6932. {
  6933. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6934. }
  6935. string sImgs = GetPostString("img");
  6936. entity.AfterSaleSupplierImg = sImgs;
  6937. entity.supRefundType = GetPostString("supRefundType");
  6938. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6939. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6940. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6941. entity.AfterSaleMemoType = GetPostString("MemoType");
  6942. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6943. {
  6944. //entity.AfterSaleSupplierState = 2;
  6945. }
  6946. string df = GetPostString("DeductFee");
  6947. if (df == "")
  6948. {
  6949. df = "0";
  6950. }
  6951. string rf = GetPostString("RefundFee");
  6952. if (rf == "")
  6953. {
  6954. rf = "0";
  6955. }
  6956. string pm = GetPostString("AfterSalePayment");
  6957. if (pm == "")
  6958. {
  6959. pm = "0";
  6960. }
  6961. entity.AfterSalePayment = Convert.ToDouble(pm);
  6962. entity.DeductFee = Convert.ToDouble(df);
  6963. entity.RefundFee = Convert.ToDouble(rf);
  6964. entity.UpdateTime = DateTime.Now;
  6965. entity.Update();
  6966. string toState = GetPostString("ToState");
  6967. string original = GetPostString("isOriginal");
  6968. ApiVo apiVo = new ApiVo();
  6969. apiVo.orderNumber = entity.ctid;
  6970. apiVo.actionName = "afterDesign";
  6971. apiVo.orderRemarks = entity.AfterSaleMethod;
  6972. apiVo.reasonRemarks = entity.AfterSaleReason;
  6973. apiVo.isDesign = isDesign;
  6974. apiVo.designFree = designFree;
  6975. apiVo.responsibleId = responsibleId;
  6976. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6977. if (toState == "设计师")
  6978. {
  6979. apiVo.isOriginal = Convert.ToBoolean(original);
  6980. }
  6981. designHelper.API_WorkCore(apiVo);//afterDesign
  6982. CeErpMethod methodSql = new CeErpMethod();
  6983. methodSql.con = entity.AfterSaleMethod;
  6984. methodSql.addTime = DateTime.Now;
  6985. methodSql.Create();
  6986. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6987. CeErpMethod.ExecuteNonQuery(delsql);
  6988. if (isCompale)
  6989. {
  6990. aftersale_data_change(entity.ctid);
  6991. }
  6992. returnSuccessMsg("操作成功!");
  6993. return;
  6994. }
  6995. returnErrorMsg("找不到订单记录");
  6996. }
  6997. }
  6998. public void ins_erp_toresponsible()
  6999. {
  7000. if (UrlPostParmsCheck("ctid"))
  7001. {
  7002. string eid = GetPostString("ctid");
  7003. CeErpTradeCell entity = null;
  7004. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7005. if (entity != null)
  7006. {
  7007. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7008. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7009. {
  7010. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7011. return;
  7012. }
  7013. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7014. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7015. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7016. if (entity.AfterSalePreTime == null)
  7017. {
  7018. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7019. {
  7020. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7021. }
  7022. }
  7023. entity.AfterSalePreTime = DateTime.Now;
  7024. //预完成给售后主管审核客户问题直接完成
  7025. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7026. {
  7027. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7028. {
  7029. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7030. }
  7031. }
  7032. ceErpTradeAfterSaleExtend.Update();
  7033. entity.AfterSaleState = 2;
  7034. entity.UpdateTime = DateTime.Now;
  7035. entity.Update();
  7036. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7037. aftersale_data_change(entity.ctid);
  7038. returnSuccessMsg("操作成功!");
  7039. return;
  7040. }
  7041. returnErrorMsg("找不到订单记录");
  7042. }
  7043. }
  7044. public void cancel_erp_aftersaleanddelnew()
  7045. {
  7046. if (UrlPostParmsCheck("ctid"))
  7047. {
  7048. string eid = GetPostString("ctid");
  7049. CeErpTradeCell entity = null;
  7050. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7051. if (entity != null)
  7052. {
  7053. entity.AfterSaleState = 0;
  7054. entity.AfterSaleReason = "";
  7055. entity.AfterSaleMethod = "";
  7056. entity.AfterSaleMemo = "";
  7057. entity.AfterSaleResponsible = "";
  7058. entity.ResponsibleUserId = "";
  7059. entity.DeductFee = 0;
  7060. entity.RefundFee = 0;
  7061. entity.IsArbitrate = 0;
  7062. CeErpTradeResponsible.DelByTid(eid, -1);
  7063. entity.Update();
  7064. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7065. if (after != null)
  7066. {
  7067. if (after.OrderState < 5)
  7068. CeErpTradeCell.DelByCtid("S_" + eid);
  7069. }
  7070. returnSuccessMsg("操作成功!");
  7071. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7072. return;
  7073. }
  7074. returnErrorMsg("找不到订单记录");
  7075. }
  7076. }
  7077. public void get_erp_aftersale_pregather()
  7078. {
  7079. List<string> lw = new List<string>();
  7080. int st = GetInt("st");
  7081. string tid = GetPostString("ctid");
  7082. if (tid.Length > 0)
  7083. {
  7084. string select_tid = getTidByCtid(tid);
  7085. lw.Add(string.Format("tid='{0}'", select_tid));
  7086. }
  7087. string shopname = GetPostString("shopname");
  7088. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7089. string buyernick = GetPostString("buyer_nick");
  7090. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7091. string sellermemo = GetPostString("seller_memo");
  7092. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7093. string orderState = GetPostString("orderState");
  7094. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7095. string reason = GetPostString("reason");
  7096. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7097. string method = GetPostString("method");
  7098. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7099. string handler = GetPostString("handler");
  7100. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7101. string handledate1 = GetPostString("handledate1");
  7102. string handledate2 = GetPostString("handledate2");
  7103. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7104. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7105. string supplier = GetPostString("supplier");
  7106. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7107. string responsible = GetPostString("responsibleman");
  7108. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7109. string customer = GetPostString("customer");
  7110. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7111. string design = GetPostString("design");
  7112. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7113. string afterMemoType = GetPostString("aftermemotype");
  7114. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7115. string afterSaleMemo = GetPostString("afterSaleMemo");
  7116. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7117. string afterresult = GetPostString("afterresult");
  7118. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7119. string poscode = CurrentUser.UserPost.Post.Code;
  7120. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7121. {
  7122. string shopid = CurrentUser.User.pemShop;
  7123. lw.Add(string.Format("shopId in ({0})", shopid));
  7124. }
  7125. var mainwhere = string.Join(" and ", lw.ToArray());
  7126. string ro_json = "";
  7127. string type = GetPostString("gather_type");
  7128. int number = 0;
  7129. if (poscode == "AfterSale")
  7130. {
  7131. //处理中
  7132. if (type == "Handling")
  7133. {
  7134. 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) : ""));
  7135. DataTable dt = null;
  7136. try
  7137. {
  7138. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7139. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7140. }
  7141. catch (Exception e)
  7142. {
  7143. dt = new DataTable();
  7144. }
  7145. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7146. return;
  7147. }
  7148. if (type == "Wait")
  7149. {
  7150. //待处理
  7151. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7152. DataTable dt1 = null;
  7153. try
  7154. {
  7155. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7156. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7157. }
  7158. catch (Exception e)
  7159. {
  7160. dt1 = new DataTable();
  7161. }
  7162. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7163. return;
  7164. }
  7165. if (type == "back")
  7166. {
  7167. //打回
  7168. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7169. DataTable dt2 = null;
  7170. try
  7171. {
  7172. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7173. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7174. }
  7175. catch (Exception e)
  7176. {
  7177. dt2 = new DataTable();
  7178. }
  7179. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7180. return;
  7181. }
  7182. if (type == "preCompletion")
  7183. {
  7184. //预完成
  7185. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7186. DataTable dt3 = null;
  7187. try
  7188. {
  7189. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7190. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7191. }
  7192. catch (Exception e)
  7193. {
  7194. dt3 = new DataTable();
  7195. }
  7196. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7197. return;
  7198. }
  7199. if (type == "documentary")
  7200. {
  7201. //跟单中
  7202. 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) : ""));
  7203. DataTable dt4 = null;
  7204. try
  7205. {
  7206. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7207. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7208. }
  7209. catch (Exception e)
  7210. {
  7211. dt4 = new DataTable();
  7212. }
  7213. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7214. return;
  7215. }
  7216. if (type == "reBack")
  7217. {
  7218. //被打回
  7219. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7220. DataTable dt1 = null;
  7221. try
  7222. {
  7223. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7224. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7225. }
  7226. catch (Exception e)
  7227. {
  7228. dt1 = new DataTable();
  7229. }
  7230. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7231. return;
  7232. }
  7233. }
  7234. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7235. {
  7236. if (type == "puBack")
  7237. {
  7238. //退回
  7239. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7240. DataTable dt = null;
  7241. try
  7242. {
  7243. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7244. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7245. }
  7246. catch (Exception e)
  7247. {
  7248. dt = new DataTable();
  7249. }
  7250. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7251. return;
  7252. }
  7253. if (type == "reBack")
  7254. {
  7255. //打回
  7256. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7257. DataTable dt1 = null;
  7258. try
  7259. {
  7260. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7261. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7262. }
  7263. catch (Exception e)
  7264. {
  7265. dt1 = new DataTable();
  7266. }
  7267. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7268. return;
  7269. }
  7270. if (type == "examEd")
  7271. {
  7272. //已审核
  7273. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7274. DataTable dt2 = null;
  7275. try
  7276. {
  7277. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7278. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7279. }
  7280. catch (Exception e)
  7281. {
  7282. dt2 = new DataTable();
  7283. }
  7284. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7285. return;
  7286. }
  7287. if (type == "waitExam")
  7288. {
  7289. //待审核
  7290. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7291. DataTable dt3 = null;
  7292. try
  7293. {
  7294. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7295. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7296. }
  7297. catch (Exception e)
  7298. {
  7299. dt3 = new DataTable();
  7300. }
  7301. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7302. return;
  7303. }
  7304. if (type == "Handling")
  7305. {
  7306. //处理中
  7307. 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) : ""));
  7308. DataTable dt4 = null;
  7309. try
  7310. {
  7311. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7312. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7313. }
  7314. catch (Exception e)
  7315. {
  7316. dt4 = new DataTable();
  7317. }
  7318. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7319. return;
  7320. }
  7321. if (type == "Wait")
  7322. {
  7323. //待处理
  7324. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7325. DataTable dt5 = null;
  7326. try
  7327. {
  7328. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7329. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7330. }
  7331. catch (Exception e)
  7332. {
  7333. dt5 = new DataTable();
  7334. }
  7335. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7336. return;
  7337. }
  7338. if (type == "documentary")
  7339. {
  7340. //跟单中
  7341. 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) : ""));
  7342. DataTable dt6 = null;
  7343. try
  7344. {
  7345. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7346. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7347. }
  7348. catch (Exception e)
  7349. {
  7350. dt6 = new DataTable();
  7351. }
  7352. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7353. return;
  7354. }
  7355. }
  7356. returnSuccess(ro_json);
  7357. }
  7358. public void end_erp_aftersale()
  7359. {
  7360. if (UrlPostParmsCheck("ctid"))
  7361. {
  7362. string eid = GetPostString("ctid");
  7363. CeErpTradeCell entity = null;
  7364. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7365. if (entity != null)
  7366. {
  7367. string stype = GetPostString("stype");
  7368. string typeStr = stype;
  7369. entity.AfterSaleState = 4;
  7370. entity.FinishAfterSaleTime = DateTime.Now;
  7371. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7372. entity.Update();
  7373. ApiVo apiVo = new ApiVo();
  7374. apiVo.orderNumber = entity.ctid;
  7375. apiVo.actionName = "afterOver";
  7376. designHelper.API_WorkCore(apiVo); //afterOver
  7377. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7378. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7379. CeErpSukuraData.createInfo(entity.ctid, 8);
  7380. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7381. returnSuccessMsg("操作成功!");
  7382. return;
  7383. }
  7384. returnErrorMsg("找不到订单记录");
  7385. }
  7386. }
  7387. public void ins_erp_finishaftersale()
  7388. {
  7389. if (UrlPostParmsCheck("id"))
  7390. {
  7391. string eid = GetPostString("id");
  7392. CeErpTradeResponsible entity = null;
  7393. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7394. if (entity != null)
  7395. {
  7396. entity.VerifyState = 1;
  7397. entity.VerifyTime = DateTime.Now;
  7398. entity.Update();
  7399. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7400. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7401. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7402. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7403. if (dt.Rows.Count <= 0)
  7404. {
  7405. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7406. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7407. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7408. CeErpSukuraData.createInfo(entity.tid, 8);
  7409. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7410. {
  7411. CeErpDesignerBill.Del(entity.tid);
  7412. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7413. }
  7414. }
  7415. returnSuccessMsg("操作成功!");
  7416. return;
  7417. }
  7418. returnErrorMsg("找不到订单记录");
  7419. }
  7420. }
  7421. public void upd_erp_arbitrateaftersale()
  7422. {
  7423. if (UrlPostParmsCheck("id"))
  7424. {
  7425. string eid = GetPostString("id");
  7426. CeErpTradeResponsible entity = null;
  7427. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7428. if (entity != null)
  7429. {
  7430. entity.IsArbitrate = 1;
  7431. entity.ArbitradeMemo = GetPostString("reason");
  7432. entity.VerifyState = 2;
  7433. entity.Update();
  7434. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7435. if (tradecell != null)
  7436. {
  7437. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7438. tradecell.IsArbitrate = 1;
  7439. tradecell.Update();
  7440. }
  7441. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7442. returnSuccessMsg("操作成功!");
  7443. return;
  7444. }
  7445. returnErrorMsg("找不到订单记录");
  7446. }
  7447. }
  7448. public void upd_erp_backaftersale()
  7449. {
  7450. if (UrlPostParmsCheck("tid"))
  7451. {
  7452. string eid = GetPostString("tid");
  7453. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7454. int backNum = 0;
  7455. if (number != null)
  7456. {
  7457. backNum = number.BackNum;
  7458. }
  7459. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7460. CeErpTradeCell entity = null;
  7461. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7462. if (entity != null)
  7463. {
  7464. entity.AfterSaleBackReason = GetPostString("backreason");
  7465. entity.AfterSaleState = 1;
  7466. entity.AfterSaleSupplierState = 0;
  7467. entity.UpdateTime = DateTime.Now;
  7468. entity.Update();
  7469. returnSuccessMsg("操作成功!");
  7470. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7471. return;
  7472. }
  7473. returnErrorMsg("找不到订单记录");
  7474. }
  7475. }
  7476. public void get_erp_supplieraftersalelist()
  7477. {
  7478. DataStruct dStruct = GetPostStruct();
  7479. List<string> lw = new List<string>();
  7480. string tid = GetPostString("ctid");
  7481. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7482. string shopname = GetPostString("shopname");
  7483. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7484. string buyernick = GetPostString("buyer_nick");
  7485. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7486. string sellermemo = GetPostString("seller_memo");
  7487. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7488. string orderState = GetPostString("orderState");
  7489. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7490. string afterState = GetPostString("afterstate");
  7491. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7492. string date1 = GetPostString("date1");
  7493. string date2 = GetPostString("date2");
  7494. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7495. if (dw.Length > 0) lw.Add(dw);
  7496. string price1 = GetPostString("price1");
  7497. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7498. string price2 = GetPostString("price2");
  7499. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7500. string reason = GetPostString("reason");
  7501. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7502. string method = GetPostString("method");
  7503. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7504. string handledate1 = GetPostString("handledate1");
  7505. string handledate2 = GetPostString("handledate2");
  7506. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7507. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7508. string handler = GetPostString("handler");
  7509. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7510. string afterdate1 = GetPostString("afterdate1");
  7511. string afterdate2 = GetPostString("afterdate2");
  7512. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7513. if (afterDate.Length > 0) lw.Add(afterDate);
  7514. string customer = GetPostString("customer");
  7515. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7516. string design = GetPostString("design");
  7517. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7518. string afterMemoType = GetPostString("aftermemotype");
  7519. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7520. string vstate = GetPostString("vstate");
  7521. if (vstate.Length > 0)
  7522. {
  7523. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7524. }
  7525. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7526. string supplier = GetPostString("supplier");
  7527. int supid = commonHelper.getSupplierIDByName(supplier);
  7528. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7529. string posCode = CurrentUser.UserPost.Post.Code;
  7530. if (posCode == "Supplier")
  7531. {
  7532. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7533. }
  7534. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7535. {
  7536. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7537. }
  7538. else
  7539. {
  7540. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7541. }
  7542. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7543. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7544. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7545. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7546. writeGridDataTableJson(dStruct.TotalCount, dt);
  7547. }
  7548. public void upd_erp_supverifyaftersale()
  7549. {
  7550. if (UrlPostParmsCheck("id"))
  7551. {
  7552. string id = GetPostString("id");
  7553. int st = GetPostInt("afterstate");
  7554. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7555. CeErpTradeCell entity = null;
  7556. if (ceErpTradeResponsible != null)
  7557. {
  7558. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7559. }
  7560. string afmemo = GetPostString("supmemo");
  7561. string image = GetPostString("image");
  7562. if (entity != null)
  7563. {
  7564. entity.AfterSaleSupplierState = st;
  7565. entity.AfterSaleSupplierMemo = afmemo;
  7566. if (st == 1)
  7567. {
  7568. ceErpTradeResponsible.VerifyState = 1;
  7569. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7570. ceErpTradeResponsible.Update();
  7571. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7572. if (isAll)
  7573. {
  7574. entity.AfterSaleState = 4;
  7575. entity.FinishAfterSaleTime = DateTime.Now;
  7576. }
  7577. }
  7578. else
  7579. {
  7580. CeErpTradeResponsible.dateByTid(entity.ctid);
  7581. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7582. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7583. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7584. if (num <= 1)
  7585. {
  7586. entity.AfterSaleState = 1;
  7587. }
  7588. else
  7589. {
  7590. entity.AfterSaleState = 5;
  7591. }
  7592. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7593. if (ceErpTradeAfterSaleExtend != null)
  7594. {
  7595. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7596. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7597. ceErpTradeAfterSaleExtend.Update();
  7598. }
  7599. else
  7600. {
  7601. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7602. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7603. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7604. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7605. ceErpTradeAfterSaleExtend.Create();
  7606. }
  7607. }
  7608. if (entity.AfterSaleState == 4)
  7609. {
  7610. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7611. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7612. {
  7613. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7614. }
  7615. ApiVo apiVo = new ApiVo();
  7616. apiVo.orderNumber = entity.ctid;
  7617. apiVo.actionName = "afterOver";
  7618. designHelper.API_WorkCore(apiVo); //afterOver
  7619. }
  7620. entity.UpdateTime = DateTime.Now;
  7621. entity.Update();
  7622. returnSuccessMsg("操作成功!");
  7623. CeErpSukuraData.createInfo(entity.ctid, 8);
  7624. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7625. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7626. return;
  7627. }
  7628. returnErrorMsg("找不到订单记录");
  7629. }
  7630. }
  7631. public void upd_erp_masteraftersale()
  7632. {
  7633. if (UrlPostParmsCheck("id"))
  7634. {
  7635. string id = GetPostString("id");
  7636. int st = GetPostInt("afterstate");
  7637. string afmemo = GetPostString("supmemo");
  7638. string image = GetPostString("image");
  7639. string textResult = GetPostString("textResult");
  7640. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7641. if (ceErpTradeResponsible != null)
  7642. {
  7643. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7644. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7645. ceErpTradeResponsible.Update();
  7646. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7647. if (entity != null)
  7648. {
  7649. entity.AfterSaleSupplierState = st;
  7650. entity.AfterSaleSupplierMemo = afmemo;
  7651. if (st == 1)
  7652. {
  7653. }
  7654. else
  7655. {
  7656. CeErpTradeResponsible.dateByTid(entity.ctid);
  7657. //退回到售后
  7658. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7659. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7660. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7661. if (num <= 1)
  7662. {
  7663. entity.AfterSaleState = 1;
  7664. }
  7665. else
  7666. {
  7667. entity.AfterSaleState = 5;
  7668. }
  7669. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7670. if (ceErpTradeAfterSaleExtend != null)
  7671. {
  7672. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7673. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7674. ceErpTradeAfterSaleExtend.Update();
  7675. }
  7676. else
  7677. {
  7678. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7679. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7680. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7681. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7682. ceErpTradeAfterSaleExtend.Create();
  7683. }
  7684. }
  7685. entity.UpdateTime = DateTime.Now;
  7686. entity.Update();
  7687. returnSuccessMsg("操作成功!");
  7688. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7689. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7690. return;
  7691. }
  7692. }
  7693. returnErrorMsg("找不到订单记录");
  7694. }
  7695. }
  7696. public void upd_erp_personaftersale()
  7697. {
  7698. if (UrlPostParmsCheck("id"))
  7699. {
  7700. //林小连
  7701. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7702. {
  7703. upd_erp_masteraftersale();
  7704. return;
  7705. }
  7706. string id = GetPostString("id");
  7707. int st = GetPostInt("afterstate");
  7708. string afmemo = GetPostString("supmemo");
  7709. string image = GetPostString("image");
  7710. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7711. if (ceErpTradeResponsible != null)
  7712. {
  7713. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7714. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7715. ceErpTradeResponsible.Update();
  7716. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7717. if (entity != null)
  7718. {
  7719. entity.AfterSaleSupplierMemo = afmemo;
  7720. entity.AfterSaleSupplierState = st;
  7721. if (st == 1)
  7722. {
  7723. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7724. if (isAll)
  7725. {
  7726. entity.AfterSaleState = 4;
  7727. entity.FinishAfterSaleTime = DateTime.Now;
  7728. }
  7729. }
  7730. else
  7731. {
  7732. CeErpTradeResponsible.dateByTid(entity.ctid);
  7733. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7734. if (ceErpTradeAfterSaleExtend != null)
  7735. {
  7736. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7737. ceErpTradeAfterSaleExtend.Update();
  7738. }
  7739. else
  7740. {
  7741. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7742. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7743. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7744. ceErpTradeAfterSaleExtend.Create();
  7745. }
  7746. //退回到主管
  7747. //entity.AfterSaleState = 2;
  7748. }
  7749. if (entity.AfterSaleState == 4)
  7750. {
  7751. ApiVo apiVo = new ApiVo();
  7752. apiVo.orderNumber = entity.ctid;
  7753. apiVo.actionName = "afterOver";
  7754. designHelper.API_WorkCore(apiVo); //afterOver
  7755. }
  7756. entity.UpdateTime = DateTime.Now;
  7757. entity.Update();
  7758. returnSuccessMsg("操作成功!");
  7759. CeErpSukuraData.createInfo(entity.ctid, 8);
  7760. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7761. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7762. return;
  7763. }
  7764. }
  7765. returnErrorMsg("找不到订单记录");
  7766. }
  7767. }
  7768. public void set_erp_supplierrefundtag()
  7769. {
  7770. if (UrlPostParmsCheck("ctid"))
  7771. {
  7772. string eid = GetPostString("ctid");
  7773. CeErpTradeCell entity = null;
  7774. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7775. if (entity != null)
  7776. {
  7777. entity.IsSupplierRefund = GetPostInt("tag");
  7778. entity.Update();
  7779. returnSuccessMsg("操作成功!");
  7780. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7781. return;
  7782. }
  7783. returnErrorMsg("找不到订单记录");
  7784. }
  7785. }
  7786. public void get_erp_refundlist()
  7787. {
  7788. DataStruct dStruct = GetPostStruct();
  7789. List<string> lw = new List<string>();
  7790. string tid = GetPostString("tid");
  7791. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7792. //string rid = GetPostString("refund_id");
  7793. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7794. string shopname = GetPostString("shopname");
  7795. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7796. string buyernick = GetPostString("buyer_nick");
  7797. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7798. string customer = GetPostString("customer");
  7799. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7800. string design = GetPostString("design");
  7801. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7802. string sellermemo = GetPostString("seller_memo");
  7803. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7804. //string date1 = GetPostString("date1");
  7805. //string date2 = GetPostString("date2");
  7806. //string dateType = GetPostString("dateType");
  7807. //if (dateType.Length > 0)
  7808. //{
  7809. // if (dateType == "1001") dateType = "0";
  7810. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7811. // if (searchDT.Count == 2)
  7812. // {
  7813. // date1 = searchDT[0].ToString();
  7814. // date2 = searchDT[1].ToString();
  7815. // }
  7816. //}
  7817. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7818. //if (dw.Length > 0) lw.Add(dw);
  7819. string redate1 = GetPostString("refunddate1");
  7820. string redate2 = GetPostString("refunddate2");
  7821. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7822. if (dwdate.Length > 0) lw.Add(dwdate);
  7823. string price1 = GetPostString("price1");
  7824. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7825. string price2 = GetPostString("price2");
  7826. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7827. string ispartrefund = GetPostString("ispartrefund");
  7828. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7829. string refundState = GetPostString("refundvstate");
  7830. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7831. int st = GetInt("st");
  7832. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7833. {
  7834. string responsible = GetPostString("responsibleman");
  7835. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7836. lw.Add(string.Format("RefundState>={0}", st));
  7837. string code = CurrentUser.UserPost.Post.Code;
  7838. if (code == "CustomerService")
  7839. {
  7840. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7841. }
  7842. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7843. {
  7844. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7845. }
  7846. else if (code == "Place" || code == "PlaceMr")
  7847. {
  7848. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7849. }
  7850. dStruct.Order = "RefundState asc,created desc";
  7851. }
  7852. else if (st == 10)
  7853. {
  7854. string responsible = GetPostString("responsibleman");
  7855. if (responsible == "空白")
  7856. {
  7857. lw.Add(string.Format("ResponsibleUserName = ''"));
  7858. }
  7859. else if (responsible.Length > 0)
  7860. {
  7861. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7862. }
  7863. lw.Add(string.Format("RefundState>=0"));
  7864. dStruct.Order = "created desc";
  7865. }
  7866. else
  7867. {
  7868. string responsible = GetPostString("responsibleman");
  7869. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7870. lw.Add(string.Format("RefundState={0}", st));
  7871. dStruct.Order = "created desc";
  7872. }
  7873. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7874. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7875. dt.Columns.Add("refund_fees");
  7876. foreach (DataRow dr in dt.Rows)
  7877. {
  7878. String status = dr["status"].ToString();
  7879. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7880. {
  7881. dr["refund_fees"] = dr["refund_fee"];
  7882. }
  7883. else
  7884. {
  7885. dr["refund_fees"] = "0.0";
  7886. }
  7887. }
  7888. writeGridDataTableJson(dStruct.TotalCount, dt);
  7889. }
  7890. public void get_erp_refunddesignlist()
  7891. {
  7892. DataStruct dStruct = GetPostStruct();
  7893. List<string> lw = new List<string>();
  7894. string tid = GetPostString("tid");
  7895. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7896. string shopname = GetPostString("shopname");
  7897. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7898. string buyernick = GetPostString("buyer_nick");
  7899. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7900. string customer = GetPostString("customer");
  7901. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7902. string design = GetPostString("design");
  7903. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7904. string sellermemo = GetPostString("seller_memo");
  7905. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7906. string redate1 = GetPostString("refunddate1");
  7907. string redate2 = GetPostString("refunddate2");
  7908. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7909. if (dwdate.Length > 0) lw.Add(dwdate);
  7910. string price1 = GetPostString("price1");
  7911. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7912. string price2 = GetPostString("price2");
  7913. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7914. string ispartrefund = GetPostString("ispartrefund");
  7915. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7916. string designerorg = GetPostString("designerorg");
  7917. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7918. string refundState = GetPostString("refundState");
  7919. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7920. int myOrgid = CurrentUser.UserPost.OrgID;
  7921. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7922. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7923. {
  7924. if (CurrentUser.User.TeamIds.Length > 0)
  7925. {
  7926. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7927. }
  7928. else
  7929. {
  7930. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7931. }
  7932. }
  7933. else if ("SysAdmin".Equals(myOrgCode))
  7934. {
  7935. }
  7936. else
  7937. {
  7938. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7939. {
  7940. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7941. }
  7942. else
  7943. {
  7944. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7945. }
  7946. }
  7947. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7948. dStruct.Order = "created desc";
  7949. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7950. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7951. dt.Columns.Add("refund_fees");
  7952. foreach (DataRow dr in dt.Rows)
  7953. {
  7954. String status = dr["status"].ToString();
  7955. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7956. {
  7957. dr["refund_fees"] = dr["refund_fee"];
  7958. }
  7959. else
  7960. {
  7961. dr["refund_fees"] = "0.0";
  7962. }
  7963. }
  7964. writeGridDataTableJson(dStruct.TotalCount, dt);
  7965. }
  7966. public void handle_erp_refundtag()
  7967. {
  7968. if (UrlPostParmsCheck("refund_id"))
  7969. {
  7970. string eid = GetPostString("refund_id");
  7971. string respMan = GetPostString("ResponsibleName");
  7972. if (respMan.Length <= 0)
  7973. {
  7974. returnErrorMsg("责任人不能为空");
  7975. return;
  7976. }
  7977. CeErpTradeRefund entity = null;
  7978. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7979. if (entity != null)
  7980. {
  7981. entity.ResponsibleUserName = respMan;
  7982. string userid = GetPostString("ResponsibleUserId");
  7983. if (userid.Length > 0)
  7984. {
  7985. entity.ResponsibleUserId = userid;
  7986. }
  7987. entity.Memo = GetPostString("Memo");
  7988. if (respMan.IndexOf("客服") != -1 ||
  7989. respMan.IndexOf("设计师") != -1 ||
  7990. respMan.IndexOf("下单员") != -1)
  7991. {
  7992. entity.RefundState = 2;
  7993. }
  7994. else
  7995. {
  7996. entity.RefundState = 3;
  7997. }
  7998. entity.modified = DateTime.Now;
  7999. entity.Update();
  8000. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8001. returnSuccessMsg("操作成功!");
  8002. return;
  8003. }
  8004. returnErrorMsg("找不到订单记录");
  8005. }
  8006. }
  8007. public void handle_erp_designrefundtag()
  8008. {
  8009. if (UrlPostParmsCheck("refund_id"))
  8010. {
  8011. string eid = GetPostString("refund_id");
  8012. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8013. if (ceErpTradeCellExtend == null)
  8014. {
  8015. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8016. ceErpTradeCellExtend.ctid = eid;
  8017. }
  8018. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8019. if (ceErpTradeCellExtend.ID > 0)
  8020. {
  8021. ceErpTradeCellExtend.Update();
  8022. }
  8023. else
  8024. {
  8025. ceErpTradeCellExtend.Create();
  8026. }
  8027. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8028. returnSuccessMsg("操作成功!");
  8029. return;
  8030. }
  8031. returnErrorMsg("找不到订单记录");
  8032. }
  8033. public void upd_erp_refundverify()
  8034. {
  8035. if (UrlPostParmsCheck("refund_id"))
  8036. {
  8037. string eid = GetPostString("refund_id");
  8038. CeErpTradeRefund entity = null;
  8039. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8040. if (entity != null)
  8041. {
  8042. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8043. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8044. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8045. {
  8046. entity.RefundState = 2;
  8047. }
  8048. else
  8049. {
  8050. entity.RefundState = 3;
  8051. }
  8052. entity.Update();
  8053. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8054. returnSuccessMsg("操作成功!");
  8055. return;
  8056. }
  8057. returnErrorMsg("找不到订单记录");
  8058. }
  8059. }
  8060. public void upd_erp_refundapprove()
  8061. {
  8062. if (UrlPostParmsCheck("refund_id"))
  8063. {
  8064. string eid = GetPostString("refund_id");
  8065. CeErpTradeRefund entity = null;
  8066. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8067. if (entity != null)
  8068. {
  8069. int apr = GetPostInt("approve");
  8070. if (apr == 0)
  8071. {
  8072. entity.RefundState = 1;
  8073. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8074. }
  8075. else if (apr == 1)
  8076. {
  8077. entity.RefundState = 3;
  8078. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8079. }
  8080. entity.modified = DateTime.Now;
  8081. entity.Update();
  8082. returnSuccessMsg("操作成功!");
  8083. return;
  8084. }
  8085. returnErrorMsg("找不到订单记录");
  8086. }
  8087. }
  8088. public void get_erp_billlist()
  8089. {
  8090. DataStruct dStruct = GetPostStruct();
  8091. List<string> lw = new List<string>();
  8092. string title = GetPostString("title");
  8093. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8094. string tid = GetPostString("tid");
  8095. string tids = GetPostString("tids");
  8096. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8097. if (tids.Length > 0)
  8098. {
  8099. tids = "'" + tids + "'";
  8100. tids = tids.Replace(",", "','");
  8101. lw.Add(string.Format("tid in ({0})", tids));
  8102. }
  8103. string shopname = GetPostString("shopname");
  8104. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8105. string buyernick = GetPostString("buyer_nick");
  8106. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8107. string customer = GetPostString("customer");
  8108. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8109. string date1 = GetPostString("date1");
  8110. string date2 = GetPostString("date2");
  8111. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8112. if (dw.Length > 0) lw.Add(dw);
  8113. string price1 = GetPostString("price1");
  8114. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8115. string price2 = GetPostString("price2");
  8116. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8117. string returndate1 = GetPostString("returndate1");
  8118. string returndate2 = GetPostString("returndate2");
  8119. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8120. if (dw1.Length > 0) lw.Add(dw1);
  8121. string billtype = GetPostString("billtype");
  8122. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8123. string billstate = GetPostString("billstate");
  8124. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8125. string usershop = CurrentUser.User.pemShop;
  8126. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8127. dStruct.Order = "createTime desc";
  8128. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8129. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8130. //foreach (DataRow dr in dt.Rows)
  8131. //{
  8132. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8133. //}
  8134. writeGridDataTableJson(dStruct.TotalCount, dt);
  8135. }
  8136. public void modify_erp_billinfo()
  8137. {
  8138. if (UrlPostParmsCheck("ID"))
  8139. {
  8140. string eid = GetPostString("ID");
  8141. CeErpBill bill_entity = null;
  8142. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8143. if (bill_entity != null)
  8144. {
  8145. bill_entity.tid = GetPostString("tid");
  8146. bill_entity.title = GetPostString("title");
  8147. bill_entity.tax = GetPostString("tax");
  8148. bill_entity.bank = GetPostString("bank");
  8149. bill_entity.bankac = GetPostString("bankac");
  8150. bill_entity.address = GetPostString("address");
  8151. bill_entity.phone = GetPostString("phone");
  8152. bill_entity.price = GetPostString("price");
  8153. bill_entity.productId = GetPostInt("ProductName");
  8154. bill_entity.num = GetPostInt("num");
  8155. bill_entity.unit = GetPostString("unit");
  8156. bill_entity.type = GetPostString("type");
  8157. bill_entity.sendType = GetPostString("SendType");
  8158. bill_entity.email = GetPostString("email");
  8159. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8160. bill_entity.shopName = GetPostString("ShopName");
  8161. bill_entity.applymemo = GetPostString("applymemo");
  8162. bill_entity.modifyTime = DateTime.Now;
  8163. bill_entity.createTime = DateTime.Now;
  8164. bill_entity.state = 0;
  8165. bill_entity.Update();
  8166. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8167. returnSuccessMsg("发票修改成功!");
  8168. return;
  8169. }
  8170. returnErrorMsg("找不到对应记录");
  8171. }
  8172. }
  8173. public void set_erp_invoicing()
  8174. {
  8175. if (UrlPostParmsCheck("id"))
  8176. {
  8177. try
  8178. {
  8179. string eid = GetPostString("id");
  8180. CeErpBill bill_entity = null;
  8181. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8182. if (bill_entity != null)
  8183. {
  8184. int ComId = GetPostInt("ComId");
  8185. //string memo = GetPostString("Memo");
  8186. int allInfo = GetPostInt("allinfo");
  8187. string clert = CurrentUser.User.Name;
  8188. //string detailValue = GetPostString("detailvalue");
  8189. string billId = bill_entity.billOrderId;
  8190. string[] billIdList = billId.Split(',');
  8191. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8192. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8193. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8194. {
  8195. billCount += 1;
  8196. }
  8197. if (billId.Length <= 0 || billIdList.Length != billCount)
  8198. {
  8199. bill_entity.billOrderId = "";
  8200. string prebill = "ltb";
  8201. for (int idx = 1; idx <= billCount; idx++)
  8202. {
  8203. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8204. string billoid = prebill + idx + dtstr;
  8205. bill_entity.billOrderId += billoid;
  8206. if (idx < billCount)
  8207. {
  8208. bill_entity.billOrderId += ",";
  8209. }
  8210. }
  8211. }
  8212. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8213. if (bill_entity.state == 5)
  8214. {
  8215. string errMsg = bill_entity.failerror;
  8216. string[] errlist = errMsg.Split('|');
  8217. string[] errTags = new string[errlist.Length];
  8218. for (int itag = 0; itag < errlist.Length; itag++)
  8219. {
  8220. if (errlist[itag].Length <= 0) continue;
  8221. errTags[itag] = errlist[itag].Split('&')[0];
  8222. }
  8223. for (int iii = 0; iii < errTags.Length; iii++)
  8224. {
  8225. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8226. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8227. if (billOrderList.Length >= erroBillOrderTag)
  8228. {
  8229. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8230. if (needModifyBillId.Length <= 19)
  8231. {
  8232. needModifyBillId = needModifyBillId + "1";
  8233. }
  8234. else
  8235. {
  8236. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8237. last = last + 1;
  8238. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8239. }
  8240. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8241. }
  8242. }
  8243. }
  8244. bool isHaveBillSucces = false;
  8245. string totalRes = "";
  8246. bill_entity.failerror = "";
  8247. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8248. {
  8249. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8250. totalRes += res;
  8251. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8252. {
  8253. isHaveBillSucces = true;
  8254. bill_entity.comId = ComId;
  8255. bill_entity.state = 1;
  8256. bill_entity.executeTime = DateTime.Now;
  8257. bill_entity.executeUser = clert;
  8258. }
  8259. else
  8260. {
  8261. bill_entity.state = 5;
  8262. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8263. }
  8264. }
  8265. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8266. bill_entity.Update();
  8267. if (isHaveBillSucces)
  8268. {
  8269. StringBuilder sql = new StringBuilder();
  8270. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8271. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8272. }
  8273. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8274. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8275. {
  8276. returnErrorMsg("开票失败");
  8277. }
  8278. else
  8279. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8280. return;
  8281. }
  8282. returnErrorMsg("找不到对应记录");
  8283. }
  8284. catch (Exception ex)
  8285. {
  8286. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8287. returnErrorMsg("操作失败");
  8288. }
  8289. }
  8290. }
  8291. public void get_erp_invoicing_back()
  8292. {
  8293. if (UrlPostParmsCheck("id"))
  8294. {
  8295. try
  8296. {
  8297. string id = GetPostString("id");
  8298. CeErpBill entiy = CeErpBill.Get(id);
  8299. if (entiy != null)
  8300. {
  8301. if (entiy.state == 0)
  8302. {
  8303. returnErrorMsg("发票还未开具");
  8304. return;
  8305. }
  8306. string[] billOrderList = entiy.billOrderId.Split(',');
  8307. int iTag = 0;
  8308. entiy.fplsh = "";
  8309. entiy.fpdm = "";
  8310. entiy.fphm = "";
  8311. foreach (string billOrderId in billOrderList)
  8312. {
  8313. iTag++;
  8314. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8315. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8316. {
  8317. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8318. try
  8319. {
  8320. Invoicing_get_response_Obj iObj = null;
  8321. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8322. if (iObj != null)
  8323. {
  8324. entiy.state = 2;
  8325. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8326. entiy.fpdm += iObj.list[0].c_fpdm;
  8327. entiy.fphm += iObj.list[0].c_fphm;
  8328. if (iTag < billOrderList.Length)
  8329. {
  8330. entiy.fplsh += ",";
  8331. entiy.fpdm += ",";
  8332. entiy.fphm += ",";
  8333. }
  8334. entiy.Update();
  8335. }
  8336. StringBuilder sql = new StringBuilder();
  8337. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8338. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8339. returnSuccessMsg("开票成功");
  8340. }
  8341. catch (Exception ex)
  8342. {
  8343. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8344. }
  8345. return;
  8346. }
  8347. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8348. {
  8349. var res_obj = new
  8350. {
  8351. data = "开票中"
  8352. };
  8353. string ro_json = JsonConvert.SerializeObject(res_obj);
  8354. returnSuccess(ro_json);
  8355. return;
  8356. }
  8357. else
  8358. {
  8359. int eidx = res.IndexOf("c_resultmsg");
  8360. int lidx = res.IndexOf("c_status");
  8361. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8362. entiy.state = 5;
  8363. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8364. entiy.Update();
  8365. returnErrorMsg("开票失败");
  8366. return;
  8367. }
  8368. }
  8369. }
  8370. }
  8371. catch (Exception ex)
  8372. {
  8373. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8374. }
  8375. return;
  8376. }
  8377. }
  8378. public void get_erp_invoicing()
  8379. {
  8380. if (UrlPostParmsCheck("id"))
  8381. {
  8382. try
  8383. {
  8384. string id = GetPostString("id");
  8385. CeErpBill entiy = CeErpBill.Get(id);
  8386. if (entiy != null)
  8387. {
  8388. if (entiy.state == 0)
  8389. {
  8390. returnErrorMsg("发票还未开具");
  8391. return;
  8392. }
  8393. if (entiy.sendType == "纸质发票")
  8394. {
  8395. if (entiy.img.Length <= 0)
  8396. {
  8397. returnErrorMsg("查无纸质发票");
  8398. return;
  8399. }
  8400. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8401. returnSuccess(returnres);
  8402. return;
  8403. }
  8404. string[] billOrderList = entiy.billOrderId.Split(',');
  8405. int iTag = 0;
  8406. string fpUrl = "";
  8407. entiy.fplsh = "";
  8408. entiy.fpdm = "";
  8409. entiy.fphm = "";
  8410. foreach (string billOrderId in billOrderList)
  8411. {
  8412. iTag++;
  8413. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8414. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8415. {
  8416. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8417. Invoicing_get_response_Obj iObj = null;
  8418. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8419. if (iObj != null)
  8420. {
  8421. //entiy.state = 2;
  8422. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8423. entiy.fpdm += iObj.list[0].c_fpdm;
  8424. entiy.fphm += iObj.list[0].c_fphm;
  8425. if (iTag < billOrderList.Length)
  8426. {
  8427. entiy.fplsh += ",";
  8428. entiy.fpdm += ",";
  8429. entiy.fphm += ",";
  8430. }
  8431. entiy.Update();
  8432. fpUrl += iObj.list[0].c_url + ",";
  8433. }
  8434. //returnSuccess(res);
  8435. StringBuilder sql = new StringBuilder();
  8436. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8437. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8438. }
  8439. else
  8440. {
  8441. int eidx = res.IndexOf("c_resultmsg");
  8442. //int lidx = res.IndexOf("c_status");
  8443. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8444. //开票失败
  8445. entiy.state = 5;
  8446. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8447. entiy.Update();
  8448. returnErrorMsg("开票失败");
  8449. return;
  8450. }
  8451. }
  8452. var returnObj = new
  8453. {
  8454. data = fpUrl
  8455. };
  8456. string ro_json = JsonConvert.SerializeObject(returnObj);
  8457. returnSuccess(ro_json);
  8458. }
  8459. }
  8460. catch (Exception ex)
  8461. {
  8462. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8463. }
  8464. return;
  8465. }
  8466. }
  8467. public void save_erp_billimg()
  8468. {
  8469. if (UrlPostParmsCheck("id"))
  8470. {
  8471. string eid = GetPostString("id");
  8472. CeErpBill bill_entity = null;
  8473. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8474. if (bill_entity != null)
  8475. {
  8476. bill_entity.img = GetPostString("img");
  8477. bill_entity.executeTime = DateTime.Now;
  8478. bill_entity.state = 2;
  8479. bill_entity.Update();
  8480. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8481. returnSuccessMsg("保存成功");
  8482. }
  8483. return;
  8484. }
  8485. }
  8486. public void upd_erp_billreturnback()
  8487. {
  8488. if (UrlPostParmsCheck("id"))
  8489. {
  8490. int eid = GetPostInt("id");
  8491. CeErpBill bill_entity = null;
  8492. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8493. if (bill_entity != null)
  8494. {
  8495. bill_entity.state = 3;
  8496. bill_entity.returnReason = GetPostString("reason");
  8497. bill_entity.Update();
  8498. returnSuccessMsg("驳回成功!");
  8499. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8500. }
  8501. return;
  8502. }
  8503. }
  8504. public void cancel_erp_bill()
  8505. {
  8506. if (UrlPostParmsCheck("id"))
  8507. {
  8508. int eid = GetPostInt("id");
  8509. int detailValue = GetPostInt("detailvalue");
  8510. CeErpBill bill_entity = null;
  8511. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8512. string cres = "";
  8513. string gres = "";
  8514. if (bill_entity != null)
  8515. {
  8516. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8517. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8518. {
  8519. int iTag = 0;
  8520. bill_entity.fplsh = "";
  8521. bill_entity.fpdm = "";
  8522. bill_entity.fphm = "";
  8523. foreach (string billOrderId in billOrderList)
  8524. {
  8525. iTag++;
  8526. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8527. if (gres.IndexOf("success") != -1)
  8528. {
  8529. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8530. Invoicing_get_response_Obj iObj = null;
  8531. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8532. if (iObj != null)
  8533. {
  8534. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8535. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8536. bill_entity.fphm += iObj.list[0].c_fphm;
  8537. if (iTag < billOrderList.Length)
  8538. {
  8539. bill_entity.fplsh += ",";
  8540. bill_entity.fpdm += ",";
  8541. bill_entity.fphm += ",";
  8542. }
  8543. bill_entity.Update();
  8544. }
  8545. }
  8546. else
  8547. {
  8548. returnErrorMsg(gres);
  8549. return;
  8550. }
  8551. }
  8552. }
  8553. if (bill_entity.sendType == "纸质发票")
  8554. {
  8555. //作废
  8556. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8557. //if (DateTime.Now.Month == extime.Month)
  8558. //{
  8559. //cres = taobaoHelper.cancel_invoicing(eid);
  8560. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8561. //{
  8562. bill_entity.state = 4;//已作废
  8563. bill_entity.Update();
  8564. returnSuccessMsg("发票已作废");
  8565. return;
  8566. //}
  8567. //else
  8568. //{
  8569. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8570. // bill_entity.Update();
  8571. // returnErrorMsg(cres);
  8572. // return;
  8573. //}
  8574. //}
  8575. //else
  8576. //{
  8577. // returnErrorMsg("纸质发票只能作废本月的发票");
  8578. // return;
  8579. //}
  8580. }
  8581. //红冲
  8582. int redTag = 0;
  8583. string[] fpdmList = bill_entity.fpdm.Split(',');
  8584. string[] fphmList = bill_entity.fphm.Split(',');
  8585. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8586. {
  8587. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8588. return;
  8589. }
  8590. foreach (string billOrderId in billOrderList)
  8591. {
  8592. redTag++;
  8593. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8594. cres += onecres;
  8595. cres += ",";
  8596. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8597. {
  8598. bill_entity.state = 4;//已作废
  8599. //bill_entity.Update();
  8600. //returnSuccessMsg("发票已红冲");
  8601. }
  8602. else if (onecres.IndexOf("重复冲红") != -1)
  8603. {
  8604. bill_entity.state = 4;//已作废
  8605. //bill_entity.Update();
  8606. //returnSuccessMsg("发票已红冲");
  8607. }
  8608. else
  8609. {
  8610. string errmsg = commonHelper.KeepChinese(onecres);
  8611. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8612. }
  8613. }
  8614. bill_entity.Update();
  8615. if (cres.IndexOf("失败") != -1)
  8616. returnErrorMsg("红冲失败");
  8617. else
  8618. returnSuccessMsg("发票已红冲");
  8619. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8620. return;
  8621. }
  8622. return;
  8623. }
  8624. }
  8625. public void del_erp_billorder()
  8626. {
  8627. if (UrlPostParmsCheck("id"))
  8628. {
  8629. string eid = GetPostString("id");
  8630. CeErpBill.Del(eid);
  8631. CeErpBill bill = CeErpBill.Get(eid);
  8632. if (bill != null)
  8633. {
  8634. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8635. }
  8636. returnSuccessMsg("删除成功");
  8637. }
  8638. }
  8639. public void finish_erp_bill()
  8640. {
  8641. if (UrlPostParmsCheck("ids"))
  8642. {
  8643. string eids = GetPostString("ids");
  8644. string[] list = eids.Split(',');
  8645. foreach (string eid in list)
  8646. {
  8647. CeErpBill bill = CeErpBill.Get(eid);
  8648. if (bill != null)
  8649. {
  8650. bill.state = 2;
  8651. bill.Update();
  8652. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8653. }
  8654. }
  8655. returnSuccessMsg("操作成功");
  8656. }
  8657. }
  8658. public void get_erp_returncash()
  8659. {
  8660. DataStruct dStruct = GetPostStruct();
  8661. List<string> lw = new List<string>();
  8662. string tid = GetPostString("tid");
  8663. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8664. string shopname = GetPostString("shopname");
  8665. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8666. string buyernick = GetPostString("buyer_nick");
  8667. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8668. string customer = GetPostString("customer");
  8669. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8670. string returndate1 = GetPostString("returndate1");
  8671. string returndate2 = GetPostString("returndate2");
  8672. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8673. if (dw.Length > 0) lw.Add(dw);
  8674. string finishDate1 = GetPostString("finishdate1");
  8675. string finishDate2 = GetPostString("finishdate2");
  8676. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8677. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8678. string returntype = GetPostString("returntype");
  8679. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8680. string returnvstate = GetPostString("returnvstate");
  8681. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8682. dStruct.Order = "created desc";
  8683. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8684. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8685. writeGridDataTableJson(dStruct.TotalCount, dt);
  8686. }
  8687. public void get_erp_staygoods()
  8688. {
  8689. DataStruct dStruct = GetPostStruct();
  8690. List<string> lw = new List<string>();
  8691. string tid = GetPostString("tid");
  8692. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8693. string shopname = GetPostString("shopname");
  8694. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8695. string wangwang = GetPostString("wangwang");
  8696. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8697. string customer = GetPostString("customer");
  8698. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8699. string returndate1 = GetPostString("returndate1");
  8700. string returndate2 = GetPostString("returndate2");
  8701. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8702. if (dw.Length > 0) lw.Add(dw);
  8703. string finishDate1 = GetPostString("finishdate1");
  8704. string finishDate2 = GetPostString("finishdate2");
  8705. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8706. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8707. string returnvstate = GetPostString("returnvstate");
  8708. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8709. string persuadetype = GetPostString("persuadetype");
  8710. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8711. string customerOrg = GetPostString("customerOrg");
  8712. if (customerOrg.Length > 0)
  8713. {
  8714. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8715. }
  8716. dStruct.Order = "creata_time desc";
  8717. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8718. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8719. writeGridDataTableJson(dStruct.TotalCount, dt);
  8720. }
  8721. public void upd_erp_staygoods()
  8722. {
  8723. if (UrlPostParmsCheck("id"))
  8724. {
  8725. int eid = GetPostInt("id");
  8726. CeErpStayGoods entity = null;
  8727. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8728. if (entity != null)
  8729. {
  8730. entity.audit_type = 1;
  8731. entity.audit_time = DateTime.Now;
  8732. entity.audit_u_id = CurrentUser.UserID;
  8733. entity.audit_u_name = CurrentUser.UserName;
  8734. entity.Update();
  8735. returnSuccessMsg("审核成功!");
  8736. return;
  8737. }
  8738. returnErrorMsg("找不到订单记录");
  8739. }
  8740. }
  8741. public void upd_erp_stayGoodsback()
  8742. {
  8743. if (UrlPostParmsCheck("id"))
  8744. {
  8745. int eid = GetPostInt("id");
  8746. CeErpStayGoods entity = null;
  8747. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8748. if (entity != null)
  8749. {
  8750. entity.audit_text = GetPostString("reason");
  8751. entity.audit_type = 2;
  8752. entity.audit_time = DateTime.Now;
  8753. entity.audit_u_id = CurrentUser.UserID;
  8754. entity.audit_u_name = CurrentUser.UserName;
  8755. entity.Update();
  8756. returnSuccessMsg("退回成功!");
  8757. return;
  8758. }
  8759. returnErrorMsg("找不到订单记录");
  8760. }
  8761. }
  8762. public void upd_erp_returncashverify()
  8763. {
  8764. if (UrlPostParmsCheck("ID"))
  8765. {
  8766. int eid = GetPostInt("ID");
  8767. CeErpReturnCash entity = null;
  8768. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8769. if (entity != null)
  8770. {
  8771. entity.cashstate = 1;
  8772. entity.verifytime = DateTime.Now;
  8773. entity.verifyuserid = CurrentUser.UserID;
  8774. entity.Update();
  8775. returnSuccessMsg("审核成功!");
  8776. return;
  8777. }
  8778. returnErrorMsg("找不到订单记录");
  8779. }
  8780. }
  8781. public void upd_all_erp_returncashverify()
  8782. {
  8783. if (UrlPostParmsCheck("ID"))
  8784. {
  8785. String[] list = GetPostString("ID").Split(',');
  8786. CeErpReturnCash entity = null;
  8787. for (int i = 0; i < list.Length; i++)
  8788. {
  8789. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8790. if (entity != null)
  8791. {
  8792. if (entity.cashstate == 1)
  8793. {
  8794. returnErrorMsg("已审核过的订单不需要在审核!");
  8795. return;
  8796. }
  8797. entity.cashstate = 1;
  8798. entity.verifytime = DateTime.Now;
  8799. entity.verifyuserid = CurrentUser.UserID;
  8800. entity.Update();
  8801. }
  8802. }
  8803. returnSuccessMsg("审核成功!");
  8804. return;
  8805. }
  8806. }
  8807. public void upd_erp_returncashback()
  8808. {
  8809. if (UrlPostParmsCheck("ID"))
  8810. {
  8811. int eid = GetPostInt("ID");
  8812. CeErpReturnCash entity = null;
  8813. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8814. if (entity != null)
  8815. {
  8816. entity.backreason = GetPostString("reason");
  8817. entity.cashstate = 2;
  8818. entity.verifytime = DateTime.Now;
  8819. entity.verifyuserid = CurrentUser.UserID;
  8820. entity.Update();
  8821. returnSuccessMsg("退回成功!");
  8822. return;
  8823. }
  8824. returnErrorMsg("找不到订单记录");
  8825. }
  8826. }
  8827. public void upd_erp_returnprice()
  8828. {
  8829. if (UrlPostParmsCheck("ID"))
  8830. {
  8831. int eid = GetPostInt("ID");
  8832. CeErpReturnCash entity = null;
  8833. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8834. if (entity != null)
  8835. {
  8836. if (entity.cashstate == 1)
  8837. {
  8838. returnErrorMsg("审核通过了不能改");
  8839. return;
  8840. }
  8841. entity.returnprice = GetPostDouble("returnprice");
  8842. entity.Update();
  8843. returnSuccessMsg("修改成功!");
  8844. return;
  8845. }
  8846. returnErrorMsg("找不到订单记录");
  8847. }
  8848. }
  8849. public void del_erp_returncash()
  8850. {
  8851. if (UrlPostParmsCheck("ID"))
  8852. {
  8853. int eid = GetPostInt("ID");
  8854. CeErpReturnCash.Del(eid);
  8855. returnSuccessMsg("操作成功");
  8856. return;
  8857. }
  8858. }
  8859. public void test_for_do_sql()
  8860. {
  8861. string sql = GetPostString("sqlstr");
  8862. if (sql.Length > 0)
  8863. {
  8864. try
  8865. {
  8866. DbHelper.DbConn.ExecuteNonQuery(sql);
  8867. var res_obj = new
  8868. {
  8869. data = "成功",
  8870. };
  8871. string ro_json = JsonConvert.SerializeObject(res_obj);
  8872. returnSuccess(ro_json);
  8873. }
  8874. catch (Exception ex)
  8875. {
  8876. var res_obj = new
  8877. {
  8878. data = ex.Message,
  8879. };
  8880. string ro_json = JsonConvert.SerializeObject(res_obj);
  8881. returnSuccess(ro_json);
  8882. }
  8883. }
  8884. }
  8885. public void get_user_info()
  8886. {
  8887. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8888. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8889. }
  8890. public void get_total_data()
  8891. {
  8892. int userId = CurrentUser.UserID;
  8893. string sql = "";
  8894. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8895. {
  8896. 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);
  8897. }
  8898. else
  8899. {
  8900. 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 " +
  8901. "(select ID from CE_ErpUser where ID = {0}) d " +
  8902. "left join " +
  8903. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8904. ") a on d.ID = a.id left join " +
  8905. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8906. ") b on a.id = b.id1 left join" +
  8907. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8908. ") c on a.id = c.id2;", userId);
  8909. }
  8910. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8911. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8912. }
  8913. public void get_date_area_total_data2()
  8914. {
  8915. int userId = CurrentUser.UserID;
  8916. string date_type = GetPostString("timetype");
  8917. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8918. string sql = "";
  8919. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8920. {
  8921. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8922. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8923. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8924. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8925. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8926. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8927. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8928. ") a on e.ID = a.id left join " +
  8929. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8930. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8931. ") b on a.id = b.id1 " +
  8932. "left join " +
  8933. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8934. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8935. ") c on a.id = c.id2 " +
  8936. "left join " +
  8937. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8938. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8939. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8940. }
  8941. else
  8942. {
  8943. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8944. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8945. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8946. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8947. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8948. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8949. ") a on e.ID = a.id left join " +
  8950. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8951. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8952. ") c on a.id = c.id2 " +
  8953. "left join " +
  8954. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8955. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8956. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8957. }
  8958. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8959. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8960. }
  8961. public void get_date_area_total_data()
  8962. {
  8963. int userId = CurrentUser.UserID;
  8964. string date_type = GetPostString("timetype");
  8965. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8966. string date1 = searchDT[0].ToString();
  8967. string date2 = searchDT[1].ToString();
  8968. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8969. {
  8970. SqlParameter[] sqlParameter ={
  8971. new SqlParameter("@userId", SqlDbType.Int,4),
  8972. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8973. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8974. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8975. };
  8976. sqlParameter[0].Value = userId;
  8977. sqlParameter[1].Value = date1;
  8978. sqlParameter[2].Value = date2;
  8979. sqlParameter[3].Direction = ParameterDirection.Output;
  8980. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8981. string res = sqlParameter[3].Value.ToString();
  8982. var res_obj = new
  8983. {
  8984. data = res
  8985. };
  8986. string ro_json = JsonConvert.SerializeObject(res_obj);
  8987. returnSuccess(ro_json);
  8988. }
  8989. else
  8990. {
  8991. SqlParameter[] sqlParameter ={
  8992. new SqlParameter("@userId", SqlDbType.Int,4),
  8993. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8994. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8995. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8996. };
  8997. sqlParameter[0].Value = userId;
  8998. sqlParameter[1].Value = date1;
  8999. sqlParameter[2].Value = date2;
  9000. sqlParameter[3].Direction = ParameterDirection.Output;
  9001. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9002. string res = sqlParameter[3].Value.ToString();
  9003. var res_obj = new
  9004. {
  9005. data = res
  9006. };
  9007. string ro_json = JsonConvert.SerializeObject(res_obj);
  9008. returnSuccess(ro_json);
  9009. }
  9010. //writeGridDataViewJson(dt.Rows.Count, dv);
  9011. }
  9012. public void get_order_list()
  9013. {
  9014. string strFields = GetPostString("paraFields");
  9015. string strOrder = GetPostString("paraOrder");
  9016. string strWhere = GetPostString("paraWhere");
  9017. string strPageSize = GetPostString("paraPageSize");
  9018. DataStruct dStruct = GetPostStruct();
  9019. dStruct.PageSize = int.Parse(strPageSize);
  9020. dStruct.Fileds = strFields;
  9021. dStruct.Order = strOrder;
  9022. dStruct.MainWhere = strWhere;
  9023. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9024. writeGridDataTableJson(dStruct.TotalCount, dt);
  9025. }
  9026. ////获取待开始订单列表
  9027. //public void get_wait_design_order_list()
  9028. //{
  9029. // string date_type = GetPostString("date_type");
  9030. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9031. // DataStruct dStruct = GetPostStruct();
  9032. // dStruct.PageSize = 1000;
  9033. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9034. // List<string> lw = new List<string>();
  9035. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9036. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9037. // dStruct.Order = "WaitDesignTime asc";
  9038. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9039. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9040. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9041. //}
  9042. //获取完成单量排名
  9043. public void get_finish_order_count_ranking()
  9044. {
  9045. /* string date_type = GetPostString("date_type");
  9046. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9047. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9048. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9049. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9050. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9051. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9052. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9053. writeGridDataTableJson(0, new DataTable());
  9054. }
  9055. public void get_finish_order_amount_ranking()
  9056. {
  9057. /*string date_type = GetPostString("date_type");
  9058. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9059. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9060. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9061. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9062. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9063. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9064. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9065. writeGridDataTableJson(0, new DataTable());
  9066. }
  9067. public void get_finish_refund_count_ranking()
  9068. {
  9069. string date_type = GetPostString("date_type");
  9070. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9071. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9072. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9073. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9074. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9075. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9076. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9077. writeGridDataTableJson(dt.Rows.Count, dt);
  9078. }
  9079. public void get_finish_refund_amount_ranking()
  9080. {
  9081. string date_type = GetPostString("date_type");
  9082. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9083. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9084. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9085. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9086. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9087. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9088. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9089. writeGridDataTableJson(dt.Rows.Count, dt);
  9090. }
  9091. public void set_erp_finishorder_director()
  9092. {
  9093. if (UrlPostParmsCheck("ctid"))
  9094. {
  9095. string eid = GetPostString("ctid");
  9096. CeErpTradeCell entity = null;
  9097. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9098. if (entity != null)
  9099. {
  9100. entity.OrderState = 8;
  9101. entity.Update();
  9102. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9103. returnSuccessMsg("操作成功!");
  9104. return;
  9105. }
  9106. returnErrorMsg("找不到记录");
  9107. }
  9108. }
  9109. public void get_erp_placeregistlist()
  9110. {
  9111. DataStruct dStruct = GetPostStruct();
  9112. List<string> lw = new List<string>();
  9113. string outsid = GetPostString("outsid");
  9114. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9115. string memo = GetPostString("memo");
  9116. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9117. string filename = GetPostString("filename");
  9118. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9119. string islate = GetPostString("islate");
  9120. if (islate.Length > 0)
  9121. {
  9122. if (islate == "1")
  9123. lw.Add(string.Format("OutLate>0"));
  9124. else
  9125. lw.Add(string.Format("OutLate=0"));
  9126. }
  9127. string placedate1 = GetPostString("placedate1");
  9128. string placedate2 = GetPostString("placedate2");
  9129. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9130. if (dw.Length > 0) lw.Add(dw);
  9131. string deliveryDate1 = GetPostString("deliverydate1");
  9132. string deliveryDate2 = GetPostString("deliverydate2");
  9133. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9134. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9135. dStruct.Order = "ID desc";
  9136. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9137. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9138. writeGridDataTableJson(dStruct.TotalCount, dt);
  9139. }
  9140. public void ins_erp_placeregist()
  9141. {
  9142. if (UrlPostParmsCheck("id"))
  9143. {
  9144. string eid = GetPostString("id");
  9145. CeErpPlaceRegister entity = null;
  9146. if (eid == "0")//新增
  9147. {
  9148. entity = new CeErpPlaceRegister();
  9149. string xdTime = GetPostString("placeTime");
  9150. if (xdTime.Length > 0)
  9151. {
  9152. entity.PlactTime = Convert.ToDateTime(xdTime);
  9153. }
  9154. string fhTime = GetPostString("deliveryTime");
  9155. if (fhTime.Length > 0)
  9156. {
  9157. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9158. }
  9159. string preTime = GetPostString("preOutTime");
  9160. if (preTime.Length > 0)
  9161. {
  9162. entity.PreOutTime = Convert.ToDateTime(preTime);
  9163. }
  9164. entity.DeliveryCount = GetPostInt("deliveryCount");
  9165. entity.ReceiveCount = GetPostInt("receiveCount");
  9166. entity.OutSid = GetPostString("outSid");
  9167. entity.FileName = GetPostString("fileName");
  9168. entity.Memo = GetPostString("memo");
  9169. entity.AddUserId = CurrentUser.UserID;
  9170. entity.CreateTime = DateTime.Now;
  9171. entity.Img = GetPostString("img");
  9172. entity.Supplier = GetPostInt("supplier");
  9173. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9174. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9175. {
  9176. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9177. DateTime dt2 = (DateTime)entity.PreOutTime;
  9178. TimeSpan span = dt1.Subtract(dt2);
  9179. if (span.Days > 0)
  9180. {
  9181. entity.OutLate = span.Days;
  9182. }
  9183. }
  9184. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9185. entity.Create();
  9186. returnSuccessMsg("添加成功!");
  9187. return;
  9188. }
  9189. else //修改
  9190. {
  9191. entity = CeErpPlaceRegister.Get(eid);
  9192. if (entity != null)
  9193. {
  9194. string xdTime = GetPostString("placeTime");
  9195. if (xdTime.Length > 0)
  9196. {
  9197. entity.PlactTime = Convert.ToDateTime(xdTime);
  9198. }
  9199. string fhTime = GetPostString("deliveryTime");
  9200. if (fhTime.Length > 0)
  9201. {
  9202. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9203. }
  9204. string preTime = GetPostString("preOutTime");
  9205. if (preTime.Length > 0)
  9206. {
  9207. entity.PreOutTime = Convert.ToDateTime(preTime);
  9208. }
  9209. entity.DeliveryCount = GetPostInt("deliveryCount");
  9210. entity.ReceiveCount = GetPostInt("receiveCount");
  9211. if (entity.DeliveryCount == entity.ReceiveCount)
  9212. {
  9213. entity.CurState = "已完成";
  9214. }
  9215. else
  9216. {
  9217. entity.CurState = "未完成";
  9218. }
  9219. entity.OutSid = GetPostString("outSid");
  9220. entity.FileName = GetPostString("fileName");
  9221. entity.Memo = GetPostString("memo");
  9222. entity.Img = GetPostString("img");
  9223. entity.Supplier = GetPostInt("supplier");
  9224. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9225. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9226. {
  9227. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9228. DateTime dt2 = (DateTime)entity.PreOutTime;
  9229. TimeSpan span = dt1.Subtract(dt2);
  9230. if (span.Days > 0)
  9231. {
  9232. entity.OutLate = span.Days;
  9233. }
  9234. }
  9235. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9236. entity.Update();
  9237. returnSuccessMsg("修改成功");
  9238. return;
  9239. }
  9240. returnErrorMsg("找不到对应的记录");
  9241. return;
  9242. }
  9243. }
  9244. returnErrorMsg("缺少必要参数");
  9245. }
  9246. public void del_erp_placeregist()
  9247. {
  9248. string eid = GetPostString("id");
  9249. CeErpPlaceRegister.Del(eid);
  9250. returnSuccessMsg("删除成功!");
  9251. return;
  9252. }
  9253. public void ins_erp_placeregistbyorder()
  9254. {
  9255. string ctid = GetPostString("ctid");
  9256. if (ctid.Length > 0)
  9257. {
  9258. StringBuilder sql = new StringBuilder();
  9259. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9260. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9261. if (dt.Rows.Count > 0)
  9262. {
  9263. foreach (DataRow dr in dt.Rows)
  9264. {
  9265. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9266. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9267. entity.AddUserId = CurrentUser.UserID;
  9268. entity.tid = dr["tid"].ToString();
  9269. entity.Did = Convert.ToString(dr["ctid"]);
  9270. entity.splitTag = dr["SplitTag"].ToString();
  9271. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9272. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9273. if (pre_ctid.Length > 0)
  9274. {
  9275. sellmemo = sellmemo.Replace(pre_ctid, "");
  9276. }
  9277. sellmemo = sellmemo.Replace("[", "");
  9278. sellmemo = sellmemo.Replace("]", "");
  9279. entity.FileName = sellmemo;
  9280. string count = dr["ProductCount"].ToString();
  9281. int usecount = commonHelper.getIntCountFromString(count);
  9282. entity.DeliveryCount = usecount;
  9283. entity.CurState = "未完成";
  9284. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9285. {
  9286. entity.Supplier = 24;//dl手提袋定制
  9287. }
  9288. else
  9289. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9290. entity.CreateTime = DateTime.Now;
  9291. entity.Create();
  9292. }
  9293. returnSuccessMsg("操作成功");
  9294. return;
  9295. }
  9296. returnErrorMsg("没有找到对应订单");
  9297. return;
  9298. }
  9299. returnErrorMsg("缺少订单编号");
  9300. return;
  9301. }
  9302. public void get_erp_persuadelist()
  9303. {
  9304. DataStruct dStruct = GetPostStruct();
  9305. List<string> lw = new List<string>();
  9306. string ctid = GetPostString("ctid");
  9307. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9308. string shopname = GetPostString("shopname");
  9309. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9310. string buyernick = GetPostString("buyer_nick");
  9311. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9312. string customer = GetPostString("customer");
  9313. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9314. string returndate1 = GetPostString("returndate1");
  9315. string returndate2 = GetPostString("returndate2");
  9316. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9317. if (dw.Length > 0) lw.Add(dw);
  9318. string finishDate1 = GetPostString("finishdate1");
  9319. string finishDate2 = GetPostString("finishdate2");
  9320. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9321. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9322. string persuadetype = GetPostString("persuadetype");
  9323. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9324. string returnvstate = GetPostString("returnvstate");
  9325. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9326. dStruct.Order = "created desc";
  9327. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9328. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9329. writeGridDataTableJson(dStruct.TotalCount, dt);
  9330. }
  9331. public void upd_erp_returnpersuadeback()
  9332. {
  9333. if (UrlPostParmsCheck("ID"))
  9334. {
  9335. int eid = GetPostInt("ID");
  9336. CeErpPersuade entity = null;
  9337. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9338. if (entity != null)
  9339. {
  9340. entity.backreason = GetPostString("reason");
  9341. entity.pstate = 2;
  9342. entity.verifytime = DateTime.Now;
  9343. entity.verifyuserid = CurrentUser.UserID;
  9344. entity.Update();
  9345. returnSuccessMsg("退回成功!");
  9346. return;
  9347. }
  9348. returnErrorMsg("找不到订单记录");
  9349. }
  9350. }
  9351. public void upd_erp_returnpersuadeverify()
  9352. {
  9353. if (UrlPostParmsCheck("ID"))
  9354. {
  9355. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9356. {
  9357. returnErrorMsg("暂无权限审核");
  9358. return;
  9359. }
  9360. int eid = GetPostInt("ID");
  9361. CeErpPersuade entity = null;
  9362. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9363. if (entity != null)
  9364. {
  9365. entity.pstate = 1;
  9366. entity.verifytime = DateTime.Now;
  9367. entity.verifyuserid = CurrentUser.UserID;
  9368. entity.Update();
  9369. returnSuccessMsg("审核成功!");
  9370. return;
  9371. }
  9372. returnErrorMsg("找不到订单记录");
  9373. }
  9374. }
  9375. public void del_erp_persuade()
  9376. {
  9377. if (UrlPostParmsCheck("ID"))
  9378. {
  9379. int eid = GetPostInt("ID");
  9380. CeErpPersuade.Del(eid);
  9381. returnSuccessMsg("操作成功");
  9382. return;
  9383. }
  9384. }
  9385. public void get_erp_oldcustoupload()
  9386. {
  9387. DataStruct dStruct = GetPostStruct();
  9388. List<string> lw = new List<string>();
  9389. string buyernick = GetPostString("buyer_nick");
  9390. if (buyernick.Length > 0)
  9391. {
  9392. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9393. }
  9394. else
  9395. return;
  9396. dStruct.Order = "pay_time desc";
  9397. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9398. DataTable dt = null;
  9399. dt = WebCache.GetData("view_erptradecell", dStruct);
  9400. writeGridDataTableJson(dStruct.TotalCount, dt);
  9401. }
  9402. public void get_erp_checkorderlist()
  9403. {
  9404. DataStruct dStruct = GetPostStruct();
  9405. List<string> lw = new List<string>();
  9406. string tid = GetPostString("ctid");
  9407. if (tid.Length > 0)
  9408. {
  9409. string select_tid = getTidByCtid(tid);
  9410. lw.Add(string.Format("tid='{0}'", select_tid));
  9411. }
  9412. string shopname = GetPostString("shopname");
  9413. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9414. string buyernick = GetPostString("buyer_nick");
  9415. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9416. string customer = GetPostString("customer");
  9417. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9418. string design = GetPostString("design");
  9419. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9420. string orderState = GetPostString("orderState");
  9421. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9422. string address = GetPostString("address");
  9423. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9424. string sellermemo = GetPostString("seller_memo");
  9425. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9426. string supplier = GetPostString("supplier");
  9427. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9428. {
  9429. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9430. }
  9431. else
  9432. {
  9433. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9434. }
  9435. string date1 = GetPostString("date1");
  9436. string date2 = GetPostString("date2");
  9437. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9438. if (dw.Length > 0) lw.Add(dw);
  9439. string placedate1 = GetPostString("placedate1");
  9440. string placedate2 = GetPostString("placedate2");
  9441. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9442. if (fdw.Length > 0) lw.Add(fdw);
  9443. string price1 = GetPostString("price1");
  9444. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9445. string price2 = GetPostString("price2");
  9446. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9447. string checkst = GetPostString("checkstate");
  9448. if (checkst.Length > 0 && "10".Equals(checkst))
  9449. {
  9450. lw.Add(string.Format("CheckOut>0"));
  9451. }
  9452. else
  9453. {
  9454. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9455. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9456. }
  9457. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9458. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9459. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9460. writeGridDataTableJson(dStruct.TotalCount, dt);
  9461. }
  9462. public void ins_erp_startCheck()
  9463. {
  9464. if (UrlPostParmsCheck("ctid"))
  9465. {
  9466. string eid = GetPostString("ctid");
  9467. CeErpTradeCell entity = null;
  9468. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9469. if (entity != null)
  9470. {
  9471. entity.MemoOpt = 4;
  9472. entity.UpdateTime = DateTime.Now;
  9473. entity.Update();
  9474. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9475. CeErpSukuraData.createInfo(entity.ctid, 6);
  9476. returnSuccessMsg("操作成功!");
  9477. return;
  9478. }
  9479. returnErrorMsg("找不到记录");
  9480. }
  9481. }
  9482. public void upd_erp_sendXlw()
  9483. {
  9484. if (UrlPostParmsCheck("ctid"))
  9485. {
  9486. string eid = GetPostString("ctid");
  9487. CeErpTradeCell entity = null;
  9488. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9489. if (entity != null)
  9490. {
  9491. if (entity.IsSendGift == 1)
  9492. {
  9493. returnErrorMsg("请勿重复标记");
  9494. return;
  9495. }
  9496. entity.IsSendGift = 1;
  9497. entity.Update();
  9498. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9499. returnSuccessMsg("操作成功!");
  9500. return;
  9501. }
  9502. returnErrorMsg("找不到记录");
  9503. }
  9504. }
  9505. public void cancel_sendXlw()
  9506. {
  9507. if (UrlPostParmsCheck("ctid"))
  9508. {
  9509. string eid = GetPostString("ctid");
  9510. CeErpTradeCell entity = null;
  9511. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9512. if (entity != null)
  9513. {
  9514. if (entity.IsSendGift == 0)
  9515. {
  9516. returnErrorMsg("未标记小礼物");
  9517. return;
  9518. }
  9519. entity.IsSendGift = 0;
  9520. entity.Update();
  9521. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9522. returnSuccessMsg("操作成功!");
  9523. return;
  9524. }
  9525. returnErrorMsg("找不到记录");
  9526. }
  9527. }
  9528. public void get_erp_designbill()
  9529. {
  9530. DataStruct dStruct = GetPostStruct();
  9531. List<string> lw = new List<string>();
  9532. int isMy = GetInt("my");
  9533. if (isMy == 1)
  9534. {
  9535. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9536. }
  9537. string tid = GetPostString("tid");
  9538. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9539. string userName = GetPostString("design");
  9540. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9541. string price1 = GetPostString("price1");
  9542. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9543. string price2 = GetPostString("price2");
  9544. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9545. string rePrice1 = GetPostString("rePrice1");
  9546. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9547. string rePrice2 = GetPostString("rePrice2");
  9548. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9549. string designerType = GetPostString("designerType");
  9550. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9551. string orderState = GetPostString("orderState");
  9552. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9553. string endTime1 = GetPostString("endTime1");
  9554. string endTime2 = GetPostString("endTime2");
  9555. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9556. if (dw.Length > 0) lw.Add(dw);
  9557. string isDk = GetPostString("isDk");
  9558. if (isDk == "1")
  9559. {
  9560. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9561. }
  9562. else if (isDk == "0")
  9563. {
  9564. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9565. }
  9566. dStruct.Order = "oid, create_time desc";
  9567. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9568. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9569. writeGridDataTableJson(dStruct.TotalCount, dt);
  9570. }
  9571. public void upd_erp_designerbill()
  9572. {
  9573. if (UrlPostParmsCheck("ID"))
  9574. {
  9575. string eid = GetPostString("ID");
  9576. CeErpDesignerBill entity = null;
  9577. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9578. if (entity != null)
  9579. {
  9580. if (GetPostDouble("designerpirce") > 0)
  9581. {
  9582. entity.realPrice = GetPostDouble("designerpirce");
  9583. entity.update_time = DateTime.Now;
  9584. entity.update_u_id = CurrentUser.UserID;
  9585. entity.update_u_name = CurrentUser.UserName;
  9586. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9587. entity.Update();
  9588. returnSuccessMsg("操作成功!");
  9589. return;
  9590. }
  9591. else
  9592. {
  9593. entity.price = GetPostDouble("price");
  9594. entity.update_time = DateTime.Now;
  9595. entity.update_u_id = CurrentUser.UserID;
  9596. entity.update_u_name = CurrentUser.UserName;
  9597. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9598. entity.Update();
  9599. returnSuccessMsg("操作成功!");
  9600. return;
  9601. }
  9602. }
  9603. returnErrorMsg("找不到记录");
  9604. }
  9605. }
  9606. public void audit_erp_designerbill()
  9607. {
  9608. if (UrlPostParmsCheck("ID"))
  9609. {
  9610. string eid = GetPostString("ID");
  9611. CeErpDesignerBill entity = null;
  9612. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9613. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9614. if (entity != null)
  9615. {
  9616. entity.realPrice = GetPostDouble("designerpirce");
  9617. entity.update_time = DateTime.Now;
  9618. entity.update_u_id = CurrentUser.UserID;
  9619. entity.update_u_name = CurrentUser.UserName;
  9620. entity.isAudit = 1;
  9621. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9622. entity.Update();
  9623. if (orderEntity != null)
  9624. {
  9625. orderEntity.IsReadTag = 3;
  9626. orderEntity.Update();
  9627. }
  9628. returnSuccessMsg("操作成功!");
  9629. return;
  9630. }
  9631. returnErrorMsg("找不到记录");
  9632. }
  9633. }
  9634. public void all_audit_erp_designerbill()
  9635. {
  9636. if (UrlPostParmsCheck("idList"))
  9637. {
  9638. string[] list = GetPostString("idList").Split(',');
  9639. CeErpDesignerBill entity = null;
  9640. for (int i = 0; i < list.Length; i++)
  9641. {
  9642. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9643. if (entity == null) return;
  9644. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9645. if (orderEntity == null) return;
  9646. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9647. entity.update_time = DateTime.Now;
  9648. entity.update_u_id = CurrentUser.UserID;
  9649. entity.update_u_name = CurrentUser.UserName;
  9650. entity.isAudit = 1;
  9651. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9652. entity.Update();
  9653. orderEntity.IsReadTag = 3;
  9654. orderEntity.Update();
  9655. }
  9656. returnSuccessMsg("操作成功!");
  9657. return;
  9658. }
  9659. }
  9660. public void get_erp_sameorders()
  9661. {
  9662. if (UrlPostParmsCheck("ctid"))
  9663. {
  9664. string eid = GetPostString("ctid");
  9665. CeErpTradeCell entity = null;
  9666. entity = CeErpTradeCell.GetByCtid(eid);
  9667. if (entity != null)
  9668. {
  9669. StringBuilder sql = new StringBuilder();
  9670. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9671. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9672. var res = new
  9673. {
  9674. data = dt.Rows.Count
  9675. };
  9676. string ro_jsond = JsonConvert.SerializeObject(res);
  9677. returnSuccess(ro_jsond);
  9678. return;
  9679. }
  9680. returnErrorMsg("未找到订单");
  9681. return;
  9682. }
  9683. returnErrorMsg("缺少必要的参数");
  9684. }
  9685. public void get_erp_islasthavesameorder()
  9686. {
  9687. if (UrlPostParmsCheck("ctid"))
  9688. {
  9689. string eid = GetPostString("ctid");
  9690. string[] ctidList = eid.Split(',');
  9691. StringBuilder sql = new StringBuilder();
  9692. string tisCtid = "";
  9693. foreach (string ctid in ctidList)
  9694. {
  9695. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9696. if (entity != null)
  9697. {
  9698. sql = new StringBuilder();
  9699. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9700. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9701. if (dth.Rows.Count > 0)
  9702. {
  9703. tisCtid += entity.ctid;
  9704. tisCtid += ",";
  9705. }
  9706. }
  9707. }
  9708. if (tisCtid.Length > 0)
  9709. {
  9710. var res = new
  9711. {
  9712. data = tisCtid
  9713. };
  9714. string ro_jsond = JsonConvert.SerializeObject(res);
  9715. returnSuccess(ro_jsond);
  9716. }
  9717. else
  9718. {
  9719. var res = new
  9720. {
  9721. data = ""
  9722. };
  9723. string ro_jsond = JsonConvert.SerializeObject(res);
  9724. returnSuccess(ro_jsond);
  9725. }
  9726. return;
  9727. }
  9728. returnErrorMsg("缺少必要的参数");
  9729. }
  9730. public void file_client_down_url()
  9731. {
  9732. if (!UrlPostParmsCheck("userId"))
  9733. {
  9734. returnErrorMsg("缺少必要的参数");
  9735. }
  9736. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9737. }
  9738. public void checkout_form_data()
  9739. {
  9740. if (!UrlPostParmsCheck("tid"))
  9741. {
  9742. returnErrorMsg("缺少必要的参数");
  9743. }
  9744. string tid = GetPostString("tid");
  9745. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9746. if (ceErpOrderFormData != null)
  9747. {
  9748. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9749. returnSuccess(ro_jsond);
  9750. return;
  9751. }
  9752. returnErrorMsg("尚未有文件!");
  9753. }
  9754. public void back_supplier_audit()
  9755. {
  9756. int userId = CurrentUser.UserID;
  9757. StringBuilder sql = new StringBuilder();
  9758. 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);
  9759. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9760. if (dt.Rows.Count > 0)
  9761. {
  9762. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9763. }
  9764. else
  9765. {
  9766. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9767. }
  9768. }
  9769. public void back_supplier_query()
  9770. {
  9771. string eid = GetPostString("ctid");
  9772. if (eid != "")
  9773. {
  9774. StringBuilder sql = new StringBuilder();
  9775. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9776. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9777. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9778. }
  9779. else
  9780. {
  9781. returnErrorMsg("找不到订单记录");
  9782. return;
  9783. }
  9784. }
  9785. public void verified_to_order()
  9786. {
  9787. int userId = CurrentUser.UserID;
  9788. StringBuilder sql = new StringBuilder();
  9789. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9790. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9791. if (dt.Rows.Count > 0)
  9792. {
  9793. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9794. }
  9795. else
  9796. {
  9797. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9798. }
  9799. }
  9800. public void upd_supplier_audit()
  9801. {
  9802. if (UrlPostParmsCheck("ctid"))
  9803. {
  9804. string eid = GetPostString("ctid");
  9805. string reason = GetPostString("returnreason");
  9806. CeErpTradeCell entity = null;
  9807. CeWithdraw withdraw = null;
  9808. withdraw = CeWithdraw.GetByTid(eid);
  9809. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9810. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9811. {
  9812. if (withdraw != null)
  9813. {
  9814. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9815. {
  9816. returnSuccessMsg("您没有权限操作!");
  9817. return;
  9818. }
  9819. else
  9820. {
  9821. if (reason.Equals("1"))
  9822. {
  9823. if (entity.OrderState == -1)
  9824. {
  9825. if (entity.FinishPlaceTime == null)
  9826. {
  9827. entity.OrderState = 2;
  9828. }
  9829. else
  9830. {
  9831. entity.OrderState = 6;
  9832. }
  9833. }
  9834. entity.Update();
  9835. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9836. if (withdraw != null)
  9837. {
  9838. withdraw.status = int.Parse(reason);
  9839. withdraw.Update();
  9840. }
  9841. returnSuccessMsg("操作成功!");
  9842. return;
  9843. }
  9844. else
  9845. {
  9846. withdraw.status = int.Parse(reason);
  9847. withdraw.acknowledgingtime = DateTime.Now;
  9848. withdraw.Update();
  9849. returnSuccessMsg("查看详细请点击线下订单查询");
  9850. return;
  9851. }
  9852. }
  9853. }
  9854. // 第一个字符是 'N'
  9855. }
  9856. if (eid[0] != 'N')
  9857. {
  9858. }
  9859. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9860. {
  9861. entity.IsVerifyToSupplier = false;
  9862. entity.IsReturn = 1;
  9863. entity.ReturnTime = DateTime.Now;
  9864. entity.ReturnReason = reason;
  9865. if (entity.OrderState == 6)
  9866. {
  9867. entity.OrderState = 5;
  9868. }
  9869. entity.Update();
  9870. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9871. if (withdraw != null)
  9872. {
  9873. withdraw.status = int.Parse(reason);
  9874. withdraw.Update();
  9875. }
  9876. returnSuccessMsg("操作成功!");
  9877. return;
  9878. }
  9879. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9880. {
  9881. ;
  9882. if (withdraw != null)
  9883. {
  9884. withdraw.status = int.Parse(reason);
  9885. withdraw.acknowledgingtime = DateTime.Now;
  9886. withdraw.Update();
  9887. returnSuccessMsg("供应商取消撤回!");
  9888. return;
  9889. }
  9890. }
  9891. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9892. {
  9893. if (entity.OrderState == -1)
  9894. {
  9895. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9896. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9897. {
  9898. returnErrorMsg("订单spu没有确认无法通过审核!");
  9899. return;
  9900. }
  9901. if (entity.FinishPlaceTime == null)
  9902. {
  9903. entity.OrderState = 2;
  9904. }
  9905. else
  9906. {
  9907. entity.OrderState = 3;
  9908. }
  9909. commonHelper.getCytPrice(entity);
  9910. }
  9911. entity.Update();
  9912. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9913. if (withdraw != null)
  9914. {
  9915. withdraw.status = int.Parse(reason);
  9916. withdraw.Update();
  9917. }
  9918. returnSuccessMsg("操作成功!");
  9919. return;
  9920. }
  9921. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9922. {
  9923. if (withdraw == null)
  9924. {
  9925. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9926. return;
  9927. }
  9928. }
  9929. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9930. {
  9931. if (withdraw != null)
  9932. {
  9933. withdraw.status = int.Parse(reason);
  9934. withdraw.acknowledgingtime = DateTime.Now;
  9935. withdraw.Update();
  9936. returnSuccessMsg("查看详细请点击线下订单查询");
  9937. return;
  9938. }
  9939. }
  9940. return;
  9941. }
  9942. }
  9943. //校验报价
  9944. public void refund_order_tip()
  9945. {
  9946. int userid = CurrentUser.UserID;
  9947. int sectionId = CurrentUser.UserPost.OrgID;
  9948. StringBuilder sql = new StringBuilder();
  9949. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9950. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9951. List<string> ids = new List<string>();
  9952. if (dth.Rows.Count > 0)
  9953. {
  9954. foreach (DataRow dr in dth.Rows)
  9955. {
  9956. ids.Add(dr["ID"].ToString());
  9957. }
  9958. try
  9959. {
  9960. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9961. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9962. }
  9963. catch (Exception ex)
  9964. {
  9965. }
  9966. }
  9967. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9968. }
  9969. public void refund_order_Design()
  9970. {
  9971. int userid = CurrentUser.UserID;
  9972. int sectionId = CurrentUser.UserPost.OrgID;
  9973. StringBuilder sql = new StringBuilder();
  9974. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9975. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9976. List<string> ids = new List<string>();
  9977. if (dth.Rows.Count > 0)
  9978. {
  9979. foreach (DataRow dr in dth.Rows)
  9980. {
  9981. ids.Add(dr["ID"].ToString());
  9982. }
  9983. try
  9984. {
  9985. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9986. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9987. }
  9988. catch (Exception ex)
  9989. {
  9990. }
  9991. }
  9992. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9993. }
  9994. public void change_order_info()
  9995. {
  9996. int userid = CurrentUser.UserID;
  9997. StringBuilder sql = new StringBuilder();
  9998. 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);
  9999. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10000. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10001. }
  10002. public void change_win_mome()
  10003. {
  10004. if (UrlPostParmsCheck("id,ctid"))
  10005. {
  10006. string id = GetPostString("id");
  10007. string ctid = GetPostString("ctid");
  10008. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10009. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10010. if (ce == null || ceErpMessageTip == null)
  10011. {
  10012. returnSuccessMsg("未找到对应的订单!");
  10013. return;
  10014. }
  10015. if (ce.OrderState >= 5)
  10016. {
  10017. returnSuccessMsg("已上传文件无法修改!");
  10018. return;
  10019. }
  10020. int type = GetPostInt("type");
  10021. string content = GetPostString("content");
  10022. if (type == 0)
  10023. {
  10024. content = content.Replace("(", "(");
  10025. content = content.Replace(")", ")");
  10026. string check = MidStrEx(content, "(", ")").Trim();
  10027. if (string.IsNullOrEmpty(check))
  10028. {
  10029. returnSuccessMsg("文件名格式不正确");
  10030. return;
  10031. }
  10032. }
  10033. ce.seller_memo = content;
  10034. ce.Update();
  10035. ceErpMessageTip.isVisit = true;
  10036. ceErpMessageTip.Update();
  10037. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10038. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10039. ApiVo apiVo = new ApiVo();
  10040. apiVo.orderNumber = ce.ctid;
  10041. apiVo.actionName = "demandDesign";
  10042. apiVo.orderRemarks = content;
  10043. apiVo.demandExamine = type + 1;
  10044. designHelper.API_WorkCore(apiVo);//demandDesign
  10045. returnSuccessMsg("修改成功!");
  10046. }
  10047. }
  10048. public static string MidStrEx(string sourse, string startstr, string endstr)
  10049. {
  10050. string result = string.Empty;
  10051. int startindex, endindex;
  10052. try
  10053. {
  10054. startindex = sourse.IndexOf(startstr);
  10055. if (startindex == -1)
  10056. return result;
  10057. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10058. endindex = tmpstr.IndexOf(endstr);
  10059. if (endindex == -1)
  10060. return result;
  10061. result = tmpstr.Remove(endindex);
  10062. }
  10063. catch (Exception ex)
  10064. {
  10065. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10066. }
  10067. return result;
  10068. }
  10069. public void refund_order_list()
  10070. {
  10071. int userid = CurrentUser.UserID;
  10072. int sectionId = CurrentUser.UserPost.OrgID;
  10073. StringBuilder sql = new StringBuilder();
  10074. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10075. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10076. DataStruct dStruct = GetPostStruct();
  10077. DataTable dt = null;
  10078. List<string> ids = new List<string>();
  10079. List<string> tids = new List<string>();
  10080. if (dth.Rows.Count > 0)
  10081. {
  10082. foreach (DataRow dr in dth.Rows)
  10083. {
  10084. tids.Add("'" + dr["tid"].ToString() + "'");
  10085. ids.Add(dr["id"].ToString());
  10086. }
  10087. try
  10088. {
  10089. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10090. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10091. List<string> lw = new List<string>();
  10092. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10093. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10094. dt = WebCache.GetData("view_orderlist", dStruct);
  10095. }
  10096. catch (Exception ex)
  10097. {
  10098. }
  10099. }
  10100. writeGridDataTableJson(dStruct.TotalCount, dt);
  10101. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10102. }
  10103. //新增
  10104. public void order_batch_downloads()
  10105. {
  10106. string ceid = GetPostString("tid");
  10107. String[] tid = ceid.Split(',');
  10108. order_batch_caiyingtong(tid);
  10109. /* (string success, string errors) = UploadFiles(tid);
  10110. returnSuccessMsg(success + errors);*/
  10111. return;
  10112. }
  10113. //报价接口
  10114. public void Get_To_Quote()
  10115. {
  10116. string ceid = GetPostString("ctid");
  10117. if (ceid != null)
  10118. {
  10119. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10120. if (entity != null)
  10121. {
  10122. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10123. {
  10124. return;
  10125. }
  10126. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10127. double price = 0;
  10128. if (cp == null)
  10129. {
  10130. JObject jsonObject12 = new JObject
  10131. {
  10132. { "UserId", "77886" },
  10133. { "Pwd", "lt666888" },
  10134. { "Filename", entity.seller_memo }
  10135. };
  10136. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10137. JObject jsonObjects1 = JObject.Parse(response1);
  10138. string ms1g = (string)jsonObjects1["msg"];
  10139. if (ms1g == "报价成功")
  10140. {
  10141. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10142. string data = (string)jsonObject1["price"];
  10143. 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 + "');";
  10144. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10145. returnSuccessMsg("获取报价成功:" + data);
  10146. price = Convert.ToDouble(data);
  10147. }
  10148. else
  10149. {
  10150. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10151. return;
  10152. }
  10153. }
  10154. String[] beizhu = entity.seller_memo.Split('-');
  10155. String chanp = "";
  10156. if (beizhu.Length > 0)
  10157. {
  10158. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10159. }
  10160. else
  10161. {
  10162. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10163. }
  10164. JObject jsonObject = new JObject
  10165. {
  10166. { "UserId", "77886" },
  10167. { "Pwd", "lt666888" },
  10168. { "Filename", chanp }
  10169. };
  10170. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10171. JObject jsonObjects = JObject.Parse(response);
  10172. string msg = (string)jsonObjects["msg"];
  10173. if (msg == "报价成功")
  10174. {
  10175. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10176. string data = (string)jsonObject1["price"];
  10177. 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 + "');";
  10178. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10179. returnSuccessMsg("获取报价成功:" + data);
  10180. price = Convert.ToDouble(data);
  10181. }
  10182. else
  10183. {
  10184. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10185. return;
  10186. }
  10187. if (price > 0)
  10188. {
  10189. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10190. if (ceErpTradeCellExtend == null)
  10191. {
  10192. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10193. ceErpTradeCellExtend.ctid = entity.ctid;
  10194. ceErpTradeCellExtend.payment_cyt = price;
  10195. ceErpTradeCellExtend.Create();
  10196. }
  10197. else
  10198. {
  10199. ceErpTradeCellExtend.payment_cyt = price;
  10200. ceErpTradeCellExtend.Update();
  10201. }
  10202. }
  10203. return;
  10204. }
  10205. }
  10206. else
  10207. {
  10208. returnErrorMsg("请至少选择一条数据");
  10209. return;
  10210. }
  10211. }
  10212. //新增
  10213. public void order_To_Supplier()
  10214. {
  10215. string ceid = GetPostString("tid");
  10216. String[] tid = ceid.Split(',');
  10217. if (tid.Length > 0)
  10218. {
  10219. try
  10220. {
  10221. for (int i = 0; i < tid.Length; i++)
  10222. {
  10223. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10224. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10225. entity.SupplierId = suid;
  10226. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10227. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10228. entity.Update();
  10229. }
  10230. }
  10231. catch (Exception ex)
  10232. {
  10233. returnErrorMsg("自动匹配供应商失败");
  10234. return;
  10235. }
  10236. }
  10237. else
  10238. {
  10239. returnErrorMsg("请至少选择一条数据");
  10240. return;
  10241. }
  10242. returnSuccessMsg("自动匹配供应商成功");
  10243. return;
  10244. }
  10245. public (string, string) UploadFiles(string[] urls)
  10246. {
  10247. string success = "";
  10248. string errors = "";
  10249. int userid = CurrentUser.UserID;
  10250. foreach (string url in urls)
  10251. {
  10252. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10253. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10254. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10255. {
  10256. JObject jsonObject = new JObject
  10257. {
  10258. { "Userid", "77886" },
  10259. { "pwd", "cyt86435015" },
  10260. { "content", base64FileContent },
  10261. { "ext", Path.GetExtension(fileName) }
  10262. };
  10263. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10264. JObject jsonObjects = JObject.Parse(response);
  10265. string msg = (string)jsonObjects["msg"];
  10266. if (msg.Equals("上传成功"))
  10267. {
  10268. success += url + " 上传成功";
  10269. }
  10270. else
  10271. {
  10272. errors += url + " 上传失败";
  10273. }
  10274. }
  10275. else
  10276. {
  10277. errors += url + " 格式出现问题";
  10278. }
  10279. }
  10280. if (urls.Length == 0)
  10281. {
  10282. return (success, errors);
  10283. }
  10284. return (success, errors);
  10285. }
  10286. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10287. {
  10288. return true; //总是接受
  10289. }
  10290. public static string HttpPost(string url, string param = null)
  10291. {
  10292. HttpWebRequest request;
  10293. //如果是发送HTTPS请求
  10294. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10295. {
  10296. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10297. request = WebRequest.Create(url) as HttpWebRequest;
  10298. request.ProtocolVersion = HttpVersion.Version10;
  10299. }
  10300. else
  10301. {
  10302. request = WebRequest.Create(url) as HttpWebRequest;
  10303. }
  10304. request.Method = "POST";
  10305. request.ContentType = "application/json";
  10306. request.Accept = "*/*";
  10307. request.Timeout = 120000;
  10308. request.AllowAutoRedirect = false;
  10309. StreamWriter requestStream = null;
  10310. WebResponse response = null;
  10311. string responseStr = null;
  10312. try
  10313. {
  10314. requestStream = new StreamWriter(request.GetRequestStream());
  10315. requestStream.Write(param);
  10316. requestStream.Close();
  10317. response = request.GetResponse();
  10318. if (response != null)
  10319. {
  10320. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10321. responseStr = reader.ReadToEnd();
  10322. reader.Close();
  10323. }
  10324. }
  10325. catch (Exception ex)
  10326. {
  10327. return ex.Message;
  10328. }
  10329. finally
  10330. {
  10331. request = null;
  10332. requestStream = null;
  10333. response = null;
  10334. }
  10335. return responseStr;
  10336. }
  10337. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10338. {
  10339. string base64FileContent;
  10340. string fileName;
  10341. using (WebClient webClient = new WebClient())
  10342. {
  10343. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10344. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10345. {
  10346. using (Stream stream = response.GetResponseStream())
  10347. {
  10348. using (MemoryStream memoryStream = new MemoryStream())
  10349. {
  10350. stream.CopyTo(memoryStream);
  10351. byte[] fileBytes = memoryStream.ToArray();
  10352. base64FileContent = Convert.ToBase64String(fileBytes);
  10353. fileName = response.Headers["Content-Disposition"];
  10354. if (!string.IsNullOrEmpty(fileName))
  10355. {
  10356. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10357. if (index >= 0)
  10358. {
  10359. fileName = fileName.Substring(index + 9).Trim('\"');
  10360. }
  10361. }
  10362. else
  10363. {
  10364. fileName = Path.GetFileName(downloadUrl);
  10365. }
  10366. }
  10367. }
  10368. }
  10369. }
  10370. return (fileName, base64FileContent);
  10371. }
  10372. //新增
  10373. public void order_batch_caiyingtong(string[] downloadUrls)
  10374. {
  10375. try
  10376. {
  10377. //遍历文件
  10378. DataStruct dStruct = GetPostStruct();
  10379. DataTable dt = null;
  10380. int userid = CurrentUser.UserID;
  10381. List<string> ids = new List<string>();//失败组
  10382. List<string> tids = new List<string>();
  10383. using (WebClient webClient = new WebClient())
  10384. {
  10385. foreach (var url in downloadUrls)
  10386. {
  10387. try
  10388. {
  10389. tids.Add("'" + url + "'");
  10390. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10391. if (entity != null)
  10392. {
  10393. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10394. if (cp == null)
  10395. {
  10396. JObject jsonObject = new JObject
  10397. {
  10398. { "Userid", "77886" },
  10399. { "pwd", "lt666888" },
  10400. { "Filename",entity.seller_memo }
  10401. };
  10402. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10403. JObject jsonObjects = JObject.Parse(response);
  10404. string msg = (string)jsonObjects["msg"];
  10405. if (msg == "报价成功")
  10406. {
  10407. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10408. DownloadAndConvertToBase64(url1);
  10409. }
  10410. else
  10411. {
  10412. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10413. }
  10414. }
  10415. else
  10416. {
  10417. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10418. JObject jsonObject = new JObject
  10419. {
  10420. { "Userid", "77886" },
  10421. { "pwd", "lt666888" },
  10422. { "Filename",chanp }
  10423. };
  10424. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10425. JObject jsonObjects = JObject.Parse(response);
  10426. string msg = (string)jsonObjects["msg"];
  10427. if (msg == "报价成功")
  10428. {
  10429. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10430. DownloadAndConvertToBase64(url1);
  10431. }
  10432. else
  10433. {
  10434. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10435. }
  10436. }
  10437. }
  10438. // 上传文件到FTP
  10439. }
  10440. catch (Exception ex)
  10441. {
  10442. Console.WriteLine($"An error occurred: {ex.Message}");
  10443. }
  10444. }
  10445. List<string> lw = new List<string>();
  10446. lw.Add(string.Format("( OrderState < 6 )"));
  10447. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10448. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10449. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10450. if (dt.Rows.Count > 0)
  10451. {
  10452. foreach (DataRow dr in dt.Rows)
  10453. {
  10454. ids.Add(dr["ctid"].ToString());
  10455. }
  10456. }
  10457. String ErrorMsgs = "";
  10458. foreach (String id in ids)
  10459. {
  10460. ErrorMsgs += id + ",";
  10461. }
  10462. if (ErrorMsgs.Length > 1)
  10463. {
  10464. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10465. }
  10466. if (ErrorMsgs.Length < 1)
  10467. {
  10468. ErrorMsgs = "上传成功";
  10469. returnSuccessMsg(ErrorMsgs);
  10470. }
  10471. else
  10472. {
  10473. returnErrorMsg("以下订单" + ErrorMsgs);
  10474. }
  10475. }
  10476. // 删除文件夹及其内容
  10477. /* Directory.Delete(localDirectory, true);*/
  10478. }
  10479. catch { }
  10480. }
  10481. public void get_center_data()
  10482. {
  10483. int userId = CurrentUser.UserID;
  10484. string postCode = CurrentUser.UserPost.Post.Code;
  10485. List<string> lw = new List<string>();
  10486. List<string> ww = new List<string>();
  10487. DateTime currentTime = DateTime.Now;
  10488. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10489. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10490. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10491. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10492. string sql = " SELECT ";
  10493. string startTime = "2023-10-01 11:22:31";
  10494. //设计
  10495. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10496. {
  10497. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10498. 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));
  10499. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10500. 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));
  10501. }
  10502. //客服
  10503. else if (postCode == "CustomerService" || postCode == "Director")
  10504. {
  10505. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10506. 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));
  10507. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10508. 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));
  10509. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10510. 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));
  10511. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10512. 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));
  10513. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10514. 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));
  10515. }
  10516. //售后
  10517. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10518. {
  10519. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10520. 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));
  10521. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10522. 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));
  10523. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10524. 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));
  10525. }
  10526. //下单部
  10527. else if (postCode == "Place" || postCode == "PlaceMr")
  10528. {
  10529. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10530. 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));
  10531. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10532. 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));
  10533. }
  10534. //车间
  10535. else if (postCode == "Supplier")
  10536. {
  10537. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10538. 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));
  10539. }
  10540. DataTable dt = new DataTable();
  10541. if (lw.Count > 0)
  10542. {
  10543. sql += string.Join(" , ", lw);
  10544. sql += " FROM ";
  10545. sql += string.Join(" , ", ww);
  10546. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10547. }
  10548. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10549. }
  10550. public void get_center_data_list()
  10551. {
  10552. int userId = CurrentUser.UserID;
  10553. string postCode = CurrentUser.UserPost.Post.Code;
  10554. string shopIds = CurrentUser.User.pemShop;
  10555. DataStruct dStruct = GetPostStruct();
  10556. List<string> lw = new List<string>();
  10557. DateTime currentTime = DateTime.Now;
  10558. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10559. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10560. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10561. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10562. string startTime = "2023-10-01 11:22:31";
  10563. int order_type = GetPostInt("order_type");
  10564. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10565. {
  10566. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10567. if (order_type == 0)
  10568. {
  10569. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10570. }
  10571. else if (order_type == 3)
  10572. {
  10573. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10574. }
  10575. else
  10576. {
  10577. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10578. }
  10579. }
  10580. //客服
  10581. if (postCode == "CustomerService" || postCode == "Director")
  10582. {
  10583. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10584. if (order_type == 0)
  10585. {
  10586. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10587. }
  10588. else if (order_type == 1)
  10589. {
  10590. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10591. }
  10592. else if (order_type == 2)
  10593. {
  10594. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10595. }
  10596. else if (order_type == 3)
  10597. {
  10598. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10599. }
  10600. else if (order_type == 4)
  10601. {
  10602. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10603. }
  10604. else
  10605. {
  10606. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10607. }
  10608. }
  10609. //售后
  10610. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10611. {
  10612. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10613. if (shopIds != "")
  10614. {
  10615. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10616. }
  10617. if (order_type == 2)
  10618. {
  10619. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10620. }
  10621. else if (order_type == 4)
  10622. {
  10623. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10624. }
  10625. else if (order_type == 5)
  10626. {
  10627. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10628. }
  10629. else
  10630. {
  10631. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10632. }
  10633. }
  10634. //下单部
  10635. if (postCode == "Place" || postCode == "PlaceMr")
  10636. {
  10637. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10638. if (shopIds != "")
  10639. {
  10640. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10641. }
  10642. else if (order_type == 1)
  10643. {
  10644. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10645. }
  10646. else if (order_type == 2)
  10647. {
  10648. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10649. }
  10650. else
  10651. {
  10652. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10653. }
  10654. }
  10655. //车间
  10656. if (postCode == "Supplier")
  10657. {
  10658. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10659. if (order_type == 5)
  10660. {
  10661. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10662. }
  10663. else
  10664. {
  10665. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10666. }
  10667. }
  10668. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10669. dStruct.Fileds = "tid,ctid";
  10670. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10671. writeGridDataTableJson(dStruct.TotalCount, dt);
  10672. }
  10673. public void aftersale_audit_master()
  10674. {
  10675. if (UrlPostParmsCheck("ctid"))
  10676. {
  10677. string ctid = GetPostString("ctid");
  10678. if (ctid.Length > 0)
  10679. {
  10680. bool result = aftersale_data_change(ctid);
  10681. if (result)
  10682. {
  10683. returnSuccessMsg("修改成功!");
  10684. return;
  10685. }
  10686. }
  10687. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10688. }
  10689. }
  10690. public void aftersale_batch_audit_master()
  10691. {
  10692. if (UrlPostParmsCheck("ctids"))
  10693. {
  10694. string ctids = GetPostString("ctids");
  10695. if (ctids.Length > 0)
  10696. {
  10697. List<string> list = new List<string>();
  10698. string[] ctid_list = ctids.Split(',');
  10699. foreach (var item in ctid_list)
  10700. {
  10701. bool result = aftersale_data_change(item);
  10702. if (!result)
  10703. {
  10704. list.Add(item);
  10705. }
  10706. }
  10707. if (list.Count > 0)
  10708. {
  10709. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10710. return;
  10711. }
  10712. returnSuccessMsg("修改成功!");
  10713. return;
  10714. }
  10715. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10716. }
  10717. }
  10718. public bool aftersale_data_change(string ctid)
  10719. {
  10720. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10721. if (ceErpTradeCell != null)
  10722. {
  10723. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10724. ceErpTradeCell.AfterSaleSupplierState = 0;
  10725. StringBuilder sql = new StringBuilder();
  10726. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10727. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10728. CeErpTradeResponsible.DelByTid(ctid, 0);
  10729. 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 == "不理赔")
  10730. {
  10731. CeErpTradeResponsible.DelByTid(ctid, 1);
  10732. ceErpTradeCell.AfterSaleSupplierState = 1;
  10733. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10734. ceErpTradeCell.AfterSaleState = 4;
  10735. }
  10736. else
  10737. {
  10738. ceErpTradeCell.AfterSaleState = 3;
  10739. }
  10740. bool needCyt = false;
  10741. if (dt != null)
  10742. {
  10743. if (dt.Rows.Count == 1)
  10744. {
  10745. bool isEnd = false;
  10746. foreach (DataRow dr in dt.Rows)
  10747. {
  10748. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10749. {
  10750. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10751. isEnd = true;
  10752. }
  10753. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10754. {
  10755. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10756. isEnd = true;
  10757. }
  10758. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10759. {
  10760. needCyt = true;
  10761. }
  10762. }
  10763. if (isEnd)
  10764. {
  10765. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10766. ceErpTradeCell.AfterSaleState = 4;
  10767. ceErpTradeCell.AfterSaleSupplierState = 1;
  10768. }
  10769. }
  10770. else
  10771. {
  10772. bool isAll = true;
  10773. foreach (DataRow dr in dt.Rows)
  10774. {
  10775. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10776. {
  10777. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10778. continue;
  10779. }
  10780. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10781. {
  10782. string path = "";
  10783. int OrgID = 0;
  10784. if (!Convert.IsDBNull(dr["OrgPath"]))
  10785. {
  10786. path = dr["OrgPath"].ToString();
  10787. }
  10788. if (!Convert.IsDBNull(dr["OrgID"]))
  10789. {
  10790. OrgID = Convert.ToInt32(dr["OrgID"]);
  10791. }
  10792. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10793. {
  10794. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10795. continue;
  10796. }
  10797. }
  10798. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10799. {
  10800. needCyt = true;
  10801. }
  10802. isAll = false;
  10803. }
  10804. if (isAll)
  10805. {
  10806. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10807. ceErpTradeCell.AfterSaleState = 4;
  10808. ceErpTradeCell.AfterSaleSupplierState = 1;
  10809. }
  10810. }
  10811. }
  10812. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10813. {
  10814. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10815. }
  10816. if (ceErpTradeCell.AfterSaleState == 4)
  10817. {
  10818. ApiVo apiVo = new ApiVo();
  10819. apiVo.orderNumber = ceErpTradeCell.ctid;
  10820. apiVo.actionName = "afterOver";
  10821. designHelper.API_WorkCore(apiVo); //afterOver
  10822. }
  10823. ceErpTradeCell.Update();
  10824. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10825. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10826. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10827. return true;
  10828. }
  10829. return false;
  10830. }
  10831. public void get_erp_wechatorder()
  10832. {
  10833. DataStruct dStruct = GetPostStruct();
  10834. List<string> lw = new List<string>();
  10835. string tid = GetPostString("tid");
  10836. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10837. string shopname = GetPostString("shopname");
  10838. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10839. string buyernick = GetPostString("buyer_nick");
  10840. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10841. string customer = GetPostString("customer");
  10842. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10843. string returndate1 = GetPostString("returndate1");
  10844. string returndate2 = GetPostString("returndate2");
  10845. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10846. if (dw.Length > 0) lw.Add(dw);
  10847. string finishDate1 = GetPostString("finishdate1");
  10848. string finishDate2 = GetPostString("finishdate2");
  10849. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10850. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10851. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10852. dStruct.Order = "created desc";
  10853. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10854. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10855. writeGridDataTableJson(dStruct.TotalCount, dt);
  10856. }
  10857. public void get_erp_wechatlist_sumprice()
  10858. {
  10859. DataStruct dStruct = GetPostStruct();
  10860. List<string> lw = new List<string>();
  10861. string tid = GetPostString("tid");
  10862. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10863. string shopname = GetPostString("shopname");
  10864. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10865. string buyernick = GetPostString("buyer_nick");
  10866. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10867. string customer = GetPostString("customer");
  10868. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10869. string returndate1 = GetPostString("returndate1");
  10870. string returndate2 = GetPostString("returndate2");
  10871. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10872. if (dw.Length > 0) lw.Add(dw);
  10873. string finishDate1 = GetPostString("finishdate1");
  10874. string finishDate2 = GetPostString("finishdate2");
  10875. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10876. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10877. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10878. string mainWhere = string.Join(" and ", lw.ToArray());
  10879. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10880. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10881. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10882. decimal total = 0;
  10883. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10884. {
  10885. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10886. }
  10887. var res = new
  10888. {
  10889. data = total
  10890. };
  10891. string ro_jsond = JsonConvert.SerializeObject(res);
  10892. returnSuccess(ro_jsond);
  10893. return;
  10894. }
  10895. public void get_erp_qr_waitdeliverylist()
  10896. {
  10897. DataStruct dStruct = GetPostStruct();
  10898. List<string> lw = new List<string>();
  10899. string tid = GetPostString("ctid");
  10900. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10901. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10902. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10903. var res_objz = new
  10904. {
  10905. restype = 1,
  10906. data = dt
  10907. };
  10908. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10909. returnSuccess(ro_jsonz);
  10910. }
  10911. public void get_erp_yield_list()
  10912. {
  10913. DataStruct dStruct = GetPostStruct();
  10914. List<string> lw = new List<string>();
  10915. string tid = GetPostString("ctid");
  10916. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10917. string shopname = GetPostString("shopname");
  10918. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10919. string buyernick = GetPostString("buyer_nick");
  10920. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10921. //if (tid.Length == 0 && buyernick.Length == 0)
  10922. //{
  10923. // lw.Add(string.Format("IsRefund<={0}", 1));
  10924. //}
  10925. string customer = GetPostString("customer");
  10926. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10927. string design = GetPostString("design");
  10928. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10929. string orderState = GetPostString("orderState");
  10930. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10931. string address = GetPostString("address");
  10932. 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));
  10933. string sellermemo = GetPostString("seller_memo");
  10934. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10935. string supplier = GetPostString("supplier");
  10936. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10937. string OrderArea = GetPostString("order_area");
  10938. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10939. string placedate1 = GetPostString("placedate1");
  10940. string placedate2 = GetPostString("placedate2");
  10941. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10942. if (fdw.Length > 0) lw.Add(fdw);
  10943. string price1 = GetPostString("price1");
  10944. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10945. string price2 = GetPostString("price2");
  10946. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10947. string unusualCon = GetPostString("unusualcon");
  10948. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10949. string posTag = CurrentUser.UserPost.Post.Code;
  10950. if (posTag == "Supplier")
  10951. {
  10952. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10953. }
  10954. lw.Add(string.Format("OrderState = 6 "));
  10955. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10956. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10957. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10958. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10959. writeGridDataTableJson(dStruct.TotalCount, dt);
  10960. }
  10961. public void change_erp_sup_state()
  10962. {
  10963. if (UrlPostParmsCheck("ctid"))
  10964. {
  10965. string ctid = GetPostString("ctid");
  10966. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10967. if (ceErpTradeCell != null)
  10968. {
  10969. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10970. if (ceErpTradeCellExtend == null)
  10971. {
  10972. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10973. ceErpTradeCellExtend.ctid = ctid;
  10974. ceErpTradeCellExtend.SupState = 1;
  10975. ceErpTradeCellExtend.Create();
  10976. }
  10977. else
  10978. {
  10979. ceErpTradeCellExtend.SupState = 1;
  10980. ceErpTradeCellExtend.Update();
  10981. }
  10982. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10983. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10984. return;
  10985. }
  10986. returnErrorMsg("找不到订单");
  10987. }
  10988. }
  10989. public void supplier_all_downs()
  10990. {
  10991. if (UrlPostParmsCheck("tids"))
  10992. {
  10993. string tids = GetPostString("tids");
  10994. if (tids != null && tids.Length > 0)
  10995. {
  10996. StringBuilder sql = new StringBuilder();
  10997. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10998. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10999. sql = new StringBuilder();
  11000. 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, "下载设计文件");
  11001. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11002. string[] list = tids.Split(',');
  11003. foreach (string ctid in list)
  11004. {
  11005. CeErpSukuraData.createInfo(ctid, 3);
  11006. }
  11007. designHelper.api_approveDesign(tids); //approveDesign
  11008. returnSuccessMsg("下载成功!");
  11009. return;
  11010. }
  11011. returnErrorMsg("下载订单更新失败");
  11012. }
  11013. }
  11014. public void uploaderFileSuccess()
  11015. {
  11016. if (UrlPostParmsCheck("fileName"))
  11017. {
  11018. string fileName = GetPostString("fileName");
  11019. ApiVo apiVo = new ApiVo();
  11020. apiVo.orderNumber = fileName;
  11021. apiVo.actionName = "finishDesign";
  11022. designHelper.API_WorkCore(apiVo);//finishDesign
  11023. returnSuccessMsg("");
  11024. }
  11025. }
  11026. public void get_sample2_order()
  11027. {
  11028. if (UrlPostParmsCheck("ctid"))
  11029. {
  11030. string ctid = GetPostString("ctid");
  11031. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11032. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11033. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11034. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11035. double total = 0.0;
  11036. double order_price = 0.0;
  11037. if (dt_bu.Rows.Count > 0)
  11038. {
  11039. foreach (DataRow dr in dt_bu.Rows)
  11040. {
  11041. total += Convert.ToDouble(dr["payment"]);
  11042. }
  11043. }
  11044. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11045. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11046. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11047. string tid = ctid.Replace("S_", "");
  11048. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11049. double paymant = 0.0;
  11050. if (entity != null)
  11051. {
  11052. paymant = entity.payment;
  11053. }
  11054. string return_reason = "";
  11055. if (dt_after != null && dt_after.Rows.Count > 0)
  11056. {
  11057. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11058. }
  11059. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11060. }
  11061. }
  11062. public void get_erp_design_status()
  11063. {
  11064. string designName = GetPostString("designName");
  11065. DataStruct dStruct = GetPostStruct();
  11066. if (designName.Length > 0)
  11067. {
  11068. 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";
  11069. sql_user += " and Name like '%" + designName + "%'";
  11070. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11071. List<string> ids_list = new List<string>();
  11072. if (user_table.Rows.Count > 0)
  11073. {
  11074. foreach (DataRow item in user_table.Rows)
  11075. {
  11076. ids_list.Add(item["id"].ToString());
  11077. string ids_s = item["TeamIds"].ToString();
  11078. if (ids_s.Length > 0)
  11079. {
  11080. ids_list.AddRange(ids_s.Split(','));
  11081. }
  11082. }
  11083. }
  11084. HashSet<string> set = new HashSet<string>(ids_list);
  11085. ids_list = set.ToList();
  11086. if (ids_list.Count > 0)
  11087. {
  11088. 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));
  11089. dStruct.MainWhere = sql;
  11090. DataTable dt = null;
  11091. dt = WebCache.GetData("view_ErpUser", dStruct);
  11092. writeGridDataTableJson(dStruct.TotalCount, dt);
  11093. }
  11094. }
  11095. }
  11096. public void change_erp_order_price()
  11097. {
  11098. string ctid = GetPostString("ctid");
  11099. double price = GetPostDouble("price");
  11100. if (ctid.Length > 0)
  11101. {
  11102. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11103. if (ceErpTradeCellExtend == null)
  11104. {
  11105. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11106. ceErpTradeCellExtend.ctid = ctid;
  11107. ceErpTradeCellExtend.payment_cyt = price;
  11108. ceErpTradeCellExtend.Create();
  11109. }
  11110. else
  11111. {
  11112. ceErpTradeCellExtend.payment_cyt = price;
  11113. ceErpTradeCellExtend.Update();
  11114. }
  11115. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11116. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11117. {
  11118. ceErpDataSendOrderInfo.isSync = false;
  11119. ceErpDataSendOrderInfo.Update();
  11120. }
  11121. if (ceErpDataSendOrderInfo == null)
  11122. {
  11123. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11124. ceErpDataSendOrderInfo.isSync = false;
  11125. ceErpDataSendOrderInfo.ctid = ctid;
  11126. ceErpDataSendOrderInfo.Create();
  11127. }
  11128. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11129. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11130. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11131. if (dth != null && dth.Rows.Count > 0)
  11132. {
  11133. dataSendOrderBean dataSendOrderBean = null;
  11134. foreach (DataRow item in dth.Rows)
  11135. {
  11136. try
  11137. {
  11138. dataSendOrderBean = new dataSendOrderBean();
  11139. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11140. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11141. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11142. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11143. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11144. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11145. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11146. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11147. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11148. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11149. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11150. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11151. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11152. if (result != null)
  11153. {
  11154. if ("0".Equals(result.errcode))
  11155. {
  11156. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11157. }
  11158. else
  11159. {
  11160. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11161. }
  11162. }
  11163. }
  11164. catch (Exception ex)
  11165. {
  11166. }
  11167. }
  11168. }
  11169. returnSuccessMsg("修改成功!");
  11170. return;
  11171. }
  11172. returnErrorMsg("找不到订单");
  11173. }
  11174. public void find_he_together()
  11175. {
  11176. string ctid = GetPostString("ctid");
  11177. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11178. List<string> list = new List<string>();
  11179. if (ceErpTradeCell != null)
  11180. {
  11181. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11182. {
  11183. 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);
  11184. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11185. if (table != null && table.Rows.Count > 0)
  11186. {
  11187. foreach (TableRow row in table.Rows)
  11188. {
  11189. }
  11190. }
  11191. }
  11192. }
  11193. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11194. }
  11195. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11196. {
  11197. //chy----19
  11198. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11199. //GD-CYT-----64
  11200. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11201. //ZHX----3
  11202. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11203. //JK----97
  11204. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11205. //ZT----70
  11206. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11207. //LHCY-----98
  11208. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11209. //XD-----90
  11210. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11211. //CYCY-----14
  11212. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11213. };
  11214. //其他改名
  11215. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11216. {
  11217. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11218. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11219. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11220. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11221. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11222. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11223. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11224. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11225. };
  11226. //不统计
  11227. List<int> no_suppliers = new List<int>()
  11228. {
  11229. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11230. };
  11231. //配件单
  11232. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11233. {
  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. {"牙签",new List<string>(){ "不干胶" } }
  11241. };
  11242. public void get_place_order_data()
  11243. {
  11244. string date1 = GetPostString("date1");
  11245. string date2 = GetPostString("date2");
  11246. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11247. DateTime start = DateTime.Parse(starttime);
  11248. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11249. DateTime end = DateTime.Parse(endtime);
  11250. if (date1 != null && date1.Length > 0)
  11251. {
  11252. DateTime dateTime = DateTime.Parse(date1);
  11253. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11254. start = DateTime.Parse(starttime);
  11255. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11256. end = DateTime.Parse(endtime);
  11257. }
  11258. if (date2 != null && date2.Length > 0)
  11259. {
  11260. DateTime dateTime = DateTime.Parse(date2);
  11261. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11262. end = DateTime.Parse(endtime);
  11263. }
  11264. 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);
  11265. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11266. //不干胶-----1,卡片-----29
  11267. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11268. foreach (DataRow row in data.Rows)
  11269. {
  11270. int productId = Convert.ToInt32(row["ProductId"]);
  11271. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11272. if (no_suppliers.Contains(supplierId))
  11273. {
  11274. continue;
  11275. }
  11276. string seller_memo = row["seller_memo"].ToString();
  11277. bool ispj = false;//是否配件单
  11278. bool isfirst = true;//第一个配
  11279. maps.Keys.ForEach(key =>
  11280. {
  11281. //备注包含配件
  11282. if (seller_memo.Contains(key) && isfirst)
  11283. {
  11284. List<string> list = maps[key];
  11285. ispj = true;
  11286. isfirst = false;
  11287. for (int i = 0; i < list.Count; i++)
  11288. {
  11289. if (seller_memo.Contains(list[i]))
  11290. {
  11291. ispj = false;
  11292. break;
  11293. }
  11294. }
  11295. }
  11296. });
  11297. if (ispj)
  11298. {
  11299. continue;
  11300. }
  11301. seller_memo = seller_memo.Replace("UV", "uv");
  11302. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11303. //吊牌归到卡片
  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. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11313. string map_key = "";
  11314. string type = "";
  11315. if (supplierMap.ContainsKey(supplierId))
  11316. {
  11317. foreach (var kvp in supplierMap[supplierId])
  11318. {
  11319. if (seller_memo.Contains(kvp.Key))
  11320. {
  11321. map_key = kvp.Value;
  11322. type = kvp.Value;
  11323. break;
  11324. }
  11325. }
  11326. }
  11327. if (map_key == "")
  11328. {
  11329. type = "其他";
  11330. map_key = "其他";
  11331. }
  11332. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11333. {
  11334. map_key = suppliers[supplierId];
  11335. }
  11336. if (supplierId == 70)
  11337. {
  11338. supplierId = 70;
  11339. }
  11340. map_key += "_" + row["SupplierName"].ToString();
  11341. Dictionary<string, int> map = null;
  11342. if (other_map.ContainsKey(map_key))
  11343. {
  11344. other_map.TryGetValue(map_key, out map);
  11345. }
  11346. else
  11347. {
  11348. map = new Dictionary<string, int>();
  11349. map.Add("dayDev", 0);//当天出货
  11350. map.Add("dayTotal", 0);//下单总数
  11351. map.Add("payTotal", 0);//500以上
  11352. map.Add("today", 0);//当天出货数量
  11353. map.Add("unusua", 0);//异常数
  11354. other_map.Add(map_key, map);
  11355. other_map.TryGetValue(map_key, out map);
  11356. }
  11357. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11358. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11359. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11360. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11361. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11362. {
  11363. map["dayTotal"]++;
  11364. if (supplierId == 97)
  11365. {
  11366. supplierId = 97;
  11367. }
  11368. }
  11369. if (Convert.ToDecimal(row["payment"]) >= 500)
  11370. {
  11371. map["payTotal"]++;
  11372. }
  11373. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11374. {
  11375. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11376. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11377. {
  11378. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11379. {
  11380. map["today"]++;
  11381. }
  11382. }
  11383. else
  11384. {
  11385. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11386. {
  11387. map["today"]++;
  11388. }
  11389. else
  11390. {
  11391. if (supplierId == 119)
  11392. {
  11393. Debug.WriteLine(row["seller_memo"].ToString());
  11394. }
  11395. }
  11396. }
  11397. }
  11398. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11399. {
  11400. map["unusua"]++;
  11401. }
  11402. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11403. //GD-CYT-----64
  11404. DateTime two = palceTimeStart.AddHours(14);
  11405. DateTime three = palceTimeStart.AddHours(15);
  11406. DateTime four = palceTimeStart.AddHours(16);
  11407. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11408. {
  11409. //下午四点前 500-1000
  11410. string count = row["ProductCount"].ToString();
  11411. if (count != null && count.Length > 0)
  11412. {
  11413. int productCount = commonHelper.getPlaceProductCount(count);
  11414. if (productCount >= 500 && productCount <= 1000)
  11415. {
  11416. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11417. {
  11418. map["dayDev"]++;
  11419. }
  11420. }
  11421. }
  11422. }
  11423. //UV
  11424. else if ("uv".Equals(type))
  11425. {
  11426. //ZT----70
  11427. //ZHX----3
  11428. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11429. {
  11430. map["dayDev"]++;
  11431. }
  11432. //JK----97
  11433. //HZX----105
  11434. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11435. {
  11436. map["dayDev"]++;
  11437. if (supplierId == 97)
  11438. {
  11439. supplierId = 97;
  11440. }
  11441. }
  11442. }
  11443. //帆布---52|条幅---27
  11444. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11445. {
  11446. //LHCY-----98
  11447. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11448. {
  11449. map["dayDev"]++;
  11450. }
  11451. }
  11452. //条幅
  11453. else if ("条幅".Equals(type))
  11454. {
  11455. //XD-----90
  11456. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11457. {
  11458. map["dayDev"]++;
  11459. }
  11460. }
  11461. //桌布
  11462. else if ("桌布".Equals(type))
  11463. {
  11464. //XD-----90
  11465. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11466. {
  11467. map["dayDev"]++;
  11468. }
  11469. }
  11470. //DL---10
  11471. //AYTW---119
  11472. //FS-CYT-DY ----80
  11473. //JK----97
  11474. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11475. {
  11476. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11477. {
  11478. map["dayDev"]++;
  11479. }
  11480. }
  11481. }
  11482. DataTable dt = new DataTable();
  11483. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11484. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11485. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11486. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11487. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11488. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11489. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11490. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11491. other_map.Keys.ForEach(key =>
  11492. {
  11493. DataRow dr = dt.NewRow();
  11494. Dictionary<string, int> map = other_map[key];
  11495. string[] key_list = key.Split('_');
  11496. dr[0] = key_list[0];
  11497. dr[1] = key_list[1];
  11498. if (key_list.Length > 2)
  11499. {
  11500. dr[1] += "(" + key_list[2] + ")";
  11501. }
  11502. dr[2] = map["dayTotal"];
  11503. dr[3] = map["payTotal"];
  11504. dr[4] = map["today"];
  11505. dr[5] = map["unusua"];
  11506. dr[6] = map["dayDev"];
  11507. double rate = 0.00;
  11508. if (map["dayDev"] > 0)
  11509. {
  11510. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11511. }
  11512. dr[7] = rate.ToString();
  11513. dt.Rows.Add(dr);
  11514. });
  11515. DataView dv = new DataView(dt);
  11516. dv.Sort = "SupplierName";
  11517. //dv.Sort = "AllOrder desc";
  11518. DataTable dtNew = dv.ToTable();
  11519. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11520. }
  11521. public void check_order_desing_info()
  11522. {
  11523. string ctid = GetPostString("ctid");
  11524. if (!string.IsNullOrEmpty(ctid))
  11525. {
  11526. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11527. if (ceErpTradeCell != null)
  11528. {
  11529. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11530. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11531. return;
  11532. }
  11533. returnErrorMsg("找不到订单");
  11534. return;
  11535. }
  11536. returnErrorMsg("找不到订单");
  11537. }
  11538. public void get_timeout_detail()
  11539. {
  11540. string poscode = CurrentUser.UserPost.Post.Code;
  11541. DataStruct dStruct = GetPostStruct();
  11542. List<string> lw = new List<string>();
  11543. string id = GetPostString("id");
  11544. string pay_date1 = GetPostString("pay_date1");
  11545. string pay_date2 = GetPostString("pay_date2");
  11546. int type = GetPostInt("type");
  11547. if (type == 0)
  11548. {
  11549. if (pay_date1.Length > 0)
  11550. {
  11551. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11552. }
  11553. if (pay_date2.Length > 0)
  11554. {
  11555. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11556. }
  11557. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11558. }
  11559. if (type == 1)
  11560. {
  11561. if (pay_date1.Length > 0)
  11562. {
  11563. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11564. }
  11565. if (pay_date2.Length > 0)
  11566. {
  11567. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11568. }
  11569. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11570. }
  11571. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11572. DataTable dt = null;
  11573. dt = WebCache.GetData("view_orderlist", dStruct);
  11574. writeGridDataTableJson(dStruct.TotalCount, dt);
  11575. }
  11576. public void saveUrgentChargePrice()
  11577. {
  11578. string ctid = GetPostString("ctid");
  11579. if (!string.IsNullOrEmpty(ctid))
  11580. {
  11581. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11582. if (ceErpTradeCell != null)
  11583. {
  11584. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11585. if (prices <= 100)
  11586. {
  11587. returnErrorMsg("此订单金额不足100元,无法加急。");
  11588. return;
  11589. }
  11590. double price = GetPostDouble("price");
  11591. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11592. if (ceErpTradeCellExtend == null)
  11593. {
  11594. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11595. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11596. }
  11597. ceErpTradeCellExtend.urgentCharge = price;
  11598. if (ceErpTradeCellExtend.ID > 0)
  11599. {
  11600. ceErpTradeCellExtend.Update();
  11601. }
  11602. else
  11603. {
  11604. ceErpTradeCellExtend.Save();
  11605. }
  11606. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11607. returnSuccessMsg("修改成功!");
  11608. return;
  11609. }
  11610. returnErrorMsg("找不到订单");
  11611. return;
  11612. }
  11613. returnErrorMsg("找不到订单");
  11614. }
  11615. public void finish_erp_order()
  11616. {
  11617. string ctid = GetPostString("ctid");
  11618. if (!string.IsNullOrEmpty(ctid))
  11619. {
  11620. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11621. {
  11622. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11623. if (ceErpTradeCell != null)
  11624. {
  11625. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11626. ceErpTradeCell.Update();
  11627. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11628. returnSuccessMsg("修改成功!");
  11629. return;
  11630. }
  11631. }
  11632. }
  11633. returnErrorMsg("找不到订单");
  11634. }
  11635. public void get_trade_order_list()
  11636. {
  11637. string tid = GetPostString("tid");
  11638. if (!string.IsNullOrEmpty(tid))
  11639. {
  11640. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11641. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11642. writeGridDataTableJson(data.Rows.Count, data);
  11643. return;
  11644. }
  11645. returnErrorMsg("找不到订单");
  11646. }
  11647. public void save_cell_spu()
  11648. {
  11649. string ctid = GetPostString("ctid");
  11650. string spu_id = GetPostString("spu_id");
  11651. if (!string.IsNullOrEmpty(ctid))
  11652. {
  11653. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11654. if (ceErpTradeCellExtend == null)
  11655. {
  11656. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11657. ceErpTradeCellExtend.ctid = ctid;
  11658. }
  11659. ceErpTradeCellExtend.spu_id = spu_id;
  11660. if (!string.IsNullOrEmpty(spu_id))
  11661. {
  11662. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11663. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  11664. ceErpTradeCellExtend.ToType = result;
  11665. if (commonHelper.spu_products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  11666. {
  11667. ceErpTradeCellExtend.ToType = "外协";
  11668. }
  11669. if ((ceErpTradeCell.seller_memo.Contains("改稿") || ceErpTradeCell.OtherMemo.Contains("改稿")) && commonHelper.spu_shopIds.Contains(ceErpTradeCell.ShopId) && !commonHelper.spu_oldProducts.Contains(ceErpTradeCell.ProductId))
  11670. {
  11671. ceErpTradeCellExtend.ToType = "内部";
  11672. }
  11673. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  11674. {
  11675. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  11676. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  11677. }
  11678. }
  11679. if (ceErpTradeCellExtend.ID == 0)
  11680. {
  11681. ceErpTradeCellExtend.Create();
  11682. }
  11683. else
  11684. {
  11685. ceErpTradeCellExtend.Update();
  11686. }
  11687. returnSuccessMsg("修改成功!");
  11688. return;
  11689. }
  11690. returnErrorMsg("找不到订单");
  11691. }
  11692. public void change_express_info()
  11693. {
  11694. string ctid = GetPostString("ctid");
  11695. string transNo = GetPostString("transNo");
  11696. string transCom = GetPostString("transCom");
  11697. if (!string.IsNullOrEmpty(ctid))
  11698. {
  11699. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11700. if (ceErpTradeCellExtend == null)
  11701. {
  11702. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11703. ceErpTradeCellExtend.ctid = ctid;
  11704. }
  11705. ceErpTradeCellExtend.modExpressNo = transNo;
  11706. ceErpTradeCellExtend.modExpressCom = transCom;
  11707. ceErpTradeCellExtend.readMod = 2;
  11708. if (ceErpTradeCellExtend.ID == 0)
  11709. {
  11710. ceErpTradeCellExtend.Create();
  11711. }
  11712. else
  11713. {
  11714. ceErpTradeCellExtend.Update();
  11715. }
  11716. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11717. returnSuccessMsg("修改成功!");
  11718. return;
  11719. }
  11720. returnErrorMsg("找不到订单");
  11721. }
  11722. public void get_change_express_list()
  11723. {
  11724. DataStruct dStruct = GetPostStruct();
  11725. List<string> lw = new List<string>();
  11726. int st = 2;
  11727. string tid = GetPostString("ctid");
  11728. if (tid.Length > 0)
  11729. {
  11730. string select_tid = getTidByCtid(tid);
  11731. lw.Add(string.Format("tid='{0}'", select_tid));
  11732. }
  11733. string shopname = GetPostString("shopname");
  11734. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11735. string buyernick = GetPostString("buyer_nick");
  11736. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11737. string sellermemo = GetPostString("seller_memo");
  11738. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11739. string supplier = GetPostString("supplier");
  11740. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11741. string customer = GetPostString("customer");
  11742. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11743. string design = GetPostString("design");
  11744. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11745. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11746. string poscode = CurrentUser.UserPost.Post.Code;
  11747. if (poscode != "SysAdmin")
  11748. {
  11749. string shopid = CurrentUser.User.pemShop;
  11750. lw.Add(string.Format("shopId in ({0})", shopid));
  11751. }
  11752. lw.Add("readMod = 2");
  11753. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11754. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11755. writeGridDataTableJson(dStruct.TotalCount, dt);
  11756. }
  11757. public void deal_express_complete()
  11758. {
  11759. string ctid = GetPostString("ctid");
  11760. if (!string.IsNullOrEmpty(ctid))
  11761. {
  11762. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11763. if (ceErpTradeCellExtend == null)
  11764. {
  11765. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11766. ceErpTradeCellExtend.ctid = ctid;
  11767. }
  11768. ceErpTradeCellExtend.readMod = 1;
  11769. if (ceErpTradeCellExtend.ID == 0)
  11770. {
  11771. ceErpTradeCellExtend.Create();
  11772. }
  11773. else
  11774. {
  11775. ceErpTradeCellExtend.Update();
  11776. }
  11777. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11778. returnSuccessMsg("修改成功!");
  11779. return;
  11780. }
  11781. returnErrorMsg("找不到订单");
  11782. }
  11783. public void aftersale_return_visit()
  11784. {
  11785. string ctid = GetPostString("ctid");
  11786. if (!string.IsNullOrEmpty(ctid))
  11787. {
  11788. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11789. if (ceErpTradeCellExtend == null)
  11790. {
  11791. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11792. ceErpTradeCellExtend.ctid = ctid;
  11793. }
  11794. ceErpTradeCellExtend.returnVisit = 1;
  11795. if (ceErpTradeCellExtend.ID == 0)
  11796. {
  11797. ceErpTradeCellExtend.Create();
  11798. }
  11799. else
  11800. {
  11801. ceErpTradeCellExtend.Update();
  11802. }
  11803. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11804. if (ceErpTradeAfterSaleExtend != null)
  11805. {
  11806. ceErpTradeAfterSaleExtend.TextResult = "";
  11807. ceErpTradeAfterSaleExtend.Update();
  11808. }
  11809. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11810. returnSuccessMsg("修改成功!");
  11811. return;
  11812. }
  11813. returnErrorMsg("找不到订单");
  11814. }
  11815. public void orderPlaceInfo()
  11816. {
  11817. string ctids = GetPostString("ctids");
  11818. string[] list = ctids.Split(',');
  11819. foreach (string ctid in list)
  11820. {
  11821. CeErpSukuraData.createInfo(ctid, 3);
  11822. }
  11823. StringBuilder sql = new StringBuilder();
  11824. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11825. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11826. designHelper.api_approveDesign(ctids); //approveDesign
  11827. returnSuccessMsg("");
  11828. }
  11829. public void get_issue_list()
  11830. {
  11831. DataStruct dStruct = GetPostStruct();
  11832. List<string> lw = new List<string>();
  11833. int st = 2;
  11834. string tid = GetPostString("ctid");
  11835. if (tid.Length > 0)
  11836. {
  11837. string select_tid = getTidByCtid(tid);
  11838. lw.Add(string.Format("tid='{0}'", select_tid));
  11839. }
  11840. string shopname = GetPostString("shopname");
  11841. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11842. string buyernick = GetPostString("buyer_nick");
  11843. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11844. string sellermemo = GetPostString("seller_memo");
  11845. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11846. string supplier = GetPostString("supplier");
  11847. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11848. string customer = GetPostString("customer");
  11849. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11850. string design = GetPostString("design");
  11851. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11852. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11853. string poscode = CurrentUser.UserPost.Post.Code;
  11854. if (poscode != "SysAdmin")
  11855. {
  11856. string shopid = CurrentUser.User.pemShop;
  11857. lw.Add(string.Format("shopId in ({0})", shopid));
  11858. }
  11859. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11860. {
  11861. lw.Add("IssueState = 1");
  11862. }
  11863. lw.Add("IssueState > 0");
  11864. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11865. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11866. writeGridDataTableJson(dStruct.TotalCount, dt);
  11867. }
  11868. public void saveIssueContent()
  11869. {
  11870. string ctid = GetPostString("ctid");
  11871. if (!string.IsNullOrEmpty(ctid))
  11872. {
  11873. string content = GetPostString("content");
  11874. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11875. if (ceErpTradeAfterSaleExtend == null)
  11876. {
  11877. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11878. ceErpTradeAfterSaleExtend.tid = ctid;
  11879. }
  11880. ceErpTradeAfterSaleExtend.IssueContent = content;
  11881. ceErpTradeAfterSaleExtend.IssueState = 1;
  11882. if (ceErpTradeAfterSaleExtend.ID > 0)
  11883. {
  11884. ceErpTradeAfterSaleExtend.Update();
  11885. }
  11886. else
  11887. {
  11888. ceErpTradeAfterSaleExtend.Create();
  11889. }
  11890. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11891. returnSuccessMsg("添加成功!");
  11892. return;
  11893. }
  11894. returnErrorMsg("找不到订单");
  11895. }
  11896. public void dealIssueContent()
  11897. {
  11898. string ctid = GetPostString("ctid");
  11899. if (!string.IsNullOrEmpty(ctid))
  11900. {
  11901. string content = GetPostString("content");
  11902. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11903. if (ceErpTradeAfterSaleExtend != null)
  11904. {
  11905. ceErpTradeAfterSaleExtend.IssueState = 2;
  11906. ceErpTradeAfterSaleExtend.Update();
  11907. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11908. returnSuccessMsg("修改完成!");
  11909. return;
  11910. }
  11911. }
  11912. returnErrorMsg("找不到订单");
  11913. }
  11914. public void set_tid_attachments()
  11915. {
  11916. string tid = GetPostString("tid");
  11917. string atta = GetPostString("atta");
  11918. if (!string.IsNullOrEmpty(tid))
  11919. {
  11920. if (string.IsNullOrEmpty(atta))
  11921. {
  11922. returnErrorMsg("文件地址为空");
  11923. return;
  11924. }
  11925. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11926. if (ceErpTradeCell != null)
  11927. {
  11928. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11929. if (ceErpTrade == null)
  11930. {
  11931. returnErrorMsg("找不到订单");
  11932. return;
  11933. }
  11934. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11935. bool isSend = false;
  11936. if (dt != null && dt.Rows.Count > 0)
  11937. {
  11938. foreach (DataRow row in dt.Rows)
  11939. {
  11940. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11941. {
  11942. isSend = true;
  11943. }
  11944. }
  11945. if (isSend)
  11946. {
  11947. returnErrorMsg("已发货无法修改");
  11948. return;
  11949. }
  11950. ceErpTrade.Attachments = atta;
  11951. ceErpTrade.Update();
  11952. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  11953. returnSuccessMsg("上传成功!");
  11954. return;
  11955. }
  11956. }
  11957. }
  11958. returnErrorMsg("找不到订单");
  11959. }
  11960. public void get_tid_attachments()
  11961. {
  11962. string tid = GetPostString("tid");
  11963. if (!string.IsNullOrEmpty(tid))
  11964. {
  11965. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11966. if (ceErpTradeCell != null)
  11967. {
  11968. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11969. if (ceErpTrade == null)
  11970. {
  11971. returnErrorMsg("找不到订单");
  11972. return;
  11973. }
  11974. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11975. return;
  11976. }
  11977. }
  11978. returnErrorMsg("找不到订单");
  11979. }
  11980. public void check_erp_sameorders()
  11981. {
  11982. if (UrlPostParmsCheck("ctid"))
  11983. {
  11984. string eid = GetPostString("ctid");
  11985. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11986. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11987. if (entity != null && ceErpTrade != null)
  11988. {
  11989. if (entity.OrderState > 6)
  11990. {
  11991. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11992. return;
  11993. }
  11994. DataTable dt = getSameOrderList(entity, ceErpTrade);
  11995. List<string> ids = new List<string>();
  11996. if (dt != null && dt.Rows.Count > 1)
  11997. {
  11998. bool needhe = true;
  11999. foreach (DataRow dr in dt.Rows)
  12000. {
  12001. ids.Add("'" + dr["ctid"] + "'");
  12002. /* //备注有合包
  12003. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12004. {
  12005. needhe = true;
  12006. }
  12007. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12008. {
  12009. needhe = true;
  12010. }
  12011. //顺丰快递
  12012. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12013. {
  12014. needhe = true;
  12015. }*/
  12016. }
  12017. if (!needhe)
  12018. {
  12019. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12020. return;
  12021. }
  12022. StringBuilder sql = new StringBuilder();
  12023. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12024. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12025. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12026. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12027. foreach (DataRow dr in dt.Rows)
  12028. {
  12029. dr["dstate"] = 0;
  12030. dr["dnumber"] = 0;
  12031. foreach (DataRow row in dt1.Rows)
  12032. {
  12033. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12034. {
  12035. dr["dstate"] = 2;
  12036. dr["default"] = 1;
  12037. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12038. }
  12039. }
  12040. if (eid.Equals(dr["ctid"].ToString()))
  12041. {
  12042. dr["dstate"] = 1;
  12043. dr["default"] = 1;
  12044. }
  12045. }
  12046. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12047. return;
  12048. }
  12049. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12050. return;
  12051. }
  12052. returnErrorMsg("未找到订单");
  12053. return;
  12054. }
  12055. returnErrorMsg("缺少必要的参数");
  12056. }
  12057. private DataTable getSameOrderList(CeErpTradeCell entity, CeErpTrade ceErpTrade)
  12058. {
  12059. StringBuilder sql = new StringBuilder();
  12060. 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);
  12061. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12062. {
  12063. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12064. }
  12065. else
  12066. {
  12067. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12068. }
  12069. DataTable dt = null;
  12070. try
  12071. {
  12072. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12073. StringBuilder timerSql = new StringBuilder();
  12074. timerSql.AppendFormat("SELECT * FROM CE_ErpSupplierProductTime WHERE supplierId={0}", entity.SupplierId);
  12075. DataTable timerTable = DbHelper.DbConn.ExecuteDataset(timerSql.ToString()).Tables[0];
  12076. //没有设置时间则不判断
  12077. if (timerTable == null || timerTable.Rows.Count == 0)
  12078. {
  12079. return dt;
  12080. }
  12081. dt.Columns.Add(new DataColumn("default", typeof(int)));
  12082. foreach (DataRow dr in dt.Rows)
  12083. {
  12084. dr["default"] = 0;
  12085. //当前订单
  12086. if (entity.ctid.Equals(dr["ctid"]))
  12087. {
  12088. continue;
  12089. }
  12090. //已经标记过发货
  12091. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(dr["ctid"].ToString());
  12092. if (ceErpDeliverMark != null)
  12093. {
  12094. dr["default"] = 1;
  12095. continue;
  12096. }
  12097. string[] productIds = null;
  12098. string productId = dr["productId"].ToString();
  12099. string finishPlaceTime = dr["FinishPlaceTime"].ToString();
  12100. string sellmer_mome = dr["seller_memo"].ToString();
  12101. string txtCount = dr["ProductCount"].ToString();
  12102. DateTime placeTime = DateTime.Now;
  12103. //没有品类
  12104. if (string.IsNullOrEmpty(productId) || "0".Equals(productId))
  12105. {
  12106. continue;
  12107. }
  12108. if (string.IsNullOrEmpty(finishPlaceTime))
  12109. {
  12110. continue;
  12111. }
  12112. placeTime = DateTime.Parse(finishPlaceTime);
  12113. foreach (DataRow row in timerTable.Rows)
  12114. {
  12115. string txtIds = row["productId"].ToString();
  12116. string[] crafts = { };
  12117. int count = Convert.ToUInt16(row["quantity"]);
  12118. if (string.IsNullOrEmpty(txtIds))
  12119. {
  12120. continue;
  12121. }
  12122. if (count > 0)
  12123. {
  12124. int quantity = commonHelper.handleProductCount(txtCount, true);
  12125. //订单数量大于写入的数量则跳过
  12126. if (quantity > count)
  12127. {
  12128. continue;
  12129. }
  12130. }
  12131. productIds = txtIds.Split(',');
  12132. if (productIds.Contains(productId))
  12133. {
  12134. string textCraft = row["craft"].ToString();
  12135. textCraft = textCraft.Replace(",", ",");//统一格式
  12136. if (!string.IsNullOrEmpty(textCraft))
  12137. {
  12138. crafts = textCraft.Split(',');
  12139. }
  12140. if (crafts.Length > 0)
  12141. {
  12142. bool isinCraft = false;
  12143. for (int i = 0; i < crafts.Length; i++)
  12144. {
  12145. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12146. {
  12147. isinCraft = true;
  12148. break;
  12149. }
  12150. }
  12151. //有写工艺并且备注中没匹配中则跳过
  12152. if (!isinCraft)
  12153. {
  12154. continue;
  12155. }
  12156. }
  12157. DateTime deadLine = DateTime.Parse(row["deadLine"].ToString());
  12158. DateTime dayDeadLine = DateTime.Parse(row["dayDeadLine"].ToString());
  12159. int sendDay = Convert.ToInt16(row["sendDay"]);
  12160. //下单时间小于当日发货时间则不用判断
  12161. //当日发货必须发货
  12162. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12163. {
  12164. dr["default"] = 1;
  12165. break;
  12166. }
  12167. //在截稿时间之前下单的可以减去一天时间
  12168. /*if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12169. {
  12170. sendDay = Math.Max(1, sendDay - 1);
  12171. }
  12172. DateTime sendtime = placeTime.AddDays(sendDay);
  12173. //判断有没有到发货日期
  12174. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) > 0)
  12175. {
  12176. break;
  12177. }*/
  12178. }
  12179. }
  12180. }
  12181. }
  12182. catch (Exception ex)
  12183. {
  12184. }
  12185. return dt;
  12186. }
  12187. public void get_mark_number()
  12188. {
  12189. string eid = GetPostString("ctid");
  12190. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12191. if (entity != null)
  12192. {
  12193. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12194. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12195. int current = 1;
  12196. if (ceErpDeliverMark == null)
  12197. {
  12198. DataTable dt = getSameOrderList(entity, ceErpTrade);
  12199. List<string> ids = new List<string>();
  12200. if (dt != null && dt.Rows.Count > 1)
  12201. {
  12202. foreach (DataRow dr in dt.Rows)
  12203. {
  12204. ids.Add("'" + dr["ctid"] + "'");
  12205. }
  12206. //查询已有的编号
  12207. StringBuilder sql = new StringBuilder();
  12208. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12209. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12210. if (dt1 == null || dt1.Rows.Count == 0)
  12211. {
  12212. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12213. List<int> list_number = new List<int>();
  12214. foreach (DataRow row in numbers.Rows)
  12215. {
  12216. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12217. }
  12218. //查询空余编号
  12219. for (int i = 0; i < list_number.Count + 2; i++)
  12220. {
  12221. if (!list_number.Contains(current))
  12222. {
  12223. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12224. //防止查询过程中有新数据生成
  12225. if (ceErpDeliverMark1 == null)
  12226. {
  12227. break;
  12228. }
  12229. }
  12230. current++;
  12231. }
  12232. }
  12233. else
  12234. {
  12235. foreach (DataRow row in dt1.Rows)
  12236. {
  12237. current = Convert.ToInt32(row["markNumber"]);
  12238. }
  12239. }
  12240. ceErpDeliverMark = new CeErpDeliverMark();
  12241. ceErpDeliverMark.ctid = eid;
  12242. ceErpDeliverMark.createtime = DateTime.Now;
  12243. if (ceErpTrade != null)
  12244. {
  12245. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12246. }
  12247. ceErpDeliverMark.markNumber = current;
  12248. ceErpDeliverMark.Create();
  12249. }
  12250. }
  12251. else
  12252. {
  12253. current = ceErpDeliverMark.markNumber;
  12254. }
  12255. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12256. return;
  12257. }
  12258. }
  12259. public void aftersaleCytSend()
  12260. {
  12261. string ctid = GetPostString("ctid");
  12262. if (!string.IsNullOrEmpty(ctid))
  12263. {
  12264. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12265. if (ceErpTradeCell != null)
  12266. {
  12267. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12268. }
  12269. returnSuccessMsg("推送成功");
  12270. return;
  12271. }
  12272. returnErrorMsg("缺少必要的参数");
  12273. }
  12274. public void packOrderInfo()
  12275. {
  12276. string ctids = GetPostString("ctids");
  12277. if (!string.IsNullOrEmpty(ctids))
  12278. {
  12279. string[] ctid_list = ctids.Split(',');
  12280. if (ctid_list.Length > 20)
  12281. {
  12282. returnErrorMsg("单次下载次数不能超过20个");
  12283. return;
  12284. }
  12285. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12286. StringBuilder sql = new StringBuilder();
  12287. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  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. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12324. returnSuccessMsg("打包成功");
  12325. return;
  12326. }
  12327. returnErrorMsg("缺少必要的参数");
  12328. }
  12329. public void rePackOrderInfo()
  12330. {
  12331. string id = GetPostString("id");
  12332. if (!string.IsNullOrEmpty(id))
  12333. {
  12334. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12335. if (ceErpPackData == null)
  12336. {
  12337. returnSuccessMsg("查无数据");
  12338. return;
  12339. }
  12340. ceErpPackData.upStatus = 0;
  12341. ceErpPackData.message = "";
  12342. ceErpPackData.Update();
  12343. returnSuccessMsg("打包成功");
  12344. return;
  12345. }
  12346. returnErrorMsg("缺少必要的参数");
  12347. }
  12348. public void addPackDownNum()
  12349. {
  12350. string id = GetPostString("id");
  12351. if (!string.IsNullOrEmpty(id))
  12352. {
  12353. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12354. returnSuccessMsg("下载成功");
  12355. return;
  12356. }
  12357. returnErrorMsg("缺少必要的参数");
  12358. }
  12359. public void get_pack_list()
  12360. {
  12361. DataStruct dStruct = GetPostStruct();
  12362. List<string> lw = new List<string>();
  12363. string supplier = GetPostString("supplier");
  12364. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12365. string posTag = CurrentUser.UserPost.Post.Code;
  12366. if (posTag == "Supplier")
  12367. {
  12368. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12369. }
  12370. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12371. dStruct.Order = "createtime desc";
  12372. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12373. writeGridDataTableJson(dStruct.TotalCount, dt);
  12374. }
  12375. public void get_supplier_product_time_list()
  12376. {
  12377. DataStruct dStruct = GetPostStruct();
  12378. List<string> lw = new List<string>();
  12379. string supplier = GetPostString("supplier");
  12380. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12381. string posTag = CurrentUser.UserPost.Post.Code;
  12382. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12383. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12384. writeGridDataTableJson(dStruct.TotalCount, dt);
  12385. }
  12386. public void saveSupplierProductTime()
  12387. {
  12388. string productId = GetPostString("productId");
  12389. if (string.IsNullOrEmpty(productId))
  12390. {
  12391. returnErrorMsg("缺少必要的参数");
  12392. return;
  12393. }
  12394. string productName = GetPostString("productName");
  12395. int supplierId = GetPostInt("supplierId");
  12396. if (supplierId == 0)
  12397. {
  12398. returnErrorMsg("缺少必要的参数");
  12399. return;
  12400. }
  12401. int quantity = GetPostInt("quantity");
  12402. int sendDay = GetPostInt("sendTime");
  12403. string supplierName = GetPostString("supplierName");
  12404. string craft = GetPostString("craft");
  12405. string deadLine = GetPostString("deadLine");
  12406. string dayDeadLine = GetPostString("dayDeadLine");
  12407. try
  12408. {
  12409. int eid = GetPostInt("eid");
  12410. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12411. if (ceErpSupplierProductTime == null)
  12412. {
  12413. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12414. }
  12415. ceErpSupplierProductTime.productId = productId;
  12416. ceErpSupplierProductTime.productName = productName;
  12417. ceErpSupplierProductTime.supplierId = supplierId;
  12418. ceErpSupplierProductTime.supplierName = supplierName;
  12419. ceErpSupplierProductTime.craft = craft;
  12420. ceErpSupplierProductTime.sendDay = sendDay;
  12421. ceErpSupplierProductTime.quantity = quantity;
  12422. if (!string.IsNullOrEmpty(deadLine))
  12423. {
  12424. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12425. }
  12426. if (!string.IsNullOrEmpty(dayDeadLine))
  12427. {
  12428. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12429. }
  12430. if (ceErpSupplierProductTime.ID == 0)
  12431. {
  12432. ceErpSupplierProductTime.Save();
  12433. }
  12434. else
  12435. {
  12436. ceErpSupplierProductTime.Update();
  12437. }
  12438. }
  12439. catch (Exception e)
  12440. {
  12441. }
  12442. returnSuccessMsg("保存成功");
  12443. return;
  12444. }
  12445. public void delSupplierProductTime()
  12446. {
  12447. int eid = GetPostInt("eid");
  12448. if (eid > 0)
  12449. {
  12450. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12451. if (ceErpSupplierProductTime == null)
  12452. {
  12453. returnErrorMsg("查无数据");
  12454. return;
  12455. }
  12456. ceErpSupplierProductTime.Delete();
  12457. returnSuccessMsg("保存成功");
  12458. return;
  12459. }
  12460. returnErrorMsg("缺少必要的参数");
  12461. }
  12462. public void getExpressInfo()
  12463. {
  12464. string ctid = GetPostString("ctid");
  12465. if (!string.IsNullOrEmpty(ctid))
  12466. {
  12467. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12468. if (ceErpTradeCell != null)
  12469. {
  12470. string outSid = ceErpTradeCell.OutSid;
  12471. if (outSid.Length > 0)
  12472. {
  12473. 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);
  12474. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12475. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12476. return;
  12477. }
  12478. }
  12479. returnErrorMsg("查无记录");
  12480. return;
  12481. }
  12482. returnErrorMsg("缺少必要的参数");
  12483. }
  12484. public void getExpressPostData()
  12485. {
  12486. string express = GetPostString("express");
  12487. if (!string.IsNullOrEmpty(express))
  12488. {
  12489. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12490. if (ceErpExpressInfo != null)
  12491. {
  12492. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12493. return;
  12494. }
  12495. }
  12496. returnErrorMsg("缺少必要的参数");
  12497. }
  12498. }
  12499. }