sync.order.cs 638 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793
  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. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  766. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  767. {
  768. //dataHelper.api_orderBack(entity.ctid, "0", "");
  769. }
  770. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  771. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  772. returnSuccessMsg("保存成功!");
  773. return;
  774. }
  775. returnErrorMsg("找不到记录");
  776. }
  777. }
  778. public void ins_erp_checkorder()
  779. {
  780. if (UrlPostParmsCheck("ctid"))
  781. {
  782. string ctid = GetPostString("ctid");
  783. CeErpTradeCell entity = null;
  784. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  785. if (entity != null)
  786. {
  787. if (entity.OrderState < 6)
  788. {
  789. returnErrorMsg("下单完成后才可查货");
  790. return;
  791. }
  792. /*if (entity.OrderState > 6)
  793. {
  794. returnErrorMsg("订单已发货");
  795. return;
  796. }*/
  797. if (entity.FinishPlaceTime != null)
  798. {
  799. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  800. {
  801. returnErrorMsg("下单时间不足,无法查货");
  802. return;
  803. }
  804. }
  805. entity.MemoOpt = 3;
  806. entity.CheckOrderTime = DateTime.Now;
  807. entity.UpdateTime = DateTime.Now;
  808. entity.Update();
  809. CeErpSukuraData.createInfo(entity.ctid, 6);
  810. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  811. returnSuccessMsg("操作成功!");
  812. return;
  813. }
  814. returnErrorMsg("找不到记录");
  815. }
  816. }
  817. public void save_erp_othermemo()
  818. {
  819. if (UrlPostParmsCheck("ctid"))
  820. {
  821. string ctid = GetPostString("ctid");
  822. CeErpTradeCell entity = null;
  823. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  824. if (entity != null)
  825. {
  826. entity.OtherMemo = GetPostString("otherMemo");
  827. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  828. {
  829. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  830. StringBuilder sql = new StringBuilder();
  831. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  832. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  833. if (dt != null && dt.Rows.Count > 0)
  834. {
  835. foreach (DataRow dr in dt.Rows)
  836. {
  837. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  838. {
  839. //品类一直
  840. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  841. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  842. if (ceErpSampleCustomer == null)
  843. {
  844. ceErpSampleCustomer = new CeErpSampleCustomer();
  845. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  846. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  847. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  848. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  849. ceErpSampleCustomer.shopId = entity.ShopId;
  850. }
  851. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  852. ceErpSampleCustomer.lastTid = entity.tid;
  853. if (ceErpSampleCustomer.ID > 0)
  854. {
  855. ceErpSampleCustomer.Update();
  856. }
  857. else
  858. {
  859. ceErpSampleCustomer.Create();
  860. }
  861. }
  862. }
  863. }
  864. }
  865. //if (entity.IsOldCustomer == 1)
  866. //{
  867. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  868. //{
  869. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  870. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  871. //}
  872. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  873. //{
  874. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  875. // {
  876. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  877. // {
  878. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  879. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  880. // }
  881. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  882. // {
  883. // entity.OrderState = 2;
  884. // entity.DesignUserId = 0;
  885. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  886. // }
  887. // else
  888. // {
  889. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  890. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  891. // }
  892. // }
  893. //}
  894. //}
  895. entity.UpdateTime = DateTime.Now;
  896. entity.Update();
  897. returnSuccessMsg("保存成功!");
  898. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  899. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  900. ceErpTradeCellExtend = commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  901. return;
  902. }
  903. returnErrorMsg("找不到记录");
  904. }
  905. }
  906. public void save_erp_customermemo()
  907. {
  908. if (UrlPostParmsCheck("ctid"))
  909. {
  910. string ctid = GetPostString("ctid");
  911. CeErpTradeCell entity = null;
  912. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  913. if (entity != null)
  914. {
  915. entity.UpdateTime = DateTime.Now;
  916. entity.CustomerMemo = GetPostString("CustomerMemo");
  917. entity.Update();
  918. ApiVo apiVo = new ApiVo();
  919. apiVo.orderNumber = entity.ctid;
  920. apiVo.actionName = "followRemarks";
  921. apiVo.orderRemarks = entity.CustomerMemo;
  922. designHelper.API_WorkCore(apiVo);//followRemarks
  923. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  924. returnSuccessMsg("保存成功!");
  925. return;
  926. }
  927. returnErrorMsg("找不到记录");
  928. }
  929. }
  930. public void upd_erp_addmemotag()
  931. {
  932. if (UrlPostParmsCheck("ctid"))
  933. {
  934. ;
  935. string eid = GetPostString("ctid");
  936. string sfTagstr = GetPostString("memotag");
  937. CeErpTradeCell entity = null;
  938. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  939. if (entity != null)
  940. {
  941. ApiVo apiVo = new ApiVo();
  942. if (entity.OrderState == 0)
  943. {
  944. returnErrorMsg("请先领单");
  945. return;
  946. }
  947. //撤销顺丰
  948. if (sfTagstr == "撤销顺丰")
  949. {
  950. entity.IsSF = 0;
  951. string reMsg = "";
  952. string oldmemo = entity.seller_memo;
  953. if (entity.OrderState < 5)
  954. {
  955. oldmemo = oldmemo.Replace("顺丰到付", "");
  956. oldmemo = oldmemo.Replace("顺丰寄付", "");
  957. entity.seller_memo = oldmemo;
  958. }
  959. else
  960. {
  961. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  962. {
  963. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  964. }
  965. }
  966. entity.Update();
  967. apiVo.orderNumber = entity.ctid;
  968. apiVo.actionName = "orderRemarks";
  969. apiVo.orderRemarks = entity.seller_memo;
  970. apiVo.isSf = entity.IsSF.ToString();
  971. designHelper.API_WorkCore(apiVo);//orderRemarks
  972. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  973. returnSuccessMsg("撤销成功!" + reMsg);
  974. return;
  975. }
  976. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  977. {
  978. //string oldmemo = entity.seller_memo;
  979. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  980. string sfStr = GetPostString("memotag");
  981. string smemo = entity.seller_memo;
  982. int kindex = smemo.IndexOf(")");
  983. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  984. if (lastoneStr != "-")
  985. {
  986. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  987. }
  988. string prememo = smemo.Substring(0, kindex + 2);
  989. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  990. int lastkindex = lastmemo.IndexOf("(");
  991. string newlastmemo = "";
  992. if (lastkindex == 0)
  993. {
  994. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  995. newlastmemo = "(" + sfStr + "." + useLastmemo;
  996. }
  997. else
  998. {
  999. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1000. }
  1001. entity.seller_memo = prememo + newlastmemo;
  1002. }
  1003. string sfTagMSg = "";
  1004. if (sfTagstr == "顺丰寄付")
  1005. {
  1006. entity.IsSF = 1;
  1007. sfTagMSg = "顺丰寄付";
  1008. }
  1009. else if (sfTagstr == "顺丰到付")
  1010. {
  1011. entity.IsSF = 2;
  1012. sfTagMSg = "顺丰到付";
  1013. }
  1014. entity.Update();
  1015. apiVo = new ApiVo();
  1016. apiVo.orderNumber = entity.ctid;
  1017. apiVo.actionName = "orderRemarks";
  1018. apiVo.orderRemarks = entity.seller_memo;
  1019. apiVo.isSf = entity.IsSF.ToString();
  1020. designHelper.API_WorkCore(apiVo);//orderRemarks
  1021. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1022. returnSuccessMsg("标记成功!");
  1023. return;
  1024. }
  1025. returnErrorMsg("找不到记录");
  1026. }
  1027. }
  1028. public void upd_erp_ordertag()
  1029. {
  1030. if (UrlPostParmsCheck("ctid"))
  1031. {
  1032. string eid = GetPostString("ctid");
  1033. CeErpTradeCell entity = null;
  1034. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1035. if (entity != null)
  1036. {
  1037. int tag = GetPostInt("wechattag");
  1038. //if(tag==4 && entity.IsSample == 2)
  1039. //{
  1040. // returnErrorMsg("补差价单不能标记微信单");
  1041. // return;
  1042. //}
  1043. entity.wechatTag = tag;
  1044. entity.Update();
  1045. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1046. if (tag == 1)
  1047. {
  1048. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1049. if (cash == null)
  1050. {
  1051. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1052. cash = new CeErpReturnCash();
  1053. cash.tid = entity.tid;
  1054. cash.seller_nick = main.seller_nick;
  1055. cash.payment = trade.payment;
  1056. cash.buyer_nick = main.buyer_nick;
  1057. cash.cashstate = 0;
  1058. cash.rtype = "微信返现";
  1059. cash.returnprice = 0;
  1060. cash.created = DateTime.Now;
  1061. cash.con = "订单标记微信单";
  1062. cash.img = "";
  1063. cash.applyuserid = CurrentUser.UserID;
  1064. cash.Create();
  1065. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1066. }
  1067. else
  1068. {
  1069. cash.cashstate = 0;
  1070. cash.Update();
  1071. }
  1072. CeErpSukuraData.createInfo(entity.ctid, 9);
  1073. }
  1074. else if (tag == 2)
  1075. {
  1076. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1077. if (cash == null)
  1078. {
  1079. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1080. cash = new CeErpReturnCash();
  1081. cash.tid = entity.tid;
  1082. cash.seller_nick = main.seller_nick;
  1083. cash.payment = trade.payment;
  1084. cash.buyer_nick = main.buyer_nick;
  1085. cash.cashstate = 0;
  1086. cash.rtype = "推购返现";
  1087. cash.returnprice = 5;
  1088. cash.created = DateTime.Now;
  1089. cash.con = "订单标记推购单";
  1090. cash.img = "";
  1091. cash.applyuserid = CurrentUser.UserID;
  1092. cash.Create();
  1093. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1094. }
  1095. else
  1096. {
  1097. cash.cashstate = 0;
  1098. cash.Update();
  1099. }
  1100. CeErpSukuraData.createInfo(entity.ctid, 9);
  1101. }
  1102. else if (tag == 3)
  1103. {
  1104. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1105. if (pers == null)
  1106. {
  1107. pers = new CeErpPersuade();
  1108. pers.ctid = entity.ctid;
  1109. pers.pstate = 0;
  1110. pers.created = DateTime.Now;
  1111. pers.applyuserid = CurrentUser.UserID;
  1112. pers.Create();
  1113. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1114. }
  1115. else
  1116. {
  1117. pers.pstate = 0;
  1118. pers.Update();
  1119. }
  1120. }
  1121. else if (tag == 4 || tag == 5)
  1122. {
  1123. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1124. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1125. if (pers == null)
  1126. {
  1127. pers = new CeErpStayGoods();
  1128. pers.t_id = entity.tid;
  1129. pers.status = "待审核";
  1130. pers.audit_type = 0;
  1131. if (tag == 4)
  1132. {
  1133. pers.stay_type = "微信推购";
  1134. }
  1135. else
  1136. {
  1137. pers.stay_type = "旺旺推购";
  1138. }
  1139. if (entity.IsXianHuo == 0)
  1140. {
  1141. pers.product_id = entity.ProductId;
  1142. }
  1143. pers.wangwang = main.buyer_nick;
  1144. pers.shop_name = main.seller_nick;
  1145. pers.creata_time = DateTime.Now;
  1146. pers.create_u_id = CurrentUser.UserID;
  1147. pers.create_u_name = CurrentUser.UserName;
  1148. pers.Create();
  1149. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1150. }
  1151. else
  1152. {
  1153. pers.audit_type = 0;
  1154. pers.Update();
  1155. }
  1156. CeErpSukuraData.createInfo(entity.ctid, 10);
  1157. }
  1158. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1159. returnSuccessMsg("标记成功!");
  1160. return;
  1161. }
  1162. returnErrorMsg("找不到记录");
  1163. }
  1164. }
  1165. public void upd_erp_ordertag_cancel()
  1166. {
  1167. if (UrlPostParmsCheck("ctid"))
  1168. {
  1169. string eid = GetPostString("ctid");
  1170. CeErpTradeCell entity = null;
  1171. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1172. if (entity != null)
  1173. {
  1174. entity.wechatTag = 0;
  1175. entity.Update();
  1176. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1177. if (pers != null)
  1178. {
  1179. pers.status = "取消推购";
  1180. pers.audit_type = 3;
  1181. pers.Update();
  1182. }
  1183. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1184. returnSuccessMsg("标记成功!");
  1185. return;
  1186. }
  1187. returnErrorMsg("找不到记录");
  1188. }
  1189. }
  1190. public void upd_erp_addweichattag()
  1191. {
  1192. if (UrlPostParmsCheck("ctid"))
  1193. {
  1194. ;
  1195. string eid = GetPostString("ctid");
  1196. CeErpTradeCell entity = null;
  1197. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1198. if (entity != null)
  1199. {
  1200. if (entity.IsAddWechat > 0)
  1201. {
  1202. returnErrorMsg("此单已经标记过了");
  1203. return;
  1204. }
  1205. 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);
  1206. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1207. if (dt.Rows.Count > 0)
  1208. {
  1209. entity.IsAddWechat = 2;
  1210. }
  1211. else
  1212. {
  1213. entity.IsAddWechat = 1;
  1214. }
  1215. entity.Update();
  1216. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1217. returnSuccessMsg("标记成功!");
  1218. return;
  1219. }
  1220. returnErrorMsg("找不到记录");
  1221. }
  1222. }
  1223. public void upd_erp_getmyorder()
  1224. {
  1225. if (UrlPostParmsCheck("ctid"))
  1226. {
  1227. ;
  1228. string eid = GetPostString("ctid");
  1229. CeErpTradeCell entity = null;
  1230. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1231. if (entity != null)
  1232. {
  1233. if (entity.ctid.IndexOf("C") != -1)
  1234. {
  1235. StringBuilder sql = new StringBuilder();
  1236. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1237. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1238. if (dt.Rows.Count > 0)
  1239. {
  1240. decimal total = 0;
  1241. foreach (DataRow dr in dt.Rows)
  1242. {
  1243. total += Convert.ToDecimal(dr["payment"]);
  1244. }
  1245. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1246. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1247. {
  1248. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1249. return;
  1250. }
  1251. }
  1252. }
  1253. if (entity.OrderState == -1)
  1254. {
  1255. returnErrorMsg("待审核订单无法领取!");
  1256. return;
  1257. }
  1258. entity.CustomerUserId = CurrentUser.UserID;
  1259. if (entity.OrderState < 2)
  1260. {
  1261. entity.OrderState = 2;
  1262. if (entity.ShopId != 0)
  1263. {
  1264. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1265. }
  1266. }
  1267. entity.UpdateTime = DateTime.Now;
  1268. entity.Update();
  1269. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1270. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1271. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1272. {
  1273. //dataHelper.api_orderBack(entity.ctid, "0", "");
  1274. }
  1275. returnSuccessMsg("领单成功!");
  1276. return;
  1277. }
  1278. returnErrorMsg("找不到记录");
  1279. }
  1280. }
  1281. public void getmyorder_from_init()
  1282. {
  1283. if (UrlPostParmsCheck("ctid"))
  1284. {
  1285. string eid = GetPostString("ctid");
  1286. CeErpTradeCell entity = null;
  1287. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1288. if (entity != null)
  1289. {
  1290. string sellerMemo = GetPostString("sellerMemo");
  1291. if (sellerMemo.Length > 0)
  1292. {
  1293. entity.seller_memo = sellerMemo;
  1294. }
  1295. string oterhMemo = GetPostString("otherMemo");
  1296. if (oterhMemo.Length > 0)
  1297. {
  1298. entity.OtherMemo = oterhMemo;
  1299. }
  1300. int urg = GetPostInt("urgency");
  1301. entity.IsUrgency = (urg == 1 ? true : false);
  1302. int wechat = GetPostInt("wechat");
  1303. int command = GetPostInt("command");
  1304. if (wechat == 1)
  1305. {
  1306. entity.wechatTag = 1;
  1307. }
  1308. if (command == 1)
  1309. {
  1310. entity.wechatTag = 2;
  1311. }
  1312. string pPro = GetPostString("pprofession");
  1313. if (pPro.Length > 0)
  1314. {
  1315. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1316. string spro = GetPostString("profession");
  1317. if (spro.Length > 0)
  1318. {
  1319. entity.ProfessionId = Convert.ToInt32(spro);
  1320. }
  1321. }
  1322. string proId = GetPostString("productId");
  1323. if (proId.Length > 0)
  1324. {
  1325. entity.ProductId = Convert.ToInt32(proId);
  1326. }
  1327. entity.Material = GetPostString("material");
  1328. entity.Craft = GetPostString("craft");
  1329. entity.CustomerUserId = CurrentUser.UserID;
  1330. if (entity.OrderState < 2)
  1331. {
  1332. entity.OrderState = 2;
  1333. if (entity.ShopId != 0)
  1334. {
  1335. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1336. }
  1337. }
  1338. entity.Update();
  1339. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1340. returnSuccessMsg("领单成功!");
  1341. return;
  1342. }
  1343. returnErrorMsg("找不到记录");
  1344. }
  1345. }
  1346. public void upd_erp_setrelationorder()
  1347. {
  1348. if (UrlPostParmsCheck("ctid"))
  1349. {
  1350. ;
  1351. string eid = GetPostString("ctid");
  1352. string ftid = GetPostString("ftid");
  1353. CeErpTradeCell entity = null;
  1354. CeErpTradeCell fentity = null;
  1355. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1356. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1357. if (fentity == null)
  1358. {
  1359. returnErrorMsg("找不到关联的主订单");
  1360. return;
  1361. }
  1362. if (entity != null)
  1363. {
  1364. if (entity.OrderState >= 5)
  1365. {
  1366. returnErrorMsg("本单已经设计完成无法关联");
  1367. return;
  1368. }
  1369. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1370. {
  1371. returnErrorMsg("线下单续审核后才能关联!");
  1372. return;
  1373. }
  1374. entity.ptid = ftid;
  1375. entity.OrderState = fentity.OrderState;
  1376. //entity.status = fentity.status;
  1377. entity.CustomerUserId = fentity.CustomerUserId;
  1378. entity.DesignUserId = fentity.DesignUserId;
  1379. entity.seller_memo = "补差价单:" + ftid;
  1380. entity.IsSample = 2;
  1381. entity.Update();
  1382. ApiVo apiVo = new ApiVo();
  1383. apiVo.orderNumber = ftid;
  1384. apiVo.payment = entity.payment;
  1385. apiVo.actionName = "repairDesign";
  1386. designHelper.API_WorkCore(apiVo);//repairDesign
  1387. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1388. returnSuccessMsg("关联成功!");
  1389. return;
  1390. }
  1391. else
  1392. returnErrorMsg("找不到记录");
  1393. }
  1394. }
  1395. public void download_erp_neworder()
  1396. {
  1397. string seller = GetPostString("seller_nick");
  1398. string tid = GetPostString("tid");
  1399. if (seller.Length <= 0 || tid.Length <= 0)
  1400. {
  1401. returnErrorMsg("数据错误");
  1402. }
  1403. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1404. //{
  1405. // returnErrorMsg("找不到店铺Sessionkey");
  1406. //}
  1407. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1408. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1409. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1410. if (res.IndexOf("refOid") == -1)
  1411. {
  1412. returnErrorMsg("下载订单数据失败");
  1413. return;
  1414. }
  1415. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1416. returnSuccessMsg("下载完成");
  1417. //tmcHelper.createNewOrder(res);
  1418. //CeErpTrade entr = null;
  1419. //entr = CeErpTrade.Get(tid);
  1420. //if (entr != null)
  1421. //{
  1422. // returnSuccess("下载成功");
  1423. // //下载成功之后,Cell表生成对应的订单;
  1424. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1425. //}
  1426. //else
  1427. //{
  1428. // returnErrorMsg("下载失败或者创建订单失败");
  1429. //}
  1430. }
  1431. public void set_erp_atersale()
  1432. {
  1433. if (UrlPostParmsCheck("ctid"))
  1434. {
  1435. string eid = GetPostString("ctid");
  1436. string reason = GetPostString("AfterSaleReason");
  1437. CeErpTradeCell entity = null;
  1438. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1439. if (entity != null)
  1440. {
  1441. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1442. {
  1443. returnErrorMsg("此订单已经在售后");
  1444. return;
  1445. }
  1446. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1447. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1448. entity.AfterSaleTime = DateTime.Now;
  1449. entity.Update();
  1450. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1451. returnSuccessMsg("转售后成功!");
  1452. return;
  1453. }
  1454. returnErrorMsg("找不到记录");
  1455. }
  1456. }
  1457. public void set_erp_withdraw()
  1458. {
  1459. if (UrlPostParmsCheck("ctid"))
  1460. {
  1461. try
  1462. {
  1463. string eid = GetPostString("ctid");//商品id
  1464. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1465. CeWithdraw ceWithdrawSelect = null;
  1466. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1467. if (ceWithdrawSelect != null)
  1468. {
  1469. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1470. {
  1471. ceWithdrawSelect.status = -1;
  1472. ceWithdrawSelect.Update();
  1473. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1474. returnSuccessMsg("重新发起审核成功");
  1475. return;
  1476. }
  1477. else
  1478. {
  1479. returnSuccessMsg("请勿重复申请!");
  1480. return;
  1481. }
  1482. }
  1483. else
  1484. {
  1485. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1486. if (string.IsNullOrEmpty(CustomerUserId))
  1487. {
  1488. CustomerUserId = "-1";
  1489. }
  1490. int Userid = CurrentUser.UserID;//用户id
  1491. CeWithdraw ceWithdraw = new CeWithdraw();
  1492. ceWithdraw.tid = eid;
  1493. ceWithdraw.userid = Userid;
  1494. ceWithdraw.providerid = CustomerUserId;
  1495. ceWithdraw.status = 3;
  1496. ceWithdraw.creationtime = DateTime.Now;
  1497. ceWithdraw.Create();
  1498. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1499. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1500. return;
  1501. }
  1502. }
  1503. catch
  1504. {
  1505. returnErrorMsg("申请撤回订单失败");
  1506. return;
  1507. }
  1508. }
  1509. }
  1510. public void ins_erp_billinfo()
  1511. {
  1512. if (UrlPostParmsCheck("ctid"))
  1513. {
  1514. string eid = GetPostString("ctid");
  1515. CeErpTradeCell entity = null;
  1516. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1517. if (entity != null)
  1518. {
  1519. CeErpBill bill = CeErpBill.GetByTid(eid);
  1520. bool isHave = false;
  1521. if (bill != null)
  1522. {
  1523. isHave = true;
  1524. if (bill.state != 4)
  1525. {
  1526. returnErrorMsg("此单已经申请过发票了");
  1527. return;
  1528. }
  1529. }
  1530. if (entity.IsNeedBill == 0)
  1531. {
  1532. entity.IsNeedBill = 1;
  1533. }
  1534. entity.Update();
  1535. string errjson = "";
  1536. try
  1537. {
  1538. CeErpBill bill_entity = new CeErpBill();
  1539. bill_entity.tid = entity.tid;
  1540. bill_entity.title = GetPostString("title");
  1541. string taxstr = GetPostString("tax");
  1542. taxstr = taxstr.Replace(" ", "");
  1543. bill_entity.tax = taxstr;
  1544. bill_entity.bank = GetPostString("bank");
  1545. string bankacstr = GetPostString("bankac");
  1546. bankacstr = bankacstr.Replace(" ", "");
  1547. bill_entity.bankac = bankacstr;
  1548. bill_entity.address = GetPostString("address");
  1549. bill_entity.phone = GetPostString("phone");
  1550. bill_entity.price = GetPostString("price");
  1551. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1552. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1553. {
  1554. billCount += 1;
  1555. }
  1556. string prebill = "ltb";
  1557. for (int idx = 1; idx <= billCount; idx++)
  1558. {
  1559. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1560. string billoid = prebill + idx + dtstr;
  1561. bill_entity.billOrderId += billoid;
  1562. if (idx < billCount)
  1563. {
  1564. bill_entity.billOrderId += ",";
  1565. }
  1566. }
  1567. bill_entity.productId = GetPostInt("ProductName");
  1568. bill_entity.num = GetPostInt("num");
  1569. bill_entity.unit = GetPostString("unit");
  1570. bill_entity.type = GetPostString("type");
  1571. bill_entity.sendType = GetPostString("SendType");
  1572. bill_entity.email = GetPostString("email");
  1573. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1574. bill_entity.shopName = GetPostString("ShopName");
  1575. bill_entity.applymemo = GetPostString("applyMemo");
  1576. bill_entity.createTime = DateTime.Now;
  1577. bill_entity.state = 0;
  1578. bill_entity.userId = CurrentUser.UserID;
  1579. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1580. bill_entity.Create();
  1581. }
  1582. catch (Exception ex)
  1583. {
  1584. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1585. returnErrorMsg("创建发票出错!");
  1586. return;
  1587. }
  1588. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1589. returnSuccessMsg("发票申请成功!");
  1590. return;
  1591. }
  1592. returnErrorMsg("找不到记录");
  1593. }
  1594. }
  1595. public void ins_erp_neworder()
  1596. {
  1597. if (UrlPostParmsCheck("receiver_name"))
  1598. {
  1599. CeErpTrade entity = new CeErpTrade();
  1600. string plat_form = GetPostString("platform");
  1601. string preStr = "N_";
  1602. if (plat_form == "拼多多")
  1603. {
  1604. preStr = "P_";
  1605. }
  1606. else if (plat_form == "阿里巴巴")
  1607. {
  1608. preStr = "A_";
  1609. }
  1610. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1611. entity.seller_nick = GetPostString("seller_nick");
  1612. entity.buyer_nick = GetPostString("buyer_nick");
  1613. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1614. entity.total_fee = entity.payment;
  1615. entity.pay_time = DateTime.Now;
  1616. entity.status = "NOT_SHIPPED";
  1617. entity.receiver_name = GetPostString("receiver_name");
  1618. entity.receiver_mobile = GetPostString("receiver_mobile");
  1619. entity.receiver_state = GetPostString("receiver_state");
  1620. entity.receiver_city = GetPostString("receiver_city");
  1621. entity.receiver_district = GetPostString("receiver_district");
  1622. entity.receiver_address = GetPostString("receiver_address");
  1623. if (entity.receiver_state == "" || entity.receiver_city == "")
  1624. {
  1625. returnErrorMsg("收件地址不能为空");
  1626. return;
  1627. }
  1628. int shopId = 0;
  1629. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1630. if (nShop != null)
  1631. {
  1632. shopId = nShop.ID;
  1633. }
  1634. if (shopId != 34 && entity.payment == 0)
  1635. {
  1636. returnErrorMsg("公司自用的单金额才能为0");
  1637. return;
  1638. }
  1639. entity.Create();
  1640. CeErpTradeCell entitycell = new CeErpTradeCell();
  1641. entitycell.ctid = entity.tid;
  1642. entitycell.tid = entity.tid;
  1643. entitycell.ShopId = shopId;
  1644. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1645. entitycell.OrderState = 0;
  1646. entitycell.pay_time = entity.pay_time;
  1647. entitycell.IsOffLineOrder = 1;
  1648. entitycell.Create();
  1649. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1650. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1651. return;
  1652. }
  1653. }
  1654. public void ins_erp_neworder2()
  1655. {
  1656. if (UrlPostParmsCheck("receiver_name"))
  1657. {
  1658. //string plat_form = GetPostString("platform");
  1659. string preStr = "X_";
  1660. string memo = GetPostString("memo");
  1661. string productId = GetPostString("productId");
  1662. string primg = GetPostString("proofimg");
  1663. string sellerNick = GetPostString("seller_nick");
  1664. string addFrom = GetPostString("addfrom");
  1665. if (addFrom == "1")
  1666. {
  1667. preStr = "N_";
  1668. }
  1669. int shopId = 0;
  1670. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1671. if (nShop != null)
  1672. {
  1673. shopId = nShop.ID;
  1674. }
  1675. else
  1676. {
  1677. returnErrorMsg("找不到对应店铺");
  1678. return;
  1679. }
  1680. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1681. {
  1682. returnErrorMsg("必须上传付款凭证");
  1683. return;
  1684. }
  1685. CeErpTrade entity = new CeErpTrade();
  1686. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1687. entity.seller_nick = sellerNick;
  1688. entity.buyer_nick = GetPostString("buyer_nick");
  1689. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1690. entity.total_fee = entity.payment;
  1691. entity.pay_time = DateTime.Now;
  1692. entity.status = "NOT_SHIPPED";
  1693. entity.receiver_name = GetPostString("receiver_name");
  1694. entity.receiver_mobile = GetPostString("receiver_mobile");
  1695. entity.receiver_state = GetPostString("receiver_state");
  1696. entity.receiver_city = GetPostString("receiver_city");
  1697. entity.receiver_district = GetPostString("receiver_district");
  1698. entity.receiver_address = GetPostString("receiver_address");
  1699. entity.seller_memo = memo;
  1700. entity.orderFrom = 20;
  1701. entity.orderType = 15;
  1702. if (entity.receiver_state == "" || entity.receiver_city == "")
  1703. {
  1704. returnErrorMsg("收件地址不能为空");
  1705. return;
  1706. }
  1707. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1708. {
  1709. returnErrorMsg("公司自用的单金额才能为0");
  1710. return;
  1711. }
  1712. entity.Create();
  1713. string toWhere = GetPostString("towhere");
  1714. CeErpTradeCell entitycell = new CeErpTradeCell();
  1715. entitycell.ctid = entity.tid;
  1716. //唯一标识
  1717. entitycell.OrderSn = entity.tid;
  1718. string orderSn = dataHelper.getSaleOrderSn();
  1719. if (orderSn != "")
  1720. {
  1721. entitycell.OrderSn = orderSn;
  1722. }
  1723. entitycell.tid = entity.tid;
  1724. //if (preStr == "X_")
  1725. //{
  1726. entitycell.IsOffLineOrder = 1;
  1727. //}
  1728. entitycell.CustomerUserId = CurrentUser.UserID;
  1729. entitycell.PayProofImg = primg;
  1730. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1731. entitycell.ProductId = Convert.ToInt32(productId);
  1732. entitycell.ShopId = shopId;
  1733. entitycell.UpdateTime = DateTime.Now;
  1734. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1735. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1736. {
  1737. entitycell.IsXianHuo = 1;
  1738. }
  1739. entitycell.pay_time = entity.pay_time;
  1740. if (toWhere == "1")
  1741. {
  1742. entitycell.OrderState = 2;
  1743. }
  1744. else
  1745. {
  1746. entitycell.OrderState = 6;
  1747. entitycell.FinishPlaceTime = entitycell.pay_time;
  1748. }
  1749. if (shopId == 94)
  1750. {
  1751. entitycell.OrderState = 4;
  1752. entitycell.WaitDesignTime = entitycell.pay_time;
  1753. entitycell.StartDesignTime = entitycell.pay_time;
  1754. entitycell.DesignUserId = 218;
  1755. }
  1756. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1757. {
  1758. entitycell.OrderState = -1;//修改12-5
  1759. CeWithdraw ceWithdraw = new CeWithdraw();
  1760. ceWithdraw.tid = entity.tid;
  1761. ceWithdraw.providerid = "-1";
  1762. ceWithdraw.status = -1;
  1763. ceWithdraw.creationtime = DateTime.Now;
  1764. ceWithdraw.userid = 1337;
  1765. ceWithdraw.Create();
  1766. }
  1767. entitycell.Create();
  1768. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1769. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1770. {
  1771. addPlaceRegist(entitycell, CurrentUser.UserID);
  1772. }
  1773. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1774. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1775. return;
  1776. }
  1777. }
  1778. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1779. {
  1780. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1781. entity.PlactTime = tradecell.pay_time;
  1782. entity.AddUserId = userid;
  1783. entity.FileName = tradecell.seller_memo;
  1784. entity.Supplier = 24;
  1785. entity.CreateTime = DateTime.Now;
  1786. entity.Did = tradecell.ctid;
  1787. entity.tid = tradecell.tid;
  1788. entity.splitTag = tradecell.SplitTag;
  1789. entity.CurState = "未完成";
  1790. entity.Create();
  1791. }
  1792. public void get_erp_offlinelist()
  1793. {
  1794. DataStruct dStruct = GetPostStruct();
  1795. List<string> lw = new List<string>();
  1796. string tid = GetPostString("ctid");
  1797. string date1 = GetPostString("date1");
  1798. string date2 = GetPostString("date2");
  1799. if (tid.Length > 0 || date1.Length > 0)
  1800. {
  1801. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1802. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1803. if (dw.Length > 0) lw.Add(dw);
  1804. }
  1805. else
  1806. {
  1807. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1808. }
  1809. string shopname = GetPostString("shopname");
  1810. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1811. string buyernick = GetPostString("buyer_nick");
  1812. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1813. string customer = GetPostString("customer");
  1814. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1815. string design = GetPostString("design");
  1816. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1817. string orderState = GetPostString("orderState");
  1818. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1819. string address = GetPostString("address");
  1820. 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));
  1821. string sellermemo = GetPostString("seller_memo");
  1822. if (sellermemo.Length > 0)
  1823. {
  1824. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1825. }
  1826. string price1 = GetPostString("price1");
  1827. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1828. string price2 = GetPostString("price2");
  1829. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1830. //if (PKey != "admin")
  1831. //{
  1832. // string usershop = CurrentUser.User.pemShop;
  1833. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1834. //}
  1835. //if (ex_psize > 0)
  1836. //{
  1837. dStruct.Order = "pay_time desc";
  1838. //}
  1839. //else
  1840. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1841. lw.Add(string.Format("IsOffLineOrder=1"));
  1842. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1843. DataTable dt = null;
  1844. dt = WebCache.GetData("view_erptradecell", dStruct);
  1845. writeGridDataTableJson(dStruct.TotalCount, dt);
  1846. }
  1847. public void get_erp_returncashrecord()
  1848. {
  1849. DataStruct dStruct = GetPostStruct();
  1850. List<string> lw = new List<string>();
  1851. string tid = GetPostString("ctid");
  1852. if (tid.Length > 0)
  1853. {
  1854. lw.Add(string.Format("tid like '%{0}%'", tid));
  1855. dStruct.Order = "id desc";
  1856. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1857. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1858. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1859. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1860. return;
  1861. }
  1862. returnErrorMsg("id数据错误!");
  1863. }
  1864. public void ins_erp_returncashrecord()
  1865. {
  1866. if (UrlPostParmsCheck("tid"))
  1867. {
  1868. string tid = GetPostString("tid");
  1869. string retype = GetPostString("type");
  1870. StringBuilder sql = new StringBuilder();
  1871. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1872. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1873. if (dt.Rows.Count > 0)
  1874. {
  1875. returnErrorMsg("相同返现类型记录已存在");
  1876. return;
  1877. }
  1878. CeErpReturnCash entity = new CeErpReturnCash();
  1879. entity.tid = tid;
  1880. entity.seller_nick = GetPostString("seller_nick");
  1881. string pment = GetPostString("payment");
  1882. if (pment.Length > 0)
  1883. {
  1884. entity.payment = Convert.ToDouble(pment);
  1885. }
  1886. entity.buyer_nick = GetPostString("buyer_nick");
  1887. entity.cashstate = 0;
  1888. entity.rtype = retype;
  1889. string rPrice = GetPostString("returnprice");
  1890. if (rPrice.Length > 0)
  1891. {
  1892. entity.returnprice = Convert.ToDouble(rPrice);
  1893. }
  1894. entity.created = DateTime.Now;
  1895. entity.con = GetPostString("con");
  1896. entity.img = GetPostString("img");
  1897. entity.applyuserid = CurrentUser.UserID;
  1898. entity.Create();
  1899. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1900. returnSuccessMsg("操作成功!");
  1901. return;
  1902. }
  1903. }
  1904. public void set_erp_predelivery()
  1905. {
  1906. if (UrlPostParmsCheck("ctid"))
  1907. {
  1908. string eid = GetPostString("ctid");
  1909. CeErpTradeCell entity = null;
  1910. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1911. if (entity != null)
  1912. {
  1913. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1914. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1915. //{
  1916. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1917. // return;
  1918. //}
  1919. entity.IsPreDelivery = 1;
  1920. entity.Update();
  1921. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1922. returnSuccessMsg("预发货成功!");
  1923. return;
  1924. //string shop = GetPostString("seller_nick");
  1925. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1926. //string comName = GetPostString("comName");
  1927. //string comCode = GetPostString("comCode");
  1928. //string outSid = GetPostString("outSid");//运单号
  1929. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1930. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1931. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1932. //string apires = "";
  1933. //if (deliveryType == "虚拟发货")
  1934. //{
  1935. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1936. //}
  1937. //else
  1938. //{
  1939. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1940. //}
  1941. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1942. ////{
  1943. //if (apires.IndexOf("发货成功") != -1)
  1944. //{
  1945. // if (deliveryType != "虚拟发货")
  1946. // {
  1947. // //还要插入快递信息到 快递信息表
  1948. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1949. // exinfo.tid = eid;
  1950. // exinfo.out_sid = outSid;
  1951. // exinfo.company_code = comCode;
  1952. // exinfo.company_name = comName;
  1953. // exinfo.delivery_memo = deliveryMemo;
  1954. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1955. // exinfo.deliveryType = deliveryType;
  1956. // exinfo.Create();
  1957. // }
  1958. // returnSuccessMsg("发货成功!");
  1959. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1960. //}
  1961. //else
  1962. //{
  1963. // returnErrorMsg("淘宝发货失败!!");
  1964. //}
  1965. //return;
  1966. }
  1967. returnErrorMsg("找不到订单记录");
  1968. }
  1969. }
  1970. public void get_erp_unusuallist()
  1971. {
  1972. DataStruct dStruct = GetPostStruct();
  1973. List<string> lw = new List<string>();
  1974. string tid = GetPostString("ctid");
  1975. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1976. string shopname = GetPostString("shopname");
  1977. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1978. string buyernick = GetPostString("buyer_nick");
  1979. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1980. string ResponsibleMan = GetPostString("responsible");
  1981. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1982. string date1 = GetPostString("date1");
  1983. string date2 = GetPostString("date2");
  1984. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1985. if (dw.Length > 0) lw.Add(dw);
  1986. string price1 = GetPostString("price1");
  1987. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1988. string price2 = GetPostString("price2");
  1989. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1990. string orderState = GetPostString("orderState");
  1991. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1992. string sellermemo = GetPostString("seller_memo");
  1993. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1994. lw.Add(string.Format("UnusualTag > 0"));
  1995. lw.Add(string.Format("IsRefund<={0}", 1));
  1996. dStruct.Order = "pay_time desc";
  1997. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1998. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1999. writeGridDataTableJson(dStruct.TotalCount, dt);
  2000. }
  2001. public void set_erp_unusualtonomal()
  2002. {
  2003. if (UrlPostParmsCheck("ctid"))
  2004. {
  2005. string eid = GetPostString("ctid");
  2006. CeErpTradeCell entity = null;
  2007. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2008. if (entity != null)
  2009. {
  2010. entity.UnusualTag = -1;
  2011. entity.Update();
  2012. returnSuccessMsg("忽略成功!");
  2013. return;
  2014. }
  2015. returnErrorMsg("找不到记录");
  2016. }
  2017. }
  2018. public void ins_erp_unusualreason()
  2019. {
  2020. if (UrlPostParmsCheck("ctid"))
  2021. {
  2022. string eid = GetPostString("ctid");
  2023. CeErpTradeCell entity = null;
  2024. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2025. if (entity != null)
  2026. {
  2027. entity.MemoOpt = 4;
  2028. entity.UnusualCon = GetPostString("con");
  2029. entity.Update();
  2030. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2031. if (trade != null)
  2032. {
  2033. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2034. }
  2035. //查货是否超时
  2036. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2037. if (ceErpTradeCellExtend == null)
  2038. {
  2039. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2040. ceErpTradeCellExtend.ctid = entity.ctid;
  2041. }
  2042. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2043. {
  2044. ceErpTradeCellExtend.CheckOut += 1;
  2045. }
  2046. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2047. if (ceErpTradeCellExtend.ID > 0)
  2048. {
  2049. ceErpTradeCellExtend.Update();
  2050. }
  2051. else
  2052. {
  2053. ceErpTradeCellExtend.Create();
  2054. }
  2055. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2056. returnSuccessMsg("操作成功!");
  2057. return;
  2058. }
  2059. returnErrorMsg("找不到记录");
  2060. }
  2061. }
  2062. public void upd_erp_sampleorder()
  2063. {
  2064. if (UrlPostParmsCheck("ctid"))
  2065. {
  2066. string eid = GetPostString("ctid");
  2067. string[] eArr = eid.Split(',');
  2068. if (eArr.Length > 1)
  2069. {
  2070. List<string> eLst = new List<string>();
  2071. for (int i = 0; i < eArr.Length; i++)
  2072. {
  2073. eLst.Add("'" + eArr[i] + "'");
  2074. }
  2075. eid = string.Join(",", eLst.ToArray());
  2076. }
  2077. else
  2078. {
  2079. eid = "'" + eid + "'";
  2080. }
  2081. StringBuilder sql = new StringBuilder();
  2082. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2083. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2084. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2085. if (dt.Rows.Count > 0)
  2086. {
  2087. string errmsg = "";
  2088. foreach (DataRow dr in dt.Rows)
  2089. {
  2090. StringBuilder sqlsb = new StringBuilder();
  2091. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2092. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2093. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2094. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2095. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2096. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2097. {
  2098. continue;
  2099. }
  2100. else
  2101. {
  2102. string emsg = commonHelper.KeepChinese(apires);
  2103. errmsg += emsg;
  2104. }
  2105. }
  2106. if (errmsg.Length > 0)
  2107. {
  2108. returnErrorMsg(errmsg);
  2109. return;
  2110. }
  2111. returnSuccessMsg("操作成功");
  2112. return;
  2113. }
  2114. returnErrorMsg("找不到记录");
  2115. }
  2116. }
  2117. public void upd_erp_transcustomer()
  2118. {
  2119. if (UrlPostParmsCheck("ctid"))
  2120. {
  2121. string eid = GetPostString("ctid");
  2122. int userid = GetPostInt("CustomerUserId");
  2123. CeErpTradeCell entity = null;
  2124. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2125. if (entity != null)
  2126. {
  2127. //string[] mlist = entity.seller_memo.Split('-');
  2128. //string sql = "select * from view_erpuser where id=" + userid;
  2129. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2130. //if (dt != null && dt.Rows.Count > 0)
  2131. //{
  2132. // string nmemo = "";
  2133. // for(int i = 0; i < mlist.Length - 1; i++)
  2134. // {
  2135. // nmemo += mlist[i];
  2136. // nmemo += "-";
  2137. // }
  2138. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2139. // entity.seller_memo = nmemo;
  2140. //}
  2141. entity.CustomerUserId = userid;
  2142. entity.Update();
  2143. returnSuccessMsg("操作成功!");
  2144. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2145. return;
  2146. }
  2147. returnErrorMsg("找不到记录");
  2148. }
  2149. }
  2150. public void upd_erp_transdesigner()
  2151. {
  2152. if (UrlPostParmsCheck("ctid"))
  2153. {
  2154. string eids = GetPostString("ctid");
  2155. string[] ctidList = eids.Split(',');
  2156. int userid = GetPostInt("DesignUserId");
  2157. foreach (string ctid in ctidList)
  2158. {
  2159. CeErpTradeCell entity = null;
  2160. CeErpDesignerBill entitys = null;
  2161. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2162. entitys = CeErpDesignerBill.GetByTid(ctid);
  2163. if (entity != null)
  2164. {
  2165. if (entity.OrderState > 4)
  2166. {
  2167. continue;
  2168. }
  2169. //存在退款不能流转
  2170. if (entity.IsRefund > 0)
  2171. {
  2172. continue;
  2173. }
  2174. entity.DesignUserId = userid;
  2175. entity.WaitDesignTime = DateTime.Now;
  2176. entity.Update();
  2177. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2178. }
  2179. }
  2180. returnSuccessMsg("操作成功!");
  2181. }
  2182. }
  2183. public void upd_erp_distributedesigner()
  2184. {
  2185. if (UrlPostParmsCheck("ctid"))
  2186. {
  2187. string eid = GetPostString("ctid");
  2188. int userid = GetPostInt("DesignUserId");
  2189. string[] idlist = eid.Split(',');
  2190. if (idlist.Length <= 0)
  2191. {
  2192. returnErrorMsg("订单不能为空");
  2193. return;
  2194. }
  2195. foreach (string ctid in idlist)
  2196. {
  2197. CeErpTradeCell entity = null;
  2198. CeErpDesignerBill entitys = null;
  2199. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2200. else continue;
  2201. if (entity != null)
  2202. {
  2203. if (userid == 2125 || userid == 3542)
  2204. { }
  2205. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2206. {
  2207. returnErrorMsg("金额错误的订单无法指派");
  2208. return;
  2209. }
  2210. if (entity.OrderState >= 5)
  2211. {
  2212. returnErrorMsg("已经设计完成无法指派");
  2213. return;
  2214. }
  2215. if (entity.OrderState == -1)
  2216. {
  2217. returnErrorMsg("审核中的订单无法指派");
  2218. return;
  2219. }
  2220. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2221. {
  2222. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2223. return;
  2224. }
  2225. //157赖橙帆 159林晨 73 静之颖
  2226. 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)
  2227. {
  2228. returnErrorMsg("指派设计共创无法再次指派!");
  2229. return;
  2230. }
  2231. entity.OrderState = 3;
  2232. if (entity.SupplierId == 0)
  2233. {
  2234. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2235. entity.SupplierId = suid;
  2236. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2237. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2238. }
  2239. if (userid == 2125 && entity.seller_memo != "")
  2240. {
  2241. apiDesign.API_GetPrintData_CreateOrder(entity);
  2242. }
  2243. if (userid == 3542 && entity.seller_memo != "")
  2244. {
  2245. string userPost = CurrentUser.UserPost.Post.Code;
  2246. if (CurrentUser.UserID == 73)
  2247. {
  2248. userPost = "SysAdmin";
  2249. }
  2250. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2251. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2252. if (response.msg != "设计共创:成功")
  2253. {
  2254. returnErrorMsg(response.msg);
  2255. return;
  2256. }
  2257. entity.DispatchSort = 2;
  2258. }
  2259. else
  2260. {
  2261. if (entity.DispatchSort == 2)
  2262. {
  2263. ApiVo apiVo = new ApiVo();
  2264. apiVo.actionName = "closeDesign";
  2265. apiVo.orderNumber = entity.ctid;
  2266. designHelper.API_WorkCore(apiVo);//closeDesign
  2267. }
  2268. entity.DispatchSort = 0;
  2269. }
  2270. entity.DesignUserId = userid;
  2271. entity.WaitDesignTime = DateTime.Now;
  2272. entity.UpdateTime = DateTime.Now;
  2273. entity.Update();
  2274. string name = commonHelper.getUserNameById(userid);
  2275. commonHelper.UpdateRelationOrder(entity.ctid);
  2276. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2277. }
  2278. }
  2279. returnSuccessMsg("操作成功!");
  2280. return;
  2281. }
  2282. }
  2283. public string getTidByCtid(string ctid)
  2284. {
  2285. string tid = "";
  2286. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2287. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2288. if (dataTable != null && dataTable.Rows.Count > 0)
  2289. {
  2290. tid = dataTable.Rows[0]["tid"].ToString();
  2291. }
  2292. return tid;
  2293. }
  2294. public List<string> getTidByCtidMore(string ctid)
  2295. {
  2296. 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);
  2297. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2298. List<string> list = new List<string>();
  2299. if (dataTable != null && dataTable.Rows.Count > 0)
  2300. {
  2301. foreach (DataRow item in dataTable.Rows)
  2302. {
  2303. list.Add("'" + item["tid"].ToString() + "'");
  2304. }
  2305. }
  2306. return list;
  2307. }
  2308. public List<string> getTidByCtidLike(string ctid)
  2309. {
  2310. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2311. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2312. List<string> list = new List<string>();
  2313. if (dataTable != null && dataTable.Rows.Count > 0)
  2314. {
  2315. foreach (DataRow item in dataTable.Rows)
  2316. {
  2317. list.Add("'" + item["tid"].ToString() + "'");
  2318. }
  2319. }
  2320. return list;
  2321. }
  2322. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2323. {
  2324. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2325. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2326. List<string> list = new List<string>();
  2327. if (dataTable != null && dataTable.Rows.Count > 0)
  2328. {
  2329. foreach (DataRow item in dataTable.Rows)
  2330. {
  2331. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2332. {
  2333. continue;
  2334. }
  2335. list.Add("'" + item["receiverId"].ToString() + "'");
  2336. }
  2337. }
  2338. return list;
  2339. }
  2340. public void get_erp_myorderlist()
  2341. {
  2342. DataStruct dStruct = GetPostStruct();
  2343. List<string> lw = new List<string>();
  2344. string tid = GetPostString("ctid");
  2345. if (tid.Length > 0)
  2346. {
  2347. string select_tid = getTidByCtid(tid);
  2348. lw.Add(string.Format("tid='{0}'", select_tid));
  2349. }
  2350. else
  2351. {
  2352. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2353. }
  2354. //12-1 修改
  2355. string urgent = GetPostString("urgent");
  2356. string back = GetPostString("back");
  2357. string offlineSearch = GetPostString("offlineSearch");
  2358. if (!string.IsNullOrWhiteSpace(urgent))
  2359. {
  2360. if (urgent.Equals("true"))
  2361. {
  2362. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2363. }
  2364. }
  2365. if (!string.IsNullOrWhiteSpace(back))
  2366. {
  2367. if (back.Equals("true"))
  2368. {
  2369. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2370. }
  2371. }
  2372. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2373. {
  2374. if (offlineSearch.Equals("true"))
  2375. {
  2376. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2377. }
  2378. }
  2379. //end
  2380. string shopname = GetPostString("shopname");
  2381. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2382. string buyernick = GetPostString("buyer_nick");
  2383. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2384. string design = GetPostString("design");
  2385. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2386. string orderState = GetPostString("orderState");
  2387. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2388. string sellermemo = GetPostString("seller_memo");
  2389. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2390. string date1 = GetPostString("date1");
  2391. string date2 = GetPostString("date2");
  2392. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2393. if (dw.Length > 0) lw.Add(dw);
  2394. string price1 = GetPostString("price1");
  2395. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2396. string price2 = GetPostString("price2");
  2397. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2398. string urgency = GetPostString("urgency");
  2399. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2400. string after = GetPostString("after");
  2401. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2402. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2403. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2404. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2405. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2406. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2407. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2408. if (dt != null && dt.Rows.Count > 0)
  2409. {
  2410. foreach (DataRow dr in dt.Rows)
  2411. {
  2412. try
  2413. {
  2414. // 对象操作
  2415. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2416. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2417. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2418. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2419. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2420. if (dStruct.PageSize != 100000)
  2421. {
  2422. if (dr["DispatchSort"].ToString() == "2")
  2423. {
  2424. dr["gongchuang"] = 200;
  2425. }
  2426. else if ("外协".Equals(dr["ToType"].ToString()))
  2427. {
  2428. dr["gongchuang"] = 200;
  2429. }
  2430. else if ("内部".Equals(dr["ToType"].ToString()))
  2431. {
  2432. dr["gongchuang"] = -1;
  2433. }
  2434. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2435. {
  2436. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2437. dr["gongchuang"] = response.code;
  2438. }
  2439. }
  2440. }
  2441. catch (NullReferenceException ex)
  2442. {
  2443. }
  2444. }
  2445. }
  2446. writeGridDataTableJson(dStruct.TotalCount, dt);
  2447. }
  2448. public void get_erp_myreturnorderlist()
  2449. {
  2450. DataStruct dStruct = GetPostStruct();
  2451. List<string> lw = new List<string>();
  2452. string tid = GetPostString("ctid");
  2453. if (tid.Length > 0)
  2454. {
  2455. string select_tid = getTidByCtid(tid);
  2456. lw.Add(string.Format("tid='{0}'", select_tid));
  2457. }
  2458. else
  2459. {
  2460. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2461. }
  2462. string shopname = GetPostString("shopname");
  2463. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2464. string buyernick = GetPostString("buyer_nick");
  2465. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2466. string design = GetPostString("design");
  2467. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2468. string orderState = GetPostString("orderState");
  2469. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2470. string sellermemo = GetPostString("seller_memo");
  2471. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2472. string date1 = GetPostString("date1");
  2473. string date2 = GetPostString("date2");
  2474. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2475. if (dw.Length > 0) lw.Add(dw);
  2476. string price1 = GetPostString("price1");
  2477. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2478. string price2 = GetPostString("price2");
  2479. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2480. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2481. {
  2482. lw.Add(string.Format("CusOrgID = 94"));
  2483. }
  2484. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2485. {
  2486. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2487. }
  2488. else
  2489. {
  2490. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2491. }
  2492. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2493. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2494. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2495. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2496. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2497. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2498. if (dt != null && dt.Rows.Count > 0)
  2499. {
  2500. foreach (DataRow dr in dt.Rows)
  2501. {
  2502. try
  2503. {
  2504. // 对象操作
  2505. if (dStruct.PageSize != 100000)
  2506. {
  2507. if (dr["DispatchSort"].ToString() == "2")
  2508. {
  2509. dr["gongchuang"] = 200;
  2510. }
  2511. else if ("外协".Equals(dr["ToType"].ToString()))
  2512. {
  2513. dr["gongchuang"] = 200;
  2514. }
  2515. else if ("内部".Equals(dr["ToType"].ToString()))
  2516. {
  2517. dr["gongchuang"] = -1;
  2518. }
  2519. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2520. {
  2521. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2522. dr["gongchuang"] = response.code;
  2523. }
  2524. }
  2525. }
  2526. catch (NullReferenceException ex)
  2527. {
  2528. // 处理空引用异常
  2529. }
  2530. }
  2531. }
  2532. writeGridDataTableJson(dStruct.TotalCount, dt);
  2533. }
  2534. public void get_erp_myorderlist_pregather()
  2535. {
  2536. string date1 = GetPostString("date1");
  2537. string date2 = GetPostString("date2");
  2538. int userId = CurrentUser.UserID; //客服id
  2539. string orderWhere = "";
  2540. List<string> lw = new List<string>();
  2541. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2542. if (dw.Length > 0) lw.Add(dw);
  2543. lw.Add(string.Format("CustomerUserId={0}", userId));
  2544. lw.Add(string.Format("OrderState<9"));
  2545. orderWhere = string.Join(" and ", lw.ToArray());
  2546. string orderWhere2 = "";
  2547. List<string> lw2 = new List<string>();
  2548. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2549. if (dw2.Length > 0) lw2.Add(dw2);
  2550. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2551. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2552. string sql = string.Format("select *" +
  2553. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2554. "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 " +
  2555. "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 " +
  2556. "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");
  2557. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2558. //writeGridDataTableJson(dt.Rows.Count, dt);
  2559. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2560. }
  2561. public void upd_erp_publishorder()
  2562. {
  2563. if (UrlPostParmsCheck("ctid"))
  2564. {
  2565. string eid = GetPostString("ctid");
  2566. CeErpTradeCell entity = null;
  2567. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2568. if (entity != null)
  2569. {
  2570. entity.OrderState = 0; //发布后,变为待抢单
  2571. entity.Update();
  2572. commonHelper.UpdateRelationOrder(entity.ctid);
  2573. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2574. returnSuccessMsg("发布成功!");
  2575. return;
  2576. }
  2577. returnErrorMsg("找不到记录");
  2578. }
  2579. }
  2580. public void get_erp_my_tiporder()
  2581. {
  2582. StringBuilder sql = new StringBuilder();
  2583. int userId = 0;
  2584. if (CurrentUser != null) userId = CurrentUser.UserID;
  2585. string posCode = CurrentUser.UserPost.Post.Code;
  2586. string isTipedAfterSaleVerify = GetPostString("af");
  2587. DataTable dt = new DataTable();
  2588. if (posCode != "Supplier")
  2589. {
  2590. if (posCode == "CustomerService" || posCode == "Director")
  2591. {
  2592. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2593. }
  2594. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2595. {
  2596. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2597. }
  2598. else
  2599. {
  2600. string teamIds = CurrentUser.User.TeamIds;
  2601. if (teamIds == "")
  2602. {
  2603. teamIds = "0";
  2604. }
  2605. 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);
  2606. }
  2607. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2608. }
  2609. if (dt.Rows.Count <= 0)
  2610. {
  2611. string key = "aftersale_order_" + userId;
  2612. if (RedisHelper.HasKey(key))
  2613. {
  2614. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2615. dt.Columns.Add("ctid", typeof(string));
  2616. dt.Columns.Add("IsReadTag", typeof(int));
  2617. foreach (var i in list)
  2618. {
  2619. DataRow data = dt.NewRow();
  2620. data["ctid"] = i;
  2621. data["IsReadTag"] = 4;
  2622. dt.Rows.Add(data);
  2623. }
  2624. RedisHelper.StringDelete(key);
  2625. }
  2626. }
  2627. if (dt.Rows.Count <= 0)
  2628. {
  2629. sql = new StringBuilder();
  2630. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2631. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2632. }
  2633. if (posCode == "Supplier")
  2634. {
  2635. string ids = CurrentUser.User.pemVend;
  2636. if (ids != null && ids.Length > 0)
  2637. {
  2638. string[] ids_list = ids.Split(',');
  2639. foreach (var item in ids_list)
  2640. {
  2641. string key = "return_order_" + item;
  2642. if (RedisHelper.HasKey(key))
  2643. {
  2644. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2645. dt.Columns.Add("ctid", typeof(string));
  2646. dt.Columns.Add("IsReadTag", typeof(int));
  2647. foreach (var i in list)
  2648. {
  2649. DataRow data = dt.NewRow();
  2650. data["ctid"] = i;
  2651. data["IsReadTag"] = 1;
  2652. dt.Rows.Add(data);
  2653. }
  2654. RedisHelper.StringDelete(key);
  2655. }
  2656. }
  2657. }
  2658. if (dt.Rows.Count <= 0)
  2659. {
  2660. sql = new StringBuilder();
  2661. 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);
  2662. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2663. }
  2664. }
  2665. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2666. }
  2667. public void reset_erp_tiporder()
  2668. {
  2669. string ids = GetPostString("ids");
  2670. string[] ctidList = ids.Split(',');
  2671. foreach (string ctid in ctidList)
  2672. {
  2673. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2674. if (enty != null)
  2675. {
  2676. enty.IsReadTag = 0;
  2677. enty.Update();
  2678. }
  2679. }
  2680. returnSuccessMsg("成功!");
  2681. return;
  2682. }
  2683. public void get_erp_designlist()
  2684. {
  2685. DataStruct dStruct = GetPostStruct();
  2686. List<string> lw = new List<string>();
  2687. string tid = GetPostString("ctid");
  2688. if (tid.Length > 0)
  2689. {
  2690. string select_tid = getTidByCtid(tid);
  2691. lw.Add(string.Format("tid='{0}'", select_tid));
  2692. }
  2693. string shopname = GetPostString("shopname");
  2694. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2695. string buyernick = GetPostString("buyer_nick");
  2696. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2697. string customer = GetPostString("customer");
  2698. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2699. string design = GetPostString("design");
  2700. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2701. string orderState = GetPostString("orderState");
  2702. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2703. lw.Add(string.Format("OrderState<6"));
  2704. string address = GetPostString("address");
  2705. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2706. string sellermemo = GetPostString("seller_memo");
  2707. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2708. string date1 = GetPostString("date1");
  2709. string date2 = GetPostString("date2");
  2710. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2711. if (dw.Length > 0) lw.Add(dw);
  2712. string apdate1 = GetPostString("apdate1");
  2713. string apdate2 = GetPostString("apdate2");
  2714. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2715. if (dwap.Length > 0) lw.Add(dwap);
  2716. string price1 = GetPostString("price1");
  2717. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2718. string price2 = GetPostString("price2");
  2719. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2720. string designTime = GetPostString("designtime");
  2721. if (designTime.Length > 0)
  2722. {
  2723. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2724. }
  2725. string usershop = CurrentUser.User.pemShop;
  2726. if (usershop.Length > 0)
  2727. {
  2728. lw.Add(string.Format("shopId in ({0})", usershop));
  2729. }
  2730. int myOrgid = CurrentUser.UserPost.OrgID;
  2731. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2732. if (myOrgCode.IndexOf("Designer") != -1)
  2733. {
  2734. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2735. {
  2736. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2737. }
  2738. else
  2739. {
  2740. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2741. }
  2742. }
  2743. else
  2744. {
  2745. string orgId = GetPostString("designerhd");
  2746. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2747. }
  2748. if (tid.Length > 0 || buyernick.Length > 0)
  2749. {
  2750. lw.Add(string.Format("OrderState >= 3"));
  2751. }
  2752. else
  2753. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2754. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2755. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2756. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2757. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2758. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2759. if (dt != null && dt.Rows.Count > 0)
  2760. {
  2761. foreach (DataRow dr in dt.Rows)
  2762. {
  2763. try
  2764. {
  2765. // 对象操作
  2766. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2767. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2768. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2769. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2770. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2771. if (dStruct.PageSize != 100000)
  2772. {
  2773. if (dr["DispatchSort"].ToString() == "2")
  2774. {
  2775. dr["gongchuang"] = 200;
  2776. }
  2777. else if ("外协".Equals(dr["ToType"].ToString()))
  2778. {
  2779. dr["gongchuang"] = 200;
  2780. }
  2781. else if ("内部".Equals(dr["ToType"].ToString()))
  2782. {
  2783. dr["gongchuang"] = -1;
  2784. }
  2785. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2786. {
  2787. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2788. dr["gongchuang"] = response.code;
  2789. }
  2790. }
  2791. }
  2792. catch (NullReferenceException ex)
  2793. {
  2794. }
  2795. }
  2796. }
  2797. writeGridDataTableJson(dStruct.TotalCount, dt);
  2798. }
  2799. public void get_erp_mydesignlist()
  2800. {
  2801. DataStruct dStruct = GetPostStruct();
  2802. List<string> lw = new List<string>();
  2803. string tid = GetPostString("ctid");
  2804. if (tid.Length > 0)
  2805. {
  2806. string select_tid = getTidByCtid(tid);
  2807. lw.Add(string.Format("tid='{0}'", select_tid));
  2808. }
  2809. string shopname = GetPostString("shopname");
  2810. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2811. string buyernick = GetPostString("buyer_nick");
  2812. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2813. string customer = GetPostString("customer");
  2814. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2815. string orderState = GetPostString("orderState");
  2816. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2817. //lw.Add(string.Format("OrderState<6"));
  2818. string date1 = GetPostString("date1");
  2819. string date2 = GetPostString("date2");
  2820. string dw = GetDateWhere("pay_time", date1, date2);
  2821. if (dw.Length > 0) lw.Add(dw);
  2822. string apdate1 = GetPostString("apdate1");
  2823. string apdate2 = GetPostString("apdate2");
  2824. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2825. if (dwap.Length > 0) lw.Add(dwap);
  2826. string price1 = GetPostString("price1");
  2827. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2828. string price2 = GetPostString("price2");
  2829. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2830. string olddownload = GetPostString("olddown");
  2831. if (olddownload == "1")
  2832. {
  2833. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2834. }
  2835. else if (olddownload == "2")
  2836. {
  2837. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2838. }
  2839. string sellermemo = GetPostString("seller_memo");
  2840. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2841. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2842. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2843. {
  2844. if (CurrentUser.User.TeamIds.Length > 0)
  2845. {
  2846. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2847. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2848. else
  2849. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2850. }
  2851. else
  2852. {
  2853. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2854. }
  2855. }
  2856. if (tid.Length <= 0)
  2857. {
  2858. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2859. }
  2860. lw.Add(string.Format("IsReturn!=3"));
  2861. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2862. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2863. string teamids = CurrentUser.User.TeamIds.ToString();
  2864. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2865. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2866. if (dt != null && dt.Rows.Count > 0)
  2867. {
  2868. foreach (DataRow dr in dt.Rows)
  2869. {
  2870. try
  2871. {
  2872. // 对象操作
  2873. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2874. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2875. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2876. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2877. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2878. if (dStruct.PageSize != 100000)
  2879. {
  2880. if (dr["DispatchSort"].ToString() == "2")
  2881. {
  2882. dr["gongchuang"] = 200;
  2883. }
  2884. else if ("外协".Equals(dr["ToType"].ToString()))
  2885. {
  2886. dr["gongchuang"] = 200;
  2887. }
  2888. else if ("内部".Equals(dr["ToType"].ToString()))
  2889. {
  2890. dr["gongchuang"] = -1;
  2891. }
  2892. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2893. {
  2894. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2895. dr["gongchuang"] = response.code;
  2896. }
  2897. }
  2898. }
  2899. catch (NullReferenceException ex)
  2900. {
  2901. }
  2902. }
  2903. }
  2904. writeGridDataTableJson(dStruct.TotalCount, dt);
  2905. }
  2906. public void set_erp_startdesign()
  2907. {
  2908. if (UrlPostParmsCheck("ctid"))
  2909. {
  2910. string eid = GetPostString("ctid");
  2911. CeErpTradeCell entity = null;
  2912. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2913. if (entity != null)
  2914. {
  2915. if (entity.OrderState != 3)
  2916. {
  2917. returnErrorMsg("请刷新,订单已经设计了");
  2918. return;
  2919. }
  2920. entity.StartDesignTime = DateTime.Now;
  2921. entity.OrderState = 4;
  2922. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2923. {
  2924. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2925. entity.SupplierId = suid;
  2926. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2927. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2928. }
  2929. entity.UpdateTime = DateTime.Now;
  2930. //entity.MakeSupplier = suname;
  2931. entity.Update();
  2932. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2933. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2934. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2935. commonHelper.getCytPrice(entity);
  2936. returnSuccessMsg("操作成功!");
  2937. return;
  2938. }
  2939. returnErrorMsg("找不到记录");
  2940. }
  2941. }
  2942. public void ins_erp_designselfmemo()
  2943. {
  2944. if (UrlPostParmsCheck("ctid"))
  2945. {
  2946. string eid = GetPostString("ctid");
  2947. string con = GetPostString("con");
  2948. CeErpTradeCell entity = null;
  2949. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2950. if (entity != null)
  2951. {
  2952. entity.DesignSelfMemo = con;
  2953. entity.Update();
  2954. returnSuccessMsg("操作成功!");
  2955. return;
  2956. }
  2957. returnErrorMsg("找不到记录");
  2958. }
  2959. }
  2960. public void ins_erp_designprice()
  2961. {
  2962. if (UrlPostParmsCheck("ctid"))
  2963. {
  2964. string eid = GetPostString("ctid");
  2965. int uid = CurrentUser.UserID;
  2966. string userName = CurrentUser.UserName;
  2967. CeErpTradeCell entity = null;
  2968. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2969. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2970. if (entitys == null)
  2971. {
  2972. entitys = new CeErpDesignerBill();
  2973. }
  2974. if (entity != null)
  2975. {
  2976. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2977. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2978. entity.StartDesignTime = DateTime.Now;
  2979. entity.OrderState = 4;
  2980. string suname = "";
  2981. if (entity.SupplierId == 0)
  2982. {
  2983. int sid = commonHelper.autoDistributeToSupplier(entity);
  2984. entity.SupplierId = sid;
  2985. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2986. }
  2987. entity.Update();
  2988. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2989. if (ceErpUserPost != null)
  2990. {
  2991. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2992. if (ceErpPost != null)
  2993. {
  2994. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2995. {
  2996. entitys.tid = entity.ctid;
  2997. entitys.oid = entity.tid;
  2998. entitys.uid = uid;
  2999. entitys.userName = userName;
  3000. entitys.designerType = 1;
  3001. entitys.designerTypeText = "内部设计师";
  3002. entitys.price = Convert.ToDouble(GetPostString("price"));
  3003. entitys.designNum = GetPostInt("designNum");
  3004. entitys.modifyNum = GetPostInt("modifyNum");
  3005. entitys.designSize = GetPostString("designSize");
  3006. entitys.modifySize = GetPostString("modifySize");
  3007. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3008. {
  3009. entitys.create_time = DateTime.Now;
  3010. entitys.create_u_id = uid;
  3011. entitys.create_u_name = userName;
  3012. entitys.Save();
  3013. }
  3014. else
  3015. {
  3016. entitys.update_time = DateTime.Now;
  3017. entitys.update_u_id = uid;
  3018. entitys.update_u_name = userName;
  3019. entitys.Update();
  3020. }
  3021. }
  3022. }
  3023. }
  3024. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3025. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3026. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3027. if (suname != "")
  3028. {
  3029. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3030. }
  3031. commonHelper.getCytPrice(entity);
  3032. returnSuccessMsg("操作成功!");
  3033. return;
  3034. }
  3035. returnErrorMsg("找不到记录");
  3036. }
  3037. }
  3038. public void upload_erp_filecomplete()
  3039. {
  3040. if (UrlPostParmsCheck("ctid"))
  3041. {
  3042. string eid = GetPostString("ctid");
  3043. CeErpTradeCell entity = null;
  3044. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3045. if (entity != null)
  3046. {
  3047. entity.OrderState = 5; //设计完成
  3048. entity.Update();
  3049. returnSuccessMsg(eid + "上传成功,设计完成!");
  3050. return;
  3051. }
  3052. returnErrorMsg("找不到订单记录");
  3053. }
  3054. }
  3055. public void get_erp_designovertimelist()
  3056. {
  3057. DataStruct dStruct = GetPostStruct();
  3058. List<string> lw = new List<string>();
  3059. string tid = GetPostString("ctid");
  3060. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3061. string shopname = GetPostString("shopname");
  3062. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3063. string buyernick = GetPostString("buyer_nick");
  3064. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3065. string ResponsibleMan = GetPostString("responsible");
  3066. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3067. string date1 = GetPostString("date1");
  3068. string date2 = GetPostString("date2");
  3069. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3070. if (dw.Length > 0) lw.Add(dw);
  3071. string price1 = GetPostString("price1");
  3072. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3073. string price2 = GetPostString("price2");
  3074. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3075. string orderState = GetPostString("orderState");
  3076. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3077. string sellermemo = GetPostString("seller_memo");
  3078. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3079. lw.Add(string.Format("UnusualTag=3"));
  3080. lw.Add(string.Format("IsRefund<={0}", 1));
  3081. dStruct.Order = "WaitDesignTime desc";
  3082. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3083. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3084. writeGridDataTableJson(dStruct.TotalCount, dt);
  3085. }
  3086. //设计管理 获取抢单大厅列表
  3087. public void get_erp_grabinglist()
  3088. {
  3089. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3090. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3091. bool oldOrder = false;
  3092. if (org != null)
  3093. {
  3094. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3095. }
  3096. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3097. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3098. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3099. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3100. //先处理订单数据
  3101. if (dt.Rows.Count > 0)
  3102. {
  3103. Dictionary<string, int> design = null;
  3104. int count = 0;
  3105. foreach (DataRow row in dt.Rows)
  3106. {
  3107. if (map.ContainsKey(row["ShopId"].ToString()))
  3108. {
  3109. map.TryGetValue(row["ShopId"].ToString(), out design);
  3110. }
  3111. else
  3112. {
  3113. design = new Dictionary<string, int>();
  3114. }
  3115. if (design.ContainsKey(row["ProductId"].ToString()))
  3116. {
  3117. design.TryGetValue(row["ProductId"].ToString(), out count);
  3118. }
  3119. count++;
  3120. design[row["ProductId"].ToString()] = count;
  3121. map[row["ShopId"].ToString()] = design;
  3122. }
  3123. }
  3124. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3125. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3126. //把店铺排序和技能排序分类
  3127. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3128. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3129. if (design_dt.Rows.Count > 0)
  3130. {
  3131. Dictionary<string, string> design = null;
  3132. List<string> shopIds = null;
  3133. foreach (DataRow row in design_dt.Rows)
  3134. {
  3135. if ("0".Equals(row["designId"].ToString()))
  3136. {
  3137. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3138. {
  3139. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3140. }
  3141. else
  3142. {
  3143. shopIds = new List<string>();
  3144. }
  3145. shopIds.Add(row["shopId"].ToString());
  3146. shop_orders[row["orders"].ToString()] = shopIds;
  3147. }
  3148. else
  3149. {
  3150. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3151. {
  3152. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3153. }
  3154. else
  3155. {
  3156. design = new Dictionary<string, string>();
  3157. }
  3158. design[row["orders"].ToString()] = row["designId"].ToString();
  3159. design_orders[row["shopId"].ToString()] = design;
  3160. }
  3161. }
  3162. //处理成key value后根据key排序
  3163. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3164. foreach (List<string> val in shop_orders.Values)
  3165. {
  3166. if (val != null)
  3167. {
  3168. foreach (string key in val)
  3169. {
  3170. if (design_orders.ContainsKey(key.ToString()))
  3171. {
  3172. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3173. }
  3174. }
  3175. }
  3176. }
  3177. }
  3178. //校验哪个优先级有订单
  3179. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3180. foreach (string key in shop_orders.Keys)
  3181. {
  3182. List<string> ids = null;
  3183. shop_orders.TryGetValue(key, out ids);
  3184. //id为shopid
  3185. foreach (string id in ids)
  3186. {
  3187. Dictionary<string, int> list = null;
  3188. Dictionary<string, string> desing = null;
  3189. map.TryGetValue(id, out list);
  3190. design_orders.TryGetValue(id, out desing);
  3191. if (list != null && desing != null)
  3192. {
  3193. foreach (var item in desing)
  3194. {
  3195. int count = 0;
  3196. if (list.ContainsKey(item.Value))
  3197. {
  3198. list.TryGetValue(item.Value, out count);
  3199. if (count > 0)
  3200. {
  3201. designIds[id] = item.Value;
  3202. break;
  3203. }
  3204. }
  3205. }
  3206. }
  3207. }
  3208. if (designIds.Count > 0)
  3209. {
  3210. break;
  3211. }
  3212. }
  3213. DataTable table = new DataTable();
  3214. table.Columns.Add("tid", typeof(string));
  3215. table.Columns.Add("ctid", typeof(string));
  3216. table.Columns.Add("seller_nick", typeof(string));
  3217. table.Columns.Add("productName", typeof(string));
  3218. table.Columns.Add("pay_time", typeof(string));
  3219. table.Columns.Add("seller_memo", typeof(string));
  3220. if (designIds.Count > 0)
  3221. {
  3222. string shopId = "";
  3223. string productId = "";
  3224. foreach (var designInfo in designIds)
  3225. {
  3226. shopId = designInfo.Key;
  3227. productId = designInfo.Value;
  3228. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3229. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3230. if (dt.Rows.Count > 0)
  3231. {
  3232. foreach (DataRow row in dt.Rows)
  3233. {
  3234. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3235. {
  3236. DataRow data = table.NewRow();
  3237. data["ctid"] = row["ctid"].ToString();
  3238. data["tid"] = row["tid"].ToString();
  3239. data["seller_nick"] = ceErpShop.ShopName;
  3240. data["pay_time"] = row["pay_time"].ToString();
  3241. data["seller_memo"] = row["seller_memo"].ToString();
  3242. data["productName"] = ceErpProduct.PType;
  3243. table.Rows.Add(data);
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. writeGridDataTableJson(table.Rows.Count, table);
  3250. }
  3251. private object rushLockObject = new object();
  3252. public void set_erp_grabingorder()
  3253. {
  3254. if (UrlPostParmsCheck("ctid"))
  3255. {
  3256. int total = CurrentUser.User.Person.Total;
  3257. int userId = CurrentUser.User.ID;
  3258. int noFinish = CurrentUser.User.Person.NoFinish;
  3259. int finalization = CurrentUser.User.Person.Finalization;
  3260. string eids = GetPostString("ctid");
  3261. string key = "RushKey_" + userId;
  3262. int count = 0;
  3263. if (erpRedis.RedisHelper.KeyExists(key))
  3264. {
  3265. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3266. if (redisCount != null)
  3267. {
  3268. count = Convert.ToInt32(redisCount);
  3269. }
  3270. }
  3271. if (count >= total)
  3272. {
  3273. returnErrorMsg("半小时内已经抢" + total + "单");
  3274. return;
  3275. }
  3276. string[] ctidlist = eids.Split(',');
  3277. if (count + ctidlist.Length > total)
  3278. {
  3279. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3280. return;
  3281. }
  3282. int itag = 0;
  3283. lock (rushLockObject)
  3284. {
  3285. if (ctidlist.Length > 0)
  3286. {
  3287. string[] dtList = new string[ctidlist.Length];
  3288. for (int i = 0; i < ctidlist.Length; i++)
  3289. {
  3290. dtList[i] = "'" + ctidlist[i] + "'";
  3291. }
  3292. 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"));
  3293. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3294. if (dt_user.Rows.Count > 0)
  3295. {
  3296. int doing = 0;//未定稿
  3297. int finish = 0;//已完成
  3298. foreach (DataRow dr in dt_user.Rows)
  3299. {
  3300. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3301. {
  3302. doing++;
  3303. }
  3304. else
  3305. {
  3306. finish++;
  3307. }
  3308. }
  3309. if (doing >= noFinish)
  3310. {
  3311. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3312. return;
  3313. }
  3314. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3315. {
  3316. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3317. return;
  3318. }
  3319. }
  3320. //校验选择单子状态
  3321. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3322. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3323. if (dt.Rows.Count > 0)
  3324. {
  3325. List<string> list = new List<string>();
  3326. foreach (DataRow dr in dt.Rows)
  3327. {
  3328. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3329. {
  3330. list.Add(dr["ctid"].ToString());
  3331. }
  3332. }
  3333. if (list.Count > 0)
  3334. {
  3335. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3336. return;
  3337. }
  3338. }
  3339. foreach (string ctid in ctidlist)
  3340. {
  3341. CeErpTradeCell entity = null;
  3342. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3343. if (entity != null)
  3344. {
  3345. entity.OrderState = 3;
  3346. entity.DesignUserId = CurrentUser.UserID;
  3347. entity.WaitDesignTime = DateTime.Now;
  3348. entity.StartDesignTime = DateTime.Now;
  3349. entity.Update();
  3350. commonHelper.UpdateRelationOrder(entity.ctid);
  3351. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3352. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3353. itag++;
  3354. }
  3355. }
  3356. }
  3357. }
  3358. count += ctidlist.Length;
  3359. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3360. if (itag == 0)
  3361. returnErrorMsg("没有找到相关订单");
  3362. else
  3363. returnSuccessMsg("抢单成功!");
  3364. return;
  3365. }
  3366. }
  3367. public void get_erp_waitorderlist()
  3368. {
  3369. DataStruct dStruct = GetPostStruct();
  3370. List<string> lw = new List<string>();
  3371. string tid = GetPostString("ctid");
  3372. if (tid.Length > 0)
  3373. {
  3374. string select_tid = getTidByCtid(tid);
  3375. lw.Add(string.Format("tid='{0}'", select_tid));
  3376. }
  3377. string shopname = GetPostString("shopname");
  3378. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3379. string buyernick = GetPostString("buyer_nick");
  3380. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3381. string customer = GetPostString("customer");
  3382. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3383. string design = GetPostString("design");
  3384. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3385. string orderState = GetPostString("orderState");
  3386. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3387. string supplier = GetPostString("supplier");
  3388. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3389. string sellermemo = GetPostString("seller_memo");
  3390. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3391. string otherMemo = GetPostString("otherMemo");
  3392. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3393. string address = GetPostString("address");
  3394. 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));
  3395. string date1 = GetPostString("date1");
  3396. string date2 = GetPostString("date2");
  3397. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3398. if (dw.Length > 0) lw.Add(dw);
  3399. string price1 = GetPostString("price1");
  3400. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3401. string price2 = GetPostString("price2");
  3402. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3403. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3404. lw.Add(string.Format("IsSample != 2 "));
  3405. lw.Add(string.Format("OrderState = 5 "));
  3406. lw.Add(string.Format("IsRefund<={0}", 1));
  3407. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3408. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3409. string pagesize = GetPostString("pagesize");
  3410. if (pagesize != null)
  3411. {
  3412. dStruct.PageSize = 200;
  3413. }
  3414. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3415. if (dt != null)
  3416. {
  3417. foreach (DataRow dr in dt.Rows)
  3418. {
  3419. 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();
  3420. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3421. {
  3422. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3423. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3424. entity.SupplierId = suid;
  3425. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3426. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3427. entity.Update();
  3428. }
  3429. }
  3430. }
  3431. writeGridDataTableJson(dStruct.TotalCount, dt);
  3432. }
  3433. public void get_erp_supplierwaitorderlist()
  3434. {
  3435. DataStruct dStruct = GetPostStruct();
  3436. List<string> lw = new List<string>();
  3437. string tid = GetPostString("ctid");
  3438. if (tid.Length > 0)
  3439. {
  3440. string select_tid = getTidByCtid(tid);
  3441. lw.Add(string.Format("tid='{0}'", select_tid));
  3442. }
  3443. string shopname = GetPostString("shopname");
  3444. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3445. string sellermemo = GetPostString("seller_memo");
  3446. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3447. string date1 = GetPostString("date1");
  3448. string date2 = GetPostString("date2");
  3449. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3450. if (dw.Length > 0) lw.Add(dw);
  3451. lw.Add(string.Format("OrderState = 5 "));
  3452. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3453. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3454. {
  3455. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3456. }
  3457. string supplier = GetPostString("supplier");
  3458. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3459. {
  3460. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3461. }
  3462. lw.Add(string.Format("IsRefund<={0}", 1));
  3463. dStruct.Order = "FinishDesignTime desc";
  3464. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3465. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3466. if (dt != null)
  3467. {
  3468. foreach (DataRow dr in dt.Rows)
  3469. {
  3470. 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();
  3471. }
  3472. }
  3473. writeGridDataTableJson(dStruct.TotalCount, dt);
  3474. }
  3475. public void upd_erp_verifytosupplier()
  3476. {
  3477. if (UrlPostParmsCheck("ctid"))
  3478. {
  3479. string eids = GetPostString("ctid");
  3480. CeErpTradeCell entity = null;
  3481. string[] eidsList = eids.Split(',');
  3482. if (eidsList.Length <= 0)
  3483. {
  3484. returnErrorMsg("订单号不能空");
  3485. return;
  3486. }
  3487. List<string> tLst = new List<string>();
  3488. foreach (string ctidstr in eidsList)
  3489. {
  3490. tLst.Add("'" + ctidstr + "'");
  3491. CeErpDataSendOrderInfo.createObject(ctidstr);
  3492. }
  3493. string needtids = string.Join(",", tLst.ToArray());
  3494. StringBuilder sql = new StringBuilder();
  3495. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3496. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3497. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3498. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3499. returnSuccessMsg("操作成功!");
  3500. return;
  3501. /**foreach (string ctidstr in eidsList)
  3502. {
  3503. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3504. if (entity != null)
  3505. {
  3506. if (entity.SupplierId == 0)
  3507. {
  3508. continue;
  3509. }
  3510. entity.IsVerifyToSupplier = true;
  3511. if (entity.IsReturn == 1) //1是供应商打回
  3512. {
  3513. entity.IsReturn = 0;
  3514. }
  3515. entity.FinishPlaceTime = DateTime.Now;
  3516. entity.PlaceUserId = CurrentUser.UserID;
  3517. entity.Update();
  3518. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3519. }
  3520. }
  3521. returnSuccessMsg("操作成功!");
  3522. return;**/
  3523. }
  3524. }
  3525. public void upd_erp_supplierback()
  3526. {
  3527. if (UrlPostParmsCheck("ctid"))
  3528. {
  3529. string eid = GetPostString("ctid");
  3530. string reason = GetPostString("returnreason");
  3531. CeErpTradeCell entity = null;
  3532. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3533. if (entity != null)
  3534. {
  3535. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3536. {
  3537. string key = "return_order_" + entity.SupplierId;
  3538. List<string> list = new List<string>();
  3539. if (RedisHelper.HasKey(key))
  3540. {
  3541. object data = RedisHelper.StringGet(key);
  3542. list = Convert.ToString(data).Split(',').ToList();
  3543. }
  3544. list.Add(eid);
  3545. RedisHelper.StringSet(key, string.Join(",", list));
  3546. }
  3547. entity.IsVerifyToSupplier = false;
  3548. entity.IsReturn = 1;
  3549. entity.ReturnTime = DateTime.Now;
  3550. entity.ReturnReason = reason;
  3551. if (entity.OrderState == 6)
  3552. {
  3553. entity.OrderState = 5;
  3554. }
  3555. entity.Update();
  3556. CeErpSukuraData.createInfo(entity.ctid, 5);
  3557. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3558. returnSuccessMsg("操作成功!");
  3559. return;
  3560. }
  3561. returnErrorMsg("找不到订单记录");
  3562. }
  3563. }
  3564. public void upd_erp_toaftersaleorder()
  3565. {
  3566. if (UrlPostParmsCheck("ctid"))
  3567. {
  3568. string eid = GetPostString("ctid");
  3569. string reason = GetPostString("returnreason");
  3570. CeErpTradeCell entity = null;
  3571. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3572. if (entity != null)
  3573. {
  3574. if (entity.isAfterSaleOrder != 1)
  3575. {
  3576. returnErrorMsg("带S的售后单才能打回给售后");
  3577. return;
  3578. }
  3579. if (entity.OrderState >= 5)
  3580. {
  3581. returnErrorMsg("已经设计完成了不能打回给售后");
  3582. return;
  3583. }
  3584. entity.OrderState = 0;
  3585. entity.IsReturn = 3;
  3586. entity.ReturnTime = DateTime.Now;
  3587. entity.UpdateTime = DateTime.Now;
  3588. entity.ReturnReason = reason;
  3589. entity.Update();
  3590. CeErpSukuraData.createInfo(entity.ctid, 5);
  3591. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3592. returnSuccessMsg("操作成功!");
  3593. return;
  3594. }
  3595. returnErrorMsg("找不到订单记录");
  3596. }
  3597. }
  3598. public void upd_erp_aftersaletodesign()
  3599. {
  3600. if (UrlPostParmsCheck("ctid"))
  3601. {
  3602. string eid = GetPostString("ctid");
  3603. CeErpTradeCell entity = null;
  3604. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3605. if (entity != null)
  3606. {
  3607. entity.OrderState = 3;
  3608. entity.IsReturn = 0;
  3609. entity.UpdateTime = DateTime.Now;
  3610. entity.Update();
  3611. CeErpSukuraData.createInfo(entity.ctid, 5);
  3612. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3613. returnSuccessMsg("操作成功!");
  3614. return;
  3615. }
  3616. returnErrorMsg("找不到订单记录");
  3617. }
  3618. }
  3619. public void assign_erp_supplier()
  3620. {
  3621. if (UrlPostParmsCheck("ctid"))
  3622. {
  3623. string eids = GetPostString("ctid");
  3624. int sid = GetPostInt("SupplierName");
  3625. string fromTag = GetPostString("tag");
  3626. string[] eidList = eids.Split(',');
  3627. if (eidList.Length <= 0)
  3628. {
  3629. returnErrorMsg("指派不能为空");
  3630. return;
  3631. }
  3632. string errMsg = "";
  3633. string suname = commonHelper.getSupplierNameById(sid);
  3634. foreach (string ctid in eidList)
  3635. {
  3636. CeErpTradeCell entity = null;
  3637. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3638. if (entity != null)
  3639. {
  3640. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3641. {
  3642. errMsg += (ctid + "指派失败!!!");
  3643. continue;
  3644. }
  3645. entity.SupplierId = sid;
  3646. entity.Update();
  3647. commonHelper.UpdateRelationOrder(entity.ctid);
  3648. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3649. if (entity.OrderState >= 6)
  3650. {
  3651. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3652. //{
  3653. // string msl = entity.MakeSupplier;
  3654. // string[] mslist = msl.Split(',');
  3655. // 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);
  3656. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3657. //}
  3658. //else
  3659. //{
  3660. StringBuilder sql = new StringBuilder();
  3661. 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);
  3662. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3663. //}
  3664. }
  3665. }
  3666. else
  3667. {
  3668. continue;
  3669. }
  3670. }
  3671. if (errMsg.Length > 0)
  3672. {
  3673. returnErrorMsg(errMsg);
  3674. return;
  3675. }
  3676. returnSuccessMsg("操作成功!");
  3677. return;
  3678. }
  3679. }
  3680. public void assign_erp_makesupplier()
  3681. {
  3682. if (UrlPostParmsCheck("ctid"))
  3683. {
  3684. string eids = GetPostString("ctid");
  3685. string sname = GetPostString("SupplierName");
  3686. string[] eidList = eids.Split(',');
  3687. if (eidList.Length <= 0)
  3688. {
  3689. returnErrorMsg("指派不能为空");
  3690. return;
  3691. }
  3692. List<string> tLst = new List<string>();
  3693. foreach (string ctid in eidList)
  3694. {
  3695. CeErpTradeCell entity = null;
  3696. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3697. if (entity != null)
  3698. {
  3699. entity.MakeSupplier = sname;
  3700. entity.Update();
  3701. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3702. tLst.Add("'" + ctid + "'");
  3703. }
  3704. else
  3705. {
  3706. continue;
  3707. }
  3708. }
  3709. string ctids = string.Join(",", tLst.ToArray());
  3710. StringBuilder sql2 = new StringBuilder();
  3711. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3712. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3713. returnSuccessMsg("操作成功!");
  3714. return;
  3715. }
  3716. }
  3717. public void ins_erp_returnreason()
  3718. {
  3719. if (UrlPostParmsCheck("ctid"))
  3720. {
  3721. string eid = GetPostString("ctid");
  3722. CeErpTradeCell entity = null;
  3723. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3724. string userpost = CurrentUser.UserPost.Post.Code;
  3725. if (entity != null)
  3726. {
  3727. bool isPlace = false;
  3728. if (entity.OrderState > 6)
  3729. {
  3730. returnErrorMsg("已发货无法打回!");
  3731. return;
  3732. }
  3733. if (entity.OrderState == 6)
  3734. {
  3735. isPlace = true;
  3736. }
  3737. bool isNeedUpdateCell2 = false;
  3738. if (entity.OrderState >= 6)
  3739. {
  3740. isNeedUpdateCell2 = true;
  3741. }
  3742. int returnTag = 2;
  3743. if (userpost == "Supplier")
  3744. {
  3745. returnTag = 1;
  3746. }
  3747. int toType = GetPostInt("totype");
  3748. string fromType = "3";
  3749. if (entity.OrderState < 5)
  3750. {
  3751. fromType = "3";
  3752. }
  3753. else
  3754. {
  3755. fromType = "4";
  3756. }
  3757. if (entity.IsXianHuo == 0)
  3758. {
  3759. if (returnTag == 2)
  3760. {
  3761. if (toType == 1)
  3762. {
  3763. entity.OrderState = 0;
  3764. entity.ReturnUserType = 1;
  3765. string clearman = GetPostString("clearman");
  3766. if (!string.IsNullOrEmpty(clearman))
  3767. {
  3768. entity.DesignUserId = 0;
  3769. }
  3770. }
  3771. else
  3772. {
  3773. entity.OrderState = 3;
  3774. entity.ReturnUserType = 2;
  3775. }
  3776. entity.IsReadTag = 1;
  3777. }
  3778. else if (returnTag == 1)
  3779. {
  3780. entity.OrderState = 5;
  3781. }
  3782. entity.IsVerifyToSupplier = false;
  3783. }
  3784. if (entity.IsXianHuo == 1)
  3785. {
  3786. entity.OrderState = 5;
  3787. }
  3788. entity.UnusualTag = 0;
  3789. entity.UnusualTime = null;
  3790. entity.UnusualCon = "";
  3791. entity.IsReturn = returnTag;
  3792. entity.ReturnTime = DateTime.Now;
  3793. entity.UpdateTime = DateTime.Now;
  3794. entity.ReturnReason = GetPostString("returnreason");
  3795. entity.Update();
  3796. if (entity.OrderState == 3)
  3797. {
  3798. ApiVo apiVo = new ApiVo();
  3799. apiVo.orderNumber = entity.ctid;
  3800. apiVo.actionName = "rebutDesign";
  3801. apiVo.orderRemarks = entity.ReturnReason;
  3802. designHelper.API_WorkCore(apiVo);//rebutDesign
  3803. }
  3804. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3805. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3806. {
  3807. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3808. }
  3809. CeErpSukuraData.createInfo(entity.ctid, 5);
  3810. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3811. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3812. if (isPlace)
  3813. {
  3814. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3815. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3816. if (dth != null && dth.Rows.Count > 0)
  3817. {
  3818. dataSendOrderBean dataSendOrderBean = null;
  3819. foreach (DataRow item in dth.Rows)
  3820. {
  3821. try
  3822. {
  3823. dataSendOrderBean = new dataSendOrderBean();
  3824. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3825. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3826. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3827. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3828. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3829. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3830. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3831. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3832. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3833. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3834. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3835. dataSendOrderBean.Radio1723534706288 = "打回";
  3836. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3837. if (result != null)
  3838. {
  3839. if ("0".Equals(result.errcode))
  3840. {
  3841. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3842. }
  3843. else
  3844. {
  3845. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3846. }
  3847. }
  3848. }
  3849. catch (Exception ex)
  3850. {
  3851. }
  3852. }
  3853. }
  3854. }
  3855. if (isNeedUpdateCell2)
  3856. {
  3857. if (entity.MakeSupplier.IndexOf(",") != -1)
  3858. {
  3859. StringBuilder sql2 = new StringBuilder();
  3860. 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);
  3861. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3862. }
  3863. else
  3864. {
  3865. StringBuilder sql2 = new StringBuilder();
  3866. 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);
  3867. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3868. }
  3869. }
  3870. returnSuccessMsg("操作成功!");
  3871. return;
  3872. }
  3873. returnErrorMsg("找不到订单记录");
  3874. }
  3875. }
  3876. public void cyt_erp_returnreason()
  3877. {
  3878. if (UrlPostParmsCheck("ctid"))
  3879. {
  3880. string eid = GetPostString("ctid");
  3881. CeErpTradeCell entity = null;
  3882. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3883. string userpost = CurrentUser.UserPost.Post.Code;
  3884. if (entity != null)
  3885. {
  3886. if (entity.OrderState > 6)
  3887. {
  3888. returnErrorMsg("已发货无法打回!");
  3889. return;
  3890. }
  3891. JObject jsonObject = new JObject
  3892. {
  3893. { "Userid", "77886" },
  3894. { "Pwd", "lt666888" },
  3895. { "LTOrderId",eid }
  3896. };
  3897. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3898. JObject jsonObjects = JObject.Parse(response);
  3899. string msg = (string)jsonObjects["msg"];
  3900. if (msg != "取消成功")
  3901. {
  3902. returnErrorMsg(msg);
  3903. return;
  3904. }
  3905. bool isNeedUpdateCell2 = false;
  3906. if (entity.OrderState >= 6)
  3907. {
  3908. isNeedUpdateCell2 = true;
  3909. }
  3910. int returnTag = 2;
  3911. if (userpost == "Supplier")
  3912. {
  3913. returnTag = 1;
  3914. }
  3915. if (entity.IsXianHuo == 0)
  3916. {
  3917. if (returnTag == 2)
  3918. {
  3919. int toType = GetPostInt("totype");
  3920. if (toType == 1)
  3921. {
  3922. entity.OrderState = 0;
  3923. entity.ReturnUserType = 1;
  3924. }
  3925. else
  3926. {
  3927. entity.OrderState = 4;
  3928. entity.ReturnUserType = 2;
  3929. }
  3930. entity.IsReadTag = 1;
  3931. }
  3932. else if (returnTag == 1)
  3933. {
  3934. entity.OrderState = 5;
  3935. }
  3936. entity.IsVerifyToSupplier = false;
  3937. }
  3938. entity.UnusualTag = 0;
  3939. entity.UnusualTime = null;
  3940. entity.UnusualCon = "";
  3941. entity.IsReturn = returnTag;
  3942. entity.ReturnTime = DateTime.Now;
  3943. entity.ReturnReason = GetPostString("returnreason");
  3944. entity.Update();
  3945. if (entity.OrderState == 4)
  3946. {
  3947. ApiVo apiVo = new ApiVo();
  3948. apiVo.orderNumber = entity.ctid;
  3949. apiVo.actionName = "rebutDesign";
  3950. apiVo.orderRemarks = entity.ReturnReason;
  3951. designHelper.API_WorkCore(apiVo);//rebutDesign
  3952. }
  3953. CeErpSukuraData.createInfo(entity.ctid, 5);
  3954. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3955. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3956. if (isNeedUpdateCell2)
  3957. {
  3958. if (entity.MakeSupplier.IndexOf(",") != -1)
  3959. {
  3960. StringBuilder sql2 = new StringBuilder();
  3961. 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);
  3962. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3963. }
  3964. else
  3965. {
  3966. StringBuilder sql2 = new StringBuilder();
  3967. 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);
  3968. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3969. }
  3970. }
  3971. returnSuccessMsg("操作成功!");
  3972. return;
  3973. }
  3974. returnErrorMsg("找不到订单记录");
  3975. }
  3976. }
  3977. public void upd_erp_xianhuoreturntag()
  3978. {
  3979. if (UrlPostParmsCheck("ctid"))
  3980. {
  3981. string eids = GetPostString("ctid");
  3982. string[] ctids = eids.Split(',');
  3983. foreach (string ctid in ctids)
  3984. {
  3985. CeErpTradeCell entity = null;
  3986. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3987. if (entity != null)
  3988. {
  3989. entity.IsReturn = 0;
  3990. entity.Update();
  3991. CeErpSukuraData.createInfo(entity.ctid, 5);
  3992. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3993. }
  3994. }
  3995. returnSuccessMsg("操作成功!");
  3996. return;
  3997. }
  3998. }
  3999. public void get_erp_waitdeliverylist()
  4000. {
  4001. DataStruct dStruct = GetPostStruct();
  4002. List<string> lw = new List<string>();
  4003. string tid = GetPostString("ctid");
  4004. if (tid.Length > 0)
  4005. {
  4006. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4007. if (tid.Length > 5)
  4008. {
  4009. List<string> tids = getTidByCtidLike(tid);
  4010. if (tids.Count > 0 && tids.Count < 10)
  4011. {
  4012. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4013. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4014. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4015. {
  4016. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4017. }
  4018. }
  4019. }
  4020. lw.Add(tid_sql);
  4021. }
  4022. string shopname = GetPostString("shopname");
  4023. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4024. string buyernick = GetPostString("buyer_nick");
  4025. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4026. //if (tid.Length == 0 && buyernick.Length == 0)
  4027. //{
  4028. // lw.Add(string.Format("IsRefund<={0}", 1));
  4029. //}
  4030. string customer = GetPostString("customer");
  4031. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4032. string design = GetPostString("design");
  4033. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4034. string orderState = GetPostString("orderState");
  4035. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4036. string address = GetPostString("address");
  4037. 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));
  4038. string sellermemo = GetPostString("seller_memo");
  4039. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4040. string supplier = GetPostString("supplier");
  4041. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4042. string OrderArea = GetPostString("order_area");
  4043. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4044. string placedate1 = GetPostString("placedate1");
  4045. string placedate2 = GetPostString("placedate2");
  4046. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4047. if (fdw.Length > 0) lw.Add(fdw);
  4048. string price1 = GetPostString("price1");
  4049. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4050. string price2 = GetPostString("price2");
  4051. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4052. string unusualCon = GetPostString("unusualcon");
  4053. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4054. string otherMemo = GetPostString("otherMemo");
  4055. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4056. string posTag = CurrentUser.UserPost.Post.Code;
  4057. if (posTag == "Supplier")
  4058. {
  4059. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4060. }
  4061. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4062. lw.Add(string.Format("type != 'PDD' "));
  4063. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4064. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4065. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4066. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4067. writeGridDataTableJson(dStruct.TotalCount, dt);
  4068. }
  4069. public void get_erp_changedeliverylist()
  4070. {
  4071. DataStruct dStruct = GetPostStruct();
  4072. List<string> lw = new List<string>();
  4073. string tid = GetPostString("ctid");
  4074. if (tid.Length > 0)
  4075. {
  4076. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4077. if (tid.Length > 5)
  4078. {
  4079. List<string> tids = getTidByCtidLike(tid);
  4080. if (tids.Count > 0 && tids.Count < 10)
  4081. {
  4082. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4083. }
  4084. }
  4085. lw.Add(tid_sql);
  4086. }
  4087. string shopname = GetPostString("shopname");
  4088. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4089. string buyernick = GetPostString("buyer_nick");
  4090. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4091. //if (tid.Length == 0 && buyernick.Length == 0)
  4092. //{
  4093. // lw.Add(string.Format("IsRefund<={0}", 1));
  4094. //}
  4095. string customer = GetPostString("customer");
  4096. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4097. string design = GetPostString("design");
  4098. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4099. string orderState = GetPostString("orderState");
  4100. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4101. string address = GetPostString("address");
  4102. 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));
  4103. string sellermemo = GetPostString("seller_memo");
  4104. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4105. string supplier = GetPostString("supplier");
  4106. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4107. string OrderArea = GetPostString("order_area");
  4108. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4109. string placedate1 = GetPostString("placedate1");
  4110. string placedate2 = GetPostString("placedate2");
  4111. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4112. if (fdw.Length > 0) lw.Add(fdw);
  4113. string price1 = GetPostString("price1");
  4114. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4115. string price2 = GetPostString("price2");
  4116. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4117. string unusualCon = GetPostString("unusualcon");
  4118. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4119. string otherMemo = GetPostString("otherMemo");
  4120. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4121. string posTag = CurrentUser.UserPost.Post.Code;
  4122. if (posTag == "Supplier")
  4123. {
  4124. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4125. }
  4126. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4127. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4128. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4129. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4130. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4131. /*if (tid.Length > 0)
  4132. {
  4133. List<string> tids = new List<string>();
  4134. if (dt != null && dt.Rows.Count > 0)
  4135. {
  4136. foreach (DataRow item in dt.Rows)
  4137. {
  4138. tids.Add("'" + item["tid"] + "'");
  4139. }
  4140. }
  4141. if (tids.Count > 0)
  4142. {
  4143. lw.RemoveAt(0);
  4144. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4145. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4146. dt = WebCache.GetData("view_erptradecell", dStruct);
  4147. }
  4148. }*/
  4149. writeGridDataTableJson(dStruct.TotalCount, dt);
  4150. }
  4151. public void get_erp_pddderiving()
  4152. {
  4153. DataStruct dStruct = GetPostStruct();
  4154. List<string> lw = new List<string>();
  4155. string tid = GetPostString("ctid");
  4156. if (tid.Length > 0)
  4157. {
  4158. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4159. if (tid.Length > 5)
  4160. {
  4161. List<string> tids = getTidByCtidLike(tid);
  4162. if (tids.Count > 0 && tids.Count < 10)
  4163. {
  4164. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4165. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4166. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4167. {
  4168. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4169. }
  4170. }
  4171. }
  4172. lw.Add(tid_sql);
  4173. }
  4174. string shopname = GetPostString("shopname");
  4175. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4176. string buyernick = GetPostString("buyer_nick");
  4177. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4178. //if (tid.Length == 0 && buyernick.Length == 0)
  4179. //{
  4180. // lw.Add(string.Format("IsRefund<={0}", 1));
  4181. //}
  4182. string customer = GetPostString("customer");
  4183. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4184. string design = GetPostString("design");
  4185. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4186. string orderState = GetPostString("orderState");
  4187. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4188. string address = GetPostString("address");
  4189. 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));
  4190. string sellermemo = GetPostString("seller_memo");
  4191. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4192. string supplier = GetPostString("supplier");
  4193. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4194. string OrderArea = GetPostString("order_area");
  4195. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4196. string placedate1 = GetPostString("placedate1");
  4197. string placedate2 = GetPostString("placedate2");
  4198. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4199. if (fdw.Length > 0) lw.Add(fdw);
  4200. string price1 = GetPostString("price1");
  4201. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4202. string price2 = GetPostString("price2");
  4203. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4204. string unusualCon = GetPostString("unusualcon");
  4205. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4206. string posTag = CurrentUser.UserPost.Post.Code;
  4207. if (posTag == "Supplier")
  4208. {
  4209. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4210. }
  4211. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4212. lw.Add(string.Format("type = 'PDD' "));
  4213. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4214. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4215. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4216. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4217. /*if (tid.Length > 0)
  4218. {
  4219. List<string> tids = new List<string>();
  4220. if (dt != null && dt.Rows.Count > 0)
  4221. {
  4222. foreach (DataRow item in dt.Rows)
  4223. {
  4224. tids.Add("'" + item["tid"] + "'");
  4225. }
  4226. }
  4227. if (tids.Count > 0)
  4228. {
  4229. lw.RemoveAt(0);
  4230. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4231. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4232. dt = WebCache.GetData("view_erptradecell", dStruct);
  4233. }
  4234. }*/
  4235. writeGridDataTableJson(dStruct.TotalCount, dt);
  4236. }
  4237. public void get_erp_jdderiving()
  4238. {
  4239. DataStruct dStruct = GetPostStruct();
  4240. List<string> lw = new List<string>();
  4241. string tid = GetPostString("ctid");
  4242. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4243. string shopname = GetPostString("shopname");
  4244. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4245. string buyernick = GetPostString("buyer_nick");
  4246. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4247. //if (tid.Length == 0 && buyernick.Length == 0)
  4248. //{
  4249. // lw.Add(string.Format("IsRefund<={0}", 1));
  4250. //}
  4251. string customer = GetPostString("customer");
  4252. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4253. string design = GetPostString("design");
  4254. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4255. string orderState = GetPostString("orderState");
  4256. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4257. string address = GetPostString("address");
  4258. 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));
  4259. string sellermemo = GetPostString("seller_memo");
  4260. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4261. string supplier = GetPostString("supplier");
  4262. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4263. string OrderArea = GetPostString("order_area");
  4264. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4265. string placedate1 = GetPostString("placedate1");
  4266. string placedate2 = GetPostString("placedate2");
  4267. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4268. if (fdw.Length > 0) lw.Add(fdw);
  4269. string price1 = GetPostString("price1");
  4270. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4271. string price2 = GetPostString("price2");
  4272. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4273. string unusualCon = GetPostString("unusualcon");
  4274. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4275. string posTag = CurrentUser.UserPost.Post.Code;
  4276. if (posTag == "Supplier")
  4277. {
  4278. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4279. }
  4280. lw.Add(string.Format("OrderState = 6 "));
  4281. lw.Add(string.Format("type = 'JD' "));
  4282. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4283. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4284. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4285. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4286. writeGridDataTableJson(dStruct.TotalCount, dt);
  4287. }
  4288. public void get_erp_demoorderlist()
  4289. {
  4290. DataStruct dStruct = GetPostStruct();
  4291. List<string> lw = new List<string>();
  4292. string tid = GetPostString("ctid");
  4293. if (tid.Length > 0)
  4294. {
  4295. string select_tid = getTidByCtid(tid);
  4296. lw.Add(string.Format("tid='{0}'", select_tid));
  4297. }
  4298. string shopname = GetPostString("shopname");
  4299. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4300. string buyernick = GetPostString("buyer_nick");
  4301. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4302. string customer = GetPostString("customer");
  4303. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4304. string design = GetPostString("design");
  4305. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4306. string orderState = GetPostString("orderState");
  4307. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4308. string address = GetPostString("address");
  4309. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4310. string sellermemo = GetPostString("seller_memo");
  4311. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4312. string supplier = GetPostString("supplier");
  4313. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4314. string OrderArea = GetPostString("order_area");
  4315. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4316. string date1 = GetPostString("date1");
  4317. string date2 = GetPostString("date2");
  4318. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4319. if (dw.Length > 0) lw.Add(dw);
  4320. string price1 = GetPostString("price1");
  4321. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4322. string price2 = GetPostString("price2");
  4323. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4324. string posTag = CurrentUser.UserPost.Post.Code;
  4325. if (posTag == "Supplier")
  4326. {
  4327. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4328. }
  4329. //lw.Add(string.Format("OrderState = 6 "));
  4330. lw.Add(string.Format("IsSample={0}", 3));
  4331. lw.Add(string.Format("IsRefund<={0}", 1));
  4332. dStruct.Order = "pay_time desc";
  4333. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4334. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4335. writeGridDataTableJson(dStruct.TotalCount, dt);
  4336. }
  4337. public void save_erp_checkmemo()
  4338. {
  4339. if (UrlPostParmsCheck("ctid"))
  4340. {
  4341. string ctid = GetPostString("ctid");
  4342. CeErpTradeCell entity = null;
  4343. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4344. if (entity != null)
  4345. {
  4346. entity.CheckMemo = GetPostString("CheckMemo");
  4347. entity.Update();
  4348. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4349. if (trade != null)
  4350. {
  4351. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4352. }
  4353. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4354. returnSuccessMsg("保存成功!");
  4355. return;
  4356. }
  4357. returnErrorMsg("找不到记录");
  4358. }
  4359. }
  4360. public void get_erp_returnlist()
  4361. {
  4362. DataStruct dStruct = GetPostStruct();
  4363. List<string> lw = new List<string>();
  4364. string tid = GetPostString("ctid");
  4365. if (tid.Length > 0)
  4366. {
  4367. string select_tid = getTidByCtid(tid);
  4368. lw.Add(string.Format("tid='{0}'", select_tid));
  4369. }
  4370. string shopname = GetPostString("shopname");
  4371. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4372. string buyernick = GetPostString("buyer_nick");
  4373. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4374. string customer = GetPostString("customer");
  4375. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4376. string design = GetPostString("design");
  4377. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4378. string orderState = GetPostString("orderState");
  4379. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4380. string address = GetPostString("address");
  4381. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4382. string sellermemo = GetPostString("seller_memo");
  4383. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4384. string supplier = GetPostString("supplier");
  4385. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4386. string date1 = GetPostString("date1");
  4387. string date2 = GetPostString("date2");
  4388. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4389. if (dw.Length > 0) lw.Add(dw);
  4390. string bdate1 = GetPostString("backdate1");
  4391. string bdate2 = GetPostString("backdate2");
  4392. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4393. if (dw_back.Length > 0) lw.Add(dw_back);
  4394. string price1 = GetPostString("price1");
  4395. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4396. string price2 = GetPostString("price2");
  4397. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4398. lw.Add(string.Format("IsReturn>0"));
  4399. lw.Add(string.Format("IsXianHuo=0"));
  4400. lw.Add(string.Format("IsReturn!=3"));
  4401. string backtype = GetPostString("backtype");
  4402. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4403. dStruct.Order = "FinishDesignTime desc";
  4404. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4405. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4406. writeGridDataTableJson(dStruct.TotalCount, dt);
  4407. }
  4408. public void get_erp_today_sumreturn()
  4409. {
  4410. DataStruct dStruct = GetPostStruct();
  4411. List<string> lw = new List<string>();
  4412. string bdate1 = GetPostString("returnTimeS");
  4413. string bdate2 = GetPostString("returnTimeE");
  4414. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4415. if (dw_back.Length > 0) lw.Add(dw_back);
  4416. lw.Add(string.Format("IsReturn=0"));
  4417. lw.Add(string.Format("IsXianHuo=0"));
  4418. string mainWhere = string.Join(" and ", lw.ToArray());
  4419. string sql = "";
  4420. if (dw_back.Length > 0)
  4421. {
  4422. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4423. }
  4424. else
  4425. {
  4426. 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 + "'";
  4427. }
  4428. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4429. decimal total = 0, today_finish = 0;
  4430. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4431. {
  4432. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4433. }
  4434. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4435. {
  4436. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4437. }
  4438. var res = new
  4439. {
  4440. data = total,
  4441. data1 = today_finish,
  4442. };
  4443. string ro_jsond = JsonConvert.SerializeObject(res);
  4444. returnSuccess(ro_jsond);
  4445. return;
  4446. }
  4447. public void get_erp_allreturnlist()
  4448. {
  4449. DataStruct dStruct = GetPostStruct();
  4450. List<string> lw = new List<string>();
  4451. string tid = GetPostString("ctid");
  4452. if (tid.Length > 0)
  4453. {
  4454. string select_tid = getTidByCtid(tid);
  4455. lw.Add(string.Format("tid='{0}'", select_tid));
  4456. }
  4457. string shopname = GetPostString("shopname");
  4458. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4459. string buyernick = GetPostString("buyer_nick");
  4460. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4461. string customer = GetPostString("customer");
  4462. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4463. string design = GetPostString("design");
  4464. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4465. string orderState = GetPostString("orderState");
  4466. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4467. string address = GetPostString("address");
  4468. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4469. string sellermemo = GetPostString("seller_memo");
  4470. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4471. string supplier = GetPostString("supplier");
  4472. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4473. string date1 = GetPostString("date1");
  4474. string date2 = GetPostString("date2");
  4475. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4476. if (dw.Length > 0) lw.Add(dw);
  4477. string bdate1 = GetPostString("backdate1");
  4478. string bdate2 = GetPostString("backdate2");
  4479. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4480. if (dw_back.Length > 0) lw.Add(dw_back);
  4481. string price1 = GetPostString("price1");
  4482. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4483. string price2 = GetPostString("price2");
  4484. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4485. string backreason = GetPostString("backreason");
  4486. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4487. lw.Add(string.Format("IsXianHuo=0"));
  4488. lw.Add(string.Format("ReturnTime != ''"));
  4489. string backtype = GetPostString("backtype");
  4490. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4491. dStruct.Order = "FinishDesignTime desc";
  4492. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4493. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4494. writeGridDataTableJson(dStruct.TotalCount, dt);
  4495. }
  4496. public void get_erp_aftersalereturnlist()
  4497. {
  4498. DataStruct dStruct = GetPostStruct();
  4499. List<string> lw = new List<string>();
  4500. string tid = GetPostString("ctid");
  4501. if (tid.Length > 0)
  4502. {
  4503. string select_tid = getTidByCtid(tid);
  4504. lw.Add(string.Format("tid='{0}'", select_tid));
  4505. }
  4506. string shopname = GetPostString("shopname");
  4507. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4508. string buyernick = GetPostString("buyer_nick");
  4509. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4510. string customer = GetPostString("customer");
  4511. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4512. string design = GetPostString("design");
  4513. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4514. string orderState = GetPostString("orderState");
  4515. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4516. string address = GetPostString("address");
  4517. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4518. string sellermemo = GetPostString("seller_memo");
  4519. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4520. string supplier = GetPostString("supplier");
  4521. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4522. string date1 = GetPostString("date1");
  4523. string date2 = GetPostString("date2");
  4524. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4525. if (dw.Length > 0) lw.Add(dw);
  4526. string bdate1 = GetPostString("backdate1");
  4527. string bdate2 = GetPostString("backdate2");
  4528. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4529. if (dw_back.Length > 0) lw.Add(dw_back);
  4530. string price1 = GetPostString("price1");
  4531. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4532. string price2 = GetPostString("price2");
  4533. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4534. lw.Add(string.Format("IsReturn=3"));
  4535. string backtype = GetPostString("backtype");
  4536. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4537. string backreason = GetPostString("backreason");
  4538. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4539. dStruct.Order = "ReturnTime desc";
  4540. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4541. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4542. writeGridDataTableJson(dStruct.TotalCount, dt);
  4543. }
  4544. public void get_erp_xianhuoreturnlist()
  4545. {
  4546. DataStruct dStruct = GetPostStruct();
  4547. List<string> lw = new List<string>();
  4548. string tid = GetPostString("ctid");
  4549. if (tid.Length > 0)
  4550. {
  4551. string select_tid = getTidByCtid(tid);
  4552. lw.Add(string.Format("tid='{0}'", select_tid));
  4553. }
  4554. string shopname = GetPostString("shopname");
  4555. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4556. string buyernick = GetPostString("buyer_nick");
  4557. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4558. string customer = GetPostString("customer");
  4559. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4560. string design = GetPostString("design");
  4561. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4562. string orderState = GetPostString("orderState");
  4563. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4564. string address = GetPostString("address");
  4565. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4566. string sellermemo = GetPostString("seller_memo");
  4567. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4568. string supplier = GetPostString("supplier");
  4569. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4570. string OrderArea = GetPostString("order_area");
  4571. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4572. string date1 = GetPostString("date1");
  4573. string date2 = GetPostString("date2");
  4574. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4575. if (dw.Length > 0) lw.Add(dw);
  4576. string price1 = GetPostString("price1");
  4577. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4578. string price2 = GetPostString("price2");
  4579. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4580. string posTag = CurrentUser.UserPost.Post.Code;
  4581. if (posTag == "Supplier")
  4582. {
  4583. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4584. }
  4585. lw.Add(string.Format("OrderState=6 "));
  4586. lw.Add(string.Format("IsXianHuo=1 "));
  4587. lw.Add(string.Format("IsReturn>0 "));
  4588. lw.Add(string.Format("IsReturn!=3"));
  4589. lw.Add(string.Format("IsRefund<={0}", 1));
  4590. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4591. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4592. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4593. writeGridDataTableJson(dStruct.TotalCount, dt);
  4594. }
  4595. public void set_erp_orderdelivery()
  4596. {
  4597. if (UrlPostParmsCheck("ctid"))
  4598. {
  4599. string eid = GetPostString("ctid");
  4600. CeErpTradeCell entity = null;
  4601. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4602. if (entity != null)
  4603. {
  4604. if (entity.OrderState >= 7)
  4605. {
  4606. returnErrorMsg("此单已发货,无需重复发货");
  4607. return;
  4608. }
  4609. if (entity.OrderState != 6)
  4610. {
  4611. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4612. return;
  4613. }
  4614. string shop = GetPostString("seller_nick");
  4615. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4616. string comName = GetPostString("comName");
  4617. string comCode = GetPostString("comCode");
  4618. string outSid = GetPostString("outSid");
  4619. string deliveryType = GetPostString("deliveryType");
  4620. string deliveryMemo = GetPostString("deliveryMemo");
  4621. outSid = outSid.Trim();
  4622. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4623. if (mainEn == null)
  4624. {
  4625. returnErrorMsg("找不到原始订单记录");
  4626. return;
  4627. }
  4628. bool isInitOrderDeliv = false;
  4629. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4630. {
  4631. isInitOrderDeliv = true;
  4632. }
  4633. string apires = "";
  4634. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4635. 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)
  4636. {
  4637. apires = "发货成功true";
  4638. }
  4639. else
  4640. {
  4641. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4642. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4643. }
  4644. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4645. {
  4646. entity.OrderState = 7;//发货后订单已发货
  4647. entity.OutSid = outSid;
  4648. entity.MemoOpt = 0;
  4649. entity.UpdateTime = DateTime.Now;
  4650. entity.FinishDeliveryTime = DateTime.Now;
  4651. entity.Update();
  4652. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4653. commonHelper.UpdateRelationOrder(entity.ctid);
  4654. //还要插入快递信息到 快递信息表
  4655. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4656. exinfo.tid = eid;
  4657. exinfo.out_sid = outSid;
  4658. exinfo.company_code = comCode;
  4659. exinfo.company_name = comName;
  4660. exinfo.delivery_memo = deliveryMemo;
  4661. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4662. exinfo.deliveryType = deliveryType;
  4663. exinfo.Create();
  4664. returnSuccessMsg("发货操作成功!");
  4665. commonHelper.UpdateRelationOrder(entity.ctid);
  4666. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4667. CeErpSukuraData.createInfo(entity.ctid, 4);
  4668. if (entity.SupplierId == 64)
  4669. {
  4670. commonHelper.sendCytExpress(exinfo);
  4671. }
  4672. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4673. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4674. }
  4675. else
  4676. {
  4677. string errmsg = commonHelper.KeepChinese(apires);
  4678. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4679. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4680. }
  4681. return;
  4682. }
  4683. returnErrorMsg("找不到订单记录");
  4684. }
  4685. }
  4686. public void set_erp_multidelivery()
  4687. {
  4688. string eids = GetPostString("tids");
  4689. string[] eidList = eids.Split(',');
  4690. if (eidList.Length <= 0)
  4691. {
  4692. returnErrorMsg("发货不能为空");
  4693. return;
  4694. }
  4695. foreach (string ctid in eidList)
  4696. {
  4697. if (ctid.Length <= 0) continue;
  4698. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4699. if (expInfo != null)
  4700. {
  4701. StringBuilder sql = new StringBuilder();
  4702. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4703. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4704. if (dt.Rows.Count > 0)
  4705. {
  4706. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4707. {
  4708. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4709. expInfo.state = "异常";
  4710. expInfo.isMultiDelivery = 1;
  4711. expInfo.Update();
  4712. continue;
  4713. }
  4714. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4715. {
  4716. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4717. expInfo.state = "异常";
  4718. expInfo.Update();
  4719. continue;
  4720. }
  4721. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4722. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4723. bool isInitOrderDeliv = false;
  4724. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4725. {
  4726. isInitOrderDeliv = true;
  4727. expInfo.isMultiDelivery = 1;
  4728. }
  4729. if (ctid.IndexOf("N") != -1)
  4730. {
  4731. StringBuilder sqlbucha = new StringBuilder();
  4732. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4733. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4734. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4735. commonHelper.UpdateRelationOrder(ctid);
  4736. expInfo.delivery_memo = "发货成功";
  4737. expInfo.state = "发货成功";
  4738. expInfo.isMultiDelivery = 1;
  4739. expInfo.Update();
  4740. }
  4741. else
  4742. {
  4743. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4744. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4745. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4746. {
  4747. expInfo.delivery_memo = "发货成功";
  4748. expInfo.state = "发货成功";
  4749. expInfo.isMultiDelivery = 1;
  4750. expInfo.Update();
  4751. commonHelper.UpdateRelationOrder(ctid);
  4752. CeErpSukuraData.createInfo(ctid, 4);
  4753. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4754. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4755. }
  4756. else
  4757. {
  4758. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4759. expInfo.state = "异常";
  4760. expInfo.Update();
  4761. }
  4762. }
  4763. }
  4764. }
  4765. }
  4766. returnSuccessMsg("操作完成");
  4767. }
  4768. public void reset_erp_memoopt()
  4769. {
  4770. if (UrlPostParmsCheck("ctid"))
  4771. {
  4772. string eid = GetPostString("ctid");
  4773. CeErpTradeCell entity = null;
  4774. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4775. if (entity != null)
  4776. {
  4777. string stropt = "";
  4778. if (entity.MemoOpt == 1)
  4779. {
  4780. stropt = "“改稿”";
  4781. }
  4782. else if (entity.MemoOpt == 2)
  4783. {
  4784. stropt = "“定稿”";
  4785. }
  4786. else if (entity.MemoOpt == 3)
  4787. {
  4788. stropt = "“完成查货”";
  4789. CeErpSukuraData.createInfo(entity.ctid, 6);
  4790. }
  4791. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4792. entity.UpdateTime = DateTime.Now;
  4793. entity.MemoOpt = 0;
  4794. entity.Update();
  4795. returnSuccessMsg("操作成功!");
  4796. return;
  4797. }
  4798. returnErrorMsg("找不到记录");
  4799. }
  4800. }
  4801. public void get_erp_deliveryunusual()
  4802. {
  4803. DataStruct dStruct = GetPostStruct();
  4804. List<string> lw = new List<string>();
  4805. string tid = GetPostString("ctid");
  4806. if (tid.Length > 0)
  4807. {
  4808. string select_tid = getTidByCtid(tid);
  4809. lw.Add(string.Format("tid='{0}'", select_tid));
  4810. }
  4811. string shopname = GetPostString("shopname");
  4812. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4813. string buyernick = GetPostString("buyer_nick");
  4814. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4815. string customer = GetPostString("customer");
  4816. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4817. string design = GetPostString("design");
  4818. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4819. string sellermemo = GetPostString("seller_memo");
  4820. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4821. string supplier = GetPostString("supplier");
  4822. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4823. string date1 = GetPostString("date1");
  4824. string date2 = GetPostString("date2");
  4825. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4826. if (dw.Length > 0) lw.Add(dw);
  4827. string placedate1 = GetPostString("placedate1");
  4828. string placedate2 = GetPostString("placedate2");
  4829. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4830. if (dw_place.Length > 0) lw.Add(dw_place);
  4831. string price1 = GetPostString("price1");
  4832. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4833. string price2 = GetPostString("price2");
  4834. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4835. string unusualCon = GetPostString("unusualcon");
  4836. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4837. string posTag = CurrentUser.UserPost.Post.Code;
  4838. if (posTag == "Supplier")
  4839. {
  4840. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4841. }
  4842. lw.Add(string.Format("OrderState = 6"));
  4843. lw.Add(string.Format("UnusualTag = 5"));
  4844. lw.Add(string.Format("IsRefund<={0}", 1));
  4845. dStruct.Order = "FinishPlaceTime desc";
  4846. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4847. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4848. writeGridDataTableJson(dStruct.TotalCount, dt);
  4849. }
  4850. public void get_erp_deliveryedlist()
  4851. {
  4852. DataStruct dStruct = GetPostStruct();
  4853. List<string> lw = new List<string>();
  4854. string tid = GetPostString("ctid");
  4855. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4856. string shopname = GetPostString("shopname");
  4857. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4858. string buyernick = GetPostString("buyer_nick");
  4859. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4860. string customer = GetPostString("customer");
  4861. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4862. string design = GetPostString("design");
  4863. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4864. string sellermemo = GetPostString("seller_memo");
  4865. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4866. string logistics = GetPostString("logistics");
  4867. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4868. string date1 = GetPostString("date1");
  4869. string date2 = GetPostString("date2");
  4870. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4871. //if (dw.Length > 0) lw.Add(dw);
  4872. string placedate1 = GetPostString("placedate1");
  4873. string placedate2 = GetPostString("placedate2");
  4874. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4875. if (fdw.Length > 0) lw.Add(fdw);
  4876. string devdate1 = GetPostString("deliverydate1");
  4877. string devdate2 = GetPostString("deliverydate2");
  4878. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4879. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4880. string price1 = GetPostString("price1");
  4881. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4882. string price2 = GetPostString("price2");
  4883. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4884. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4885. {
  4886. if (tid.Length > 0)
  4887. {
  4888. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4889. if (tid.Length > 5)
  4890. {
  4891. List<string> tids = getTidByCtidLike(tid);
  4892. if (tids.Count > 0 && tids.Count < 10)
  4893. {
  4894. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4895. }
  4896. }
  4897. lw.Add(tid_sql);
  4898. }
  4899. if (buyernick.Length > 0)
  4900. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4901. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4902. if (dw.Length > 0) lw.Add(dw);
  4903. }
  4904. else
  4905. {
  4906. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4907. }
  4908. string posTag = CurrentUser.UserPost.Post.Code;
  4909. if (posTag == "Supplier")
  4910. {
  4911. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4912. }
  4913. else
  4914. {
  4915. string supplier = GetPostString("supplier");
  4916. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4917. }
  4918. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4919. lw.Add(string.Format("type != 'PDD' "));
  4920. lw.Add(string.Format("IsRefund!={0}", 2));
  4921. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4922. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4923. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4924. /*if (tid.Length > 0)
  4925. {
  4926. List<string> tids = new List<string>();
  4927. if (dt != null && dt.Rows.Count > 0)
  4928. {
  4929. foreach (DataRow item in dt.Rows)
  4930. {
  4931. tids.Add("'" + item["tid"] + "'");
  4932. }
  4933. }
  4934. if (tids.Count > 0)
  4935. {
  4936. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4937. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4938. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4939. dt = WebCache.GetData("view_erptradecell", dStruct);
  4940. }
  4941. }*/
  4942. if (dt != null)
  4943. {
  4944. foreach (DataRow dr in dt.Rows)
  4945. {
  4946. 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();
  4947. }
  4948. }
  4949. writeGridDataTableJson(dStruct.TotalCount, dt);
  4950. }
  4951. public void get_erp_pdddeliveryed()
  4952. {
  4953. DataStruct dStruct = GetPostStruct();
  4954. List<string> lw = new List<string>();
  4955. string tid = GetPostString("ctid");
  4956. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4957. string shopname = GetPostString("shopname");
  4958. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4959. string buyernick = GetPostString("buyer_nick");
  4960. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4961. string customer = GetPostString("customer");
  4962. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4963. string design = GetPostString("design");
  4964. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4965. string sellermemo = GetPostString("seller_memo");
  4966. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4967. string logistics = GetPostString("logistics");
  4968. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4969. string date1 = GetPostString("date1");
  4970. string date2 = GetPostString("date2");
  4971. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4972. //if (dw.Length > 0) lw.Add(dw);
  4973. string placedate1 = GetPostString("placedate1");
  4974. string placedate2 = GetPostString("placedate2");
  4975. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4976. if (fdw.Length > 0) lw.Add(fdw);
  4977. string devdate1 = GetPostString("deliverydate1");
  4978. string devdate2 = GetPostString("deliverydate2");
  4979. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4980. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4981. string price1 = GetPostString("price1");
  4982. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4983. string price2 = GetPostString("price2");
  4984. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4985. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4986. {
  4987. if (tid.Length > 0)
  4988. {
  4989. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4990. if (tid.Length > 5)
  4991. {
  4992. List<string> tids = getTidByCtidLike(tid);
  4993. if (tids.Count > 0 && tids.Count < 10)
  4994. {
  4995. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4996. }
  4997. }
  4998. lw.Add(tid_sql);
  4999. }
  5000. if (buyernick.Length > 0)
  5001. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5002. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5003. if (dw.Length > 0) lw.Add(dw);
  5004. }
  5005. else
  5006. {
  5007. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5008. }
  5009. string posTag = CurrentUser.UserPost.Post.Code;
  5010. if (posTag == "Supplier")
  5011. {
  5012. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5013. }
  5014. else
  5015. {
  5016. string supplier = GetPostString("supplier");
  5017. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5018. }
  5019. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5020. lw.Add(string.Format("type = 'PDD' "));
  5021. lw.Add(string.Format("IsRefund!={0}", 2));
  5022. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5023. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5024. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5025. /* if (tid.Length > 0)
  5026. {
  5027. List<string> tids = new List<string>();
  5028. if (dt != null && dt.Rows.Count > 0)
  5029. {
  5030. foreach (DataRow item in dt.Rows)
  5031. {
  5032. tids.Add("'" + item["tid"] + "'");
  5033. }
  5034. }
  5035. if (tids.Count > 0)
  5036. {
  5037. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5038. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5039. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5040. dt = WebCache.GetData("view_erptradecell", dStruct);
  5041. }
  5042. }*/
  5043. foreach (DataRow dr in dt.Rows)
  5044. {
  5045. 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();
  5046. }
  5047. writeGridDataTableJson(dStruct.TotalCount, dt);
  5048. }
  5049. public void get_erp_jddeliveryed()
  5050. {
  5051. DataStruct dStruct = GetPostStruct();
  5052. List<string> lw = new List<string>();
  5053. string tid = GetPostString("ctid");
  5054. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5055. string shopname = GetPostString("shopname");
  5056. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5057. string buyernick = GetPostString("buyer_nick");
  5058. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5059. string customer = GetPostString("customer");
  5060. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5061. string design = GetPostString("design");
  5062. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5063. string sellermemo = GetPostString("seller_memo");
  5064. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5065. string date1 = GetPostString("date1");
  5066. string date2 = GetPostString("date2");
  5067. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5068. //if (dw.Length > 0) lw.Add(dw);
  5069. string placedate1 = GetPostString("placedate1");
  5070. string placedate2 = GetPostString("placedate2");
  5071. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5072. if (fdw.Length > 0) lw.Add(fdw);
  5073. string devdate1 = GetPostString("deliverydate1");
  5074. string devdate2 = GetPostString("deliverydate2");
  5075. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5076. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5077. string price1 = GetPostString("price1");
  5078. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5079. string price2 = GetPostString("price2");
  5080. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5081. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5082. {
  5083. if (tid.Length > 0)
  5084. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5085. if (buyernick.Length > 0)
  5086. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5087. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5088. if (dw.Length > 0) lw.Add(dw);
  5089. }
  5090. else
  5091. {
  5092. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5093. }
  5094. string posTag = CurrentUser.UserPost.Post.Code;
  5095. if (posTag == "Supplier")
  5096. {
  5097. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5098. }
  5099. else
  5100. {
  5101. string supplier = GetPostString("supplier");
  5102. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5103. }
  5104. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5105. lw.Add(string.Format("type = 'JD' "));
  5106. lw.Add(string.Format("IsRefund!={0}", 2));
  5107. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5108. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5109. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5110. foreach (DataRow dr in dt.Rows)
  5111. {
  5112. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5113. }
  5114. writeGridDataTableJson(dStruct.TotalCount, dt);
  5115. }
  5116. public void get_erp_allplacelist()
  5117. {
  5118. DataStruct dStruct = GetPostStruct();
  5119. List<string> lw = new List<string>();
  5120. string tid = GetPostString("ctid");
  5121. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5122. string shopname = GetPostString("shopname");
  5123. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5124. string buyernick = GetPostString("buyer_nick");
  5125. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5126. string customer = GetPostString("customer");
  5127. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5128. string design = GetPostString("design");
  5129. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5130. string sellermemo = GetPostString("seller_memo");
  5131. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5132. string supplier = GetPostString("supplier");
  5133. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5134. string date1 = GetPostString("date1");
  5135. string date2 = GetPostString("date2");
  5136. string pldate1 = GetPostString("placedate1");
  5137. string pldate2 = GetPostString("placedate2");
  5138. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5139. //if (dw.Length > 0) lw.Add(dw);
  5140. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5141. {
  5142. if (tid.Length > 0)
  5143. {
  5144. string select_tid = getTidByCtid(tid);
  5145. lw.Add(string.Format("tid='{0}'", select_tid));
  5146. }
  5147. if (buyernick.Length > 0)
  5148. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5149. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5150. if (dw.Length > 0) lw.Add(dw);
  5151. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5152. if (dw_place.Length > 0) lw.Add(dw_place);
  5153. }
  5154. else
  5155. {
  5156. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5157. {
  5158. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5159. }
  5160. }
  5161. string price1 = GetPostString("price1");
  5162. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5163. string price2 = GetPostString("price2");
  5164. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5165. string posTag = CurrentUser.UserPost.Post.Code;
  5166. if (posTag == "Supplier")
  5167. {
  5168. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5169. }
  5170. lw.Add(string.Format("OrderState >= 6"));
  5171. lw.Add(string.Format("IsSample != 2 "));
  5172. //lw.Add(string.Format("isDianziOrder = 0 "));
  5173. lw.Add(string.Format("SupplierId > 0 "));
  5174. //lw.Add(string.Format("IsRefund<={0}", 1));
  5175. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5176. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5177. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5178. foreach (DataRow dr in dt.Rows)
  5179. {
  5180. 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();
  5181. }
  5182. writeGridDataTableJson(dStruct.TotalCount, dt);
  5183. }
  5184. public void get_erp_financeallplacelist()
  5185. {
  5186. DataStruct dStruct = GetPostStruct();
  5187. List<string> lw = new List<string>();
  5188. string tid = GetPostString("ctid");
  5189. string shopname = GetPostString("shopname");
  5190. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5191. string buyernick = GetPostString("buyer_nick");
  5192. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5193. string customer = GetPostString("customer");
  5194. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5195. string design = GetPostString("design");
  5196. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5197. string sellermemo = GetPostString("seller_memo");
  5198. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5199. string supplier = GetPostString("supplier");
  5200. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5201. string date1 = GetPostString("date1");
  5202. string date2 = GetPostString("date2");
  5203. string pldate1 = GetPostString("placedate1");
  5204. string pldate2 = GetPostString("placedate2");
  5205. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5206. {
  5207. if (tid.Length > 0)
  5208. {
  5209. string select_tid = getTidByCtid(tid);
  5210. lw.Add(string.Format("tid='{0}'", select_tid));
  5211. }
  5212. if (buyernick.Length > 0)
  5213. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5214. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5215. if (dw.Length > 0) lw.Add(dw);
  5216. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5217. if (dw_place.Length > 0) lw.Add(dw_place);
  5218. }
  5219. else
  5220. {
  5221. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5222. {
  5223. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5224. }
  5225. }
  5226. string price1 = GetPostString("price1");
  5227. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5228. string price2 = GetPostString("price2");
  5229. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5230. string posTag = CurrentUser.UserPost.Post.Code;
  5231. if (posTag == "Supplier")
  5232. {
  5233. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5234. }
  5235. //lw.Add(string.Format("OrderState >= 6"));
  5236. lw.Add(string.Format("IsSample != 2 "));
  5237. lw.Add(string.Format("isDianziOrder = 0 "));
  5238. //lw.Add(string.Format("IsRefund<={0}", 1));
  5239. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5240. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5241. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5242. foreach (DataRow dr in dt.Rows)
  5243. {
  5244. 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();
  5245. }
  5246. writeGridDataTableJson(dStruct.TotalCount, dt);
  5247. }
  5248. public void get_erp_expresslist()
  5249. {
  5250. int listtype = GetInt("ltype");
  5251. DataStruct dStruct = GetPostStruct();
  5252. List<string> lw = new List<string>();
  5253. string tid = GetPostString("tid");
  5254. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5255. string outsid = GetPostString("out_sid");
  5256. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5257. string importer = GetPostString("ImportUserName");
  5258. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5259. string file = GetPostString("import_file");
  5260. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5261. string printman = GetPostString("printman");
  5262. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5263. string date1 = GetPostString("date1");
  5264. string date2 = GetPostString("date2");
  5265. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5266. if (dw.Length > 0) lw.Add(dw);
  5267. string fdate1 = GetPostString("finishdate1");
  5268. string fdate2 = GetPostString("finishdate2");
  5269. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5270. if (fdw.Length > 0) lw.Add(fdw);
  5271. string supplierId = GetPostString("supplierId");
  5272. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5273. if (listtype == 1)
  5274. {
  5275. lw.Add(string.Format("importUserId !=0"));
  5276. }
  5277. string posTag = CurrentUser.UserPost.Post.Code;
  5278. if (posTag == "Supplier")
  5279. {
  5280. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5281. }
  5282. if (dStruct.PageSize != 100000)
  5283. {
  5284. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5285. }
  5286. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5287. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5288. writeGridDataTableJson(dStruct.TotalCount, dt);
  5289. }
  5290. public void set_erp_buchaorderdelivery()
  5291. {
  5292. if (UrlPostParmsCheck("ctid"))
  5293. {
  5294. string eid = GetPostString("ctid");
  5295. CeErpTradeCell entity = null;
  5296. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5297. if (entity != null)
  5298. {
  5299. if (entity.IsSample != 2)
  5300. {
  5301. returnErrorMsg("补差价单才能标记为已发货");
  5302. return;
  5303. }
  5304. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5305. entity.OrderState = 7;
  5306. entity.Update();
  5307. returnSuccessMsg("操作成功!");
  5308. return;
  5309. }
  5310. returnErrorMsg("找不到记录");
  5311. }
  5312. }
  5313. public void get_stdtemplates()
  5314. {
  5315. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5316. //string res = taobaoHelper.test();
  5317. string res = apiHelper.API_PrintTemplate();
  5318. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5319. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5320. {
  5321. int sidx = res.IndexOf("error_code");
  5322. int eidx = res.IndexOf("success");
  5323. string msg = res.Substring(sidx, eidx - sidx);
  5324. returnErrorMsg(msg);
  5325. return;
  5326. }
  5327. if (res.Length <= 0)
  5328. {
  5329. returnErrorMsg("模板数据为空!");
  5330. return;
  5331. }
  5332. ReturnSuccess(res);
  5333. }
  5334. public void cancel_print_order()
  5335. {
  5336. if (UrlPostParmsCheck("ctid"))
  5337. {
  5338. string ctid = GetPostString("ctid");
  5339. CeErpTradeCell entity = null;
  5340. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5341. if (entity != null)
  5342. {
  5343. string res = "";
  5344. string code = entity.LastBillWaybillCode;
  5345. if (code == "")
  5346. {
  5347. code = entity.OutSid;
  5348. }
  5349. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5350. XLog.SaveLog(0, "取消面单" + res);
  5351. }
  5352. }
  5353. }
  5354. public void set_erp_printwaybill()
  5355. {
  5356. if (UrlPostParmsCheck("ctid"))
  5357. {
  5358. string ctid = GetPostString("ctid");
  5359. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5360. string cpName = GetPostString("cpname");
  5361. string isTogether = GetPostString("together");
  5362. //var res_obj = new
  5363. //{
  5364. // restype = 1,
  5365. // 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\"}"
  5366. //};
  5367. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5368. //ReturnSuccess(ro_json);
  5369. //return;
  5370. bool isUseLastWayBillCode = false;
  5371. CeErpTradeCell entity = null;
  5372. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5373. if (entity != null)
  5374. {
  5375. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5376. {
  5377. isUseLastWayBillCode = true;
  5378. }
  5379. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5380. {
  5381. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5382. return;
  5383. }
  5384. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5385. {
  5386. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5387. return;
  5388. }
  5389. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5390. {
  5391. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5392. return;
  5393. }
  5394. }
  5395. string res = "";
  5396. Api_waybill_code_response_Obj fullObj = null;
  5397. string pData_str = "";
  5398. string curUseWayBillCode = "";
  5399. if (isUseLastWayBillCode == false)
  5400. {
  5401. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5402. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5403. if (res.IndexOf("failure") != -1)
  5404. {
  5405. //int idx = res.IndexOf("sub_message");
  5406. //int idx2 = res.IndexOf("flag");
  5407. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5408. string errMsgNeed = commonHelper.KeepChinese(res);
  5409. var res_objd = new
  5410. {
  5411. restype = 0,
  5412. data = "获取面单失败" + errMsgNeed
  5413. };
  5414. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5415. returnSuccess(ro_jsond);
  5416. if (res.IndexOf("停发") != -1)
  5417. {
  5418. entity.UnusualCon = "物流停发";
  5419. entity.Update();
  5420. }
  5421. //returnErrorMsg("获取面单失败,"+emsg);
  5422. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5423. return;
  5424. }
  5425. else if (res.IndexOf("errorMsg") != -1)
  5426. {
  5427. //int idx = res.IndexOf("errorMsg");
  5428. //int idx2 = res.IndexOf("}]}");
  5429. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5430. string errMsgNeed = commonHelper.KeepChinese(res);
  5431. var res_objf = new
  5432. {
  5433. restype = 0,
  5434. data = "获取面单失败2" + errMsgNeed
  5435. };
  5436. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5437. if (res.IndexOf("停发") != -1)
  5438. {
  5439. entity.UnusualCon = "物流停发";
  5440. entity.Update();
  5441. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5442. if (trade != null)
  5443. {
  5444. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5445. }
  5446. }
  5447. returnSuccess(ro_jsonf);
  5448. //returnErrorMsg("获取面单失败," + emsg);
  5449. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5450. return;
  5451. }
  5452. try
  5453. {
  5454. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5455. //res = res.Replace(" ", "");
  5456. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5457. }
  5458. catch (Exception ex)
  5459. {
  5460. XLog.SaveLog(0, "生成fullObj" + res);
  5461. var res_objf = new
  5462. {
  5463. restype = 0,
  5464. data = "生成fullObj发生错误" + ex.Message
  5465. };
  5466. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5467. returnSuccess(ro_jsonf);
  5468. return;
  5469. }
  5470. if (fullObj.response.data.content.Count > 0)
  5471. {
  5472. ContentItem codeObj = fullObj.response.data.content[0];
  5473. if (cpCode.IndexOf("SFFQ-") != -1)
  5474. {
  5475. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5476. }
  5477. else
  5478. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5479. curUseWayBillCode = codeObj.waybillCode;
  5480. }
  5481. else
  5482. {
  5483. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5484. var res_objf = new
  5485. {
  5486. restype = 0,
  5487. data = "生成fullObj找不到快递单号waybillCode"
  5488. };
  5489. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5490. returnSuccess(ro_jsonf);
  5491. return;
  5492. }
  5493. }
  5494. else
  5495. {
  5496. //使用上次打印的快递单号
  5497. if (cpCode == "SFFQ-LY")
  5498. {
  5499. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5500. }
  5501. else
  5502. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5503. curUseWayBillCode = entity.LastBillWaybillCode;
  5504. }
  5505. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5506. {
  5507. var res_obje = new
  5508. {
  5509. restype = 0,
  5510. data = "获取加密打印数据失败"
  5511. };
  5512. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5513. returnSuccess(ro_jsone);
  5514. entity.LastBillCpCode = cpCode;
  5515. entity.LastBillWaybillCode = curUseWayBillCode;
  5516. entity.Update();
  5517. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5518. //returnErrorMsg("获取加密打印数据失败");
  5519. return;
  5520. }
  5521. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5522. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5523. string btnType = "";
  5524. string errorMsg = "";
  5525. if (entity != null)
  5526. {
  5527. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5528. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5529. //cpcode是 YTO-CAINIAO
  5530. //string comCode = cpCode.Split('-')[0].ToString();
  5531. string apires = "";
  5532. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5533. //isTogether=2是新的合包弹窗
  5534. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5535. {
  5536. if (ctid.IndexOf("N") != -1)
  5537. {
  5538. apires = "发货成功";
  5539. }
  5540. else
  5541. {
  5542. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5543. }
  5544. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5545. //打单后发货
  5546. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5547. {
  5548. try
  5549. {
  5550. btnType = "待发货";
  5551. entity.OutSid = curUseWayBillCode;
  5552. entity.OrderState = 7;
  5553. entity.IsUrgency = false;
  5554. entity.LastBillCpCode = "";
  5555. entity.LastBillWaybillCode = "";
  5556. entity.FinishDeliveryTime = DateTime.Now;
  5557. entity.IsReturn = 0;
  5558. entity.MemoOpt = 0;
  5559. entity.UpdateTime = DateTime.Now;
  5560. entity.Update();
  5561. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5562. //还要插入快递信息到 快递信息表
  5563. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5564. exinfo.tid = entity.ctid;
  5565. exinfo.out_sid = curUseWayBillCode;
  5566. exinfo.company_code = cpCode;
  5567. exinfo.company_name = cpName;
  5568. exinfo.supplierUserName = supplierName;
  5569. exinfo.deliveryType = "发货成功";
  5570. exinfo.print_time = DateTime.Now;
  5571. exinfo.printUser = CurrentUser.UserName;
  5572. exinfo.postData = pData_str;
  5573. exinfo.Create();
  5574. commonHelper.UpdateRelationOrder(entity.ctid);
  5575. CeErpSukuraData.createInfo(ctid, 4);
  5576. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5577. if (entity.SupplierId == 64)
  5578. {
  5579. commonHelper.sendCytExpress(exinfo);
  5580. }
  5581. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5582. if (!string.IsNullOrEmpty(isTogether))
  5583. {
  5584. if (Convert.ToInt32(isTogether) > 0)
  5585. {
  5586. StringBuilder sqlsb = new StringBuilder();
  5587. 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);
  5588. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5589. }
  5590. }
  5591. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5592. }
  5593. catch (Exception ex)
  5594. {
  5595. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5596. }
  5597. }
  5598. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5599. {
  5600. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5601. if (entity.OrderState == 6)
  5602. {
  5603. entity.OrderState = 7;
  5604. }
  5605. entity.UpdateTime = DateTime.Now;
  5606. entity.FinishDeliveryTime = DateTime.Now;
  5607. btnType = "已发货";
  5608. entity.Update();
  5609. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5610. exinfo.tid = entity.ctid;
  5611. exinfo.out_sid = curUseWayBillCode;
  5612. exinfo.company_code = cpCode;
  5613. exinfo.company_name = cpName;
  5614. exinfo.supplierUserName = supplierName;
  5615. exinfo.deliveryType = "发货成功";
  5616. exinfo.print_time = DateTime.Now;
  5617. exinfo.printUser = CurrentUser.UserName;
  5618. exinfo.postData = pData_str;
  5619. exinfo.Create();
  5620. commonHelper.UpdateRelationOrder(entity.ctid);
  5621. CeErpSukuraData.createInfo(entity.ctid, 4);
  5622. if (entity.SupplierId == 64)
  5623. {
  5624. commonHelper.sendCytExpress(exinfo);
  5625. }
  5626. if (!string.IsNullOrEmpty(isTogether))
  5627. {
  5628. if (Convert.ToInt32(isTogether) > 0)
  5629. {
  5630. StringBuilder sqlsb = new StringBuilder();
  5631. 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);
  5632. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5633. }
  5634. }
  5635. //不处理
  5636. }
  5637. else
  5638. {
  5639. entity.UpdateTime = DateTime.Now;
  5640. entity.LastBillCpCode = cpCode;
  5641. entity.LastBillWaybillCode = curUseWayBillCode;
  5642. entity.Update();
  5643. string errmsg = commonHelper.KeepChinese(apires);
  5644. var res_objz = new
  5645. {
  5646. restype = 0,
  5647. data = "打单后发货失败"
  5648. };
  5649. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5650. returnSuccess(ro_jsonz);
  5651. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5652. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5653. return;
  5654. }
  5655. }
  5656. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5657. {
  5658. string ctids = GetPostString("ctids");
  5659. DataTable dt = getSameOrderList(entity, mainEn);
  5660. List<string> list = new List<string>();
  5661. List<string> send_list = new List<string>();
  5662. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5663. CeErpTrade ceErpTrade = new CeErpTrade();
  5664. //可合包的合并一起发货
  5665. if (dt == null && string.IsNullOrEmpty(ctids))
  5666. {
  5667. var res_objz = new
  5668. {
  5669. restype = 0,
  5670. data = "打单后发货失败"
  5671. };
  5672. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5673. returnSuccess(ro_jsonz);
  5674. return;
  5675. }
  5676. if (!string.IsNullOrEmpty(ctids))
  5677. {
  5678. StringBuilder sql = new StringBuilder();
  5679. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5680. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5681. }
  5682. foreach (DataRow row in dt.Rows)
  5683. {
  5684. list.Add("'" + row["ctid"] + "'");
  5685. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5686. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5687. if (ctid.IndexOf("N") != -1)
  5688. {
  5689. apires = "发货成功";
  5690. }
  5691. else
  5692. {
  5693. if (!send_list.Contains(ceErpTrade.tid))
  5694. {
  5695. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5696. }
  5697. else
  5698. {
  5699. apires = "发货成功";
  5700. }
  5701. }
  5702. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5703. {
  5704. send_list.Add(ceErpTrade.tid);
  5705. try
  5706. {
  5707. btnType = "待发货";
  5708. ceErpTradeCell.OutSid = curUseWayBillCode;
  5709. ceErpTradeCell.OrderState = 7;
  5710. ceErpTradeCell.IsUrgency = false;
  5711. ceErpTradeCell.LastBillCpCode = "";
  5712. ceErpTradeCell.LastBillWaybillCode = "";
  5713. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5714. ceErpTradeCell.IsReturn = 0;
  5715. ceErpTradeCell.MemoOpt = 0;
  5716. ceErpTradeCell.UpdateTime = DateTime.Now;
  5717. ceErpTradeCell.Update();
  5718. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5719. //还要插入快递信息到 快递信息表
  5720. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5721. exinfo.tid = ceErpTradeCell.ctid;
  5722. exinfo.out_sid = curUseWayBillCode;
  5723. exinfo.company_code = cpCode;
  5724. exinfo.company_name = cpName;
  5725. exinfo.supplierUserName = supplierName;
  5726. exinfo.deliveryType = "发货成功";
  5727. exinfo.print_time = DateTime.Now;
  5728. exinfo.printUser = CurrentUser.UserName;
  5729. exinfo.postData = pData_str;
  5730. exinfo.Create();
  5731. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5732. CeErpSukuraData.createInfo(ctid, 4);
  5733. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5734. if (ceErpTradeCell.SupplierId == 64)
  5735. {
  5736. commonHelper.sendCytExpress(exinfo);
  5737. }
  5738. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5739. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5740. }
  5741. catch (Exception ex)
  5742. {
  5743. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5744. }
  5745. }
  5746. else
  5747. {
  5748. ceErpTradeCell.UpdateTime = DateTime.Now;
  5749. ceErpTradeCell.LastBillCpCode = cpCode;
  5750. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5751. ceErpTradeCell.Update();
  5752. string errmsg = commonHelper.KeepChinese(apires);
  5753. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5754. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5755. }
  5756. }
  5757. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5758. }
  5759. }
  5760. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5761. var res_obj = new
  5762. {
  5763. restype = 1,
  5764. data = pData_str,
  5765. errorMsg
  5766. };
  5767. string ro_json = JsonConvert.SerializeObject(res_obj);
  5768. ReturnSuccess(ro_json);
  5769. return;
  5770. }
  5771. }
  5772. private string GetUTF8String(byte[] vs)
  5773. {
  5774. throw new NotImplementedException();
  5775. }
  5776. public void set_erp_printwaybill_cn()
  5777. {
  5778. if (UrlPostParmsCheck("ctid"))
  5779. {
  5780. string ctid = GetPostString("ctid");
  5781. string cpCode = GetPostString("cpcode");
  5782. string cpName = GetPostString("cpname");
  5783. string tempUrl = GetPostString("tempurl");
  5784. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5785. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5786. //string res = taobaoHelper.test();
  5787. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5788. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5789. {
  5790. int sidx = res.IndexOf("errorMsg");
  5791. int eidx = res.IndexOf("}");
  5792. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5793. var res_objzxx = new
  5794. {
  5795. restype = 0,
  5796. data = msg
  5797. };
  5798. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5799. returnSuccess(ro_jsonzxx);
  5800. //returnErrorMsg(msg);
  5801. return;
  5802. }
  5803. int idx = res.IndexOf("waybillCode");
  5804. int idx2 = res.IndexOf("printData");
  5805. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5806. string eid = GetPostString("ctid");
  5807. CeErpTradeCell entity = null;
  5808. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5809. if (entity != null)
  5810. {
  5811. string osid = entity.OutSid;
  5812. entity.OutSid = osid + "," + outsid;
  5813. entity.FinishDeliveryTime = DateTime.Now;
  5814. entity.OrderState = 7;
  5815. entity.UpdateTime = DateTime.Now;
  5816. entity.IsReturn = 0;
  5817. entity.Update();
  5818. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5819. exinfo.tid = entity.ctid;
  5820. exinfo.out_sid = outsid;
  5821. exinfo.company_code = cpCode;
  5822. exinfo.company_name = cpName;
  5823. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5824. exinfo.deliveryType = "发货成功";
  5825. exinfo.print_time = DateTime.Now;
  5826. exinfo.printUser = CurrentUser.UserName;
  5827. exinfo.Create();
  5828. if (entity.SupplierId == 64)
  5829. {
  5830. commonHelper.sendCytExpress(exinfo);
  5831. }
  5832. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5833. }
  5834. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5835. var res_objz = new
  5836. {
  5837. restype = 1,
  5838. data = res
  5839. };
  5840. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5841. returnSuccess(ro_jsonz);
  5842. //ReturnSuccess(res);
  5843. }
  5844. }
  5845. ////打单,打印面单 获取面单号
  5846. //public void set_erp_printwaybill()
  5847. //{
  5848. // if (UrlPostParmsCheck("ctid"))
  5849. // {
  5850. // string ctid = GetPostString("ctid");
  5851. // string cpCode = GetPostString("cpcode");
  5852. // string tempUrl = GetPostString("tempurl");
  5853. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5854. // //string res = taobaoHelper.test();
  5855. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5856. // if (res.IndexOf("error_response") != -1)
  5857. // {
  5858. // int sidx = res.IndexOf("sub_msg");
  5859. // int eidx = res.IndexOf("request_id");
  5860. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5861. // returnErrorMsg(msg);
  5862. // return;
  5863. // }
  5864. // int idx = res.IndexOf("waybill_code");
  5865. // int idx2 = res.IndexOf("}]}");
  5866. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5867. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5868. // ReturnSuccess(res);
  5869. // }
  5870. //}
  5871. public void cancel_erp_aftersale()
  5872. {
  5873. if (UrlPostParmsCheck("ctid"))
  5874. {
  5875. string eid = GetPostString("ctid");
  5876. CeErpTradeCell entity = null;
  5877. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5878. if (entity != null)
  5879. {
  5880. //有过处理的售后,取消也不能删除 售 字,保留
  5881. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5882. {
  5883. entity.AfterSaleState = 4;
  5884. }
  5885. else
  5886. entity.AfterSaleState = 0;
  5887. entity.UpdateTime = DateTime.Now;
  5888. entity.Update();
  5889. returnSuccessMsg("操作成功!");
  5890. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5891. return;
  5892. }
  5893. returnErrorMsg("找不到订单记录");
  5894. }
  5895. }
  5896. public void get_erp_aftersalelist()
  5897. {
  5898. DataStruct dStruct = GetPostStruct();
  5899. List<string> lw = new List<string>();
  5900. int st = GetInt("st");
  5901. string tid = GetPostString("ctid");
  5902. if (st == 3)
  5903. {
  5904. if (tid.Length > 0)
  5905. {
  5906. string select_tid = getTidByCtid(tid);
  5907. lw.Add(string.Format("tid='{0}'", select_tid));
  5908. }
  5909. }
  5910. else
  5911. {
  5912. if (tid.Length > 0)
  5913. {
  5914. string select_tid = getTidByCtid(tid);
  5915. lw.Add(string.Format("tid='{0}'", select_tid));
  5916. }
  5917. }
  5918. string shopname = GetPostString("shopname");
  5919. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5920. string buyernick = GetPostString("buyer_nick");
  5921. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5922. string sellermemo = GetPostString("seller_memo");
  5923. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5924. string orderState = GetPostString("orderState");
  5925. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5926. string afterState = GetPostString("afterstate");
  5927. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5928. string date1 = GetPostString("date1");
  5929. string date2 = GetPostString("date2");
  5930. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5931. if (dw.Length > 0) lw.Add(dw);
  5932. string price1 = GetPostString("price1");
  5933. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5934. string price2 = GetPostString("price2");
  5935. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5936. //lw.Add(string.Format("IsRefund!={0}", 1));
  5937. string reason = GetPostString("reason");
  5938. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5939. string method = GetPostString("method");
  5940. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5941. string handler = GetPostString("handler");
  5942. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5943. string handledate1 = GetPostString("handledate1");
  5944. string handledate2 = GetPostString("handledate2");
  5945. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5946. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5947. string finish1 = GetPostString("finishdate1");
  5948. string finish2 = GetPostString("finishdate2");
  5949. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5950. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5951. string afterdate1 = GetPostString("afterdate1");
  5952. string afterdate2 = GetPostString("afterdate2");
  5953. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5954. if (afterDate.Length > 0) lw.Add(afterDate);
  5955. string supplier = GetPostString("supplier");
  5956. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5957. string responsible = GetPostString("responsibleman");
  5958. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5959. string customer = GetPostString("customer");
  5960. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5961. string design = GetPostString("design");
  5962. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5963. string afterMemoType = GetPostString("aftermemotype");
  5964. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5965. string posCode = CurrentUser.UserPost.Post.Code;
  5966. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5967. //{
  5968. // string vstate = GetPostString("vstate");
  5969. // if (vstate.Length > 0)
  5970. // {
  5971. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5972. // }
  5973. // if (posCode == "Supplier")
  5974. // {
  5975. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5976. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5977. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5978. // }
  5979. // else
  5980. // {
  5981. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5982. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5983. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5984. // {
  5985. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5986. // }
  5987. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5988. // {
  5989. // int orgid = CurrentUser.UserPost.OrgID;
  5990. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5991. // }
  5992. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5993. // {
  5994. // string shopid = CurrentUser.User.pemShop;
  5995. // lw.Add(string.Format("shopId in ({0})", shopid));
  5996. // }
  5997. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5998. // //{
  5999. // // int org_id = CurrentUser.UserPost.OrgID;
  6000. // // lw.Add(string.Format("OrgID={0}", org_id));
  6001. // //}
  6002. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6003. // }
  6004. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6005. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6006. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6007. //}
  6008. if (st == 5)
  6009. {
  6010. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6011. {
  6012. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6013. {
  6014. string shopid = CurrentUser.User.pemShop;
  6015. lw.Add(string.Format("shopId in ({0})", shopid));
  6016. }
  6017. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6018. {
  6019. int mrOrgid = CurrentUser.UserPost.OrgID;
  6020. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6021. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6022. }
  6023. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6024. //{
  6025. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6026. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6027. //}
  6028. else
  6029. {
  6030. string userIdStr = "";
  6031. if (posCode == "CustomerService")
  6032. {
  6033. userIdStr = CurrentUser.UserID + "_k";
  6034. }
  6035. else if (posCode == "Designer" || posCode == "wxDesigner")
  6036. {
  6037. userIdStr = CurrentUser.UserID + "_s";
  6038. }
  6039. else if (posCode == "Place")
  6040. {
  6041. userIdStr = CurrentUser.UserID + "_x";
  6042. }
  6043. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6044. }
  6045. }
  6046. string placedate1 = GetPostString("placedate1");
  6047. string placedate2 = GetPostString("placedate2");
  6048. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6049. if (dwplace.Length > 0) lw.Add(dwplace);
  6050. string supState = GetPostString("supState");
  6051. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6052. string searchType = GetPostString("searchType");
  6053. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6054. {
  6055. lw.Add(string.Format("BackNum>1"));
  6056. }
  6057. lw.Add(string.Format("AfterSaleState>0"));
  6058. if (ex_psize > 0)
  6059. {
  6060. if (CurrentUser.UserPost.Post.Code == "Finance")
  6061. dStruct.Order = "pay_time desc";
  6062. else
  6063. dStruct.Order = "HandleTime desc";
  6064. }
  6065. else
  6066. dStruct.Order = "HandleTime desc";
  6067. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6068. DataTable dt = WebCache.GetData("view_test", dStruct);
  6069. writeGridDataTableJson(dStruct.TotalCount, dt);
  6070. }
  6071. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6072. //{
  6073. // lw.Add(string.Format("AfterSaleState=4"));
  6074. // string code = CurrentUser.UserPost.Post.Code;
  6075. // if (code == "CustomerService")
  6076. // {
  6077. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6078. // }
  6079. // else if (code == "Designer" || code == "DesignerMr")
  6080. // {
  6081. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6082. // }
  6083. // else if (code == "Place" || code == "PlaceMr")
  6084. // {
  6085. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6086. // }
  6087. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6088. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6089. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6090. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6091. //}
  6092. //else //处理中的售后,待处理和处理中合并
  6093. //{
  6094. // if (afterState.Length <= 0)
  6095. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6096. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6097. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6098. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6099. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6100. //}
  6101. }
  6102. public void get_erp_disagreeftersalelist()
  6103. {
  6104. DataStruct dStruct = GetPostStruct();
  6105. List<string> lw = new List<string>();
  6106. int st = 2;
  6107. string tid = GetPostString("ctid");
  6108. if (tid.Length > 0)
  6109. {
  6110. string select_tid = getTidByCtid(tid);
  6111. lw.Add(string.Format("tid='{0}'", select_tid));
  6112. }
  6113. string shopname = GetPostString("shopname");
  6114. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6115. string buyernick = GetPostString("buyer_nick");
  6116. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6117. string sellermemo = GetPostString("seller_memo");
  6118. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6119. string orderState = GetPostString("orderState");
  6120. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6121. string afterState = GetPostString("afterstate");
  6122. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6123. string date1 = GetPostString("date1");
  6124. string date2 = GetPostString("date2");
  6125. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6126. if (dw.Length > 0) lw.Add(dw);
  6127. string price1 = GetPostString("price1");
  6128. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6129. string price2 = GetPostString("price2");
  6130. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6131. //lw.Add(string.Format("IsRefund!={0}", 1));
  6132. string reason = GetPostString("reason");
  6133. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6134. string method = GetPostString("method");
  6135. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6136. string handler = GetPostString("handler");
  6137. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6138. string handledate1 = GetPostString("handledate1");
  6139. string handledate2 = GetPostString("handledate2");
  6140. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6141. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6142. string afterdate1 = GetPostString("afterdate1");
  6143. string afterdate2 = GetPostString("afterdate2");
  6144. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6145. if (afterDate.Length > 0) lw.Add(afterDate);
  6146. string backdate1 = GetPostString("backdate1");
  6147. string backdate2 = GetPostString("backdate2");
  6148. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6149. if (backDate.Length > 0) lw.Add(backDate);
  6150. string supplier = GetPostString("supplier");
  6151. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6152. string responsible = GetPostString("responsibleman");
  6153. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6154. string customer = GetPostString("customer");
  6155. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6156. string design = GetPostString("design");
  6157. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6158. string afterSaleMemo = GetPostString("afterSaleMemo");
  6159. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6160. string afterMemoType = GetPostString("aftermemotype");
  6161. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6162. string aftersakereason = GetPostString("aftersakereason");
  6163. if (aftersakereason.Length > 0)
  6164. {
  6165. if (aftersakereason == "1")
  6166. {
  6167. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6168. }
  6169. if (aftersakereason == "2")
  6170. {
  6171. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6172. }
  6173. }
  6174. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6175. string poscode = CurrentUser.UserPost.Post.Code;
  6176. if (poscode != "SysAdmin")
  6177. {
  6178. string shopid = CurrentUser.User.pemShop;
  6179. lw.Add(string.Format("shopId in ({0})", shopid));
  6180. }
  6181. string searchType = GetPostString("searchType");
  6182. if (searchType == "wait")
  6183. {
  6184. lw.Add(string.Format("HandleTime is null"));
  6185. }
  6186. if (searchType == "handling")
  6187. {
  6188. lw.Add(string.Format("HandleTime is not null "));
  6189. }
  6190. if (searchType == "back" || searchType == "puBack")
  6191. {
  6192. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6193. }
  6194. if (searchType == "reBack")
  6195. {
  6196. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6197. }
  6198. if (searchType == "moreBack")
  6199. {
  6200. lw.Add(string.Format("backNum > 1"));
  6201. }
  6202. lw.Add(string.Format("(AfterSaleState=5)"));
  6203. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6204. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6205. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6206. writeGridDataTableJson(dStruct.TotalCount, dt);
  6207. }
  6208. public void get_erp_handlingaftersalelist()
  6209. {
  6210. DataStruct dStruct = GetPostStruct();
  6211. List<string> lw = new List<string>();
  6212. int st = 2;
  6213. string tid = GetPostString("ctid");
  6214. if (tid.Length > 0)
  6215. {
  6216. string select_tid = getTidByCtid(tid);
  6217. lw.Add(string.Format("tid='{0}'", select_tid));
  6218. }
  6219. string shopname = GetPostString("shopname");
  6220. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6221. string buyernick = GetPostString("buyer_nick");
  6222. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6223. string sellermemo = GetPostString("seller_memo");
  6224. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6225. string orderState = GetPostString("orderState");
  6226. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6227. string afterState = GetPostString("afterstate");
  6228. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6229. string date1 = GetPostString("date1");
  6230. string date2 = GetPostString("date2");
  6231. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6232. if (dw.Length > 0) lw.Add(dw);
  6233. string price1 = GetPostString("price1");
  6234. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6235. string price2 = GetPostString("price2");
  6236. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6237. //lw.Add(string.Format("IsRefund!={0}", 1));
  6238. string reason = GetPostString("reason");
  6239. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6240. string method = GetPostString("method");
  6241. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6242. string handler = GetPostString("handler");
  6243. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6244. string handledate1 = GetPostString("handledate1");
  6245. string handledate2 = GetPostString("handledate2");
  6246. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6247. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6248. string afterdate1 = GetPostString("afterdate1");
  6249. string afterdate2 = GetPostString("afterdate2");
  6250. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6251. if (afterDate.Length > 0) lw.Add(afterDate);
  6252. string supplier = GetPostString("supplier");
  6253. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6254. string responsible = GetPostString("responsibleman");
  6255. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6256. string customer = GetPostString("customer");
  6257. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6258. string design = GetPostString("design");
  6259. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6260. string afterSaleMemo = GetPostString("afterSaleMemo");
  6261. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6262. string afterMemoType = GetPostString("aftermemotype");
  6263. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6264. string afterresult = GetPostString("afterresult");
  6265. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6266. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6267. string poscode = CurrentUser.UserPost.Post.Code;
  6268. if (poscode != "SysAdmin")
  6269. {
  6270. string shopid = CurrentUser.User.pemShop;
  6271. lw.Add(string.Format("shopId in ({0})", shopid));
  6272. }
  6273. string searchType = GetPostString("searchType");
  6274. if (searchType == "wait")
  6275. {
  6276. lw.Add(string.Format("HandleTime is null"));
  6277. }
  6278. if (searchType == "documentary")
  6279. {
  6280. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6281. }
  6282. if (searchType == "handling")
  6283. {
  6284. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6285. }
  6286. if (searchType == "back" || searchType == "puBack")
  6287. {
  6288. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6289. }
  6290. if (searchType == "reBack")
  6291. {
  6292. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6293. }
  6294. if (afterState.Length <= 0)
  6295. {
  6296. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6297. }
  6298. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6299. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6300. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6301. writeGridDataTableJson(dStruct.TotalCount, dt);
  6302. }
  6303. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6304. //public void get_erp_back_handlingaftersalelist()
  6305. //{
  6306. // DataStruct dStruct = GetPostStruct();
  6307. // List<string> lw = new List<string>();
  6308. // string tid = GetPostString("ctid");
  6309. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6310. // string shopname = GetPostString("shopname");
  6311. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6312. // string buyernick = GetPostString("buyer_nick");
  6313. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6314. // string sellermemo = GetPostString("seller_memo");
  6315. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6316. // string orderState = GetPostString("orderState");
  6317. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6318. // string afterState = GetPostString("afterstate");
  6319. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6320. // string date1 = GetPostString("date1");
  6321. // string date2 = GetPostString("date2");
  6322. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6323. // if (dw.Length > 0) lw.Add(dw);
  6324. // string price1 = GetPostString("price1");
  6325. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6326. // string price2 = GetPostString("price2");
  6327. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6328. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6329. // string reason = GetPostString("reason");
  6330. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6331. // string method = GetPostString("method");
  6332. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6333. // string handler = GetPostString("handler");
  6334. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6335. // string handledate1 = GetPostString("handledate1");
  6336. // string handledate2 = GetPostString("handledate2");
  6337. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6338. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6339. // string afterdate1 = GetPostString("afterdate1");
  6340. // string afterdate2 = GetPostString("afterdate2");
  6341. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6342. // if (afterDate.Length > 0) lw.Add(afterDate);
  6343. // string supplier = GetPostString("supplier");
  6344. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6345. // string responsible = GetPostString("responsibleman");
  6346. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6347. // string customer = GetPostString("customer");
  6348. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6349. // string design = GetPostString("design");
  6350. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6351. // string afterMemoType = GetPostString("aftermemotype");
  6352. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6353. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6354. // if (afterState.Length <= 0)
  6355. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6356. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6357. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6358. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6359. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6360. //}
  6361. public void get_erp_aftersaleverifylist()
  6362. {
  6363. DataStruct dStruct = GetPostStruct();
  6364. List<string> lw = new List<string>();
  6365. string tid = GetPostString("ctid");
  6366. if (tid.Length > 0)
  6367. {
  6368. string select_tid = getTidByCtid(tid);
  6369. lw.Add(string.Format("otid='{0}'", select_tid));
  6370. }
  6371. string shopname = GetPostString("shopname");
  6372. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6373. string buyernick = GetPostString("buyer_nick");
  6374. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6375. string sellermemo = GetPostString("seller_memo");
  6376. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6377. string orderState = GetPostString("orderState");
  6378. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6379. //lw.Add(string.Format("IsRefund!={0}", 1));
  6380. string reason = GetPostString("reason");
  6381. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6382. string method = GetPostString("method");
  6383. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6384. string handler = GetPostString("handler");
  6385. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6386. string handledate1 = GetPostString("handledate1");
  6387. string handledate2 = GetPostString("handledate2");
  6388. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6389. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6390. string finish1 = GetPostString("finishdate1");
  6391. string finish2 = GetPostString("finishdate2");
  6392. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6393. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6394. string supplier = GetPostString("supplier");
  6395. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6396. string responsible = GetPostString("responsibleman");
  6397. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6398. string posCode = CurrentUser.UserPost.Post.Code;
  6399. string vstate = GetPostString("vstate");
  6400. if (vstate.Length > 0)
  6401. {
  6402. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6403. }
  6404. if (posCode == "Supplier")
  6405. {
  6406. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6407. lw.Add(string.Format("VerifyState = 0"));
  6408. lw.Add("type = 1");
  6409. lw.Add(string.Format("AfterSaleState={0}", 3));
  6410. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6411. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6412. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6413. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6414. writeGridDataTableJson(dStruct.TotalCount, dt);
  6415. }
  6416. else if (posCode == "logistics")
  6417. {
  6418. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6419. lw.Add(string.Format("VerifyState = 0"));
  6420. lw.Add("type = 2");
  6421. lw.Add(string.Format("AfterSaleState={0}", 3));
  6422. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6423. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6424. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6425. writeGridDataTableJson(dStruct.TotalCount, dt);
  6426. }
  6427. else
  6428. {
  6429. lw.Add(string.Format("(AfterSaleState = 3)"));
  6430. string reasonState = GetPostString("reasonState");
  6431. lw.Add("type = 0");
  6432. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6433. || posCode == "Summarize" || posCode == "Finance")
  6434. {
  6435. if (reasonState == "2")
  6436. {
  6437. lw.Add("VerifyState = 3");
  6438. }
  6439. else if (reasonState == "1")
  6440. {
  6441. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6442. }
  6443. else
  6444. {
  6445. lw.Add("VerifyState in (0,3)");
  6446. }
  6447. //不加条件,可以看全部
  6448. }
  6449. 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")
  6450. {
  6451. int orgid = CurrentUser.UserPost.OrgID;
  6452. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6453. if (string.IsNullOrEmpty(manageOrgId))
  6454. {
  6455. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6456. }
  6457. else
  6458. {
  6459. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6460. }
  6461. if (reasonState == "1")
  6462. {
  6463. lw.Add("VerifyState = 3");
  6464. }
  6465. else if (reasonState == "2")
  6466. {
  6467. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6468. }
  6469. else
  6470. {
  6471. }
  6472. }
  6473. else
  6474. {
  6475. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6476. }
  6477. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6478. //{
  6479. // int org_id = CurrentUser.UserPost.OrgID;
  6480. // lw.Add(string.Format("OrgID={0}", org_id));
  6481. //}
  6482. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6483. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6484. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6485. writeGridDataTableJson(dStruct.TotalCount, dt);
  6486. }
  6487. }
  6488. public void get_erp_finishaftersalelist()
  6489. {
  6490. DataStruct dStruct = GetPostStruct();
  6491. List<string> lw = new List<string>();
  6492. int st = 4;
  6493. string tid = GetPostString("ctid");
  6494. if (tid.Length > 0)
  6495. {
  6496. string select_tid = getTidByCtid(tid);
  6497. lw.Add(string.Format("otid='{0}'", select_tid));
  6498. }
  6499. string shopname = GetPostString("shopname");
  6500. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6501. //lw.Add(string.Format("IsRefund!={0}", 1));
  6502. string reason = GetPostString("reason");
  6503. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6504. string method = GetPostString("method");
  6505. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6506. string buyernick = GetPostString("buyer_nick");
  6507. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6508. string handler = GetPostString("handler");
  6509. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6510. string handledate1 = GetPostString("handledate1");
  6511. string handledate2 = GetPostString("handledate2");
  6512. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6513. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6514. string finish1 = GetPostString("finishdate1");
  6515. string finish2 = GetPostString("finishdate2");
  6516. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6517. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6518. string supplier = GetPostString("supplier");
  6519. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6520. string responsible = GetPostString("responsibleman");
  6521. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6522. string vstate = GetPostString("vstate");
  6523. if (vstate.Length > 0)
  6524. {
  6525. if ("3".Equals(vstate))
  6526. {
  6527. lw.Add(string.Format("IsTem=1"));
  6528. }
  6529. else
  6530. {
  6531. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6532. }
  6533. }
  6534. lw.Add(string.Format("AfterSaleState=4"));
  6535. string code = CurrentUser.UserPost.Post.Code;
  6536. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6537. {
  6538. //不加条件,可以看全部
  6539. }
  6540. else if (code == "Supplier")
  6541. {
  6542. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6543. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6544. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6545. }
  6546. else if (code == "logistics")
  6547. {
  6548. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6549. lw.Add("type = 2");
  6550. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6551. }
  6552. 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")
  6553. {
  6554. int orgid = CurrentUser.UserPost.OrgID;
  6555. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6556. if (string.IsNullOrEmpty(manageOrgIds))
  6557. {
  6558. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6559. }
  6560. else
  6561. {
  6562. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6563. }
  6564. }
  6565. else
  6566. {
  6567. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6568. }
  6569. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6570. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6571. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6572. writeGridDataTableJson(dStruct.TotalCount, dt);
  6573. }
  6574. public void handle_erp_aftersale()
  6575. {
  6576. if (UrlPostParmsCheck("ctid"))
  6577. {
  6578. string eid = GetPostString("ctid");
  6579. string responStr = GetPostString("AfterSaleResponsible");
  6580. if (responStr.Length <= 0)
  6581. {
  6582. returnErrorMsg("售后责任人不能为空");
  6583. return;
  6584. }
  6585. bool isDesign = false;
  6586. double designFree = 0.00;
  6587. int responsibleId = 0;
  6588. CeErpTradeCell entity = null;
  6589. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6590. if (entity != null)
  6591. {
  6592. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6593. string afterMethod = GetPostString("AfterSaleMethod");
  6594. if (isNeedNewOrder == 1)
  6595. {
  6596. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6597. bool ishav = true;
  6598. if (newentity == null)
  6599. {
  6600. newentity = entity.Clone() as CeErpTradeCell;
  6601. ishav = false;
  6602. newentity.ctid = "S_" + entity.ctid;
  6603. newentity.OrderState = 0;
  6604. //唯一标识
  6605. newentity.OrderSn = newentity.ctid;
  6606. string orderSn = dataHelper.getSaleOrderSn();
  6607. if (orderSn != "")
  6608. {
  6609. newentity.OrderSn = orderSn;
  6610. }
  6611. }
  6612. newentity.UpdateTime = DateTime.Now;
  6613. newentity.AfterSaleState = 0;
  6614. newentity.AfterSaleMethod = afterMethod;
  6615. if (!ishav)
  6616. {
  6617. string memo_str = newentity.seller_memo;
  6618. memo_str = memo_str.Replace("(", "(");
  6619. memo_str = memo_str.Replace(")", ")");
  6620. int sIndex = memo_str.IndexOf("(");
  6621. int eIndex = memo_str.IndexOf(")");
  6622. if (sIndex == -1 || eIndex == -1)
  6623. {
  6624. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6625. return;
  6626. }
  6627. string first = memo_str.Substring(0, sIndex + 1);
  6628. string memoCtid = newentity.OrderSn;
  6629. //if (memoCtid.IndexOf("C") != -1)
  6630. //{
  6631. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6632. //if (CIdx.IndexOf("+") != -1)
  6633. //{
  6634. //CIdx = "C" + CIdx.Split('+')[1];
  6635. //}
  6636. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6637. //}
  6638. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6639. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6640. string newMemo = first + memoCtid + last;
  6641. newentity.seller_memo = newMemo;
  6642. newentity.FinishPlaceTime = null;
  6643. newentity.UnusualTag = 0;
  6644. newentity.UnusualCon = "";
  6645. newentity.UnusualTime = null;
  6646. newentity.AfterSaleMemo = "";
  6647. newentity.AfterSaleMethod = afterMethod;
  6648. newentity.AfterSalePreTime = null;
  6649. newentity.AfterSaleReason = "";
  6650. newentity.AfterSaleResponsible = "";
  6651. newentity.AfterSaleState = 0;
  6652. newentity.AfterSaleTime = null;
  6653. newentity.AfterSaleUserId = 0;
  6654. newentity.AfterSaleSupplierState = 0;
  6655. newentity.LastBillWaybillCode = "";
  6656. newentity.LastBillCpCode = "";
  6657. newentity.FinishAfterSaleTime = null;
  6658. newentity.HandleTime = null;
  6659. newentity.IsSF = 0;
  6660. newentity.IsOldCustomer = 0;
  6661. newentity.UrgencyTime = null;
  6662. newentity.ResponsibleUserId = "";
  6663. newentity.IsVerifyToSupplier = false;
  6664. newentity.payment = 0;
  6665. newentity.CheckMemo = "";
  6666. newentity.OutSid = "";
  6667. newentity.CheckOrderTime = null;
  6668. newentity.MemoOpt = 0;
  6669. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6670. }
  6671. newentity.isAfterSaleOrder = 1;
  6672. newentity.IsRefund = 0;
  6673. string receiveMobile = GetPostString("receiver_mobile");
  6674. if (receiveMobile.Length > 0)
  6675. {
  6676. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6677. if (trade != null)
  6678. {
  6679. trade.receiver_name = GetPostString("receiver_name");
  6680. trade.receiver_mobile = receiveMobile;
  6681. trade.receiver_state = GetPostString("receiver_state");
  6682. trade.receiver_city = GetPostString("receiver_city");
  6683. trade.receiver_district = GetPostString("receiver_district");
  6684. trade.receiver_address = GetPostString("receiver_address");
  6685. newentity.IsOffLineOrder = 1;
  6686. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6687. }
  6688. }
  6689. string st = GetPostString("ToState");
  6690. if (st.Length > 0)
  6691. {
  6692. if (newentity.OrderState <= 3)
  6693. {
  6694. newentity.WaitDesignTime = DateTime.Now;
  6695. newentity.StartDesignTime = null;
  6696. newentity.FinishDesignTime = null;
  6697. newentity.OrderState = 3;
  6698. if (st == "下单员")
  6699. {
  6700. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6701. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6702. {
  6703. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6704. }
  6705. }
  6706. else
  6707. {
  6708. newentity.WaitDesignTime = DateTime.Now;
  6709. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6710. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6711. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6712. {
  6713. DataRow user = dt1.Rows[0];
  6714. //找主管
  6715. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6716. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6717. if (dt != null && dt.Rows.Count > 0)
  6718. {
  6719. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6720. newentity.DesignUserId = designMr;
  6721. string key = "aftersale_order_" + designMr;
  6722. if (RedisHelper.HasKey(key))
  6723. {
  6724. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6725. list.Add(newentity.ctid);
  6726. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6727. }
  6728. }
  6729. //账号正常
  6730. if (user["State"].ToString() == "0")
  6731. {
  6732. newentity.DesignUserId = entity.DesignUserId;
  6733. string key = "aftersale_order_" + entity.DesignUserId;
  6734. if (RedisHelper.HasKey(key))
  6735. {
  6736. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6737. list.Add(newentity.ctid);
  6738. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6739. }
  6740. }
  6741. }
  6742. }
  6743. }
  6744. if (entity.IsXianHuo == 1)
  6745. {
  6746. newentity.OrderState = 6;
  6747. entity.FinishPlaceTime = DateTime.Now;
  6748. }
  6749. }
  6750. if (ishav)
  6751. {
  6752. newentity.Update();
  6753. }
  6754. else
  6755. {
  6756. newentity.Create();
  6757. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6758. newCellExtend.ctid = newentity.ctid;
  6759. newCellExtend.orderFrom = 20;
  6760. newCellExtend.orderType = 30;
  6761. if (st == "下单员")
  6762. {
  6763. }
  6764. else
  6765. {
  6766. newCellExtend.ReprintTime = DateTime.Now;
  6767. }
  6768. newCellExtend.Create();
  6769. }
  6770. if (st != "下单员")
  6771. {
  6772. if (entity.DispatchSort == 2)
  6773. {
  6774. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6775. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6776. }
  6777. }
  6778. }
  6779. //处理售后扩展
  6780. string resIdStr = GetPostString("ResponsibleUserId");
  6781. string refundFees = GetPostString("refundFrees");
  6782. int IsComplain = GetPostInt("isComplain");
  6783. int IsBad = GetPostInt("isBad");
  6784. string IsOriginal = GetPostString("isOriginal");
  6785. double diffResultPrice = GetPostDouble("diffResultPrice");
  6786. string textResult = GetPostString("textResult");
  6787. string supplierResponsible = GetPostString("supplierResponsible");
  6788. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6789. if (ceErpTradeAfterSaleExtend == null)
  6790. {
  6791. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6792. ceErpTradeAfterSaleExtend.tid = eid;
  6793. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6794. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6795. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6796. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6797. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6798. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6799. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6800. ceErpTradeAfterSaleExtend.Create();
  6801. }
  6802. else
  6803. {
  6804. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6805. {
  6806. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6807. }
  6808. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6809. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6810. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6811. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6812. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6813. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6814. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6815. ceErpTradeAfterSaleExtend.Update();
  6816. }
  6817. int gysid = GetPostInt("ResponsibleSupId");
  6818. if (entity.AfterSaleUserId == 0)
  6819. {
  6820. entity.AfterSaleUserId = CurrentUser.UserID;
  6821. }
  6822. entity.ResponsibleUserId = resIdStr;
  6823. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6824. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6825. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6826. {
  6827. CeErpTradeResponsible.DelByTid(eid, -1);
  6828. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6829. int backNum = 0;
  6830. if (number != null)
  6831. {
  6832. backNum = number.BackNum;
  6833. }
  6834. char[] separator = { ',' };
  6835. string[] sArray = resIdStr.Split(separator);
  6836. string[] refundFreeList = { };
  6837. if (refundFees.Length > 0)
  6838. {
  6839. refundFreeList = refundFees.Split(separator);
  6840. }
  6841. int index = -1;
  6842. foreach (string i in sArray)
  6843. {
  6844. index++;
  6845. if (i.Length <= 0) continue;
  6846. char[] separator2 = { '_' };
  6847. string idstr = i.Split(separator2)[0];
  6848. string idtype = i.Split(separator2)[1];
  6849. double refudFree = 0;
  6850. if (refundFreeList.Length > 0)
  6851. {
  6852. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6853. }
  6854. if (idtype == "s")
  6855. {
  6856. isDesign = true;
  6857. designFree = refudFree;
  6858. }
  6859. int userId = Convert.ToInt32(idstr);
  6860. int type = 0;
  6861. if (idtype == "g")
  6862. {
  6863. type = 1;
  6864. }
  6865. if (idtype == "w")
  6866. {
  6867. type = 2;
  6868. }
  6869. if (idtype == "t")
  6870. {
  6871. type = 3;
  6872. }
  6873. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6874. if (ceErpTradeResponsible == null)
  6875. {
  6876. ceErpTradeResponsible = new CeErpTradeResponsible();
  6877. ceErpTradeResponsible.tid = eid;
  6878. ceErpTradeResponsible.UserId = userId;
  6879. ceErpTradeResponsible.createdTime = DateTime.Now;
  6880. ceErpTradeResponsible.type = type;
  6881. if (type == 1)
  6882. {
  6883. ceErpTradeResponsible.IsSup = 1;
  6884. }
  6885. if (type == 2)
  6886. {
  6887. ceErpTradeResponsible.IsFlow = 1;
  6888. }
  6889. }
  6890. ceErpTradeResponsible.RefundFee = refudFree;
  6891. ceErpTradeResponsible.VerifyState = 0;
  6892. if (userId == 2125 || idtype == "w")
  6893. {
  6894. ceErpTradeResponsible.VerifyState = 1;
  6895. }
  6896. if (idtype == "w" && userId == 101)
  6897. {
  6898. ceErpTradeResponsible.VerifyState = 0;
  6899. }
  6900. if (ceErpTradeResponsible.ID > 0)
  6901. {
  6902. ceErpTradeResponsible.Update();
  6903. }
  6904. else
  6905. {
  6906. ceErpTradeResponsible.Create();
  6907. }
  6908. if (isDesign)
  6909. {
  6910. responsibleId = ceErpTradeResponsible.ID;
  6911. }
  6912. }
  6913. CeErpTradeResponsible.NumByTid(backNum, eid);
  6914. }
  6915. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6916. if (ceErpTradeCellExtend != null)
  6917. {
  6918. ceErpTradeCellExtend.returnVisit = 0;
  6919. ceErpTradeCellExtend.Update();
  6920. }
  6921. if (entity.HandleTime != null)
  6922. {
  6923. if (entity.AfterSaleState == 1)
  6924. {
  6925. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6926. }
  6927. else
  6928. {
  6929. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6930. }
  6931. }
  6932. else
  6933. {
  6934. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6935. entity.HandleTime = DateTime.Now;
  6936. }
  6937. bool isCompale = false;
  6938. if (entity.AfterSaleState == 5)
  6939. {
  6940. isCompale = true;
  6941. entity.AfterSaleState = 3;
  6942. }
  6943. entity.AfterSaleSupplierState = 0;
  6944. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6945. {
  6946. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6947. }
  6948. string sImgs = GetPostString("img");
  6949. entity.AfterSaleSupplierImg = sImgs;
  6950. entity.supRefundType = GetPostString("supRefundType");
  6951. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6952. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6953. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6954. entity.AfterSaleMemoType = GetPostString("MemoType");
  6955. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6956. {
  6957. //entity.AfterSaleSupplierState = 2;
  6958. }
  6959. string df = GetPostString("DeductFee");
  6960. if (df == "")
  6961. {
  6962. df = "0";
  6963. }
  6964. string rf = GetPostString("RefundFee");
  6965. if (rf == "")
  6966. {
  6967. rf = "0";
  6968. }
  6969. string pm = GetPostString("AfterSalePayment");
  6970. if (pm == "")
  6971. {
  6972. pm = "0";
  6973. }
  6974. entity.AfterSalePayment = Convert.ToDouble(pm);
  6975. entity.DeductFee = Convert.ToDouble(df);
  6976. entity.RefundFee = Convert.ToDouble(rf);
  6977. entity.UpdateTime = DateTime.Now;
  6978. entity.Update();
  6979. string toState = GetPostString("ToState");
  6980. string original = GetPostString("isOriginal");
  6981. ApiVo apiVo = new ApiVo();
  6982. apiVo.orderNumber = entity.ctid;
  6983. apiVo.actionName = "afterDesign";
  6984. apiVo.orderRemarks = entity.AfterSaleMethod;
  6985. apiVo.reasonRemarks = entity.AfterSaleReason;
  6986. apiVo.isDesign = isDesign;
  6987. apiVo.designFree = designFree;
  6988. apiVo.responsibleId = responsibleId;
  6989. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6990. if (toState == "设计师")
  6991. {
  6992. apiVo.isOriginal = Convert.ToBoolean(original);
  6993. }
  6994. designHelper.API_WorkCore(apiVo);//afterDesign
  6995. CeErpMethod methodSql = new CeErpMethod();
  6996. methodSql.con = entity.AfterSaleMethod;
  6997. methodSql.addTime = DateTime.Now;
  6998. methodSql.Create();
  6999. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7000. CeErpMethod.ExecuteNonQuery(delsql);
  7001. if (isCompale)
  7002. {
  7003. aftersale_data_change(entity.ctid);
  7004. }
  7005. returnSuccessMsg("操作成功!");
  7006. return;
  7007. }
  7008. returnErrorMsg("找不到订单记录");
  7009. }
  7010. }
  7011. public void ins_erp_toresponsible()
  7012. {
  7013. if (UrlPostParmsCheck("ctid"))
  7014. {
  7015. string eid = GetPostString("ctid");
  7016. CeErpTradeCell entity = null;
  7017. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7018. if (entity != null)
  7019. {
  7020. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7021. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7022. {
  7023. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7024. return;
  7025. }
  7026. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7027. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7028. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7029. if (entity.AfterSalePreTime == null)
  7030. {
  7031. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7032. {
  7033. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7034. }
  7035. }
  7036. entity.AfterSalePreTime = DateTime.Now;
  7037. //预完成给售后主管审核客户问题直接完成
  7038. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7039. {
  7040. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7041. {
  7042. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7043. }
  7044. }
  7045. ceErpTradeAfterSaleExtend.Update();
  7046. entity.AfterSaleState = 2;
  7047. entity.UpdateTime = DateTime.Now;
  7048. entity.Update();
  7049. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7050. aftersale_data_change(entity.ctid);
  7051. returnSuccessMsg("操作成功!");
  7052. return;
  7053. }
  7054. returnErrorMsg("找不到订单记录");
  7055. }
  7056. }
  7057. public void cancel_erp_aftersaleanddelnew()
  7058. {
  7059. if (UrlPostParmsCheck("ctid"))
  7060. {
  7061. string eid = GetPostString("ctid");
  7062. CeErpTradeCell entity = null;
  7063. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7064. if (entity != null)
  7065. {
  7066. entity.AfterSaleState = 0;
  7067. entity.AfterSaleReason = "";
  7068. entity.AfterSaleMethod = "";
  7069. entity.AfterSaleMemo = "";
  7070. entity.AfterSaleResponsible = "";
  7071. entity.ResponsibleUserId = "";
  7072. entity.DeductFee = 0;
  7073. entity.RefundFee = 0;
  7074. entity.IsArbitrate = 0;
  7075. CeErpTradeResponsible.DelByTid(eid, -1);
  7076. entity.Update();
  7077. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7078. if (after != null)
  7079. {
  7080. if (after.OrderState < 5)
  7081. CeErpTradeCell.DelByCtid("S_" + eid);
  7082. }
  7083. returnSuccessMsg("操作成功!");
  7084. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7085. return;
  7086. }
  7087. returnErrorMsg("找不到订单记录");
  7088. }
  7089. }
  7090. public void get_erp_aftersale_pregather()
  7091. {
  7092. List<string> lw = new List<string>();
  7093. int st = GetInt("st");
  7094. string tid = GetPostString("ctid");
  7095. if (tid.Length > 0)
  7096. {
  7097. string select_tid = getTidByCtid(tid);
  7098. lw.Add(string.Format("tid='{0}'", select_tid));
  7099. }
  7100. string shopname = GetPostString("shopname");
  7101. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7102. string buyernick = GetPostString("buyer_nick");
  7103. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7104. string sellermemo = GetPostString("seller_memo");
  7105. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7106. string orderState = GetPostString("orderState");
  7107. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7108. string reason = GetPostString("reason");
  7109. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7110. string method = GetPostString("method");
  7111. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7112. string handler = GetPostString("handler");
  7113. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7114. string handledate1 = GetPostString("handledate1");
  7115. string handledate2 = GetPostString("handledate2");
  7116. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7117. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7118. string supplier = GetPostString("supplier");
  7119. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7120. string responsible = GetPostString("responsibleman");
  7121. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7122. string customer = GetPostString("customer");
  7123. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7124. string design = GetPostString("design");
  7125. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7126. string afterMemoType = GetPostString("aftermemotype");
  7127. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7128. string afterSaleMemo = GetPostString("afterSaleMemo");
  7129. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7130. string afterresult = GetPostString("afterresult");
  7131. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7132. string poscode = CurrentUser.UserPost.Post.Code;
  7133. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7134. {
  7135. string shopid = CurrentUser.User.pemShop;
  7136. lw.Add(string.Format("shopId in ({0})", shopid));
  7137. }
  7138. var mainwhere = string.Join(" and ", lw.ToArray());
  7139. string ro_json = "";
  7140. string type = GetPostString("gather_type");
  7141. int number = 0;
  7142. if (poscode == "AfterSale")
  7143. {
  7144. //处理中
  7145. if (type == "Handling")
  7146. {
  7147. 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) : ""));
  7148. DataTable dt = null;
  7149. try
  7150. {
  7151. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7152. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7153. }
  7154. catch (Exception e)
  7155. {
  7156. dt = new DataTable();
  7157. }
  7158. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7159. return;
  7160. }
  7161. if (type == "Wait")
  7162. {
  7163. //待处理
  7164. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7165. DataTable dt1 = null;
  7166. try
  7167. {
  7168. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7169. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7170. }
  7171. catch (Exception e)
  7172. {
  7173. dt1 = new DataTable();
  7174. }
  7175. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7176. return;
  7177. }
  7178. if (type == "back")
  7179. {
  7180. //打回
  7181. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7182. DataTable dt2 = null;
  7183. try
  7184. {
  7185. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7186. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7187. }
  7188. catch (Exception e)
  7189. {
  7190. dt2 = new DataTable();
  7191. }
  7192. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7193. return;
  7194. }
  7195. if (type == "preCompletion")
  7196. {
  7197. //预完成
  7198. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7199. DataTable dt3 = null;
  7200. try
  7201. {
  7202. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7203. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7204. }
  7205. catch (Exception e)
  7206. {
  7207. dt3 = new DataTable();
  7208. }
  7209. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7210. return;
  7211. }
  7212. if (type == "documentary")
  7213. {
  7214. //跟单中
  7215. 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) : ""));
  7216. DataTable dt4 = null;
  7217. try
  7218. {
  7219. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7220. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7221. }
  7222. catch (Exception e)
  7223. {
  7224. dt4 = new DataTable();
  7225. }
  7226. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7227. return;
  7228. }
  7229. if (type == "reBack")
  7230. {
  7231. //被打回
  7232. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7233. DataTable dt1 = null;
  7234. try
  7235. {
  7236. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7237. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7238. }
  7239. catch (Exception e)
  7240. {
  7241. dt1 = new DataTable();
  7242. }
  7243. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7244. return;
  7245. }
  7246. }
  7247. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7248. {
  7249. if (type == "puBack")
  7250. {
  7251. //退回
  7252. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7253. DataTable dt = null;
  7254. try
  7255. {
  7256. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7257. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7258. }
  7259. catch (Exception e)
  7260. {
  7261. dt = new DataTable();
  7262. }
  7263. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7264. return;
  7265. }
  7266. if (type == "reBack")
  7267. {
  7268. //打回
  7269. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7270. DataTable dt1 = null;
  7271. try
  7272. {
  7273. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7274. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7275. }
  7276. catch (Exception e)
  7277. {
  7278. dt1 = new DataTable();
  7279. }
  7280. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7281. return;
  7282. }
  7283. if (type == "examEd")
  7284. {
  7285. //已审核
  7286. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7287. DataTable dt2 = null;
  7288. try
  7289. {
  7290. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7291. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7292. }
  7293. catch (Exception e)
  7294. {
  7295. dt2 = new DataTable();
  7296. }
  7297. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7298. return;
  7299. }
  7300. if (type == "waitExam")
  7301. {
  7302. //待审核
  7303. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7304. DataTable dt3 = null;
  7305. try
  7306. {
  7307. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7308. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7309. }
  7310. catch (Exception e)
  7311. {
  7312. dt3 = new DataTable();
  7313. }
  7314. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7315. return;
  7316. }
  7317. if (type == "Handling")
  7318. {
  7319. //处理中
  7320. 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) : ""));
  7321. DataTable dt4 = null;
  7322. try
  7323. {
  7324. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7325. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7326. }
  7327. catch (Exception e)
  7328. {
  7329. dt4 = new DataTable();
  7330. }
  7331. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7332. return;
  7333. }
  7334. if (type == "Wait")
  7335. {
  7336. //待处理
  7337. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7338. DataTable dt5 = null;
  7339. try
  7340. {
  7341. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7342. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7343. }
  7344. catch (Exception e)
  7345. {
  7346. dt5 = new DataTable();
  7347. }
  7348. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7349. return;
  7350. }
  7351. if (type == "documentary")
  7352. {
  7353. //跟单中
  7354. 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) : ""));
  7355. DataTable dt6 = null;
  7356. try
  7357. {
  7358. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7359. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7360. }
  7361. catch (Exception e)
  7362. {
  7363. dt6 = new DataTable();
  7364. }
  7365. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7366. return;
  7367. }
  7368. }
  7369. returnSuccess(ro_json);
  7370. }
  7371. public void end_erp_aftersale()
  7372. {
  7373. if (UrlPostParmsCheck("ctid"))
  7374. {
  7375. string eid = GetPostString("ctid");
  7376. CeErpTradeCell entity = null;
  7377. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7378. if (entity != null)
  7379. {
  7380. string stype = GetPostString("stype");
  7381. string typeStr = stype;
  7382. entity.AfterSaleState = 4;
  7383. entity.FinishAfterSaleTime = DateTime.Now;
  7384. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7385. entity.Update();
  7386. ApiVo apiVo = new ApiVo();
  7387. apiVo.orderNumber = entity.ctid;
  7388. apiVo.actionName = "afterOver";
  7389. designHelper.API_WorkCore(apiVo); //afterOver
  7390. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7391. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7392. CeErpSukuraData.createInfo(entity.ctid, 8);
  7393. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7394. returnSuccessMsg("操作成功!");
  7395. return;
  7396. }
  7397. returnErrorMsg("找不到订单记录");
  7398. }
  7399. }
  7400. public void ins_erp_finishaftersale()
  7401. {
  7402. if (UrlPostParmsCheck("id"))
  7403. {
  7404. string eid = GetPostString("id");
  7405. CeErpTradeResponsible entity = null;
  7406. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7407. if (entity != null)
  7408. {
  7409. entity.VerifyState = 1;
  7410. entity.VerifyTime = DateTime.Now;
  7411. entity.Update();
  7412. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7413. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7414. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7415. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7416. if (dt.Rows.Count <= 0)
  7417. {
  7418. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7419. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7420. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7421. CeErpSukuraData.createInfo(entity.tid, 8);
  7422. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7423. {
  7424. CeErpDesignerBill.Del(entity.tid);
  7425. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7426. }
  7427. }
  7428. returnSuccessMsg("操作成功!");
  7429. return;
  7430. }
  7431. returnErrorMsg("找不到订单记录");
  7432. }
  7433. }
  7434. public void upd_erp_arbitrateaftersale()
  7435. {
  7436. if (UrlPostParmsCheck("id"))
  7437. {
  7438. string eid = GetPostString("id");
  7439. CeErpTradeResponsible entity = null;
  7440. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7441. if (entity != null)
  7442. {
  7443. entity.IsArbitrate = 1;
  7444. entity.ArbitradeMemo = GetPostString("reason");
  7445. entity.VerifyState = 2;
  7446. entity.Update();
  7447. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7448. if (tradecell != null)
  7449. {
  7450. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7451. tradecell.IsArbitrate = 1;
  7452. tradecell.Update();
  7453. }
  7454. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7455. returnSuccessMsg("操作成功!");
  7456. return;
  7457. }
  7458. returnErrorMsg("找不到订单记录");
  7459. }
  7460. }
  7461. public void upd_erp_backaftersale()
  7462. {
  7463. if (UrlPostParmsCheck("tid"))
  7464. {
  7465. string eid = GetPostString("tid");
  7466. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7467. int backNum = 0;
  7468. if (number != null)
  7469. {
  7470. backNum = number.BackNum;
  7471. }
  7472. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7473. CeErpTradeCell entity = null;
  7474. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7475. if (entity != null)
  7476. {
  7477. entity.AfterSaleBackReason = GetPostString("backreason");
  7478. entity.AfterSaleState = 1;
  7479. entity.AfterSaleSupplierState = 0;
  7480. entity.UpdateTime = DateTime.Now;
  7481. entity.Update();
  7482. returnSuccessMsg("操作成功!");
  7483. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7484. return;
  7485. }
  7486. returnErrorMsg("找不到订单记录");
  7487. }
  7488. }
  7489. public void get_erp_supplieraftersalelist()
  7490. {
  7491. DataStruct dStruct = GetPostStruct();
  7492. List<string> lw = new List<string>();
  7493. string tid = GetPostString("ctid");
  7494. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7495. string shopname = GetPostString("shopname");
  7496. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7497. string buyernick = GetPostString("buyer_nick");
  7498. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7499. string sellermemo = GetPostString("seller_memo");
  7500. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7501. string orderState = GetPostString("orderState");
  7502. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7503. string afterState = GetPostString("afterstate");
  7504. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7505. string date1 = GetPostString("date1");
  7506. string date2 = GetPostString("date2");
  7507. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7508. if (dw.Length > 0) lw.Add(dw);
  7509. string price1 = GetPostString("price1");
  7510. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7511. string price2 = GetPostString("price2");
  7512. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7513. string reason = GetPostString("reason");
  7514. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7515. string method = GetPostString("method");
  7516. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7517. string handledate1 = GetPostString("handledate1");
  7518. string handledate2 = GetPostString("handledate2");
  7519. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7520. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7521. string handler = GetPostString("handler");
  7522. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7523. string afterdate1 = GetPostString("afterdate1");
  7524. string afterdate2 = GetPostString("afterdate2");
  7525. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7526. if (afterDate.Length > 0) lw.Add(afterDate);
  7527. string customer = GetPostString("customer");
  7528. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7529. string design = GetPostString("design");
  7530. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7531. string afterMemoType = GetPostString("aftermemotype");
  7532. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7533. string vstate = GetPostString("vstate");
  7534. if (vstate.Length > 0)
  7535. {
  7536. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7537. }
  7538. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7539. string supplier = GetPostString("supplier");
  7540. int supid = commonHelper.getSupplierIDByName(supplier);
  7541. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7542. string posCode = CurrentUser.UserPost.Post.Code;
  7543. if (posCode == "Supplier")
  7544. {
  7545. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7546. }
  7547. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7548. {
  7549. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7550. }
  7551. else
  7552. {
  7553. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7554. }
  7555. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7556. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7557. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7558. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7559. writeGridDataTableJson(dStruct.TotalCount, dt);
  7560. }
  7561. public void upd_erp_supverifyaftersale()
  7562. {
  7563. if (UrlPostParmsCheck("id"))
  7564. {
  7565. string id = GetPostString("id");
  7566. int st = GetPostInt("afterstate");
  7567. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7568. CeErpTradeCell entity = null;
  7569. if (ceErpTradeResponsible != null)
  7570. {
  7571. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7572. }
  7573. string afmemo = GetPostString("supmemo");
  7574. string image = GetPostString("image");
  7575. if (entity != null)
  7576. {
  7577. entity.AfterSaleSupplierState = st;
  7578. entity.AfterSaleSupplierMemo = afmemo;
  7579. if (st == 1)
  7580. {
  7581. ceErpTradeResponsible.VerifyState = 1;
  7582. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7583. ceErpTradeResponsible.Update();
  7584. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7585. if (isAll)
  7586. {
  7587. entity.AfterSaleState = 4;
  7588. entity.FinishAfterSaleTime = DateTime.Now;
  7589. }
  7590. }
  7591. else
  7592. {
  7593. CeErpTradeResponsible.dateByTid(entity.ctid);
  7594. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7595. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7596. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7597. if (num <= 1)
  7598. {
  7599. entity.AfterSaleState = 1;
  7600. }
  7601. else
  7602. {
  7603. entity.AfterSaleState = 5;
  7604. }
  7605. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7606. if (ceErpTradeAfterSaleExtend != null)
  7607. {
  7608. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7609. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7610. ceErpTradeAfterSaleExtend.Update();
  7611. }
  7612. else
  7613. {
  7614. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7615. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7616. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7617. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7618. ceErpTradeAfterSaleExtend.Create();
  7619. }
  7620. }
  7621. if (entity.AfterSaleState == 4)
  7622. {
  7623. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7624. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7625. {
  7626. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7627. }
  7628. ApiVo apiVo = new ApiVo();
  7629. apiVo.orderNumber = entity.ctid;
  7630. apiVo.actionName = "afterOver";
  7631. designHelper.API_WorkCore(apiVo); //afterOver
  7632. }
  7633. entity.UpdateTime = DateTime.Now;
  7634. entity.Update();
  7635. returnSuccessMsg("操作成功!");
  7636. CeErpSukuraData.createInfo(entity.ctid, 8);
  7637. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7638. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7639. return;
  7640. }
  7641. returnErrorMsg("找不到订单记录");
  7642. }
  7643. }
  7644. public void upd_erp_masteraftersale()
  7645. {
  7646. if (UrlPostParmsCheck("id"))
  7647. {
  7648. string id = GetPostString("id");
  7649. int st = GetPostInt("afterstate");
  7650. string afmemo = GetPostString("supmemo");
  7651. string image = GetPostString("image");
  7652. string textResult = GetPostString("textResult");
  7653. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7654. if (ceErpTradeResponsible != null)
  7655. {
  7656. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7657. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7658. ceErpTradeResponsible.Update();
  7659. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7660. if (entity != null)
  7661. {
  7662. entity.AfterSaleSupplierState = st;
  7663. entity.AfterSaleSupplierMemo = afmemo;
  7664. if (st == 1)
  7665. {
  7666. }
  7667. else
  7668. {
  7669. CeErpTradeResponsible.dateByTid(entity.ctid);
  7670. //退回到售后
  7671. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7672. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7673. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7674. if (num <= 1)
  7675. {
  7676. entity.AfterSaleState = 1;
  7677. }
  7678. else
  7679. {
  7680. entity.AfterSaleState = 5;
  7681. }
  7682. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7683. if (ceErpTradeAfterSaleExtend != null)
  7684. {
  7685. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7686. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7687. ceErpTradeAfterSaleExtend.Update();
  7688. }
  7689. else
  7690. {
  7691. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7692. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7693. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7694. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7695. ceErpTradeAfterSaleExtend.Create();
  7696. }
  7697. }
  7698. entity.UpdateTime = DateTime.Now;
  7699. entity.Update();
  7700. returnSuccessMsg("操作成功!");
  7701. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7702. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7703. return;
  7704. }
  7705. }
  7706. returnErrorMsg("找不到订单记录");
  7707. }
  7708. }
  7709. public void upd_erp_personaftersale()
  7710. {
  7711. if (UrlPostParmsCheck("id"))
  7712. {
  7713. //林小连
  7714. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7715. {
  7716. upd_erp_masteraftersale();
  7717. return;
  7718. }
  7719. string id = GetPostString("id");
  7720. int st = GetPostInt("afterstate");
  7721. string afmemo = GetPostString("supmemo");
  7722. string image = GetPostString("image");
  7723. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7724. if (ceErpTradeResponsible != null)
  7725. {
  7726. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7727. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7728. ceErpTradeResponsible.Update();
  7729. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7730. if (entity != null)
  7731. {
  7732. entity.AfterSaleSupplierMemo = afmemo;
  7733. entity.AfterSaleSupplierState = st;
  7734. if (st == 1)
  7735. {
  7736. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7737. if (isAll)
  7738. {
  7739. entity.AfterSaleState = 4;
  7740. entity.FinishAfterSaleTime = DateTime.Now;
  7741. }
  7742. }
  7743. else
  7744. {
  7745. CeErpTradeResponsible.dateByTid(entity.ctid);
  7746. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7747. if (ceErpTradeAfterSaleExtend != null)
  7748. {
  7749. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7750. ceErpTradeAfterSaleExtend.Update();
  7751. }
  7752. else
  7753. {
  7754. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7755. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7756. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7757. ceErpTradeAfterSaleExtend.Create();
  7758. }
  7759. //退回到主管
  7760. //entity.AfterSaleState = 2;
  7761. }
  7762. if (entity.AfterSaleState == 4)
  7763. {
  7764. ApiVo apiVo = new ApiVo();
  7765. apiVo.orderNumber = entity.ctid;
  7766. apiVo.actionName = "afterOver";
  7767. designHelper.API_WorkCore(apiVo); //afterOver
  7768. }
  7769. entity.UpdateTime = DateTime.Now;
  7770. entity.Update();
  7771. returnSuccessMsg("操作成功!");
  7772. CeErpSukuraData.createInfo(entity.ctid, 8);
  7773. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7774. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7775. return;
  7776. }
  7777. }
  7778. returnErrorMsg("找不到订单记录");
  7779. }
  7780. }
  7781. public void set_erp_supplierrefundtag()
  7782. {
  7783. if (UrlPostParmsCheck("ctid"))
  7784. {
  7785. string eid = GetPostString("ctid");
  7786. CeErpTradeCell entity = null;
  7787. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7788. if (entity != null)
  7789. {
  7790. entity.IsSupplierRefund = GetPostInt("tag");
  7791. entity.Update();
  7792. returnSuccessMsg("操作成功!");
  7793. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7794. return;
  7795. }
  7796. returnErrorMsg("找不到订单记录");
  7797. }
  7798. }
  7799. public void get_erp_refundlist()
  7800. {
  7801. DataStruct dStruct = GetPostStruct();
  7802. List<string> lw = new List<string>();
  7803. string tid = GetPostString("tid");
  7804. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7805. //string rid = GetPostString("refund_id");
  7806. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7807. string shopname = GetPostString("shopname");
  7808. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7809. string buyernick = GetPostString("buyer_nick");
  7810. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7811. string customer = GetPostString("customer");
  7812. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7813. string design = GetPostString("design");
  7814. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7815. string sellermemo = GetPostString("seller_memo");
  7816. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7817. //string date1 = GetPostString("date1");
  7818. //string date2 = GetPostString("date2");
  7819. //string dateType = GetPostString("dateType");
  7820. //if (dateType.Length > 0)
  7821. //{
  7822. // if (dateType == "1001") dateType = "0";
  7823. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7824. // if (searchDT.Count == 2)
  7825. // {
  7826. // date1 = searchDT[0].ToString();
  7827. // date2 = searchDT[1].ToString();
  7828. // }
  7829. //}
  7830. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7831. //if (dw.Length > 0) lw.Add(dw);
  7832. string redate1 = GetPostString("refunddate1");
  7833. string redate2 = GetPostString("refunddate2");
  7834. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7835. if (dwdate.Length > 0) lw.Add(dwdate);
  7836. string price1 = GetPostString("price1");
  7837. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7838. string price2 = GetPostString("price2");
  7839. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7840. string ispartrefund = GetPostString("ispartrefund");
  7841. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7842. string refundState = GetPostString("refundvstate");
  7843. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7844. int st = GetInt("st");
  7845. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7846. {
  7847. string responsible = GetPostString("responsibleman");
  7848. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7849. lw.Add(string.Format("RefundState>={0}", st));
  7850. string code = CurrentUser.UserPost.Post.Code;
  7851. if (code == "CustomerService")
  7852. {
  7853. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7854. }
  7855. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7856. {
  7857. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7858. }
  7859. else if (code == "Place" || code == "PlaceMr")
  7860. {
  7861. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7862. }
  7863. dStruct.Order = "RefundState asc,created desc";
  7864. }
  7865. else if (st == 10)
  7866. {
  7867. string responsible = GetPostString("responsibleman");
  7868. if (responsible == "空白")
  7869. {
  7870. lw.Add(string.Format("ResponsibleUserName = ''"));
  7871. }
  7872. else if (responsible.Length > 0)
  7873. {
  7874. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7875. }
  7876. lw.Add(string.Format("RefundState>=0"));
  7877. dStruct.Order = "created desc";
  7878. }
  7879. else
  7880. {
  7881. string responsible = GetPostString("responsibleman");
  7882. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7883. lw.Add(string.Format("RefundState={0}", st));
  7884. dStruct.Order = "created desc";
  7885. }
  7886. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7887. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7888. dt.Columns.Add("refund_fees");
  7889. foreach (DataRow dr in dt.Rows)
  7890. {
  7891. String status = dr["status"].ToString();
  7892. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7893. {
  7894. dr["refund_fees"] = dr["refund_fee"];
  7895. }
  7896. else
  7897. {
  7898. dr["refund_fees"] = "0.0";
  7899. }
  7900. }
  7901. writeGridDataTableJson(dStruct.TotalCount, dt);
  7902. }
  7903. public void get_erp_refunddesignlist()
  7904. {
  7905. DataStruct dStruct = GetPostStruct();
  7906. List<string> lw = new List<string>();
  7907. string tid = GetPostString("tid");
  7908. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7909. string shopname = GetPostString("shopname");
  7910. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7911. string buyernick = GetPostString("buyer_nick");
  7912. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7913. string customer = GetPostString("customer");
  7914. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7915. string design = GetPostString("design");
  7916. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7917. string sellermemo = GetPostString("seller_memo");
  7918. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7919. string redate1 = GetPostString("refunddate1");
  7920. string redate2 = GetPostString("refunddate2");
  7921. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7922. if (dwdate.Length > 0) lw.Add(dwdate);
  7923. string price1 = GetPostString("price1");
  7924. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7925. string price2 = GetPostString("price2");
  7926. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7927. string ispartrefund = GetPostString("ispartrefund");
  7928. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7929. string designerorg = GetPostString("designerorg");
  7930. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7931. string refundState = GetPostString("refundState");
  7932. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7933. int myOrgid = CurrentUser.UserPost.OrgID;
  7934. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7935. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7936. {
  7937. if (CurrentUser.User.TeamIds.Length > 0)
  7938. {
  7939. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7940. }
  7941. else
  7942. {
  7943. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7944. }
  7945. }
  7946. else if ("SysAdmin".Equals(myOrgCode))
  7947. {
  7948. }
  7949. else
  7950. {
  7951. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7952. {
  7953. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7954. }
  7955. else
  7956. {
  7957. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7958. }
  7959. }
  7960. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7961. dStruct.Order = "created desc";
  7962. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7963. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7964. dt.Columns.Add("refund_fees");
  7965. foreach (DataRow dr in dt.Rows)
  7966. {
  7967. String status = dr["status"].ToString();
  7968. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7969. {
  7970. dr["refund_fees"] = dr["refund_fee"];
  7971. }
  7972. else
  7973. {
  7974. dr["refund_fees"] = "0.0";
  7975. }
  7976. }
  7977. writeGridDataTableJson(dStruct.TotalCount, dt);
  7978. }
  7979. public void handle_erp_refundtag()
  7980. {
  7981. if (UrlPostParmsCheck("refund_id"))
  7982. {
  7983. string eid = GetPostString("refund_id");
  7984. string respMan = GetPostString("ResponsibleName");
  7985. if (respMan.Length <= 0)
  7986. {
  7987. returnErrorMsg("责任人不能为空");
  7988. return;
  7989. }
  7990. CeErpTradeRefund entity = null;
  7991. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7992. if (entity != null)
  7993. {
  7994. entity.ResponsibleUserName = respMan;
  7995. string userid = GetPostString("ResponsibleUserId");
  7996. if (userid.Length > 0)
  7997. {
  7998. entity.ResponsibleUserId = userid;
  7999. }
  8000. entity.Memo = GetPostString("Memo");
  8001. if (respMan.IndexOf("客服") != -1 ||
  8002. respMan.IndexOf("设计师") != -1 ||
  8003. respMan.IndexOf("下单员") != -1)
  8004. {
  8005. entity.RefundState = 2;
  8006. }
  8007. else
  8008. {
  8009. entity.RefundState = 3;
  8010. }
  8011. entity.modified = DateTime.Now;
  8012. entity.Update();
  8013. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8014. returnSuccessMsg("操作成功!");
  8015. return;
  8016. }
  8017. returnErrorMsg("找不到订单记录");
  8018. }
  8019. }
  8020. public void handle_erp_designrefundtag()
  8021. {
  8022. if (UrlPostParmsCheck("refund_id"))
  8023. {
  8024. string eid = GetPostString("refund_id");
  8025. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8026. if (ceErpTradeCellExtend == null)
  8027. {
  8028. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8029. ceErpTradeCellExtend.ctid = eid;
  8030. }
  8031. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8032. if (ceErpTradeCellExtend.ID > 0)
  8033. {
  8034. ceErpTradeCellExtend.Update();
  8035. }
  8036. else
  8037. {
  8038. ceErpTradeCellExtend.Create();
  8039. }
  8040. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8041. returnSuccessMsg("操作成功!");
  8042. return;
  8043. }
  8044. returnErrorMsg("找不到订单记录");
  8045. }
  8046. public void upd_erp_refundverify()
  8047. {
  8048. if (UrlPostParmsCheck("refund_id"))
  8049. {
  8050. string eid = GetPostString("refund_id");
  8051. CeErpTradeRefund entity = null;
  8052. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8053. if (entity != null)
  8054. {
  8055. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8056. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8057. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8058. {
  8059. entity.RefundState = 2;
  8060. }
  8061. else
  8062. {
  8063. entity.RefundState = 3;
  8064. }
  8065. entity.Update();
  8066. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8067. returnSuccessMsg("操作成功!");
  8068. return;
  8069. }
  8070. returnErrorMsg("找不到订单记录");
  8071. }
  8072. }
  8073. public void upd_erp_refundapprove()
  8074. {
  8075. if (UrlPostParmsCheck("refund_id"))
  8076. {
  8077. string eid = GetPostString("refund_id");
  8078. CeErpTradeRefund entity = null;
  8079. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8080. if (entity != null)
  8081. {
  8082. int apr = GetPostInt("approve");
  8083. if (apr == 0)
  8084. {
  8085. entity.RefundState = 1;
  8086. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8087. }
  8088. else if (apr == 1)
  8089. {
  8090. entity.RefundState = 3;
  8091. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8092. }
  8093. entity.modified = DateTime.Now;
  8094. entity.Update();
  8095. returnSuccessMsg("操作成功!");
  8096. return;
  8097. }
  8098. returnErrorMsg("找不到订单记录");
  8099. }
  8100. }
  8101. public void get_erp_billlist()
  8102. {
  8103. DataStruct dStruct = GetPostStruct();
  8104. List<string> lw = new List<string>();
  8105. string title = GetPostString("title");
  8106. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8107. string tid = GetPostString("tid");
  8108. string tids = GetPostString("tids");
  8109. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8110. if (tids.Length > 0)
  8111. {
  8112. tids = "'" + tids + "'";
  8113. tids = tids.Replace(",", "','");
  8114. lw.Add(string.Format("tid in ({0})", tids));
  8115. }
  8116. string shopname = GetPostString("shopname");
  8117. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8118. string buyernick = GetPostString("buyer_nick");
  8119. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8120. string customer = GetPostString("customer");
  8121. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8122. string date1 = GetPostString("date1");
  8123. string date2 = GetPostString("date2");
  8124. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8125. if (dw.Length > 0) lw.Add(dw);
  8126. string price1 = GetPostString("price1");
  8127. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8128. string price2 = GetPostString("price2");
  8129. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8130. string returndate1 = GetPostString("returndate1");
  8131. string returndate2 = GetPostString("returndate2");
  8132. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8133. if (dw1.Length > 0) lw.Add(dw1);
  8134. string billtype = GetPostString("billtype");
  8135. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8136. string billstate = GetPostString("billstate");
  8137. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8138. string usershop = CurrentUser.User.pemShop;
  8139. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8140. dStruct.Order = "createTime desc";
  8141. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8142. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8143. //foreach (DataRow dr in dt.Rows)
  8144. //{
  8145. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8146. //}
  8147. writeGridDataTableJson(dStruct.TotalCount, dt);
  8148. }
  8149. public void modify_erp_billinfo()
  8150. {
  8151. if (UrlPostParmsCheck("ID"))
  8152. {
  8153. string eid = GetPostString("ID");
  8154. CeErpBill bill_entity = null;
  8155. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8156. if (bill_entity != null)
  8157. {
  8158. bill_entity.tid = GetPostString("tid");
  8159. bill_entity.title = GetPostString("title");
  8160. bill_entity.tax = GetPostString("tax");
  8161. bill_entity.bank = GetPostString("bank");
  8162. bill_entity.bankac = GetPostString("bankac");
  8163. bill_entity.address = GetPostString("address");
  8164. bill_entity.phone = GetPostString("phone");
  8165. bill_entity.price = GetPostString("price");
  8166. bill_entity.productId = GetPostInt("ProductName");
  8167. bill_entity.num = GetPostInt("num");
  8168. bill_entity.unit = GetPostString("unit");
  8169. bill_entity.type = GetPostString("type");
  8170. bill_entity.sendType = GetPostString("SendType");
  8171. bill_entity.email = GetPostString("email");
  8172. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8173. bill_entity.shopName = GetPostString("ShopName");
  8174. bill_entity.applymemo = GetPostString("applymemo");
  8175. bill_entity.modifyTime = DateTime.Now;
  8176. bill_entity.createTime = DateTime.Now;
  8177. bill_entity.state = 0;
  8178. bill_entity.Update();
  8179. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8180. returnSuccessMsg("发票修改成功!");
  8181. return;
  8182. }
  8183. returnErrorMsg("找不到对应记录");
  8184. }
  8185. }
  8186. public void set_erp_invoicing()
  8187. {
  8188. if (UrlPostParmsCheck("id"))
  8189. {
  8190. try
  8191. {
  8192. string eid = GetPostString("id");
  8193. CeErpBill bill_entity = null;
  8194. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8195. if (bill_entity != null)
  8196. {
  8197. int ComId = GetPostInt("ComId");
  8198. //string memo = GetPostString("Memo");
  8199. int allInfo = GetPostInt("allinfo");
  8200. string clert = CurrentUser.User.Name;
  8201. //string detailValue = GetPostString("detailvalue");
  8202. string billId = bill_entity.billOrderId;
  8203. string[] billIdList = billId.Split(',');
  8204. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8205. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8206. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8207. {
  8208. billCount += 1;
  8209. }
  8210. if (billId.Length <= 0 || billIdList.Length != billCount)
  8211. {
  8212. bill_entity.billOrderId = "";
  8213. string prebill = "ltb";
  8214. for (int idx = 1; idx <= billCount; idx++)
  8215. {
  8216. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8217. string billoid = prebill + idx + dtstr;
  8218. bill_entity.billOrderId += billoid;
  8219. if (idx < billCount)
  8220. {
  8221. bill_entity.billOrderId += ",";
  8222. }
  8223. }
  8224. }
  8225. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8226. if (bill_entity.state == 5)
  8227. {
  8228. string errMsg = bill_entity.failerror;
  8229. string[] errlist = errMsg.Split('|');
  8230. string[] errTags = new string[errlist.Length];
  8231. for (int itag = 0; itag < errlist.Length; itag++)
  8232. {
  8233. if (errlist[itag].Length <= 0) continue;
  8234. errTags[itag] = errlist[itag].Split('&')[0];
  8235. }
  8236. for (int iii = 0; iii < errTags.Length; iii++)
  8237. {
  8238. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8239. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8240. if (billOrderList.Length >= erroBillOrderTag)
  8241. {
  8242. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8243. if (needModifyBillId.Length <= 19)
  8244. {
  8245. needModifyBillId = needModifyBillId + "1";
  8246. }
  8247. else
  8248. {
  8249. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8250. last = last + 1;
  8251. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8252. }
  8253. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8254. }
  8255. }
  8256. }
  8257. bool isHaveBillSucces = false;
  8258. string totalRes = "";
  8259. bill_entity.failerror = "";
  8260. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8261. {
  8262. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8263. totalRes += res;
  8264. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8265. {
  8266. isHaveBillSucces = true;
  8267. bill_entity.comId = ComId;
  8268. bill_entity.state = 1;
  8269. bill_entity.executeTime = DateTime.Now;
  8270. bill_entity.executeUser = clert;
  8271. }
  8272. else
  8273. {
  8274. bill_entity.state = 5;
  8275. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8276. }
  8277. }
  8278. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8279. bill_entity.Update();
  8280. if (isHaveBillSucces)
  8281. {
  8282. StringBuilder sql = new StringBuilder();
  8283. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8284. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8285. }
  8286. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8287. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8288. {
  8289. returnErrorMsg("开票失败");
  8290. }
  8291. else
  8292. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8293. return;
  8294. }
  8295. returnErrorMsg("找不到对应记录");
  8296. }
  8297. catch (Exception ex)
  8298. {
  8299. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8300. returnErrorMsg("操作失败");
  8301. }
  8302. }
  8303. }
  8304. public void get_erp_invoicing_back()
  8305. {
  8306. if (UrlPostParmsCheck("id"))
  8307. {
  8308. try
  8309. {
  8310. string id = GetPostString("id");
  8311. CeErpBill entiy = CeErpBill.Get(id);
  8312. if (entiy != null)
  8313. {
  8314. if (entiy.state == 0)
  8315. {
  8316. returnErrorMsg("发票还未开具");
  8317. return;
  8318. }
  8319. string[] billOrderList = entiy.billOrderId.Split(',');
  8320. int iTag = 0;
  8321. entiy.fplsh = "";
  8322. entiy.fpdm = "";
  8323. entiy.fphm = "";
  8324. foreach (string billOrderId in billOrderList)
  8325. {
  8326. iTag++;
  8327. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8328. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8329. {
  8330. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8331. try
  8332. {
  8333. Invoicing_get_response_Obj iObj = null;
  8334. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8335. if (iObj != null)
  8336. {
  8337. entiy.state = 2;
  8338. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8339. entiy.fpdm += iObj.list[0].c_fpdm;
  8340. entiy.fphm += iObj.list[0].c_fphm;
  8341. if (iTag < billOrderList.Length)
  8342. {
  8343. entiy.fplsh += ",";
  8344. entiy.fpdm += ",";
  8345. entiy.fphm += ",";
  8346. }
  8347. entiy.Update();
  8348. }
  8349. StringBuilder sql = new StringBuilder();
  8350. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8351. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8352. returnSuccessMsg("开票成功");
  8353. }
  8354. catch (Exception ex)
  8355. {
  8356. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8357. }
  8358. return;
  8359. }
  8360. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8361. {
  8362. var res_obj = new
  8363. {
  8364. data = "开票中"
  8365. };
  8366. string ro_json = JsonConvert.SerializeObject(res_obj);
  8367. returnSuccess(ro_json);
  8368. return;
  8369. }
  8370. else
  8371. {
  8372. int eidx = res.IndexOf("c_resultmsg");
  8373. int lidx = res.IndexOf("c_status");
  8374. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8375. entiy.state = 5;
  8376. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8377. entiy.Update();
  8378. returnErrorMsg("开票失败");
  8379. return;
  8380. }
  8381. }
  8382. }
  8383. }
  8384. catch (Exception ex)
  8385. {
  8386. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8387. }
  8388. return;
  8389. }
  8390. }
  8391. public void get_erp_invoicing()
  8392. {
  8393. if (UrlPostParmsCheck("id"))
  8394. {
  8395. try
  8396. {
  8397. string id = GetPostString("id");
  8398. CeErpBill entiy = CeErpBill.Get(id);
  8399. if (entiy != null)
  8400. {
  8401. if (entiy.state == 0)
  8402. {
  8403. returnErrorMsg("发票还未开具");
  8404. return;
  8405. }
  8406. if (entiy.sendType == "纸质发票")
  8407. {
  8408. if (entiy.img.Length <= 0)
  8409. {
  8410. returnErrorMsg("查无纸质发票");
  8411. return;
  8412. }
  8413. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8414. returnSuccess(returnres);
  8415. return;
  8416. }
  8417. string[] billOrderList = entiy.billOrderId.Split(',');
  8418. int iTag = 0;
  8419. string fpUrl = "";
  8420. entiy.fplsh = "";
  8421. entiy.fpdm = "";
  8422. entiy.fphm = "";
  8423. foreach (string billOrderId in billOrderList)
  8424. {
  8425. iTag++;
  8426. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8427. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8428. {
  8429. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8430. Invoicing_get_response_Obj iObj = null;
  8431. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8432. if (iObj != null)
  8433. {
  8434. //entiy.state = 2;
  8435. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8436. entiy.fpdm += iObj.list[0].c_fpdm;
  8437. entiy.fphm += iObj.list[0].c_fphm;
  8438. if (iTag < billOrderList.Length)
  8439. {
  8440. entiy.fplsh += ",";
  8441. entiy.fpdm += ",";
  8442. entiy.fphm += ",";
  8443. }
  8444. entiy.Update();
  8445. fpUrl += iObj.list[0].c_url + ",";
  8446. }
  8447. //returnSuccess(res);
  8448. StringBuilder sql = new StringBuilder();
  8449. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8450. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8451. }
  8452. else
  8453. {
  8454. int eidx = res.IndexOf("c_resultmsg");
  8455. //int lidx = res.IndexOf("c_status");
  8456. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8457. //开票失败
  8458. entiy.state = 5;
  8459. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8460. entiy.Update();
  8461. returnErrorMsg("开票失败");
  8462. return;
  8463. }
  8464. }
  8465. var returnObj = new
  8466. {
  8467. data = fpUrl
  8468. };
  8469. string ro_json = JsonConvert.SerializeObject(returnObj);
  8470. returnSuccess(ro_json);
  8471. }
  8472. }
  8473. catch (Exception ex)
  8474. {
  8475. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8476. }
  8477. return;
  8478. }
  8479. }
  8480. public void save_erp_billimg()
  8481. {
  8482. if (UrlPostParmsCheck("id"))
  8483. {
  8484. string eid = GetPostString("id");
  8485. CeErpBill bill_entity = null;
  8486. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8487. if (bill_entity != null)
  8488. {
  8489. bill_entity.img = GetPostString("img");
  8490. bill_entity.executeTime = DateTime.Now;
  8491. bill_entity.state = 2;
  8492. bill_entity.Update();
  8493. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8494. returnSuccessMsg("保存成功");
  8495. }
  8496. return;
  8497. }
  8498. }
  8499. public void upd_erp_billreturnback()
  8500. {
  8501. if (UrlPostParmsCheck("id"))
  8502. {
  8503. int eid = GetPostInt("id");
  8504. CeErpBill bill_entity = null;
  8505. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8506. if (bill_entity != null)
  8507. {
  8508. bill_entity.state = 3;
  8509. bill_entity.returnReason = GetPostString("reason");
  8510. bill_entity.Update();
  8511. returnSuccessMsg("驳回成功!");
  8512. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8513. }
  8514. return;
  8515. }
  8516. }
  8517. public void cancel_erp_bill()
  8518. {
  8519. if (UrlPostParmsCheck("id"))
  8520. {
  8521. int eid = GetPostInt("id");
  8522. int detailValue = GetPostInt("detailvalue");
  8523. CeErpBill bill_entity = null;
  8524. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8525. string cres = "";
  8526. string gres = "";
  8527. if (bill_entity != null)
  8528. {
  8529. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8530. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8531. {
  8532. int iTag = 0;
  8533. bill_entity.fplsh = "";
  8534. bill_entity.fpdm = "";
  8535. bill_entity.fphm = "";
  8536. foreach (string billOrderId in billOrderList)
  8537. {
  8538. iTag++;
  8539. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8540. if (gres.IndexOf("success") != -1)
  8541. {
  8542. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8543. Invoicing_get_response_Obj iObj = null;
  8544. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8545. if (iObj != null)
  8546. {
  8547. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8548. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8549. bill_entity.fphm += iObj.list[0].c_fphm;
  8550. if (iTag < billOrderList.Length)
  8551. {
  8552. bill_entity.fplsh += ",";
  8553. bill_entity.fpdm += ",";
  8554. bill_entity.fphm += ",";
  8555. }
  8556. bill_entity.Update();
  8557. }
  8558. }
  8559. else
  8560. {
  8561. returnErrorMsg(gres);
  8562. return;
  8563. }
  8564. }
  8565. }
  8566. if (bill_entity.sendType == "纸质发票")
  8567. {
  8568. //作废
  8569. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8570. //if (DateTime.Now.Month == extime.Month)
  8571. //{
  8572. //cres = taobaoHelper.cancel_invoicing(eid);
  8573. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8574. //{
  8575. bill_entity.state = 4;//已作废
  8576. bill_entity.Update();
  8577. returnSuccessMsg("发票已作废");
  8578. return;
  8579. //}
  8580. //else
  8581. //{
  8582. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8583. // bill_entity.Update();
  8584. // returnErrorMsg(cres);
  8585. // return;
  8586. //}
  8587. //}
  8588. //else
  8589. //{
  8590. // returnErrorMsg("纸质发票只能作废本月的发票");
  8591. // return;
  8592. //}
  8593. }
  8594. //红冲
  8595. int redTag = 0;
  8596. string[] fpdmList = bill_entity.fpdm.Split(',');
  8597. string[] fphmList = bill_entity.fphm.Split(',');
  8598. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8599. {
  8600. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8601. return;
  8602. }
  8603. foreach (string billOrderId in billOrderList)
  8604. {
  8605. redTag++;
  8606. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8607. cres += onecres;
  8608. cres += ",";
  8609. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8610. {
  8611. bill_entity.state = 4;//已作废
  8612. //bill_entity.Update();
  8613. //returnSuccessMsg("发票已红冲");
  8614. }
  8615. else if (onecres.IndexOf("重复冲红") != -1)
  8616. {
  8617. bill_entity.state = 4;//已作废
  8618. //bill_entity.Update();
  8619. //returnSuccessMsg("发票已红冲");
  8620. }
  8621. else
  8622. {
  8623. string errmsg = commonHelper.KeepChinese(onecres);
  8624. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8625. }
  8626. }
  8627. bill_entity.Update();
  8628. if (cres.IndexOf("失败") != -1)
  8629. returnErrorMsg("红冲失败");
  8630. else
  8631. returnSuccessMsg("发票已红冲");
  8632. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8633. return;
  8634. }
  8635. return;
  8636. }
  8637. }
  8638. public void del_erp_billorder()
  8639. {
  8640. if (UrlPostParmsCheck("id"))
  8641. {
  8642. string eid = GetPostString("id");
  8643. CeErpBill.Del(eid);
  8644. CeErpBill bill = CeErpBill.Get(eid);
  8645. if (bill != null)
  8646. {
  8647. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8648. }
  8649. returnSuccessMsg("删除成功");
  8650. }
  8651. }
  8652. public void finish_erp_bill()
  8653. {
  8654. if (UrlPostParmsCheck("ids"))
  8655. {
  8656. string eids = GetPostString("ids");
  8657. string[] list = eids.Split(',');
  8658. foreach (string eid in list)
  8659. {
  8660. CeErpBill bill = CeErpBill.Get(eid);
  8661. if (bill != null)
  8662. {
  8663. bill.state = 2;
  8664. bill.Update();
  8665. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8666. }
  8667. }
  8668. returnSuccessMsg("操作成功");
  8669. }
  8670. }
  8671. public void get_erp_returncash()
  8672. {
  8673. DataStruct dStruct = GetPostStruct();
  8674. List<string> lw = new List<string>();
  8675. string tid = GetPostString("tid");
  8676. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8677. string shopname = GetPostString("shopname");
  8678. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8679. string buyernick = GetPostString("buyer_nick");
  8680. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8681. string customer = GetPostString("customer");
  8682. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8683. string returndate1 = GetPostString("returndate1");
  8684. string returndate2 = GetPostString("returndate2");
  8685. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8686. if (dw.Length > 0) lw.Add(dw);
  8687. string finishDate1 = GetPostString("finishdate1");
  8688. string finishDate2 = GetPostString("finishdate2");
  8689. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8690. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8691. string returntype = GetPostString("returntype");
  8692. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8693. string returnvstate = GetPostString("returnvstate");
  8694. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8695. dStruct.Order = "created desc";
  8696. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8697. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8698. writeGridDataTableJson(dStruct.TotalCount, dt);
  8699. }
  8700. public void get_erp_staygoods()
  8701. {
  8702. DataStruct dStruct = GetPostStruct();
  8703. List<string> lw = new List<string>();
  8704. string tid = GetPostString("tid");
  8705. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8706. string shopname = GetPostString("shopname");
  8707. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8708. string wangwang = GetPostString("wangwang");
  8709. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8710. string customer = GetPostString("customer");
  8711. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8712. string returndate1 = GetPostString("returndate1");
  8713. string returndate2 = GetPostString("returndate2");
  8714. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8715. if (dw.Length > 0) lw.Add(dw);
  8716. string finishDate1 = GetPostString("finishdate1");
  8717. string finishDate2 = GetPostString("finishdate2");
  8718. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8719. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8720. string returnvstate = GetPostString("returnvstate");
  8721. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8722. string persuadetype = GetPostString("persuadetype");
  8723. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8724. string customerOrg = GetPostString("customerOrg");
  8725. if (customerOrg.Length > 0)
  8726. {
  8727. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8728. }
  8729. dStruct.Order = "creata_time desc";
  8730. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8731. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8732. writeGridDataTableJson(dStruct.TotalCount, dt);
  8733. }
  8734. public void upd_erp_staygoods()
  8735. {
  8736. if (UrlPostParmsCheck("id"))
  8737. {
  8738. int eid = GetPostInt("id");
  8739. CeErpStayGoods entity = null;
  8740. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8741. if (entity != null)
  8742. {
  8743. entity.audit_type = 1;
  8744. entity.audit_time = DateTime.Now;
  8745. entity.audit_u_id = CurrentUser.UserID;
  8746. entity.audit_u_name = CurrentUser.UserName;
  8747. entity.Update();
  8748. returnSuccessMsg("审核成功!");
  8749. return;
  8750. }
  8751. returnErrorMsg("找不到订单记录");
  8752. }
  8753. }
  8754. public void upd_erp_stayGoodsback()
  8755. {
  8756. if (UrlPostParmsCheck("id"))
  8757. {
  8758. int eid = GetPostInt("id");
  8759. CeErpStayGoods entity = null;
  8760. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8761. if (entity != null)
  8762. {
  8763. entity.audit_text = GetPostString("reason");
  8764. entity.audit_type = 2;
  8765. entity.audit_time = DateTime.Now;
  8766. entity.audit_u_id = CurrentUser.UserID;
  8767. entity.audit_u_name = CurrentUser.UserName;
  8768. entity.Update();
  8769. returnSuccessMsg("退回成功!");
  8770. return;
  8771. }
  8772. returnErrorMsg("找不到订单记录");
  8773. }
  8774. }
  8775. public void upd_erp_returncashverify()
  8776. {
  8777. if (UrlPostParmsCheck("ID"))
  8778. {
  8779. int eid = GetPostInt("ID");
  8780. CeErpReturnCash entity = null;
  8781. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8782. if (entity != null)
  8783. {
  8784. entity.cashstate = 1;
  8785. entity.verifytime = DateTime.Now;
  8786. entity.verifyuserid = CurrentUser.UserID;
  8787. entity.Update();
  8788. returnSuccessMsg("审核成功!");
  8789. return;
  8790. }
  8791. returnErrorMsg("找不到订单记录");
  8792. }
  8793. }
  8794. public void upd_all_erp_returncashverify()
  8795. {
  8796. if (UrlPostParmsCheck("ID"))
  8797. {
  8798. String[] list = GetPostString("ID").Split(',');
  8799. CeErpReturnCash entity = null;
  8800. for (int i = 0; i < list.Length; i++)
  8801. {
  8802. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8803. if (entity != null)
  8804. {
  8805. if (entity.cashstate == 1)
  8806. {
  8807. returnErrorMsg("已审核过的订单不需要在审核!");
  8808. return;
  8809. }
  8810. entity.cashstate = 1;
  8811. entity.verifytime = DateTime.Now;
  8812. entity.verifyuserid = CurrentUser.UserID;
  8813. entity.Update();
  8814. }
  8815. }
  8816. returnSuccessMsg("审核成功!");
  8817. return;
  8818. }
  8819. }
  8820. public void upd_erp_returncashback()
  8821. {
  8822. if (UrlPostParmsCheck("ID"))
  8823. {
  8824. int eid = GetPostInt("ID");
  8825. CeErpReturnCash entity = null;
  8826. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8827. if (entity != null)
  8828. {
  8829. entity.backreason = GetPostString("reason");
  8830. entity.cashstate = 2;
  8831. entity.verifytime = DateTime.Now;
  8832. entity.verifyuserid = CurrentUser.UserID;
  8833. entity.Update();
  8834. returnSuccessMsg("退回成功!");
  8835. return;
  8836. }
  8837. returnErrorMsg("找不到订单记录");
  8838. }
  8839. }
  8840. public void upd_erp_returnprice()
  8841. {
  8842. if (UrlPostParmsCheck("ID"))
  8843. {
  8844. int eid = GetPostInt("ID");
  8845. CeErpReturnCash entity = null;
  8846. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8847. if (entity != null)
  8848. {
  8849. if (entity.cashstate == 1)
  8850. {
  8851. returnErrorMsg("审核通过了不能改");
  8852. return;
  8853. }
  8854. entity.returnprice = GetPostDouble("returnprice");
  8855. entity.Update();
  8856. returnSuccessMsg("修改成功!");
  8857. return;
  8858. }
  8859. returnErrorMsg("找不到订单记录");
  8860. }
  8861. }
  8862. public void del_erp_returncash()
  8863. {
  8864. if (UrlPostParmsCheck("ID"))
  8865. {
  8866. int eid = GetPostInt("ID");
  8867. CeErpReturnCash.Del(eid);
  8868. returnSuccessMsg("操作成功");
  8869. return;
  8870. }
  8871. }
  8872. public void test_for_do_sql()
  8873. {
  8874. string sql = GetPostString("sqlstr");
  8875. if (sql.Length > 0)
  8876. {
  8877. try
  8878. {
  8879. DbHelper.DbConn.ExecuteNonQuery(sql);
  8880. var res_obj = new
  8881. {
  8882. data = "成功",
  8883. };
  8884. string ro_json = JsonConvert.SerializeObject(res_obj);
  8885. returnSuccess(ro_json);
  8886. }
  8887. catch (Exception ex)
  8888. {
  8889. var res_obj = new
  8890. {
  8891. data = ex.Message,
  8892. };
  8893. string ro_json = JsonConvert.SerializeObject(res_obj);
  8894. returnSuccess(ro_json);
  8895. }
  8896. }
  8897. }
  8898. public void get_user_info()
  8899. {
  8900. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8901. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8902. }
  8903. public void get_total_data()
  8904. {
  8905. int userId = CurrentUser.UserID;
  8906. string sql = "";
  8907. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8908. {
  8909. 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);
  8910. }
  8911. else
  8912. {
  8913. 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 " +
  8914. "(select ID from CE_ErpUser where ID = {0}) d " +
  8915. "left join " +
  8916. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8917. ") a on d.ID = a.id left join " +
  8918. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8919. ") b on a.id = b.id1 left join" +
  8920. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8921. ") c on a.id = c.id2;", userId);
  8922. }
  8923. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8924. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8925. }
  8926. public void get_date_area_total_data2()
  8927. {
  8928. int userId = CurrentUser.UserID;
  8929. string date_type = GetPostString("timetype");
  8930. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8931. string sql = "";
  8932. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8933. {
  8934. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8935. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8936. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8937. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8938. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8939. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8940. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8941. ") a on e.ID = a.id left join " +
  8942. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8943. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8944. ") b on a.id = b.id1 " +
  8945. "left join " +
  8946. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8947. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8948. ") c on a.id = c.id2 " +
  8949. "left join " +
  8950. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8951. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8952. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8953. }
  8954. else
  8955. {
  8956. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8957. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8958. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8959. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8960. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8961. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8962. ") a on e.ID = a.id left join " +
  8963. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8964. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8965. ") c on a.id = c.id2 " +
  8966. "left join " +
  8967. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8968. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8969. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8970. }
  8971. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8972. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8973. }
  8974. public void get_date_area_total_data()
  8975. {
  8976. int userId = CurrentUser.UserID;
  8977. string date_type = GetPostString("timetype");
  8978. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8979. string date1 = searchDT[0].ToString();
  8980. string date2 = searchDT[1].ToString();
  8981. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8982. {
  8983. SqlParameter[] sqlParameter ={
  8984. new SqlParameter("@userId", SqlDbType.Int,4),
  8985. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8986. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8987. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8988. };
  8989. sqlParameter[0].Value = userId;
  8990. sqlParameter[1].Value = date1;
  8991. sqlParameter[2].Value = date2;
  8992. sqlParameter[3].Direction = ParameterDirection.Output;
  8993. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8994. string res = sqlParameter[3].Value.ToString();
  8995. var res_obj = new
  8996. {
  8997. data = res
  8998. };
  8999. string ro_json = JsonConvert.SerializeObject(res_obj);
  9000. returnSuccess(ro_json);
  9001. }
  9002. else
  9003. {
  9004. SqlParameter[] sqlParameter ={
  9005. new SqlParameter("@userId", SqlDbType.Int,4),
  9006. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9007. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9008. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9009. };
  9010. sqlParameter[0].Value = userId;
  9011. sqlParameter[1].Value = date1;
  9012. sqlParameter[2].Value = date2;
  9013. sqlParameter[3].Direction = ParameterDirection.Output;
  9014. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9015. string res = sqlParameter[3].Value.ToString();
  9016. var res_obj = new
  9017. {
  9018. data = res
  9019. };
  9020. string ro_json = JsonConvert.SerializeObject(res_obj);
  9021. returnSuccess(ro_json);
  9022. }
  9023. //writeGridDataViewJson(dt.Rows.Count, dv);
  9024. }
  9025. public void get_order_list()
  9026. {
  9027. string strFields = GetPostString("paraFields");
  9028. string strOrder = GetPostString("paraOrder");
  9029. string strWhere = GetPostString("paraWhere");
  9030. string strPageSize = GetPostString("paraPageSize");
  9031. DataStruct dStruct = GetPostStruct();
  9032. dStruct.PageSize = int.Parse(strPageSize);
  9033. dStruct.Fileds = strFields;
  9034. dStruct.Order = strOrder;
  9035. dStruct.MainWhere = strWhere;
  9036. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9037. writeGridDataTableJson(dStruct.TotalCount, dt);
  9038. }
  9039. ////获取待开始订单列表
  9040. //public void get_wait_design_order_list()
  9041. //{
  9042. // string date_type = GetPostString("date_type");
  9043. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9044. // DataStruct dStruct = GetPostStruct();
  9045. // dStruct.PageSize = 1000;
  9046. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9047. // List<string> lw = new List<string>();
  9048. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9049. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9050. // dStruct.Order = "WaitDesignTime asc";
  9051. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9052. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9053. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9054. //}
  9055. //获取完成单量排名
  9056. public void get_finish_order_count_ranking()
  9057. {
  9058. /* string date_type = GetPostString("date_type");
  9059. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9060. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9061. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9062. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9063. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9064. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9065. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9066. writeGridDataTableJson(0, new DataTable());
  9067. }
  9068. public void get_finish_order_amount_ranking()
  9069. {
  9070. /*string date_type = GetPostString("date_type");
  9071. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9072. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9073. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9074. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9075. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9076. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9077. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9078. writeGridDataTableJson(0, new DataTable());
  9079. }
  9080. public void get_finish_refund_count_ranking()
  9081. {
  9082. string date_type = GetPostString("date_type");
  9083. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9084. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9085. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9086. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9087. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9088. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9089. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9090. writeGridDataTableJson(dt.Rows.Count, dt);
  9091. }
  9092. public void get_finish_refund_amount_ranking()
  9093. {
  9094. string date_type = GetPostString("date_type");
  9095. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9096. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9097. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9098. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9099. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9100. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9101. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9102. writeGridDataTableJson(dt.Rows.Count, dt);
  9103. }
  9104. public void set_erp_finishorder_director()
  9105. {
  9106. if (UrlPostParmsCheck("ctid"))
  9107. {
  9108. string eid = GetPostString("ctid");
  9109. CeErpTradeCell entity = null;
  9110. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9111. if (entity != null)
  9112. {
  9113. entity.OrderState = 8;
  9114. entity.Update();
  9115. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9116. returnSuccessMsg("操作成功!");
  9117. return;
  9118. }
  9119. returnErrorMsg("找不到记录");
  9120. }
  9121. }
  9122. public void get_erp_placeregistlist()
  9123. {
  9124. DataStruct dStruct = GetPostStruct();
  9125. List<string> lw = new List<string>();
  9126. string outsid = GetPostString("outsid");
  9127. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9128. string memo = GetPostString("memo");
  9129. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9130. string filename = GetPostString("filename");
  9131. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9132. string islate = GetPostString("islate");
  9133. if (islate.Length > 0)
  9134. {
  9135. if (islate == "1")
  9136. lw.Add(string.Format("OutLate>0"));
  9137. else
  9138. lw.Add(string.Format("OutLate=0"));
  9139. }
  9140. string placedate1 = GetPostString("placedate1");
  9141. string placedate2 = GetPostString("placedate2");
  9142. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9143. if (dw.Length > 0) lw.Add(dw);
  9144. string deliveryDate1 = GetPostString("deliverydate1");
  9145. string deliveryDate2 = GetPostString("deliverydate2");
  9146. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9147. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9148. dStruct.Order = "ID desc";
  9149. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9150. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9151. writeGridDataTableJson(dStruct.TotalCount, dt);
  9152. }
  9153. public void ins_erp_placeregist()
  9154. {
  9155. if (UrlPostParmsCheck("id"))
  9156. {
  9157. string eid = GetPostString("id");
  9158. CeErpPlaceRegister entity = null;
  9159. if (eid == "0")//新增
  9160. {
  9161. entity = new CeErpPlaceRegister();
  9162. string xdTime = GetPostString("placeTime");
  9163. if (xdTime.Length > 0)
  9164. {
  9165. entity.PlactTime = Convert.ToDateTime(xdTime);
  9166. }
  9167. string fhTime = GetPostString("deliveryTime");
  9168. if (fhTime.Length > 0)
  9169. {
  9170. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9171. }
  9172. string preTime = GetPostString("preOutTime");
  9173. if (preTime.Length > 0)
  9174. {
  9175. entity.PreOutTime = Convert.ToDateTime(preTime);
  9176. }
  9177. entity.DeliveryCount = GetPostInt("deliveryCount");
  9178. entity.ReceiveCount = GetPostInt("receiveCount");
  9179. entity.OutSid = GetPostString("outSid");
  9180. entity.FileName = GetPostString("fileName");
  9181. entity.Memo = GetPostString("memo");
  9182. entity.AddUserId = CurrentUser.UserID;
  9183. entity.CreateTime = DateTime.Now;
  9184. entity.Img = GetPostString("img");
  9185. entity.Supplier = GetPostInt("supplier");
  9186. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9187. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9188. {
  9189. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9190. DateTime dt2 = (DateTime)entity.PreOutTime;
  9191. TimeSpan span = dt1.Subtract(dt2);
  9192. if (span.Days > 0)
  9193. {
  9194. entity.OutLate = span.Days;
  9195. }
  9196. }
  9197. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9198. entity.Create();
  9199. returnSuccessMsg("添加成功!");
  9200. return;
  9201. }
  9202. else //修改
  9203. {
  9204. entity = CeErpPlaceRegister.Get(eid);
  9205. if (entity != null)
  9206. {
  9207. string xdTime = GetPostString("placeTime");
  9208. if (xdTime.Length > 0)
  9209. {
  9210. entity.PlactTime = Convert.ToDateTime(xdTime);
  9211. }
  9212. string fhTime = GetPostString("deliveryTime");
  9213. if (fhTime.Length > 0)
  9214. {
  9215. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9216. }
  9217. string preTime = GetPostString("preOutTime");
  9218. if (preTime.Length > 0)
  9219. {
  9220. entity.PreOutTime = Convert.ToDateTime(preTime);
  9221. }
  9222. entity.DeliveryCount = GetPostInt("deliveryCount");
  9223. entity.ReceiveCount = GetPostInt("receiveCount");
  9224. if (entity.DeliveryCount == entity.ReceiveCount)
  9225. {
  9226. entity.CurState = "已完成";
  9227. }
  9228. else
  9229. {
  9230. entity.CurState = "未完成";
  9231. }
  9232. entity.OutSid = GetPostString("outSid");
  9233. entity.FileName = GetPostString("fileName");
  9234. entity.Memo = GetPostString("memo");
  9235. entity.Img = GetPostString("img");
  9236. entity.Supplier = GetPostInt("supplier");
  9237. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9238. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9239. {
  9240. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9241. DateTime dt2 = (DateTime)entity.PreOutTime;
  9242. TimeSpan span = dt1.Subtract(dt2);
  9243. if (span.Days > 0)
  9244. {
  9245. entity.OutLate = span.Days;
  9246. }
  9247. }
  9248. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9249. entity.Update();
  9250. returnSuccessMsg("修改成功");
  9251. return;
  9252. }
  9253. returnErrorMsg("找不到对应的记录");
  9254. return;
  9255. }
  9256. }
  9257. returnErrorMsg("缺少必要参数");
  9258. }
  9259. public void del_erp_placeregist()
  9260. {
  9261. string eid = GetPostString("id");
  9262. CeErpPlaceRegister.Del(eid);
  9263. returnSuccessMsg("删除成功!");
  9264. return;
  9265. }
  9266. public void ins_erp_placeregistbyorder()
  9267. {
  9268. string ctid = GetPostString("ctid");
  9269. if (ctid.Length > 0)
  9270. {
  9271. StringBuilder sql = new StringBuilder();
  9272. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9273. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9274. if (dt.Rows.Count > 0)
  9275. {
  9276. foreach (DataRow dr in dt.Rows)
  9277. {
  9278. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9279. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9280. entity.AddUserId = CurrentUser.UserID;
  9281. entity.tid = dr["tid"].ToString();
  9282. entity.Did = Convert.ToString(dr["ctid"]);
  9283. entity.splitTag = dr["SplitTag"].ToString();
  9284. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9285. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9286. if (pre_ctid.Length > 0)
  9287. {
  9288. sellmemo = sellmemo.Replace(pre_ctid, "");
  9289. }
  9290. sellmemo = sellmemo.Replace("[", "");
  9291. sellmemo = sellmemo.Replace("]", "");
  9292. entity.FileName = sellmemo;
  9293. string count = dr["ProductCount"].ToString();
  9294. int usecount = commonHelper.getIntCountFromString(count);
  9295. entity.DeliveryCount = usecount;
  9296. entity.CurState = "未完成";
  9297. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9298. {
  9299. entity.Supplier = 24;//dl手提袋定制
  9300. }
  9301. else
  9302. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9303. entity.CreateTime = DateTime.Now;
  9304. entity.Create();
  9305. }
  9306. returnSuccessMsg("操作成功");
  9307. return;
  9308. }
  9309. returnErrorMsg("没有找到对应订单");
  9310. return;
  9311. }
  9312. returnErrorMsg("缺少订单编号");
  9313. return;
  9314. }
  9315. public void get_erp_persuadelist()
  9316. {
  9317. DataStruct dStruct = GetPostStruct();
  9318. List<string> lw = new List<string>();
  9319. string ctid = GetPostString("ctid");
  9320. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9321. string shopname = GetPostString("shopname");
  9322. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9323. string buyernick = GetPostString("buyer_nick");
  9324. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9325. string customer = GetPostString("customer");
  9326. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9327. string returndate1 = GetPostString("returndate1");
  9328. string returndate2 = GetPostString("returndate2");
  9329. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9330. if (dw.Length > 0) lw.Add(dw);
  9331. string finishDate1 = GetPostString("finishdate1");
  9332. string finishDate2 = GetPostString("finishdate2");
  9333. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9334. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9335. string persuadetype = GetPostString("persuadetype");
  9336. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9337. string returnvstate = GetPostString("returnvstate");
  9338. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9339. dStruct.Order = "created desc";
  9340. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9341. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9342. writeGridDataTableJson(dStruct.TotalCount, dt);
  9343. }
  9344. public void upd_erp_returnpersuadeback()
  9345. {
  9346. if (UrlPostParmsCheck("ID"))
  9347. {
  9348. int eid = GetPostInt("ID");
  9349. CeErpPersuade entity = null;
  9350. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9351. if (entity != null)
  9352. {
  9353. entity.backreason = GetPostString("reason");
  9354. entity.pstate = 2;
  9355. entity.verifytime = DateTime.Now;
  9356. entity.verifyuserid = CurrentUser.UserID;
  9357. entity.Update();
  9358. returnSuccessMsg("退回成功!");
  9359. return;
  9360. }
  9361. returnErrorMsg("找不到订单记录");
  9362. }
  9363. }
  9364. public void upd_erp_returnpersuadeverify()
  9365. {
  9366. if (UrlPostParmsCheck("ID"))
  9367. {
  9368. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9369. {
  9370. returnErrorMsg("暂无权限审核");
  9371. return;
  9372. }
  9373. int eid = GetPostInt("ID");
  9374. CeErpPersuade entity = null;
  9375. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9376. if (entity != null)
  9377. {
  9378. entity.pstate = 1;
  9379. entity.verifytime = DateTime.Now;
  9380. entity.verifyuserid = CurrentUser.UserID;
  9381. entity.Update();
  9382. returnSuccessMsg("审核成功!");
  9383. return;
  9384. }
  9385. returnErrorMsg("找不到订单记录");
  9386. }
  9387. }
  9388. public void del_erp_persuade()
  9389. {
  9390. if (UrlPostParmsCheck("ID"))
  9391. {
  9392. int eid = GetPostInt("ID");
  9393. CeErpPersuade.Del(eid);
  9394. returnSuccessMsg("操作成功");
  9395. return;
  9396. }
  9397. }
  9398. public void get_erp_oldcustoupload()
  9399. {
  9400. DataStruct dStruct = GetPostStruct();
  9401. List<string> lw = new List<string>();
  9402. string buyernick = GetPostString("buyer_nick");
  9403. if (buyernick.Length > 0)
  9404. {
  9405. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9406. }
  9407. else
  9408. return;
  9409. dStruct.Order = "pay_time desc";
  9410. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9411. DataTable dt = null;
  9412. dt = WebCache.GetData("view_erptradecell", dStruct);
  9413. writeGridDataTableJson(dStruct.TotalCount, dt);
  9414. }
  9415. public void get_erp_checkorderlist()
  9416. {
  9417. DataStruct dStruct = GetPostStruct();
  9418. List<string> lw = new List<string>();
  9419. string tid = GetPostString("ctid");
  9420. if (tid.Length > 0)
  9421. {
  9422. string select_tid = getTidByCtid(tid);
  9423. lw.Add(string.Format("tid='{0}'", select_tid));
  9424. }
  9425. string shopname = GetPostString("shopname");
  9426. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9427. string buyernick = GetPostString("buyer_nick");
  9428. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9429. string customer = GetPostString("customer");
  9430. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9431. string design = GetPostString("design");
  9432. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9433. string orderState = GetPostString("orderState");
  9434. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9435. string address = GetPostString("address");
  9436. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9437. string sellermemo = GetPostString("seller_memo");
  9438. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9439. string supplier = GetPostString("supplier");
  9440. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9441. {
  9442. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9443. }
  9444. else
  9445. {
  9446. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9447. }
  9448. string date1 = GetPostString("date1");
  9449. string date2 = GetPostString("date2");
  9450. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9451. if (dw.Length > 0) lw.Add(dw);
  9452. string placedate1 = GetPostString("placedate1");
  9453. string placedate2 = GetPostString("placedate2");
  9454. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9455. if (fdw.Length > 0) lw.Add(fdw);
  9456. string price1 = GetPostString("price1");
  9457. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9458. string price2 = GetPostString("price2");
  9459. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9460. string checkst = GetPostString("checkstate");
  9461. if (checkst.Length > 0 && "10".Equals(checkst))
  9462. {
  9463. lw.Add(string.Format("CheckOut>0"));
  9464. }
  9465. else
  9466. {
  9467. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9468. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9469. }
  9470. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9471. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9472. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9473. writeGridDataTableJson(dStruct.TotalCount, dt);
  9474. }
  9475. public void ins_erp_startCheck()
  9476. {
  9477. if (UrlPostParmsCheck("ctid"))
  9478. {
  9479. string eid = GetPostString("ctid");
  9480. CeErpTradeCell entity = null;
  9481. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9482. if (entity != null)
  9483. {
  9484. entity.MemoOpt = 4;
  9485. entity.UpdateTime = DateTime.Now;
  9486. entity.Update();
  9487. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9488. CeErpSukuraData.createInfo(entity.ctid, 6);
  9489. returnSuccessMsg("操作成功!");
  9490. return;
  9491. }
  9492. returnErrorMsg("找不到记录");
  9493. }
  9494. }
  9495. public void upd_erp_sendXlw()
  9496. {
  9497. if (UrlPostParmsCheck("ctid"))
  9498. {
  9499. string eid = GetPostString("ctid");
  9500. CeErpTradeCell entity = null;
  9501. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9502. if (entity != null)
  9503. {
  9504. if (entity.IsSendGift == 1)
  9505. {
  9506. returnErrorMsg("请勿重复标记");
  9507. return;
  9508. }
  9509. entity.IsSendGift = 1;
  9510. entity.Update();
  9511. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9512. returnSuccessMsg("操作成功!");
  9513. return;
  9514. }
  9515. returnErrorMsg("找不到记录");
  9516. }
  9517. }
  9518. public void cancel_sendXlw()
  9519. {
  9520. if (UrlPostParmsCheck("ctid"))
  9521. {
  9522. string eid = GetPostString("ctid");
  9523. CeErpTradeCell entity = null;
  9524. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9525. if (entity != null)
  9526. {
  9527. if (entity.IsSendGift == 0)
  9528. {
  9529. returnErrorMsg("未标记小礼物");
  9530. return;
  9531. }
  9532. entity.IsSendGift = 0;
  9533. entity.Update();
  9534. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9535. returnSuccessMsg("操作成功!");
  9536. return;
  9537. }
  9538. returnErrorMsg("找不到记录");
  9539. }
  9540. }
  9541. public void get_erp_designbill()
  9542. {
  9543. DataStruct dStruct = GetPostStruct();
  9544. List<string> lw = new List<string>();
  9545. int isMy = GetInt("my");
  9546. if (isMy == 1)
  9547. {
  9548. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9549. }
  9550. string tid = GetPostString("tid");
  9551. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9552. string userName = GetPostString("design");
  9553. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9554. string price1 = GetPostString("price1");
  9555. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9556. string price2 = GetPostString("price2");
  9557. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9558. string rePrice1 = GetPostString("rePrice1");
  9559. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9560. string rePrice2 = GetPostString("rePrice2");
  9561. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9562. string designerType = GetPostString("designerType");
  9563. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9564. string orderState = GetPostString("orderState");
  9565. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9566. string endTime1 = GetPostString("endTime1");
  9567. string endTime2 = GetPostString("endTime2");
  9568. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9569. if (dw.Length > 0) lw.Add(dw);
  9570. string isDk = GetPostString("isDk");
  9571. if (isDk == "1")
  9572. {
  9573. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9574. }
  9575. else if (isDk == "0")
  9576. {
  9577. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9578. }
  9579. dStruct.Order = "oid, create_time desc";
  9580. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9581. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9582. writeGridDataTableJson(dStruct.TotalCount, dt);
  9583. }
  9584. public void upd_erp_designerbill()
  9585. {
  9586. if (UrlPostParmsCheck("ID"))
  9587. {
  9588. string eid = GetPostString("ID");
  9589. CeErpDesignerBill entity = null;
  9590. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9591. if (entity != null)
  9592. {
  9593. if (GetPostDouble("designerpirce") > 0)
  9594. {
  9595. entity.realPrice = GetPostDouble("designerpirce");
  9596. entity.update_time = DateTime.Now;
  9597. entity.update_u_id = CurrentUser.UserID;
  9598. entity.update_u_name = CurrentUser.UserName;
  9599. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9600. entity.Update();
  9601. returnSuccessMsg("操作成功!");
  9602. return;
  9603. }
  9604. else
  9605. {
  9606. entity.price = GetPostDouble("price");
  9607. entity.update_time = DateTime.Now;
  9608. entity.update_u_id = CurrentUser.UserID;
  9609. entity.update_u_name = CurrentUser.UserName;
  9610. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9611. entity.Update();
  9612. returnSuccessMsg("操作成功!");
  9613. return;
  9614. }
  9615. }
  9616. returnErrorMsg("找不到记录");
  9617. }
  9618. }
  9619. public void audit_erp_designerbill()
  9620. {
  9621. if (UrlPostParmsCheck("ID"))
  9622. {
  9623. string eid = GetPostString("ID");
  9624. CeErpDesignerBill entity = null;
  9625. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9626. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9627. if (entity != null)
  9628. {
  9629. entity.realPrice = GetPostDouble("designerpirce");
  9630. entity.update_time = DateTime.Now;
  9631. entity.update_u_id = CurrentUser.UserID;
  9632. entity.update_u_name = CurrentUser.UserName;
  9633. entity.isAudit = 1;
  9634. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9635. entity.Update();
  9636. if (orderEntity != null)
  9637. {
  9638. orderEntity.IsReadTag = 3;
  9639. orderEntity.Update();
  9640. }
  9641. returnSuccessMsg("操作成功!");
  9642. return;
  9643. }
  9644. returnErrorMsg("找不到记录");
  9645. }
  9646. }
  9647. public void all_audit_erp_designerbill()
  9648. {
  9649. if (UrlPostParmsCheck("idList"))
  9650. {
  9651. string[] list = GetPostString("idList").Split(',');
  9652. CeErpDesignerBill entity = null;
  9653. for (int i = 0; i < list.Length; i++)
  9654. {
  9655. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9656. if (entity == null) return;
  9657. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9658. if (orderEntity == null) return;
  9659. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9660. entity.update_time = DateTime.Now;
  9661. entity.update_u_id = CurrentUser.UserID;
  9662. entity.update_u_name = CurrentUser.UserName;
  9663. entity.isAudit = 1;
  9664. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9665. entity.Update();
  9666. orderEntity.IsReadTag = 3;
  9667. orderEntity.Update();
  9668. }
  9669. returnSuccessMsg("操作成功!");
  9670. return;
  9671. }
  9672. }
  9673. public void get_erp_sameorders()
  9674. {
  9675. if (UrlPostParmsCheck("ctid"))
  9676. {
  9677. string eid = GetPostString("ctid");
  9678. CeErpTradeCell entity = null;
  9679. entity = CeErpTradeCell.GetByCtid(eid);
  9680. if (entity != null)
  9681. {
  9682. StringBuilder sql = new StringBuilder();
  9683. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9684. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9685. var res = new
  9686. {
  9687. data = dt.Rows.Count
  9688. };
  9689. string ro_jsond = JsonConvert.SerializeObject(res);
  9690. returnSuccess(ro_jsond);
  9691. return;
  9692. }
  9693. returnErrorMsg("未找到订单");
  9694. return;
  9695. }
  9696. returnErrorMsg("缺少必要的参数");
  9697. }
  9698. public void get_erp_islasthavesameorder()
  9699. {
  9700. if (UrlPostParmsCheck("ctid"))
  9701. {
  9702. string eid = GetPostString("ctid");
  9703. string[] ctidList = eid.Split(',');
  9704. StringBuilder sql = new StringBuilder();
  9705. string tisCtid = "";
  9706. foreach (string ctid in ctidList)
  9707. {
  9708. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9709. if (entity != null)
  9710. {
  9711. sql = new StringBuilder();
  9712. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9713. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9714. if (dth.Rows.Count > 0)
  9715. {
  9716. tisCtid += entity.ctid;
  9717. tisCtid += ",";
  9718. }
  9719. }
  9720. }
  9721. if (tisCtid.Length > 0)
  9722. {
  9723. var res = new
  9724. {
  9725. data = tisCtid
  9726. };
  9727. string ro_jsond = JsonConvert.SerializeObject(res);
  9728. returnSuccess(ro_jsond);
  9729. }
  9730. else
  9731. {
  9732. var res = new
  9733. {
  9734. data = ""
  9735. };
  9736. string ro_jsond = JsonConvert.SerializeObject(res);
  9737. returnSuccess(ro_jsond);
  9738. }
  9739. return;
  9740. }
  9741. returnErrorMsg("缺少必要的参数");
  9742. }
  9743. public void file_client_down_url()
  9744. {
  9745. if (!UrlPostParmsCheck("userId"))
  9746. {
  9747. returnErrorMsg("缺少必要的参数");
  9748. }
  9749. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9750. }
  9751. public void checkout_form_data()
  9752. {
  9753. if (!UrlPostParmsCheck("tid"))
  9754. {
  9755. returnErrorMsg("缺少必要的参数");
  9756. }
  9757. string tid = GetPostString("tid");
  9758. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9759. if (ceErpOrderFormData != null)
  9760. {
  9761. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9762. returnSuccess(ro_jsond);
  9763. return;
  9764. }
  9765. returnErrorMsg("尚未有文件!");
  9766. }
  9767. public void back_supplier_audit()
  9768. {
  9769. int userId = CurrentUser.UserID;
  9770. StringBuilder sql = new StringBuilder();
  9771. 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);
  9772. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9773. if (dt.Rows.Count > 0)
  9774. {
  9775. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9776. }
  9777. else
  9778. {
  9779. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9780. }
  9781. }
  9782. public void back_supplier_query()
  9783. {
  9784. string eid = GetPostString("ctid");
  9785. if (eid != "")
  9786. {
  9787. StringBuilder sql = new StringBuilder();
  9788. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9789. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9790. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9791. }
  9792. else
  9793. {
  9794. returnErrorMsg("找不到订单记录");
  9795. return;
  9796. }
  9797. }
  9798. public void verified_to_order()
  9799. {
  9800. int userId = CurrentUser.UserID;
  9801. StringBuilder sql = new StringBuilder();
  9802. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9803. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9804. if (dt.Rows.Count > 0)
  9805. {
  9806. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9807. }
  9808. else
  9809. {
  9810. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9811. }
  9812. }
  9813. public void upd_supplier_audit()
  9814. {
  9815. if (UrlPostParmsCheck("ctid"))
  9816. {
  9817. string eid = GetPostString("ctid");
  9818. string reason = GetPostString("returnreason");
  9819. CeErpTradeCell entity = null;
  9820. CeWithdraw withdraw = null;
  9821. withdraw = CeWithdraw.GetByTid(eid);
  9822. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9823. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9824. {
  9825. if (withdraw != null)
  9826. {
  9827. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9828. {
  9829. returnSuccessMsg("您没有权限操作!");
  9830. return;
  9831. }
  9832. else
  9833. {
  9834. if (reason.Equals("1"))
  9835. {
  9836. if (entity.OrderState == -1)
  9837. {
  9838. if (entity.FinishPlaceTime == null)
  9839. {
  9840. entity.OrderState = 2;
  9841. }
  9842. else
  9843. {
  9844. entity.OrderState = 6;
  9845. }
  9846. }
  9847. entity.Update();
  9848. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9849. if (withdraw != null)
  9850. {
  9851. withdraw.status = int.Parse(reason);
  9852. withdraw.Update();
  9853. }
  9854. returnSuccessMsg("操作成功!");
  9855. return;
  9856. }
  9857. else
  9858. {
  9859. withdraw.status = int.Parse(reason);
  9860. withdraw.acknowledgingtime = DateTime.Now;
  9861. withdraw.Update();
  9862. returnSuccessMsg("查看详细请点击线下订单查询");
  9863. return;
  9864. }
  9865. }
  9866. }
  9867. // 第一个字符是 'N'
  9868. }
  9869. if (eid[0] != 'N')
  9870. {
  9871. }
  9872. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9873. {
  9874. entity.IsVerifyToSupplier = false;
  9875. entity.IsReturn = 1;
  9876. entity.ReturnTime = DateTime.Now;
  9877. entity.ReturnReason = reason;
  9878. if (entity.OrderState == 6)
  9879. {
  9880. entity.OrderState = 5;
  9881. }
  9882. entity.Update();
  9883. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9884. if (withdraw != null)
  9885. {
  9886. withdraw.status = int.Parse(reason);
  9887. withdraw.Update();
  9888. }
  9889. returnSuccessMsg("操作成功!");
  9890. return;
  9891. }
  9892. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9893. {
  9894. ;
  9895. if (withdraw != null)
  9896. {
  9897. withdraw.status = int.Parse(reason);
  9898. withdraw.acknowledgingtime = DateTime.Now;
  9899. withdraw.Update();
  9900. returnSuccessMsg("供应商取消撤回!");
  9901. return;
  9902. }
  9903. }
  9904. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9905. {
  9906. if (entity.OrderState == -1)
  9907. {
  9908. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9909. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9910. {
  9911. returnErrorMsg("订单spu没有确认无法通过审核!");
  9912. return;
  9913. }
  9914. if (entity.FinishPlaceTime == null)
  9915. {
  9916. entity.OrderState = 2;
  9917. }
  9918. else
  9919. {
  9920. entity.OrderState = 3;
  9921. }
  9922. commonHelper.getCytPrice(entity);
  9923. }
  9924. entity.Update();
  9925. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9926. if (withdraw != null)
  9927. {
  9928. withdraw.status = int.Parse(reason);
  9929. withdraw.Update();
  9930. }
  9931. returnSuccessMsg("操作成功!");
  9932. return;
  9933. }
  9934. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9935. {
  9936. if (withdraw == null)
  9937. {
  9938. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9939. return;
  9940. }
  9941. }
  9942. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9943. {
  9944. if (withdraw != null)
  9945. {
  9946. withdraw.status = int.Parse(reason);
  9947. withdraw.acknowledgingtime = DateTime.Now;
  9948. withdraw.Update();
  9949. returnSuccessMsg("查看详细请点击线下订单查询");
  9950. return;
  9951. }
  9952. }
  9953. return;
  9954. }
  9955. }
  9956. //校验报价
  9957. public void refund_order_tip()
  9958. {
  9959. int userid = CurrentUser.UserID;
  9960. int sectionId = CurrentUser.UserPost.OrgID;
  9961. StringBuilder sql = new StringBuilder();
  9962. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9963. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9964. List<string> ids = new List<string>();
  9965. if (dth.Rows.Count > 0)
  9966. {
  9967. foreach (DataRow dr in dth.Rows)
  9968. {
  9969. ids.Add(dr["ID"].ToString());
  9970. }
  9971. try
  9972. {
  9973. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9974. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9975. }
  9976. catch (Exception ex)
  9977. {
  9978. }
  9979. }
  9980. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9981. }
  9982. public void refund_order_Design()
  9983. {
  9984. int userid = CurrentUser.UserID;
  9985. int sectionId = CurrentUser.UserPost.OrgID;
  9986. StringBuilder sql = new StringBuilder();
  9987. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9988. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9989. List<string> ids = new List<string>();
  9990. if (dth.Rows.Count > 0)
  9991. {
  9992. foreach (DataRow dr in dth.Rows)
  9993. {
  9994. ids.Add(dr["ID"].ToString());
  9995. }
  9996. try
  9997. {
  9998. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9999. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10000. }
  10001. catch (Exception ex)
  10002. {
  10003. }
  10004. }
  10005. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10006. }
  10007. public void change_order_info()
  10008. {
  10009. int userid = CurrentUser.UserID;
  10010. StringBuilder sql = new StringBuilder();
  10011. 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);
  10012. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10013. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10014. }
  10015. public void change_win_mome()
  10016. {
  10017. if (UrlPostParmsCheck("id,ctid"))
  10018. {
  10019. string id = GetPostString("id");
  10020. string ctid = GetPostString("ctid");
  10021. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10022. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10023. if (ce == null || ceErpMessageTip == null)
  10024. {
  10025. returnSuccessMsg("未找到对应的订单!");
  10026. return;
  10027. }
  10028. if (ce.OrderState >= 5)
  10029. {
  10030. returnSuccessMsg("已上传文件无法修改!");
  10031. return;
  10032. }
  10033. int type = GetPostInt("type");
  10034. string content = GetPostString("content");
  10035. if (type == 0)
  10036. {
  10037. content = content.Replace("(", "(");
  10038. content = content.Replace(")", ")");
  10039. string check = MidStrEx(content, "(", ")").Trim();
  10040. if (string.IsNullOrEmpty(check))
  10041. {
  10042. returnSuccessMsg("文件名格式不正确");
  10043. return;
  10044. }
  10045. }
  10046. ce.seller_memo = content;
  10047. ce.Update();
  10048. ceErpMessageTip.isVisit = true;
  10049. ceErpMessageTip.Update();
  10050. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10051. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10052. ApiVo apiVo = new ApiVo();
  10053. apiVo.orderNumber = ce.ctid;
  10054. apiVo.actionName = "demandDesign";
  10055. apiVo.orderRemarks = content;
  10056. apiVo.demandExamine = type + 1;
  10057. designHelper.API_WorkCore(apiVo);//demandDesign
  10058. returnSuccessMsg("修改成功!");
  10059. }
  10060. }
  10061. public static string MidStrEx(string sourse, string startstr, string endstr)
  10062. {
  10063. string result = string.Empty;
  10064. int startindex, endindex;
  10065. try
  10066. {
  10067. startindex = sourse.IndexOf(startstr);
  10068. if (startindex == -1)
  10069. return result;
  10070. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10071. endindex = tmpstr.IndexOf(endstr);
  10072. if (endindex == -1)
  10073. return result;
  10074. result = tmpstr.Remove(endindex);
  10075. }
  10076. catch (Exception ex)
  10077. {
  10078. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10079. }
  10080. return result;
  10081. }
  10082. public void refund_order_list()
  10083. {
  10084. int userid = CurrentUser.UserID;
  10085. int sectionId = CurrentUser.UserPost.OrgID;
  10086. StringBuilder sql = new StringBuilder();
  10087. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10088. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10089. DataStruct dStruct = GetPostStruct();
  10090. DataTable dt = null;
  10091. List<string> ids = new List<string>();
  10092. List<string> tids = new List<string>();
  10093. if (dth.Rows.Count > 0)
  10094. {
  10095. foreach (DataRow dr in dth.Rows)
  10096. {
  10097. tids.Add("'" + dr["tid"].ToString() + "'");
  10098. ids.Add(dr["id"].ToString());
  10099. }
  10100. try
  10101. {
  10102. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10103. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10104. List<string> lw = new List<string>();
  10105. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10106. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10107. dt = WebCache.GetData("view_orderlist", dStruct);
  10108. }
  10109. catch (Exception ex)
  10110. {
  10111. }
  10112. }
  10113. writeGridDataTableJson(dStruct.TotalCount, dt);
  10114. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10115. }
  10116. //新增
  10117. public void order_batch_downloads()
  10118. {
  10119. string ceid = GetPostString("tid");
  10120. String[] tid = ceid.Split(',');
  10121. order_batch_caiyingtong(tid);
  10122. /* (string success, string errors) = UploadFiles(tid);
  10123. returnSuccessMsg(success + errors);*/
  10124. return;
  10125. }
  10126. //报价接口
  10127. public void Get_To_Quote()
  10128. {
  10129. string ceid = GetPostString("ctid");
  10130. if (ceid != null)
  10131. {
  10132. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10133. if (entity != null)
  10134. {
  10135. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10136. {
  10137. return;
  10138. }
  10139. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10140. double price = 0;
  10141. if (cp == null)
  10142. {
  10143. JObject jsonObject12 = new JObject
  10144. {
  10145. { "UserId", "77886" },
  10146. { "Pwd", "lt666888" },
  10147. { "Filename", entity.seller_memo }
  10148. };
  10149. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10150. JObject jsonObjects1 = JObject.Parse(response1);
  10151. string ms1g = (string)jsonObjects1["msg"];
  10152. if (ms1g == "报价成功")
  10153. {
  10154. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10155. string data = (string)jsonObject1["price"];
  10156. 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 + "');";
  10157. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10158. returnSuccessMsg("获取报价成功:" + data);
  10159. price = Convert.ToDouble(data);
  10160. }
  10161. else
  10162. {
  10163. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10164. return;
  10165. }
  10166. }
  10167. String[] beizhu = entity.seller_memo.Split('-');
  10168. String chanp = "";
  10169. if (beizhu.Length > 0)
  10170. {
  10171. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10172. }
  10173. else
  10174. {
  10175. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10176. }
  10177. JObject jsonObject = new JObject
  10178. {
  10179. { "UserId", "77886" },
  10180. { "Pwd", "lt666888" },
  10181. { "Filename", chanp }
  10182. };
  10183. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10184. JObject jsonObjects = JObject.Parse(response);
  10185. string msg = (string)jsonObjects["msg"];
  10186. if (msg == "报价成功")
  10187. {
  10188. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10189. string data = (string)jsonObject1["price"];
  10190. 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 + "');";
  10191. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10192. returnSuccessMsg("获取报价成功:" + data);
  10193. price = Convert.ToDouble(data);
  10194. }
  10195. else
  10196. {
  10197. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10198. return;
  10199. }
  10200. if (price > 0)
  10201. {
  10202. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10203. if (ceErpTradeCellExtend == null)
  10204. {
  10205. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10206. ceErpTradeCellExtend.ctid = entity.ctid;
  10207. ceErpTradeCellExtend.payment_cyt = price;
  10208. ceErpTradeCellExtend.Create();
  10209. }
  10210. else
  10211. {
  10212. ceErpTradeCellExtend.payment_cyt = price;
  10213. ceErpTradeCellExtend.Update();
  10214. }
  10215. }
  10216. return;
  10217. }
  10218. }
  10219. else
  10220. {
  10221. returnErrorMsg("请至少选择一条数据");
  10222. return;
  10223. }
  10224. }
  10225. //新增
  10226. public void order_To_Supplier()
  10227. {
  10228. string ceid = GetPostString("tid");
  10229. String[] tid = ceid.Split(',');
  10230. if (tid.Length > 0)
  10231. {
  10232. try
  10233. {
  10234. for (int i = 0; i < tid.Length; i++)
  10235. {
  10236. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10237. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10238. entity.SupplierId = suid;
  10239. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10240. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10241. entity.Update();
  10242. }
  10243. }
  10244. catch (Exception ex)
  10245. {
  10246. returnErrorMsg("自动匹配供应商失败");
  10247. return;
  10248. }
  10249. }
  10250. else
  10251. {
  10252. returnErrorMsg("请至少选择一条数据");
  10253. return;
  10254. }
  10255. returnSuccessMsg("自动匹配供应商成功");
  10256. return;
  10257. }
  10258. public (string, string) UploadFiles(string[] urls)
  10259. {
  10260. string success = "";
  10261. string errors = "";
  10262. int userid = CurrentUser.UserID;
  10263. foreach (string url in urls)
  10264. {
  10265. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10266. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10267. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10268. {
  10269. JObject jsonObject = new JObject
  10270. {
  10271. { "Userid", "77886" },
  10272. { "pwd", "cyt86435015" },
  10273. { "content", base64FileContent },
  10274. { "ext", Path.GetExtension(fileName) }
  10275. };
  10276. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10277. JObject jsonObjects = JObject.Parse(response);
  10278. string msg = (string)jsonObjects["msg"];
  10279. if (msg.Equals("上传成功"))
  10280. {
  10281. success += url + " 上传成功";
  10282. }
  10283. else
  10284. {
  10285. errors += url + " 上传失败";
  10286. }
  10287. }
  10288. else
  10289. {
  10290. errors += url + " 格式出现问题";
  10291. }
  10292. }
  10293. if (urls.Length == 0)
  10294. {
  10295. return (success, errors);
  10296. }
  10297. return (success, errors);
  10298. }
  10299. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10300. {
  10301. return true; //总是接受
  10302. }
  10303. public static string HttpPost(string url, string param = null)
  10304. {
  10305. HttpWebRequest request;
  10306. //如果是发送HTTPS请求
  10307. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10308. {
  10309. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10310. request = WebRequest.Create(url) as HttpWebRequest;
  10311. request.ProtocolVersion = HttpVersion.Version10;
  10312. }
  10313. else
  10314. {
  10315. request = WebRequest.Create(url) as HttpWebRequest;
  10316. }
  10317. request.Method = "POST";
  10318. request.ContentType = "application/json";
  10319. request.Accept = "*/*";
  10320. request.Timeout = 120000;
  10321. request.AllowAutoRedirect = false;
  10322. StreamWriter requestStream = null;
  10323. WebResponse response = null;
  10324. string responseStr = null;
  10325. try
  10326. {
  10327. requestStream = new StreamWriter(request.GetRequestStream());
  10328. requestStream.Write(param);
  10329. requestStream.Close();
  10330. response = request.GetResponse();
  10331. if (response != null)
  10332. {
  10333. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10334. responseStr = reader.ReadToEnd();
  10335. reader.Close();
  10336. }
  10337. }
  10338. catch (Exception ex)
  10339. {
  10340. return ex.Message;
  10341. }
  10342. finally
  10343. {
  10344. request = null;
  10345. requestStream = null;
  10346. response = null;
  10347. }
  10348. return responseStr;
  10349. }
  10350. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10351. {
  10352. string base64FileContent;
  10353. string fileName;
  10354. using (WebClient webClient = new WebClient())
  10355. {
  10356. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10357. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10358. {
  10359. using (Stream stream = response.GetResponseStream())
  10360. {
  10361. using (MemoryStream memoryStream = new MemoryStream())
  10362. {
  10363. stream.CopyTo(memoryStream);
  10364. byte[] fileBytes = memoryStream.ToArray();
  10365. base64FileContent = Convert.ToBase64String(fileBytes);
  10366. fileName = response.Headers["Content-Disposition"];
  10367. if (!string.IsNullOrEmpty(fileName))
  10368. {
  10369. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10370. if (index >= 0)
  10371. {
  10372. fileName = fileName.Substring(index + 9).Trim('\"');
  10373. }
  10374. }
  10375. else
  10376. {
  10377. fileName = Path.GetFileName(downloadUrl);
  10378. }
  10379. }
  10380. }
  10381. }
  10382. }
  10383. return (fileName, base64FileContent);
  10384. }
  10385. //新增
  10386. public void order_batch_caiyingtong(string[] downloadUrls)
  10387. {
  10388. try
  10389. {
  10390. //遍历文件
  10391. DataStruct dStruct = GetPostStruct();
  10392. DataTable dt = null;
  10393. int userid = CurrentUser.UserID;
  10394. List<string> ids = new List<string>();//失败组
  10395. List<string> tids = new List<string>();
  10396. using (WebClient webClient = new WebClient())
  10397. {
  10398. foreach (var url in downloadUrls)
  10399. {
  10400. try
  10401. {
  10402. tids.Add("'" + url + "'");
  10403. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10404. if (entity != null)
  10405. {
  10406. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10407. if (cp == null)
  10408. {
  10409. JObject jsonObject = new JObject
  10410. {
  10411. { "Userid", "77886" },
  10412. { "pwd", "lt666888" },
  10413. { "Filename",entity.seller_memo }
  10414. };
  10415. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10416. JObject jsonObjects = JObject.Parse(response);
  10417. string msg = (string)jsonObjects["msg"];
  10418. if (msg == "报价成功")
  10419. {
  10420. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10421. DownloadAndConvertToBase64(url1);
  10422. }
  10423. else
  10424. {
  10425. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10426. }
  10427. }
  10428. else
  10429. {
  10430. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10431. JObject jsonObject = new JObject
  10432. {
  10433. { "Userid", "77886" },
  10434. { "pwd", "lt666888" },
  10435. { "Filename",chanp }
  10436. };
  10437. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10438. JObject jsonObjects = JObject.Parse(response);
  10439. string msg = (string)jsonObjects["msg"];
  10440. if (msg == "报价成功")
  10441. {
  10442. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10443. DownloadAndConvertToBase64(url1);
  10444. }
  10445. else
  10446. {
  10447. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10448. }
  10449. }
  10450. }
  10451. // 上传文件到FTP
  10452. }
  10453. catch (Exception ex)
  10454. {
  10455. Console.WriteLine($"An error occurred: {ex.Message}");
  10456. }
  10457. }
  10458. List<string> lw = new List<string>();
  10459. lw.Add(string.Format("( OrderState < 6 )"));
  10460. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10461. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10462. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10463. if (dt.Rows.Count > 0)
  10464. {
  10465. foreach (DataRow dr in dt.Rows)
  10466. {
  10467. ids.Add(dr["ctid"].ToString());
  10468. }
  10469. }
  10470. String ErrorMsgs = "";
  10471. foreach (String id in ids)
  10472. {
  10473. ErrorMsgs += id + ",";
  10474. }
  10475. if (ErrorMsgs.Length > 1)
  10476. {
  10477. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10478. }
  10479. if (ErrorMsgs.Length < 1)
  10480. {
  10481. ErrorMsgs = "上传成功";
  10482. returnSuccessMsg(ErrorMsgs);
  10483. }
  10484. else
  10485. {
  10486. returnErrorMsg("以下订单" + ErrorMsgs);
  10487. }
  10488. }
  10489. // 删除文件夹及其内容
  10490. /* Directory.Delete(localDirectory, true);*/
  10491. }
  10492. catch { }
  10493. }
  10494. public void get_center_data()
  10495. {
  10496. int userId = CurrentUser.UserID;
  10497. string postCode = CurrentUser.UserPost.Post.Code;
  10498. List<string> lw = new List<string>();
  10499. List<string> ww = new List<string>();
  10500. DateTime currentTime = DateTime.Now;
  10501. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10502. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10503. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10504. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10505. string sql = " SELECT ";
  10506. string startTime = "2023-10-01 11:22:31";
  10507. //设计
  10508. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10509. {
  10510. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10511. 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));
  10512. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10513. 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));
  10514. }
  10515. //客服
  10516. else if (postCode == "CustomerService" || postCode == "Director")
  10517. {
  10518. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10519. 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));
  10520. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10521. 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));
  10522. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10523. 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));
  10524. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10525. 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));
  10526. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10527. 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));
  10528. }
  10529. //售后
  10530. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10531. {
  10532. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10533. 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));
  10534. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10535. 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));
  10536. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10537. ww.Add(string.Format("( SELECT COUNT ( * ) AS checkCount FROM CE_ErpTradeCell WHERE CheckOrderTime < '{1}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND pay_time > '{0}' ) AS cc", startTime, checkOrderTime));
  10538. }
  10539. //下单部
  10540. else if (postCode == "Place" || postCode == "PlaceMr")
  10541. {
  10542. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10543. 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));
  10544. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10545. 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));
  10546. }
  10547. //车间
  10548. else if (postCode == "Supplier")
  10549. {
  10550. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10551. 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));
  10552. }
  10553. DataTable dt = new DataTable();
  10554. if (lw.Count > 0)
  10555. {
  10556. sql += string.Join(" , ", lw);
  10557. sql += " FROM ";
  10558. sql += string.Join(" , ", ww);
  10559. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10560. }
  10561. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10562. }
  10563. public void get_center_data_list()
  10564. {
  10565. int userId = CurrentUser.UserID;
  10566. string postCode = CurrentUser.UserPost.Post.Code;
  10567. string shopIds = CurrentUser.User.pemShop;
  10568. DataStruct dStruct = GetPostStruct();
  10569. List<string> lw = new List<string>();
  10570. DateTime currentTime = DateTime.Now;
  10571. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10572. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10573. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10574. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10575. string startTime = "2023-10-01 11:22:31";
  10576. int order_type = GetPostInt("order_type");
  10577. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10578. {
  10579. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10580. if (order_type == 0)
  10581. {
  10582. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10583. }
  10584. else if (order_type == 3)
  10585. {
  10586. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10587. }
  10588. else
  10589. {
  10590. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10591. }
  10592. }
  10593. //客服
  10594. if (postCode == "CustomerService" || postCode == "Director")
  10595. {
  10596. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10597. if (order_type == 0)
  10598. {
  10599. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10600. }
  10601. else if (order_type == 1)
  10602. {
  10603. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10604. }
  10605. else if (order_type == 2)
  10606. {
  10607. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10608. }
  10609. else if (order_type == 3)
  10610. {
  10611. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10612. }
  10613. else if (order_type == 4)
  10614. {
  10615. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10616. }
  10617. else
  10618. {
  10619. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10620. }
  10621. }
  10622. //售后
  10623. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10624. {
  10625. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10626. if (shopIds != "")
  10627. {
  10628. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10629. }
  10630. if (order_type == 2)
  10631. {
  10632. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10633. }
  10634. else if (order_type == 4)
  10635. {
  10636. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10637. }
  10638. else if (order_type == 5)
  10639. {
  10640. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10641. }
  10642. else
  10643. {
  10644. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10645. }
  10646. }
  10647. //下单部
  10648. if (postCode == "Place" || postCode == "PlaceMr")
  10649. {
  10650. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10651. if (shopIds != "")
  10652. {
  10653. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10654. }
  10655. else if (order_type == 1)
  10656. {
  10657. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10658. }
  10659. else if (order_type == 2)
  10660. {
  10661. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10662. }
  10663. else
  10664. {
  10665. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10666. }
  10667. }
  10668. //车间
  10669. if (postCode == "Supplier")
  10670. {
  10671. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10672. if (order_type == 5)
  10673. {
  10674. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10675. }
  10676. else
  10677. {
  10678. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10679. }
  10680. }
  10681. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10682. dStruct.Fileds = "tid,ctid";
  10683. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10684. writeGridDataTableJson(dStruct.TotalCount, dt);
  10685. }
  10686. public void aftersale_audit_master()
  10687. {
  10688. if (UrlPostParmsCheck("ctid"))
  10689. {
  10690. string ctid = GetPostString("ctid");
  10691. if (ctid.Length > 0)
  10692. {
  10693. bool result = aftersale_data_change(ctid);
  10694. if (result)
  10695. {
  10696. returnSuccessMsg("修改成功!");
  10697. return;
  10698. }
  10699. }
  10700. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10701. }
  10702. }
  10703. public void aftersale_batch_audit_master()
  10704. {
  10705. if (UrlPostParmsCheck("ctids"))
  10706. {
  10707. string ctids = GetPostString("ctids");
  10708. if (ctids.Length > 0)
  10709. {
  10710. List<string> list = new List<string>();
  10711. string[] ctid_list = ctids.Split(',');
  10712. foreach (var item in ctid_list)
  10713. {
  10714. bool result = aftersale_data_change(item);
  10715. if (!result)
  10716. {
  10717. list.Add(item);
  10718. }
  10719. }
  10720. if (list.Count > 0)
  10721. {
  10722. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10723. return;
  10724. }
  10725. returnSuccessMsg("修改成功!");
  10726. return;
  10727. }
  10728. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10729. }
  10730. }
  10731. public bool aftersale_data_change(string ctid)
  10732. {
  10733. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10734. if (ceErpTradeCell != null)
  10735. {
  10736. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10737. ceErpTradeCell.AfterSaleSupplierState = 0;
  10738. StringBuilder sql = new StringBuilder();
  10739. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10740. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10741. CeErpTradeResponsible.DelByTid(ctid, 0);
  10742. 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 == "不理赔")
  10743. {
  10744. CeErpTradeResponsible.DelByTid(ctid, 1);
  10745. ceErpTradeCell.AfterSaleSupplierState = 1;
  10746. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10747. ceErpTradeCell.AfterSaleState = 4;
  10748. }
  10749. else
  10750. {
  10751. ceErpTradeCell.AfterSaleState = 3;
  10752. }
  10753. bool needCyt = false;
  10754. if (dt != null)
  10755. {
  10756. if (dt.Rows.Count == 1)
  10757. {
  10758. bool isEnd = false;
  10759. foreach (DataRow dr in dt.Rows)
  10760. {
  10761. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10762. {
  10763. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10764. isEnd = true;
  10765. }
  10766. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10767. {
  10768. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10769. isEnd = true;
  10770. }
  10771. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10772. {
  10773. needCyt = true;
  10774. }
  10775. }
  10776. if (isEnd)
  10777. {
  10778. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10779. ceErpTradeCell.AfterSaleState = 4;
  10780. ceErpTradeCell.AfterSaleSupplierState = 1;
  10781. }
  10782. }
  10783. else
  10784. {
  10785. bool isAll = true;
  10786. foreach (DataRow dr in dt.Rows)
  10787. {
  10788. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10789. {
  10790. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10791. continue;
  10792. }
  10793. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10794. {
  10795. string path = "";
  10796. int OrgID = 0;
  10797. if (!Convert.IsDBNull(dr["OrgPath"]))
  10798. {
  10799. path = dr["OrgPath"].ToString();
  10800. }
  10801. if (!Convert.IsDBNull(dr["OrgID"]))
  10802. {
  10803. OrgID = Convert.ToInt32(dr["OrgID"]);
  10804. }
  10805. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10806. {
  10807. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10808. continue;
  10809. }
  10810. }
  10811. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10812. {
  10813. needCyt = true;
  10814. }
  10815. isAll = false;
  10816. }
  10817. if (isAll)
  10818. {
  10819. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10820. ceErpTradeCell.AfterSaleState = 4;
  10821. ceErpTradeCell.AfterSaleSupplierState = 1;
  10822. }
  10823. }
  10824. }
  10825. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10826. {
  10827. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10828. }
  10829. if (ceErpTradeCell.AfterSaleState == 4)
  10830. {
  10831. ApiVo apiVo = new ApiVo();
  10832. apiVo.orderNumber = ceErpTradeCell.ctid;
  10833. apiVo.actionName = "afterOver";
  10834. designHelper.API_WorkCore(apiVo); //afterOver
  10835. }
  10836. ceErpTradeCell.Update();
  10837. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10838. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10839. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10840. return true;
  10841. }
  10842. return false;
  10843. }
  10844. public void get_erp_wechatorder()
  10845. {
  10846. DataStruct dStruct = GetPostStruct();
  10847. List<string> lw = new List<string>();
  10848. string tid = GetPostString("tid");
  10849. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10850. string shopname = GetPostString("shopname");
  10851. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10852. string buyernick = GetPostString("buyer_nick");
  10853. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10854. string customer = GetPostString("customer");
  10855. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10856. string returndate1 = GetPostString("returndate1");
  10857. string returndate2 = GetPostString("returndate2");
  10858. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10859. if (dw.Length > 0) lw.Add(dw);
  10860. string finishDate1 = GetPostString("finishdate1");
  10861. string finishDate2 = GetPostString("finishdate2");
  10862. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10863. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10864. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10865. dStruct.Order = "created desc";
  10866. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10867. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10868. writeGridDataTableJson(dStruct.TotalCount, dt);
  10869. }
  10870. public void get_erp_wechatlist_sumprice()
  10871. {
  10872. DataStruct dStruct = GetPostStruct();
  10873. List<string> lw = new List<string>();
  10874. string tid = GetPostString("tid");
  10875. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10876. string shopname = GetPostString("shopname");
  10877. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10878. string buyernick = GetPostString("buyer_nick");
  10879. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10880. string customer = GetPostString("customer");
  10881. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10882. string returndate1 = GetPostString("returndate1");
  10883. string returndate2 = GetPostString("returndate2");
  10884. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10885. if (dw.Length > 0) lw.Add(dw);
  10886. string finishDate1 = GetPostString("finishdate1");
  10887. string finishDate2 = GetPostString("finishdate2");
  10888. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10889. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10890. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10891. string mainWhere = string.Join(" and ", lw.ToArray());
  10892. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10893. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10894. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10895. decimal total = 0;
  10896. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10897. {
  10898. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10899. }
  10900. var res = new
  10901. {
  10902. data = total
  10903. };
  10904. string ro_jsond = JsonConvert.SerializeObject(res);
  10905. returnSuccess(ro_jsond);
  10906. return;
  10907. }
  10908. public void get_erp_qr_waitdeliverylist()
  10909. {
  10910. DataStruct dStruct = GetPostStruct();
  10911. List<string> lw = new List<string>();
  10912. string tid = GetPostString("ctid");
  10913. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10914. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10915. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10916. var res_objz = new
  10917. {
  10918. restype = 1,
  10919. data = dt
  10920. };
  10921. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10922. returnSuccess(ro_jsonz);
  10923. }
  10924. public void get_erp_yield_list()
  10925. {
  10926. DataStruct dStruct = GetPostStruct();
  10927. List<string> lw = new List<string>();
  10928. string tid = GetPostString("ctid");
  10929. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10930. string shopname = GetPostString("shopname");
  10931. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10932. string buyernick = GetPostString("buyer_nick");
  10933. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10934. //if (tid.Length == 0 && buyernick.Length == 0)
  10935. //{
  10936. // lw.Add(string.Format("IsRefund<={0}", 1));
  10937. //}
  10938. string customer = GetPostString("customer");
  10939. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10940. string design = GetPostString("design");
  10941. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10942. string orderState = GetPostString("orderState");
  10943. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10944. string address = GetPostString("address");
  10945. 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));
  10946. string sellermemo = GetPostString("seller_memo");
  10947. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10948. string supplier = GetPostString("supplier");
  10949. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10950. string OrderArea = GetPostString("order_area");
  10951. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10952. string placedate1 = GetPostString("placedate1");
  10953. string placedate2 = GetPostString("placedate2");
  10954. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10955. if (fdw.Length > 0) lw.Add(fdw);
  10956. string price1 = GetPostString("price1");
  10957. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10958. string price2 = GetPostString("price2");
  10959. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10960. string unusualCon = GetPostString("unusualcon");
  10961. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10962. string posTag = CurrentUser.UserPost.Post.Code;
  10963. if (posTag == "Supplier")
  10964. {
  10965. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10966. }
  10967. lw.Add(string.Format("OrderState = 6 "));
  10968. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10969. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10970. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10971. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10972. writeGridDataTableJson(dStruct.TotalCount, dt);
  10973. }
  10974. public void change_erp_sup_state()
  10975. {
  10976. if (UrlPostParmsCheck("ctid"))
  10977. {
  10978. string ctid = GetPostString("ctid");
  10979. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10980. if (ceErpTradeCell != null)
  10981. {
  10982. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10983. if (ceErpTradeCellExtend == null)
  10984. {
  10985. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10986. ceErpTradeCellExtend.ctid = ctid;
  10987. ceErpTradeCellExtend.SupState = 1;
  10988. ceErpTradeCellExtend.Create();
  10989. }
  10990. else
  10991. {
  10992. ceErpTradeCellExtend.SupState = 1;
  10993. ceErpTradeCellExtend.Update();
  10994. }
  10995. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10996. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10997. return;
  10998. }
  10999. returnErrorMsg("找不到订单");
  11000. }
  11001. }
  11002. public void supplier_all_downs()
  11003. {
  11004. if (UrlPostParmsCheck("tids"))
  11005. {
  11006. string tids = GetPostString("tids");
  11007. if (tids != null && tids.Length > 0)
  11008. {
  11009. StringBuilder sql = new StringBuilder();
  11010. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11011. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11012. sql = new StringBuilder();
  11013. 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, "下载设计文件");
  11014. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11015. string[] list = tids.Split(',');
  11016. foreach (string ctid in list)
  11017. {
  11018. CeErpSukuraData.createInfo(ctid, 3);
  11019. }
  11020. designHelper.api_approveDesign(tids); //approveDesign
  11021. returnSuccessMsg("下载成功!");
  11022. return;
  11023. }
  11024. returnErrorMsg("下载订单更新失败");
  11025. }
  11026. }
  11027. public void uploaderFileSuccess()
  11028. {
  11029. if (UrlPostParmsCheck("fileName"))
  11030. {
  11031. string fileName = GetPostString("fileName");
  11032. ApiVo apiVo = new ApiVo();
  11033. apiVo.orderNumber = fileName;
  11034. apiVo.actionName = "finishDesign";
  11035. designHelper.API_WorkCore(apiVo);//finishDesign
  11036. returnSuccessMsg("");
  11037. }
  11038. }
  11039. public void get_sample2_order()
  11040. {
  11041. if (UrlPostParmsCheck("ctid"))
  11042. {
  11043. string ctid = GetPostString("ctid");
  11044. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11045. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11046. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11047. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11048. double total = 0.0;
  11049. double order_price = 0.0;
  11050. if (dt_bu.Rows.Count > 0)
  11051. {
  11052. foreach (DataRow dr in dt_bu.Rows)
  11053. {
  11054. total += Convert.ToDouble(dr["payment"]);
  11055. }
  11056. }
  11057. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11058. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11059. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11060. string tid = ctid.Replace("S_", "");
  11061. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11062. double paymant = 0.0;
  11063. if (entity != null)
  11064. {
  11065. paymant = entity.payment;
  11066. }
  11067. string return_reason = "";
  11068. if (dt_after != null && dt_after.Rows.Count > 0)
  11069. {
  11070. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11071. }
  11072. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11073. }
  11074. }
  11075. public void get_erp_design_status()
  11076. {
  11077. string designName = GetPostString("designName");
  11078. DataStruct dStruct = GetPostStruct();
  11079. if (designName.Length > 0)
  11080. {
  11081. 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";
  11082. sql_user += " and Name like '%" + designName + "%'";
  11083. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11084. List<string> ids_list = new List<string>();
  11085. if (user_table.Rows.Count > 0)
  11086. {
  11087. foreach (DataRow item in user_table.Rows)
  11088. {
  11089. ids_list.Add(item["id"].ToString());
  11090. string ids_s = item["TeamIds"].ToString();
  11091. if (ids_s.Length > 0)
  11092. {
  11093. ids_list.AddRange(ids_s.Split(','));
  11094. }
  11095. }
  11096. }
  11097. HashSet<string> set = new HashSet<string>(ids_list);
  11098. ids_list = set.ToList();
  11099. if (ids_list.Count > 0)
  11100. {
  11101. 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));
  11102. dStruct.MainWhere = sql;
  11103. DataTable dt = null;
  11104. dt = WebCache.GetData("view_ErpUser", dStruct);
  11105. writeGridDataTableJson(dStruct.TotalCount, dt);
  11106. }
  11107. }
  11108. }
  11109. public void change_erp_order_price()
  11110. {
  11111. string ctid = GetPostString("ctid");
  11112. double price = GetPostDouble("price");
  11113. if (ctid.Length > 0)
  11114. {
  11115. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11116. if (ceErpTradeCellExtend == null)
  11117. {
  11118. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11119. ceErpTradeCellExtend.ctid = ctid;
  11120. ceErpTradeCellExtend.payment_cyt = price;
  11121. ceErpTradeCellExtend.Create();
  11122. }
  11123. else
  11124. {
  11125. ceErpTradeCellExtend.payment_cyt = price;
  11126. ceErpTradeCellExtend.Update();
  11127. }
  11128. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11129. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11130. {
  11131. ceErpDataSendOrderInfo.isSync = false;
  11132. ceErpDataSendOrderInfo.Update();
  11133. }
  11134. if (ceErpDataSendOrderInfo == null)
  11135. {
  11136. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11137. ceErpDataSendOrderInfo.isSync = false;
  11138. ceErpDataSendOrderInfo.ctid = ctid;
  11139. ceErpDataSendOrderInfo.Create();
  11140. }
  11141. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11142. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11143. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11144. if (dth != null && dth.Rows.Count > 0)
  11145. {
  11146. dataSendOrderBean dataSendOrderBean = null;
  11147. foreach (DataRow item in dth.Rows)
  11148. {
  11149. try
  11150. {
  11151. dataSendOrderBean = new dataSendOrderBean();
  11152. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11153. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11154. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11155. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11156. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11157. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11158. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11159. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11160. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11161. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11162. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11163. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11164. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11165. if (result != null)
  11166. {
  11167. if ("0".Equals(result.errcode))
  11168. {
  11169. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11170. }
  11171. else
  11172. {
  11173. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11174. }
  11175. }
  11176. }
  11177. catch (Exception ex)
  11178. {
  11179. }
  11180. }
  11181. }
  11182. returnSuccessMsg("修改成功!");
  11183. return;
  11184. }
  11185. returnErrorMsg("找不到订单");
  11186. }
  11187. public void find_he_together()
  11188. {
  11189. string ctid = GetPostString("ctid");
  11190. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11191. List<string> list = new List<string>();
  11192. if (ceErpTradeCell != null)
  11193. {
  11194. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11195. {
  11196. 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);
  11197. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11198. if (table != null && table.Rows.Count > 0)
  11199. {
  11200. foreach (TableRow row in table.Rows)
  11201. {
  11202. }
  11203. }
  11204. }
  11205. }
  11206. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11207. }
  11208. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11209. {
  11210. //chy----19
  11211. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11212. //GD-CYT-----64
  11213. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11214. //ZHX----3
  11215. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11216. //JK----97
  11217. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11218. //ZT----70
  11219. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11220. //LHCY-----98
  11221. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11222. //XD-----90
  11223. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11224. //CYCY-----14
  11225. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11226. };
  11227. //其他改名
  11228. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11229. {
  11230. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11231. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11232. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11233. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11234. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11235. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11236. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11237. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11238. };
  11239. //不统计
  11240. List<int> no_suppliers = new List<int>()
  11241. {
  11242. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11243. };
  11244. //配件单
  11245. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11246. {
  11247. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11248. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11249. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11250. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11251. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11252. {"旗杆",new List<string>(){ "班旗" } },
  11253. {"牙签",new List<string>(){ "不干胶" } }
  11254. };
  11255. public void get_place_order_data()
  11256. {
  11257. string date1 = GetPostString("date1");
  11258. string date2 = GetPostString("date2");
  11259. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11260. DateTime start = DateTime.Parse(starttime);
  11261. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11262. DateTime end = DateTime.Parse(endtime);
  11263. if (date1 != null && date1.Length > 0)
  11264. {
  11265. DateTime dateTime = DateTime.Parse(date1);
  11266. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11267. start = DateTime.Parse(starttime);
  11268. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11269. end = DateTime.Parse(endtime);
  11270. }
  11271. if (date2 != null && date2.Length > 0)
  11272. {
  11273. DateTime dateTime = DateTime.Parse(date2);
  11274. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11275. end = DateTime.Parse(endtime);
  11276. }
  11277. 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);
  11278. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11279. //不干胶-----1,卡片-----29
  11280. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11281. foreach (DataRow row in data.Rows)
  11282. {
  11283. int productId = Convert.ToInt32(row["ProductId"]);
  11284. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11285. if (no_suppliers.Contains(supplierId))
  11286. {
  11287. continue;
  11288. }
  11289. string seller_memo = row["seller_memo"].ToString();
  11290. bool ispj = false;//是否配件单
  11291. bool isfirst = true;//第一个配
  11292. maps.Keys.ForEach(key =>
  11293. {
  11294. //备注包含配件
  11295. if (seller_memo.Contains(key) && isfirst)
  11296. {
  11297. List<string> list = maps[key];
  11298. ispj = true;
  11299. isfirst = false;
  11300. for (int i = 0; i < list.Count; i++)
  11301. {
  11302. if (seller_memo.Contains(list[i]))
  11303. {
  11304. ispj = false;
  11305. break;
  11306. }
  11307. }
  11308. }
  11309. });
  11310. if (ispj)
  11311. {
  11312. continue;
  11313. }
  11314. seller_memo = seller_memo.Replace("UV", "uv");
  11315. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11316. //吊牌归到卡片
  11317. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11318. seller_memo = seller_memo.Replace("卡套", "卡片");
  11319. seller_memo = seller_memo.Replace("封套", "卡片");
  11320. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11321. seller_memo = seller_memo.Replace("腰封", "卡片");
  11322. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11323. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11324. seller_memo = seller_memo.Replace("横幅", "条幅");
  11325. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11326. string map_key = "";
  11327. string type = "";
  11328. if (supplierMap.ContainsKey(supplierId))
  11329. {
  11330. foreach (var kvp in supplierMap[supplierId])
  11331. {
  11332. if (seller_memo.Contains(kvp.Key))
  11333. {
  11334. map_key = kvp.Value;
  11335. type = kvp.Value;
  11336. break;
  11337. }
  11338. }
  11339. }
  11340. if (map_key == "")
  11341. {
  11342. type = "其他";
  11343. map_key = "其他";
  11344. }
  11345. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11346. {
  11347. map_key = suppliers[supplierId];
  11348. }
  11349. if (supplierId == 70)
  11350. {
  11351. supplierId = 70;
  11352. }
  11353. map_key += "_" + row["SupplierName"].ToString();
  11354. Dictionary<string, int> map = null;
  11355. if (other_map.ContainsKey(map_key))
  11356. {
  11357. other_map.TryGetValue(map_key, out map);
  11358. }
  11359. else
  11360. {
  11361. map = new Dictionary<string, int>();
  11362. map.Add("dayDev", 0);//当天出货
  11363. map.Add("dayTotal", 0);//下单总数
  11364. map.Add("payTotal", 0);//500以上
  11365. map.Add("today", 0);//当天出货数量
  11366. map.Add("unusua", 0);//异常数
  11367. other_map.Add(map_key, map);
  11368. other_map.TryGetValue(map_key, out map);
  11369. }
  11370. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11371. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11372. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11373. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11374. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11375. {
  11376. map["dayTotal"]++;
  11377. if (supplierId == 97)
  11378. {
  11379. supplierId = 97;
  11380. }
  11381. }
  11382. if (Convert.ToDecimal(row["payment"]) >= 500)
  11383. {
  11384. map["payTotal"]++;
  11385. }
  11386. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11387. {
  11388. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11389. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11390. {
  11391. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11392. {
  11393. map["today"]++;
  11394. }
  11395. }
  11396. else
  11397. {
  11398. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11399. {
  11400. map["today"]++;
  11401. }
  11402. else
  11403. {
  11404. if (supplierId == 119)
  11405. {
  11406. Debug.WriteLine(row["seller_memo"].ToString());
  11407. }
  11408. }
  11409. }
  11410. }
  11411. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11412. {
  11413. map["unusua"]++;
  11414. }
  11415. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11416. //GD-CYT-----64
  11417. DateTime two = palceTimeStart.AddHours(14);
  11418. DateTime three = palceTimeStart.AddHours(15);
  11419. DateTime four = palceTimeStart.AddHours(16);
  11420. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11421. {
  11422. //下午四点前 500-1000
  11423. string count = row["ProductCount"].ToString();
  11424. if (count != null && count.Length > 0)
  11425. {
  11426. int productCount = commonHelper.getPlaceProductCount(count);
  11427. if (productCount >= 500 && productCount <= 1000)
  11428. {
  11429. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11430. {
  11431. map["dayDev"]++;
  11432. }
  11433. }
  11434. }
  11435. }
  11436. //UV
  11437. else if ("uv".Equals(type))
  11438. {
  11439. //ZT----70
  11440. //ZHX----3
  11441. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11442. {
  11443. map["dayDev"]++;
  11444. }
  11445. //JK----97
  11446. //HZX----105
  11447. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11448. {
  11449. map["dayDev"]++;
  11450. if (supplierId == 97)
  11451. {
  11452. supplierId = 97;
  11453. }
  11454. }
  11455. }
  11456. //帆布---52|条幅---27
  11457. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11458. {
  11459. //LHCY-----98
  11460. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11461. {
  11462. map["dayDev"]++;
  11463. }
  11464. }
  11465. //条幅
  11466. else if ("条幅".Equals(type))
  11467. {
  11468. //XD-----90
  11469. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11470. {
  11471. map["dayDev"]++;
  11472. }
  11473. }
  11474. //桌布
  11475. else if ("桌布".Equals(type))
  11476. {
  11477. //XD-----90
  11478. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11479. {
  11480. map["dayDev"]++;
  11481. }
  11482. }
  11483. //DL---10
  11484. //AYTW---119
  11485. //FS-CYT-DY ----80
  11486. //JK----97
  11487. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11488. {
  11489. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11490. {
  11491. map["dayDev"]++;
  11492. }
  11493. }
  11494. }
  11495. DataTable dt = new DataTable();
  11496. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11497. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11498. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11499. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11500. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11501. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11502. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11503. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11504. other_map.Keys.ForEach(key =>
  11505. {
  11506. DataRow dr = dt.NewRow();
  11507. Dictionary<string, int> map = other_map[key];
  11508. string[] key_list = key.Split('_');
  11509. dr[0] = key_list[0];
  11510. dr[1] = key_list[1];
  11511. if (key_list.Length > 2)
  11512. {
  11513. dr[1] += "(" + key_list[2] + ")";
  11514. }
  11515. dr[2] = map["dayTotal"];
  11516. dr[3] = map["payTotal"];
  11517. dr[4] = map["today"];
  11518. dr[5] = map["unusua"];
  11519. dr[6] = map["dayDev"];
  11520. double rate = 0.00;
  11521. if (map["dayDev"] > 0)
  11522. {
  11523. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11524. }
  11525. dr[7] = rate.ToString();
  11526. dt.Rows.Add(dr);
  11527. });
  11528. DataView dv = new DataView(dt);
  11529. dv.Sort = "SupplierName";
  11530. //dv.Sort = "AllOrder desc";
  11531. DataTable dtNew = dv.ToTable();
  11532. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11533. }
  11534. public void check_order_desing_info()
  11535. {
  11536. string ctid = GetPostString("ctid");
  11537. if (!string.IsNullOrEmpty(ctid))
  11538. {
  11539. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11540. if (ceErpTradeCell != null)
  11541. {
  11542. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11543. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11544. return;
  11545. }
  11546. returnErrorMsg("找不到订单");
  11547. return;
  11548. }
  11549. returnErrorMsg("找不到订单");
  11550. }
  11551. public void get_timeout_detail()
  11552. {
  11553. string poscode = CurrentUser.UserPost.Post.Code;
  11554. DataStruct dStruct = GetPostStruct();
  11555. List<string> lw = new List<string>();
  11556. string id = GetPostString("id");
  11557. string pay_date1 = GetPostString("pay_date1");
  11558. string pay_date2 = GetPostString("pay_date2");
  11559. int type = GetPostInt("type");
  11560. if (type == 0)
  11561. {
  11562. if (pay_date1.Length > 0)
  11563. {
  11564. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11565. }
  11566. if (pay_date2.Length > 0)
  11567. {
  11568. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11569. }
  11570. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11571. }
  11572. if (type == 1)
  11573. {
  11574. if (pay_date1.Length > 0)
  11575. {
  11576. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11577. }
  11578. if (pay_date2.Length > 0)
  11579. {
  11580. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11581. }
  11582. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11583. }
  11584. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11585. DataTable dt = null;
  11586. dt = WebCache.GetData("view_orderlist", dStruct);
  11587. writeGridDataTableJson(dStruct.TotalCount, dt);
  11588. }
  11589. public void saveUrgentChargePrice()
  11590. {
  11591. string ctid = GetPostString("ctid");
  11592. if (!string.IsNullOrEmpty(ctid))
  11593. {
  11594. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11595. if (ceErpTradeCell != null)
  11596. {
  11597. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11598. if (prices <= 100)
  11599. {
  11600. returnErrorMsg("此订单金额不足100元,无法加急。");
  11601. return;
  11602. }
  11603. double price = GetPostDouble("price");
  11604. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11605. if (ceErpTradeCellExtend == null)
  11606. {
  11607. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11608. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11609. }
  11610. ceErpTradeCellExtend.urgentCharge = price;
  11611. if (ceErpTradeCellExtend.ID > 0)
  11612. {
  11613. ceErpTradeCellExtend.Update();
  11614. }
  11615. else
  11616. {
  11617. ceErpTradeCellExtend.Save();
  11618. }
  11619. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11620. returnSuccessMsg("修改成功!");
  11621. return;
  11622. }
  11623. returnErrorMsg("找不到订单");
  11624. return;
  11625. }
  11626. returnErrorMsg("找不到订单");
  11627. }
  11628. public void finish_erp_order()
  11629. {
  11630. string ctid = GetPostString("ctid");
  11631. if (!string.IsNullOrEmpty(ctid))
  11632. {
  11633. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11634. {
  11635. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11636. if (ceErpTradeCell != null)
  11637. {
  11638. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11639. ceErpTradeCell.Update();
  11640. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11641. returnSuccessMsg("修改成功!");
  11642. return;
  11643. }
  11644. }
  11645. }
  11646. returnErrorMsg("找不到订单");
  11647. }
  11648. public void get_trade_order_list()
  11649. {
  11650. string tid = GetPostString("tid");
  11651. if (!string.IsNullOrEmpty(tid))
  11652. {
  11653. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11654. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11655. writeGridDataTableJson(data.Rows.Count, data);
  11656. return;
  11657. }
  11658. returnErrorMsg("找不到订单");
  11659. }
  11660. public void save_cell_spu()
  11661. {
  11662. string ctid = GetPostString("ctid");
  11663. string spu_id = GetPostString("spu_id");
  11664. if (!string.IsNullOrEmpty(ctid))
  11665. {
  11666. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11667. if (ceErpTradeCellExtend == null)
  11668. {
  11669. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11670. ceErpTradeCellExtend.ctid = ctid;
  11671. }
  11672. ceErpTradeCellExtend.spu_id = spu_id;
  11673. if (!string.IsNullOrEmpty(spu_id))
  11674. {
  11675. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11676. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11677. }
  11678. if (ceErpTradeCellExtend.ID == 0)
  11679. {
  11680. ceErpTradeCellExtend.Create();
  11681. }
  11682. else
  11683. {
  11684. ceErpTradeCellExtend.Update();
  11685. }
  11686. returnSuccessMsg("修改成功!");
  11687. return;
  11688. }
  11689. returnErrorMsg("找不到订单");
  11690. }
  11691. public void change_express_info()
  11692. {
  11693. string ctid = GetPostString("ctid");
  11694. string transNo = GetPostString("transNo");
  11695. string transCom = GetPostString("transCom");
  11696. if (!string.IsNullOrEmpty(ctid))
  11697. {
  11698. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11699. if (ceErpTradeCellExtend == null)
  11700. {
  11701. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11702. ceErpTradeCellExtend.ctid = ctid;
  11703. }
  11704. ceErpTradeCellExtend.modExpressNo = transNo;
  11705. ceErpTradeCellExtend.modExpressCom = transCom;
  11706. ceErpTradeCellExtend.readMod = 2;
  11707. if (ceErpTradeCellExtend.ID == 0)
  11708. {
  11709. ceErpTradeCellExtend.Create();
  11710. }
  11711. else
  11712. {
  11713. ceErpTradeCellExtend.Update();
  11714. }
  11715. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11716. returnSuccessMsg("修改成功!");
  11717. return;
  11718. }
  11719. returnErrorMsg("找不到订单");
  11720. }
  11721. public void get_change_express_list()
  11722. {
  11723. DataStruct dStruct = GetPostStruct();
  11724. List<string> lw = new List<string>();
  11725. int st = 2;
  11726. string tid = GetPostString("ctid");
  11727. if (tid.Length > 0)
  11728. {
  11729. string select_tid = getTidByCtid(tid);
  11730. lw.Add(string.Format("tid='{0}'", select_tid));
  11731. }
  11732. string shopname = GetPostString("shopname");
  11733. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11734. string buyernick = GetPostString("buyer_nick");
  11735. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11736. string sellermemo = GetPostString("seller_memo");
  11737. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11738. string supplier = GetPostString("supplier");
  11739. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11740. string customer = GetPostString("customer");
  11741. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11742. string design = GetPostString("design");
  11743. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11744. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11745. string poscode = CurrentUser.UserPost.Post.Code;
  11746. if (poscode != "SysAdmin")
  11747. {
  11748. string shopid = CurrentUser.User.pemShop;
  11749. lw.Add(string.Format("shopId in ({0})", shopid));
  11750. }
  11751. lw.Add("readMod = 2");
  11752. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11753. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11754. writeGridDataTableJson(dStruct.TotalCount, dt);
  11755. }
  11756. public void deal_express_complete()
  11757. {
  11758. string ctid = GetPostString("ctid");
  11759. if (!string.IsNullOrEmpty(ctid))
  11760. {
  11761. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11762. if (ceErpTradeCellExtend == null)
  11763. {
  11764. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11765. ceErpTradeCellExtend.ctid = ctid;
  11766. }
  11767. ceErpTradeCellExtend.readMod = 1;
  11768. if (ceErpTradeCellExtend.ID == 0)
  11769. {
  11770. ceErpTradeCellExtend.Create();
  11771. }
  11772. else
  11773. {
  11774. ceErpTradeCellExtend.Update();
  11775. }
  11776. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11777. returnSuccessMsg("修改成功!");
  11778. return;
  11779. }
  11780. returnErrorMsg("找不到订单");
  11781. }
  11782. public void aftersale_return_visit()
  11783. {
  11784. string ctid = GetPostString("ctid");
  11785. if (!string.IsNullOrEmpty(ctid))
  11786. {
  11787. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11788. if (ceErpTradeCellExtend == null)
  11789. {
  11790. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11791. ceErpTradeCellExtend.ctid = ctid;
  11792. }
  11793. ceErpTradeCellExtend.returnVisit = 1;
  11794. if (ceErpTradeCellExtend.ID == 0)
  11795. {
  11796. ceErpTradeCellExtend.Create();
  11797. }
  11798. else
  11799. {
  11800. ceErpTradeCellExtend.Update();
  11801. }
  11802. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11803. if (ceErpTradeAfterSaleExtend != null)
  11804. {
  11805. ceErpTradeAfterSaleExtend.TextResult = "";
  11806. ceErpTradeAfterSaleExtend.Update();
  11807. }
  11808. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11809. returnSuccessMsg("修改成功!");
  11810. return;
  11811. }
  11812. returnErrorMsg("找不到订单");
  11813. }
  11814. public void orderPlaceInfo()
  11815. {
  11816. string ctids = GetPostString("ctids");
  11817. string[] list = ctids.Split(',');
  11818. foreach (string ctid in list)
  11819. {
  11820. CeErpSukuraData.createInfo(ctid, 3);
  11821. }
  11822. StringBuilder sql = new StringBuilder();
  11823. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11824. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11825. designHelper.api_approveDesign(ctids); //approveDesign
  11826. returnSuccessMsg("");
  11827. }
  11828. public void get_issue_list()
  11829. {
  11830. DataStruct dStruct = GetPostStruct();
  11831. List<string> lw = new List<string>();
  11832. int st = 2;
  11833. string tid = GetPostString("ctid");
  11834. if (tid.Length > 0)
  11835. {
  11836. string select_tid = getTidByCtid(tid);
  11837. lw.Add(string.Format("tid='{0}'", select_tid));
  11838. }
  11839. string shopname = GetPostString("shopname");
  11840. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11841. string buyernick = GetPostString("buyer_nick");
  11842. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11843. string sellermemo = GetPostString("seller_memo");
  11844. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11845. string supplier = GetPostString("supplier");
  11846. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11847. string customer = GetPostString("customer");
  11848. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11849. string design = GetPostString("design");
  11850. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11851. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11852. string poscode = CurrentUser.UserPost.Post.Code;
  11853. if (poscode != "SysAdmin")
  11854. {
  11855. string shopid = CurrentUser.User.pemShop;
  11856. lw.Add(string.Format("shopId in ({0})", shopid));
  11857. }
  11858. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11859. {
  11860. lw.Add("IssueState = 1");
  11861. }
  11862. lw.Add("IssueState > 0");
  11863. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11864. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11865. writeGridDataTableJson(dStruct.TotalCount, dt);
  11866. }
  11867. public void saveIssueContent()
  11868. {
  11869. string ctid = GetPostString("ctid");
  11870. if (!string.IsNullOrEmpty(ctid))
  11871. {
  11872. string content = GetPostString("content");
  11873. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11874. if (ceErpTradeAfterSaleExtend == null)
  11875. {
  11876. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11877. ceErpTradeAfterSaleExtend.tid = ctid;
  11878. }
  11879. ceErpTradeAfterSaleExtend.IssueContent = content;
  11880. ceErpTradeAfterSaleExtend.IssueState = 1;
  11881. if (ceErpTradeAfterSaleExtend.ID > 0)
  11882. {
  11883. ceErpTradeAfterSaleExtend.Update();
  11884. }
  11885. else
  11886. {
  11887. ceErpTradeAfterSaleExtend.Create();
  11888. }
  11889. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11890. returnSuccessMsg("添加成功!");
  11891. return;
  11892. }
  11893. returnErrorMsg("找不到订单");
  11894. }
  11895. public void dealIssueContent()
  11896. {
  11897. string ctid = GetPostString("ctid");
  11898. if (!string.IsNullOrEmpty(ctid))
  11899. {
  11900. string content = GetPostString("content");
  11901. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11902. if (ceErpTradeAfterSaleExtend != null)
  11903. {
  11904. ceErpTradeAfterSaleExtend.IssueState = 2;
  11905. ceErpTradeAfterSaleExtend.Update();
  11906. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11907. returnSuccessMsg("修改完成!");
  11908. return;
  11909. }
  11910. }
  11911. returnErrorMsg("找不到订单");
  11912. }
  11913. public void set_tid_attachments()
  11914. {
  11915. string tid = GetPostString("tid");
  11916. string atta = GetPostString("atta");
  11917. if (!string.IsNullOrEmpty(tid))
  11918. {
  11919. if (string.IsNullOrEmpty(atta))
  11920. {
  11921. returnErrorMsg("文件地址为空");
  11922. return;
  11923. }
  11924. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11925. if (ceErpTradeCell != null)
  11926. {
  11927. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11928. if (ceErpTrade == null)
  11929. {
  11930. returnErrorMsg("找不到订单");
  11931. return;
  11932. }
  11933. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11934. bool isSend = false;
  11935. if (dt != null && dt.Rows.Count > 0)
  11936. {
  11937. foreach (DataRow row in dt.Rows)
  11938. {
  11939. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11940. {
  11941. isSend = true;
  11942. }
  11943. }
  11944. if (isSend)
  11945. {
  11946. returnErrorMsg("已发货无法修改");
  11947. return;
  11948. }
  11949. ceErpTrade.Attachments = atta;
  11950. ceErpTrade.Update();
  11951. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  11952. returnSuccessMsg("上传成功!");
  11953. return;
  11954. }
  11955. }
  11956. }
  11957. returnErrorMsg("找不到订单");
  11958. }
  11959. public void get_tid_attachments()
  11960. {
  11961. string tid = GetPostString("tid");
  11962. if (!string.IsNullOrEmpty(tid))
  11963. {
  11964. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11965. if (ceErpTradeCell != null)
  11966. {
  11967. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11968. if (ceErpTrade == null)
  11969. {
  11970. returnErrorMsg("找不到订单");
  11971. return;
  11972. }
  11973. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11974. return;
  11975. }
  11976. }
  11977. returnErrorMsg("找不到订单");
  11978. }
  11979. public void check_erp_sameorders()
  11980. {
  11981. if (UrlPostParmsCheck("ctid"))
  11982. {
  11983. string eid = GetPostString("ctid");
  11984. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11985. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11986. if (entity != null && ceErpTrade != null)
  11987. {
  11988. if (entity.OrderState > 6)
  11989. {
  11990. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11991. return;
  11992. }
  11993. DataTable dt = getSameOrderList(entity, ceErpTrade);
  11994. List<string> ids = new List<string>();
  11995. if (dt != null && dt.Rows.Count > 1)
  11996. {
  11997. bool needhe = true;
  11998. foreach (DataRow dr in dt.Rows)
  11999. {
  12000. ids.Add("'" + dr["ctid"] + "'");
  12001. /* //备注有合包
  12002. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12003. {
  12004. needhe = true;
  12005. }
  12006. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12007. {
  12008. needhe = true;
  12009. }
  12010. //顺丰快递
  12011. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12012. {
  12013. needhe = true;
  12014. }*/
  12015. }
  12016. if (!needhe)
  12017. {
  12018. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12019. return;
  12020. }
  12021. StringBuilder sql = new StringBuilder();
  12022. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12023. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12024. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12025. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12026. foreach (DataRow dr in dt.Rows)
  12027. {
  12028. dr["dstate"] = 0;
  12029. dr["dnumber"] = 0;
  12030. foreach (DataRow row in dt1.Rows)
  12031. {
  12032. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12033. {
  12034. dr["dstate"] = 2;
  12035. dr["default"] = 1;
  12036. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12037. }
  12038. }
  12039. if (eid.Equals(dr["ctid"].ToString()))
  12040. {
  12041. dr["dstate"] = 1;
  12042. dr["default"] = 1;
  12043. }
  12044. }
  12045. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12046. return;
  12047. }
  12048. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12049. return;
  12050. }
  12051. returnErrorMsg("未找到订单");
  12052. return;
  12053. }
  12054. returnErrorMsg("缺少必要的参数");
  12055. }
  12056. private DataTable getSameOrderList(CeErpTradeCell entity, CeErpTrade ceErpTrade)
  12057. {
  12058. StringBuilder sql = new StringBuilder();
  12059. 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);
  12060. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12061. {
  12062. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12063. }
  12064. else
  12065. {
  12066. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12067. }
  12068. DataTable dt = null;
  12069. try
  12070. {
  12071. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12072. StringBuilder timerSql = new StringBuilder();
  12073. timerSql.AppendFormat("SELECT * FROM CE_ErpSupplierProductTime WHERE supplierId={0}", entity.SupplierId);
  12074. DataTable timerTable = DbHelper.DbConn.ExecuteDataset(timerSql.ToString()).Tables[0];
  12075. //没有设置时间则不判断
  12076. if (timerTable == null || timerTable.Rows.Count == 0)
  12077. {
  12078. return dt;
  12079. }
  12080. dt.Columns.Add(new DataColumn("default", typeof(int)));
  12081. foreach (DataRow dr in dt.Rows)
  12082. {
  12083. dr["default"] = 0;
  12084. //当前订单
  12085. if (entity.ctid.Equals(dr["ctid"]))
  12086. {
  12087. continue;
  12088. }
  12089. //已经标记过发货
  12090. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(dr["ctid"].ToString());
  12091. if (ceErpDeliverMark != null)
  12092. {
  12093. dr["default"] = 1;
  12094. continue;
  12095. }
  12096. string[] productIds = null;
  12097. string productId = dr["productId"].ToString();
  12098. string finishPlaceTime = dr["FinishPlaceTime"].ToString();
  12099. string sellmer_mome = dr["seller_memo"].ToString();
  12100. string txtCount = dr["ProductCount"].ToString();
  12101. DateTime placeTime = DateTime.Now;
  12102. //没有品类
  12103. if (string.IsNullOrEmpty(productId) || "0".Equals(productId))
  12104. {
  12105. continue;
  12106. }
  12107. if (string.IsNullOrEmpty(finishPlaceTime))
  12108. {
  12109. continue;
  12110. }
  12111. placeTime = DateTime.Parse(finishPlaceTime);
  12112. foreach (DataRow row in timerTable.Rows)
  12113. {
  12114. string txtIds = row["productId"].ToString();
  12115. string[] crafts = { };
  12116. int count = Convert.ToUInt16(row["quantity"]);
  12117. if (string.IsNullOrEmpty(txtIds))
  12118. {
  12119. continue;
  12120. }
  12121. if (count > 0)
  12122. {
  12123. int quantity = commonHelper.handleProductCount(txtCount, true);
  12124. //订单数量大于写入的数量则跳过
  12125. if (quantity > count)
  12126. {
  12127. continue;
  12128. }
  12129. }
  12130. productIds = txtIds.Split(',');
  12131. if (productIds.Contains(productId))
  12132. {
  12133. string textCraft = row["craft"].ToString();
  12134. textCraft = textCraft.Replace(",", ",");//统一格式
  12135. if (!string.IsNullOrEmpty(textCraft))
  12136. {
  12137. crafts = textCraft.Split(',');
  12138. }
  12139. if (crafts.Length > 0)
  12140. {
  12141. bool isinCraft = false;
  12142. for (int i = 0; i < crafts.Length; i++)
  12143. {
  12144. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12145. {
  12146. isinCraft = true;
  12147. break;
  12148. }
  12149. }
  12150. //有写工艺并且备注中没匹配中则跳过
  12151. if (!isinCraft)
  12152. {
  12153. continue;
  12154. }
  12155. }
  12156. DateTime deadLine = DateTime.Parse(row["deadLine"].ToString());
  12157. DateTime dayDeadLine = DateTime.Parse(row["dayDeadLine"].ToString());
  12158. int sendDay = Convert.ToInt16(row["sendDay"]);
  12159. //下单时间小于当日发货时间则不用判断
  12160. //当日发货必须发货
  12161. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12162. {
  12163. dr["default"] = 1;
  12164. break;
  12165. }
  12166. //在截稿时间之前下单的可以减去一天时间
  12167. /*if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12168. {
  12169. sendDay = Math.Max(1, sendDay - 1);
  12170. }
  12171. DateTime sendtime = placeTime.AddDays(sendDay);
  12172. //判断有没有到发货日期
  12173. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) > 0)
  12174. {
  12175. break;
  12176. }*/
  12177. }
  12178. }
  12179. }
  12180. }
  12181. catch (Exception ex)
  12182. {
  12183. }
  12184. return dt;
  12185. }
  12186. public void get_mark_number()
  12187. {
  12188. string eid = GetPostString("ctid");
  12189. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12190. if (entity != null)
  12191. {
  12192. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12193. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12194. int current = 1;
  12195. if (ceErpDeliverMark == null)
  12196. {
  12197. DataTable dt = getSameOrderList(entity, ceErpTrade);
  12198. List<string> ids = new List<string>();
  12199. if (dt != null && dt.Rows.Count > 1)
  12200. {
  12201. foreach (DataRow dr in dt.Rows)
  12202. {
  12203. ids.Add("'" + dr["ctid"] + "'");
  12204. }
  12205. //查询已有的编号
  12206. StringBuilder sql = new StringBuilder();
  12207. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12208. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12209. if (dt1 == null || dt1.Rows.Count == 0)
  12210. {
  12211. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12212. List<int> list_number = new List<int>();
  12213. foreach (DataRow row in numbers.Rows)
  12214. {
  12215. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12216. }
  12217. //查询空余编号
  12218. for (int i = 0; i < list_number.Count + 2; i++)
  12219. {
  12220. if (!list_number.Contains(current))
  12221. {
  12222. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12223. //防止查询过程中有新数据生成
  12224. if (ceErpDeliverMark1 == null)
  12225. {
  12226. break;
  12227. }
  12228. }
  12229. current++;
  12230. }
  12231. }
  12232. else
  12233. {
  12234. foreach (DataRow row in dt1.Rows)
  12235. {
  12236. current = Convert.ToInt32(row["markNumber"]);
  12237. }
  12238. }
  12239. ceErpDeliverMark = new CeErpDeliverMark();
  12240. ceErpDeliverMark.ctid = eid;
  12241. ceErpDeliverMark.createtime = DateTime.Now;
  12242. if (ceErpTrade != null)
  12243. {
  12244. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12245. }
  12246. ceErpDeliverMark.markNumber = current;
  12247. ceErpDeliverMark.Create();
  12248. }
  12249. }
  12250. else
  12251. {
  12252. current = ceErpDeliverMark.markNumber;
  12253. }
  12254. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12255. return;
  12256. }
  12257. }
  12258. public void aftersaleCytSend()
  12259. {
  12260. string ctid = GetPostString("ctid");
  12261. if (!string.IsNullOrEmpty(ctid))
  12262. {
  12263. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12264. if (ceErpTradeCell != null)
  12265. {
  12266. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12267. }
  12268. returnSuccessMsg("推送成功");
  12269. return;
  12270. }
  12271. returnErrorMsg("缺少必要的参数");
  12272. }
  12273. public void packOrderInfo()
  12274. {
  12275. string ctids = GetPostString("ctids");
  12276. if (!string.IsNullOrEmpty(ctids))
  12277. {
  12278. string[] ctid_list = ctids.Split(',');
  12279. if (ctid_list.Length > 20)
  12280. {
  12281. returnErrorMsg("单次下载次数不能超过20个");
  12282. return;
  12283. }
  12284. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12285. StringBuilder sql = new StringBuilder();
  12286. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12287. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12288. int supplierId = 0;
  12289. StringBuilder insterSql = new StringBuilder();
  12290. for (int i = 0; i < dt.Rows.Count; i++)
  12291. {
  12292. DataRow row = dt.Rows[i];
  12293. if (i == 0)
  12294. {
  12295. supplierId = Convert.ToInt32(row["SupplierId"]);
  12296. }
  12297. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12298. {
  12299. returnErrorMsg("同车间的订单才能一起打包");
  12300. return;
  12301. }
  12302. int orderState = Convert.ToInt32(row["OrderState"]);
  12303. if (orderState != 5)
  12304. {
  12305. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12306. return;
  12307. }
  12308. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12309. }
  12310. CeErpPackData ceErpPackData = new CeErpPackData();
  12311. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip";
  12312. ceErpPackData.supplierId = supplierId;
  12313. ceErpPackData.createtime = DateTime.Now;
  12314. ceErpPackData.createBy = CurrentUser.UserID;
  12315. ceErpPackData.createName = CurrentUser.UserName;
  12316. ceErpPackData.Create();
  12317. if (ceErpPackData.ID > 0)
  12318. {
  12319. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12320. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12321. }
  12322. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12323. returnSuccessMsg("打包成功");
  12324. return;
  12325. }
  12326. returnErrorMsg("缺少必要的参数");
  12327. }
  12328. public void rePackOrderInfo()
  12329. {
  12330. string id = GetPostString("id");
  12331. if (!string.IsNullOrEmpty(id))
  12332. {
  12333. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12334. if (ceErpPackData == null)
  12335. {
  12336. returnSuccessMsg("查无数据");
  12337. return;
  12338. }
  12339. ceErpPackData.upStatus = 0;
  12340. ceErpPackData.message = "";
  12341. ceErpPackData.Update();
  12342. returnSuccessMsg("打包成功");
  12343. return;
  12344. }
  12345. returnErrorMsg("缺少必要的参数");
  12346. }
  12347. public void addPackDownNum()
  12348. {
  12349. string id = GetPostString("id");
  12350. if (!string.IsNullOrEmpty(id))
  12351. {
  12352. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12353. returnSuccessMsg("下载成功");
  12354. return;
  12355. }
  12356. returnErrorMsg("缺少必要的参数");
  12357. }
  12358. public void get_pack_list()
  12359. {
  12360. DataStruct dStruct = GetPostStruct();
  12361. List<string> lw = new List<string>();
  12362. string supplier = GetPostString("supplier");
  12363. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12364. string posTag = CurrentUser.UserPost.Post.Code;
  12365. if (posTag == "Supplier")
  12366. {
  12367. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12368. }
  12369. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12370. dStruct.Order = "createtime desc";
  12371. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12372. writeGridDataTableJson(dStruct.TotalCount, dt);
  12373. }
  12374. public void get_supplier_product_time_list()
  12375. {
  12376. DataStruct dStruct = GetPostStruct();
  12377. List<string> lw = new List<string>();
  12378. string supplier = GetPostString("supplier");
  12379. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12380. string posTag = CurrentUser.UserPost.Post.Code;
  12381. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12382. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12383. writeGridDataTableJson(dStruct.TotalCount, dt);
  12384. }
  12385. public void saveSupplierProductTime()
  12386. {
  12387. string productId = GetPostString("productId");
  12388. if (string.IsNullOrEmpty(productId))
  12389. {
  12390. returnErrorMsg("缺少必要的参数");
  12391. return;
  12392. }
  12393. string productName = GetPostString("productName");
  12394. int supplierId = GetPostInt("supplierId");
  12395. if (supplierId == 0)
  12396. {
  12397. returnErrorMsg("缺少必要的参数");
  12398. return;
  12399. }
  12400. int quantity = GetPostInt("quantity");
  12401. int sendDay = GetPostInt("sendTime");
  12402. string supplierName = GetPostString("supplierName");
  12403. string craft = GetPostString("craft");
  12404. string deadLine = GetPostString("deadLine");
  12405. string dayDeadLine = GetPostString("dayDeadLine");
  12406. try
  12407. {
  12408. int eid = GetPostInt("eid");
  12409. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12410. if (ceErpSupplierProductTime == null)
  12411. {
  12412. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12413. }
  12414. ceErpSupplierProductTime.productId = productId;
  12415. ceErpSupplierProductTime.productName = productName;
  12416. ceErpSupplierProductTime.supplierId = supplierId;
  12417. ceErpSupplierProductTime.supplierName = supplierName;
  12418. ceErpSupplierProductTime.craft = craft;
  12419. ceErpSupplierProductTime.sendDay = sendDay;
  12420. ceErpSupplierProductTime.quantity = quantity;
  12421. if (!string.IsNullOrEmpty(deadLine))
  12422. {
  12423. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12424. }
  12425. if (!string.IsNullOrEmpty(dayDeadLine))
  12426. {
  12427. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12428. }
  12429. if (ceErpSupplierProductTime.ID == 0)
  12430. {
  12431. ceErpSupplierProductTime.Save();
  12432. }
  12433. else
  12434. {
  12435. ceErpSupplierProductTime.Update();
  12436. }
  12437. }
  12438. catch (Exception e)
  12439. {
  12440. }
  12441. returnSuccessMsg("保存成功");
  12442. return;
  12443. }
  12444. public void delSupplierProductTime()
  12445. {
  12446. int eid = GetPostInt("eid");
  12447. if (eid > 0)
  12448. {
  12449. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12450. if (ceErpSupplierProductTime == null)
  12451. {
  12452. returnErrorMsg("查无数据");
  12453. return;
  12454. }
  12455. ceErpSupplierProductTime.Delete();
  12456. returnSuccessMsg("保存成功");
  12457. return;
  12458. }
  12459. returnErrorMsg("缺少必要的参数");
  12460. }
  12461. public void getExpressInfo()
  12462. {
  12463. string ctid = GetPostString("ctid");
  12464. if (!string.IsNullOrEmpty(ctid))
  12465. {
  12466. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12467. if (ceErpTradeCell != null)
  12468. {
  12469. string outSid = ceErpTradeCell.OutSid;
  12470. if (outSid.Length > 0)
  12471. {
  12472. 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);
  12473. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12474. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12475. return;
  12476. }
  12477. }
  12478. returnErrorMsg("查无记录");
  12479. return;
  12480. }
  12481. returnErrorMsg("缺少必要的参数");
  12482. }
  12483. public void getExpressPostData()
  12484. {
  12485. string express = GetPostString("express");
  12486. if (!string.IsNullOrEmpty(express))
  12487. {
  12488. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12489. if (ceErpExpressInfo != null)
  12490. {
  12491. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12492. return;
  12493. }
  12494. }
  12495. returnErrorMsg("缺少必要的参数");
  12496. }
  12497. }
  12498. }