sync.order.cs 635 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. namespace SiteCore.Handler
  48. {
  49. public partial class sync
  50. {
  51. public void get_erp_orderlist()
  52. {
  53. string poscode = CurrentUser.UserPost.Post.Code;
  54. DataStruct dStruct = GetPostStruct();
  55. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\店铺.xlsx");
  56. //apiHelper.Api_SyncOrderByTime("598825");
  57. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  58. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  59. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  60. //banniuApiHelper.sendLogisticsInfo(null);
  61. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  62. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  63. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  64. //int sid = commonHelper.autoDistributeToSupplier(entity);
  65. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  66. //tmcHelper.Api_TmcTradeMsg("{\r\n \"content\": {\r\n \"businessType\": \"GUARANTEE\",\r\n \"buyerMemo\": \"\",\r\n \"consolidateType\": \"\",\r\n \"createTime\": 1744882656361,\r\n \"deliveryType\": \"OFFLINE\",\r\n \"discountFee\": 0.0,\r\n \"flag\": \"NONE\",\r\n \"latestDeliveryTime\": 1744882656361,\r\n \"lines\": [\r\n {\r\n \"mark2\": [],\r\n \"num\": 4,\r\n \"outerId\": \"\",\r\n \"payment\": 60.0,\r\n \"picUrl\": \"https://img.alicdn.com/bao/uploaded/i4/2209226402185/O1CN011Zh53V1S0mQKgHJyF_!!4611686018427382153-0-item_pic.jpg\",\r\n \"platServiceFee\": 0.0,\r\n \"price\": 10.0,\r\n \"refOlId\": \"1111122222333338942\",\r\n \"refSkuId\": \"0\",\r\n \"refSpuId\": \"908453435193\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellPrice\": 10.0,\r\n \"singleFee\": 10.0,\r\n \"standards\": \"测试内部\",\r\n \"status\": \"NOT_SHIPPED\",\r\n \"title\": \"【老客户订单2】测试老客户订单内部\",\r\n \"totalFee\": 60.0,\r\n \"totalPrice\": 60.0,\r\n \"totalSellPrice\": 60.0\r\n }\r\n ],\r\n \"logisticsOrderNo\": \"\",\r\n \"mark2\": [],\r\n \"modifyTime\": 1744882656361,\r\n \"openBuyerId\": \"AAG1RHraABkUZRPgSx3g7Eam\",\r\n \"openBuyerNick\": \"0**\",\r\n \"openSellerNick\": \"海角七旗舰店\",\r\n \"orderSource\": \"SYNC\",\r\n \"orderTime\": 1744882656361,\r\n \"payTime\": 1744882656361,\r\n \"payment\": 100.0,\r\n \"platServiceFee\": 0.0,\r\n \"posCode\": \"HJQ\",\r\n \"posId\": 663281,\r\n \"postFee\": 0.0,\r\n \"props\": {\r\n \"payType\": \"ALI_PAY\",\r\n \"govSubsidyAmount\": 0\r\n },\r\n \"receivedPayment\": 0.0,\r\n \"receiverCity\": \"龙岩市\",\r\n \"receiverCountry\": \"中国\",\r\n \"receiverDistrict\": \"新罗区\",\r\n \"receiverId\": \"d1b65912ef886228ac4ada4b65055e52$\",\r\n \"receiverState\": \"福建省\",\r\n \"receiverTown\": \"西陂街道\",\r\n \"refOid\": \"1111122222333338942\",\r\n \"refType\": \"TB\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellerMemo\": \"\",\r\n \"serviceFee\": 0.0,\r\n \"status\": \"NOT_SHIPPED\",\r\n \"totalFee\": 100.0,\r\n \"totalPrice\": 100.0,\r\n \"totalSellPrice\": 100.0,\r\n \"type\": \"SALE\"\r\n }\r\n}");
  67. //refundTmcHelper.Api_TmcRefundMsg("{\"content\":{\"afterStatus\":\"SUCCESS\",\"createTime\":1735287446000,\"desc\":\"\",\"interceptInvestor\":\"NONE\",\"interceptStatus\":\"NONE\",\"interceptType\":\"NONE\",\"lines\":[{\"num\":2,\"outerId\":\"\",\"price\":50.0,\"refAid\":\"313001208133750610\",\"refAlId\":\"313001208133750610\",\"refBoughtSkuId\":\"\",\"refOid\":\"4181722704291751006\",\"refOlId\":\"4181722704291751006\",\"refSkuId\":\"0\",\"refSpuId\":\"865893808768\",\"refundFee\":98.86,\"refundStatus\":\"SUCCESS\",\"title\":\"新年会抽奖券定制2025蛇年公司活动正副可撕代金券打印纪念票根奖品兑换尾牙晚宴邀请卡号码牌创意入场券设计\",\"totalFee\":98.86,\"type\":1}],\"logisticsCompany\":\"\",\"logisticsOrderNo\":\"\",\"mark2\":[],\"openBuyerNick\":\"0**\",\"openSellerNick\":\"万慕办公旗舰店\",\"posCode\":\"wanmu\",\"posId\":598798,\"reason\":\"订单信息拍错(规格/尺码/颜色等)\",\"receiverCity\":\"\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"\",\"receiverId\":\"\",\"receiverState\":\"\",\"receiverTown\":\"\",\"receiverZip\":\"\",\"refAid\":\"313001208133750610\",\"refOid\":\"4181722704291751006\",\"refPlatform\":\"TB\",\"refType\":\"TMALL\",\"refundCreateTime\":1735287358000,\"refundFee\":\"98.86\",\"refundPhase\":\"ON_SALE\",\"refundTime\":1735289443000,\"refundUpdateTime\":1735289443000,\"refundVersion\":1735287358100,\"senderAddress\":\"\",\"senderCity\":\"\",\"senderCountry\":\"中国\",\"senderDistrict\":\"\",\"senderMobile\":\"\",\"senderName\":\"\",\"senderPhone\":\"\",\"senderState\":\"\",\"senderTown\":\"\",\"senderZip\":\"\",\"status\":\"SUCCESS\",\"statusCode\":\"SUCCESS\",\"statusName\":\"退款成功\",\"totalFee\":\"98.86\",\"type\":\"REFUND\",\"updateTime\":1735289479000}}");
  68. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  69. List<string> lw = new List<string>();
  70. string tid = GetPostString("ctid");
  71. string date1 = GetPostString("date1");
  72. //12-1 修改
  73. string urgent = GetPostString("urgent");
  74. string back = GetPostString("back");
  75. string offlineSearch = GetPostString("offlineSearch");
  76. int paramsCount = 0;
  77. if (!string.IsNullOrWhiteSpace(urgent))
  78. {
  79. if (urgent.Equals("true"))
  80. {
  81. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  82. }
  83. }
  84. if (!string.IsNullOrWhiteSpace(back))
  85. {
  86. if (back.Equals("true"))
  87. {
  88. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  89. }
  90. }
  91. if (!string.IsNullOrWhiteSpace(offlineSearch))
  92. {
  93. if (offlineSearch.Equals("true"))
  94. {
  95. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  96. }
  97. }
  98. //end
  99. string date2 = GetPostString("date2");
  100. string buyernick = GetPostString("buyer_nick");
  101. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  102. {
  103. if (tid.Length <= 0 && buyernick.Length <= 0)
  104. {
  105. return;
  106. }
  107. }
  108. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  109. {
  110. if (tid.Length > 0)
  111. {
  112. List<string> select_tid = getTidByCtidMore(tid);
  113. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  114. }
  115. if (buyernick.Length > 0)
  116. {
  117. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  118. }
  119. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  120. if (dw.Length > 0)
  121. {
  122. lw.Add(dw);
  123. }
  124. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  125. {
  126. string usershop = CurrentUser.User.pemShop;
  127. lw.Add(string.Format("ShopId in ({0})", usershop));
  128. }
  129. }
  130. else
  131. {
  132. if (ex_psize == 0)
  133. {
  134. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  135. }
  136. if (PKey != "admin")
  137. {
  138. string usershop = CurrentUser.User.pemShop;
  139. lw.Add(string.Format("ShopId in ({0})", usershop));
  140. paramsCount++;
  141. }
  142. }
  143. string uploaddate1 = GetPostString("uploaddate1");
  144. string uploaddate2 = GetPostString("uploaddate2");
  145. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  146. if (update.Length > 0) lw.Add(update);
  147. string deliverydate1 = GetPostString("deliverydate1");
  148. string deliverydate2 = GetPostString("deliverydate2");
  149. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  150. if (deliverydate.Length > 0)
  151. {
  152. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  153. };
  154. string shopname = GetPostString("shopname");
  155. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  156. string addwechat = GetPostString("addwechat");
  157. if (addwechat.Length > 0)
  158. {
  159. int addWt = Convert.ToInt32(addwechat);
  160. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  161. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  162. }
  163. string customer = GetPostString("customer");
  164. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  165. string design = GetPostString("design");
  166. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  167. string orderState = GetPostString("orderState");
  168. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  169. string address = GetPostString("address");
  170. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  171. string sellermemo = GetPostString("seller_memo");
  172. if (sellermemo.Length > 0)
  173. {
  174. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  175. }
  176. string backReason = GetPostString("backReason");
  177. if (backReason.Length > 0)
  178. {
  179. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  180. }
  181. string apdate1 = GetPostString("apdate1");
  182. string apdate2 = GetPostString("apdate2");
  183. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  184. if (dwap.Length > 0) lw.Add(dwap);
  185. string price1 = GetPostString("price1");
  186. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  187. string price2 = GetPostString("price2");
  188. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  189. string isoldcustomer = GetPostString("isoldcus");
  190. string spudata = GetPostString("spudata");
  191. if ("0".Equals(spudata))
  192. {
  193. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  194. }
  195. if ("1".Equals(spudata))
  196. {
  197. lw.Add(string.Format("spu_id <> ''"));
  198. }
  199. string finishdate1 = GetPostString("finishdate1");
  200. string finishdate2 = GetPostString("finishdate2");
  201. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  202. bool isFinish = false;
  203. if (finishdate.Length > 0)
  204. {
  205. lw.Add(finishdate);
  206. isFinish = true;
  207. paramsCount++;
  208. }
  209. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  210. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  211. if (ex_psize > 0)
  212. {
  213. int UserID = CurrentUser.UserID;
  214. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  215. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  216. {
  217. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  218. }
  219. dStruct.Order = "pay_time desc";
  220. }
  221. string isNew = GetPostString("isNew");
  222. if (isNew == "true")
  223. {
  224. lw.Add(string.Format("IsNew = {0}", 1));
  225. }
  226. string overtime = GetPostString("overtime");
  227. if (overtime == "1")
  228. {
  229. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  230. }
  231. String usePost = CurrentUser.UserPost.Post.Code;
  232. if (usePost.Equals("Operation") == true)
  233. {
  234. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  235. }
  236. else
  237. {
  238. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  239. }
  240. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  241. if (dStruct.PageSize == 100000)
  242. {
  243. dStruct.Order = "";
  244. }
  245. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  246. DataTable dt = null;
  247. string tablename = "view_orderlist";
  248. if (isFinish)
  249. {
  250. tablename = "view_orderlist_end";
  251. }
  252. dt = WebCache.GetData(tablename, dStruct);
  253. if (dt != null && dt.Rows.Count > 0)
  254. {
  255. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  256. foreach (DataRow dr in dt.Rows)
  257. {
  258. try
  259. {
  260. if (dr["refund_fees"] != null)
  261. {
  262. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  263. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  264. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  265. if (payment == refund_fees)
  266. {
  267. dr["refund_fees"] = Math.Round(refund_fees, 2);
  268. }
  269. else if (refund_fees == total_fee)
  270. {
  271. dr["refund_fees"] = payment;
  272. }
  273. else
  274. {
  275. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  276. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  277. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  278. }
  279. }
  280. // 对象操作
  281. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  282. ceErpTradeCell.ctid = dr["ctid"].ToString();
  283. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  284. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  285. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  286. if (dStruct.PageSize != 100000)
  287. {
  288. if (dr["DispatchSort"].ToString() == "2")
  289. {
  290. dr["gongchuang"] = 200;
  291. }
  292. else if ("外协".Equals(dr["ToType"].ToString()))
  293. {
  294. dr["gongchuang"] = 200;
  295. }
  296. else if ("内部".Equals(dr["ToType"].ToString()))
  297. {
  298. dr["gongchuang"] = -1;
  299. }
  300. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  301. {
  302. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  303. dr["gongchuang"] = response.code;
  304. }
  305. }
  306. }
  307. catch (NullReferenceException ex)
  308. {
  309. // 处理空引用异常
  310. dr["refund_fees"] = "0.00";
  311. }
  312. }
  313. }
  314. writeGridDataTableJson(dStruct.TotalCount, dt);
  315. }
  316. public void get_erp_orderlist_sumprice()
  317. {
  318. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  319. return;
  320. List<string> lw = new List<string>();
  321. string tid = GetPostString("ctid");
  322. string date1 = GetPostString("date1");
  323. string date2 = GetPostString("date2");
  324. if (tid.Length > 0 || date1.Length > 0)
  325. {
  326. lw.Add(string.Format("ctid like '%{0}%'", tid));
  327. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  328. if (dw.Length > 0) lw.Add(dw);
  329. }
  330. else
  331. {
  332. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  333. }
  334. string shopname = GetPostString("shopname");
  335. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  336. string buyernick = GetPostString("buyer_nick");
  337. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  338. string customer = GetPostString("customer");
  339. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  340. string design = GetPostString("design");
  341. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  342. string orderState = GetPostString("orderState");
  343. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  344. string address = GetPostString("address");
  345. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  346. string sellermemo = GetPostString("seller_memo");
  347. if (sellermemo.Length > 0)
  348. {
  349. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  350. }
  351. string apdate1 = GetPostString("apdate1");
  352. string apdate2 = GetPostString("apdate2");
  353. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  354. if (dwap.Length > 0) lw.Add(dwap);
  355. string price1 = GetPostString("price1");
  356. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  357. string price2 = GetPostString("price2");
  358. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  359. string isoldcustomer = GetPostString("isoldcus");
  360. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  361. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  362. if (PKey != "admin")
  363. {
  364. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  365. lw.Add(string.Format("shopId in ({0})", usershop));
  366. }
  367. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  368. string mainWhere = string.Join(" and ", lw.ToArray());
  369. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  370. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  371. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  372. decimal total = 0;
  373. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  374. {
  375. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  376. }
  377. var res = new
  378. {
  379. data = total
  380. };
  381. string ro_jsond = JsonConvert.SerializeObject(res);
  382. returnSuccess(ro_jsond);
  383. return;
  384. }
  385. public void get_erp_CustomerServiceGather()
  386. {
  387. string userWhere = "", orderWhere = "";
  388. List<string> lw = new List<string>();
  389. string customer = GetPostString("customer");
  390. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  391. string shopname = GetPostString("shopname");
  392. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  393. string date1 = GetPostString("date1");
  394. string date2 = GetPostString("date2");
  395. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  396. if (dw.Length > 0) lw.Add(dw);
  397. orderWhere = string.Join(" and ", lw.ToArray());
  398. string sql = string.Format("select a.Name CusName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitRelease,0) WaitRelease, isnull(e.WaitRob,0) WaitRob, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  399. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  400. "left join " +
  401. "( " +
  402. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  403. ") as b on a.ID = b.CustomerUserId " +
  404. "left join " +
  405. "( " +
  406. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  407. ") as d on a.ID = d.CustomerUserId " +
  408. "left join " +
  409. "( " +
  410. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  411. ") as e on a.ID = e.CustomerUserId " +
  412. "left join " +
  413. "( " +
  414. " select CustomerUserId, RefundCount, RefundSum from " +
  415. " ( " +
  416. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  417. " from CE_ErpTradeRefund a " +
  418. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  419. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  420. " group by CustomerUserId " +
  421. " ) as a " +
  422. ") as f on a.ID = f.CustomerUserId " +
  423. "where a.PostCode = 'CustomerService'",
  424. userWhere, orderWhere);
  425. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  426. writeGridDataTableJson(dt.Rows.Count, dt);
  427. //writeGridDataTableJson(dt.Rows.Count, dt);
  428. }
  429. //设计汇总
  430. public void get_erp_DesignerGather()
  431. {
  432. string userWhere = "", orderWhere = "";
  433. List<string> lw = new List<string>();
  434. string Designer = GetPostString("designer");
  435. int org = GetPostInt("org");
  436. if (Designer.Length > 0)
  437. {
  438. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  439. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  440. }
  441. else if (org > 0)
  442. {
  443. userWhere = string.Format(" where OrgID ={0}", org);
  444. }
  445. string shopname = GetPostString("shopname");
  446. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  447. string state = GetPostString("state");
  448. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  449. string OrderArea = GetPostString("order_area");
  450. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  451. string date1 = GetPostString("date1");
  452. string date2 = GetPostString("date2");
  453. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  454. if (dw.Length > 0) lw.Add(dw);
  455. string UpDate1 = GetPostString("UpDate1");
  456. string UpDate2 = GetPostString("UpDate2");
  457. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  458. if (dw.Length > 0) lw.Add(dw);
  459. orderWhere = string.Join(" and ", lw.ToArray());
  460. string sql = string.Format("select *,cast(cast(z.DesignFinish as float) / (case z.AllOrder when 0 then 1 else z.AllOrder end) * 100 as numeric(18,2)) as FinalizationRate from (" +
  461. "select a.Name DesignerName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitDesign,0) WaitDesign, isnull(e.Designing,0) Designing, isnull(g.DesignFinish,0) DesignFinish, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  462. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  463. "left join " +
  464. "( " +
  465. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  466. ") as b on a.ID = b.DesignUserId " +
  467. "left join " +
  468. "( " +
  469. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  470. ") as d on a.ID = d.DesignUserId " +
  471. "left join " +
  472. "( " +
  473. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  474. ") as e on a.ID = e.DesignUserId " +
  475. "left join " +
  476. "( " +
  477. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  478. ") as g on a.ID = g.DesignUserId " +
  479. "left join " +
  480. "( " +
  481. " select CustomerUserId, RefundCount, RefundSum from " +
  482. " ( " +
  483. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  484. " from CE_ErpTradeRefund a " +
  485. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  486. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  487. " group by CustomerUserId " +
  488. " ) as a " +
  489. ") as f on a.ID = f.CustomerUserId " +
  490. "where a.PostCode = 'Designer') as z",
  491. userWhere, orderWhere);
  492. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  493. writeGridDataTableJson(dt.Rows.Count, dt);
  494. }
  495. //删除tradecell的订单
  496. public void del_erp_cellorder()
  497. {
  498. if (UrlPostParmsCheck("ctid"))
  499. {
  500. string eid = GetPostString("ctid");
  501. CeErpTradeCell.DelByCtid(eid);
  502. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  503. returnSuccessMsg("删除成功");
  504. }
  505. }
  506. public void clear_erp_refundstate()
  507. {
  508. if (UrlPostParmsCheck("ids"))
  509. {
  510. string eids = GetPostString("ids");
  511. string[] ctidList = eids.Split(',');
  512. foreach (string ctid in ctidList)
  513. {
  514. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  515. if (entity != null)
  516. {
  517. entity.IsRefund = 0;
  518. entity.Update();
  519. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  520. }
  521. else
  522. continue;
  523. }
  524. returnSuccessMsg("操作成功");
  525. return;
  526. }
  527. returnErrorMsg("缺少必要参数");
  528. }
  529. public void set_erp_urgency()
  530. {
  531. if (UrlPostParmsCheck("ctid"))
  532. {
  533. string eid = GetPostString("ctid");
  534. CeErpTradeCell entity = null;
  535. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  536. if (entity != null)
  537. {
  538. string utime = GetPostString("urgencytime");
  539. if (utime.Length > 0)
  540. {
  541. entity.UrgencyTime = Convert.ToDateTime(utime);
  542. }
  543. else
  544. {
  545. returnErrorMsg("请选择加急时间");
  546. return;
  547. }
  548. if (entity.OrderState <= 4)
  549. {
  550. //entity.seller_memo = entity.seller_memo + "-加急";
  551. string smemo = entity.seller_memo;
  552. int kindex = smemo.IndexOf(")");
  553. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  554. if (lastoneStr != "-")
  555. {
  556. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  557. }
  558. string prememo = smemo.Substring(0, kindex + 2);
  559. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  560. int lastkindex = lastmemo.IndexOf("(");
  561. DateTime urgtime = Convert.ToDateTime(utime);
  562. string newlastmemo = "";
  563. if (lastkindex == 0)
  564. {
  565. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  566. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  567. }
  568. else
  569. {
  570. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  571. }
  572. entity.seller_memo = prememo + newlastmemo;
  573. }
  574. entity.IsUrgency = true;
  575. entity.UpdateTime = DateTime.Now;
  576. entity.Update();
  577. ApiVo apiVo = new ApiVo();
  578. apiVo.orderNumber = entity.ctid;
  579. apiVo.actionName = "changeDesign";
  580. apiVo.orderRemarks = entity.seller_memo;
  581. apiVo.remarkSign = 3;
  582. designHelper.API_WorkCore(apiVo); //changeDesign
  583. CeErpSukuraData.createInfo(entity.ctid, 7);
  584. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  585. returnSuccessMsg("设置成功!");
  586. return;
  587. }
  588. returnErrorMsg("找不到记录");
  589. }
  590. }
  591. public void set_erp_reset()
  592. {
  593. if (UrlPostParmsCheck("ctid"))
  594. {
  595. string eid = GetPostString("ctid");
  596. CeErpTradeCell entity = null;
  597. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  598. if (entity != null)
  599. {
  600. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  601. {
  602. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  603. {
  604. returnErrorMsg("财务要求已下单已发货无法重置");
  605. return;
  606. }
  607. }
  608. entity.IsUrgency = false;
  609. entity.seller_memo = "";
  610. entity.OtherMemo = "";
  611. entity.OrderState = 0;
  612. entity.IsReturn = 0;
  613. //entity.IsRefund = 0;
  614. entity.MemoOpt = 0;
  615. entity.AfterSaleState = 0;
  616. entity.AfterSaleResponsible = "";
  617. entity.AfterSaleUserId = 0;
  618. entity.IsNeedBill = 0;
  619. entity.CustomerUserId = 0;
  620. entity.DesignUserId = 0;
  621. entity.SupplierId = 0;
  622. entity.PlaceUserId = 0;
  623. entity.ptid = "";
  624. entity.IsSample = 0;
  625. entity.IsXianHuo = 0;
  626. entity.isDianziOrder = 0;
  627. entity.DispatchSort = 0;
  628. entity.FinishPlaceTime = null;
  629. entity.Update();
  630. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  631. if (trade != null)
  632. {
  633. trade.seller_memo = "";
  634. trade.Update();
  635. }
  636. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  637. returnSuccessMsg("重置成功!");
  638. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  639. if (desginBill != null)
  640. {
  641. desginBill.isDel = 1;
  642. desginBill.Update();
  643. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  644. }
  645. ApiVo apiVo = new ApiVo();
  646. apiVo.orderNumber = entity.ctid;
  647. apiVo.actionName = "resetDesign";
  648. designHelper.API_WorkCore(apiVo);//resetDesign
  649. return;
  650. }
  651. returnErrorMsg("找不到记录");
  652. }
  653. }
  654. public void save_erp_sellermemo()
  655. {
  656. if (UrlPostParmsCheck("ctid"))
  657. {
  658. string ctid = GetPostString("ctid");
  659. CeErpTradeCell entity = null;
  660. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  661. if (entity != null)
  662. {
  663. string memo = GetPostString("seller_memo");
  664. memo = memo.Replace(" ", "");
  665. if (memo.Contains("补差"))
  666. {
  667. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  668. return;
  669. }
  670. List<string> bitList = new List<string>
  671. {
  672. "\\","/",":","*","?", "\"","<" ,">","|"
  673. };
  674. bool isIn = false;
  675. foreach (string bit in bitList)
  676. {
  677. if (memo.Contains(bit))
  678. {
  679. isIn = true;
  680. }
  681. }
  682. if (isIn)
  683. {
  684. returnErrorMsg("不能使用 一些符合作为文件名");
  685. return;
  686. }
  687. if (entity.seller_memo != memo)
  688. {
  689. if (entity.IsSample == 2)
  690. {
  691. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  692. return;
  693. }
  694. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  695. {
  696. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  697. {
  698. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  699. return;
  700. }
  701. /*if (CurrentUser.UserPost.Post.Code != "Place")
  702. {
  703. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  704. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  705. {
  706. returnErrorMsg("售前系统订单无法再此修改!");
  707. return;
  708. }
  709. }*/
  710. }
  711. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  712. }
  713. commonHelper.getCytPrice(entity);
  714. int memoopt = GetPostInt("MemoOpt");
  715. Boolean ismemoopt = false;
  716. if (memoopt > 0)
  717. {
  718. string stropt = "";
  719. if (memoopt == 1)
  720. {
  721. stropt = "“改稿”";
  722. ismemoopt = true;
  723. }
  724. else if (memoopt == 2)
  725. {
  726. stropt = "“定稿”";
  727. }
  728. else if (memoopt == 3)
  729. {
  730. stropt = "“查货”";
  731. CeErpSukuraData.createInfo(entity.ctid, 6);
  732. }
  733. entity.MemoOpt = Convert.ToInt32(memoopt);
  734. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  735. }
  736. if (entity.OrderState < 5)
  737. {
  738. memo = memo.Replace("(", "(");
  739. memo = memo.Replace(")", ")");
  740. }
  741. if (entity.OrderState < 3)
  742. {
  743. entity.DispatchSort = 0;
  744. }
  745. entity.seller_memo = memo;
  746. entity.UpdateTime = DateTime.Now;
  747. entity.Update();
  748. ApiVo apiVo = new ApiVo();
  749. apiVo.orderNumber = entity.ctid;
  750. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  751. apiVo.orderRemarks = memo;
  752. apiVo.remarkSign = memoopt;
  753. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  754. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  755. returnSuccessMsg("保存成功!");
  756. return;
  757. }
  758. returnErrorMsg("找不到记录");
  759. }
  760. }
  761. public void ins_erp_checkorder()
  762. {
  763. if (UrlPostParmsCheck("ctid"))
  764. {
  765. string ctid = GetPostString("ctid");
  766. CeErpTradeCell entity = null;
  767. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  768. if (entity != null)
  769. {
  770. if (entity.OrderState < 6)
  771. {
  772. returnErrorMsg("下单完成后才可查货");
  773. return;
  774. }
  775. /*if (entity.OrderState > 6)
  776. {
  777. returnErrorMsg("订单已发货");
  778. return;
  779. }*/
  780. if (entity.FinishPlaceTime != null)
  781. {
  782. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  783. {
  784. returnErrorMsg("下单时间不足,无法查货");
  785. return;
  786. }
  787. }
  788. entity.MemoOpt = 3;
  789. entity.CheckOrderTime = DateTime.Now;
  790. entity.UpdateTime = DateTime.Now;
  791. entity.Update();
  792. CeErpSukuraData.createInfo(entity.ctid, 6);
  793. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  794. returnSuccessMsg("操作成功!");
  795. return;
  796. }
  797. returnErrorMsg("找不到记录");
  798. }
  799. }
  800. public void save_erp_othermemo()
  801. {
  802. if (UrlPostParmsCheck("ctid"))
  803. {
  804. string ctid = GetPostString("ctid");
  805. CeErpTradeCell entity = null;
  806. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  807. if (entity != null)
  808. {
  809. entity.OtherMemo = GetPostString("otherMemo");
  810. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  811. {
  812. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  813. StringBuilder sql = new StringBuilder();
  814. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  815. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  816. if (dt != null && dt.Rows.Count > 0)
  817. {
  818. foreach (DataRow dr in dt.Rows)
  819. {
  820. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  821. {
  822. //品类一直
  823. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  824. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  825. if (ceErpSampleCustomer == null)
  826. {
  827. ceErpSampleCustomer = new CeErpSampleCustomer();
  828. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  829. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  830. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  831. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  832. ceErpSampleCustomer.shopId = entity.ShopId;
  833. }
  834. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  835. ceErpSampleCustomer.lastTid = entity.tid;
  836. if (ceErpSampleCustomer.ID > 0)
  837. {
  838. ceErpSampleCustomer.Update();
  839. }
  840. else
  841. {
  842. ceErpSampleCustomer.Create();
  843. }
  844. }
  845. }
  846. }
  847. }
  848. //if (entity.IsOldCustomer == 1)
  849. //{
  850. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  851. //{
  852. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  853. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  854. //}
  855. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  856. //{
  857. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  858. // {
  859. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  860. // {
  861. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  862. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  863. // }
  864. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  865. // {
  866. // entity.OrderState = 2;
  867. // entity.DesignUserId = 0;
  868. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  869. // }
  870. // else
  871. // {
  872. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  873. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  874. // }
  875. // }
  876. //}
  877. //}
  878. entity.UpdateTime = DateTime.Now;
  879. entity.Update();
  880. returnSuccessMsg("保存成功!");
  881. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  882. return;
  883. }
  884. returnErrorMsg("找不到记录");
  885. }
  886. }
  887. public void save_erp_customermemo()
  888. {
  889. if (UrlPostParmsCheck("ctid"))
  890. {
  891. string ctid = GetPostString("ctid");
  892. CeErpTradeCell entity = null;
  893. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  894. if (entity != null)
  895. {
  896. entity.UpdateTime = DateTime.Now;
  897. entity.CustomerMemo = GetPostString("CustomerMemo");
  898. entity.Update();
  899. ApiVo apiVo = new ApiVo();
  900. apiVo.orderNumber = entity.ctid;
  901. apiVo.actionName = "followRemarks";
  902. apiVo.orderRemarks = entity.CustomerMemo;
  903. designHelper.API_WorkCore(apiVo);//followRemarks
  904. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  905. returnSuccessMsg("保存成功!");
  906. return;
  907. }
  908. returnErrorMsg("找不到记录");
  909. }
  910. }
  911. public void upd_erp_addmemotag()
  912. {
  913. if (UrlPostParmsCheck("ctid"))
  914. {
  915. ;
  916. string eid = GetPostString("ctid");
  917. string sfTagstr = GetPostString("memotag");
  918. CeErpTradeCell entity = null;
  919. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  920. if (entity != null)
  921. {
  922. ApiVo apiVo = new ApiVo();
  923. if (entity.OrderState == 0)
  924. {
  925. returnErrorMsg("请先领单");
  926. return;
  927. }
  928. //撤销顺丰
  929. if (sfTagstr == "撤销顺丰")
  930. {
  931. entity.IsSF = 0;
  932. string reMsg = "";
  933. string oldmemo = entity.seller_memo;
  934. if (entity.OrderState < 5)
  935. {
  936. oldmemo = oldmemo.Replace("顺丰到付", "");
  937. oldmemo = oldmemo.Replace("顺丰寄付", "");
  938. entity.seller_memo = oldmemo;
  939. }
  940. else
  941. {
  942. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  943. {
  944. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  945. }
  946. }
  947. entity.Update();
  948. apiVo.orderNumber = entity.ctid;
  949. apiVo.actionName = "orderRemarks";
  950. apiVo.orderRemarks = entity.seller_memo;
  951. apiVo.isSf = entity.IsSF.ToString();
  952. designHelper.API_WorkCore(apiVo);//orderRemarks
  953. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  954. returnSuccessMsg("撤销成功!" + reMsg);
  955. return;
  956. }
  957. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  958. {
  959. //string oldmemo = entity.seller_memo;
  960. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  961. string sfStr = GetPostString("memotag");
  962. string smemo = entity.seller_memo;
  963. int kindex = smemo.IndexOf(")");
  964. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  965. if (lastoneStr != "-")
  966. {
  967. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  968. }
  969. string prememo = smemo.Substring(0, kindex + 2);
  970. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  971. int lastkindex = lastmemo.IndexOf("(");
  972. string newlastmemo = "";
  973. if (lastkindex == 0)
  974. {
  975. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  976. newlastmemo = "(" + sfStr + "." + useLastmemo;
  977. }
  978. else
  979. {
  980. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  981. }
  982. entity.seller_memo = prememo + newlastmemo;
  983. }
  984. string sfTagMSg = "";
  985. if (sfTagstr == "顺丰寄付")
  986. {
  987. entity.IsSF = 1;
  988. sfTagMSg = "顺丰寄付";
  989. }
  990. else if (sfTagstr == "顺丰到付")
  991. {
  992. entity.IsSF = 2;
  993. sfTagMSg = "顺丰到付";
  994. }
  995. entity.Update();
  996. apiVo = new ApiVo();
  997. apiVo.orderNumber = entity.ctid;
  998. apiVo.actionName = "orderRemarks";
  999. apiVo.orderRemarks = entity.seller_memo;
  1000. apiVo.isSf = entity.IsSF.ToString();
  1001. designHelper.API_WorkCore(apiVo);//orderRemarks
  1002. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1003. returnSuccessMsg("标记成功!");
  1004. return;
  1005. }
  1006. returnErrorMsg("找不到记录");
  1007. }
  1008. }
  1009. public void upd_erp_ordertag()
  1010. {
  1011. if (UrlPostParmsCheck("ctid"))
  1012. {
  1013. string eid = GetPostString("ctid");
  1014. CeErpTradeCell entity = null;
  1015. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1016. if (entity != null)
  1017. {
  1018. int tag = GetPostInt("wechattag");
  1019. //if(tag==4 && entity.IsSample == 2)
  1020. //{
  1021. // returnErrorMsg("补差价单不能标记微信单");
  1022. // return;
  1023. //}
  1024. entity.wechatTag = tag;
  1025. entity.Update();
  1026. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1027. if (tag == 1)
  1028. {
  1029. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1030. if (cash == null)
  1031. {
  1032. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1033. cash = new CeErpReturnCash();
  1034. cash.tid = entity.tid;
  1035. cash.seller_nick = main.seller_nick;
  1036. cash.payment = trade.payment;
  1037. cash.buyer_nick = main.buyer_nick;
  1038. cash.cashstate = 0;
  1039. cash.rtype = "微信返现";
  1040. cash.returnprice = 0;
  1041. cash.created = DateTime.Now;
  1042. cash.con = "订单标记微信单";
  1043. cash.img = "";
  1044. cash.applyuserid = CurrentUser.UserID;
  1045. cash.Create();
  1046. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1047. }
  1048. else
  1049. {
  1050. cash.cashstate = 0;
  1051. cash.Update();
  1052. }
  1053. CeErpSukuraData.createInfo(entity.ctid, 9);
  1054. }
  1055. else if (tag == 2)
  1056. {
  1057. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1058. if (cash == null)
  1059. {
  1060. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1061. cash = new CeErpReturnCash();
  1062. cash.tid = entity.tid;
  1063. cash.seller_nick = main.seller_nick;
  1064. cash.payment = trade.payment;
  1065. cash.buyer_nick = main.buyer_nick;
  1066. cash.cashstate = 0;
  1067. cash.rtype = "推购返现";
  1068. cash.returnprice = 5;
  1069. cash.created = DateTime.Now;
  1070. cash.con = "订单标记推购单";
  1071. cash.img = "";
  1072. cash.applyuserid = CurrentUser.UserID;
  1073. cash.Create();
  1074. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1075. }
  1076. else
  1077. {
  1078. cash.cashstate = 0;
  1079. cash.Update();
  1080. }
  1081. CeErpSukuraData.createInfo(entity.ctid, 9);
  1082. }
  1083. else if (tag == 3)
  1084. {
  1085. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1086. if (pers == null)
  1087. {
  1088. pers = new CeErpPersuade();
  1089. pers.ctid = entity.ctid;
  1090. pers.pstate = 0;
  1091. pers.created = DateTime.Now;
  1092. pers.applyuserid = CurrentUser.UserID;
  1093. pers.Create();
  1094. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1095. }
  1096. else
  1097. {
  1098. pers.pstate = 0;
  1099. pers.Update();
  1100. }
  1101. }
  1102. else if (tag == 4 || tag == 5)
  1103. {
  1104. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1105. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1106. if (pers == null)
  1107. {
  1108. pers = new CeErpStayGoods();
  1109. pers.t_id = entity.tid;
  1110. pers.status = "待审核";
  1111. pers.audit_type = 0;
  1112. if (tag == 4)
  1113. {
  1114. pers.stay_type = "微信推购";
  1115. }
  1116. else
  1117. {
  1118. pers.stay_type = "旺旺推购";
  1119. }
  1120. if (entity.IsXianHuo == 0)
  1121. {
  1122. pers.product_id = entity.ProductId;
  1123. }
  1124. pers.wangwang = main.buyer_nick;
  1125. pers.shop_name = main.seller_nick;
  1126. pers.creata_time = DateTime.Now;
  1127. pers.create_u_id = CurrentUser.UserID;
  1128. pers.create_u_name = CurrentUser.UserName;
  1129. pers.Create();
  1130. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1131. }
  1132. else
  1133. {
  1134. pers.audit_type = 0;
  1135. pers.Update();
  1136. }
  1137. CeErpSukuraData.createInfo(entity.ctid, 10);
  1138. }
  1139. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1140. returnSuccessMsg("标记成功!");
  1141. return;
  1142. }
  1143. returnErrorMsg("找不到记录");
  1144. }
  1145. }
  1146. public void upd_erp_ordertag_cancel()
  1147. {
  1148. if (UrlPostParmsCheck("ctid"))
  1149. {
  1150. string eid = GetPostString("ctid");
  1151. CeErpTradeCell entity = null;
  1152. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1153. if (entity != null)
  1154. {
  1155. entity.wechatTag = 0;
  1156. entity.Update();
  1157. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1158. if (pers != null)
  1159. {
  1160. pers.status = "取消推购";
  1161. pers.audit_type = 3;
  1162. pers.Update();
  1163. }
  1164. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1165. returnSuccessMsg("标记成功!");
  1166. return;
  1167. }
  1168. returnErrorMsg("找不到记录");
  1169. }
  1170. }
  1171. public void upd_erp_addweichattag()
  1172. {
  1173. if (UrlPostParmsCheck("ctid"))
  1174. {
  1175. ;
  1176. string eid = GetPostString("ctid");
  1177. CeErpTradeCell entity = null;
  1178. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1179. if (entity != null)
  1180. {
  1181. if (entity.IsAddWechat > 0)
  1182. {
  1183. returnErrorMsg("此单已经标记过了");
  1184. return;
  1185. }
  1186. 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);
  1187. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1188. if (dt.Rows.Count > 0)
  1189. {
  1190. entity.IsAddWechat = 2;
  1191. }
  1192. else
  1193. {
  1194. entity.IsAddWechat = 1;
  1195. }
  1196. entity.Update();
  1197. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1198. returnSuccessMsg("标记成功!");
  1199. return;
  1200. }
  1201. returnErrorMsg("找不到记录");
  1202. }
  1203. }
  1204. public void upd_erp_getmyorder()
  1205. {
  1206. if (UrlPostParmsCheck("ctid"))
  1207. {
  1208. ;
  1209. string eid = GetPostString("ctid");
  1210. CeErpTradeCell entity = null;
  1211. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1212. if (entity != null)
  1213. {
  1214. if (entity.ctid.IndexOf("C") != -1)
  1215. {
  1216. StringBuilder sql = new StringBuilder();
  1217. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1218. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1219. if (dt.Rows.Count > 0)
  1220. {
  1221. decimal total = 0;
  1222. foreach (DataRow dr in dt.Rows)
  1223. {
  1224. total += Convert.ToDecimal(dr["payment"]);
  1225. }
  1226. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1227. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1228. {
  1229. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1230. return;
  1231. }
  1232. }
  1233. }
  1234. if (entity.OrderState == -1)
  1235. {
  1236. returnErrorMsg("待审核订单无法领取!");
  1237. return;
  1238. }
  1239. entity.CustomerUserId = CurrentUser.UserID;
  1240. if (entity.OrderState < 2)
  1241. {
  1242. entity.OrderState = 2;
  1243. if (entity.ShopId != 0)
  1244. {
  1245. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1246. }
  1247. }
  1248. entity.UpdateTime = DateTime.Now;
  1249. entity.Update();
  1250. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1251. returnSuccessMsg("领单成功!");
  1252. return;
  1253. }
  1254. returnErrorMsg("找不到记录");
  1255. }
  1256. }
  1257. public void getmyorder_from_init()
  1258. {
  1259. if (UrlPostParmsCheck("ctid"))
  1260. {
  1261. string eid = GetPostString("ctid");
  1262. CeErpTradeCell entity = null;
  1263. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1264. if (entity != null)
  1265. {
  1266. string sellerMemo = GetPostString("sellerMemo");
  1267. if (sellerMemo.Length > 0)
  1268. {
  1269. entity.seller_memo = sellerMemo;
  1270. }
  1271. string oterhMemo = GetPostString("otherMemo");
  1272. if (oterhMemo.Length > 0)
  1273. {
  1274. entity.OtherMemo = oterhMemo;
  1275. }
  1276. int urg = GetPostInt("urgency");
  1277. entity.IsUrgency = (urg == 1 ? true : false);
  1278. int wechat = GetPostInt("wechat");
  1279. int command = GetPostInt("command");
  1280. if (wechat == 1)
  1281. {
  1282. entity.wechatTag = 1;
  1283. }
  1284. if (command == 1)
  1285. {
  1286. entity.wechatTag = 2;
  1287. }
  1288. string pPro = GetPostString("pprofession");
  1289. if (pPro.Length > 0)
  1290. {
  1291. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1292. string spro = GetPostString("profession");
  1293. if (spro.Length > 0)
  1294. {
  1295. entity.ProfessionId = Convert.ToInt32(spro);
  1296. }
  1297. }
  1298. string proId = GetPostString("productId");
  1299. if (proId.Length > 0)
  1300. {
  1301. entity.ProductId = Convert.ToInt32(proId);
  1302. }
  1303. entity.Material = GetPostString("material");
  1304. entity.Craft = GetPostString("craft");
  1305. entity.CustomerUserId = CurrentUser.UserID;
  1306. if (entity.OrderState < 2)
  1307. {
  1308. entity.OrderState = 2;
  1309. if (entity.ShopId != 0)
  1310. {
  1311. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1312. }
  1313. }
  1314. entity.Update();
  1315. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1316. returnSuccessMsg("领单成功!");
  1317. return;
  1318. }
  1319. returnErrorMsg("找不到记录");
  1320. }
  1321. }
  1322. public void upd_erp_setrelationorder()
  1323. {
  1324. if (UrlPostParmsCheck("ctid"))
  1325. {
  1326. ;
  1327. string eid = GetPostString("ctid");
  1328. string ftid = GetPostString("ftid");
  1329. CeErpTradeCell entity = null;
  1330. CeErpTradeCell fentity = null;
  1331. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1332. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1333. if (fentity == null)
  1334. {
  1335. returnErrorMsg("找不到关联的主订单");
  1336. return;
  1337. }
  1338. if (entity != null)
  1339. {
  1340. if (entity.OrderState >= 5)
  1341. {
  1342. returnErrorMsg("本单已经设计完成无法关联");
  1343. return;
  1344. }
  1345. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1346. {
  1347. returnErrorMsg("线下单续审核后才能关联!");
  1348. return;
  1349. }
  1350. entity.ptid = ftid;
  1351. entity.OrderState = fentity.OrderState;
  1352. //entity.status = fentity.status;
  1353. entity.CustomerUserId = fentity.CustomerUserId;
  1354. entity.DesignUserId = fentity.DesignUserId;
  1355. entity.seller_memo = "补差价单:" + ftid;
  1356. entity.IsSample = 2;
  1357. entity.Update();
  1358. ApiVo apiVo = new ApiVo();
  1359. apiVo.orderNumber = ftid;
  1360. apiVo.payment = entity.payment;
  1361. apiVo.actionName = "repairDesign";
  1362. designHelper.API_WorkCore(apiVo);//repairDesign
  1363. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1364. returnSuccessMsg("关联成功!");
  1365. return;
  1366. }
  1367. else
  1368. returnErrorMsg("找不到记录");
  1369. }
  1370. }
  1371. public void download_erp_neworder()
  1372. {
  1373. string seller = GetPostString("seller_nick");
  1374. string tid = GetPostString("tid");
  1375. if (seller.Length <= 0 || tid.Length <= 0)
  1376. {
  1377. returnErrorMsg("数据错误");
  1378. }
  1379. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1380. //{
  1381. // returnErrorMsg("找不到店铺Sessionkey");
  1382. //}
  1383. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1384. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1385. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1386. if (res.IndexOf("refOid") == -1)
  1387. {
  1388. returnErrorMsg("下载订单数据失败");
  1389. return;
  1390. }
  1391. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1392. returnSuccessMsg("下载完成");
  1393. //tmcHelper.createNewOrder(res);
  1394. //CeErpTrade entr = null;
  1395. //entr = CeErpTrade.Get(tid);
  1396. //if (entr != null)
  1397. //{
  1398. // returnSuccess("下载成功");
  1399. // //下载成功之后,Cell表生成对应的订单;
  1400. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1401. //}
  1402. //else
  1403. //{
  1404. // returnErrorMsg("下载失败或者创建订单失败");
  1405. //}
  1406. }
  1407. public void set_erp_atersale()
  1408. {
  1409. if (UrlPostParmsCheck("ctid"))
  1410. {
  1411. string eid = GetPostString("ctid");
  1412. string reason = GetPostString("AfterSaleReason");
  1413. CeErpTradeCell entity = null;
  1414. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1415. if (entity != null)
  1416. {
  1417. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1418. {
  1419. returnErrorMsg("此订单已经在售后");
  1420. return;
  1421. }
  1422. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1423. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1424. entity.AfterSaleTime = DateTime.Now;
  1425. entity.Update();
  1426. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1427. returnSuccessMsg("转售后成功!");
  1428. return;
  1429. }
  1430. returnErrorMsg("找不到记录");
  1431. }
  1432. }
  1433. public void set_erp_withdraw()
  1434. {
  1435. if (UrlPostParmsCheck("ctid"))
  1436. {
  1437. try
  1438. {
  1439. string eid = GetPostString("ctid");//商品id
  1440. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1441. CeWithdraw ceWithdrawSelect = null;
  1442. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1443. if (ceWithdrawSelect != null)
  1444. {
  1445. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1446. {
  1447. ceWithdrawSelect.status = -1;
  1448. ceWithdrawSelect.Update();
  1449. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1450. returnSuccessMsg("重新发起审核成功");
  1451. return;
  1452. }
  1453. else
  1454. {
  1455. returnSuccessMsg("请勿重复申请!");
  1456. return;
  1457. }
  1458. }
  1459. else
  1460. {
  1461. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1462. if (string.IsNullOrEmpty(CustomerUserId))
  1463. {
  1464. CustomerUserId = "-1";
  1465. }
  1466. int Userid = CurrentUser.UserID;//用户id
  1467. CeWithdraw ceWithdraw = new CeWithdraw();
  1468. ceWithdraw.tid = eid;
  1469. ceWithdraw.userid = Userid;
  1470. ceWithdraw.providerid = CustomerUserId;
  1471. ceWithdraw.status = 3;
  1472. ceWithdraw.creationtime = DateTime.Now;
  1473. ceWithdraw.Create();
  1474. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1475. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1476. return;
  1477. }
  1478. }
  1479. catch
  1480. {
  1481. returnErrorMsg("申请撤回订单失败");
  1482. return;
  1483. }
  1484. }
  1485. }
  1486. public void ins_erp_billinfo()
  1487. {
  1488. if (UrlPostParmsCheck("ctid"))
  1489. {
  1490. string eid = GetPostString("ctid");
  1491. CeErpTradeCell entity = null;
  1492. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1493. if (entity != null)
  1494. {
  1495. CeErpBill bill = CeErpBill.GetByTid(eid);
  1496. bool isHave = false;
  1497. if (bill != null)
  1498. {
  1499. isHave = true;
  1500. if (bill.state != 4)
  1501. {
  1502. returnErrorMsg("此单已经申请过发票了");
  1503. return;
  1504. }
  1505. }
  1506. if (entity.IsNeedBill == 0)
  1507. {
  1508. entity.IsNeedBill = 1;
  1509. }
  1510. entity.Update();
  1511. string errjson = "";
  1512. try
  1513. {
  1514. CeErpBill bill_entity = new CeErpBill();
  1515. bill_entity.tid = entity.tid;
  1516. bill_entity.title = GetPostString("title");
  1517. string taxstr = GetPostString("tax");
  1518. taxstr = taxstr.Replace(" ", "");
  1519. bill_entity.tax = taxstr;
  1520. bill_entity.bank = GetPostString("bank");
  1521. string bankacstr = GetPostString("bankac");
  1522. bankacstr = bankacstr.Replace(" ", "");
  1523. bill_entity.bankac = bankacstr;
  1524. bill_entity.address = GetPostString("address");
  1525. bill_entity.phone = GetPostString("phone");
  1526. bill_entity.price = GetPostString("price");
  1527. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1528. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1529. {
  1530. billCount += 1;
  1531. }
  1532. string prebill = "ltb";
  1533. for (int idx = 1; idx <= billCount; idx++)
  1534. {
  1535. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1536. string billoid = prebill + idx + dtstr;
  1537. bill_entity.billOrderId += billoid;
  1538. if (idx < billCount)
  1539. {
  1540. bill_entity.billOrderId += ",";
  1541. }
  1542. }
  1543. bill_entity.productId = GetPostInt("ProductName");
  1544. bill_entity.num = GetPostInt("num");
  1545. bill_entity.unit = GetPostString("unit");
  1546. bill_entity.type = GetPostString("type");
  1547. bill_entity.sendType = GetPostString("SendType");
  1548. bill_entity.email = GetPostString("email");
  1549. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1550. bill_entity.shopName = GetPostString("ShopName");
  1551. bill_entity.applymemo = GetPostString("applyMemo");
  1552. bill_entity.createTime = DateTime.Now;
  1553. bill_entity.state = 0;
  1554. bill_entity.userId = CurrentUser.UserID;
  1555. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1556. bill_entity.Create();
  1557. }
  1558. catch (Exception ex)
  1559. {
  1560. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1561. returnErrorMsg("创建发票出错!");
  1562. return;
  1563. }
  1564. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1565. returnSuccessMsg("发票申请成功!");
  1566. return;
  1567. }
  1568. returnErrorMsg("找不到记录");
  1569. }
  1570. }
  1571. public void ins_erp_neworder()
  1572. {
  1573. if (UrlPostParmsCheck("receiver_name"))
  1574. {
  1575. CeErpTrade entity = new CeErpTrade();
  1576. string plat_form = GetPostString("platform");
  1577. string preStr = "N_";
  1578. if (plat_form == "拼多多")
  1579. {
  1580. preStr = "P_";
  1581. }
  1582. else if (plat_form == "阿里巴巴")
  1583. {
  1584. preStr = "A_";
  1585. }
  1586. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1587. entity.seller_nick = GetPostString("seller_nick");
  1588. entity.buyer_nick = GetPostString("buyer_nick");
  1589. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1590. entity.total_fee = entity.payment;
  1591. entity.pay_time = DateTime.Now;
  1592. entity.status = "NOT_SHIPPED";
  1593. entity.receiver_name = GetPostString("receiver_name");
  1594. entity.receiver_mobile = GetPostString("receiver_mobile");
  1595. entity.receiver_state = GetPostString("receiver_state");
  1596. entity.receiver_city = GetPostString("receiver_city");
  1597. entity.receiver_district = GetPostString("receiver_district");
  1598. entity.receiver_address = GetPostString("receiver_address");
  1599. if (entity.receiver_state == "" || entity.receiver_city == "")
  1600. {
  1601. returnErrorMsg("收件地址不能为空");
  1602. return;
  1603. }
  1604. int shopId = 0;
  1605. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1606. if (nShop != null)
  1607. {
  1608. shopId = nShop.ID;
  1609. }
  1610. if (shopId != 34 && entity.payment == 0)
  1611. {
  1612. returnErrorMsg("公司自用的单金额才能为0");
  1613. return;
  1614. }
  1615. entity.Create();
  1616. CeErpTradeCell entitycell = new CeErpTradeCell();
  1617. entitycell.ctid = entity.tid;
  1618. entitycell.tid = entity.tid;
  1619. entitycell.ShopId = shopId;
  1620. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1621. entitycell.OrderState = 0;
  1622. entitycell.pay_time = entity.pay_time;
  1623. entitycell.IsOffLineOrder = 1;
  1624. entitycell.Create();
  1625. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1626. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1627. return;
  1628. }
  1629. }
  1630. public void ins_erp_neworder2()
  1631. {
  1632. if (UrlPostParmsCheck("receiver_name"))
  1633. {
  1634. //string plat_form = GetPostString("platform");
  1635. string preStr = "X_";
  1636. string memo = GetPostString("memo");
  1637. string productId = GetPostString("productId");
  1638. string primg = GetPostString("proofimg");
  1639. string sellerNick = GetPostString("seller_nick");
  1640. string addFrom = GetPostString("addfrom");
  1641. if (addFrom == "1")
  1642. {
  1643. preStr = "N_";
  1644. }
  1645. int shopId = 0;
  1646. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1647. if (nShop != null)
  1648. {
  1649. shopId = nShop.ID;
  1650. }
  1651. else
  1652. {
  1653. returnErrorMsg("找不到对应店铺");
  1654. return;
  1655. }
  1656. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1657. {
  1658. returnErrorMsg("必须上传付款凭证");
  1659. return;
  1660. }
  1661. CeErpTrade entity = new CeErpTrade();
  1662. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1663. entity.seller_nick = sellerNick;
  1664. entity.buyer_nick = GetPostString("buyer_nick");
  1665. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1666. entity.total_fee = entity.payment;
  1667. entity.pay_time = DateTime.Now;
  1668. entity.status = "NOT_SHIPPED";
  1669. entity.receiver_name = GetPostString("receiver_name");
  1670. entity.receiver_mobile = GetPostString("receiver_mobile");
  1671. entity.receiver_state = GetPostString("receiver_state");
  1672. entity.receiver_city = GetPostString("receiver_city");
  1673. entity.receiver_district = GetPostString("receiver_district");
  1674. entity.receiver_address = GetPostString("receiver_address");
  1675. entity.seller_memo = memo;
  1676. entity.orderFrom = 20;
  1677. entity.orderType = 15;
  1678. if (entity.receiver_state == "" || entity.receiver_city == "")
  1679. {
  1680. returnErrorMsg("收件地址不能为空");
  1681. return;
  1682. }
  1683. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1684. {
  1685. returnErrorMsg("公司自用的单金额才能为0");
  1686. return;
  1687. }
  1688. entity.Create();
  1689. string toWhere = GetPostString("towhere");
  1690. CeErpTradeCell entitycell = new CeErpTradeCell();
  1691. entitycell.ctid = entity.tid;
  1692. //唯一标识
  1693. entitycell.OrderSn = entity.tid;
  1694. string orderSn = dataHelper.getSaleOrderSn();
  1695. if (orderSn != "")
  1696. {
  1697. entitycell.OrderSn = orderSn;
  1698. }
  1699. entitycell.tid = entity.tid;
  1700. //if (preStr == "X_")
  1701. //{
  1702. entitycell.IsOffLineOrder = 1;
  1703. //}
  1704. entitycell.CustomerUserId = CurrentUser.UserID;
  1705. entitycell.PayProofImg = primg;
  1706. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1707. entitycell.ProductId = Convert.ToInt32(productId);
  1708. entitycell.ShopId = shopId;
  1709. entitycell.UpdateTime = DateTime.Now;
  1710. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1711. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1712. {
  1713. entitycell.IsXianHuo = 1;
  1714. }
  1715. entitycell.pay_time = entity.pay_time;
  1716. if (toWhere == "1")
  1717. {
  1718. entitycell.OrderState = 2;
  1719. }
  1720. else
  1721. {
  1722. entitycell.OrderState = 6;
  1723. entitycell.FinishPlaceTime = entitycell.pay_time;
  1724. }
  1725. if (shopId == 94)
  1726. {
  1727. entitycell.OrderState = 4;
  1728. entitycell.WaitDesignTime = entitycell.pay_time;
  1729. entitycell.StartDesignTime = entitycell.pay_time;
  1730. entitycell.DesignUserId = 218;
  1731. }
  1732. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1733. {
  1734. entitycell.OrderState = -1;//修改12-5
  1735. CeWithdraw ceWithdraw = new CeWithdraw();
  1736. ceWithdraw.tid = entity.tid;
  1737. ceWithdraw.providerid = "-1";
  1738. ceWithdraw.status = -1;
  1739. ceWithdraw.creationtime = DateTime.Now;
  1740. ceWithdraw.userid = 1337;
  1741. ceWithdraw.Create();
  1742. }
  1743. entitycell.Create();
  1744. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1745. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1746. {
  1747. addPlaceRegist(entitycell, CurrentUser.UserID);
  1748. }
  1749. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1750. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1751. return;
  1752. }
  1753. }
  1754. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1755. {
  1756. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1757. entity.PlactTime = tradecell.pay_time;
  1758. entity.AddUserId = userid;
  1759. entity.FileName = tradecell.seller_memo;
  1760. entity.Supplier = 24;
  1761. entity.CreateTime = DateTime.Now;
  1762. entity.Did = tradecell.ctid;
  1763. entity.tid = tradecell.tid;
  1764. entity.splitTag = tradecell.SplitTag;
  1765. entity.CurState = "未完成";
  1766. entity.Create();
  1767. }
  1768. public void get_erp_offlinelist()
  1769. {
  1770. DataStruct dStruct = GetPostStruct();
  1771. List<string> lw = new List<string>();
  1772. string tid = GetPostString("ctid");
  1773. string date1 = GetPostString("date1");
  1774. string date2 = GetPostString("date2");
  1775. if (tid.Length > 0 || date1.Length > 0)
  1776. {
  1777. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1778. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1779. if (dw.Length > 0) lw.Add(dw);
  1780. }
  1781. else
  1782. {
  1783. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1784. }
  1785. string shopname = GetPostString("shopname");
  1786. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1787. string buyernick = GetPostString("buyer_nick");
  1788. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1789. string customer = GetPostString("customer");
  1790. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1791. string design = GetPostString("design");
  1792. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1793. string orderState = GetPostString("orderState");
  1794. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1795. string address = GetPostString("address");
  1796. 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));
  1797. string sellermemo = GetPostString("seller_memo");
  1798. if (sellermemo.Length > 0)
  1799. {
  1800. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1801. }
  1802. string price1 = GetPostString("price1");
  1803. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1804. string price2 = GetPostString("price2");
  1805. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1806. //if (PKey != "admin")
  1807. //{
  1808. // string usershop = CurrentUser.User.pemShop;
  1809. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1810. //}
  1811. //if (ex_psize > 0)
  1812. //{
  1813. dStruct.Order = "pay_time desc";
  1814. //}
  1815. //else
  1816. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1817. lw.Add(string.Format("IsOffLineOrder=1"));
  1818. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1819. DataTable dt = null;
  1820. dt = WebCache.GetData("view_erptradecell", dStruct);
  1821. writeGridDataTableJson(dStruct.TotalCount, dt);
  1822. }
  1823. public void get_erp_returncashrecord()
  1824. {
  1825. DataStruct dStruct = GetPostStruct();
  1826. List<string> lw = new List<string>();
  1827. string tid = GetPostString("ctid");
  1828. if (tid.Length > 0)
  1829. {
  1830. lw.Add(string.Format("tid like '%{0}%'", tid));
  1831. dStruct.Order = "id desc";
  1832. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1833. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1834. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1835. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1836. return;
  1837. }
  1838. returnErrorMsg("id数据错误!");
  1839. }
  1840. public void ins_erp_returncashrecord()
  1841. {
  1842. if (UrlPostParmsCheck("tid"))
  1843. {
  1844. string tid = GetPostString("tid");
  1845. string retype = GetPostString("type");
  1846. StringBuilder sql = new StringBuilder();
  1847. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1848. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1849. if (dt.Rows.Count > 0)
  1850. {
  1851. returnErrorMsg("相同返现类型记录已存在");
  1852. return;
  1853. }
  1854. CeErpReturnCash entity = new CeErpReturnCash();
  1855. entity.tid = tid;
  1856. entity.seller_nick = GetPostString("seller_nick");
  1857. string pment = GetPostString("payment");
  1858. if (pment.Length > 0)
  1859. {
  1860. entity.payment = Convert.ToDouble(pment);
  1861. }
  1862. entity.buyer_nick = GetPostString("buyer_nick");
  1863. entity.cashstate = 0;
  1864. entity.rtype = retype;
  1865. string rPrice = GetPostString("returnprice");
  1866. if (rPrice.Length > 0)
  1867. {
  1868. entity.returnprice = Convert.ToDouble(rPrice);
  1869. }
  1870. entity.created = DateTime.Now;
  1871. entity.con = GetPostString("con");
  1872. entity.img = GetPostString("img");
  1873. entity.applyuserid = CurrentUser.UserID;
  1874. entity.Create();
  1875. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1876. returnSuccessMsg("操作成功!");
  1877. return;
  1878. }
  1879. }
  1880. public void set_erp_predelivery()
  1881. {
  1882. if (UrlPostParmsCheck("ctid"))
  1883. {
  1884. string eid = GetPostString("ctid");
  1885. CeErpTradeCell entity = null;
  1886. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1887. if (entity != null)
  1888. {
  1889. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1890. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1891. //{
  1892. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1893. // return;
  1894. //}
  1895. entity.IsPreDelivery = 1;
  1896. entity.Update();
  1897. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1898. returnSuccessMsg("预发货成功!");
  1899. return;
  1900. //string shop = GetPostString("seller_nick");
  1901. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1902. //string comName = GetPostString("comName");
  1903. //string comCode = GetPostString("comCode");
  1904. //string outSid = GetPostString("outSid");//运单号
  1905. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1906. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1907. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1908. //string apires = "";
  1909. //if (deliveryType == "虚拟发货")
  1910. //{
  1911. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1912. //}
  1913. //else
  1914. //{
  1915. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1916. //}
  1917. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1918. ////{
  1919. //if (apires.IndexOf("发货成功") != -1)
  1920. //{
  1921. // if (deliveryType != "虚拟发货")
  1922. // {
  1923. // //还要插入快递信息到 快递信息表
  1924. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1925. // exinfo.tid = eid;
  1926. // exinfo.out_sid = outSid;
  1927. // exinfo.company_code = comCode;
  1928. // exinfo.company_name = comName;
  1929. // exinfo.delivery_memo = deliveryMemo;
  1930. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1931. // exinfo.deliveryType = deliveryType;
  1932. // exinfo.Create();
  1933. // }
  1934. // returnSuccessMsg("发货成功!");
  1935. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1936. //}
  1937. //else
  1938. //{
  1939. // returnErrorMsg("淘宝发货失败!!");
  1940. //}
  1941. //return;
  1942. }
  1943. returnErrorMsg("找不到订单记录");
  1944. }
  1945. }
  1946. public void get_erp_unusuallist()
  1947. {
  1948. DataStruct dStruct = GetPostStruct();
  1949. List<string> lw = new List<string>();
  1950. string tid = GetPostString("ctid");
  1951. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1952. string shopname = GetPostString("shopname");
  1953. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1954. string buyernick = GetPostString("buyer_nick");
  1955. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1956. string ResponsibleMan = GetPostString("responsible");
  1957. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1958. string date1 = GetPostString("date1");
  1959. string date2 = GetPostString("date2");
  1960. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1961. if (dw.Length > 0) lw.Add(dw);
  1962. string price1 = GetPostString("price1");
  1963. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1964. string price2 = GetPostString("price2");
  1965. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1966. string orderState = GetPostString("orderState");
  1967. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1968. string sellermemo = GetPostString("seller_memo");
  1969. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1970. lw.Add(string.Format("UnusualTag > 0"));
  1971. lw.Add(string.Format("IsRefund<={0}", 1));
  1972. dStruct.Order = "pay_time desc";
  1973. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1974. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1975. writeGridDataTableJson(dStruct.TotalCount, dt);
  1976. }
  1977. public void set_erp_unusualtonomal()
  1978. {
  1979. if (UrlPostParmsCheck("ctid"))
  1980. {
  1981. string eid = GetPostString("ctid");
  1982. CeErpTradeCell entity = null;
  1983. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1984. if (entity != null)
  1985. {
  1986. entity.UnusualTag = -1;
  1987. entity.Update();
  1988. returnSuccessMsg("忽略成功!");
  1989. return;
  1990. }
  1991. returnErrorMsg("找不到记录");
  1992. }
  1993. }
  1994. public void ins_erp_unusualreason()
  1995. {
  1996. if (UrlPostParmsCheck("ctid"))
  1997. {
  1998. string eid = GetPostString("ctid");
  1999. CeErpTradeCell entity = null;
  2000. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2001. if (entity != null)
  2002. {
  2003. entity.MemoOpt = 4;
  2004. entity.UnusualCon = GetPostString("con");
  2005. entity.Update();
  2006. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2007. if (trade != null)
  2008. {
  2009. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2010. }
  2011. //查货是否超时
  2012. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2013. if (ceErpTradeCellExtend == null)
  2014. {
  2015. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2016. ceErpTradeCellExtend.ctid = entity.ctid;
  2017. }
  2018. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2019. {
  2020. ceErpTradeCellExtend.CheckOut += 1;
  2021. }
  2022. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2023. if (ceErpTradeCellExtend.ID > 0)
  2024. {
  2025. ceErpTradeCellExtend.Update();
  2026. }
  2027. else
  2028. {
  2029. ceErpTradeCellExtend.Create();
  2030. }
  2031. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2032. returnSuccessMsg("操作成功!");
  2033. return;
  2034. }
  2035. returnErrorMsg("找不到记录");
  2036. }
  2037. }
  2038. public void upd_erp_sampleorder()
  2039. {
  2040. if (UrlPostParmsCheck("ctid"))
  2041. {
  2042. string eid = GetPostString("ctid");
  2043. string[] eArr = eid.Split(',');
  2044. if (eArr.Length > 1)
  2045. {
  2046. List<string> eLst = new List<string>();
  2047. for (int i = 0; i < eArr.Length; i++)
  2048. {
  2049. eLst.Add("'" + eArr[i] + "'");
  2050. }
  2051. eid = string.Join(",", eLst.ToArray());
  2052. }
  2053. else
  2054. {
  2055. eid = "'" + eid + "'";
  2056. }
  2057. StringBuilder sql = new StringBuilder();
  2058. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2059. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2060. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2061. if (dt.Rows.Count > 0)
  2062. {
  2063. string errmsg = "";
  2064. foreach (DataRow dr in dt.Rows)
  2065. {
  2066. StringBuilder sqlsb = new StringBuilder();
  2067. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2068. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2069. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2070. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2071. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2072. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2073. {
  2074. continue;
  2075. }
  2076. else
  2077. {
  2078. string emsg = commonHelper.KeepChinese(apires);
  2079. errmsg += emsg;
  2080. }
  2081. }
  2082. if (errmsg.Length > 0)
  2083. {
  2084. returnErrorMsg(errmsg);
  2085. return;
  2086. }
  2087. returnSuccessMsg("操作成功");
  2088. return;
  2089. }
  2090. returnErrorMsg("找不到记录");
  2091. }
  2092. }
  2093. public void upd_erp_transcustomer()
  2094. {
  2095. if (UrlPostParmsCheck("ctid"))
  2096. {
  2097. string eid = GetPostString("ctid");
  2098. int userid = GetPostInt("CustomerUserId");
  2099. CeErpTradeCell entity = null;
  2100. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2101. if (entity != null)
  2102. {
  2103. //string[] mlist = entity.seller_memo.Split('-');
  2104. //string sql = "select * from view_erpuser where id=" + userid;
  2105. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2106. //if (dt != null && dt.Rows.Count > 0)
  2107. //{
  2108. // string nmemo = "";
  2109. // for(int i = 0; i < mlist.Length - 1; i++)
  2110. // {
  2111. // nmemo += mlist[i];
  2112. // nmemo += "-";
  2113. // }
  2114. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2115. // entity.seller_memo = nmemo;
  2116. //}
  2117. entity.CustomerUserId = userid;
  2118. entity.Update();
  2119. returnSuccessMsg("操作成功!");
  2120. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2121. return;
  2122. }
  2123. returnErrorMsg("找不到记录");
  2124. }
  2125. }
  2126. public void upd_erp_transdesigner()
  2127. {
  2128. if (UrlPostParmsCheck("ctid"))
  2129. {
  2130. string eids = GetPostString("ctid");
  2131. string[] ctidList = eids.Split(',');
  2132. int userid = GetPostInt("DesignUserId");
  2133. foreach (string ctid in ctidList)
  2134. {
  2135. CeErpTradeCell entity = null;
  2136. CeErpDesignerBill entitys = null;
  2137. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2138. entitys = CeErpDesignerBill.GetByTid(ctid);
  2139. if (entity != null)
  2140. {
  2141. if (entity.OrderState > 4)
  2142. {
  2143. continue;
  2144. }
  2145. //存在退款不能流转
  2146. if (entity.IsRefund > 0)
  2147. {
  2148. continue;
  2149. }
  2150. entity.DesignUserId = userid;
  2151. entity.WaitDesignTime = DateTime.Now;
  2152. entity.Update();
  2153. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2154. }
  2155. }
  2156. returnSuccessMsg("操作成功!");
  2157. }
  2158. }
  2159. public void upd_erp_distributedesigner()
  2160. {
  2161. if (UrlPostParmsCheck("ctid"))
  2162. {
  2163. string eid = GetPostString("ctid");
  2164. int userid = GetPostInt("DesignUserId");
  2165. string[] idlist = eid.Split(',');
  2166. if (idlist.Length <= 0)
  2167. {
  2168. returnErrorMsg("订单不能为空");
  2169. return;
  2170. }
  2171. foreach (string ctid in idlist)
  2172. {
  2173. CeErpTradeCell entity = null;
  2174. CeErpDesignerBill entitys = null;
  2175. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2176. else continue;
  2177. if (entity != null)
  2178. {
  2179. if (userid == 2125 || userid == 3542)
  2180. { }
  2181. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2182. {
  2183. returnErrorMsg("金额错误的订单无法指派");
  2184. return;
  2185. }
  2186. if (entity.OrderState >= 5)
  2187. {
  2188. returnErrorMsg("已经设计完成无法指派");
  2189. return;
  2190. }
  2191. if (entity.OrderState == -1)
  2192. {
  2193. returnErrorMsg("审核中的订单无法指派");
  2194. return;
  2195. }
  2196. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2197. {
  2198. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2199. return;
  2200. }
  2201. //157赖橙帆 159林晨 73 静之颖
  2202. 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)
  2203. {
  2204. returnErrorMsg("指派设计共创无法再次指派!");
  2205. return;
  2206. }
  2207. entity.OrderState = 3;
  2208. if (entity.SupplierId == 0)
  2209. {
  2210. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2211. entity.SupplierId = suid;
  2212. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2213. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2214. }
  2215. if (userid == 2125 && entity.seller_memo != "")
  2216. {
  2217. apiDesign.API_GetPrintData_CreateOrder(entity);
  2218. }
  2219. if (userid == 3542 && entity.seller_memo != "")
  2220. {
  2221. string userPost = CurrentUser.UserPost.Post.Code;
  2222. if (CurrentUser.UserID == 73)
  2223. {
  2224. userPost = "SysAdmin";
  2225. }
  2226. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2227. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2228. if (response.msg != "设计共创:成功")
  2229. {
  2230. returnErrorMsg(response.msg);
  2231. return;
  2232. }
  2233. entity.DispatchSort = 2;
  2234. }
  2235. else
  2236. {
  2237. if (entity.DispatchSort == 2)
  2238. {
  2239. ApiVo apiVo = new ApiVo();
  2240. apiVo.actionName = "closeDesign";
  2241. apiVo.orderNumber = entity.ctid;
  2242. designHelper.API_WorkCore(apiVo);//closeDesign
  2243. }
  2244. entity.DispatchSort = 0;
  2245. }
  2246. entity.DesignUserId = userid;
  2247. entity.WaitDesignTime = DateTime.Now;
  2248. entity.UpdateTime = DateTime.Now;
  2249. entity.Update();
  2250. string name = commonHelper.getUserNameById(userid);
  2251. commonHelper.UpdateRelationOrder(entity.ctid);
  2252. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2253. }
  2254. }
  2255. returnSuccessMsg("操作成功!");
  2256. return;
  2257. }
  2258. }
  2259. public string getTidByCtid(string ctid)
  2260. {
  2261. string tid = "";
  2262. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2263. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2264. if (dataTable != null && dataTable.Rows.Count > 0)
  2265. {
  2266. tid = dataTable.Rows[0]["tid"].ToString();
  2267. }
  2268. return tid;
  2269. }
  2270. public List<string> getTidByCtidMore(string ctid)
  2271. {
  2272. 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);
  2273. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2274. List<string> list = new List<string>();
  2275. if (dataTable != null && dataTable.Rows.Count > 0)
  2276. {
  2277. foreach (DataRow item in dataTable.Rows)
  2278. {
  2279. list.Add("'" + item["tid"].ToString() + "'");
  2280. }
  2281. }
  2282. return list;
  2283. }
  2284. public List<string> getTidByCtidLike(string ctid)
  2285. {
  2286. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2287. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2288. List<string> list = new List<string>();
  2289. if (dataTable != null && dataTable.Rows.Count > 0)
  2290. {
  2291. foreach (DataRow item in dataTable.Rows)
  2292. {
  2293. list.Add("'" + item["tid"].ToString() + "'");
  2294. }
  2295. }
  2296. return list;
  2297. }
  2298. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2299. {
  2300. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2301. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2302. List<string> list = new List<string>();
  2303. if (dataTable != null && dataTable.Rows.Count > 0)
  2304. {
  2305. foreach (DataRow item in dataTable.Rows)
  2306. {
  2307. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2308. {
  2309. continue;
  2310. }
  2311. list.Add("'" + item["receiverId"].ToString() + "'");
  2312. }
  2313. }
  2314. return list;
  2315. }
  2316. public void get_erp_myorderlist()
  2317. {
  2318. DataStruct dStruct = GetPostStruct();
  2319. List<string> lw = new List<string>();
  2320. string tid = GetPostString("ctid");
  2321. if (tid.Length > 0)
  2322. {
  2323. string select_tid = getTidByCtid(tid);
  2324. lw.Add(string.Format("tid='{0}'", select_tid));
  2325. }
  2326. else
  2327. {
  2328. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2329. }
  2330. //12-1 修改
  2331. string urgent = GetPostString("urgent");
  2332. string back = GetPostString("back");
  2333. string offlineSearch = GetPostString("offlineSearch");
  2334. if (!string.IsNullOrWhiteSpace(urgent))
  2335. {
  2336. if (urgent.Equals("true"))
  2337. {
  2338. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2339. }
  2340. }
  2341. if (!string.IsNullOrWhiteSpace(back))
  2342. {
  2343. if (back.Equals("true"))
  2344. {
  2345. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2346. }
  2347. }
  2348. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2349. {
  2350. if (offlineSearch.Equals("true"))
  2351. {
  2352. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2353. }
  2354. }
  2355. //end
  2356. string shopname = GetPostString("shopname");
  2357. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2358. string buyernick = GetPostString("buyer_nick");
  2359. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2360. string design = GetPostString("design");
  2361. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2362. string orderState = GetPostString("orderState");
  2363. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2364. string sellermemo = GetPostString("seller_memo");
  2365. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2366. string date1 = GetPostString("date1");
  2367. string date2 = GetPostString("date2");
  2368. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2369. if (dw.Length > 0) lw.Add(dw);
  2370. string price1 = GetPostString("price1");
  2371. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2372. string price2 = GetPostString("price2");
  2373. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2374. string urgency = GetPostString("urgency");
  2375. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2376. string after = GetPostString("after");
  2377. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2378. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2379. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2380. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2381. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2382. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2383. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2384. if (dt != null && dt.Rows.Count > 0)
  2385. {
  2386. foreach (DataRow dr in dt.Rows)
  2387. {
  2388. try
  2389. {
  2390. // 对象操作
  2391. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2392. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2393. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2394. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2395. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2396. if (dStruct.PageSize != 100000)
  2397. {
  2398. if (dr["DispatchSort"].ToString() == "2")
  2399. {
  2400. dr["gongchuang"] = 200;
  2401. }
  2402. else if ("外协".Equals(dr["ToType"].ToString()))
  2403. {
  2404. dr["gongchuang"] = 200;
  2405. }
  2406. else if ("内部".Equals(dr["ToType"].ToString()))
  2407. {
  2408. dr["gongchuang"] = -1;
  2409. }
  2410. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2411. {
  2412. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2413. dr["gongchuang"] = response.code;
  2414. }
  2415. }
  2416. }
  2417. catch (NullReferenceException ex)
  2418. {
  2419. }
  2420. }
  2421. }
  2422. writeGridDataTableJson(dStruct.TotalCount, dt);
  2423. }
  2424. public void get_erp_myreturnorderlist()
  2425. {
  2426. DataStruct dStruct = GetPostStruct();
  2427. List<string> lw = new List<string>();
  2428. string tid = GetPostString("ctid");
  2429. if (tid.Length > 0)
  2430. {
  2431. string select_tid = getTidByCtid(tid);
  2432. lw.Add(string.Format("tid='{0}'", select_tid));
  2433. }
  2434. else
  2435. {
  2436. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2437. }
  2438. string shopname = GetPostString("shopname");
  2439. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2440. string buyernick = GetPostString("buyer_nick");
  2441. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2442. string design = GetPostString("design");
  2443. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2444. string orderState = GetPostString("orderState");
  2445. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2446. string sellermemo = GetPostString("seller_memo");
  2447. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2448. string date1 = GetPostString("date1");
  2449. string date2 = GetPostString("date2");
  2450. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2451. if (dw.Length > 0) lw.Add(dw);
  2452. string price1 = GetPostString("price1");
  2453. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2454. string price2 = GetPostString("price2");
  2455. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2456. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2457. {
  2458. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2459. }
  2460. else
  2461. {
  2462. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2463. }
  2464. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2465. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2466. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2467. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2468. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2469. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2470. if (dt != null && dt.Rows.Count > 0)
  2471. {
  2472. foreach (DataRow dr in dt.Rows)
  2473. {
  2474. try
  2475. {
  2476. // 对象操作
  2477. if (dStruct.PageSize != 100000)
  2478. {
  2479. if (dr["DispatchSort"].ToString() == "2")
  2480. {
  2481. dr["gongchuang"] = 200;
  2482. }
  2483. else if ("外协".Equals(dr["ToType"].ToString()))
  2484. {
  2485. dr["gongchuang"] = 200;
  2486. }
  2487. else if ("内部".Equals(dr["ToType"].ToString()))
  2488. {
  2489. dr["gongchuang"] = -1;
  2490. }
  2491. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2492. {
  2493. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2494. dr["gongchuang"] = response.code;
  2495. }
  2496. }
  2497. }
  2498. catch (NullReferenceException ex)
  2499. {
  2500. // 处理空引用异常
  2501. }
  2502. }
  2503. }
  2504. writeGridDataTableJson(dStruct.TotalCount, dt);
  2505. }
  2506. public void get_erp_myorderlist_pregather()
  2507. {
  2508. string date1 = GetPostString("date1");
  2509. string date2 = GetPostString("date2");
  2510. int userId = CurrentUser.UserID; //客服id
  2511. string orderWhere = "";
  2512. List<string> lw = new List<string>();
  2513. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2514. if (dw.Length > 0) lw.Add(dw);
  2515. lw.Add(string.Format("CustomerUserId={0}", userId));
  2516. lw.Add(string.Format("OrderState<9"));
  2517. orderWhere = string.Join(" and ", lw.ToArray());
  2518. string orderWhere2 = "";
  2519. List<string> lw2 = new List<string>();
  2520. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2521. if (dw2.Length > 0) lw2.Add(dw2);
  2522. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2523. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2524. string sql = string.Format("select *" +
  2525. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2526. "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 " +
  2527. "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 " +
  2528. "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");
  2529. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2530. //writeGridDataTableJson(dt.Rows.Count, dt);
  2531. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2532. }
  2533. public void upd_erp_publishorder()
  2534. {
  2535. if (UrlPostParmsCheck("ctid"))
  2536. {
  2537. string eid = GetPostString("ctid");
  2538. CeErpTradeCell entity = null;
  2539. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2540. if (entity != null)
  2541. {
  2542. entity.OrderState = 0; //发布后,变为待抢单
  2543. entity.Update();
  2544. commonHelper.UpdateRelationOrder(entity.ctid);
  2545. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2546. returnSuccessMsg("发布成功!");
  2547. return;
  2548. }
  2549. returnErrorMsg("找不到记录");
  2550. }
  2551. }
  2552. public void get_erp_my_tiporder()
  2553. {
  2554. StringBuilder sql = new StringBuilder();
  2555. int userId = 0;
  2556. if (CurrentUser != null) userId = CurrentUser.UserID;
  2557. string posCode = CurrentUser.UserPost.Post.Code;
  2558. string isTipedAfterSaleVerify = GetPostString("af");
  2559. DataTable dt = new DataTable();
  2560. if (posCode != "Supplier")
  2561. {
  2562. if (posCode == "CustomerService" || posCode == "Director")
  2563. {
  2564. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2565. }
  2566. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2567. {
  2568. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2569. }
  2570. else
  2571. {
  2572. string teamIds = CurrentUser.User.TeamIds;
  2573. if (teamIds == "")
  2574. {
  2575. teamIds = "0";
  2576. }
  2577. 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);
  2578. }
  2579. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2580. }
  2581. if (dt.Rows.Count <= 0)
  2582. {
  2583. string key = "aftersale_order_" + userId;
  2584. if (RedisHelper.HasKey(key))
  2585. {
  2586. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2587. dt.Columns.Add("ctid", typeof(string));
  2588. dt.Columns.Add("IsReadTag", typeof(int));
  2589. foreach (var i in list)
  2590. {
  2591. DataRow data = dt.NewRow();
  2592. data["ctid"] = i;
  2593. data["IsReadTag"] = 4;
  2594. dt.Rows.Add(data);
  2595. }
  2596. RedisHelper.StringDelete(key);
  2597. }
  2598. }
  2599. if (dt.Rows.Count <= 0)
  2600. {
  2601. sql = new StringBuilder();
  2602. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2603. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2604. }
  2605. if (posCode == "Supplier")
  2606. {
  2607. string ids = CurrentUser.User.pemVend;
  2608. if (ids != null && ids.Length > 0)
  2609. {
  2610. string[] ids_list = ids.Split(',');
  2611. foreach (var item in ids_list)
  2612. {
  2613. string key = "return_order_" + item;
  2614. if (RedisHelper.HasKey(key))
  2615. {
  2616. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2617. dt.Columns.Add("ctid", typeof(string));
  2618. dt.Columns.Add("IsReadTag", typeof(int));
  2619. foreach (var i in list)
  2620. {
  2621. DataRow data = dt.NewRow();
  2622. data["ctid"] = i;
  2623. data["IsReadTag"] = 1;
  2624. dt.Rows.Add(data);
  2625. }
  2626. RedisHelper.StringDelete(key);
  2627. }
  2628. }
  2629. }
  2630. if (dt.Rows.Count <= 0)
  2631. {
  2632. sql = new StringBuilder();
  2633. 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);
  2634. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2635. }
  2636. }
  2637. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2638. }
  2639. public void reset_erp_tiporder()
  2640. {
  2641. string ids = GetPostString("ids");
  2642. string[] ctidList = ids.Split(',');
  2643. foreach (string ctid in ctidList)
  2644. {
  2645. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2646. if (enty != null)
  2647. {
  2648. enty.IsReadTag = 0;
  2649. enty.Update();
  2650. }
  2651. }
  2652. returnSuccessMsg("成功!");
  2653. return;
  2654. }
  2655. public void get_erp_designlist()
  2656. {
  2657. DataStruct dStruct = GetPostStruct();
  2658. List<string> lw = new List<string>();
  2659. string tid = GetPostString("ctid");
  2660. if (tid.Length > 0)
  2661. {
  2662. string select_tid = getTidByCtid(tid);
  2663. lw.Add(string.Format("tid='{0}'", select_tid));
  2664. }
  2665. string shopname = GetPostString("shopname");
  2666. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2667. string buyernick = GetPostString("buyer_nick");
  2668. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2669. string customer = GetPostString("customer");
  2670. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2671. string design = GetPostString("design");
  2672. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2673. string orderState = GetPostString("orderState");
  2674. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2675. lw.Add(string.Format("OrderState<6"));
  2676. string address = GetPostString("address");
  2677. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2678. string sellermemo = GetPostString("seller_memo");
  2679. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2680. string date1 = GetPostString("date1");
  2681. string date2 = GetPostString("date2");
  2682. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2683. if (dw.Length > 0) lw.Add(dw);
  2684. string apdate1 = GetPostString("apdate1");
  2685. string apdate2 = GetPostString("apdate2");
  2686. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2687. if (dwap.Length > 0) lw.Add(dwap);
  2688. string price1 = GetPostString("price1");
  2689. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2690. string price2 = GetPostString("price2");
  2691. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2692. string designTime = GetPostString("designtime");
  2693. if (designTime.Length > 0)
  2694. {
  2695. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2696. }
  2697. string usershop = CurrentUser.User.pemShop;
  2698. if (usershop.Length > 0)
  2699. {
  2700. lw.Add(string.Format("shopId in ({0})", usershop));
  2701. }
  2702. int myOrgid = CurrentUser.UserPost.OrgID;
  2703. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2704. if (myOrgCode.IndexOf("Designer") != -1)
  2705. {
  2706. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2707. {
  2708. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2709. }
  2710. else
  2711. {
  2712. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2713. }
  2714. }
  2715. else
  2716. {
  2717. string orgId = GetPostString("designerhd");
  2718. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2719. }
  2720. if (tid.Length > 0 || buyernick.Length > 0)
  2721. {
  2722. lw.Add(string.Format("OrderState >= 3"));
  2723. }
  2724. else
  2725. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2726. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2727. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2728. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2729. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2730. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2731. if (dt != null && dt.Rows.Count > 0)
  2732. {
  2733. foreach (DataRow dr in dt.Rows)
  2734. {
  2735. try
  2736. {
  2737. // 对象操作
  2738. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2739. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2740. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2741. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2742. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2743. if (dStruct.PageSize != 100000)
  2744. {
  2745. if (dr["DispatchSort"].ToString() == "2")
  2746. {
  2747. dr["gongchuang"] = 200;
  2748. }
  2749. else if ("外协".Equals(dr["ToType"].ToString()))
  2750. {
  2751. dr["gongchuang"] = 200;
  2752. }
  2753. else if ("内部".Equals(dr["ToType"].ToString()))
  2754. {
  2755. dr["gongchuang"] = -1;
  2756. }
  2757. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2758. {
  2759. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2760. dr["gongchuang"] = response.code;
  2761. }
  2762. }
  2763. }
  2764. catch (NullReferenceException ex)
  2765. {
  2766. }
  2767. }
  2768. }
  2769. writeGridDataTableJson(dStruct.TotalCount, dt);
  2770. }
  2771. public void get_erp_mydesignlist()
  2772. {
  2773. DataStruct dStruct = GetPostStruct();
  2774. List<string> lw = new List<string>();
  2775. string tid = GetPostString("ctid");
  2776. if (tid.Length > 0)
  2777. {
  2778. string select_tid = getTidByCtid(tid);
  2779. lw.Add(string.Format("tid='{0}'", select_tid));
  2780. }
  2781. string shopname = GetPostString("shopname");
  2782. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2783. string buyernick = GetPostString("buyer_nick");
  2784. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2785. string customer = GetPostString("customer");
  2786. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2787. string orderState = GetPostString("orderState");
  2788. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2789. //lw.Add(string.Format("OrderState<6"));
  2790. string date1 = GetPostString("date1");
  2791. string date2 = GetPostString("date2");
  2792. string dw = GetDateWhere("pay_time", date1, date2);
  2793. if (dw.Length > 0) lw.Add(dw);
  2794. string apdate1 = GetPostString("apdate1");
  2795. string apdate2 = GetPostString("apdate2");
  2796. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2797. if (dwap.Length > 0) lw.Add(dwap);
  2798. string price1 = GetPostString("price1");
  2799. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2800. string price2 = GetPostString("price2");
  2801. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2802. string olddownload = GetPostString("olddown");
  2803. if (olddownload == "1")
  2804. {
  2805. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2806. }
  2807. else if (olddownload == "2")
  2808. {
  2809. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2810. }
  2811. string sellermemo = GetPostString("seller_memo");
  2812. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2813. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2814. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2815. {
  2816. if (CurrentUser.User.TeamIds.Length > 0)
  2817. {
  2818. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2819. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2820. else
  2821. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2822. }
  2823. else
  2824. {
  2825. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2826. }
  2827. }
  2828. if (tid.Length <= 0)
  2829. {
  2830. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2831. }
  2832. lw.Add(string.Format("IsReturn!=3"));
  2833. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2834. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2835. string teamids = CurrentUser.User.TeamIds.ToString();
  2836. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2837. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2838. if (dt != null && dt.Rows.Count > 0)
  2839. {
  2840. foreach (DataRow dr in dt.Rows)
  2841. {
  2842. try
  2843. {
  2844. // 对象操作
  2845. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2846. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2847. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2848. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2849. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2850. if (dStruct.PageSize != 100000)
  2851. {
  2852. if (dr["DispatchSort"].ToString() == "2")
  2853. {
  2854. dr["gongchuang"] = 200;
  2855. }
  2856. else if ("外协".Equals(dr["ToType"].ToString()))
  2857. {
  2858. dr["gongchuang"] = 200;
  2859. }
  2860. else if ("内部".Equals(dr["ToType"].ToString()))
  2861. {
  2862. dr["gongchuang"] = -1;
  2863. }
  2864. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2865. {
  2866. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2867. dr["gongchuang"] = response.code;
  2868. }
  2869. }
  2870. }
  2871. catch (NullReferenceException ex)
  2872. {
  2873. }
  2874. }
  2875. }
  2876. writeGridDataTableJson(dStruct.TotalCount, dt);
  2877. }
  2878. public void set_erp_startdesign()
  2879. {
  2880. if (UrlPostParmsCheck("ctid"))
  2881. {
  2882. string eid = GetPostString("ctid");
  2883. CeErpTradeCell entity = null;
  2884. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2885. if (entity != null)
  2886. {
  2887. if (entity.OrderState != 3)
  2888. {
  2889. returnErrorMsg("请刷新,订单已经设计了");
  2890. return;
  2891. }
  2892. entity.StartDesignTime = DateTime.Now;
  2893. entity.OrderState = 4;
  2894. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2895. {
  2896. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2897. entity.SupplierId = suid;
  2898. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2899. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2900. }
  2901. entity.UpdateTime = DateTime.Now;
  2902. //entity.MakeSupplier = suname;
  2903. entity.Update();
  2904. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2905. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2906. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2907. commonHelper.getCytPrice(entity);
  2908. returnSuccessMsg("操作成功!");
  2909. return;
  2910. }
  2911. returnErrorMsg("找不到记录");
  2912. }
  2913. }
  2914. public void ins_erp_designselfmemo()
  2915. {
  2916. if (UrlPostParmsCheck("ctid"))
  2917. {
  2918. string eid = GetPostString("ctid");
  2919. string con = GetPostString("con");
  2920. CeErpTradeCell entity = null;
  2921. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2922. if (entity != null)
  2923. {
  2924. entity.DesignSelfMemo = con;
  2925. entity.Update();
  2926. returnSuccessMsg("操作成功!");
  2927. return;
  2928. }
  2929. returnErrorMsg("找不到记录");
  2930. }
  2931. }
  2932. public void ins_erp_designprice()
  2933. {
  2934. if (UrlPostParmsCheck("ctid"))
  2935. {
  2936. string eid = GetPostString("ctid");
  2937. int uid = CurrentUser.UserID;
  2938. string userName = CurrentUser.UserName;
  2939. CeErpTradeCell entity = null;
  2940. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2941. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2942. if (entitys == null)
  2943. {
  2944. entitys = new CeErpDesignerBill();
  2945. }
  2946. if (entity != null)
  2947. {
  2948. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2949. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2950. entity.StartDesignTime = DateTime.Now;
  2951. entity.OrderState = 4;
  2952. string suname = "";
  2953. if (entity.SupplierId == 0)
  2954. {
  2955. int sid = commonHelper.autoDistributeToSupplier(entity);
  2956. entity.SupplierId = sid;
  2957. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2958. }
  2959. entity.Update();
  2960. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2961. if (ceErpUserPost != null)
  2962. {
  2963. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2964. if (ceErpPost != null)
  2965. {
  2966. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2967. {
  2968. entitys.tid = entity.ctid;
  2969. entitys.oid = entity.tid;
  2970. entitys.uid = uid;
  2971. entitys.userName = userName;
  2972. entitys.designerType = 1;
  2973. entitys.designerTypeText = "内部设计师";
  2974. entitys.price = Convert.ToDouble(GetPostString("price"));
  2975. entitys.designNum = GetPostInt("designNum");
  2976. entitys.modifyNum = GetPostInt("modifyNum");
  2977. entitys.designSize = GetPostString("designSize");
  2978. entitys.modifySize = GetPostString("modifySize");
  2979. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2980. {
  2981. entitys.create_time = DateTime.Now;
  2982. entitys.create_u_id = uid;
  2983. entitys.create_u_name = userName;
  2984. entitys.Save();
  2985. }
  2986. else
  2987. {
  2988. entitys.update_time = DateTime.Now;
  2989. entitys.update_u_id = uid;
  2990. entitys.update_u_name = userName;
  2991. entitys.Update();
  2992. }
  2993. }
  2994. }
  2995. }
  2996. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2997. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2998. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2999. if (suname != "")
  3000. {
  3001. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3002. }
  3003. commonHelper.getCytPrice(entity);
  3004. returnSuccessMsg("操作成功!");
  3005. return;
  3006. }
  3007. returnErrorMsg("找不到记录");
  3008. }
  3009. }
  3010. public void upload_erp_filecomplete()
  3011. {
  3012. if (UrlPostParmsCheck("ctid"))
  3013. {
  3014. string eid = GetPostString("ctid");
  3015. CeErpTradeCell entity = null;
  3016. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3017. if (entity != null)
  3018. {
  3019. entity.OrderState = 5; //设计完成
  3020. entity.Update();
  3021. returnSuccessMsg(eid + "上传成功,设计完成!");
  3022. return;
  3023. }
  3024. returnErrorMsg("找不到订单记录");
  3025. }
  3026. }
  3027. public void get_erp_designovertimelist()
  3028. {
  3029. DataStruct dStruct = GetPostStruct();
  3030. List<string> lw = new List<string>();
  3031. string tid = GetPostString("ctid");
  3032. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3033. string shopname = GetPostString("shopname");
  3034. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3035. string buyernick = GetPostString("buyer_nick");
  3036. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3037. string ResponsibleMan = GetPostString("responsible");
  3038. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3039. string date1 = GetPostString("date1");
  3040. string date2 = GetPostString("date2");
  3041. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3042. if (dw.Length > 0) lw.Add(dw);
  3043. string price1 = GetPostString("price1");
  3044. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3045. string price2 = GetPostString("price2");
  3046. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3047. string orderState = GetPostString("orderState");
  3048. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3049. string sellermemo = GetPostString("seller_memo");
  3050. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3051. lw.Add(string.Format("UnusualTag=3"));
  3052. lw.Add(string.Format("IsRefund<={0}", 1));
  3053. dStruct.Order = "WaitDesignTime desc";
  3054. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3055. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3056. writeGridDataTableJson(dStruct.TotalCount, dt);
  3057. }
  3058. //设计管理 获取抢单大厅列表
  3059. public void get_erp_grabinglist()
  3060. {
  3061. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3062. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3063. bool oldOrder = false;
  3064. if (org != null)
  3065. {
  3066. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3067. }
  3068. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3069. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3070. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3071. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3072. //先处理订单数据
  3073. if (dt.Rows.Count > 0)
  3074. {
  3075. Dictionary<string, int> design = null;
  3076. int count = 0;
  3077. foreach (DataRow row in dt.Rows)
  3078. {
  3079. if (map.ContainsKey(row["ShopId"].ToString()))
  3080. {
  3081. map.TryGetValue(row["ShopId"].ToString(), out design);
  3082. }
  3083. else
  3084. {
  3085. design = new Dictionary<string, int>();
  3086. }
  3087. if (design.ContainsKey(row["ProductId"].ToString()))
  3088. {
  3089. design.TryGetValue(row["ProductId"].ToString(), out count);
  3090. }
  3091. count++;
  3092. design[row["ProductId"].ToString()] = count;
  3093. map[row["ShopId"].ToString()] = design;
  3094. }
  3095. }
  3096. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3097. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3098. //把店铺排序和技能排序分类
  3099. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3100. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3101. if (design_dt.Rows.Count > 0)
  3102. {
  3103. Dictionary<string, string> design = null;
  3104. List<string> shopIds = null;
  3105. foreach (DataRow row in design_dt.Rows)
  3106. {
  3107. if ("0".Equals(row["designId"].ToString()))
  3108. {
  3109. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3110. {
  3111. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3112. }
  3113. else
  3114. {
  3115. shopIds = new List<string>();
  3116. }
  3117. shopIds.Add(row["shopId"].ToString());
  3118. shop_orders[row["orders"].ToString()] = shopIds;
  3119. }
  3120. else
  3121. {
  3122. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3123. {
  3124. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3125. }
  3126. else
  3127. {
  3128. design = new Dictionary<string, string>();
  3129. }
  3130. design[row["orders"].ToString()] = row["designId"].ToString();
  3131. design_orders[row["shopId"].ToString()] = design;
  3132. }
  3133. }
  3134. //处理成key value后根据key排序
  3135. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3136. foreach (List<string> val in shop_orders.Values)
  3137. {
  3138. if (val != null)
  3139. {
  3140. foreach (string key in val)
  3141. {
  3142. if (design_orders.ContainsKey(key.ToString()))
  3143. {
  3144. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3145. }
  3146. }
  3147. }
  3148. }
  3149. }
  3150. //校验哪个优先级有订单
  3151. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3152. foreach (string key in shop_orders.Keys)
  3153. {
  3154. List<string> ids = null;
  3155. shop_orders.TryGetValue(key, out ids);
  3156. //id为shopid
  3157. foreach (string id in ids)
  3158. {
  3159. Dictionary<string, int> list = null;
  3160. Dictionary<string, string> desing = null;
  3161. map.TryGetValue(id, out list);
  3162. design_orders.TryGetValue(id, out desing);
  3163. if (list != null && desing != null)
  3164. {
  3165. foreach (var item in desing)
  3166. {
  3167. int count = 0;
  3168. if (list.ContainsKey(item.Value))
  3169. {
  3170. list.TryGetValue(item.Value, out count);
  3171. if (count > 0)
  3172. {
  3173. designIds[id] = item.Value;
  3174. break;
  3175. }
  3176. }
  3177. }
  3178. }
  3179. }
  3180. if (designIds.Count > 0)
  3181. {
  3182. break;
  3183. }
  3184. }
  3185. DataTable table = new DataTable();
  3186. table.Columns.Add("tid", typeof(string));
  3187. table.Columns.Add("ctid", typeof(string));
  3188. table.Columns.Add("seller_nick", typeof(string));
  3189. table.Columns.Add("productName", typeof(string));
  3190. table.Columns.Add("pay_time", typeof(string));
  3191. table.Columns.Add("seller_memo", typeof(string));
  3192. if (designIds.Count > 0)
  3193. {
  3194. string shopId = "";
  3195. string productId = "";
  3196. foreach (var designInfo in designIds)
  3197. {
  3198. shopId = designInfo.Key;
  3199. productId = designInfo.Value;
  3200. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3201. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3202. if (dt.Rows.Count > 0)
  3203. {
  3204. foreach (DataRow row in dt.Rows)
  3205. {
  3206. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3207. {
  3208. DataRow data = table.NewRow();
  3209. data["ctid"] = row["ctid"].ToString();
  3210. data["tid"] = row["tid"].ToString();
  3211. data["seller_nick"] = ceErpShop.ShopName;
  3212. data["pay_time"] = row["pay_time"].ToString();
  3213. data["seller_memo"] = row["seller_memo"].ToString();
  3214. data["productName"] = ceErpProduct.PType;
  3215. table.Rows.Add(data);
  3216. }
  3217. }
  3218. }
  3219. }
  3220. }
  3221. writeGridDataTableJson(table.Rows.Count, table);
  3222. }
  3223. private object rushLockObject = new object();
  3224. public void set_erp_grabingorder()
  3225. {
  3226. if (UrlPostParmsCheck("ctid"))
  3227. {
  3228. int total = CurrentUser.User.Person.Total;
  3229. int userId = CurrentUser.User.ID;
  3230. int noFinish = CurrentUser.User.Person.NoFinish;
  3231. int finalization = CurrentUser.User.Person.Finalization;
  3232. string eids = GetPostString("ctid");
  3233. string key = "RushKey_" + userId;
  3234. int count = 0;
  3235. if (erpRedis.RedisHelper.KeyExists(key))
  3236. {
  3237. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3238. if (redisCount != null)
  3239. {
  3240. count = Convert.ToInt32(redisCount);
  3241. }
  3242. }
  3243. if (count >= total)
  3244. {
  3245. returnErrorMsg("半小时内已经抢" + total + "单");
  3246. return;
  3247. }
  3248. string[] ctidlist = eids.Split(',');
  3249. if (count + ctidlist.Length > total)
  3250. {
  3251. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3252. return;
  3253. }
  3254. int itag = 0;
  3255. lock (rushLockObject)
  3256. {
  3257. if (ctidlist.Length > 0)
  3258. {
  3259. string[] dtList = new string[ctidlist.Length];
  3260. for (int i = 0; i < ctidlist.Length; i++)
  3261. {
  3262. dtList[i] = "'" + ctidlist[i] + "'";
  3263. }
  3264. 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"));
  3265. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3266. if (dt_user.Rows.Count > 0)
  3267. {
  3268. int doing = 0;//未定稿
  3269. int finish = 0;//已完成
  3270. foreach (DataRow dr in dt_user.Rows)
  3271. {
  3272. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3273. {
  3274. doing++;
  3275. }
  3276. else
  3277. {
  3278. finish++;
  3279. }
  3280. }
  3281. if (doing >= noFinish)
  3282. {
  3283. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3284. return;
  3285. }
  3286. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3287. {
  3288. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3289. return;
  3290. }
  3291. }
  3292. //校验选择单子状态
  3293. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3294. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3295. if (dt.Rows.Count > 0)
  3296. {
  3297. List<string> list = new List<string>();
  3298. foreach (DataRow dr in dt.Rows)
  3299. {
  3300. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3301. {
  3302. list.Add(dr["ctid"].ToString());
  3303. }
  3304. }
  3305. if (list.Count > 0)
  3306. {
  3307. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3308. return;
  3309. }
  3310. }
  3311. foreach (string ctid in ctidlist)
  3312. {
  3313. CeErpTradeCell entity = null;
  3314. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3315. if (entity != null)
  3316. {
  3317. entity.OrderState = 3;
  3318. entity.DesignUserId = CurrentUser.UserID;
  3319. entity.WaitDesignTime = DateTime.Now;
  3320. entity.StartDesignTime = DateTime.Now;
  3321. entity.Update();
  3322. commonHelper.UpdateRelationOrder(entity.ctid);
  3323. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3324. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3325. itag++;
  3326. }
  3327. }
  3328. }
  3329. }
  3330. count += ctidlist.Length;
  3331. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3332. if (itag == 0)
  3333. returnErrorMsg("没有找到相关订单");
  3334. else
  3335. returnSuccessMsg("抢单成功!");
  3336. return;
  3337. }
  3338. }
  3339. public void get_erp_waitorderlist()
  3340. {
  3341. DataStruct dStruct = GetPostStruct();
  3342. List<string> lw = new List<string>();
  3343. string tid = GetPostString("ctid");
  3344. if (tid.Length > 0)
  3345. {
  3346. string select_tid = getTidByCtid(tid);
  3347. lw.Add(string.Format("tid='{0}'", select_tid));
  3348. }
  3349. string shopname = GetPostString("shopname");
  3350. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3351. string buyernick = GetPostString("buyer_nick");
  3352. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3353. string customer = GetPostString("customer");
  3354. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3355. string design = GetPostString("design");
  3356. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3357. string orderState = GetPostString("orderState");
  3358. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3359. string supplier = GetPostString("supplier");
  3360. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3361. string sellermemo = GetPostString("seller_memo");
  3362. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3363. string otherMemo = GetPostString("otherMemo");
  3364. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3365. string address = GetPostString("address");
  3366. 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));
  3367. string date1 = GetPostString("date1");
  3368. string date2 = GetPostString("date2");
  3369. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3370. if (dw.Length > 0) lw.Add(dw);
  3371. string price1 = GetPostString("price1");
  3372. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3373. string price2 = GetPostString("price2");
  3374. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3375. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3376. lw.Add(string.Format("IsSample != 2 "));
  3377. lw.Add(string.Format("OrderState = 5 "));
  3378. lw.Add(string.Format("IsRefund<={0}", 1));
  3379. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3380. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3381. string pagesize = GetPostString("pagesize");
  3382. if (pagesize != null)
  3383. {
  3384. dStruct.PageSize = 200;
  3385. }
  3386. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3387. if (dt != null)
  3388. {
  3389. foreach (DataRow dr in dt.Rows)
  3390. {
  3391. 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();
  3392. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3393. {
  3394. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3395. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3396. entity.SupplierId = suid;
  3397. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3398. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3399. entity.Update();
  3400. }
  3401. }
  3402. }
  3403. writeGridDataTableJson(dStruct.TotalCount, dt);
  3404. }
  3405. public void get_erp_supplierwaitorderlist()
  3406. {
  3407. DataStruct dStruct = GetPostStruct();
  3408. List<string> lw = new List<string>();
  3409. string tid = GetPostString("ctid");
  3410. if (tid.Length > 0)
  3411. {
  3412. string select_tid = getTidByCtid(tid);
  3413. lw.Add(string.Format("tid='{0}'", select_tid));
  3414. }
  3415. string shopname = GetPostString("shopname");
  3416. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3417. string sellermemo = GetPostString("seller_memo");
  3418. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3419. string date1 = GetPostString("date1");
  3420. string date2 = GetPostString("date2");
  3421. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3422. if (dw.Length > 0) lw.Add(dw);
  3423. lw.Add(string.Format("OrderState = 5 "));
  3424. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3425. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3426. {
  3427. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3428. }
  3429. string supplier = GetPostString("supplier");
  3430. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3431. {
  3432. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3433. }
  3434. lw.Add(string.Format("IsRefund<={0}", 1));
  3435. dStruct.Order = "FinishDesignTime desc";
  3436. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3437. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3438. if (dt != null)
  3439. {
  3440. foreach (DataRow dr in dt.Rows)
  3441. {
  3442. 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();
  3443. }
  3444. }
  3445. writeGridDataTableJson(dStruct.TotalCount, dt);
  3446. }
  3447. public void upd_erp_verifytosupplier()
  3448. {
  3449. if (UrlPostParmsCheck("ctid"))
  3450. {
  3451. string eids = GetPostString("ctid");
  3452. CeErpTradeCell entity = null;
  3453. string[] eidsList = eids.Split(',');
  3454. if (eidsList.Length <= 0)
  3455. {
  3456. returnErrorMsg("订单号不能空");
  3457. return;
  3458. }
  3459. List<string> tLst = new List<string>();
  3460. foreach (string ctidstr in eidsList)
  3461. {
  3462. tLst.Add("'" + ctidstr + "'");
  3463. CeErpDataSendOrderInfo.createObject(ctidstr);
  3464. }
  3465. string needtids = string.Join(",", tLst.ToArray());
  3466. StringBuilder sql = new StringBuilder();
  3467. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3468. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3469. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3470. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3471. returnSuccessMsg("操作成功!");
  3472. return;
  3473. /**foreach (string ctidstr in eidsList)
  3474. {
  3475. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3476. if (entity != null)
  3477. {
  3478. if (entity.SupplierId == 0)
  3479. {
  3480. continue;
  3481. }
  3482. entity.IsVerifyToSupplier = true;
  3483. if (entity.IsReturn == 1) //1是供应商打回
  3484. {
  3485. entity.IsReturn = 0;
  3486. }
  3487. entity.FinishPlaceTime = DateTime.Now;
  3488. entity.PlaceUserId = CurrentUser.UserID;
  3489. entity.Update();
  3490. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3491. }
  3492. }
  3493. returnSuccessMsg("操作成功!");
  3494. return;**/
  3495. }
  3496. }
  3497. public void upd_erp_supplierback()
  3498. {
  3499. if (UrlPostParmsCheck("ctid"))
  3500. {
  3501. string eid = GetPostString("ctid");
  3502. string reason = GetPostString("returnreason");
  3503. CeErpTradeCell entity = null;
  3504. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3505. if (entity != null)
  3506. {
  3507. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3508. {
  3509. string key = "return_order_" + entity.SupplierId;
  3510. List<string> list = new List<string>();
  3511. if (RedisHelper.HasKey(key))
  3512. {
  3513. object data = RedisHelper.StringGet(key);
  3514. list = Convert.ToString(data).Split(',').ToList();
  3515. }
  3516. list.Add(eid);
  3517. RedisHelper.StringSet(key, string.Join(",", list));
  3518. }
  3519. entity.IsVerifyToSupplier = false;
  3520. entity.IsReturn = 1;
  3521. entity.ReturnTime = DateTime.Now;
  3522. entity.ReturnReason = reason;
  3523. if (entity.OrderState == 6)
  3524. {
  3525. entity.OrderState = 5;
  3526. }
  3527. entity.Update();
  3528. CeErpSukuraData.createInfo(entity.ctid, 5);
  3529. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3530. returnSuccessMsg("操作成功!");
  3531. return;
  3532. }
  3533. returnErrorMsg("找不到订单记录");
  3534. }
  3535. }
  3536. public void upd_erp_toaftersaleorder()
  3537. {
  3538. if (UrlPostParmsCheck("ctid"))
  3539. {
  3540. string eid = GetPostString("ctid");
  3541. string reason = GetPostString("returnreason");
  3542. CeErpTradeCell entity = null;
  3543. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3544. if (entity != null)
  3545. {
  3546. if (entity.isAfterSaleOrder != 1)
  3547. {
  3548. returnErrorMsg("带S的售后单才能打回给售后");
  3549. return;
  3550. }
  3551. if (entity.OrderState >= 5)
  3552. {
  3553. returnErrorMsg("已经设计完成了不能打回给售后");
  3554. return;
  3555. }
  3556. entity.OrderState = 0;
  3557. entity.IsReturn = 3;
  3558. entity.ReturnTime = DateTime.Now;
  3559. entity.UpdateTime = DateTime.Now;
  3560. entity.ReturnReason = reason;
  3561. entity.Update();
  3562. CeErpSukuraData.createInfo(entity.ctid, 5);
  3563. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3564. returnSuccessMsg("操作成功!");
  3565. return;
  3566. }
  3567. returnErrorMsg("找不到订单记录");
  3568. }
  3569. }
  3570. public void upd_erp_aftersaletodesign()
  3571. {
  3572. if (UrlPostParmsCheck("ctid"))
  3573. {
  3574. string eid = GetPostString("ctid");
  3575. CeErpTradeCell entity = null;
  3576. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3577. if (entity != null)
  3578. {
  3579. entity.OrderState = 3;
  3580. entity.IsReturn = 0;
  3581. entity.UpdateTime = DateTime.Now;
  3582. entity.Update();
  3583. CeErpSukuraData.createInfo(entity.ctid, 5);
  3584. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3585. returnSuccessMsg("操作成功!");
  3586. return;
  3587. }
  3588. returnErrorMsg("找不到订单记录");
  3589. }
  3590. }
  3591. public void assign_erp_supplier()
  3592. {
  3593. if (UrlPostParmsCheck("ctid"))
  3594. {
  3595. string eids = GetPostString("ctid");
  3596. int sid = GetPostInt("SupplierName");
  3597. string fromTag = GetPostString("tag");
  3598. string[] eidList = eids.Split(',');
  3599. if (eidList.Length <= 0)
  3600. {
  3601. returnErrorMsg("指派不能为空");
  3602. return;
  3603. }
  3604. string errMsg = "";
  3605. string suname = commonHelper.getSupplierNameById(sid);
  3606. foreach (string ctid in eidList)
  3607. {
  3608. CeErpTradeCell entity = null;
  3609. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3610. if (entity != null)
  3611. {
  3612. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3613. {
  3614. errMsg += (ctid + "指派失败!!!");
  3615. continue;
  3616. }
  3617. entity.SupplierId = sid;
  3618. entity.Update();
  3619. commonHelper.UpdateRelationOrder(entity.ctid);
  3620. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3621. if (entity.OrderState >= 6)
  3622. {
  3623. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3624. //{
  3625. // string msl = entity.MakeSupplier;
  3626. // string[] mslist = msl.Split(',');
  3627. // 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);
  3628. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3629. //}
  3630. //else
  3631. //{
  3632. StringBuilder sql = new StringBuilder();
  3633. 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);
  3634. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3635. //}
  3636. }
  3637. }
  3638. else
  3639. {
  3640. continue;
  3641. }
  3642. }
  3643. if (errMsg.Length > 0)
  3644. {
  3645. returnErrorMsg(errMsg);
  3646. return;
  3647. }
  3648. returnSuccessMsg("操作成功!");
  3649. return;
  3650. }
  3651. }
  3652. public void assign_erp_makesupplier()
  3653. {
  3654. if (UrlPostParmsCheck("ctid"))
  3655. {
  3656. string eids = GetPostString("ctid");
  3657. string sname = GetPostString("SupplierName");
  3658. string[] eidList = eids.Split(',');
  3659. if (eidList.Length <= 0)
  3660. {
  3661. returnErrorMsg("指派不能为空");
  3662. return;
  3663. }
  3664. List<string> tLst = new List<string>();
  3665. foreach (string ctid in eidList)
  3666. {
  3667. CeErpTradeCell entity = null;
  3668. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3669. if (entity != null)
  3670. {
  3671. entity.MakeSupplier = sname;
  3672. entity.Update();
  3673. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3674. tLst.Add("'" + ctid + "'");
  3675. }
  3676. else
  3677. {
  3678. continue;
  3679. }
  3680. }
  3681. string ctids = string.Join(",", tLst.ToArray());
  3682. StringBuilder sql2 = new StringBuilder();
  3683. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3684. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3685. returnSuccessMsg("操作成功!");
  3686. return;
  3687. }
  3688. }
  3689. public void ins_erp_returnreason()
  3690. {
  3691. if (UrlPostParmsCheck("ctid"))
  3692. {
  3693. string eid = GetPostString("ctid");
  3694. CeErpTradeCell entity = null;
  3695. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3696. string userpost = CurrentUser.UserPost.Post.Code;
  3697. if (entity != null)
  3698. {
  3699. bool isPlace = false;
  3700. if (entity.OrderState > 6)
  3701. {
  3702. returnErrorMsg("已发货无法打回!");
  3703. return;
  3704. }
  3705. if (entity.OrderState == 6)
  3706. {
  3707. isPlace = true;
  3708. }
  3709. bool isNeedUpdateCell2 = false;
  3710. if (entity.OrderState >= 6)
  3711. {
  3712. isNeedUpdateCell2 = true;
  3713. }
  3714. int returnTag = 2;
  3715. if (userpost == "Supplier")
  3716. {
  3717. returnTag = 1;
  3718. }
  3719. int toType = GetPostInt("totype");
  3720. string fromType = "3";
  3721. if (entity.OrderState < 5)
  3722. {
  3723. fromType = "3";
  3724. }
  3725. else
  3726. {
  3727. fromType = "4";
  3728. }
  3729. if (entity.IsXianHuo == 0)
  3730. {
  3731. if (returnTag == 2)
  3732. {
  3733. if (toType == 1)
  3734. {
  3735. entity.OrderState = 0;
  3736. entity.ReturnUserType = 1;
  3737. string clearman = GetPostString("clearman");
  3738. if (!string.IsNullOrEmpty(clearman))
  3739. {
  3740. entity.DesignUserId = 0;
  3741. }
  3742. }
  3743. else
  3744. {
  3745. entity.OrderState = 3;
  3746. entity.ReturnUserType = 2;
  3747. }
  3748. entity.IsReadTag = 1;
  3749. }
  3750. else if (returnTag == 1)
  3751. {
  3752. entity.OrderState = 5;
  3753. }
  3754. entity.IsVerifyToSupplier = false;
  3755. }
  3756. if (entity.IsXianHuo == 1)
  3757. {
  3758. entity.OrderState = 5;
  3759. }
  3760. entity.UnusualTag = 0;
  3761. entity.UnusualTime = null;
  3762. entity.UnusualCon = "";
  3763. entity.IsReturn = returnTag;
  3764. entity.ReturnTime = DateTime.Now;
  3765. entity.UpdateTime = DateTime.Now;
  3766. entity.ReturnReason = GetPostString("returnreason");
  3767. entity.Update();
  3768. if (entity.OrderState == 3)
  3769. {
  3770. ApiVo apiVo = new ApiVo();
  3771. apiVo.orderNumber = entity.ctid;
  3772. apiVo.actionName = "rebutDesign";
  3773. apiVo.orderRemarks = entity.ReturnReason;
  3774. designHelper.API_WorkCore(apiVo);//rebutDesign
  3775. }
  3776. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3777. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3778. {
  3779. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3780. }
  3781. CeErpSukuraData.createInfo(entity.ctid, 5);
  3782. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3783. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3784. if (isPlace)
  3785. {
  3786. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3787. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3788. if (dth != null && dth.Rows.Count > 0)
  3789. {
  3790. dataSendOrderBean dataSendOrderBean = null;
  3791. foreach (DataRow item in dth.Rows)
  3792. {
  3793. try
  3794. {
  3795. dataSendOrderBean = new dataSendOrderBean();
  3796. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3797. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3798. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3799. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3800. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3801. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3802. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3803. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3804. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3805. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3806. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3807. dataSendOrderBean.Radio1723534706288 = "打回";
  3808. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3809. if (result != null)
  3810. {
  3811. if ("0".Equals(result.errcode))
  3812. {
  3813. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3814. }
  3815. else
  3816. {
  3817. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3818. }
  3819. }
  3820. }
  3821. catch (Exception ex)
  3822. {
  3823. }
  3824. }
  3825. }
  3826. }
  3827. if (isNeedUpdateCell2)
  3828. {
  3829. if (entity.MakeSupplier.IndexOf(",") != -1)
  3830. {
  3831. StringBuilder sql2 = new StringBuilder();
  3832. 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);
  3833. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3834. }
  3835. else
  3836. {
  3837. StringBuilder sql2 = new StringBuilder();
  3838. 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);
  3839. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3840. }
  3841. }
  3842. returnSuccessMsg("操作成功!");
  3843. return;
  3844. }
  3845. returnErrorMsg("找不到订单记录");
  3846. }
  3847. }
  3848. public void cyt_erp_returnreason()
  3849. {
  3850. if (UrlPostParmsCheck("ctid"))
  3851. {
  3852. string eid = GetPostString("ctid");
  3853. CeErpTradeCell entity = null;
  3854. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3855. string userpost = CurrentUser.UserPost.Post.Code;
  3856. if (entity != null)
  3857. {
  3858. if (entity.OrderState > 6)
  3859. {
  3860. returnErrorMsg("已发货无法打回!");
  3861. return;
  3862. }
  3863. JObject jsonObject = new JObject
  3864. {
  3865. { "Userid", "77886" },
  3866. { "Pwd", "lt666888" },
  3867. { "LTOrderId",eid }
  3868. };
  3869. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3870. JObject jsonObjects = JObject.Parse(response);
  3871. string msg = (string)jsonObjects["msg"];
  3872. if (msg != "取消成功")
  3873. {
  3874. returnErrorMsg(msg);
  3875. return;
  3876. }
  3877. bool isNeedUpdateCell2 = false;
  3878. if (entity.OrderState >= 6)
  3879. {
  3880. isNeedUpdateCell2 = true;
  3881. }
  3882. int returnTag = 2;
  3883. if (userpost == "Supplier")
  3884. {
  3885. returnTag = 1;
  3886. }
  3887. if (entity.IsXianHuo == 0)
  3888. {
  3889. if (returnTag == 2)
  3890. {
  3891. int toType = GetPostInt("totype");
  3892. if (toType == 1)
  3893. {
  3894. entity.OrderState = 0;
  3895. entity.ReturnUserType = 1;
  3896. }
  3897. else
  3898. {
  3899. entity.OrderState = 4;
  3900. entity.ReturnUserType = 2;
  3901. }
  3902. entity.IsReadTag = 1;
  3903. }
  3904. else if (returnTag == 1)
  3905. {
  3906. entity.OrderState = 5;
  3907. }
  3908. entity.IsVerifyToSupplier = false;
  3909. }
  3910. entity.UnusualTag = 0;
  3911. entity.UnusualTime = null;
  3912. entity.UnusualCon = "";
  3913. entity.IsReturn = returnTag;
  3914. entity.ReturnTime = DateTime.Now;
  3915. entity.ReturnReason = GetPostString("returnreason");
  3916. entity.Update();
  3917. if (entity.OrderState == 4)
  3918. {
  3919. ApiVo apiVo = new ApiVo();
  3920. apiVo.orderNumber = entity.ctid;
  3921. apiVo.actionName = "rebutDesign";
  3922. apiVo.orderRemarks = entity.ReturnReason;
  3923. designHelper.API_WorkCore(apiVo);//rebutDesign
  3924. }
  3925. CeErpSukuraData.createInfo(entity.ctid, 5);
  3926. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3927. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3928. if (isNeedUpdateCell2)
  3929. {
  3930. if (entity.MakeSupplier.IndexOf(",") != -1)
  3931. {
  3932. StringBuilder sql2 = new StringBuilder();
  3933. 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);
  3934. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3935. }
  3936. else
  3937. {
  3938. StringBuilder sql2 = new StringBuilder();
  3939. 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);
  3940. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3941. }
  3942. }
  3943. returnSuccessMsg("操作成功!");
  3944. return;
  3945. }
  3946. returnErrorMsg("找不到订单记录");
  3947. }
  3948. }
  3949. public void upd_erp_xianhuoreturntag()
  3950. {
  3951. if (UrlPostParmsCheck("ctid"))
  3952. {
  3953. string eids = GetPostString("ctid");
  3954. string[] ctids = eids.Split(',');
  3955. foreach (string ctid in ctids)
  3956. {
  3957. CeErpTradeCell entity = null;
  3958. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3959. if (entity != null)
  3960. {
  3961. entity.IsReturn = 0;
  3962. entity.Update();
  3963. CeErpSukuraData.createInfo(entity.ctid, 5);
  3964. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3965. }
  3966. }
  3967. returnSuccessMsg("操作成功!");
  3968. return;
  3969. }
  3970. }
  3971. public void get_erp_waitdeliverylist()
  3972. {
  3973. DataStruct dStruct = GetPostStruct();
  3974. List<string> lw = new List<string>();
  3975. string tid = GetPostString("ctid");
  3976. if (tid.Length > 0)
  3977. {
  3978. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3979. if (tid.Length > 5)
  3980. {
  3981. List<string> tids = getTidByCtidLike(tid);
  3982. if (tids.Count > 0 && tids.Count < 10)
  3983. {
  3984. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3985. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  3986. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  3987. {
  3988. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  3989. }
  3990. }
  3991. }
  3992. lw.Add(tid_sql);
  3993. }
  3994. string shopname = GetPostString("shopname");
  3995. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3996. string buyernick = GetPostString("buyer_nick");
  3997. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3998. //if (tid.Length == 0 && buyernick.Length == 0)
  3999. //{
  4000. // lw.Add(string.Format("IsRefund<={0}", 1));
  4001. //}
  4002. string customer = GetPostString("customer");
  4003. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4004. string design = GetPostString("design");
  4005. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4006. string orderState = GetPostString("orderState");
  4007. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4008. string address = GetPostString("address");
  4009. 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));
  4010. string sellermemo = GetPostString("seller_memo");
  4011. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4012. string supplier = GetPostString("supplier");
  4013. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4014. string OrderArea = GetPostString("order_area");
  4015. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4016. string placedate1 = GetPostString("placedate1");
  4017. string placedate2 = GetPostString("placedate2");
  4018. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4019. if (fdw.Length > 0) lw.Add(fdw);
  4020. string price1 = GetPostString("price1");
  4021. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4022. string price2 = GetPostString("price2");
  4023. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4024. string unusualCon = GetPostString("unusualcon");
  4025. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4026. string otherMemo = GetPostString("otherMemo");
  4027. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4028. string posTag = CurrentUser.UserPost.Post.Code;
  4029. if (posTag == "Supplier")
  4030. {
  4031. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4032. }
  4033. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4034. lw.Add(string.Format("type != 'PDD' "));
  4035. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4036. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4037. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4038. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4039. writeGridDataTableJson(dStruct.TotalCount, dt);
  4040. }
  4041. public void get_erp_changedeliverylist()
  4042. {
  4043. DataStruct dStruct = GetPostStruct();
  4044. List<string> lw = new List<string>();
  4045. string tid = GetPostString("ctid");
  4046. if (tid.Length > 0)
  4047. {
  4048. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4049. if (tid.Length > 5)
  4050. {
  4051. List<string> tids = getTidByCtidLike(tid);
  4052. if (tids.Count > 0 && tids.Count < 10)
  4053. {
  4054. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4055. }
  4056. }
  4057. lw.Add(tid_sql);
  4058. }
  4059. string shopname = GetPostString("shopname");
  4060. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4061. string buyernick = GetPostString("buyer_nick");
  4062. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4063. //if (tid.Length == 0 && buyernick.Length == 0)
  4064. //{
  4065. // lw.Add(string.Format("IsRefund<={0}", 1));
  4066. //}
  4067. string customer = GetPostString("customer");
  4068. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4069. string design = GetPostString("design");
  4070. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4071. string orderState = GetPostString("orderState");
  4072. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4073. string address = GetPostString("address");
  4074. 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));
  4075. string sellermemo = GetPostString("seller_memo");
  4076. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4077. string supplier = GetPostString("supplier");
  4078. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4079. string OrderArea = GetPostString("order_area");
  4080. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4081. string placedate1 = GetPostString("placedate1");
  4082. string placedate2 = GetPostString("placedate2");
  4083. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4084. if (fdw.Length > 0) lw.Add(fdw);
  4085. string price1 = GetPostString("price1");
  4086. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4087. string price2 = GetPostString("price2");
  4088. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4089. string unusualCon = GetPostString("unusualcon");
  4090. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4091. string otherMemo = GetPostString("otherMemo");
  4092. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4093. string posTag = CurrentUser.UserPost.Post.Code;
  4094. if (posTag == "Supplier")
  4095. {
  4096. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4097. }
  4098. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4099. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4100. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4101. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4102. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4103. /*if (tid.Length > 0)
  4104. {
  4105. List<string> tids = new List<string>();
  4106. if (dt != null && dt.Rows.Count > 0)
  4107. {
  4108. foreach (DataRow item in dt.Rows)
  4109. {
  4110. tids.Add("'" + item["tid"] + "'");
  4111. }
  4112. }
  4113. if (tids.Count > 0)
  4114. {
  4115. lw.RemoveAt(0);
  4116. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4117. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4118. dt = WebCache.GetData("view_erptradecell", dStruct);
  4119. }
  4120. }*/
  4121. writeGridDataTableJson(dStruct.TotalCount, dt);
  4122. }
  4123. public void get_erp_pddderiving()
  4124. {
  4125. DataStruct dStruct = GetPostStruct();
  4126. List<string> lw = new List<string>();
  4127. string tid = GetPostString("ctid");
  4128. if (tid.Length > 0)
  4129. {
  4130. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4131. if (tid.Length > 5)
  4132. {
  4133. List<string> tids = getTidByCtidLike(tid);
  4134. if (tids.Count > 0 && tids.Count < 10)
  4135. {
  4136. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4137. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4138. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4139. {
  4140. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4141. }
  4142. }
  4143. }
  4144. lw.Add(tid_sql);
  4145. }
  4146. string shopname = GetPostString("shopname");
  4147. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4148. string buyernick = GetPostString("buyer_nick");
  4149. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4150. //if (tid.Length == 0 && buyernick.Length == 0)
  4151. //{
  4152. // lw.Add(string.Format("IsRefund<={0}", 1));
  4153. //}
  4154. string customer = GetPostString("customer");
  4155. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4156. string design = GetPostString("design");
  4157. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4158. string orderState = GetPostString("orderState");
  4159. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4160. string address = GetPostString("address");
  4161. 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));
  4162. string sellermemo = GetPostString("seller_memo");
  4163. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4164. string supplier = GetPostString("supplier");
  4165. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4166. string OrderArea = GetPostString("order_area");
  4167. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4168. string placedate1 = GetPostString("placedate1");
  4169. string placedate2 = GetPostString("placedate2");
  4170. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4171. if (fdw.Length > 0) lw.Add(fdw);
  4172. string price1 = GetPostString("price1");
  4173. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4174. string price2 = GetPostString("price2");
  4175. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4176. string unusualCon = GetPostString("unusualcon");
  4177. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4178. string posTag = CurrentUser.UserPost.Post.Code;
  4179. if (posTag == "Supplier")
  4180. {
  4181. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4182. }
  4183. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4184. lw.Add(string.Format("type = 'PDD' "));
  4185. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4186. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4187. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4188. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4189. /*if (tid.Length > 0)
  4190. {
  4191. List<string> tids = new List<string>();
  4192. if (dt != null && dt.Rows.Count > 0)
  4193. {
  4194. foreach (DataRow item in dt.Rows)
  4195. {
  4196. tids.Add("'" + item["tid"] + "'");
  4197. }
  4198. }
  4199. if (tids.Count > 0)
  4200. {
  4201. lw.RemoveAt(0);
  4202. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4203. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4204. dt = WebCache.GetData("view_erptradecell", dStruct);
  4205. }
  4206. }*/
  4207. writeGridDataTableJson(dStruct.TotalCount, dt);
  4208. }
  4209. public void get_erp_jdderiving()
  4210. {
  4211. DataStruct dStruct = GetPostStruct();
  4212. List<string> lw = new List<string>();
  4213. string tid = GetPostString("ctid");
  4214. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4215. string shopname = GetPostString("shopname");
  4216. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4217. string buyernick = GetPostString("buyer_nick");
  4218. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4219. //if (tid.Length == 0 && buyernick.Length == 0)
  4220. //{
  4221. // lw.Add(string.Format("IsRefund<={0}", 1));
  4222. //}
  4223. string customer = GetPostString("customer");
  4224. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4225. string design = GetPostString("design");
  4226. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4227. string orderState = GetPostString("orderState");
  4228. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4229. string address = GetPostString("address");
  4230. 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));
  4231. string sellermemo = GetPostString("seller_memo");
  4232. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4233. string supplier = GetPostString("supplier");
  4234. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4235. string OrderArea = GetPostString("order_area");
  4236. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4237. string placedate1 = GetPostString("placedate1");
  4238. string placedate2 = GetPostString("placedate2");
  4239. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4240. if (fdw.Length > 0) lw.Add(fdw);
  4241. string price1 = GetPostString("price1");
  4242. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4243. string price2 = GetPostString("price2");
  4244. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4245. string unusualCon = GetPostString("unusualcon");
  4246. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4247. string posTag = CurrentUser.UserPost.Post.Code;
  4248. if (posTag == "Supplier")
  4249. {
  4250. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4251. }
  4252. lw.Add(string.Format("OrderState = 6 "));
  4253. lw.Add(string.Format("type = 'JD' "));
  4254. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4255. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4256. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4257. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4258. writeGridDataTableJson(dStruct.TotalCount, dt);
  4259. }
  4260. public void get_erp_demoorderlist()
  4261. {
  4262. DataStruct dStruct = GetPostStruct();
  4263. List<string> lw = new List<string>();
  4264. string tid = GetPostString("ctid");
  4265. if (tid.Length > 0)
  4266. {
  4267. string select_tid = getTidByCtid(tid);
  4268. lw.Add(string.Format("tid='{0}'", select_tid));
  4269. }
  4270. string shopname = GetPostString("shopname");
  4271. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4272. string buyernick = GetPostString("buyer_nick");
  4273. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4274. string customer = GetPostString("customer");
  4275. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4276. string design = GetPostString("design");
  4277. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4278. string orderState = GetPostString("orderState");
  4279. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4280. string address = GetPostString("address");
  4281. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4282. string sellermemo = GetPostString("seller_memo");
  4283. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4284. string supplier = GetPostString("supplier");
  4285. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4286. string OrderArea = GetPostString("order_area");
  4287. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4288. string date1 = GetPostString("date1");
  4289. string date2 = GetPostString("date2");
  4290. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4291. if (dw.Length > 0) lw.Add(dw);
  4292. string price1 = GetPostString("price1");
  4293. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4294. string price2 = GetPostString("price2");
  4295. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4296. string posTag = CurrentUser.UserPost.Post.Code;
  4297. if (posTag == "Supplier")
  4298. {
  4299. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4300. }
  4301. //lw.Add(string.Format("OrderState = 6 "));
  4302. lw.Add(string.Format("IsSample={0}", 3));
  4303. lw.Add(string.Format("IsRefund<={0}", 1));
  4304. dStruct.Order = "pay_time desc";
  4305. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4306. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4307. writeGridDataTableJson(dStruct.TotalCount, dt);
  4308. }
  4309. public void save_erp_checkmemo()
  4310. {
  4311. if (UrlPostParmsCheck("ctid"))
  4312. {
  4313. string ctid = GetPostString("ctid");
  4314. CeErpTradeCell entity = null;
  4315. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4316. if (entity != null)
  4317. {
  4318. entity.CheckMemo = GetPostString("CheckMemo");
  4319. entity.Update();
  4320. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4321. if (trade != null)
  4322. {
  4323. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4324. }
  4325. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4326. returnSuccessMsg("保存成功!");
  4327. return;
  4328. }
  4329. returnErrorMsg("找不到记录");
  4330. }
  4331. }
  4332. public void get_erp_returnlist()
  4333. {
  4334. DataStruct dStruct = GetPostStruct();
  4335. List<string> lw = new List<string>();
  4336. string tid = GetPostString("ctid");
  4337. if (tid.Length > 0)
  4338. {
  4339. string select_tid = getTidByCtid(tid);
  4340. lw.Add(string.Format("tid='{0}'", select_tid));
  4341. }
  4342. string shopname = GetPostString("shopname");
  4343. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4344. string buyernick = GetPostString("buyer_nick");
  4345. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4346. string customer = GetPostString("customer");
  4347. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4348. string design = GetPostString("design");
  4349. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4350. string orderState = GetPostString("orderState");
  4351. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4352. string address = GetPostString("address");
  4353. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4354. string sellermemo = GetPostString("seller_memo");
  4355. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4356. string supplier = GetPostString("supplier");
  4357. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4358. string date1 = GetPostString("date1");
  4359. string date2 = GetPostString("date2");
  4360. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4361. if (dw.Length > 0) lw.Add(dw);
  4362. string bdate1 = GetPostString("backdate1");
  4363. string bdate2 = GetPostString("backdate2");
  4364. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4365. if (dw_back.Length > 0) lw.Add(dw_back);
  4366. string price1 = GetPostString("price1");
  4367. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4368. string price2 = GetPostString("price2");
  4369. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4370. lw.Add(string.Format("IsReturn>0"));
  4371. lw.Add(string.Format("IsXianHuo=0"));
  4372. lw.Add(string.Format("IsReturn!=3"));
  4373. string backtype = GetPostString("backtype");
  4374. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4375. dStruct.Order = "FinishDesignTime desc";
  4376. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4377. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4378. writeGridDataTableJson(dStruct.TotalCount, dt);
  4379. }
  4380. public void get_erp_today_sumreturn()
  4381. {
  4382. DataStruct dStruct = GetPostStruct();
  4383. List<string> lw = new List<string>();
  4384. string bdate1 = GetPostString("returnTimeS");
  4385. string bdate2 = GetPostString("returnTimeE");
  4386. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4387. if (dw_back.Length > 0) lw.Add(dw_back);
  4388. lw.Add(string.Format("IsReturn=0"));
  4389. lw.Add(string.Format("IsXianHuo=0"));
  4390. string mainWhere = string.Join(" and ", lw.ToArray());
  4391. string sql = "";
  4392. if (dw_back.Length > 0)
  4393. {
  4394. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4395. }
  4396. else
  4397. {
  4398. 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 + "'";
  4399. }
  4400. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4401. decimal total = 0, today_finish = 0;
  4402. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4403. {
  4404. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4405. }
  4406. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4407. {
  4408. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4409. }
  4410. var res = new
  4411. {
  4412. data = total,
  4413. data1 = today_finish,
  4414. };
  4415. string ro_jsond = JsonConvert.SerializeObject(res);
  4416. returnSuccess(ro_jsond);
  4417. return;
  4418. }
  4419. public void get_erp_allreturnlist()
  4420. {
  4421. DataStruct dStruct = GetPostStruct();
  4422. List<string> lw = new List<string>();
  4423. string tid = GetPostString("ctid");
  4424. if (tid.Length > 0)
  4425. {
  4426. string select_tid = getTidByCtid(tid);
  4427. lw.Add(string.Format("tid='{0}'", select_tid));
  4428. }
  4429. string shopname = GetPostString("shopname");
  4430. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4431. string buyernick = GetPostString("buyer_nick");
  4432. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4433. string customer = GetPostString("customer");
  4434. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4435. string design = GetPostString("design");
  4436. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4437. string orderState = GetPostString("orderState");
  4438. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4439. string address = GetPostString("address");
  4440. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4441. string sellermemo = GetPostString("seller_memo");
  4442. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4443. string supplier = GetPostString("supplier");
  4444. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4445. string date1 = GetPostString("date1");
  4446. string date2 = GetPostString("date2");
  4447. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4448. if (dw.Length > 0) lw.Add(dw);
  4449. string bdate1 = GetPostString("backdate1");
  4450. string bdate2 = GetPostString("backdate2");
  4451. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4452. if (dw_back.Length > 0) lw.Add(dw_back);
  4453. string price1 = GetPostString("price1");
  4454. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4455. string price2 = GetPostString("price2");
  4456. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4457. string backreason = GetPostString("backreason");
  4458. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4459. lw.Add(string.Format("IsXianHuo=0"));
  4460. lw.Add(string.Format("ReturnTime != ''"));
  4461. string backtype = GetPostString("backtype");
  4462. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4463. dStruct.Order = "FinishDesignTime desc";
  4464. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4465. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4466. writeGridDataTableJson(dStruct.TotalCount, dt);
  4467. }
  4468. public void get_erp_aftersalereturnlist()
  4469. {
  4470. DataStruct dStruct = GetPostStruct();
  4471. List<string> lw = new List<string>();
  4472. string tid = GetPostString("ctid");
  4473. if (tid.Length > 0)
  4474. {
  4475. string select_tid = getTidByCtid(tid);
  4476. lw.Add(string.Format("tid='{0}'", select_tid));
  4477. }
  4478. string shopname = GetPostString("shopname");
  4479. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4480. string buyernick = GetPostString("buyer_nick");
  4481. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4482. string customer = GetPostString("customer");
  4483. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4484. string design = GetPostString("design");
  4485. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4486. string orderState = GetPostString("orderState");
  4487. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4488. string address = GetPostString("address");
  4489. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4490. string sellermemo = GetPostString("seller_memo");
  4491. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4492. string supplier = GetPostString("supplier");
  4493. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4494. string date1 = GetPostString("date1");
  4495. string date2 = GetPostString("date2");
  4496. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4497. if (dw.Length > 0) lw.Add(dw);
  4498. string bdate1 = GetPostString("backdate1");
  4499. string bdate2 = GetPostString("backdate2");
  4500. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4501. if (dw_back.Length > 0) lw.Add(dw_back);
  4502. string price1 = GetPostString("price1");
  4503. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4504. string price2 = GetPostString("price2");
  4505. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4506. lw.Add(string.Format("IsReturn=3"));
  4507. string backtype = GetPostString("backtype");
  4508. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4509. string backreason = GetPostString("backreason");
  4510. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4511. dStruct.Order = "ReturnTime desc";
  4512. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4513. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4514. writeGridDataTableJson(dStruct.TotalCount, dt);
  4515. }
  4516. public void get_erp_xianhuoreturnlist()
  4517. {
  4518. DataStruct dStruct = GetPostStruct();
  4519. List<string> lw = new List<string>();
  4520. string tid = GetPostString("ctid");
  4521. if (tid.Length > 0)
  4522. {
  4523. string select_tid = getTidByCtid(tid);
  4524. lw.Add(string.Format("tid='{0}'", select_tid));
  4525. }
  4526. string shopname = GetPostString("shopname");
  4527. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4528. string buyernick = GetPostString("buyer_nick");
  4529. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4530. string customer = GetPostString("customer");
  4531. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4532. string design = GetPostString("design");
  4533. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4534. string orderState = GetPostString("orderState");
  4535. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4536. string address = GetPostString("address");
  4537. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4538. string sellermemo = GetPostString("seller_memo");
  4539. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4540. string supplier = GetPostString("supplier");
  4541. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4542. string OrderArea = GetPostString("order_area");
  4543. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4544. string date1 = GetPostString("date1");
  4545. string date2 = GetPostString("date2");
  4546. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4547. if (dw.Length > 0) lw.Add(dw);
  4548. string price1 = GetPostString("price1");
  4549. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4550. string price2 = GetPostString("price2");
  4551. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4552. string posTag = CurrentUser.UserPost.Post.Code;
  4553. if (posTag == "Supplier")
  4554. {
  4555. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4556. }
  4557. lw.Add(string.Format("OrderState=6 "));
  4558. lw.Add(string.Format("IsXianHuo=1 "));
  4559. lw.Add(string.Format("IsReturn>0 "));
  4560. lw.Add(string.Format("IsReturn!=3"));
  4561. lw.Add(string.Format("IsRefund<={0}", 1));
  4562. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4563. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4564. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4565. writeGridDataTableJson(dStruct.TotalCount, dt);
  4566. }
  4567. public void set_erp_orderdelivery()
  4568. {
  4569. if (UrlPostParmsCheck("ctid"))
  4570. {
  4571. string eid = GetPostString("ctid");
  4572. CeErpTradeCell entity = null;
  4573. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4574. if (entity != null)
  4575. {
  4576. if (entity.OrderState >= 7)
  4577. {
  4578. returnErrorMsg("此单已发货,无需重复发货");
  4579. return;
  4580. }
  4581. if (entity.OrderState != 6)
  4582. {
  4583. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4584. return;
  4585. }
  4586. string shop = GetPostString("seller_nick");
  4587. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4588. string comName = GetPostString("comName");
  4589. string comCode = GetPostString("comCode");
  4590. string outSid = GetPostString("outSid");
  4591. string deliveryType = GetPostString("deliveryType");
  4592. string deliveryMemo = GetPostString("deliveryMemo");
  4593. outSid = outSid.Trim();
  4594. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4595. if (mainEn == null)
  4596. {
  4597. returnErrorMsg("找不到原始订单记录");
  4598. return;
  4599. }
  4600. bool isInitOrderDeliv = false;
  4601. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4602. {
  4603. isInitOrderDeliv = true;
  4604. }
  4605. string apires = "";
  4606. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4607. 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)
  4608. {
  4609. apires = "发货成功true";
  4610. }
  4611. else
  4612. {
  4613. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4614. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4615. }
  4616. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4617. {
  4618. entity.OrderState = 7;//发货后订单已发货
  4619. entity.OutSid = outSid;
  4620. entity.MemoOpt = 0;
  4621. entity.UpdateTime = DateTime.Now;
  4622. entity.FinishDeliveryTime = DateTime.Now;
  4623. entity.Update();
  4624. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4625. commonHelper.UpdateRelationOrder(entity.ctid);
  4626. //还要插入快递信息到 快递信息表
  4627. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4628. exinfo.tid = eid;
  4629. exinfo.out_sid = outSid;
  4630. exinfo.company_code = comCode;
  4631. exinfo.company_name = comName;
  4632. exinfo.delivery_memo = deliveryMemo;
  4633. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4634. exinfo.deliveryType = deliveryType;
  4635. exinfo.Create();
  4636. returnSuccessMsg("发货操作成功!");
  4637. commonHelper.UpdateRelationOrder(entity.ctid);
  4638. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4639. CeErpSukuraData.createInfo(entity.ctid, 4);
  4640. if (entity.SupplierId == 64)
  4641. {
  4642. commonHelper.sendCytExpress(exinfo);
  4643. }
  4644. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4645. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4646. }
  4647. else
  4648. {
  4649. string errmsg = commonHelper.KeepChinese(apires);
  4650. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4651. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4652. }
  4653. return;
  4654. }
  4655. returnErrorMsg("找不到订单记录");
  4656. }
  4657. }
  4658. public void set_erp_multidelivery()
  4659. {
  4660. string eids = GetPostString("tids");
  4661. string[] eidList = eids.Split(',');
  4662. if (eidList.Length <= 0)
  4663. {
  4664. returnErrorMsg("发货不能为空");
  4665. return;
  4666. }
  4667. foreach (string ctid in eidList)
  4668. {
  4669. if (ctid.Length <= 0) continue;
  4670. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4671. if (expInfo != null)
  4672. {
  4673. StringBuilder sql = new StringBuilder();
  4674. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4675. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4676. if (dt.Rows.Count > 0)
  4677. {
  4678. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4679. {
  4680. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4681. expInfo.state = "异常";
  4682. expInfo.isMultiDelivery = 1;
  4683. expInfo.Update();
  4684. continue;
  4685. }
  4686. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4687. {
  4688. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4689. expInfo.state = "异常";
  4690. expInfo.Update();
  4691. continue;
  4692. }
  4693. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4694. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4695. bool isInitOrderDeliv = false;
  4696. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4697. {
  4698. isInitOrderDeliv = true;
  4699. expInfo.isMultiDelivery = 1;
  4700. }
  4701. if (ctid.IndexOf("N") != -1)
  4702. {
  4703. StringBuilder sqlbucha = new StringBuilder();
  4704. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4705. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4706. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4707. commonHelper.UpdateRelationOrder(ctid);
  4708. expInfo.delivery_memo = "发货成功";
  4709. expInfo.state = "发货成功";
  4710. expInfo.isMultiDelivery = 1;
  4711. expInfo.Update();
  4712. }
  4713. else
  4714. {
  4715. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4716. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4717. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4718. {
  4719. expInfo.delivery_memo = "发货成功";
  4720. expInfo.state = "发货成功";
  4721. expInfo.isMultiDelivery = 1;
  4722. expInfo.Update();
  4723. commonHelper.UpdateRelationOrder(ctid);
  4724. CeErpSukuraData.createInfo(ctid, 4);
  4725. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4726. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4727. }
  4728. else
  4729. {
  4730. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4731. expInfo.state = "异常";
  4732. expInfo.Update();
  4733. }
  4734. }
  4735. }
  4736. }
  4737. }
  4738. returnSuccessMsg("操作完成");
  4739. }
  4740. public void reset_erp_memoopt()
  4741. {
  4742. if (UrlPostParmsCheck("ctid"))
  4743. {
  4744. string eid = GetPostString("ctid");
  4745. CeErpTradeCell entity = null;
  4746. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4747. if (entity != null)
  4748. {
  4749. string stropt = "";
  4750. if (entity.MemoOpt == 1)
  4751. {
  4752. stropt = "“改稿”";
  4753. }
  4754. else if (entity.MemoOpt == 2)
  4755. {
  4756. stropt = "“定稿”";
  4757. }
  4758. else if (entity.MemoOpt == 3)
  4759. {
  4760. stropt = "“完成查货”";
  4761. CeErpSukuraData.createInfo(entity.ctid, 6);
  4762. }
  4763. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4764. entity.UpdateTime = DateTime.Now;
  4765. entity.MemoOpt = 0;
  4766. entity.Update();
  4767. returnSuccessMsg("操作成功!");
  4768. return;
  4769. }
  4770. returnErrorMsg("找不到记录");
  4771. }
  4772. }
  4773. public void get_erp_deliveryunusual()
  4774. {
  4775. DataStruct dStruct = GetPostStruct();
  4776. List<string> lw = new List<string>();
  4777. string tid = GetPostString("ctid");
  4778. if (tid.Length > 0)
  4779. {
  4780. string select_tid = getTidByCtid(tid);
  4781. lw.Add(string.Format("tid='{0}'", select_tid));
  4782. }
  4783. string shopname = GetPostString("shopname");
  4784. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4785. string buyernick = GetPostString("buyer_nick");
  4786. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4787. string customer = GetPostString("customer");
  4788. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4789. string design = GetPostString("design");
  4790. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4791. string sellermemo = GetPostString("seller_memo");
  4792. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4793. string supplier = GetPostString("supplier");
  4794. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4795. string date1 = GetPostString("date1");
  4796. string date2 = GetPostString("date2");
  4797. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4798. if (dw.Length > 0) lw.Add(dw);
  4799. string placedate1 = GetPostString("placedate1");
  4800. string placedate2 = GetPostString("placedate2");
  4801. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4802. if (dw_place.Length > 0) lw.Add(dw_place);
  4803. string price1 = GetPostString("price1");
  4804. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4805. string price2 = GetPostString("price2");
  4806. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4807. string unusualCon = GetPostString("unusualcon");
  4808. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4809. string posTag = CurrentUser.UserPost.Post.Code;
  4810. if (posTag == "Supplier")
  4811. {
  4812. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4813. }
  4814. lw.Add(string.Format("OrderState = 6"));
  4815. lw.Add(string.Format("UnusualTag = 5"));
  4816. lw.Add(string.Format("IsRefund<={0}", 1));
  4817. dStruct.Order = "FinishPlaceTime desc";
  4818. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4819. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4820. writeGridDataTableJson(dStruct.TotalCount, dt);
  4821. }
  4822. public void get_erp_deliveryedlist()
  4823. {
  4824. DataStruct dStruct = GetPostStruct();
  4825. List<string> lw = new List<string>();
  4826. string tid = GetPostString("ctid");
  4827. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4828. string shopname = GetPostString("shopname");
  4829. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4830. string buyernick = GetPostString("buyer_nick");
  4831. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4832. string customer = GetPostString("customer");
  4833. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4834. string design = GetPostString("design");
  4835. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4836. string sellermemo = GetPostString("seller_memo");
  4837. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4838. string logistics = GetPostString("logistics");
  4839. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4840. string date1 = GetPostString("date1");
  4841. string date2 = GetPostString("date2");
  4842. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4843. //if (dw.Length > 0) lw.Add(dw);
  4844. string placedate1 = GetPostString("placedate1");
  4845. string placedate2 = GetPostString("placedate2");
  4846. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4847. if (fdw.Length > 0) lw.Add(fdw);
  4848. string devdate1 = GetPostString("deliverydate1");
  4849. string devdate2 = GetPostString("deliverydate2");
  4850. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4851. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4852. string price1 = GetPostString("price1");
  4853. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4854. string price2 = GetPostString("price2");
  4855. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4856. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4857. {
  4858. if (tid.Length > 0)
  4859. {
  4860. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4861. if (tid.Length > 5)
  4862. {
  4863. List<string> tids = getTidByCtidLike(tid);
  4864. if (tids.Count > 0 && tids.Count < 10)
  4865. {
  4866. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4867. }
  4868. }
  4869. lw.Add(tid_sql);
  4870. }
  4871. if (buyernick.Length > 0)
  4872. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4873. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4874. if (dw.Length > 0) lw.Add(dw);
  4875. }
  4876. else
  4877. {
  4878. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4879. }
  4880. string posTag = CurrentUser.UserPost.Post.Code;
  4881. if (posTag == "Supplier")
  4882. {
  4883. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4884. }
  4885. else
  4886. {
  4887. string supplier = GetPostString("supplier");
  4888. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4889. }
  4890. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4891. lw.Add(string.Format("type != 'PDD' "));
  4892. lw.Add(string.Format("IsRefund!={0}", 2));
  4893. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4894. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4895. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4896. /*if (tid.Length > 0)
  4897. {
  4898. List<string> tids = new List<string>();
  4899. if (dt != null && dt.Rows.Count > 0)
  4900. {
  4901. foreach (DataRow item in dt.Rows)
  4902. {
  4903. tids.Add("'" + item["tid"] + "'");
  4904. }
  4905. }
  4906. if (tids.Count > 0)
  4907. {
  4908. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4909. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4910. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4911. dt = WebCache.GetData("view_erptradecell", dStruct);
  4912. }
  4913. }*/
  4914. if (dt != null)
  4915. {
  4916. foreach (DataRow dr in dt.Rows)
  4917. {
  4918. 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();
  4919. }
  4920. }
  4921. writeGridDataTableJson(dStruct.TotalCount, dt);
  4922. }
  4923. public void get_erp_pdddeliveryed()
  4924. {
  4925. DataStruct dStruct = GetPostStruct();
  4926. List<string> lw = new List<string>();
  4927. string tid = GetPostString("ctid");
  4928. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4929. string shopname = GetPostString("shopname");
  4930. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4931. string buyernick = GetPostString("buyer_nick");
  4932. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4933. string customer = GetPostString("customer");
  4934. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4935. string design = GetPostString("design");
  4936. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4937. string sellermemo = GetPostString("seller_memo");
  4938. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4939. string logistics = GetPostString("logistics");
  4940. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4941. string date1 = GetPostString("date1");
  4942. string date2 = GetPostString("date2");
  4943. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4944. //if (dw.Length > 0) lw.Add(dw);
  4945. string placedate1 = GetPostString("placedate1");
  4946. string placedate2 = GetPostString("placedate2");
  4947. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4948. if (fdw.Length > 0) lw.Add(fdw);
  4949. string devdate1 = GetPostString("deliverydate1");
  4950. string devdate2 = GetPostString("deliverydate2");
  4951. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4952. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4953. string price1 = GetPostString("price1");
  4954. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4955. string price2 = GetPostString("price2");
  4956. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4957. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4958. {
  4959. if (tid.Length > 0)
  4960. {
  4961. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4962. if (tid.Length > 5)
  4963. {
  4964. List<string> tids = getTidByCtidLike(tid);
  4965. if (tids.Count > 0 && tids.Count < 10)
  4966. {
  4967. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4968. }
  4969. }
  4970. lw.Add(tid_sql);
  4971. }
  4972. if (buyernick.Length > 0)
  4973. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4974. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4975. if (dw.Length > 0) lw.Add(dw);
  4976. }
  4977. else
  4978. {
  4979. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  4980. }
  4981. string posTag = CurrentUser.UserPost.Post.Code;
  4982. if (posTag == "Supplier")
  4983. {
  4984. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4985. }
  4986. else
  4987. {
  4988. string supplier = GetPostString("supplier");
  4989. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4990. }
  4991. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4992. lw.Add(string.Format("type = 'PDD' "));
  4993. lw.Add(string.Format("IsRefund!={0}", 2));
  4994. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4995. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4996. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4997. /* if (tid.Length > 0)
  4998. {
  4999. List<string> tids = new List<string>();
  5000. if (dt != null && dt.Rows.Count > 0)
  5001. {
  5002. foreach (DataRow item in dt.Rows)
  5003. {
  5004. tids.Add("'" + item["tid"] + "'");
  5005. }
  5006. }
  5007. if (tids.Count > 0)
  5008. {
  5009. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5010. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5011. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5012. dt = WebCache.GetData("view_erptradecell", dStruct);
  5013. }
  5014. }*/
  5015. foreach (DataRow dr in dt.Rows)
  5016. {
  5017. 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();
  5018. }
  5019. writeGridDataTableJson(dStruct.TotalCount, dt);
  5020. }
  5021. public void get_erp_jddeliveryed()
  5022. {
  5023. DataStruct dStruct = GetPostStruct();
  5024. List<string> lw = new List<string>();
  5025. string tid = GetPostString("ctid");
  5026. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5027. string shopname = GetPostString("shopname");
  5028. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5029. string buyernick = GetPostString("buyer_nick");
  5030. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5031. string customer = GetPostString("customer");
  5032. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5033. string design = GetPostString("design");
  5034. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5035. string sellermemo = GetPostString("seller_memo");
  5036. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5037. string date1 = GetPostString("date1");
  5038. string date2 = GetPostString("date2");
  5039. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5040. //if (dw.Length > 0) lw.Add(dw);
  5041. string placedate1 = GetPostString("placedate1");
  5042. string placedate2 = GetPostString("placedate2");
  5043. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5044. if (fdw.Length > 0) lw.Add(fdw);
  5045. string devdate1 = GetPostString("deliverydate1");
  5046. string devdate2 = GetPostString("deliverydate2");
  5047. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5048. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5049. string price1 = GetPostString("price1");
  5050. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5051. string price2 = GetPostString("price2");
  5052. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5053. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5054. {
  5055. if (tid.Length > 0)
  5056. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5057. if (buyernick.Length > 0)
  5058. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5059. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5060. if (dw.Length > 0) lw.Add(dw);
  5061. }
  5062. else
  5063. {
  5064. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5065. }
  5066. string posTag = CurrentUser.UserPost.Post.Code;
  5067. if (posTag == "Supplier")
  5068. {
  5069. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5070. }
  5071. else
  5072. {
  5073. string supplier = GetPostString("supplier");
  5074. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5075. }
  5076. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5077. lw.Add(string.Format("type = 'JD' "));
  5078. lw.Add(string.Format("IsRefund!={0}", 2));
  5079. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5080. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5081. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5082. foreach (DataRow dr in dt.Rows)
  5083. {
  5084. 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();
  5085. }
  5086. writeGridDataTableJson(dStruct.TotalCount, dt);
  5087. }
  5088. public void get_erp_allplacelist()
  5089. {
  5090. DataStruct dStruct = GetPostStruct();
  5091. List<string> lw = new List<string>();
  5092. string tid = GetPostString("ctid");
  5093. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5094. string shopname = GetPostString("shopname");
  5095. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5096. string buyernick = GetPostString("buyer_nick");
  5097. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5098. string customer = GetPostString("customer");
  5099. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5100. string design = GetPostString("design");
  5101. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5102. string sellermemo = GetPostString("seller_memo");
  5103. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5104. string supplier = GetPostString("supplier");
  5105. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5106. string date1 = GetPostString("date1");
  5107. string date2 = GetPostString("date2");
  5108. string pldate1 = GetPostString("placedate1");
  5109. string pldate2 = GetPostString("placedate2");
  5110. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5111. //if (dw.Length > 0) lw.Add(dw);
  5112. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5113. {
  5114. if (tid.Length > 0)
  5115. {
  5116. string select_tid = getTidByCtid(tid);
  5117. lw.Add(string.Format("tid='{0}'", select_tid));
  5118. }
  5119. if (buyernick.Length > 0)
  5120. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5121. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5122. if (dw.Length > 0) lw.Add(dw);
  5123. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5124. if (dw_place.Length > 0) lw.Add(dw_place);
  5125. }
  5126. else
  5127. {
  5128. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5129. {
  5130. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5131. }
  5132. }
  5133. string price1 = GetPostString("price1");
  5134. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5135. string price2 = GetPostString("price2");
  5136. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5137. string posTag = CurrentUser.UserPost.Post.Code;
  5138. if (posTag == "Supplier")
  5139. {
  5140. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5141. }
  5142. lw.Add(string.Format("OrderState >= 6"));
  5143. lw.Add(string.Format("IsSample != 2 "));
  5144. //lw.Add(string.Format("isDianziOrder = 0 "));
  5145. lw.Add(string.Format("SupplierId > 0 "));
  5146. //lw.Add(string.Format("IsRefund<={0}", 1));
  5147. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5148. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5149. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5150. foreach (DataRow dr in dt.Rows)
  5151. {
  5152. 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();
  5153. }
  5154. writeGridDataTableJson(dStruct.TotalCount, dt);
  5155. }
  5156. public void get_erp_financeallplacelist()
  5157. {
  5158. DataStruct dStruct = GetPostStruct();
  5159. List<string> lw = new List<string>();
  5160. string tid = GetPostString("ctid");
  5161. string shopname = GetPostString("shopname");
  5162. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5163. string buyernick = GetPostString("buyer_nick");
  5164. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5165. string customer = GetPostString("customer");
  5166. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5167. string design = GetPostString("design");
  5168. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5169. string sellermemo = GetPostString("seller_memo");
  5170. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5171. string supplier = GetPostString("supplier");
  5172. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5173. string date1 = GetPostString("date1");
  5174. string date2 = GetPostString("date2");
  5175. string pldate1 = GetPostString("placedate1");
  5176. string pldate2 = GetPostString("placedate2");
  5177. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5178. {
  5179. if (tid.Length > 0)
  5180. {
  5181. string select_tid = getTidByCtid(tid);
  5182. lw.Add(string.Format("tid='{0}'", select_tid));
  5183. }
  5184. if (buyernick.Length > 0)
  5185. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5186. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5187. if (dw.Length > 0) lw.Add(dw);
  5188. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5189. if (dw_place.Length > 0) lw.Add(dw_place);
  5190. }
  5191. else
  5192. {
  5193. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5194. {
  5195. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5196. }
  5197. }
  5198. string price1 = GetPostString("price1");
  5199. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5200. string price2 = GetPostString("price2");
  5201. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5202. string posTag = CurrentUser.UserPost.Post.Code;
  5203. if (posTag == "Supplier")
  5204. {
  5205. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5206. }
  5207. //lw.Add(string.Format("OrderState >= 6"));
  5208. lw.Add(string.Format("IsSample != 2 "));
  5209. lw.Add(string.Format("isDianziOrder = 0 "));
  5210. //lw.Add(string.Format("IsRefund<={0}", 1));
  5211. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5212. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5213. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5214. foreach (DataRow dr in dt.Rows)
  5215. {
  5216. 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();
  5217. }
  5218. writeGridDataTableJson(dStruct.TotalCount, dt);
  5219. }
  5220. public void get_erp_expresslist()
  5221. {
  5222. int listtype = GetInt("ltype");
  5223. DataStruct dStruct = GetPostStruct();
  5224. List<string> lw = new List<string>();
  5225. string tid = GetPostString("tid");
  5226. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5227. string outsid = GetPostString("out_sid");
  5228. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5229. string importer = GetPostString("ImportUserName");
  5230. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5231. string file = GetPostString("import_file");
  5232. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5233. string printman = GetPostString("printman");
  5234. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5235. string date1 = GetPostString("date1");
  5236. string date2 = GetPostString("date2");
  5237. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5238. if (dw.Length > 0) lw.Add(dw);
  5239. string fdate1 = GetPostString("finishdate1");
  5240. string fdate2 = GetPostString("finishdate2");
  5241. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5242. if (fdw.Length > 0) lw.Add(fdw);
  5243. string supplierId = GetPostString("supplierId");
  5244. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5245. if (listtype == 1)
  5246. {
  5247. lw.Add(string.Format("importUserId !=0"));
  5248. }
  5249. string posTag = CurrentUser.UserPost.Post.Code;
  5250. if (posTag == "Supplier")
  5251. {
  5252. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5253. }
  5254. if (dStruct.PageSize != 100000)
  5255. {
  5256. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5257. }
  5258. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5259. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5260. writeGridDataTableJson(dStruct.TotalCount, dt);
  5261. }
  5262. public void set_erp_buchaorderdelivery()
  5263. {
  5264. if (UrlPostParmsCheck("ctid"))
  5265. {
  5266. string eid = GetPostString("ctid");
  5267. CeErpTradeCell entity = null;
  5268. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5269. if (entity != null)
  5270. {
  5271. if (entity.IsSample != 2)
  5272. {
  5273. returnErrorMsg("补差价单才能标记为已发货");
  5274. return;
  5275. }
  5276. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5277. entity.OrderState = 7;
  5278. entity.Update();
  5279. returnSuccessMsg("操作成功!");
  5280. return;
  5281. }
  5282. returnErrorMsg("找不到记录");
  5283. }
  5284. }
  5285. public void get_stdtemplates()
  5286. {
  5287. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5288. //string res = taobaoHelper.test();
  5289. string res = apiHelper.API_PrintTemplate();
  5290. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5291. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5292. {
  5293. int sidx = res.IndexOf("error_code");
  5294. int eidx = res.IndexOf("success");
  5295. string msg = res.Substring(sidx, eidx - sidx);
  5296. returnErrorMsg(msg);
  5297. return;
  5298. }
  5299. if (res.Length <= 0)
  5300. {
  5301. returnErrorMsg("模板数据为空!");
  5302. return;
  5303. }
  5304. ReturnSuccess(res);
  5305. }
  5306. public void cancel_print_order()
  5307. {
  5308. if (UrlPostParmsCheck("ctid"))
  5309. {
  5310. string ctid = GetPostString("ctid");
  5311. CeErpTradeCell entity = null;
  5312. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5313. if (entity != null)
  5314. {
  5315. string res = "";
  5316. string code = entity.LastBillWaybillCode;
  5317. if (code == "")
  5318. {
  5319. code = entity.OutSid;
  5320. }
  5321. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5322. XLog.SaveLog(0, "取消面单" + res);
  5323. }
  5324. }
  5325. }
  5326. public void set_erp_printwaybill()
  5327. {
  5328. if (UrlPostParmsCheck("ctid"))
  5329. {
  5330. string ctid = GetPostString("ctid");
  5331. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5332. string cpName = GetPostString("cpname");
  5333. string isTogether = GetPostString("together");
  5334. //var res_obj = new
  5335. //{
  5336. // restype = 1,
  5337. // 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\"}"
  5338. //};
  5339. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5340. //ReturnSuccess(ro_json);
  5341. //return;
  5342. bool isUseLastWayBillCode = false;
  5343. CeErpTradeCell entity = null;
  5344. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5345. if (entity != null)
  5346. {
  5347. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5348. {
  5349. isUseLastWayBillCode = true;
  5350. }
  5351. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5352. {
  5353. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5354. return;
  5355. }
  5356. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5357. {
  5358. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5359. return;
  5360. }
  5361. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5362. {
  5363. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5364. return;
  5365. }
  5366. }
  5367. string res = "";
  5368. Api_waybill_code_response_Obj fullObj = null;
  5369. string pData_str = "";
  5370. string curUseWayBillCode = "";
  5371. if (isUseLastWayBillCode == false)
  5372. {
  5373. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5374. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5375. if (res.IndexOf("failure") != -1)
  5376. {
  5377. //int idx = res.IndexOf("sub_message");
  5378. //int idx2 = res.IndexOf("flag");
  5379. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5380. string errMsgNeed = commonHelper.KeepChinese(res);
  5381. var res_objd = new
  5382. {
  5383. restype = 0,
  5384. data = "获取面单失败" + errMsgNeed
  5385. };
  5386. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5387. returnSuccess(ro_jsond);
  5388. if (res.IndexOf("停发") != -1)
  5389. {
  5390. entity.UnusualCon = "物流停发";
  5391. entity.Update();
  5392. }
  5393. //returnErrorMsg("获取面单失败,"+emsg);
  5394. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5395. return;
  5396. }
  5397. else if (res.IndexOf("errorMsg") != -1)
  5398. {
  5399. //int idx = res.IndexOf("errorMsg");
  5400. //int idx2 = res.IndexOf("}]}");
  5401. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5402. string errMsgNeed = commonHelper.KeepChinese(res);
  5403. var res_objf = new
  5404. {
  5405. restype = 0,
  5406. data = "获取面单失败2" + errMsgNeed
  5407. };
  5408. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5409. if (res.IndexOf("停发") != -1)
  5410. {
  5411. entity.UnusualCon = "物流停发";
  5412. entity.Update();
  5413. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5414. if (trade != null)
  5415. {
  5416. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5417. }
  5418. }
  5419. returnSuccess(ro_jsonf);
  5420. //returnErrorMsg("获取面单失败," + emsg);
  5421. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5422. return;
  5423. }
  5424. try
  5425. {
  5426. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5427. //res = res.Replace(" ", "");
  5428. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5429. }
  5430. catch (Exception ex)
  5431. {
  5432. XLog.SaveLog(0, "生成fullObj" + res);
  5433. var res_objf = new
  5434. {
  5435. restype = 0,
  5436. data = "生成fullObj发生错误" + ex.Message
  5437. };
  5438. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5439. returnSuccess(ro_jsonf);
  5440. return;
  5441. }
  5442. if (fullObj.response.data.content.Count > 0)
  5443. {
  5444. ContentItem codeObj = fullObj.response.data.content[0];
  5445. if (cpCode.IndexOf("SFFQ-") != -1)
  5446. {
  5447. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5448. }
  5449. else
  5450. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5451. curUseWayBillCode = codeObj.waybillCode;
  5452. }
  5453. else
  5454. {
  5455. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5456. var res_objf = new
  5457. {
  5458. restype = 0,
  5459. data = "生成fullObj找不到快递单号waybillCode"
  5460. };
  5461. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5462. returnSuccess(ro_jsonf);
  5463. return;
  5464. }
  5465. }
  5466. else
  5467. {
  5468. //使用上次打印的快递单号
  5469. if (cpCode == "SFFQ-LY")
  5470. {
  5471. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5472. }
  5473. else
  5474. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5475. curUseWayBillCode = entity.LastBillWaybillCode;
  5476. }
  5477. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5478. {
  5479. var res_obje = new
  5480. {
  5481. restype = 0,
  5482. data = "获取加密打印数据失败"
  5483. };
  5484. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5485. returnSuccess(ro_jsone);
  5486. entity.LastBillCpCode = cpCode;
  5487. entity.LastBillWaybillCode = curUseWayBillCode;
  5488. entity.Update();
  5489. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5490. //returnErrorMsg("获取加密打印数据失败");
  5491. return;
  5492. }
  5493. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5494. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5495. string btnType = "";
  5496. string errorMsg = "";
  5497. if (entity != null)
  5498. {
  5499. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5500. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5501. //cpcode是 YTO-CAINIAO
  5502. //string comCode = cpCode.Split('-')[0].ToString();
  5503. string apires = "";
  5504. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5505. //isTogether=2是新的合包弹窗
  5506. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5507. {
  5508. if (ctid.IndexOf("N") != -1)
  5509. {
  5510. apires = "发货成功";
  5511. }
  5512. else
  5513. {
  5514. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5515. }
  5516. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5517. //打单后发货
  5518. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5519. {
  5520. try
  5521. {
  5522. btnType = "待发货";
  5523. entity.OutSid = curUseWayBillCode;
  5524. entity.OrderState = 7;
  5525. entity.IsUrgency = false;
  5526. entity.LastBillCpCode = "";
  5527. entity.LastBillWaybillCode = "";
  5528. entity.FinishDeliveryTime = DateTime.Now;
  5529. entity.IsReturn = 0;
  5530. entity.MemoOpt = 0;
  5531. entity.UpdateTime = DateTime.Now;
  5532. entity.Update();
  5533. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5534. //还要插入快递信息到 快递信息表
  5535. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5536. exinfo.tid = entity.ctid;
  5537. exinfo.out_sid = curUseWayBillCode;
  5538. exinfo.company_code = cpCode;
  5539. exinfo.company_name = cpName;
  5540. exinfo.supplierUserName = supplierName;
  5541. exinfo.deliveryType = "发货成功";
  5542. exinfo.print_time = DateTime.Now;
  5543. exinfo.printUser = CurrentUser.UserName;
  5544. exinfo.postData = pData_str;
  5545. exinfo.Create();
  5546. commonHelper.UpdateRelationOrder(entity.ctid);
  5547. CeErpSukuraData.createInfo(ctid, 4);
  5548. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5549. if (entity.SupplierId == 64)
  5550. {
  5551. commonHelper.sendCytExpress(exinfo);
  5552. }
  5553. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5554. if (!string.IsNullOrEmpty(isTogether))
  5555. {
  5556. if (Convert.ToInt32(isTogether) > 0)
  5557. {
  5558. StringBuilder sqlsb = new StringBuilder();
  5559. 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);
  5560. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5561. }
  5562. }
  5563. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5564. }
  5565. catch (Exception ex)
  5566. {
  5567. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5568. }
  5569. }
  5570. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5571. {
  5572. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5573. if (entity.OrderState == 6)
  5574. {
  5575. entity.OrderState = 7;
  5576. }
  5577. entity.UpdateTime = DateTime.Now;
  5578. entity.FinishDeliveryTime = DateTime.Now;
  5579. btnType = "已发货";
  5580. entity.Update();
  5581. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5582. exinfo.tid = entity.ctid;
  5583. exinfo.out_sid = curUseWayBillCode;
  5584. exinfo.company_code = cpCode;
  5585. exinfo.company_name = cpName;
  5586. exinfo.supplierUserName = supplierName;
  5587. exinfo.deliveryType = "发货成功";
  5588. exinfo.print_time = DateTime.Now;
  5589. exinfo.printUser = CurrentUser.UserName;
  5590. exinfo.postData = pData_str;
  5591. exinfo.Create();
  5592. commonHelper.UpdateRelationOrder(entity.ctid);
  5593. CeErpSukuraData.createInfo(entity.ctid, 4);
  5594. if (entity.SupplierId == 64)
  5595. {
  5596. commonHelper.sendCytExpress(exinfo);
  5597. }
  5598. if (!string.IsNullOrEmpty(isTogether))
  5599. {
  5600. if (Convert.ToInt32(isTogether) > 0)
  5601. {
  5602. StringBuilder sqlsb = new StringBuilder();
  5603. 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);
  5604. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5605. }
  5606. }
  5607. //不处理
  5608. }
  5609. else
  5610. {
  5611. entity.UpdateTime = DateTime.Now;
  5612. entity.LastBillCpCode = cpCode;
  5613. entity.LastBillWaybillCode = curUseWayBillCode;
  5614. entity.Update();
  5615. string errmsg = commonHelper.KeepChinese(apires);
  5616. var res_objz = new
  5617. {
  5618. restype = 0,
  5619. data = "打单后发货失败"
  5620. };
  5621. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5622. returnSuccess(ro_jsonz);
  5623. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5624. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5625. return;
  5626. }
  5627. }
  5628. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5629. {
  5630. DataTable dt = getSameOrderList(entity, mainEn);
  5631. List<string> list = new List<string>();
  5632. List<string> send_list = new List<string>();
  5633. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5634. CeErpTrade ceErpTrade = new CeErpTrade();
  5635. //可合包的合并一起发货
  5636. if (dt == null)
  5637. {
  5638. var res_objz = new
  5639. {
  5640. restype = 0,
  5641. data = "打单后发货失败"
  5642. };
  5643. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5644. returnSuccess(ro_jsonz);
  5645. return;
  5646. }
  5647. foreach (DataRow row in dt.Rows)
  5648. {
  5649. list.Add("'" + row["ctid"] + "'");
  5650. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5651. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5652. if (ctid.IndexOf("N") != -1)
  5653. {
  5654. apires = "发货成功";
  5655. }
  5656. else
  5657. {
  5658. if (!send_list.Contains(ceErpTrade.tid))
  5659. {
  5660. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5661. }
  5662. else
  5663. {
  5664. apires = "发货成功";
  5665. }
  5666. }
  5667. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5668. {
  5669. send_list.Add(ceErpTrade.tid);
  5670. try
  5671. {
  5672. btnType = "待发货";
  5673. ceErpTradeCell.OutSid = curUseWayBillCode;
  5674. ceErpTradeCell.OrderState = 7;
  5675. ceErpTradeCell.IsUrgency = false;
  5676. ceErpTradeCell.LastBillCpCode = "";
  5677. ceErpTradeCell.LastBillWaybillCode = "";
  5678. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5679. ceErpTradeCell.IsReturn = 0;
  5680. ceErpTradeCell.MemoOpt = 0;
  5681. ceErpTradeCell.UpdateTime = DateTime.Now;
  5682. ceErpTradeCell.Update();
  5683. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5684. //还要插入快递信息到 快递信息表
  5685. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5686. exinfo.tid = ceErpTradeCell.ctid;
  5687. exinfo.out_sid = curUseWayBillCode;
  5688. exinfo.company_code = cpCode;
  5689. exinfo.company_name = cpName;
  5690. exinfo.supplierUserName = supplierName;
  5691. exinfo.deliveryType = "发货成功";
  5692. exinfo.print_time = DateTime.Now;
  5693. exinfo.printUser = CurrentUser.UserName;
  5694. exinfo.postData = pData_str;
  5695. exinfo.Create();
  5696. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5697. CeErpSukuraData.createInfo(ctid, 4);
  5698. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5699. if (ceErpTradeCell.SupplierId == 64)
  5700. {
  5701. commonHelper.sendCytExpress(exinfo);
  5702. }
  5703. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5704. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5705. }
  5706. catch (Exception ex)
  5707. {
  5708. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5709. }
  5710. }
  5711. else
  5712. {
  5713. ceErpTradeCell.UpdateTime = DateTime.Now;
  5714. ceErpTradeCell.LastBillCpCode = cpCode;
  5715. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5716. ceErpTradeCell.Update();
  5717. string errmsg = commonHelper.KeepChinese(apires);
  5718. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5719. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5720. }
  5721. }
  5722. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5723. }
  5724. }
  5725. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5726. var res_obj = new
  5727. {
  5728. restype = 1,
  5729. data = pData_str,
  5730. errorMsg
  5731. };
  5732. string ro_json = JsonConvert.SerializeObject(res_obj);
  5733. ReturnSuccess(ro_json);
  5734. return;
  5735. }
  5736. }
  5737. private string GetUTF8String(byte[] vs)
  5738. {
  5739. throw new NotImplementedException();
  5740. }
  5741. public void set_erp_printwaybill_cn()
  5742. {
  5743. if (UrlPostParmsCheck("ctid"))
  5744. {
  5745. string ctid = GetPostString("ctid");
  5746. string cpCode = GetPostString("cpcode");
  5747. string cpName = GetPostString("cpname");
  5748. string tempUrl = GetPostString("tempurl");
  5749. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5750. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5751. //string res = taobaoHelper.test();
  5752. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5753. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5754. {
  5755. int sidx = res.IndexOf("errorMsg");
  5756. int eidx = res.IndexOf("}");
  5757. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5758. var res_objzxx = new
  5759. {
  5760. restype = 0,
  5761. data = msg
  5762. };
  5763. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5764. returnSuccess(ro_jsonzxx);
  5765. //returnErrorMsg(msg);
  5766. return;
  5767. }
  5768. int idx = res.IndexOf("waybillCode");
  5769. int idx2 = res.IndexOf("printData");
  5770. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5771. string eid = GetPostString("ctid");
  5772. CeErpTradeCell entity = null;
  5773. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5774. if (entity != null)
  5775. {
  5776. string osid = entity.OutSid;
  5777. entity.OutSid = osid + "," + outsid;
  5778. entity.FinishDeliveryTime = DateTime.Now;
  5779. entity.OrderState = 7;
  5780. entity.UpdateTime = DateTime.Now;
  5781. entity.IsReturn = 0;
  5782. entity.Update();
  5783. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5784. exinfo.tid = entity.ctid;
  5785. exinfo.out_sid = outsid;
  5786. exinfo.company_code = cpCode;
  5787. exinfo.company_name = cpName;
  5788. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5789. exinfo.deliveryType = "发货成功";
  5790. exinfo.print_time = DateTime.Now;
  5791. exinfo.printUser = CurrentUser.UserName;
  5792. exinfo.Create();
  5793. if (entity.SupplierId == 64)
  5794. {
  5795. commonHelper.sendCytExpress(exinfo);
  5796. }
  5797. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5798. }
  5799. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5800. var res_objz = new
  5801. {
  5802. restype = 1,
  5803. data = res
  5804. };
  5805. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5806. returnSuccess(ro_jsonz);
  5807. //ReturnSuccess(res);
  5808. }
  5809. }
  5810. ////打单,打印面单 获取面单号
  5811. //public void set_erp_printwaybill()
  5812. //{
  5813. // if (UrlPostParmsCheck("ctid"))
  5814. // {
  5815. // string ctid = GetPostString("ctid");
  5816. // string cpCode = GetPostString("cpcode");
  5817. // string tempUrl = GetPostString("tempurl");
  5818. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5819. // //string res = taobaoHelper.test();
  5820. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5821. // if (res.IndexOf("error_response") != -1)
  5822. // {
  5823. // int sidx = res.IndexOf("sub_msg");
  5824. // int eidx = res.IndexOf("request_id");
  5825. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5826. // returnErrorMsg(msg);
  5827. // return;
  5828. // }
  5829. // int idx = res.IndexOf("waybill_code");
  5830. // int idx2 = res.IndexOf("}]}");
  5831. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5832. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5833. // ReturnSuccess(res);
  5834. // }
  5835. //}
  5836. public void cancel_erp_aftersale()
  5837. {
  5838. if (UrlPostParmsCheck("ctid"))
  5839. {
  5840. string eid = GetPostString("ctid");
  5841. CeErpTradeCell entity = null;
  5842. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5843. if (entity != null)
  5844. {
  5845. //有过处理的售后,取消也不能删除 售 字,保留
  5846. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5847. {
  5848. entity.AfterSaleState = 4;
  5849. }
  5850. else
  5851. entity.AfterSaleState = 0;
  5852. entity.UpdateTime = DateTime.Now;
  5853. entity.Update();
  5854. returnSuccessMsg("操作成功!");
  5855. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5856. return;
  5857. }
  5858. returnErrorMsg("找不到订单记录");
  5859. }
  5860. }
  5861. public void get_erp_aftersalelist()
  5862. {
  5863. DataStruct dStruct = GetPostStruct();
  5864. List<string> lw = new List<string>();
  5865. int st = GetInt("st");
  5866. string tid = GetPostString("ctid");
  5867. if (st == 3)
  5868. {
  5869. if (tid.Length > 0)
  5870. {
  5871. string select_tid = getTidByCtid(tid);
  5872. lw.Add(string.Format("tid='{0}'", select_tid));
  5873. }
  5874. }
  5875. else
  5876. {
  5877. if (tid.Length > 0)
  5878. {
  5879. string select_tid = getTidByCtid(tid);
  5880. lw.Add(string.Format("tid='{0}'", select_tid));
  5881. }
  5882. }
  5883. string shopname = GetPostString("shopname");
  5884. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5885. string buyernick = GetPostString("buyer_nick");
  5886. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5887. string sellermemo = GetPostString("seller_memo");
  5888. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5889. string orderState = GetPostString("orderState");
  5890. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5891. string afterState = GetPostString("afterstate");
  5892. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5893. string date1 = GetPostString("date1");
  5894. string date2 = GetPostString("date2");
  5895. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5896. if (dw.Length > 0) lw.Add(dw);
  5897. string price1 = GetPostString("price1");
  5898. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5899. string price2 = GetPostString("price2");
  5900. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5901. //lw.Add(string.Format("IsRefund!={0}", 1));
  5902. string reason = GetPostString("reason");
  5903. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5904. string method = GetPostString("method");
  5905. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5906. string handler = GetPostString("handler");
  5907. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5908. string handledate1 = GetPostString("handledate1");
  5909. string handledate2 = GetPostString("handledate2");
  5910. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5911. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5912. string finish1 = GetPostString("finishdate1");
  5913. string finish2 = GetPostString("finishdate2");
  5914. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5915. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5916. string afterdate1 = GetPostString("afterdate1");
  5917. string afterdate2 = GetPostString("afterdate2");
  5918. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5919. if (afterDate.Length > 0) lw.Add(afterDate);
  5920. string supplier = GetPostString("supplier");
  5921. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5922. string responsible = GetPostString("responsibleman");
  5923. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5924. string customer = GetPostString("customer");
  5925. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5926. string design = GetPostString("design");
  5927. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5928. string afterMemoType = GetPostString("aftermemotype");
  5929. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5930. string posCode = CurrentUser.UserPost.Post.Code;
  5931. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5932. //{
  5933. // string vstate = GetPostString("vstate");
  5934. // if (vstate.Length > 0)
  5935. // {
  5936. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5937. // }
  5938. // if (posCode == "Supplier")
  5939. // {
  5940. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5941. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5942. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5943. // }
  5944. // else
  5945. // {
  5946. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5947. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5948. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5949. // {
  5950. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5951. // }
  5952. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5953. // {
  5954. // int orgid = CurrentUser.UserPost.OrgID;
  5955. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5956. // }
  5957. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5958. // {
  5959. // string shopid = CurrentUser.User.pemShop;
  5960. // lw.Add(string.Format("shopId in ({0})", shopid));
  5961. // }
  5962. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5963. // //{
  5964. // // int org_id = CurrentUser.UserPost.OrgID;
  5965. // // lw.Add(string.Format("OrgID={0}", org_id));
  5966. // //}
  5967. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5968. // }
  5969. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5970. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5971. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5972. //}
  5973. if (st == 5)
  5974. {
  5975. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5976. {
  5977. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5978. {
  5979. string shopid = CurrentUser.User.pemShop;
  5980. lw.Add(string.Format("shopId in ({0})", shopid));
  5981. }
  5982. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5983. {
  5984. int mrOrgid = CurrentUser.UserPost.OrgID;
  5985. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5986. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5987. }
  5988. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5989. //{
  5990. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5991. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5992. //}
  5993. else
  5994. {
  5995. string userIdStr = "";
  5996. if (posCode == "CustomerService")
  5997. {
  5998. userIdStr = CurrentUser.UserID + "_k";
  5999. }
  6000. else if (posCode == "Designer" || posCode == "wxDesigner")
  6001. {
  6002. userIdStr = CurrentUser.UserID + "_s";
  6003. }
  6004. else if (posCode == "Place")
  6005. {
  6006. userIdStr = CurrentUser.UserID + "_x";
  6007. }
  6008. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6009. }
  6010. }
  6011. string placedate1 = GetPostString("placedate1");
  6012. string placedate2 = GetPostString("placedate2");
  6013. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6014. if (dwplace.Length > 0) lw.Add(dwplace);
  6015. string supState = GetPostString("supState");
  6016. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6017. string searchType = GetPostString("searchType");
  6018. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6019. {
  6020. lw.Add(string.Format("BackNum>1"));
  6021. }
  6022. lw.Add(string.Format("AfterSaleState>0"));
  6023. if (ex_psize > 0)
  6024. {
  6025. if (CurrentUser.UserPost.Post.Code == "Finance")
  6026. dStruct.Order = "pay_time desc";
  6027. else
  6028. dStruct.Order = "HandleTime desc";
  6029. }
  6030. else
  6031. dStruct.Order = "HandleTime desc";
  6032. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6033. DataTable dt = WebCache.GetData("view_test", dStruct);
  6034. writeGridDataTableJson(dStruct.TotalCount, dt);
  6035. }
  6036. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6037. //{
  6038. // lw.Add(string.Format("AfterSaleState=4"));
  6039. // string code = CurrentUser.UserPost.Post.Code;
  6040. // if (code == "CustomerService")
  6041. // {
  6042. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6043. // }
  6044. // else if (code == "Designer" || code == "DesignerMr")
  6045. // {
  6046. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6047. // }
  6048. // else if (code == "Place" || code == "PlaceMr")
  6049. // {
  6050. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6051. // }
  6052. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6053. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6054. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6055. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6056. //}
  6057. //else //处理中的售后,待处理和处理中合并
  6058. //{
  6059. // if (afterState.Length <= 0)
  6060. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6061. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6062. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6063. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6064. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6065. //}
  6066. }
  6067. public void get_erp_disagreeftersalelist()
  6068. {
  6069. DataStruct dStruct = GetPostStruct();
  6070. List<string> lw = new List<string>();
  6071. int st = 2;
  6072. string tid = GetPostString("ctid");
  6073. if (tid.Length > 0)
  6074. {
  6075. string select_tid = getTidByCtid(tid);
  6076. lw.Add(string.Format("tid='{0}'", select_tid));
  6077. }
  6078. string shopname = GetPostString("shopname");
  6079. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6080. string buyernick = GetPostString("buyer_nick");
  6081. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6082. string sellermemo = GetPostString("seller_memo");
  6083. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6084. string orderState = GetPostString("orderState");
  6085. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6086. string afterState = GetPostString("afterstate");
  6087. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6088. string date1 = GetPostString("date1");
  6089. string date2 = GetPostString("date2");
  6090. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6091. if (dw.Length > 0) lw.Add(dw);
  6092. string price1 = GetPostString("price1");
  6093. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6094. string price2 = GetPostString("price2");
  6095. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6096. //lw.Add(string.Format("IsRefund!={0}", 1));
  6097. string reason = GetPostString("reason");
  6098. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6099. string method = GetPostString("method");
  6100. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6101. string handler = GetPostString("handler");
  6102. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6103. string handledate1 = GetPostString("handledate1");
  6104. string handledate2 = GetPostString("handledate2");
  6105. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6106. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6107. string afterdate1 = GetPostString("afterdate1");
  6108. string afterdate2 = GetPostString("afterdate2");
  6109. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6110. if (afterDate.Length > 0) lw.Add(afterDate);
  6111. string backdate1 = GetPostString("backdate1");
  6112. string backdate2 = GetPostString("backdate2");
  6113. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6114. if (backDate.Length > 0) lw.Add(backDate);
  6115. string supplier = GetPostString("supplier");
  6116. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6117. string responsible = GetPostString("responsibleman");
  6118. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6119. string customer = GetPostString("customer");
  6120. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6121. string design = GetPostString("design");
  6122. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6123. string afterSaleMemo = GetPostString("afterSaleMemo");
  6124. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6125. string afterMemoType = GetPostString("aftermemotype");
  6126. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6127. string aftersakereason = GetPostString("aftersakereason");
  6128. if (aftersakereason.Length > 0)
  6129. {
  6130. if (aftersakereason == "1")
  6131. {
  6132. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6133. }
  6134. if (aftersakereason == "2")
  6135. {
  6136. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6137. }
  6138. }
  6139. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6140. string poscode = CurrentUser.UserPost.Post.Code;
  6141. if (poscode != "SysAdmin")
  6142. {
  6143. string shopid = CurrentUser.User.pemShop;
  6144. lw.Add(string.Format("shopId in ({0})", shopid));
  6145. }
  6146. string searchType = GetPostString("searchType");
  6147. if (searchType == "wait")
  6148. {
  6149. lw.Add(string.Format("HandleTime is null"));
  6150. }
  6151. if (searchType == "handling")
  6152. {
  6153. lw.Add(string.Format("HandleTime is not null "));
  6154. }
  6155. if (searchType == "back" || searchType == "puBack")
  6156. {
  6157. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6158. }
  6159. if (searchType == "reBack")
  6160. {
  6161. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6162. }
  6163. if (searchType == "moreBack")
  6164. {
  6165. lw.Add(string.Format("backNum > 1"));
  6166. }
  6167. lw.Add(string.Format("(AfterSaleState=5)"));
  6168. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6169. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6170. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6171. writeGridDataTableJson(dStruct.TotalCount, dt);
  6172. }
  6173. public void get_erp_handlingaftersalelist()
  6174. {
  6175. DataStruct dStruct = GetPostStruct();
  6176. List<string> lw = new List<string>();
  6177. int st = 2;
  6178. string tid = GetPostString("ctid");
  6179. if (tid.Length > 0)
  6180. {
  6181. string select_tid = getTidByCtid(tid);
  6182. lw.Add(string.Format("tid='{0}'", select_tid));
  6183. }
  6184. string shopname = GetPostString("shopname");
  6185. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6186. string buyernick = GetPostString("buyer_nick");
  6187. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6188. string sellermemo = GetPostString("seller_memo");
  6189. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6190. string orderState = GetPostString("orderState");
  6191. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6192. string afterState = GetPostString("afterstate");
  6193. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6194. string date1 = GetPostString("date1");
  6195. string date2 = GetPostString("date2");
  6196. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6197. if (dw.Length > 0) lw.Add(dw);
  6198. string price1 = GetPostString("price1");
  6199. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6200. string price2 = GetPostString("price2");
  6201. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6202. //lw.Add(string.Format("IsRefund!={0}", 1));
  6203. string reason = GetPostString("reason");
  6204. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6205. string method = GetPostString("method");
  6206. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6207. string handler = GetPostString("handler");
  6208. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6209. string handledate1 = GetPostString("handledate1");
  6210. string handledate2 = GetPostString("handledate2");
  6211. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6212. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6213. string afterdate1 = GetPostString("afterdate1");
  6214. string afterdate2 = GetPostString("afterdate2");
  6215. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6216. if (afterDate.Length > 0) lw.Add(afterDate);
  6217. string supplier = GetPostString("supplier");
  6218. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6219. string responsible = GetPostString("responsibleman");
  6220. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6221. string customer = GetPostString("customer");
  6222. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6223. string design = GetPostString("design");
  6224. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6225. string afterSaleMemo = GetPostString("afterSaleMemo");
  6226. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6227. string afterMemoType = GetPostString("aftermemotype");
  6228. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6229. string afterresult = GetPostString("afterresult");
  6230. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6231. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6232. string poscode = CurrentUser.UserPost.Post.Code;
  6233. if (poscode != "SysAdmin")
  6234. {
  6235. string shopid = CurrentUser.User.pemShop;
  6236. lw.Add(string.Format("shopId in ({0})", shopid));
  6237. }
  6238. string searchType = GetPostString("searchType");
  6239. if (searchType == "wait")
  6240. {
  6241. lw.Add(string.Format("HandleTime is null"));
  6242. }
  6243. if (searchType == "documentary")
  6244. {
  6245. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6246. }
  6247. if (searchType == "handling")
  6248. {
  6249. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6250. }
  6251. if (searchType == "back" || searchType == "puBack")
  6252. {
  6253. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6254. }
  6255. if (searchType == "reBack")
  6256. {
  6257. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6258. }
  6259. if (afterState.Length <= 0)
  6260. {
  6261. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6262. }
  6263. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6264. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6265. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6266. writeGridDataTableJson(dStruct.TotalCount, dt);
  6267. }
  6268. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6269. //public void get_erp_back_handlingaftersalelist()
  6270. //{
  6271. // DataStruct dStruct = GetPostStruct();
  6272. // List<string> lw = new List<string>();
  6273. // string tid = GetPostString("ctid");
  6274. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6275. // string shopname = GetPostString("shopname");
  6276. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6277. // string buyernick = GetPostString("buyer_nick");
  6278. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6279. // string sellermemo = GetPostString("seller_memo");
  6280. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6281. // string orderState = GetPostString("orderState");
  6282. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6283. // string afterState = GetPostString("afterstate");
  6284. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6285. // string date1 = GetPostString("date1");
  6286. // string date2 = GetPostString("date2");
  6287. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6288. // if (dw.Length > 0) lw.Add(dw);
  6289. // string price1 = GetPostString("price1");
  6290. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6291. // string price2 = GetPostString("price2");
  6292. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6293. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6294. // string reason = GetPostString("reason");
  6295. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6296. // string method = GetPostString("method");
  6297. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6298. // string handler = GetPostString("handler");
  6299. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6300. // string handledate1 = GetPostString("handledate1");
  6301. // string handledate2 = GetPostString("handledate2");
  6302. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6303. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6304. // string afterdate1 = GetPostString("afterdate1");
  6305. // string afterdate2 = GetPostString("afterdate2");
  6306. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6307. // if (afterDate.Length > 0) lw.Add(afterDate);
  6308. // string supplier = GetPostString("supplier");
  6309. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6310. // string responsible = GetPostString("responsibleman");
  6311. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6312. // string customer = GetPostString("customer");
  6313. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6314. // string design = GetPostString("design");
  6315. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6316. // string afterMemoType = GetPostString("aftermemotype");
  6317. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6318. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6319. // if (afterState.Length <= 0)
  6320. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6321. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6322. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6323. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6324. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6325. //}
  6326. public void get_erp_aftersaleverifylist()
  6327. {
  6328. DataStruct dStruct = GetPostStruct();
  6329. List<string> lw = new List<string>();
  6330. string tid = GetPostString("ctid");
  6331. if (tid.Length > 0)
  6332. {
  6333. string select_tid = getTidByCtid(tid);
  6334. lw.Add(string.Format("otid='{0}'", select_tid));
  6335. }
  6336. string shopname = GetPostString("shopname");
  6337. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6338. string buyernick = GetPostString("buyer_nick");
  6339. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6340. string sellermemo = GetPostString("seller_memo");
  6341. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6342. string orderState = GetPostString("orderState");
  6343. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6344. //lw.Add(string.Format("IsRefund!={0}", 1));
  6345. string reason = GetPostString("reason");
  6346. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6347. string method = GetPostString("method");
  6348. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6349. string handler = GetPostString("handler");
  6350. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6351. string handledate1 = GetPostString("handledate1");
  6352. string handledate2 = GetPostString("handledate2");
  6353. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6354. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6355. string finish1 = GetPostString("finishdate1");
  6356. string finish2 = GetPostString("finishdate2");
  6357. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6358. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6359. string supplier = GetPostString("supplier");
  6360. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6361. string responsible = GetPostString("responsibleman");
  6362. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6363. string posCode = CurrentUser.UserPost.Post.Code;
  6364. string vstate = GetPostString("vstate");
  6365. if (vstate.Length > 0)
  6366. {
  6367. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6368. }
  6369. if (posCode == "Supplier")
  6370. {
  6371. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6372. lw.Add(string.Format("VerifyState = 0"));
  6373. lw.Add("type = 1");
  6374. lw.Add(string.Format("AfterSaleState={0}", 3));
  6375. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6376. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6377. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6378. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6379. writeGridDataTableJson(dStruct.TotalCount, dt);
  6380. }
  6381. else if (posCode == "logistics")
  6382. {
  6383. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6384. lw.Add(string.Format("VerifyState = 0"));
  6385. lw.Add("type = 2");
  6386. lw.Add(string.Format("AfterSaleState={0}", 3));
  6387. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6388. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6389. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6390. writeGridDataTableJson(dStruct.TotalCount, dt);
  6391. }
  6392. else
  6393. {
  6394. lw.Add(string.Format("(AfterSaleState = 3)"));
  6395. string reasonState = GetPostString("reasonState");
  6396. lw.Add("type = 0");
  6397. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6398. || posCode == "Summarize" || posCode == "Finance")
  6399. {
  6400. if (reasonState == "2")
  6401. {
  6402. lw.Add("VerifyState = 3");
  6403. }
  6404. else if (reasonState == "1")
  6405. {
  6406. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6407. }
  6408. else
  6409. {
  6410. lw.Add("VerifyState in (0,3)");
  6411. }
  6412. //不加条件,可以看全部
  6413. }
  6414. 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")
  6415. {
  6416. int orgid = CurrentUser.UserPost.OrgID;
  6417. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6418. if (string.IsNullOrEmpty(manageOrgId))
  6419. {
  6420. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6421. }
  6422. else
  6423. {
  6424. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6425. }
  6426. if (reasonState == "1")
  6427. {
  6428. lw.Add("VerifyState = 3");
  6429. }
  6430. else if (reasonState == "2")
  6431. {
  6432. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6433. }
  6434. else
  6435. {
  6436. }
  6437. }
  6438. else
  6439. {
  6440. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6441. }
  6442. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6443. //{
  6444. // int org_id = CurrentUser.UserPost.OrgID;
  6445. // lw.Add(string.Format("OrgID={0}", org_id));
  6446. //}
  6447. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6448. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6449. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6450. writeGridDataTableJson(dStruct.TotalCount, dt);
  6451. }
  6452. }
  6453. public void get_erp_finishaftersalelist()
  6454. {
  6455. DataStruct dStruct = GetPostStruct();
  6456. List<string> lw = new List<string>();
  6457. int st = 4;
  6458. string tid = GetPostString("ctid");
  6459. if (tid.Length > 0)
  6460. {
  6461. string select_tid = getTidByCtid(tid);
  6462. lw.Add(string.Format("otid='{0}'", select_tid));
  6463. }
  6464. string shopname = GetPostString("shopname");
  6465. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6466. //lw.Add(string.Format("IsRefund!={0}", 1));
  6467. string reason = GetPostString("reason");
  6468. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6469. string method = GetPostString("method");
  6470. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6471. string buyernick = GetPostString("buyer_nick");
  6472. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6473. string handler = GetPostString("handler");
  6474. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6475. string handledate1 = GetPostString("handledate1");
  6476. string handledate2 = GetPostString("handledate2");
  6477. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6478. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6479. string finish1 = GetPostString("finishdate1");
  6480. string finish2 = GetPostString("finishdate2");
  6481. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6482. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6483. string supplier = GetPostString("supplier");
  6484. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6485. string responsible = GetPostString("responsibleman");
  6486. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6487. string vstate = GetPostString("vstate");
  6488. if (vstate.Length > 0)
  6489. {
  6490. if ("3".Equals(vstate))
  6491. {
  6492. lw.Add(string.Format("IsTem=1"));
  6493. }
  6494. else
  6495. {
  6496. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6497. }
  6498. }
  6499. lw.Add(string.Format("AfterSaleState=4"));
  6500. string code = CurrentUser.UserPost.Post.Code;
  6501. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6502. {
  6503. //不加条件,可以看全部
  6504. }
  6505. else if (code == "Supplier")
  6506. {
  6507. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6508. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6509. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6510. }
  6511. else if (code == "logistics")
  6512. {
  6513. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6514. lw.Add("type = 2");
  6515. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6516. }
  6517. 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")
  6518. {
  6519. int orgid = CurrentUser.UserPost.OrgID;
  6520. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6521. if (string.IsNullOrEmpty(manageOrgIds))
  6522. {
  6523. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6524. }
  6525. else
  6526. {
  6527. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6528. }
  6529. }
  6530. else
  6531. {
  6532. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6533. }
  6534. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6535. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6536. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6537. writeGridDataTableJson(dStruct.TotalCount, dt);
  6538. }
  6539. public void handle_erp_aftersale()
  6540. {
  6541. if (UrlPostParmsCheck("ctid"))
  6542. {
  6543. string eid = GetPostString("ctid");
  6544. string responStr = GetPostString("AfterSaleResponsible");
  6545. if (responStr.Length <= 0)
  6546. {
  6547. returnErrorMsg("售后责任人不能为空");
  6548. return;
  6549. }
  6550. bool isDesign = false;
  6551. double designFree = 0.00;
  6552. int responsibleId = 0;
  6553. CeErpTradeCell entity = null;
  6554. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6555. if (entity != null)
  6556. {
  6557. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6558. string afterMethod = GetPostString("AfterSaleMethod");
  6559. if (isNeedNewOrder == 1)
  6560. {
  6561. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6562. bool ishav = true;
  6563. if (newentity == null)
  6564. {
  6565. newentity = entity.Clone() as CeErpTradeCell;
  6566. ishav = false;
  6567. newentity.ctid = "S_" + entity.ctid;
  6568. newentity.OrderState = 0;
  6569. //唯一标识
  6570. newentity.OrderSn = newentity.ctid;
  6571. string orderSn = dataHelper.getSaleOrderSn();
  6572. if (orderSn != "")
  6573. {
  6574. newentity.OrderSn = orderSn;
  6575. }
  6576. }
  6577. newentity.UpdateTime = DateTime.Now;
  6578. newentity.AfterSaleState = 0;
  6579. newentity.AfterSaleMethod = afterMethod;
  6580. if (!ishav)
  6581. {
  6582. string memo_str = newentity.seller_memo;
  6583. memo_str = memo_str.Replace("(", "(");
  6584. memo_str = memo_str.Replace(")", ")");
  6585. int sIndex = memo_str.IndexOf("(");
  6586. int eIndex = memo_str.IndexOf(")");
  6587. if (sIndex == -1 || eIndex == -1)
  6588. {
  6589. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6590. return;
  6591. }
  6592. string first = memo_str.Substring(0, sIndex + 1);
  6593. string memoCtid = newentity.OrderSn;
  6594. //if (memoCtid.IndexOf("C") != -1)
  6595. //{
  6596. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6597. //if (CIdx.IndexOf("+") != -1)
  6598. //{
  6599. //CIdx = "C" + CIdx.Split('+')[1];
  6600. //}
  6601. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6602. //}
  6603. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6604. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6605. string newMemo = first + memoCtid + last;
  6606. newentity.seller_memo = newMemo;
  6607. newentity.FinishPlaceTime = null;
  6608. newentity.UnusualTag = 0;
  6609. newentity.UnusualCon = "";
  6610. newentity.UnusualTime = null;
  6611. newentity.AfterSaleMemo = "";
  6612. newentity.AfterSaleMethod = afterMethod;
  6613. newentity.AfterSalePreTime = null;
  6614. newentity.AfterSaleReason = "";
  6615. newentity.AfterSaleResponsible = "";
  6616. newentity.AfterSaleState = 0;
  6617. newentity.AfterSaleTime = null;
  6618. newentity.AfterSaleUserId = 0;
  6619. newentity.AfterSaleSupplierState = 0;
  6620. newentity.LastBillWaybillCode = "";
  6621. newentity.LastBillCpCode = "";
  6622. newentity.FinishAfterSaleTime = null;
  6623. newentity.HandleTime = null;
  6624. newentity.IsSF = 0;
  6625. newentity.IsOldCustomer = 0;
  6626. newentity.UrgencyTime = null;
  6627. newentity.ResponsibleUserId = "";
  6628. newentity.IsVerifyToSupplier = false;
  6629. newentity.payment = 0;
  6630. newentity.CheckMemo = "";
  6631. newentity.OutSid = "";
  6632. newentity.CheckOrderTime = null;
  6633. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6634. }
  6635. newentity.isAfterSaleOrder = 1;
  6636. newentity.IsRefund = 0;
  6637. string receiveMobile = GetPostString("receiver_mobile");
  6638. if (receiveMobile.Length > 0)
  6639. {
  6640. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6641. if (trade != null)
  6642. {
  6643. trade.receiver_name = GetPostString("receiver_name");
  6644. trade.receiver_mobile = receiveMobile;
  6645. trade.receiver_state = GetPostString("receiver_state");
  6646. trade.receiver_city = GetPostString("receiver_city");
  6647. trade.receiver_district = GetPostString("receiver_district");
  6648. trade.receiver_address = GetPostString("receiver_address");
  6649. newentity.IsOffLineOrder = 1;
  6650. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6651. }
  6652. }
  6653. string st = GetPostString("ToState");
  6654. if (st.Length > 0)
  6655. {
  6656. if (newentity.OrderState <= 3)
  6657. {
  6658. newentity.WaitDesignTime = DateTime.Now;
  6659. newentity.StartDesignTime = null;
  6660. newentity.FinishDesignTime = null;
  6661. newentity.OrderState = 3;
  6662. if (st == "下单员")
  6663. {
  6664. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6665. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6666. {
  6667. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6668. }
  6669. }
  6670. else
  6671. {
  6672. newentity.WaitDesignTime = DateTime.Now;
  6673. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6674. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6675. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6676. {
  6677. DataRow user = dt1.Rows[0];
  6678. //找主管
  6679. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6680. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6681. if (dt != null && dt.Rows.Count > 0)
  6682. {
  6683. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6684. newentity.DesignUserId = designMr;
  6685. string key = "aftersale_order_" + designMr;
  6686. if (RedisHelper.HasKey(key))
  6687. {
  6688. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6689. list.Add(newentity.ctid);
  6690. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6691. }
  6692. }
  6693. //账号正常
  6694. if (user["State"].ToString() == "0")
  6695. {
  6696. newentity.DesignUserId = entity.DesignUserId;
  6697. string key = "aftersale_order_" + entity.DesignUserId;
  6698. if (RedisHelper.HasKey(key))
  6699. {
  6700. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6701. list.Add(newentity.ctid);
  6702. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6703. }
  6704. }
  6705. }
  6706. }
  6707. }
  6708. if (entity.IsXianHuo == 1)
  6709. {
  6710. newentity.OrderState = 6;
  6711. entity.FinishPlaceTime = DateTime.Now;
  6712. }
  6713. }
  6714. if (ishav)
  6715. {
  6716. newentity.Update();
  6717. }
  6718. else
  6719. {
  6720. newentity.Create();
  6721. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6722. newCellExtend.ctid = newentity.ctid;
  6723. newCellExtend.orderFrom = 20;
  6724. newCellExtend.orderType = 30;
  6725. if (st == "下单员")
  6726. {
  6727. }
  6728. else
  6729. {
  6730. newCellExtend.ReprintTime = DateTime.Now;
  6731. }
  6732. newCellExtend.Create();
  6733. }
  6734. if (st != "下单员")
  6735. {
  6736. if (entity.DispatchSort == 2)
  6737. {
  6738. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6739. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6740. }
  6741. }
  6742. }
  6743. //处理售后扩展
  6744. string resIdStr = GetPostString("ResponsibleUserId");
  6745. string refundFees = GetPostString("refundFrees");
  6746. int IsComplain = GetPostInt("isComplain");
  6747. int IsBad = GetPostInt("isBad");
  6748. string IsOriginal = GetPostString("isOriginal");
  6749. double diffResultPrice = GetPostDouble("diffResultPrice");
  6750. string textResult = GetPostString("textResult");
  6751. string supplierResponsible = GetPostString("supplierResponsible");
  6752. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6753. if (ceErpTradeAfterSaleExtend == null)
  6754. {
  6755. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6756. ceErpTradeAfterSaleExtend.tid = eid;
  6757. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6758. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6759. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6760. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6761. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6762. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6763. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6764. ceErpTradeAfterSaleExtend.Create();
  6765. }
  6766. else
  6767. {
  6768. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6769. {
  6770. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6771. }
  6772. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6773. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6774. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6775. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6776. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6777. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6778. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6779. ceErpTradeAfterSaleExtend.Update();
  6780. }
  6781. int gysid = GetPostInt("ResponsibleSupId");
  6782. if (entity.AfterSaleUserId == 0)
  6783. {
  6784. entity.AfterSaleUserId = CurrentUser.UserID;
  6785. }
  6786. entity.ResponsibleUserId = resIdStr;
  6787. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6788. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6789. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6790. {
  6791. CeErpTradeResponsible.DelByTid(eid, -1);
  6792. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6793. int backNum = 0;
  6794. if (number != null)
  6795. {
  6796. backNum = number.BackNum;
  6797. }
  6798. char[] separator = { ',' };
  6799. string[] sArray = resIdStr.Split(separator);
  6800. string[] refundFreeList = { };
  6801. if (refundFees.Length > 0)
  6802. {
  6803. refundFreeList = refundFees.Split(separator);
  6804. }
  6805. int index = -1;
  6806. foreach (string i in sArray)
  6807. {
  6808. index++;
  6809. if (i.Length <= 0) continue;
  6810. char[] separator2 = { '_' };
  6811. string idstr = i.Split(separator2)[0];
  6812. string idtype = i.Split(separator2)[1];
  6813. double refudFree = 0;
  6814. if (refundFreeList.Length > 0)
  6815. {
  6816. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6817. }
  6818. if (idtype == "s")
  6819. {
  6820. isDesign = true;
  6821. designFree = refudFree;
  6822. }
  6823. int userId = Convert.ToInt32(idstr);
  6824. int type = 0;
  6825. if (idtype == "g")
  6826. {
  6827. type = 1;
  6828. }
  6829. if (idtype == "w")
  6830. {
  6831. type = 2;
  6832. }
  6833. if (idtype == "t")
  6834. {
  6835. type = 3;
  6836. }
  6837. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6838. if (ceErpTradeResponsible == null)
  6839. {
  6840. ceErpTradeResponsible = new CeErpTradeResponsible();
  6841. ceErpTradeResponsible.tid = eid;
  6842. ceErpTradeResponsible.UserId = userId;
  6843. ceErpTradeResponsible.createdTime = DateTime.Now;
  6844. ceErpTradeResponsible.type = type;
  6845. if (type == 1)
  6846. {
  6847. ceErpTradeResponsible.IsSup = 1;
  6848. }
  6849. if (type == 2)
  6850. {
  6851. ceErpTradeResponsible.IsFlow = 1;
  6852. }
  6853. }
  6854. ceErpTradeResponsible.RefundFee = refudFree;
  6855. ceErpTradeResponsible.VerifyState = 0;
  6856. if (userId == 2125 || idtype == "w")
  6857. {
  6858. ceErpTradeResponsible.VerifyState = 1;
  6859. }
  6860. if (idtype == "w" && userId == 101)
  6861. {
  6862. ceErpTradeResponsible.VerifyState = 0;
  6863. }
  6864. if (ceErpTradeResponsible.ID > 0)
  6865. {
  6866. ceErpTradeResponsible.Update();
  6867. }
  6868. else
  6869. {
  6870. ceErpTradeResponsible.Create();
  6871. }
  6872. if (isDesign)
  6873. {
  6874. responsibleId = ceErpTradeResponsible.ID;
  6875. }
  6876. }
  6877. CeErpTradeResponsible.NumByTid(backNum, eid);
  6878. }
  6879. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6880. if (ceErpTradeCellExtend != null)
  6881. {
  6882. ceErpTradeCellExtend.returnVisit = 0;
  6883. ceErpTradeCellExtend.Update();
  6884. }
  6885. if (entity.HandleTime != null)
  6886. {
  6887. if (entity.AfterSaleState == 1)
  6888. {
  6889. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6890. }
  6891. else
  6892. {
  6893. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6894. }
  6895. }
  6896. else
  6897. {
  6898. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6899. entity.HandleTime = DateTime.Now;
  6900. }
  6901. bool isCompale = false;
  6902. if (entity.AfterSaleState == 5)
  6903. {
  6904. isCompale = true;
  6905. entity.AfterSaleState = 3;
  6906. }
  6907. entity.AfterSaleSupplierState = 0;
  6908. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6909. {
  6910. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6911. }
  6912. string sImgs = GetPostString("img");
  6913. entity.AfterSaleSupplierImg = sImgs;
  6914. entity.supRefundType = GetPostString("supRefundType");
  6915. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6916. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6917. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6918. entity.AfterSaleMemoType = GetPostString("MemoType");
  6919. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6920. {
  6921. //entity.AfterSaleSupplierState = 2;
  6922. }
  6923. string df = GetPostString("DeductFee");
  6924. if (df == "")
  6925. {
  6926. df = "0";
  6927. }
  6928. string rf = GetPostString("RefundFee");
  6929. if (rf == "")
  6930. {
  6931. rf = "0";
  6932. }
  6933. string pm = GetPostString("AfterSalePayment");
  6934. if (pm == "")
  6935. {
  6936. pm = "0";
  6937. }
  6938. entity.AfterSalePayment = Convert.ToDouble(pm);
  6939. entity.DeductFee = Convert.ToDouble(df);
  6940. entity.RefundFee = Convert.ToDouble(rf);
  6941. entity.UpdateTime = DateTime.Now;
  6942. entity.Update();
  6943. string toState = GetPostString("ToState");
  6944. string original = GetPostString("isOriginal");
  6945. ApiVo apiVo = new ApiVo();
  6946. apiVo.orderNumber = entity.ctid;
  6947. apiVo.actionName = "afterDesign";
  6948. apiVo.orderRemarks = entity.AfterSaleMethod;
  6949. apiVo.reasonRemarks = entity.AfterSaleReason;
  6950. apiVo.isDesign = isDesign;
  6951. apiVo.designFree = designFree;
  6952. apiVo.responsibleId = responsibleId;
  6953. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6954. if (toState == "设计师")
  6955. {
  6956. apiVo.isOriginal = Convert.ToBoolean(original);
  6957. }
  6958. designHelper.API_WorkCore(apiVo);//afterDesign
  6959. CeErpMethod methodSql = new CeErpMethod();
  6960. methodSql.con = entity.AfterSaleMethod;
  6961. methodSql.addTime = DateTime.Now;
  6962. methodSql.Create();
  6963. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6964. CeErpMethod.ExecuteNonQuery(delsql);
  6965. if (isCompale)
  6966. {
  6967. aftersale_data_change(entity.ctid);
  6968. }
  6969. returnSuccessMsg("操作成功!");
  6970. return;
  6971. }
  6972. returnErrorMsg("找不到订单记录");
  6973. }
  6974. }
  6975. public void ins_erp_toresponsible()
  6976. {
  6977. if (UrlPostParmsCheck("ctid"))
  6978. {
  6979. string eid = GetPostString("ctid");
  6980. CeErpTradeCell entity = null;
  6981. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6982. if (entity != null)
  6983. {
  6984. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6985. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6986. {
  6987. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6988. return;
  6989. }
  6990. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6991. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6992. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6993. if (entity.AfterSalePreTime == null)
  6994. {
  6995. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6996. {
  6997. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6998. }
  6999. }
  7000. entity.AfterSalePreTime = DateTime.Now;
  7001. //预完成给售后主管审核客户问题直接完成
  7002. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7003. {
  7004. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7005. {
  7006. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7007. }
  7008. }
  7009. ceErpTradeAfterSaleExtend.Update();
  7010. entity.AfterSaleState = 2;
  7011. entity.UpdateTime = DateTime.Now;
  7012. entity.Update();
  7013. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7014. aftersale_data_change(entity.ctid);
  7015. returnSuccessMsg("操作成功!");
  7016. return;
  7017. }
  7018. returnErrorMsg("找不到订单记录");
  7019. }
  7020. }
  7021. public void cancel_erp_aftersaleanddelnew()
  7022. {
  7023. if (UrlPostParmsCheck("ctid"))
  7024. {
  7025. string eid = GetPostString("ctid");
  7026. CeErpTradeCell entity = null;
  7027. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7028. if (entity != null)
  7029. {
  7030. entity.AfterSaleState = 0;
  7031. entity.AfterSaleReason = "";
  7032. entity.AfterSaleMethod = "";
  7033. entity.AfterSaleMemo = "";
  7034. entity.AfterSaleResponsible = "";
  7035. entity.ResponsibleUserId = "";
  7036. entity.DeductFee = 0;
  7037. entity.RefundFee = 0;
  7038. entity.IsArbitrate = 0;
  7039. CeErpTradeResponsible.DelByTid(eid, -1);
  7040. entity.Update();
  7041. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7042. if (after != null)
  7043. {
  7044. if (after.OrderState < 5)
  7045. CeErpTradeCell.DelByCtid("S_" + eid);
  7046. }
  7047. returnSuccessMsg("操作成功!");
  7048. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7049. return;
  7050. }
  7051. returnErrorMsg("找不到订单记录");
  7052. }
  7053. }
  7054. public void get_erp_aftersale_pregather()
  7055. {
  7056. List<string> lw = new List<string>();
  7057. int st = GetInt("st");
  7058. string tid = GetPostString("ctid");
  7059. if (tid.Length > 0)
  7060. {
  7061. string select_tid = getTidByCtid(tid);
  7062. lw.Add(string.Format("tid='{0}'", select_tid));
  7063. }
  7064. string shopname = GetPostString("shopname");
  7065. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7066. string buyernick = GetPostString("buyer_nick");
  7067. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7068. string sellermemo = GetPostString("seller_memo");
  7069. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7070. string orderState = GetPostString("orderState");
  7071. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7072. string reason = GetPostString("reason");
  7073. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7074. string method = GetPostString("method");
  7075. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7076. string handler = GetPostString("handler");
  7077. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7078. string handledate1 = GetPostString("handledate1");
  7079. string handledate2 = GetPostString("handledate2");
  7080. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7081. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7082. string supplier = GetPostString("supplier");
  7083. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7084. string responsible = GetPostString("responsibleman");
  7085. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7086. string customer = GetPostString("customer");
  7087. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7088. string design = GetPostString("design");
  7089. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7090. string afterMemoType = GetPostString("aftermemotype");
  7091. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7092. string afterSaleMemo = GetPostString("afterSaleMemo");
  7093. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7094. string afterresult = GetPostString("afterresult");
  7095. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7096. string poscode = CurrentUser.UserPost.Post.Code;
  7097. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7098. {
  7099. string shopid = CurrentUser.User.pemShop;
  7100. lw.Add(string.Format("shopId in ({0})", shopid));
  7101. }
  7102. var mainwhere = string.Join(" and ", lw.ToArray());
  7103. string ro_json = "";
  7104. string type = GetPostString("gather_type");
  7105. int number = 0;
  7106. if (poscode == "AfterSale")
  7107. {
  7108. //处理中
  7109. if (type == "Handling")
  7110. {
  7111. 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) : ""));
  7112. DataTable dt = null;
  7113. try
  7114. {
  7115. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7116. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7117. }
  7118. catch (Exception e)
  7119. {
  7120. dt = new DataTable();
  7121. }
  7122. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7123. return;
  7124. }
  7125. if (type == "Wait")
  7126. {
  7127. //待处理
  7128. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7129. DataTable dt1 = null;
  7130. try
  7131. {
  7132. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7133. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7134. }
  7135. catch (Exception e)
  7136. {
  7137. dt1 = new DataTable();
  7138. }
  7139. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7140. return;
  7141. }
  7142. if (type == "back")
  7143. {
  7144. //打回
  7145. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7146. DataTable dt2 = null;
  7147. try
  7148. {
  7149. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7150. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7151. }
  7152. catch (Exception e)
  7153. {
  7154. dt2 = new DataTable();
  7155. }
  7156. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7157. return;
  7158. }
  7159. if (type == "preCompletion")
  7160. {
  7161. //预完成
  7162. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7163. DataTable dt3 = null;
  7164. try
  7165. {
  7166. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7167. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7168. }
  7169. catch (Exception e)
  7170. {
  7171. dt3 = new DataTable();
  7172. }
  7173. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7174. return;
  7175. }
  7176. if (type == "documentary")
  7177. {
  7178. //跟单中
  7179. 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) : ""));
  7180. DataTable dt4 = null;
  7181. try
  7182. {
  7183. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7184. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7185. }
  7186. catch (Exception e)
  7187. {
  7188. dt4 = new DataTable();
  7189. }
  7190. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7191. return;
  7192. }
  7193. if (type == "reBack")
  7194. {
  7195. //被打回
  7196. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7197. DataTable dt1 = null;
  7198. try
  7199. {
  7200. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7201. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7202. }
  7203. catch (Exception e)
  7204. {
  7205. dt1 = new DataTable();
  7206. }
  7207. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7208. return;
  7209. }
  7210. }
  7211. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7212. {
  7213. if (type == "puBack")
  7214. {
  7215. //退回
  7216. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7217. DataTable dt = null;
  7218. try
  7219. {
  7220. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7221. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7222. }
  7223. catch (Exception e)
  7224. {
  7225. dt = new DataTable();
  7226. }
  7227. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7228. return;
  7229. }
  7230. if (type == "reBack")
  7231. {
  7232. //打回
  7233. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7234. DataTable dt1 = null;
  7235. try
  7236. {
  7237. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7238. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7239. }
  7240. catch (Exception e)
  7241. {
  7242. dt1 = new DataTable();
  7243. }
  7244. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7245. return;
  7246. }
  7247. if (type == "examEd")
  7248. {
  7249. //已审核
  7250. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7251. DataTable dt2 = null;
  7252. try
  7253. {
  7254. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7255. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7256. }
  7257. catch (Exception e)
  7258. {
  7259. dt2 = new DataTable();
  7260. }
  7261. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7262. return;
  7263. }
  7264. if (type == "waitExam")
  7265. {
  7266. //待审核
  7267. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7268. DataTable dt3 = null;
  7269. try
  7270. {
  7271. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7272. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7273. }
  7274. catch (Exception e)
  7275. {
  7276. dt3 = new DataTable();
  7277. }
  7278. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7279. return;
  7280. }
  7281. if (type == "Handling")
  7282. {
  7283. //处理中
  7284. 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) : ""));
  7285. DataTable dt4 = null;
  7286. try
  7287. {
  7288. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7289. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7290. }
  7291. catch (Exception e)
  7292. {
  7293. dt4 = new DataTable();
  7294. }
  7295. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7296. return;
  7297. }
  7298. if (type == "Wait")
  7299. {
  7300. //待处理
  7301. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7302. DataTable dt5 = null;
  7303. try
  7304. {
  7305. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7306. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7307. }
  7308. catch (Exception e)
  7309. {
  7310. dt5 = new DataTable();
  7311. }
  7312. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7313. return;
  7314. }
  7315. if (type == "documentary")
  7316. {
  7317. //跟单中
  7318. 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) : ""));
  7319. DataTable dt6 = null;
  7320. try
  7321. {
  7322. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7323. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7324. }
  7325. catch (Exception e)
  7326. {
  7327. dt6 = new DataTable();
  7328. }
  7329. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7330. return;
  7331. }
  7332. }
  7333. returnSuccess(ro_json);
  7334. }
  7335. public void end_erp_aftersale()
  7336. {
  7337. if (UrlPostParmsCheck("ctid"))
  7338. {
  7339. string eid = GetPostString("ctid");
  7340. CeErpTradeCell entity = null;
  7341. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7342. if (entity != null)
  7343. {
  7344. string stype = GetPostString("stype");
  7345. string typeStr = stype;
  7346. entity.AfterSaleState = 4;
  7347. entity.FinishAfterSaleTime = DateTime.Now;
  7348. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7349. entity.Update();
  7350. ApiVo apiVo = new ApiVo();
  7351. apiVo.orderNumber = entity.ctid;
  7352. apiVo.actionName = "afterOver";
  7353. designHelper.API_WorkCore(apiVo); //afterOver
  7354. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7355. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7356. CeErpSukuraData.createInfo(entity.ctid, 8);
  7357. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7358. returnSuccessMsg("操作成功!");
  7359. return;
  7360. }
  7361. returnErrorMsg("找不到订单记录");
  7362. }
  7363. }
  7364. public void ins_erp_finishaftersale()
  7365. {
  7366. if (UrlPostParmsCheck("id"))
  7367. {
  7368. string eid = GetPostString("id");
  7369. CeErpTradeResponsible entity = null;
  7370. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7371. if (entity != null)
  7372. {
  7373. entity.VerifyState = 1;
  7374. entity.VerifyTime = DateTime.Now;
  7375. entity.Update();
  7376. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7377. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7378. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7379. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7380. if (dt.Rows.Count <= 0)
  7381. {
  7382. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7383. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7384. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7385. CeErpSukuraData.createInfo(entity.tid, 8);
  7386. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7387. {
  7388. CeErpDesignerBill.Del(entity.tid);
  7389. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7390. }
  7391. }
  7392. returnSuccessMsg("操作成功!");
  7393. return;
  7394. }
  7395. returnErrorMsg("找不到订单记录");
  7396. }
  7397. }
  7398. public void upd_erp_arbitrateaftersale()
  7399. {
  7400. if (UrlPostParmsCheck("id"))
  7401. {
  7402. string eid = GetPostString("id");
  7403. CeErpTradeResponsible entity = null;
  7404. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7405. if (entity != null)
  7406. {
  7407. entity.IsArbitrate = 1;
  7408. entity.ArbitradeMemo = GetPostString("reason");
  7409. entity.VerifyState = 2;
  7410. entity.Update();
  7411. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7412. if (tradecell != null)
  7413. {
  7414. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7415. tradecell.IsArbitrate = 1;
  7416. tradecell.Update();
  7417. }
  7418. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7419. returnSuccessMsg("操作成功!");
  7420. return;
  7421. }
  7422. returnErrorMsg("找不到订单记录");
  7423. }
  7424. }
  7425. public void upd_erp_backaftersale()
  7426. {
  7427. if (UrlPostParmsCheck("tid"))
  7428. {
  7429. string eid = GetPostString("tid");
  7430. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7431. int backNum = 0;
  7432. if (number != null)
  7433. {
  7434. backNum = number.BackNum;
  7435. }
  7436. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7437. CeErpTradeCell entity = null;
  7438. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7439. if (entity != null)
  7440. {
  7441. entity.AfterSaleBackReason = GetPostString("backreason");
  7442. entity.AfterSaleState = 1;
  7443. entity.AfterSaleSupplierState = 0;
  7444. entity.UpdateTime = DateTime.Now;
  7445. entity.Update();
  7446. returnSuccessMsg("操作成功!");
  7447. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7448. return;
  7449. }
  7450. returnErrorMsg("找不到订单记录");
  7451. }
  7452. }
  7453. public void get_erp_supplieraftersalelist()
  7454. {
  7455. DataStruct dStruct = GetPostStruct();
  7456. List<string> lw = new List<string>();
  7457. string tid = GetPostString("ctid");
  7458. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7459. string shopname = GetPostString("shopname");
  7460. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7461. string buyernick = GetPostString("buyer_nick");
  7462. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7463. string sellermemo = GetPostString("seller_memo");
  7464. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7465. string orderState = GetPostString("orderState");
  7466. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7467. string afterState = GetPostString("afterstate");
  7468. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7469. string date1 = GetPostString("date1");
  7470. string date2 = GetPostString("date2");
  7471. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7472. if (dw.Length > 0) lw.Add(dw);
  7473. string price1 = GetPostString("price1");
  7474. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7475. string price2 = GetPostString("price2");
  7476. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7477. string reason = GetPostString("reason");
  7478. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7479. string method = GetPostString("method");
  7480. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7481. string handledate1 = GetPostString("handledate1");
  7482. string handledate2 = GetPostString("handledate2");
  7483. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7484. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7485. string handler = GetPostString("handler");
  7486. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7487. string afterdate1 = GetPostString("afterdate1");
  7488. string afterdate2 = GetPostString("afterdate2");
  7489. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7490. if (afterDate.Length > 0) lw.Add(afterDate);
  7491. string customer = GetPostString("customer");
  7492. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7493. string design = GetPostString("design");
  7494. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7495. string afterMemoType = GetPostString("aftermemotype");
  7496. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7497. string vstate = GetPostString("vstate");
  7498. if (vstate.Length > 0)
  7499. {
  7500. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7501. }
  7502. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7503. string supplier = GetPostString("supplier");
  7504. int supid = commonHelper.getSupplierIDByName(supplier);
  7505. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7506. string posCode = CurrentUser.UserPost.Post.Code;
  7507. if (posCode == "Supplier")
  7508. {
  7509. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7510. }
  7511. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7512. {
  7513. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7514. }
  7515. else
  7516. {
  7517. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7518. }
  7519. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7520. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7521. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7522. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7523. writeGridDataTableJson(dStruct.TotalCount, dt);
  7524. }
  7525. public void upd_erp_supverifyaftersale()
  7526. {
  7527. if (UrlPostParmsCheck("id"))
  7528. {
  7529. string id = GetPostString("id");
  7530. int st = GetPostInt("afterstate");
  7531. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7532. CeErpTradeCell entity = null;
  7533. if (ceErpTradeResponsible != null)
  7534. {
  7535. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7536. }
  7537. string afmemo = GetPostString("supmemo");
  7538. string image = GetPostString("image");
  7539. if (entity != null)
  7540. {
  7541. entity.AfterSaleSupplierState = st;
  7542. entity.AfterSaleSupplierMemo = afmemo;
  7543. if (st == 1)
  7544. {
  7545. ceErpTradeResponsible.VerifyState = 1;
  7546. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7547. ceErpTradeResponsible.Update();
  7548. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7549. if (isAll)
  7550. {
  7551. entity.AfterSaleState = 4;
  7552. entity.FinishAfterSaleTime = DateTime.Now;
  7553. }
  7554. }
  7555. else
  7556. {
  7557. CeErpTradeResponsible.dateByTid(entity.ctid);
  7558. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7559. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7560. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7561. if (num <= 1)
  7562. {
  7563. entity.AfterSaleState = 1;
  7564. }
  7565. else
  7566. {
  7567. entity.AfterSaleState = 5;
  7568. }
  7569. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7570. if (ceErpTradeAfterSaleExtend != null)
  7571. {
  7572. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7573. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7574. ceErpTradeAfterSaleExtend.Update();
  7575. }
  7576. else
  7577. {
  7578. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7579. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7580. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7581. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7582. ceErpTradeAfterSaleExtend.Create();
  7583. }
  7584. }
  7585. if (entity.AfterSaleState == 4)
  7586. {
  7587. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7588. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7589. {
  7590. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7591. }
  7592. ApiVo apiVo = new ApiVo();
  7593. apiVo.orderNumber = entity.ctid;
  7594. apiVo.actionName = "afterOver";
  7595. designHelper.API_WorkCore(apiVo); //afterOver
  7596. }
  7597. entity.UpdateTime = DateTime.Now;
  7598. entity.Update();
  7599. returnSuccessMsg("操作成功!");
  7600. CeErpSukuraData.createInfo(entity.ctid, 8);
  7601. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7602. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7603. return;
  7604. }
  7605. returnErrorMsg("找不到订单记录");
  7606. }
  7607. }
  7608. public void upd_erp_masteraftersale()
  7609. {
  7610. if (UrlPostParmsCheck("id"))
  7611. {
  7612. string id = GetPostString("id");
  7613. int st = GetPostInt("afterstate");
  7614. string afmemo = GetPostString("supmemo");
  7615. string image = GetPostString("image");
  7616. string textResult = GetPostString("textResult");
  7617. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7618. if (ceErpTradeResponsible != null)
  7619. {
  7620. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7621. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7622. ceErpTradeResponsible.Update();
  7623. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7624. if (entity != null)
  7625. {
  7626. entity.AfterSaleSupplierState = st;
  7627. entity.AfterSaleSupplierMemo = afmemo;
  7628. if (st == 1)
  7629. {
  7630. }
  7631. else
  7632. {
  7633. CeErpTradeResponsible.dateByTid(entity.ctid);
  7634. //退回到售后
  7635. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7636. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7637. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7638. if (num <= 1)
  7639. {
  7640. entity.AfterSaleState = 1;
  7641. }
  7642. else
  7643. {
  7644. entity.AfterSaleState = 5;
  7645. }
  7646. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7647. if (ceErpTradeAfterSaleExtend != null)
  7648. {
  7649. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7650. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7651. ceErpTradeAfterSaleExtend.Update();
  7652. }
  7653. else
  7654. {
  7655. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7656. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7657. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7658. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7659. ceErpTradeAfterSaleExtend.Create();
  7660. }
  7661. }
  7662. entity.UpdateTime = DateTime.Now;
  7663. entity.Update();
  7664. returnSuccessMsg("操作成功!");
  7665. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7666. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7667. return;
  7668. }
  7669. }
  7670. returnErrorMsg("找不到订单记录");
  7671. }
  7672. }
  7673. public void upd_erp_personaftersale()
  7674. {
  7675. if (UrlPostParmsCheck("id"))
  7676. {
  7677. //林小连
  7678. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7679. {
  7680. upd_erp_masteraftersale();
  7681. return;
  7682. }
  7683. string id = GetPostString("id");
  7684. int st = GetPostInt("afterstate");
  7685. string afmemo = GetPostString("supmemo");
  7686. string image = GetPostString("image");
  7687. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7688. if (ceErpTradeResponsible != null)
  7689. {
  7690. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7691. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7692. ceErpTradeResponsible.Update();
  7693. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7694. if (entity != null)
  7695. {
  7696. entity.AfterSaleSupplierMemo = afmemo;
  7697. entity.AfterSaleSupplierState = st;
  7698. if (st == 1)
  7699. {
  7700. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7701. if (isAll)
  7702. {
  7703. entity.AfterSaleState = 4;
  7704. entity.FinishAfterSaleTime = DateTime.Now;
  7705. }
  7706. }
  7707. else
  7708. {
  7709. CeErpTradeResponsible.dateByTid(entity.ctid);
  7710. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7711. if (ceErpTradeAfterSaleExtend != null)
  7712. {
  7713. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7714. ceErpTradeAfterSaleExtend.Update();
  7715. }
  7716. else
  7717. {
  7718. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7719. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7720. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7721. ceErpTradeAfterSaleExtend.Create();
  7722. }
  7723. //退回到主管
  7724. //entity.AfterSaleState = 2;
  7725. }
  7726. if (entity.AfterSaleState == 4)
  7727. {
  7728. ApiVo apiVo = new ApiVo();
  7729. apiVo.orderNumber = entity.ctid;
  7730. apiVo.actionName = "afterOver";
  7731. designHelper.API_WorkCore(apiVo); //afterOver
  7732. }
  7733. entity.UpdateTime = DateTime.Now;
  7734. entity.Update();
  7735. returnSuccessMsg("操作成功!");
  7736. CeErpSukuraData.createInfo(entity.ctid, 8);
  7737. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7738. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7739. return;
  7740. }
  7741. }
  7742. returnErrorMsg("找不到订单记录");
  7743. }
  7744. }
  7745. public void set_erp_supplierrefundtag()
  7746. {
  7747. if (UrlPostParmsCheck("ctid"))
  7748. {
  7749. string eid = GetPostString("ctid");
  7750. CeErpTradeCell entity = null;
  7751. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7752. if (entity != null)
  7753. {
  7754. entity.IsSupplierRefund = GetPostInt("tag");
  7755. entity.Update();
  7756. returnSuccessMsg("操作成功!");
  7757. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7758. return;
  7759. }
  7760. returnErrorMsg("找不到订单记录");
  7761. }
  7762. }
  7763. public void get_erp_refundlist()
  7764. {
  7765. DataStruct dStruct = GetPostStruct();
  7766. List<string> lw = new List<string>();
  7767. string tid = GetPostString("tid");
  7768. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7769. //string rid = GetPostString("refund_id");
  7770. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7771. string shopname = GetPostString("shopname");
  7772. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7773. string buyernick = GetPostString("buyer_nick");
  7774. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7775. string customer = GetPostString("customer");
  7776. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7777. string design = GetPostString("design");
  7778. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7779. string sellermemo = GetPostString("seller_memo");
  7780. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7781. //string date1 = GetPostString("date1");
  7782. //string date2 = GetPostString("date2");
  7783. //string dateType = GetPostString("dateType");
  7784. //if (dateType.Length > 0)
  7785. //{
  7786. // if (dateType == "1001") dateType = "0";
  7787. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7788. // if (searchDT.Count == 2)
  7789. // {
  7790. // date1 = searchDT[0].ToString();
  7791. // date2 = searchDT[1].ToString();
  7792. // }
  7793. //}
  7794. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7795. //if (dw.Length > 0) lw.Add(dw);
  7796. string redate1 = GetPostString("refunddate1");
  7797. string redate2 = GetPostString("refunddate2");
  7798. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7799. if (dwdate.Length > 0) lw.Add(dwdate);
  7800. string price1 = GetPostString("price1");
  7801. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7802. string price2 = GetPostString("price2");
  7803. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7804. string ispartrefund = GetPostString("ispartrefund");
  7805. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7806. string refundState = GetPostString("refundvstate");
  7807. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7808. int st = GetInt("st");
  7809. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7810. {
  7811. string responsible = GetPostString("responsibleman");
  7812. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7813. lw.Add(string.Format("RefundState>={0}", st));
  7814. string code = CurrentUser.UserPost.Post.Code;
  7815. if (code == "CustomerService")
  7816. {
  7817. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7818. }
  7819. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7820. {
  7821. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7822. }
  7823. else if (code == "Place" || code == "PlaceMr")
  7824. {
  7825. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7826. }
  7827. dStruct.Order = "RefundState asc,created desc";
  7828. }
  7829. else if (st == 10)
  7830. {
  7831. string responsible = GetPostString("responsibleman");
  7832. if (responsible == "空白")
  7833. {
  7834. lw.Add(string.Format("ResponsibleUserName = ''"));
  7835. }
  7836. else if (responsible.Length > 0)
  7837. {
  7838. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7839. }
  7840. lw.Add(string.Format("RefundState>=0"));
  7841. dStruct.Order = "created desc";
  7842. }
  7843. else
  7844. {
  7845. string responsible = GetPostString("responsibleman");
  7846. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7847. lw.Add(string.Format("RefundState={0}", st));
  7848. dStruct.Order = "created desc";
  7849. }
  7850. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7851. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7852. dt.Columns.Add("refund_fees");
  7853. foreach (DataRow dr in dt.Rows)
  7854. {
  7855. String status = dr["status"].ToString();
  7856. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7857. {
  7858. dr["refund_fees"] = dr["refund_fee"];
  7859. }
  7860. else
  7861. {
  7862. dr["refund_fees"] = "0.0";
  7863. }
  7864. }
  7865. writeGridDataTableJson(dStruct.TotalCount, dt);
  7866. }
  7867. public void get_erp_refunddesignlist()
  7868. {
  7869. DataStruct dStruct = GetPostStruct();
  7870. List<string> lw = new List<string>();
  7871. string tid = GetPostString("tid");
  7872. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7873. string shopname = GetPostString("shopname");
  7874. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7875. string buyernick = GetPostString("buyer_nick");
  7876. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7877. string customer = GetPostString("customer");
  7878. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7879. string design = GetPostString("design");
  7880. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7881. string sellermemo = GetPostString("seller_memo");
  7882. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7883. string redate1 = GetPostString("refunddate1");
  7884. string redate2 = GetPostString("refunddate2");
  7885. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7886. if (dwdate.Length > 0) lw.Add(dwdate);
  7887. string price1 = GetPostString("price1");
  7888. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7889. string price2 = GetPostString("price2");
  7890. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7891. string ispartrefund = GetPostString("ispartrefund");
  7892. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7893. string designerorg = GetPostString("designerorg");
  7894. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7895. string refundState = GetPostString("refundState");
  7896. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7897. int myOrgid = CurrentUser.UserPost.OrgID;
  7898. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7899. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7900. {
  7901. if (CurrentUser.User.TeamIds.Length > 0)
  7902. {
  7903. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7904. }
  7905. else
  7906. {
  7907. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7908. }
  7909. }
  7910. else if ("SysAdmin".Equals(myOrgCode))
  7911. {
  7912. }
  7913. else
  7914. {
  7915. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7916. {
  7917. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7918. }
  7919. else
  7920. {
  7921. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7922. }
  7923. }
  7924. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7925. dStruct.Order = "created desc";
  7926. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7927. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7928. dt.Columns.Add("refund_fees");
  7929. foreach (DataRow dr in dt.Rows)
  7930. {
  7931. String status = dr["status"].ToString();
  7932. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7933. {
  7934. dr["refund_fees"] = dr["refund_fee"];
  7935. }
  7936. else
  7937. {
  7938. dr["refund_fees"] = "0.0";
  7939. }
  7940. }
  7941. writeGridDataTableJson(dStruct.TotalCount, dt);
  7942. }
  7943. public void handle_erp_refundtag()
  7944. {
  7945. if (UrlPostParmsCheck("refund_id"))
  7946. {
  7947. string eid = GetPostString("refund_id");
  7948. string respMan = GetPostString("ResponsibleName");
  7949. if (respMan.Length <= 0)
  7950. {
  7951. returnErrorMsg("责任人不能为空");
  7952. return;
  7953. }
  7954. CeErpTradeRefund entity = null;
  7955. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7956. if (entity != null)
  7957. {
  7958. entity.ResponsibleUserName = respMan;
  7959. string userid = GetPostString("ResponsibleUserId");
  7960. if (userid.Length > 0)
  7961. {
  7962. entity.ResponsibleUserId = userid;
  7963. }
  7964. entity.Memo = GetPostString("Memo");
  7965. if (respMan.IndexOf("客服") != -1 ||
  7966. respMan.IndexOf("设计师") != -1 ||
  7967. respMan.IndexOf("下单员") != -1)
  7968. {
  7969. entity.RefundState = 2;
  7970. }
  7971. else
  7972. {
  7973. entity.RefundState = 3;
  7974. }
  7975. entity.modified = DateTime.Now;
  7976. entity.Update();
  7977. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7978. returnSuccessMsg("操作成功!");
  7979. return;
  7980. }
  7981. returnErrorMsg("找不到订单记录");
  7982. }
  7983. }
  7984. public void handle_erp_designrefundtag()
  7985. {
  7986. if (UrlPostParmsCheck("refund_id"))
  7987. {
  7988. string eid = GetPostString("refund_id");
  7989. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7990. if (ceErpTradeCellExtend == null)
  7991. {
  7992. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7993. ceErpTradeCellExtend.ctid = eid;
  7994. }
  7995. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7996. if (ceErpTradeCellExtend.ID > 0)
  7997. {
  7998. ceErpTradeCellExtend.Update();
  7999. }
  8000. else
  8001. {
  8002. ceErpTradeCellExtend.Create();
  8003. }
  8004. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8005. returnSuccessMsg("操作成功!");
  8006. return;
  8007. }
  8008. returnErrorMsg("找不到订单记录");
  8009. }
  8010. public void upd_erp_refundverify()
  8011. {
  8012. if (UrlPostParmsCheck("refund_id"))
  8013. {
  8014. string eid = GetPostString("refund_id");
  8015. CeErpTradeRefund entity = null;
  8016. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8017. if (entity != null)
  8018. {
  8019. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8020. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8021. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8022. {
  8023. entity.RefundState = 2;
  8024. }
  8025. else
  8026. {
  8027. entity.RefundState = 3;
  8028. }
  8029. entity.Update();
  8030. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8031. returnSuccessMsg("操作成功!");
  8032. return;
  8033. }
  8034. returnErrorMsg("找不到订单记录");
  8035. }
  8036. }
  8037. public void upd_erp_refundapprove()
  8038. {
  8039. if (UrlPostParmsCheck("refund_id"))
  8040. {
  8041. string eid = GetPostString("refund_id");
  8042. CeErpTradeRefund entity = null;
  8043. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8044. if (entity != null)
  8045. {
  8046. int apr = GetPostInt("approve");
  8047. if (apr == 0)
  8048. {
  8049. entity.RefundState = 1;
  8050. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8051. }
  8052. else if (apr == 1)
  8053. {
  8054. entity.RefundState = 3;
  8055. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8056. }
  8057. entity.modified = DateTime.Now;
  8058. entity.Update();
  8059. returnSuccessMsg("操作成功!");
  8060. return;
  8061. }
  8062. returnErrorMsg("找不到订单记录");
  8063. }
  8064. }
  8065. public void get_erp_billlist()
  8066. {
  8067. DataStruct dStruct = GetPostStruct();
  8068. List<string> lw = new List<string>();
  8069. string title = GetPostString("title");
  8070. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8071. string tid = GetPostString("tid");
  8072. string tids = GetPostString("tids");
  8073. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8074. if (tids.Length > 0)
  8075. {
  8076. tids = "'" + tids + "'";
  8077. tids = tids.Replace(",", "','");
  8078. lw.Add(string.Format("tid in ({0})", tids));
  8079. }
  8080. string shopname = GetPostString("shopname");
  8081. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8082. string buyernick = GetPostString("buyer_nick");
  8083. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8084. string customer = GetPostString("customer");
  8085. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8086. string date1 = GetPostString("date1");
  8087. string date2 = GetPostString("date2");
  8088. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8089. if (dw.Length > 0) lw.Add(dw);
  8090. string price1 = GetPostString("price1");
  8091. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8092. string price2 = GetPostString("price2");
  8093. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8094. string returndate1 = GetPostString("returndate1");
  8095. string returndate2 = GetPostString("returndate2");
  8096. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8097. if (dw1.Length > 0) lw.Add(dw1);
  8098. string billtype = GetPostString("billtype");
  8099. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8100. string billstate = GetPostString("billstate");
  8101. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8102. string usershop = CurrentUser.User.pemShop;
  8103. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8104. dStruct.Order = "createTime desc";
  8105. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8106. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8107. //foreach (DataRow dr in dt.Rows)
  8108. //{
  8109. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8110. //}
  8111. writeGridDataTableJson(dStruct.TotalCount, dt);
  8112. }
  8113. public void modify_erp_billinfo()
  8114. {
  8115. if (UrlPostParmsCheck("ID"))
  8116. {
  8117. string eid = GetPostString("ID");
  8118. CeErpBill bill_entity = null;
  8119. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8120. if (bill_entity != null)
  8121. {
  8122. bill_entity.tid = GetPostString("tid");
  8123. bill_entity.title = GetPostString("title");
  8124. bill_entity.tax = GetPostString("tax");
  8125. bill_entity.bank = GetPostString("bank");
  8126. bill_entity.bankac = GetPostString("bankac");
  8127. bill_entity.address = GetPostString("address");
  8128. bill_entity.phone = GetPostString("phone");
  8129. bill_entity.price = GetPostString("price");
  8130. bill_entity.productId = GetPostInt("ProductName");
  8131. bill_entity.num = GetPostInt("num");
  8132. bill_entity.unit = GetPostString("unit");
  8133. bill_entity.type = GetPostString("type");
  8134. bill_entity.sendType = GetPostString("SendType");
  8135. bill_entity.email = GetPostString("email");
  8136. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8137. bill_entity.shopName = GetPostString("ShopName");
  8138. bill_entity.applymemo = GetPostString("applymemo");
  8139. bill_entity.modifyTime = DateTime.Now;
  8140. bill_entity.createTime = DateTime.Now;
  8141. bill_entity.state = 0;
  8142. bill_entity.Update();
  8143. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8144. returnSuccessMsg("发票修改成功!");
  8145. return;
  8146. }
  8147. returnErrorMsg("找不到对应记录");
  8148. }
  8149. }
  8150. public void set_erp_invoicing()
  8151. {
  8152. if (UrlPostParmsCheck("id"))
  8153. {
  8154. try
  8155. {
  8156. string eid = GetPostString("id");
  8157. CeErpBill bill_entity = null;
  8158. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8159. if (bill_entity != null)
  8160. {
  8161. int ComId = GetPostInt("ComId");
  8162. //string memo = GetPostString("Memo");
  8163. int allInfo = GetPostInt("allinfo");
  8164. string clert = CurrentUser.User.Name;
  8165. //string detailValue = GetPostString("detailvalue");
  8166. string billId = bill_entity.billOrderId;
  8167. string[] billIdList = billId.Split(',');
  8168. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8169. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8170. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8171. {
  8172. billCount += 1;
  8173. }
  8174. if (billId.Length <= 0 || billIdList.Length != billCount)
  8175. {
  8176. bill_entity.billOrderId = "";
  8177. string prebill = "ltb";
  8178. for (int idx = 1; idx <= billCount; idx++)
  8179. {
  8180. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8181. string billoid = prebill + idx + dtstr;
  8182. bill_entity.billOrderId += billoid;
  8183. if (idx < billCount)
  8184. {
  8185. bill_entity.billOrderId += ",";
  8186. }
  8187. }
  8188. }
  8189. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8190. if (bill_entity.state == 5)
  8191. {
  8192. string errMsg = bill_entity.failerror;
  8193. string[] errlist = errMsg.Split('|');
  8194. string[] errTags = new string[errlist.Length];
  8195. for (int itag = 0; itag < errlist.Length; itag++)
  8196. {
  8197. if (errlist[itag].Length <= 0) continue;
  8198. errTags[itag] = errlist[itag].Split('&')[0];
  8199. }
  8200. for (int iii = 0; iii < errTags.Length; iii++)
  8201. {
  8202. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8203. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8204. if (billOrderList.Length >= erroBillOrderTag)
  8205. {
  8206. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8207. if (needModifyBillId.Length <= 19)
  8208. {
  8209. needModifyBillId = needModifyBillId + "1";
  8210. }
  8211. else
  8212. {
  8213. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8214. last = last + 1;
  8215. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8216. }
  8217. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8218. }
  8219. }
  8220. }
  8221. bool isHaveBillSucces = false;
  8222. string totalRes = "";
  8223. bill_entity.failerror = "";
  8224. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8225. {
  8226. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8227. totalRes += res;
  8228. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8229. {
  8230. isHaveBillSucces = true;
  8231. bill_entity.comId = ComId;
  8232. bill_entity.state = 1;
  8233. bill_entity.executeTime = DateTime.Now;
  8234. bill_entity.executeUser = clert;
  8235. }
  8236. else
  8237. {
  8238. bill_entity.state = 5;
  8239. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8240. }
  8241. }
  8242. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8243. bill_entity.Update();
  8244. if (isHaveBillSucces)
  8245. {
  8246. StringBuilder sql = new StringBuilder();
  8247. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8248. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8249. }
  8250. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8251. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8252. {
  8253. returnErrorMsg("开票失败");
  8254. }
  8255. else
  8256. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8257. return;
  8258. }
  8259. returnErrorMsg("找不到对应记录");
  8260. }
  8261. catch (Exception ex)
  8262. {
  8263. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8264. returnErrorMsg("操作失败");
  8265. }
  8266. }
  8267. }
  8268. public void get_erp_invoicing_back()
  8269. {
  8270. if (UrlPostParmsCheck("id"))
  8271. {
  8272. try
  8273. {
  8274. string id = GetPostString("id");
  8275. CeErpBill entiy = CeErpBill.Get(id);
  8276. if (entiy != null)
  8277. {
  8278. if (entiy.state == 0)
  8279. {
  8280. returnErrorMsg("发票还未开具");
  8281. return;
  8282. }
  8283. string[] billOrderList = entiy.billOrderId.Split(',');
  8284. int iTag = 0;
  8285. entiy.fplsh = "";
  8286. entiy.fpdm = "";
  8287. entiy.fphm = "";
  8288. foreach (string billOrderId in billOrderList)
  8289. {
  8290. iTag++;
  8291. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8292. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8293. {
  8294. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8295. try
  8296. {
  8297. Invoicing_get_response_Obj iObj = null;
  8298. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8299. if (iObj != null)
  8300. {
  8301. entiy.state = 2;
  8302. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8303. entiy.fpdm += iObj.list[0].c_fpdm;
  8304. entiy.fphm += iObj.list[0].c_fphm;
  8305. if (iTag < billOrderList.Length)
  8306. {
  8307. entiy.fplsh += ",";
  8308. entiy.fpdm += ",";
  8309. entiy.fphm += ",";
  8310. }
  8311. entiy.Update();
  8312. }
  8313. StringBuilder sql = new StringBuilder();
  8314. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8315. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8316. returnSuccessMsg("开票成功");
  8317. }
  8318. catch (Exception ex)
  8319. {
  8320. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8321. }
  8322. return;
  8323. }
  8324. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8325. {
  8326. var res_obj = new
  8327. {
  8328. data = "开票中"
  8329. };
  8330. string ro_json = JsonConvert.SerializeObject(res_obj);
  8331. returnSuccess(ro_json);
  8332. return;
  8333. }
  8334. else
  8335. {
  8336. int eidx = res.IndexOf("c_resultmsg");
  8337. int lidx = res.IndexOf("c_status");
  8338. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8339. entiy.state = 5;
  8340. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8341. entiy.Update();
  8342. returnErrorMsg("开票失败");
  8343. return;
  8344. }
  8345. }
  8346. }
  8347. }
  8348. catch (Exception ex)
  8349. {
  8350. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8351. }
  8352. return;
  8353. }
  8354. }
  8355. public void get_erp_invoicing()
  8356. {
  8357. if (UrlPostParmsCheck("id"))
  8358. {
  8359. try
  8360. {
  8361. string id = GetPostString("id");
  8362. CeErpBill entiy = CeErpBill.Get(id);
  8363. if (entiy != null)
  8364. {
  8365. if (entiy.state == 0)
  8366. {
  8367. returnErrorMsg("发票还未开具");
  8368. return;
  8369. }
  8370. if (entiy.sendType == "纸质发票")
  8371. {
  8372. if (entiy.img.Length <= 0)
  8373. {
  8374. returnErrorMsg("查无纸质发票");
  8375. return;
  8376. }
  8377. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8378. returnSuccess(returnres);
  8379. return;
  8380. }
  8381. string[] billOrderList = entiy.billOrderId.Split(',');
  8382. int iTag = 0;
  8383. string fpUrl = "";
  8384. entiy.fplsh = "";
  8385. entiy.fpdm = "";
  8386. entiy.fphm = "";
  8387. foreach (string billOrderId in billOrderList)
  8388. {
  8389. iTag++;
  8390. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8391. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8392. {
  8393. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8394. Invoicing_get_response_Obj iObj = null;
  8395. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8396. if (iObj != null)
  8397. {
  8398. //entiy.state = 2;
  8399. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8400. entiy.fpdm += iObj.list[0].c_fpdm;
  8401. entiy.fphm += iObj.list[0].c_fphm;
  8402. if (iTag < billOrderList.Length)
  8403. {
  8404. entiy.fplsh += ",";
  8405. entiy.fpdm += ",";
  8406. entiy.fphm += ",";
  8407. }
  8408. entiy.Update();
  8409. fpUrl += iObj.list[0].c_url + ",";
  8410. }
  8411. //returnSuccess(res);
  8412. StringBuilder sql = new StringBuilder();
  8413. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8414. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8415. }
  8416. else
  8417. {
  8418. int eidx = res.IndexOf("c_resultmsg");
  8419. //int lidx = res.IndexOf("c_status");
  8420. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8421. //开票失败
  8422. entiy.state = 5;
  8423. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8424. entiy.Update();
  8425. returnErrorMsg("开票失败");
  8426. return;
  8427. }
  8428. }
  8429. var returnObj = new
  8430. {
  8431. data = fpUrl
  8432. };
  8433. string ro_json = JsonConvert.SerializeObject(returnObj);
  8434. returnSuccess(ro_json);
  8435. }
  8436. }
  8437. catch (Exception ex)
  8438. {
  8439. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8440. }
  8441. return;
  8442. }
  8443. }
  8444. public void save_erp_billimg()
  8445. {
  8446. if (UrlPostParmsCheck("id"))
  8447. {
  8448. string eid = GetPostString("id");
  8449. CeErpBill bill_entity = null;
  8450. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8451. if (bill_entity != null)
  8452. {
  8453. bill_entity.img = GetPostString("img");
  8454. bill_entity.executeTime = DateTime.Now;
  8455. bill_entity.state = 2;
  8456. bill_entity.Update();
  8457. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8458. returnSuccessMsg("保存成功");
  8459. }
  8460. return;
  8461. }
  8462. }
  8463. public void upd_erp_billreturnback()
  8464. {
  8465. if (UrlPostParmsCheck("id"))
  8466. {
  8467. int eid = GetPostInt("id");
  8468. CeErpBill bill_entity = null;
  8469. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8470. if (bill_entity != null)
  8471. {
  8472. bill_entity.state = 3;
  8473. bill_entity.returnReason = GetPostString("reason");
  8474. bill_entity.Update();
  8475. returnSuccessMsg("驳回成功!");
  8476. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8477. }
  8478. return;
  8479. }
  8480. }
  8481. public void cancel_erp_bill()
  8482. {
  8483. if (UrlPostParmsCheck("id"))
  8484. {
  8485. int eid = GetPostInt("id");
  8486. int detailValue = GetPostInt("detailvalue");
  8487. CeErpBill bill_entity = null;
  8488. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8489. string cres = "";
  8490. string gres = "";
  8491. if (bill_entity != null)
  8492. {
  8493. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8494. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8495. {
  8496. int iTag = 0;
  8497. bill_entity.fplsh = "";
  8498. bill_entity.fpdm = "";
  8499. bill_entity.fphm = "";
  8500. foreach (string billOrderId in billOrderList)
  8501. {
  8502. iTag++;
  8503. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8504. if (gres.IndexOf("success") != -1)
  8505. {
  8506. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8507. Invoicing_get_response_Obj iObj = null;
  8508. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8509. if (iObj != null)
  8510. {
  8511. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8512. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8513. bill_entity.fphm += iObj.list[0].c_fphm;
  8514. if (iTag < billOrderList.Length)
  8515. {
  8516. bill_entity.fplsh += ",";
  8517. bill_entity.fpdm += ",";
  8518. bill_entity.fphm += ",";
  8519. }
  8520. bill_entity.Update();
  8521. }
  8522. }
  8523. else
  8524. {
  8525. returnErrorMsg(gres);
  8526. return;
  8527. }
  8528. }
  8529. }
  8530. if (bill_entity.sendType == "纸质发票")
  8531. {
  8532. //作废
  8533. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8534. //if (DateTime.Now.Month == extime.Month)
  8535. //{
  8536. //cres = taobaoHelper.cancel_invoicing(eid);
  8537. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8538. //{
  8539. bill_entity.state = 4;//已作废
  8540. bill_entity.Update();
  8541. returnSuccessMsg("发票已作废");
  8542. return;
  8543. //}
  8544. //else
  8545. //{
  8546. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8547. // bill_entity.Update();
  8548. // returnErrorMsg(cres);
  8549. // return;
  8550. //}
  8551. //}
  8552. //else
  8553. //{
  8554. // returnErrorMsg("纸质发票只能作废本月的发票");
  8555. // return;
  8556. //}
  8557. }
  8558. //红冲
  8559. int redTag = 0;
  8560. string[] fpdmList = bill_entity.fpdm.Split(',');
  8561. string[] fphmList = bill_entity.fphm.Split(',');
  8562. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8563. {
  8564. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8565. return;
  8566. }
  8567. foreach (string billOrderId in billOrderList)
  8568. {
  8569. redTag++;
  8570. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8571. cres += onecres;
  8572. cres += ",";
  8573. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8574. {
  8575. bill_entity.state = 4;//已作废
  8576. //bill_entity.Update();
  8577. //returnSuccessMsg("发票已红冲");
  8578. }
  8579. else if (onecres.IndexOf("重复冲红") != -1)
  8580. {
  8581. bill_entity.state = 4;//已作废
  8582. //bill_entity.Update();
  8583. //returnSuccessMsg("发票已红冲");
  8584. }
  8585. else
  8586. {
  8587. string errmsg = commonHelper.KeepChinese(onecres);
  8588. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8589. }
  8590. }
  8591. bill_entity.Update();
  8592. if (cres.IndexOf("失败") != -1)
  8593. returnErrorMsg("红冲失败");
  8594. else
  8595. returnSuccessMsg("发票已红冲");
  8596. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8597. return;
  8598. }
  8599. return;
  8600. }
  8601. }
  8602. public void del_erp_billorder()
  8603. {
  8604. if (UrlPostParmsCheck("id"))
  8605. {
  8606. string eid = GetPostString("id");
  8607. CeErpBill.Del(eid);
  8608. CeErpBill bill = CeErpBill.Get(eid);
  8609. if (bill != null)
  8610. {
  8611. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8612. }
  8613. returnSuccessMsg("删除成功");
  8614. }
  8615. }
  8616. public void finish_erp_bill()
  8617. {
  8618. if (UrlPostParmsCheck("ids"))
  8619. {
  8620. string eids = GetPostString("ids");
  8621. string[] list = eids.Split(',');
  8622. foreach (string eid in list)
  8623. {
  8624. CeErpBill bill = CeErpBill.Get(eid);
  8625. if (bill != null)
  8626. {
  8627. bill.state = 2;
  8628. bill.Update();
  8629. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8630. }
  8631. }
  8632. returnSuccessMsg("操作成功");
  8633. }
  8634. }
  8635. public void get_erp_returncash()
  8636. {
  8637. DataStruct dStruct = GetPostStruct();
  8638. List<string> lw = new List<string>();
  8639. string tid = GetPostString("tid");
  8640. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8641. string shopname = GetPostString("shopname");
  8642. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8643. string buyernick = GetPostString("buyer_nick");
  8644. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8645. string customer = GetPostString("customer");
  8646. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8647. string returndate1 = GetPostString("returndate1");
  8648. string returndate2 = GetPostString("returndate2");
  8649. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8650. if (dw.Length > 0) lw.Add(dw);
  8651. string finishDate1 = GetPostString("finishdate1");
  8652. string finishDate2 = GetPostString("finishdate2");
  8653. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8654. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8655. string returntype = GetPostString("returntype");
  8656. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8657. string returnvstate = GetPostString("returnvstate");
  8658. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8659. dStruct.Order = "created desc";
  8660. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8661. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8662. writeGridDataTableJson(dStruct.TotalCount, dt);
  8663. }
  8664. public void get_erp_staygoods()
  8665. {
  8666. DataStruct dStruct = GetPostStruct();
  8667. List<string> lw = new List<string>();
  8668. string tid = GetPostString("tid");
  8669. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8670. string shopname = GetPostString("shopname");
  8671. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8672. string wangwang = GetPostString("wangwang");
  8673. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8674. string customer = GetPostString("customer");
  8675. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8676. string returndate1 = GetPostString("returndate1");
  8677. string returndate2 = GetPostString("returndate2");
  8678. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8679. if (dw.Length > 0) lw.Add(dw);
  8680. string finishDate1 = GetPostString("finishdate1");
  8681. string finishDate2 = GetPostString("finishdate2");
  8682. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8683. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8684. string returnvstate = GetPostString("returnvstate");
  8685. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8686. string persuadetype = GetPostString("persuadetype");
  8687. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8688. string customerOrg = GetPostString("customerOrg");
  8689. if (customerOrg.Length > 0)
  8690. {
  8691. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8692. }
  8693. dStruct.Order = "creata_time desc";
  8694. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8695. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8696. writeGridDataTableJson(dStruct.TotalCount, dt);
  8697. }
  8698. public void upd_erp_staygoods()
  8699. {
  8700. if (UrlPostParmsCheck("id"))
  8701. {
  8702. int eid = GetPostInt("id");
  8703. CeErpStayGoods entity = null;
  8704. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8705. if (entity != null)
  8706. {
  8707. entity.audit_type = 1;
  8708. entity.audit_time = DateTime.Now;
  8709. entity.audit_u_id = CurrentUser.UserID;
  8710. entity.audit_u_name = CurrentUser.UserName;
  8711. entity.Update();
  8712. returnSuccessMsg("审核成功!");
  8713. return;
  8714. }
  8715. returnErrorMsg("找不到订单记录");
  8716. }
  8717. }
  8718. public void upd_erp_stayGoodsback()
  8719. {
  8720. if (UrlPostParmsCheck("id"))
  8721. {
  8722. int eid = GetPostInt("id");
  8723. CeErpStayGoods entity = null;
  8724. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8725. if (entity != null)
  8726. {
  8727. entity.audit_text = GetPostString("reason");
  8728. entity.audit_type = 2;
  8729. entity.audit_time = DateTime.Now;
  8730. entity.audit_u_id = CurrentUser.UserID;
  8731. entity.audit_u_name = CurrentUser.UserName;
  8732. entity.Update();
  8733. returnSuccessMsg("退回成功!");
  8734. return;
  8735. }
  8736. returnErrorMsg("找不到订单记录");
  8737. }
  8738. }
  8739. public void upd_erp_returncashverify()
  8740. {
  8741. if (UrlPostParmsCheck("ID"))
  8742. {
  8743. int eid = GetPostInt("ID");
  8744. CeErpReturnCash entity = null;
  8745. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8746. if (entity != null)
  8747. {
  8748. entity.cashstate = 1;
  8749. entity.verifytime = DateTime.Now;
  8750. entity.verifyuserid = CurrentUser.UserID;
  8751. entity.Update();
  8752. returnSuccessMsg("审核成功!");
  8753. return;
  8754. }
  8755. returnErrorMsg("找不到订单记录");
  8756. }
  8757. }
  8758. public void upd_all_erp_returncashverify()
  8759. {
  8760. if (UrlPostParmsCheck("ID"))
  8761. {
  8762. String[] list = GetPostString("ID").Split(',');
  8763. CeErpReturnCash entity = null;
  8764. for (int i = 0; i < list.Length; i++)
  8765. {
  8766. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8767. if (entity != null)
  8768. {
  8769. if (entity.cashstate == 1)
  8770. {
  8771. returnErrorMsg("已审核过的订单不需要在审核!");
  8772. return;
  8773. }
  8774. entity.cashstate = 1;
  8775. entity.verifytime = DateTime.Now;
  8776. entity.verifyuserid = CurrentUser.UserID;
  8777. entity.Update();
  8778. }
  8779. }
  8780. returnSuccessMsg("审核成功!");
  8781. return;
  8782. }
  8783. }
  8784. public void upd_erp_returncashback()
  8785. {
  8786. if (UrlPostParmsCheck("ID"))
  8787. {
  8788. int eid = GetPostInt("ID");
  8789. CeErpReturnCash entity = null;
  8790. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8791. if (entity != null)
  8792. {
  8793. entity.backreason = GetPostString("reason");
  8794. entity.cashstate = 2;
  8795. entity.verifytime = DateTime.Now;
  8796. entity.verifyuserid = CurrentUser.UserID;
  8797. entity.Update();
  8798. returnSuccessMsg("退回成功!");
  8799. return;
  8800. }
  8801. returnErrorMsg("找不到订单记录");
  8802. }
  8803. }
  8804. public void upd_erp_returnprice()
  8805. {
  8806. if (UrlPostParmsCheck("ID"))
  8807. {
  8808. int eid = GetPostInt("ID");
  8809. CeErpReturnCash entity = null;
  8810. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8811. if (entity != null)
  8812. {
  8813. if (entity.cashstate == 1)
  8814. {
  8815. returnErrorMsg("审核通过了不能改");
  8816. return;
  8817. }
  8818. entity.returnprice = GetPostDouble("returnprice");
  8819. entity.Update();
  8820. returnSuccessMsg("修改成功!");
  8821. return;
  8822. }
  8823. returnErrorMsg("找不到订单记录");
  8824. }
  8825. }
  8826. public void del_erp_returncash()
  8827. {
  8828. if (UrlPostParmsCheck("ID"))
  8829. {
  8830. int eid = GetPostInt("ID");
  8831. CeErpReturnCash.Del(eid);
  8832. returnSuccessMsg("操作成功");
  8833. return;
  8834. }
  8835. }
  8836. public void test_for_do_sql()
  8837. {
  8838. string sql = GetPostString("sqlstr");
  8839. if (sql.Length > 0)
  8840. {
  8841. try
  8842. {
  8843. DbHelper.DbConn.ExecuteNonQuery(sql);
  8844. var res_obj = new
  8845. {
  8846. data = "成功",
  8847. };
  8848. string ro_json = JsonConvert.SerializeObject(res_obj);
  8849. returnSuccess(ro_json);
  8850. }
  8851. catch (Exception ex)
  8852. {
  8853. var res_obj = new
  8854. {
  8855. data = ex.Message,
  8856. };
  8857. string ro_json = JsonConvert.SerializeObject(res_obj);
  8858. returnSuccess(ro_json);
  8859. }
  8860. }
  8861. }
  8862. public void get_user_info()
  8863. {
  8864. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8865. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8866. }
  8867. public void get_total_data()
  8868. {
  8869. int userId = CurrentUser.UserID;
  8870. string sql = "";
  8871. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8872. {
  8873. 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);
  8874. }
  8875. else
  8876. {
  8877. 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 " +
  8878. "(select ID from CE_ErpUser where ID = {0}) d " +
  8879. "left join " +
  8880. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8881. ") a on d.ID = a.id left join " +
  8882. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8883. ") b on a.id = b.id1 left join" +
  8884. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8885. ") c on a.id = c.id2;", userId);
  8886. }
  8887. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8888. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8889. }
  8890. public void get_date_area_total_data2()
  8891. {
  8892. int userId = CurrentUser.UserID;
  8893. string date_type = GetPostString("timetype");
  8894. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8895. string sql = "";
  8896. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8897. {
  8898. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8899. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8900. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8901. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8902. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8903. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8904. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8905. ") a on e.ID = a.id left join " +
  8906. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8907. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8908. ") b on a.id = b.id1 " +
  8909. "left join " +
  8910. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8911. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8912. ") c on a.id = c.id2 " +
  8913. "left join " +
  8914. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8915. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8916. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8917. }
  8918. else
  8919. {
  8920. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8921. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8922. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8923. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8924. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8925. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8926. ") a on e.ID = a.id left join " +
  8927. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8928. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8929. ") c on a.id = c.id2 " +
  8930. "left join " +
  8931. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8932. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8933. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8934. }
  8935. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8936. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8937. }
  8938. public void get_date_area_total_data()
  8939. {
  8940. int userId = CurrentUser.UserID;
  8941. string date_type = GetPostString("timetype");
  8942. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8943. string date1 = searchDT[0].ToString();
  8944. string date2 = searchDT[1].ToString();
  8945. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8946. {
  8947. SqlParameter[] sqlParameter ={
  8948. new SqlParameter("@userId", SqlDbType.Int,4),
  8949. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8950. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8951. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8952. };
  8953. sqlParameter[0].Value = userId;
  8954. sqlParameter[1].Value = date1;
  8955. sqlParameter[2].Value = date2;
  8956. sqlParameter[3].Direction = ParameterDirection.Output;
  8957. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8958. string res = sqlParameter[3].Value.ToString();
  8959. var res_obj = new
  8960. {
  8961. data = res
  8962. };
  8963. string ro_json = JsonConvert.SerializeObject(res_obj);
  8964. returnSuccess(ro_json);
  8965. }
  8966. else
  8967. {
  8968. SqlParameter[] sqlParameter ={
  8969. new SqlParameter("@userId", SqlDbType.Int,4),
  8970. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8971. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8972. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8973. };
  8974. sqlParameter[0].Value = userId;
  8975. sqlParameter[1].Value = date1;
  8976. sqlParameter[2].Value = date2;
  8977. sqlParameter[3].Direction = ParameterDirection.Output;
  8978. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8979. string res = sqlParameter[3].Value.ToString();
  8980. var res_obj = new
  8981. {
  8982. data = res
  8983. };
  8984. string ro_json = JsonConvert.SerializeObject(res_obj);
  8985. returnSuccess(ro_json);
  8986. }
  8987. //writeGridDataViewJson(dt.Rows.Count, dv);
  8988. }
  8989. public void get_order_list()
  8990. {
  8991. string strFields = GetPostString("paraFields");
  8992. string strOrder = GetPostString("paraOrder");
  8993. string strWhere = GetPostString("paraWhere");
  8994. string strPageSize = GetPostString("paraPageSize");
  8995. DataStruct dStruct = GetPostStruct();
  8996. dStruct.PageSize = int.Parse(strPageSize);
  8997. dStruct.Fileds = strFields;
  8998. dStruct.Order = strOrder;
  8999. dStruct.MainWhere = strWhere;
  9000. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9001. writeGridDataTableJson(dStruct.TotalCount, dt);
  9002. }
  9003. ////获取待开始订单列表
  9004. //public void get_wait_design_order_list()
  9005. //{
  9006. // string date_type = GetPostString("date_type");
  9007. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9008. // DataStruct dStruct = GetPostStruct();
  9009. // dStruct.PageSize = 1000;
  9010. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9011. // List<string> lw = new List<string>();
  9012. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9013. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9014. // dStruct.Order = "WaitDesignTime asc";
  9015. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9016. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9017. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9018. //}
  9019. //获取完成单量排名
  9020. public void get_finish_order_count_ranking()
  9021. {
  9022. /* string date_type = GetPostString("date_type");
  9023. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9024. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9025. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9026. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9027. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9028. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9029. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9030. writeGridDataTableJson(0, new DataTable());
  9031. }
  9032. public void get_finish_order_amount_ranking()
  9033. {
  9034. /*string date_type = GetPostString("date_type");
  9035. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9036. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9037. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9038. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9039. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9040. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9041. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9042. writeGridDataTableJson(0, new DataTable());
  9043. }
  9044. public void get_finish_refund_count_ranking()
  9045. {
  9046. string date_type = GetPostString("date_type");
  9047. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9048. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9049. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9050. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9051. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9052. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9053. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9054. writeGridDataTableJson(dt.Rows.Count, dt);
  9055. }
  9056. public void get_finish_refund_amount_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.orderAmount, 0) as orderAmount " +
  9061. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9062. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9063. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9064. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9065. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9066. writeGridDataTableJson(dt.Rows.Count, dt);
  9067. }
  9068. public void set_erp_finishorder_director()
  9069. {
  9070. if (UrlPostParmsCheck("ctid"))
  9071. {
  9072. string eid = GetPostString("ctid");
  9073. CeErpTradeCell entity = null;
  9074. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9075. if (entity != null)
  9076. {
  9077. entity.OrderState = 8;
  9078. entity.Update();
  9079. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9080. returnSuccessMsg("操作成功!");
  9081. return;
  9082. }
  9083. returnErrorMsg("找不到记录");
  9084. }
  9085. }
  9086. public void get_erp_placeregistlist()
  9087. {
  9088. DataStruct dStruct = GetPostStruct();
  9089. List<string> lw = new List<string>();
  9090. string outsid = GetPostString("outsid");
  9091. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9092. string memo = GetPostString("memo");
  9093. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9094. string filename = GetPostString("filename");
  9095. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9096. string islate = GetPostString("islate");
  9097. if (islate.Length > 0)
  9098. {
  9099. if (islate == "1")
  9100. lw.Add(string.Format("OutLate>0"));
  9101. else
  9102. lw.Add(string.Format("OutLate=0"));
  9103. }
  9104. string placedate1 = GetPostString("placedate1");
  9105. string placedate2 = GetPostString("placedate2");
  9106. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9107. if (dw.Length > 0) lw.Add(dw);
  9108. string deliveryDate1 = GetPostString("deliverydate1");
  9109. string deliveryDate2 = GetPostString("deliverydate2");
  9110. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9111. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9112. dStruct.Order = "ID desc";
  9113. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9114. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9115. writeGridDataTableJson(dStruct.TotalCount, dt);
  9116. }
  9117. public void ins_erp_placeregist()
  9118. {
  9119. if (UrlPostParmsCheck("id"))
  9120. {
  9121. string eid = GetPostString("id");
  9122. CeErpPlaceRegister entity = null;
  9123. if (eid == "0")//新增
  9124. {
  9125. entity = new CeErpPlaceRegister();
  9126. string xdTime = GetPostString("placeTime");
  9127. if (xdTime.Length > 0)
  9128. {
  9129. entity.PlactTime = Convert.ToDateTime(xdTime);
  9130. }
  9131. string fhTime = GetPostString("deliveryTime");
  9132. if (fhTime.Length > 0)
  9133. {
  9134. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9135. }
  9136. string preTime = GetPostString("preOutTime");
  9137. if (preTime.Length > 0)
  9138. {
  9139. entity.PreOutTime = Convert.ToDateTime(preTime);
  9140. }
  9141. entity.DeliveryCount = GetPostInt("deliveryCount");
  9142. entity.ReceiveCount = GetPostInt("receiveCount");
  9143. entity.OutSid = GetPostString("outSid");
  9144. entity.FileName = GetPostString("fileName");
  9145. entity.Memo = GetPostString("memo");
  9146. entity.AddUserId = CurrentUser.UserID;
  9147. entity.CreateTime = DateTime.Now;
  9148. entity.Img = GetPostString("img");
  9149. entity.Supplier = GetPostInt("supplier");
  9150. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9151. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9152. {
  9153. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9154. DateTime dt2 = (DateTime)entity.PreOutTime;
  9155. TimeSpan span = dt1.Subtract(dt2);
  9156. if (span.Days > 0)
  9157. {
  9158. entity.OutLate = span.Days;
  9159. }
  9160. }
  9161. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9162. entity.Create();
  9163. returnSuccessMsg("添加成功!");
  9164. return;
  9165. }
  9166. else //修改
  9167. {
  9168. entity = CeErpPlaceRegister.Get(eid);
  9169. if (entity != null)
  9170. {
  9171. string xdTime = GetPostString("placeTime");
  9172. if (xdTime.Length > 0)
  9173. {
  9174. entity.PlactTime = Convert.ToDateTime(xdTime);
  9175. }
  9176. string fhTime = GetPostString("deliveryTime");
  9177. if (fhTime.Length > 0)
  9178. {
  9179. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9180. }
  9181. string preTime = GetPostString("preOutTime");
  9182. if (preTime.Length > 0)
  9183. {
  9184. entity.PreOutTime = Convert.ToDateTime(preTime);
  9185. }
  9186. entity.DeliveryCount = GetPostInt("deliveryCount");
  9187. entity.ReceiveCount = GetPostInt("receiveCount");
  9188. if (entity.DeliveryCount == entity.ReceiveCount)
  9189. {
  9190. entity.CurState = "已完成";
  9191. }
  9192. else
  9193. {
  9194. entity.CurState = "未完成";
  9195. }
  9196. entity.OutSid = GetPostString("outSid");
  9197. entity.FileName = GetPostString("fileName");
  9198. entity.Memo = GetPostString("memo");
  9199. entity.Img = GetPostString("img");
  9200. entity.Supplier = GetPostInt("supplier");
  9201. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9202. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9203. {
  9204. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9205. DateTime dt2 = (DateTime)entity.PreOutTime;
  9206. TimeSpan span = dt1.Subtract(dt2);
  9207. if (span.Days > 0)
  9208. {
  9209. entity.OutLate = span.Days;
  9210. }
  9211. }
  9212. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9213. entity.Update();
  9214. returnSuccessMsg("修改成功");
  9215. return;
  9216. }
  9217. returnErrorMsg("找不到对应的记录");
  9218. return;
  9219. }
  9220. }
  9221. returnErrorMsg("缺少必要参数");
  9222. }
  9223. public void del_erp_placeregist()
  9224. {
  9225. string eid = GetPostString("id");
  9226. CeErpPlaceRegister.Del(eid);
  9227. returnSuccessMsg("删除成功!");
  9228. return;
  9229. }
  9230. public void ins_erp_placeregistbyorder()
  9231. {
  9232. string ctid = GetPostString("ctid");
  9233. if (ctid.Length > 0)
  9234. {
  9235. StringBuilder sql = new StringBuilder();
  9236. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9237. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9238. if (dt.Rows.Count > 0)
  9239. {
  9240. foreach (DataRow dr in dt.Rows)
  9241. {
  9242. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9243. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9244. entity.AddUserId = CurrentUser.UserID;
  9245. entity.tid = dr["tid"].ToString();
  9246. entity.Did = Convert.ToString(dr["ctid"]);
  9247. entity.splitTag = dr["SplitTag"].ToString();
  9248. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9249. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9250. if (pre_ctid.Length > 0)
  9251. {
  9252. sellmemo = sellmemo.Replace(pre_ctid, "");
  9253. }
  9254. sellmemo = sellmemo.Replace("[", "");
  9255. sellmemo = sellmemo.Replace("]", "");
  9256. entity.FileName = sellmemo;
  9257. string count = dr["ProductCount"].ToString();
  9258. int usecount = commonHelper.getIntCountFromString(count);
  9259. entity.DeliveryCount = usecount;
  9260. entity.CurState = "未完成";
  9261. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9262. {
  9263. entity.Supplier = 24;//dl手提袋定制
  9264. }
  9265. else
  9266. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9267. entity.CreateTime = DateTime.Now;
  9268. entity.Create();
  9269. }
  9270. returnSuccessMsg("操作成功");
  9271. return;
  9272. }
  9273. returnErrorMsg("没有找到对应订单");
  9274. return;
  9275. }
  9276. returnErrorMsg("缺少订单编号");
  9277. return;
  9278. }
  9279. public void get_erp_persuadelist()
  9280. {
  9281. DataStruct dStruct = GetPostStruct();
  9282. List<string> lw = new List<string>();
  9283. string ctid = GetPostString("ctid");
  9284. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9285. string shopname = GetPostString("shopname");
  9286. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9287. string buyernick = GetPostString("buyer_nick");
  9288. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9289. string customer = GetPostString("customer");
  9290. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9291. string returndate1 = GetPostString("returndate1");
  9292. string returndate2 = GetPostString("returndate2");
  9293. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9294. if (dw.Length > 0) lw.Add(dw);
  9295. string finishDate1 = GetPostString("finishdate1");
  9296. string finishDate2 = GetPostString("finishdate2");
  9297. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9298. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9299. string persuadetype = GetPostString("persuadetype");
  9300. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9301. string returnvstate = GetPostString("returnvstate");
  9302. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9303. dStruct.Order = "created desc";
  9304. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9305. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9306. writeGridDataTableJson(dStruct.TotalCount, dt);
  9307. }
  9308. public void upd_erp_returnpersuadeback()
  9309. {
  9310. if (UrlPostParmsCheck("ID"))
  9311. {
  9312. int eid = GetPostInt("ID");
  9313. CeErpPersuade entity = null;
  9314. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9315. if (entity != null)
  9316. {
  9317. entity.backreason = GetPostString("reason");
  9318. entity.pstate = 2;
  9319. entity.verifytime = DateTime.Now;
  9320. entity.verifyuserid = CurrentUser.UserID;
  9321. entity.Update();
  9322. returnSuccessMsg("退回成功!");
  9323. return;
  9324. }
  9325. returnErrorMsg("找不到订单记录");
  9326. }
  9327. }
  9328. public void upd_erp_returnpersuadeverify()
  9329. {
  9330. if (UrlPostParmsCheck("ID"))
  9331. {
  9332. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9333. {
  9334. returnErrorMsg("暂无权限审核");
  9335. return;
  9336. }
  9337. int eid = GetPostInt("ID");
  9338. CeErpPersuade entity = null;
  9339. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9340. if (entity != null)
  9341. {
  9342. entity.pstate = 1;
  9343. entity.verifytime = DateTime.Now;
  9344. entity.verifyuserid = CurrentUser.UserID;
  9345. entity.Update();
  9346. returnSuccessMsg("审核成功!");
  9347. return;
  9348. }
  9349. returnErrorMsg("找不到订单记录");
  9350. }
  9351. }
  9352. public void del_erp_persuade()
  9353. {
  9354. if (UrlPostParmsCheck("ID"))
  9355. {
  9356. int eid = GetPostInt("ID");
  9357. CeErpPersuade.Del(eid);
  9358. returnSuccessMsg("操作成功");
  9359. return;
  9360. }
  9361. }
  9362. public void get_erp_oldcustoupload()
  9363. {
  9364. DataStruct dStruct = GetPostStruct();
  9365. List<string> lw = new List<string>();
  9366. string buyernick = GetPostString("buyer_nick");
  9367. if (buyernick.Length > 0)
  9368. {
  9369. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9370. }
  9371. else
  9372. return;
  9373. dStruct.Order = "pay_time desc";
  9374. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9375. DataTable dt = null;
  9376. dt = WebCache.GetData("view_erptradecell", dStruct);
  9377. writeGridDataTableJson(dStruct.TotalCount, dt);
  9378. }
  9379. public void get_erp_checkorderlist()
  9380. {
  9381. DataStruct dStruct = GetPostStruct();
  9382. List<string> lw = new List<string>();
  9383. string tid = GetPostString("ctid");
  9384. if (tid.Length > 0)
  9385. {
  9386. string select_tid = getTidByCtid(tid);
  9387. lw.Add(string.Format("tid='{0}'", select_tid));
  9388. }
  9389. string shopname = GetPostString("shopname");
  9390. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9391. string buyernick = GetPostString("buyer_nick");
  9392. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9393. string customer = GetPostString("customer");
  9394. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9395. string design = GetPostString("design");
  9396. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9397. string orderState = GetPostString("orderState");
  9398. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9399. string address = GetPostString("address");
  9400. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9401. string sellermemo = GetPostString("seller_memo");
  9402. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9403. string supplier = GetPostString("supplier");
  9404. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9405. {
  9406. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9407. }
  9408. else
  9409. {
  9410. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9411. }
  9412. string date1 = GetPostString("date1");
  9413. string date2 = GetPostString("date2");
  9414. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9415. if (dw.Length > 0) lw.Add(dw);
  9416. string placedate1 = GetPostString("placedate1");
  9417. string placedate2 = GetPostString("placedate2");
  9418. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9419. if (fdw.Length > 0) lw.Add(fdw);
  9420. string price1 = GetPostString("price1");
  9421. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9422. string price2 = GetPostString("price2");
  9423. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9424. string checkst = GetPostString("checkstate");
  9425. if (checkst.Length > 0 && "10".Equals(checkst))
  9426. {
  9427. lw.Add(string.Format("CheckOut>0"));
  9428. }
  9429. else
  9430. {
  9431. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9432. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9433. }
  9434. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9435. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9436. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9437. writeGridDataTableJson(dStruct.TotalCount, dt);
  9438. }
  9439. public void ins_erp_startCheck()
  9440. {
  9441. if (UrlPostParmsCheck("ctid"))
  9442. {
  9443. string eid = GetPostString("ctid");
  9444. CeErpTradeCell entity = null;
  9445. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9446. if (entity != null)
  9447. {
  9448. entity.MemoOpt = 4;
  9449. entity.UpdateTime = DateTime.Now;
  9450. entity.Update();
  9451. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9452. CeErpSukuraData.createInfo(entity.ctid, 6);
  9453. returnSuccessMsg("操作成功!");
  9454. return;
  9455. }
  9456. returnErrorMsg("找不到记录");
  9457. }
  9458. }
  9459. public void upd_erp_sendXlw()
  9460. {
  9461. if (UrlPostParmsCheck("ctid"))
  9462. {
  9463. string eid = GetPostString("ctid");
  9464. CeErpTradeCell entity = null;
  9465. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9466. if (entity != null)
  9467. {
  9468. if (entity.IsSendGift == 1)
  9469. {
  9470. returnErrorMsg("请勿重复标记");
  9471. return;
  9472. }
  9473. entity.IsSendGift = 1;
  9474. entity.Update();
  9475. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9476. returnSuccessMsg("操作成功!");
  9477. return;
  9478. }
  9479. returnErrorMsg("找不到记录");
  9480. }
  9481. }
  9482. public void cancel_sendXlw()
  9483. {
  9484. if (UrlPostParmsCheck("ctid"))
  9485. {
  9486. string eid = GetPostString("ctid");
  9487. CeErpTradeCell entity = null;
  9488. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9489. if (entity != null)
  9490. {
  9491. if (entity.IsSendGift == 0)
  9492. {
  9493. returnErrorMsg("未标记小礼物");
  9494. return;
  9495. }
  9496. entity.IsSendGift = 0;
  9497. entity.Update();
  9498. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9499. returnSuccessMsg("操作成功!");
  9500. return;
  9501. }
  9502. returnErrorMsg("找不到记录");
  9503. }
  9504. }
  9505. public void get_erp_designbill()
  9506. {
  9507. DataStruct dStruct = GetPostStruct();
  9508. List<string> lw = new List<string>();
  9509. int isMy = GetInt("my");
  9510. if (isMy == 1)
  9511. {
  9512. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9513. }
  9514. string tid = GetPostString("tid");
  9515. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9516. string userName = GetPostString("design");
  9517. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9518. string price1 = GetPostString("price1");
  9519. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9520. string price2 = GetPostString("price2");
  9521. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9522. string rePrice1 = GetPostString("rePrice1");
  9523. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9524. string rePrice2 = GetPostString("rePrice2");
  9525. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9526. string designerType = GetPostString("designerType");
  9527. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9528. string orderState = GetPostString("orderState");
  9529. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9530. string endTime1 = GetPostString("endTime1");
  9531. string endTime2 = GetPostString("endTime2");
  9532. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9533. if (dw.Length > 0) lw.Add(dw);
  9534. string isDk = GetPostString("isDk");
  9535. if (isDk == "1")
  9536. {
  9537. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9538. }
  9539. else if (isDk == "0")
  9540. {
  9541. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9542. }
  9543. dStruct.Order = "oid, create_time desc";
  9544. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9545. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9546. writeGridDataTableJson(dStruct.TotalCount, dt);
  9547. }
  9548. public void upd_erp_designerbill()
  9549. {
  9550. if (UrlPostParmsCheck("ID"))
  9551. {
  9552. string eid = GetPostString("ID");
  9553. CeErpDesignerBill entity = null;
  9554. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9555. if (entity != null)
  9556. {
  9557. if (GetPostDouble("designerpirce") > 0)
  9558. {
  9559. entity.realPrice = GetPostDouble("designerpirce");
  9560. entity.update_time = DateTime.Now;
  9561. entity.update_u_id = CurrentUser.UserID;
  9562. entity.update_u_name = CurrentUser.UserName;
  9563. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9564. entity.Update();
  9565. returnSuccessMsg("操作成功!");
  9566. return;
  9567. }
  9568. else
  9569. {
  9570. entity.price = GetPostDouble("price");
  9571. entity.update_time = DateTime.Now;
  9572. entity.update_u_id = CurrentUser.UserID;
  9573. entity.update_u_name = CurrentUser.UserName;
  9574. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9575. entity.Update();
  9576. returnSuccessMsg("操作成功!");
  9577. return;
  9578. }
  9579. }
  9580. returnErrorMsg("找不到记录");
  9581. }
  9582. }
  9583. public void audit_erp_designerbill()
  9584. {
  9585. if (UrlPostParmsCheck("ID"))
  9586. {
  9587. string eid = GetPostString("ID");
  9588. CeErpDesignerBill entity = null;
  9589. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9590. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9591. if (entity != null)
  9592. {
  9593. entity.realPrice = GetPostDouble("designerpirce");
  9594. entity.update_time = DateTime.Now;
  9595. entity.update_u_id = CurrentUser.UserID;
  9596. entity.update_u_name = CurrentUser.UserName;
  9597. entity.isAudit = 1;
  9598. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9599. entity.Update();
  9600. if (orderEntity != null)
  9601. {
  9602. orderEntity.IsReadTag = 3;
  9603. orderEntity.Update();
  9604. }
  9605. returnSuccessMsg("操作成功!");
  9606. return;
  9607. }
  9608. returnErrorMsg("找不到记录");
  9609. }
  9610. }
  9611. public void all_audit_erp_designerbill()
  9612. {
  9613. if (UrlPostParmsCheck("idList"))
  9614. {
  9615. string[] list = GetPostString("idList").Split(',');
  9616. CeErpDesignerBill entity = null;
  9617. for (int i = 0; i < list.Length; i++)
  9618. {
  9619. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9620. if (entity == null) return;
  9621. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9622. if (orderEntity == null) return;
  9623. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9624. entity.update_time = DateTime.Now;
  9625. entity.update_u_id = CurrentUser.UserID;
  9626. entity.update_u_name = CurrentUser.UserName;
  9627. entity.isAudit = 1;
  9628. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9629. entity.Update();
  9630. orderEntity.IsReadTag = 3;
  9631. orderEntity.Update();
  9632. }
  9633. returnSuccessMsg("操作成功!");
  9634. return;
  9635. }
  9636. }
  9637. public void get_erp_sameorders()
  9638. {
  9639. if (UrlPostParmsCheck("ctid"))
  9640. {
  9641. string eid = GetPostString("ctid");
  9642. CeErpTradeCell entity = null;
  9643. entity = CeErpTradeCell.GetByCtid(eid);
  9644. if (entity != null)
  9645. {
  9646. StringBuilder sql = new StringBuilder();
  9647. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9648. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9649. var res = new
  9650. {
  9651. data = dt.Rows.Count
  9652. };
  9653. string ro_jsond = JsonConvert.SerializeObject(res);
  9654. returnSuccess(ro_jsond);
  9655. return;
  9656. }
  9657. returnErrorMsg("未找到订单");
  9658. return;
  9659. }
  9660. returnErrorMsg("缺少必要的参数");
  9661. }
  9662. public void get_erp_islasthavesameorder()
  9663. {
  9664. if (UrlPostParmsCheck("ctid"))
  9665. {
  9666. string eid = GetPostString("ctid");
  9667. string[] ctidList = eid.Split(',');
  9668. StringBuilder sql = new StringBuilder();
  9669. string tisCtid = "";
  9670. foreach (string ctid in ctidList)
  9671. {
  9672. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9673. if (entity != null)
  9674. {
  9675. sql = new StringBuilder();
  9676. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9677. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9678. if (dth.Rows.Count > 0)
  9679. {
  9680. tisCtid += entity.ctid;
  9681. tisCtid += ",";
  9682. }
  9683. }
  9684. }
  9685. if (tisCtid.Length > 0)
  9686. {
  9687. var res = new
  9688. {
  9689. data = tisCtid
  9690. };
  9691. string ro_jsond = JsonConvert.SerializeObject(res);
  9692. returnSuccess(ro_jsond);
  9693. }
  9694. else
  9695. {
  9696. var res = new
  9697. {
  9698. data = ""
  9699. };
  9700. string ro_jsond = JsonConvert.SerializeObject(res);
  9701. returnSuccess(ro_jsond);
  9702. }
  9703. return;
  9704. }
  9705. returnErrorMsg("缺少必要的参数");
  9706. }
  9707. public void file_client_down_url()
  9708. {
  9709. if (!UrlPostParmsCheck("userId"))
  9710. {
  9711. returnErrorMsg("缺少必要的参数");
  9712. }
  9713. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9714. }
  9715. public void checkout_form_data()
  9716. {
  9717. if (!UrlPostParmsCheck("tid"))
  9718. {
  9719. returnErrorMsg("缺少必要的参数");
  9720. }
  9721. string tid = GetPostString("tid");
  9722. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9723. if (ceErpOrderFormData != null)
  9724. {
  9725. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9726. returnSuccess(ro_jsond);
  9727. return;
  9728. }
  9729. returnErrorMsg("尚未有文件!");
  9730. }
  9731. public void back_supplier_audit()
  9732. {
  9733. int userId = CurrentUser.UserID;
  9734. StringBuilder sql = new StringBuilder();
  9735. 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);
  9736. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9737. if (dt.Rows.Count > 0)
  9738. {
  9739. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9740. }
  9741. else
  9742. {
  9743. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9744. }
  9745. }
  9746. public void back_supplier_query()
  9747. {
  9748. string eid = GetPostString("ctid");
  9749. if (eid != "")
  9750. {
  9751. StringBuilder sql = new StringBuilder();
  9752. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9753. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9754. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9755. }
  9756. else
  9757. {
  9758. returnErrorMsg("找不到订单记录");
  9759. return;
  9760. }
  9761. }
  9762. public void verified_to_order()
  9763. {
  9764. int userId = CurrentUser.UserID;
  9765. StringBuilder sql = new StringBuilder();
  9766. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9767. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9768. if (dt.Rows.Count > 0)
  9769. {
  9770. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9771. }
  9772. else
  9773. {
  9774. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9775. }
  9776. }
  9777. public void upd_supplier_audit()
  9778. {
  9779. if (UrlPostParmsCheck("ctid"))
  9780. {
  9781. string eid = GetPostString("ctid");
  9782. string reason = GetPostString("returnreason");
  9783. CeErpTradeCell entity = null;
  9784. CeWithdraw withdraw = null;
  9785. withdraw = CeWithdraw.GetByTid(eid);
  9786. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9787. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9788. {
  9789. if (withdraw != null)
  9790. {
  9791. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9792. {
  9793. returnSuccessMsg("您没有权限操作!");
  9794. return;
  9795. }
  9796. else
  9797. {
  9798. if (reason.Equals("1"))
  9799. {
  9800. if (entity.OrderState == -1)
  9801. {
  9802. if (entity.FinishPlaceTime == null)
  9803. {
  9804. entity.OrderState = 2;
  9805. }
  9806. else
  9807. {
  9808. entity.OrderState = 6;
  9809. }
  9810. }
  9811. entity.Update();
  9812. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9813. if (withdraw != null)
  9814. {
  9815. withdraw.status = int.Parse(reason);
  9816. withdraw.Update();
  9817. }
  9818. returnSuccessMsg("操作成功!");
  9819. return;
  9820. }
  9821. else
  9822. {
  9823. withdraw.status = int.Parse(reason);
  9824. withdraw.acknowledgingtime = DateTime.Now;
  9825. withdraw.Update();
  9826. returnSuccessMsg("查看详细请点击线下订单查询");
  9827. return;
  9828. }
  9829. }
  9830. }
  9831. // 第一个字符是 'N'
  9832. }
  9833. if (eid[0] != 'N')
  9834. {
  9835. }
  9836. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9837. {
  9838. entity.IsVerifyToSupplier = false;
  9839. entity.IsReturn = 1;
  9840. entity.ReturnTime = DateTime.Now;
  9841. entity.ReturnReason = reason;
  9842. if (entity.OrderState == 6)
  9843. {
  9844. entity.OrderState = 5;
  9845. }
  9846. entity.Update();
  9847. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9848. if (withdraw != null)
  9849. {
  9850. withdraw.status = int.Parse(reason);
  9851. withdraw.Update();
  9852. }
  9853. returnSuccessMsg("操作成功!");
  9854. return;
  9855. }
  9856. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9857. {
  9858. ;
  9859. if (withdraw != null)
  9860. {
  9861. withdraw.status = int.Parse(reason);
  9862. withdraw.acknowledgingtime = DateTime.Now;
  9863. withdraw.Update();
  9864. returnSuccessMsg("供应商取消撤回!");
  9865. return;
  9866. }
  9867. }
  9868. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9869. {
  9870. if (entity.OrderState == -1)
  9871. {
  9872. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9873. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9874. {
  9875. returnErrorMsg("订单spu没有确认无法通过审核!");
  9876. return;
  9877. }
  9878. if (entity.FinishPlaceTime == null)
  9879. {
  9880. entity.OrderState = 2;
  9881. }
  9882. else
  9883. {
  9884. entity.OrderState = 3;
  9885. }
  9886. commonHelper.getCytPrice(entity);
  9887. }
  9888. entity.Update();
  9889. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9890. if (withdraw != null)
  9891. {
  9892. withdraw.status = int.Parse(reason);
  9893. withdraw.Update();
  9894. }
  9895. returnSuccessMsg("操作成功!");
  9896. return;
  9897. }
  9898. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9899. {
  9900. if (withdraw == null)
  9901. {
  9902. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9903. return;
  9904. }
  9905. }
  9906. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9907. {
  9908. if (withdraw != null)
  9909. {
  9910. withdraw.status = int.Parse(reason);
  9911. withdraw.acknowledgingtime = DateTime.Now;
  9912. withdraw.Update();
  9913. returnSuccessMsg("查看详细请点击线下订单查询");
  9914. return;
  9915. }
  9916. }
  9917. return;
  9918. }
  9919. }
  9920. //校验报价
  9921. public void refund_order_tip()
  9922. {
  9923. int userid = CurrentUser.UserID;
  9924. int sectionId = CurrentUser.UserPost.OrgID;
  9925. StringBuilder sql = new StringBuilder();
  9926. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9927. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9928. List<string> ids = new List<string>();
  9929. if (dth.Rows.Count > 0)
  9930. {
  9931. foreach (DataRow dr in dth.Rows)
  9932. {
  9933. ids.Add(dr["ID"].ToString());
  9934. }
  9935. try
  9936. {
  9937. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9938. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9939. }
  9940. catch (Exception ex)
  9941. {
  9942. }
  9943. }
  9944. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9945. }
  9946. public void refund_order_Design()
  9947. {
  9948. int userid = CurrentUser.UserID;
  9949. int sectionId = CurrentUser.UserPost.OrgID;
  9950. StringBuilder sql = new StringBuilder();
  9951. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9952. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9953. List<string> ids = new List<string>();
  9954. if (dth.Rows.Count > 0)
  9955. {
  9956. foreach (DataRow dr in dth.Rows)
  9957. {
  9958. ids.Add(dr["ID"].ToString());
  9959. }
  9960. try
  9961. {
  9962. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9963. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9964. }
  9965. catch (Exception ex)
  9966. {
  9967. }
  9968. }
  9969. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9970. }
  9971. public void change_order_info()
  9972. {
  9973. int userid = CurrentUser.UserID;
  9974. StringBuilder sql = new StringBuilder();
  9975. 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);
  9976. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9977. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9978. }
  9979. public void change_win_mome()
  9980. {
  9981. if (UrlPostParmsCheck("id,ctid"))
  9982. {
  9983. string id = GetPostString("id");
  9984. string ctid = GetPostString("ctid");
  9985. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9986. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9987. if (ce == null || ceErpMessageTip == null)
  9988. {
  9989. returnSuccessMsg("未找到对应的订单!");
  9990. return;
  9991. }
  9992. if (ce.OrderState >= 5)
  9993. {
  9994. returnSuccessMsg("已上传文件无法修改!");
  9995. return;
  9996. }
  9997. int type = GetPostInt("type");
  9998. string content = GetPostString("content");
  9999. if (type == 0)
  10000. {
  10001. content = content.Replace("(", "(");
  10002. content = content.Replace(")", ")");
  10003. string check = MidStrEx(content, "(", ")").Trim();
  10004. if (string.IsNullOrEmpty(check))
  10005. {
  10006. returnSuccessMsg("文件名格式不正确");
  10007. return;
  10008. }
  10009. }
  10010. ce.seller_memo = content;
  10011. ce.Update();
  10012. ceErpMessageTip.isVisit = true;
  10013. ceErpMessageTip.Update();
  10014. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10015. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10016. ApiVo apiVo = new ApiVo();
  10017. apiVo.orderNumber = ce.ctid;
  10018. apiVo.actionName = "demandDesign";
  10019. apiVo.orderRemarks = content;
  10020. apiVo.demandExamine = type + 1;
  10021. designHelper.API_WorkCore(apiVo);//demandDesign
  10022. returnSuccessMsg("修改成功!");
  10023. }
  10024. }
  10025. public static string MidStrEx(string sourse, string startstr, string endstr)
  10026. {
  10027. string result = string.Empty;
  10028. int startindex, endindex;
  10029. try
  10030. {
  10031. startindex = sourse.IndexOf(startstr);
  10032. if (startindex == -1)
  10033. return result;
  10034. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10035. endindex = tmpstr.IndexOf(endstr);
  10036. if (endindex == -1)
  10037. return result;
  10038. result = tmpstr.Remove(endindex);
  10039. }
  10040. catch (Exception ex)
  10041. {
  10042. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10043. }
  10044. return result;
  10045. }
  10046. public void refund_order_list()
  10047. {
  10048. int userid = CurrentUser.UserID;
  10049. int sectionId = CurrentUser.UserPost.OrgID;
  10050. StringBuilder sql = new StringBuilder();
  10051. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10052. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10053. DataStruct dStruct = GetPostStruct();
  10054. DataTable dt = null;
  10055. List<string> ids = new List<string>();
  10056. List<string> tids = new List<string>();
  10057. if (dth.Rows.Count > 0)
  10058. {
  10059. foreach (DataRow dr in dth.Rows)
  10060. {
  10061. tids.Add("'" + dr["tid"].ToString() + "'");
  10062. ids.Add(dr["id"].ToString());
  10063. }
  10064. try
  10065. {
  10066. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10067. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10068. List<string> lw = new List<string>();
  10069. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10070. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10071. dt = WebCache.GetData("view_orderlist", dStruct);
  10072. }
  10073. catch (Exception ex)
  10074. {
  10075. }
  10076. }
  10077. writeGridDataTableJson(dStruct.TotalCount, dt);
  10078. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10079. }
  10080. //新增
  10081. public void order_batch_downloads()
  10082. {
  10083. string ceid = GetPostString("tid");
  10084. String[] tid = ceid.Split(',');
  10085. order_batch_caiyingtong(tid);
  10086. /* (string success, string errors) = UploadFiles(tid);
  10087. returnSuccessMsg(success + errors);*/
  10088. return;
  10089. }
  10090. //报价接口
  10091. public void Get_To_Quote()
  10092. {
  10093. string ceid = GetPostString("ctid");
  10094. if (ceid != null)
  10095. {
  10096. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10097. if (entity != null)
  10098. {
  10099. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10100. {
  10101. return;
  10102. }
  10103. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10104. double price = 0;
  10105. if (cp == null)
  10106. {
  10107. JObject jsonObject12 = new JObject
  10108. {
  10109. { "UserId", "77886" },
  10110. { "Pwd", "lt666888" },
  10111. { "Filename", entity.seller_memo }
  10112. };
  10113. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10114. JObject jsonObjects1 = JObject.Parse(response1);
  10115. string ms1g = (string)jsonObjects1["msg"];
  10116. if (ms1g == "报价成功")
  10117. {
  10118. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10119. string data = (string)jsonObject1["price"];
  10120. 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 + "');";
  10121. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10122. returnSuccessMsg("获取报价成功:" + data);
  10123. price = Convert.ToDouble(data);
  10124. }
  10125. else
  10126. {
  10127. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10128. return;
  10129. }
  10130. }
  10131. String[] beizhu = entity.seller_memo.Split('-');
  10132. String chanp = "";
  10133. if (beizhu.Length > 0)
  10134. {
  10135. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10136. }
  10137. else
  10138. {
  10139. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10140. }
  10141. JObject jsonObject = new JObject
  10142. {
  10143. { "UserId", "77886" },
  10144. { "Pwd", "lt666888" },
  10145. { "Filename", chanp }
  10146. };
  10147. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10148. JObject jsonObjects = JObject.Parse(response);
  10149. string msg = (string)jsonObjects["msg"];
  10150. if (msg == "报价成功")
  10151. {
  10152. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10153. string data = (string)jsonObject1["price"];
  10154. 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 + "');";
  10155. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10156. returnSuccessMsg("获取报价成功:" + data);
  10157. price = Convert.ToDouble(data);
  10158. }
  10159. else
  10160. {
  10161. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10162. return;
  10163. }
  10164. if (price > 0)
  10165. {
  10166. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10167. if (ceErpTradeCellExtend == null)
  10168. {
  10169. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10170. ceErpTradeCellExtend.ctid = entity.ctid;
  10171. ceErpTradeCellExtend.payment_cyt = price;
  10172. ceErpTradeCellExtend.Create();
  10173. }
  10174. else
  10175. {
  10176. ceErpTradeCellExtend.payment_cyt = price;
  10177. ceErpTradeCellExtend.Update();
  10178. }
  10179. }
  10180. return;
  10181. }
  10182. }
  10183. else
  10184. {
  10185. returnErrorMsg("请至少选择一条数据");
  10186. return;
  10187. }
  10188. }
  10189. //新增
  10190. public void order_To_Supplier()
  10191. {
  10192. string ceid = GetPostString("tid");
  10193. String[] tid = ceid.Split(',');
  10194. if (tid.Length > 0)
  10195. {
  10196. try
  10197. {
  10198. for (int i = 0; i < tid.Length; i++)
  10199. {
  10200. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10201. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10202. entity.SupplierId = suid;
  10203. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10204. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10205. entity.Update();
  10206. }
  10207. }
  10208. catch (Exception ex)
  10209. {
  10210. returnErrorMsg("自动匹配供应商失败");
  10211. return;
  10212. }
  10213. }
  10214. else
  10215. {
  10216. returnErrorMsg("请至少选择一条数据");
  10217. return;
  10218. }
  10219. returnSuccessMsg("自动匹配供应商成功");
  10220. return;
  10221. }
  10222. public (string, string) UploadFiles(string[] urls)
  10223. {
  10224. string success = "";
  10225. string errors = "";
  10226. int userid = CurrentUser.UserID;
  10227. foreach (string url in urls)
  10228. {
  10229. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10230. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10231. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10232. {
  10233. JObject jsonObject = new JObject
  10234. {
  10235. { "Userid", "77886" },
  10236. { "pwd", "cyt86435015" },
  10237. { "content", base64FileContent },
  10238. { "ext", Path.GetExtension(fileName) }
  10239. };
  10240. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10241. JObject jsonObjects = JObject.Parse(response);
  10242. string msg = (string)jsonObjects["msg"];
  10243. if (msg.Equals("上传成功"))
  10244. {
  10245. success += url + " 上传成功";
  10246. }
  10247. else
  10248. {
  10249. errors += url + " 上传失败";
  10250. }
  10251. }
  10252. else
  10253. {
  10254. errors += url + " 格式出现问题";
  10255. }
  10256. }
  10257. if (urls.Length == 0)
  10258. {
  10259. return (success, errors);
  10260. }
  10261. return (success, errors);
  10262. }
  10263. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10264. {
  10265. return true; //总是接受
  10266. }
  10267. public static string HttpPost(string url, string param = null)
  10268. {
  10269. HttpWebRequest request;
  10270. //如果是发送HTTPS请求
  10271. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10272. {
  10273. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10274. request = WebRequest.Create(url) as HttpWebRequest;
  10275. request.ProtocolVersion = HttpVersion.Version10;
  10276. }
  10277. else
  10278. {
  10279. request = WebRequest.Create(url) as HttpWebRequest;
  10280. }
  10281. request.Method = "POST";
  10282. request.ContentType = "application/json";
  10283. request.Accept = "*/*";
  10284. request.Timeout = 120000;
  10285. request.AllowAutoRedirect = false;
  10286. StreamWriter requestStream = null;
  10287. WebResponse response = null;
  10288. string responseStr = null;
  10289. try
  10290. {
  10291. requestStream = new StreamWriter(request.GetRequestStream());
  10292. requestStream.Write(param);
  10293. requestStream.Close();
  10294. response = request.GetResponse();
  10295. if (response != null)
  10296. {
  10297. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10298. responseStr = reader.ReadToEnd();
  10299. reader.Close();
  10300. }
  10301. }
  10302. catch (Exception ex)
  10303. {
  10304. return ex.Message;
  10305. }
  10306. finally
  10307. {
  10308. request = null;
  10309. requestStream = null;
  10310. response = null;
  10311. }
  10312. return responseStr;
  10313. }
  10314. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10315. {
  10316. string base64FileContent;
  10317. string fileName;
  10318. using (WebClient webClient = new WebClient())
  10319. {
  10320. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10321. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10322. {
  10323. using (Stream stream = response.GetResponseStream())
  10324. {
  10325. using (MemoryStream memoryStream = new MemoryStream())
  10326. {
  10327. stream.CopyTo(memoryStream);
  10328. byte[] fileBytes = memoryStream.ToArray();
  10329. base64FileContent = Convert.ToBase64String(fileBytes);
  10330. fileName = response.Headers["Content-Disposition"];
  10331. if (!string.IsNullOrEmpty(fileName))
  10332. {
  10333. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10334. if (index >= 0)
  10335. {
  10336. fileName = fileName.Substring(index + 9).Trim('\"');
  10337. }
  10338. }
  10339. else
  10340. {
  10341. fileName = Path.GetFileName(downloadUrl);
  10342. }
  10343. }
  10344. }
  10345. }
  10346. }
  10347. return (fileName, base64FileContent);
  10348. }
  10349. //新增
  10350. public void order_batch_caiyingtong(string[] downloadUrls)
  10351. {
  10352. try
  10353. {
  10354. //遍历文件
  10355. DataStruct dStruct = GetPostStruct();
  10356. DataTable dt = null;
  10357. int userid = CurrentUser.UserID;
  10358. List<string> ids = new List<string>();//失败组
  10359. List<string> tids = new List<string>();
  10360. using (WebClient webClient = new WebClient())
  10361. {
  10362. foreach (var url in downloadUrls)
  10363. {
  10364. try
  10365. {
  10366. tids.Add("'" + url + "'");
  10367. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10368. if (entity != null)
  10369. {
  10370. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10371. if (cp == null)
  10372. {
  10373. JObject jsonObject = new JObject
  10374. {
  10375. { "Userid", "77886" },
  10376. { "pwd", "lt666888" },
  10377. { "Filename",entity.seller_memo }
  10378. };
  10379. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10380. JObject jsonObjects = JObject.Parse(response);
  10381. string msg = (string)jsonObjects["msg"];
  10382. if (msg == "报价成功")
  10383. {
  10384. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10385. DownloadAndConvertToBase64(url1);
  10386. }
  10387. else
  10388. {
  10389. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10390. }
  10391. }
  10392. else
  10393. {
  10394. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10395. JObject jsonObject = new JObject
  10396. {
  10397. { "Userid", "77886" },
  10398. { "pwd", "lt666888" },
  10399. { "Filename",chanp }
  10400. };
  10401. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10402. JObject jsonObjects = JObject.Parse(response);
  10403. string msg = (string)jsonObjects["msg"];
  10404. if (msg == "报价成功")
  10405. {
  10406. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10407. DownloadAndConvertToBase64(url1);
  10408. }
  10409. else
  10410. {
  10411. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10412. }
  10413. }
  10414. }
  10415. // 上传文件到FTP
  10416. }
  10417. catch (Exception ex)
  10418. {
  10419. Console.WriteLine($"An error occurred: {ex.Message}");
  10420. }
  10421. }
  10422. List<string> lw = new List<string>();
  10423. lw.Add(string.Format("( OrderState < 6 )"));
  10424. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10425. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10426. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10427. if (dt.Rows.Count > 0)
  10428. {
  10429. foreach (DataRow dr in dt.Rows)
  10430. {
  10431. ids.Add(dr["ctid"].ToString());
  10432. }
  10433. }
  10434. String ErrorMsgs = "";
  10435. foreach (String id in ids)
  10436. {
  10437. ErrorMsgs += id + ",";
  10438. }
  10439. if (ErrorMsgs.Length > 1)
  10440. {
  10441. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10442. }
  10443. if (ErrorMsgs.Length < 1)
  10444. {
  10445. ErrorMsgs = "上传成功";
  10446. returnSuccessMsg(ErrorMsgs);
  10447. }
  10448. else
  10449. {
  10450. returnErrorMsg("以下订单" + ErrorMsgs);
  10451. }
  10452. }
  10453. // 删除文件夹及其内容
  10454. /* Directory.Delete(localDirectory, true);*/
  10455. }
  10456. catch { }
  10457. }
  10458. public void get_center_data()
  10459. {
  10460. int userId = CurrentUser.UserID;
  10461. string postCode = CurrentUser.UserPost.Post.Code;
  10462. List<string> lw = new List<string>();
  10463. List<string> ww = new List<string>();
  10464. DateTime currentTime = DateTime.Now;
  10465. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10466. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10467. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10468. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10469. string sql = " SELECT ";
  10470. string startTime = "2023-10-01 11:22:31";
  10471. //设计
  10472. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10473. {
  10474. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10475. 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));
  10476. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10477. 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));
  10478. }
  10479. //客服
  10480. else if (postCode == "CustomerService" || postCode == "Director")
  10481. {
  10482. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10483. 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));
  10484. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10485. 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));
  10486. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10487. 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));
  10488. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10489. 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));
  10490. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10491. 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));
  10492. }
  10493. //售后
  10494. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10495. {
  10496. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10497. 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));
  10498. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10499. 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));
  10500. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10501. 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));
  10502. }
  10503. //下单部
  10504. else if (postCode == "Place" || postCode == "PlaceMr")
  10505. {
  10506. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10507. ww.Add(string.Format("( SELECT COUNT ( * ) AS orderCount FROM CE_ErpTradeCell WHERE FinishDesignTime < '{1}' AND OrderState = 5 AND IsReturn = 0 AND pay_time > '{0}' ) AS oc", startTime, finishDesignTime));
  10508. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10509. ww.Add(string.Format("( SELECT COUNT ( * ) AS sendCount FROM CE_ErpTradeCell WHERE FinishPlaceTime < '{1}' AND OrderState = 6 AND IsReturn = 0 AND pay_time > '{0}' ) AS sc", startTime, finishPlaceTime));
  10510. }
  10511. //车间
  10512. else if (postCode == "Supplier")
  10513. {
  10514. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10515. 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));
  10516. }
  10517. DataTable dt = new DataTable();
  10518. if (lw.Count > 0)
  10519. {
  10520. sql += string.Join(" , ", lw);
  10521. sql += " FROM ";
  10522. sql += string.Join(" , ", ww);
  10523. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10524. }
  10525. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10526. }
  10527. public void get_center_data_list()
  10528. {
  10529. int userId = CurrentUser.UserID;
  10530. string postCode = CurrentUser.UserPost.Post.Code;
  10531. string shopIds = CurrentUser.User.pemShop;
  10532. DataStruct dStruct = GetPostStruct();
  10533. List<string> lw = new List<string>();
  10534. DateTime currentTime = DateTime.Now;
  10535. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10536. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10537. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10538. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10539. string startTime = "2023-10-01 11:22:31";
  10540. int order_type = GetPostInt("order_type");
  10541. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10542. {
  10543. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10544. if (order_type == 0)
  10545. {
  10546. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10547. }
  10548. else if (order_type == 3)
  10549. {
  10550. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10551. }
  10552. else
  10553. {
  10554. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10555. }
  10556. }
  10557. //客服
  10558. if (postCode == "CustomerService" || postCode == "Director")
  10559. {
  10560. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10561. if (order_type == 0)
  10562. {
  10563. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10564. }
  10565. else if (order_type == 1)
  10566. {
  10567. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10568. }
  10569. else if (order_type == 2)
  10570. {
  10571. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10572. }
  10573. else if (order_type == 3)
  10574. {
  10575. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10576. }
  10577. else if (order_type == 4)
  10578. {
  10579. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10580. }
  10581. else
  10582. {
  10583. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10584. }
  10585. }
  10586. //售后
  10587. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10588. {
  10589. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10590. if (shopIds != "")
  10591. {
  10592. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10593. }
  10594. if (order_type == 2)
  10595. {
  10596. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10597. }
  10598. else if (order_type == 4)
  10599. {
  10600. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10601. }
  10602. else if (order_type == 5)
  10603. {
  10604. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10605. }
  10606. else
  10607. {
  10608. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10609. }
  10610. }
  10611. //下单部
  10612. if (postCode == "Place" || postCode == "PlaceMr")
  10613. {
  10614. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10615. if (shopIds != "")
  10616. {
  10617. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10618. }
  10619. else if (order_type == 1)
  10620. {
  10621. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10622. }
  10623. else if (order_type == 2)
  10624. {
  10625. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10626. }
  10627. else
  10628. {
  10629. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10630. }
  10631. }
  10632. //车间
  10633. if (postCode == "Supplier")
  10634. {
  10635. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10636. if (order_type == 5)
  10637. {
  10638. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10639. }
  10640. else
  10641. {
  10642. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10643. }
  10644. }
  10645. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10646. dStruct.Fileds = "tid,ctid";
  10647. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10648. writeGridDataTableJson(dStruct.TotalCount, dt);
  10649. }
  10650. public void aftersale_audit_master()
  10651. {
  10652. if (UrlPostParmsCheck("ctid"))
  10653. {
  10654. string ctid = GetPostString("ctid");
  10655. if (ctid.Length > 0)
  10656. {
  10657. bool result = aftersale_data_change(ctid);
  10658. if (result)
  10659. {
  10660. returnSuccessMsg("修改成功!");
  10661. return;
  10662. }
  10663. }
  10664. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10665. }
  10666. }
  10667. public void aftersale_batch_audit_master()
  10668. {
  10669. if (UrlPostParmsCheck("ctids"))
  10670. {
  10671. string ctids = GetPostString("ctids");
  10672. if (ctids.Length > 0)
  10673. {
  10674. List<string> list = new List<string>();
  10675. string[] ctid_list = ctids.Split(',');
  10676. foreach (var item in ctid_list)
  10677. {
  10678. bool result = aftersale_data_change(item);
  10679. if (!result)
  10680. {
  10681. list.Add(item);
  10682. }
  10683. }
  10684. if (list.Count > 0)
  10685. {
  10686. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10687. return;
  10688. }
  10689. returnSuccessMsg("修改成功!");
  10690. return;
  10691. }
  10692. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10693. }
  10694. }
  10695. public bool aftersale_data_change(string ctid)
  10696. {
  10697. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10698. if (ceErpTradeCell != null)
  10699. {
  10700. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10701. ceErpTradeCell.AfterSaleSupplierState = 0;
  10702. StringBuilder sql = new StringBuilder();
  10703. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10704. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10705. CeErpTradeResponsible.DelByTid(ctid, 0);
  10706. 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 == "不理赔")
  10707. {
  10708. CeErpTradeResponsible.DelByTid(ctid, 1);
  10709. ceErpTradeCell.AfterSaleSupplierState = 1;
  10710. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10711. ceErpTradeCell.AfterSaleState = 4;
  10712. }
  10713. else
  10714. {
  10715. ceErpTradeCell.AfterSaleState = 3;
  10716. }
  10717. bool needCyt = false;
  10718. if (dt != null)
  10719. {
  10720. if (dt.Rows.Count == 1)
  10721. {
  10722. bool isEnd = false;
  10723. foreach (DataRow dr in dt.Rows)
  10724. {
  10725. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10726. {
  10727. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10728. isEnd = true;
  10729. }
  10730. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10731. {
  10732. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10733. isEnd = true;
  10734. }
  10735. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10736. {
  10737. needCyt = true;
  10738. }
  10739. }
  10740. if (isEnd)
  10741. {
  10742. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10743. ceErpTradeCell.AfterSaleState = 4;
  10744. ceErpTradeCell.AfterSaleSupplierState = 1;
  10745. }
  10746. }
  10747. else
  10748. {
  10749. bool isAll = true;
  10750. foreach (DataRow dr in dt.Rows)
  10751. {
  10752. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10753. {
  10754. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10755. continue;
  10756. }
  10757. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10758. {
  10759. string path = "";
  10760. int OrgID = 0;
  10761. if (!Convert.IsDBNull(dr["OrgPath"]))
  10762. {
  10763. path = dr["OrgPath"].ToString();
  10764. }
  10765. if (!Convert.IsDBNull(dr["OrgID"]))
  10766. {
  10767. OrgID = Convert.ToInt32(dr["OrgID"]);
  10768. }
  10769. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10770. {
  10771. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10772. continue;
  10773. }
  10774. }
  10775. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10776. {
  10777. needCyt = true;
  10778. }
  10779. isAll = false;
  10780. }
  10781. if (isAll)
  10782. {
  10783. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10784. ceErpTradeCell.AfterSaleState = 4;
  10785. ceErpTradeCell.AfterSaleSupplierState = 1;
  10786. }
  10787. }
  10788. }
  10789. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10790. {
  10791. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10792. }
  10793. if (ceErpTradeCell.AfterSaleState == 4)
  10794. {
  10795. ApiVo apiVo = new ApiVo();
  10796. apiVo.orderNumber = ceErpTradeCell.ctid;
  10797. apiVo.actionName = "afterOver";
  10798. designHelper.API_WorkCore(apiVo); //afterOver
  10799. }
  10800. ceErpTradeCell.Update();
  10801. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10802. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10803. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10804. return true;
  10805. }
  10806. return false;
  10807. }
  10808. public void get_erp_wechatorder()
  10809. {
  10810. DataStruct dStruct = GetPostStruct();
  10811. List<string> lw = new List<string>();
  10812. string tid = GetPostString("tid");
  10813. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10814. string shopname = GetPostString("shopname");
  10815. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10816. string buyernick = GetPostString("buyer_nick");
  10817. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10818. string customer = GetPostString("customer");
  10819. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10820. string returndate1 = GetPostString("returndate1");
  10821. string returndate2 = GetPostString("returndate2");
  10822. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10823. if (dw.Length > 0) lw.Add(dw);
  10824. string finishDate1 = GetPostString("finishdate1");
  10825. string finishDate2 = GetPostString("finishdate2");
  10826. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10827. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10828. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10829. dStruct.Order = "created desc";
  10830. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10831. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10832. writeGridDataTableJson(dStruct.TotalCount, dt);
  10833. }
  10834. public void get_erp_wechatlist_sumprice()
  10835. {
  10836. DataStruct dStruct = GetPostStruct();
  10837. List<string> lw = new List<string>();
  10838. string tid = GetPostString("tid");
  10839. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10840. string shopname = GetPostString("shopname");
  10841. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10842. string buyernick = GetPostString("buyer_nick");
  10843. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10844. string customer = GetPostString("customer");
  10845. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10846. string returndate1 = GetPostString("returndate1");
  10847. string returndate2 = GetPostString("returndate2");
  10848. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10849. if (dw.Length > 0) lw.Add(dw);
  10850. string finishDate1 = GetPostString("finishdate1");
  10851. string finishDate2 = GetPostString("finishdate2");
  10852. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10853. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10854. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10855. string mainWhere = string.Join(" and ", lw.ToArray());
  10856. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10857. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10858. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10859. decimal total = 0;
  10860. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10861. {
  10862. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10863. }
  10864. var res = new
  10865. {
  10866. data = total
  10867. };
  10868. string ro_jsond = JsonConvert.SerializeObject(res);
  10869. returnSuccess(ro_jsond);
  10870. return;
  10871. }
  10872. public void get_erp_qr_waitdeliverylist()
  10873. {
  10874. DataStruct dStruct = GetPostStruct();
  10875. List<string> lw = new List<string>();
  10876. string tid = GetPostString("ctid");
  10877. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10878. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10879. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10880. var res_objz = new
  10881. {
  10882. restype = 1,
  10883. data = dt
  10884. };
  10885. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10886. returnSuccess(ro_jsonz);
  10887. }
  10888. public void get_erp_yield_list()
  10889. {
  10890. DataStruct dStruct = GetPostStruct();
  10891. List<string> lw = new List<string>();
  10892. string tid = GetPostString("ctid");
  10893. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10894. string shopname = GetPostString("shopname");
  10895. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10896. string buyernick = GetPostString("buyer_nick");
  10897. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10898. //if (tid.Length == 0 && buyernick.Length == 0)
  10899. //{
  10900. // lw.Add(string.Format("IsRefund<={0}", 1));
  10901. //}
  10902. string customer = GetPostString("customer");
  10903. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10904. string design = GetPostString("design");
  10905. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10906. string orderState = GetPostString("orderState");
  10907. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10908. string address = GetPostString("address");
  10909. 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));
  10910. string sellermemo = GetPostString("seller_memo");
  10911. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10912. string supplier = GetPostString("supplier");
  10913. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10914. string OrderArea = GetPostString("order_area");
  10915. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10916. string placedate1 = GetPostString("placedate1");
  10917. string placedate2 = GetPostString("placedate2");
  10918. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10919. if (fdw.Length > 0) lw.Add(fdw);
  10920. string price1 = GetPostString("price1");
  10921. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10922. string price2 = GetPostString("price2");
  10923. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10924. string unusualCon = GetPostString("unusualcon");
  10925. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10926. string posTag = CurrentUser.UserPost.Post.Code;
  10927. if (posTag == "Supplier")
  10928. {
  10929. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10930. }
  10931. lw.Add(string.Format("OrderState = 6 "));
  10932. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10933. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10934. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10935. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10936. writeGridDataTableJson(dStruct.TotalCount, dt);
  10937. }
  10938. public void change_erp_sup_state()
  10939. {
  10940. if (UrlPostParmsCheck("ctid"))
  10941. {
  10942. string ctid = GetPostString("ctid");
  10943. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10944. if (ceErpTradeCell != null)
  10945. {
  10946. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10947. if (ceErpTradeCellExtend == null)
  10948. {
  10949. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10950. ceErpTradeCellExtend.ctid = ctid;
  10951. ceErpTradeCellExtend.SupState = 1;
  10952. ceErpTradeCellExtend.Create();
  10953. }
  10954. else
  10955. {
  10956. ceErpTradeCellExtend.SupState = 1;
  10957. ceErpTradeCellExtend.Update();
  10958. }
  10959. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10960. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10961. return;
  10962. }
  10963. returnErrorMsg("找不到订单");
  10964. }
  10965. }
  10966. public void supplier_all_downs()
  10967. {
  10968. if (UrlPostParmsCheck("tids"))
  10969. {
  10970. string tids = GetPostString("tids");
  10971. if (tids != null && tids.Length > 0)
  10972. {
  10973. StringBuilder sql = new StringBuilder();
  10974. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10975. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10976. sql = new StringBuilder();
  10977. 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, "下载设计文件");
  10978. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10979. string[] list = tids.Split(',');
  10980. foreach (string ctid in list)
  10981. {
  10982. CeErpSukuraData.createInfo(ctid, 3);
  10983. }
  10984. designHelper.api_approveDesign(tids); //approveDesign
  10985. returnSuccessMsg("下载成功!");
  10986. return;
  10987. }
  10988. returnErrorMsg("下载订单更新失败");
  10989. }
  10990. }
  10991. public void uploaderFileSuccess()
  10992. {
  10993. if (UrlPostParmsCheck("fileName"))
  10994. {
  10995. string fileName = GetPostString("fileName");
  10996. ApiVo apiVo = new ApiVo();
  10997. apiVo.orderNumber = fileName;
  10998. apiVo.actionName = "finishDesign";
  10999. designHelper.API_WorkCore(apiVo);//finishDesign
  11000. returnSuccessMsg("");
  11001. }
  11002. }
  11003. public void get_sample2_order()
  11004. {
  11005. if (UrlPostParmsCheck("ctid"))
  11006. {
  11007. string ctid = GetPostString("ctid");
  11008. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11009. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11010. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11011. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11012. double total = 0.0;
  11013. double order_price = 0.0;
  11014. if (dt_bu.Rows.Count > 0)
  11015. {
  11016. foreach (DataRow dr in dt_bu.Rows)
  11017. {
  11018. total += Convert.ToDouble(dr["payment"]);
  11019. }
  11020. }
  11021. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11022. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11023. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11024. string tid = ctid.Replace("S_", "");
  11025. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11026. double paymant = 0.0;
  11027. if (entity != null)
  11028. {
  11029. paymant = entity.payment;
  11030. }
  11031. string return_reason = "";
  11032. if (dt_after != null && dt_after.Rows.Count > 0)
  11033. {
  11034. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11035. }
  11036. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11037. }
  11038. }
  11039. public void get_erp_design_status()
  11040. {
  11041. string designName = GetPostString("designName");
  11042. DataStruct dStruct = GetPostStruct();
  11043. if (designName.Length > 0)
  11044. {
  11045. 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";
  11046. sql_user += " and Name like '%" + designName + "%'";
  11047. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11048. List<string> ids_list = new List<string>();
  11049. if (user_table.Rows.Count > 0)
  11050. {
  11051. foreach (DataRow item in user_table.Rows)
  11052. {
  11053. ids_list.Add(item["id"].ToString());
  11054. string ids_s = item["TeamIds"].ToString();
  11055. if (ids_s.Length > 0)
  11056. {
  11057. ids_list.AddRange(ids_s.Split(','));
  11058. }
  11059. }
  11060. }
  11061. HashSet<string> set = new HashSet<string>(ids_list);
  11062. ids_list = set.ToList();
  11063. if (ids_list.Count > 0)
  11064. {
  11065. 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));
  11066. dStruct.MainWhere = sql;
  11067. DataTable dt = null;
  11068. dt = WebCache.GetData("view_ErpUser", dStruct);
  11069. writeGridDataTableJson(dStruct.TotalCount, dt);
  11070. }
  11071. }
  11072. }
  11073. public void change_erp_order_price()
  11074. {
  11075. string ctid = GetPostString("ctid");
  11076. double price = GetPostDouble("price");
  11077. if (ctid.Length > 0)
  11078. {
  11079. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11080. if (ceErpTradeCellExtend == null)
  11081. {
  11082. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11083. ceErpTradeCellExtend.ctid = ctid;
  11084. ceErpTradeCellExtend.payment_cyt = price;
  11085. ceErpTradeCellExtend.Create();
  11086. }
  11087. else
  11088. {
  11089. ceErpTradeCellExtend.payment_cyt = price;
  11090. ceErpTradeCellExtend.Update();
  11091. }
  11092. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11093. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11094. {
  11095. ceErpDataSendOrderInfo.isSync = false;
  11096. ceErpDataSendOrderInfo.Update();
  11097. }
  11098. if (ceErpDataSendOrderInfo == null)
  11099. {
  11100. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11101. ceErpDataSendOrderInfo.isSync = false;
  11102. ceErpDataSendOrderInfo.ctid = ctid;
  11103. ceErpDataSendOrderInfo.Create();
  11104. }
  11105. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11106. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11107. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11108. if (dth != null && dth.Rows.Count > 0)
  11109. {
  11110. dataSendOrderBean dataSendOrderBean = null;
  11111. foreach (DataRow item in dth.Rows)
  11112. {
  11113. try
  11114. {
  11115. dataSendOrderBean = new dataSendOrderBean();
  11116. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11117. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11118. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11119. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11120. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11121. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11122. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11123. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11124. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11125. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11126. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11127. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11128. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11129. if (result != null)
  11130. {
  11131. if ("0".Equals(result.errcode))
  11132. {
  11133. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11134. }
  11135. else
  11136. {
  11137. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11138. }
  11139. }
  11140. }
  11141. catch (Exception ex)
  11142. {
  11143. }
  11144. }
  11145. }
  11146. returnSuccessMsg("修改成功!");
  11147. return;
  11148. }
  11149. returnErrorMsg("找不到订单");
  11150. }
  11151. public void find_he_together()
  11152. {
  11153. string ctid = GetPostString("ctid");
  11154. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11155. List<string> list = new List<string>();
  11156. if (ceErpTradeCell != null)
  11157. {
  11158. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11159. {
  11160. 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);
  11161. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11162. if (table != null && table.Rows.Count > 0)
  11163. {
  11164. foreach (TableRow row in table.Rows)
  11165. {
  11166. }
  11167. }
  11168. }
  11169. }
  11170. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11171. }
  11172. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11173. {
  11174. //chy----19
  11175. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11176. //GD-CYT-----64
  11177. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11178. //ZHX----3
  11179. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11180. //JK----97
  11181. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11182. //ZT----70
  11183. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11184. //LHCY-----98
  11185. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11186. //XD-----90
  11187. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11188. //CYCY-----14
  11189. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11190. };
  11191. //其他改名
  11192. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11193. {
  11194. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11195. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11196. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11197. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11198. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11199. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11200. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11201. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11202. };
  11203. //不统计
  11204. List<int> no_suppliers = new List<int>()
  11205. {
  11206. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11207. };
  11208. //配件单
  11209. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11210. {
  11211. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11212. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11213. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11214. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11215. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11216. {"旗杆",new List<string>(){ "班旗" } },
  11217. {"牙签",new List<string>(){ "不干胶" } }
  11218. };
  11219. public void get_place_order_data()
  11220. {
  11221. string date1 = GetPostString("date1");
  11222. string date2 = GetPostString("date2");
  11223. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11224. DateTime start = DateTime.Parse(starttime);
  11225. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11226. DateTime end = DateTime.Parse(endtime);
  11227. if (date1 != null && date1.Length > 0)
  11228. {
  11229. DateTime dateTime = DateTime.Parse(date1);
  11230. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11231. start = DateTime.Parse(starttime);
  11232. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11233. end = DateTime.Parse(endtime);
  11234. }
  11235. if (date2 != null && date2.Length > 0)
  11236. {
  11237. DateTime dateTime = DateTime.Parse(date2);
  11238. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11239. end = DateTime.Parse(endtime);
  11240. }
  11241. 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);
  11242. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11243. //不干胶-----1,卡片-----29
  11244. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11245. foreach (DataRow row in data.Rows)
  11246. {
  11247. int productId = Convert.ToInt32(row["ProductId"]);
  11248. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11249. if (no_suppliers.Contains(supplierId))
  11250. {
  11251. continue;
  11252. }
  11253. string seller_memo = row["seller_memo"].ToString();
  11254. bool ispj = false;//是否配件单
  11255. bool isfirst = true;//第一个配
  11256. maps.Keys.ForEach(key =>
  11257. {
  11258. //备注包含配件
  11259. if (seller_memo.Contains(key) && isfirst)
  11260. {
  11261. List<string> list = maps[key];
  11262. ispj = true;
  11263. isfirst = false;
  11264. for (int i = 0; i < list.Count; i++)
  11265. {
  11266. if (seller_memo.Contains(list[i]))
  11267. {
  11268. ispj = false;
  11269. break;
  11270. }
  11271. }
  11272. }
  11273. });
  11274. if (ispj)
  11275. {
  11276. continue;
  11277. }
  11278. seller_memo = seller_memo.Replace("UV", "uv");
  11279. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11280. //吊牌归到卡片
  11281. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11282. seller_memo = seller_memo.Replace("卡套", "卡片");
  11283. seller_memo = seller_memo.Replace("封套", "卡片");
  11284. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11285. seller_memo = seller_memo.Replace("腰封", "卡片");
  11286. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11287. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11288. seller_memo = seller_memo.Replace("横幅", "条幅");
  11289. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11290. string map_key = "";
  11291. string type = "";
  11292. if (supplierMap.ContainsKey(supplierId))
  11293. {
  11294. foreach (var kvp in supplierMap[supplierId])
  11295. {
  11296. if (seller_memo.Contains(kvp.Key))
  11297. {
  11298. map_key = kvp.Value;
  11299. type = kvp.Value;
  11300. break;
  11301. }
  11302. }
  11303. }
  11304. if (map_key == "")
  11305. {
  11306. type = "其他";
  11307. map_key = "其他";
  11308. }
  11309. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11310. {
  11311. map_key = suppliers[supplierId];
  11312. }
  11313. if (supplierId == 70)
  11314. {
  11315. supplierId = 70;
  11316. }
  11317. map_key += "_" + row["SupplierName"].ToString();
  11318. Dictionary<string, int> map = null;
  11319. if (other_map.ContainsKey(map_key))
  11320. {
  11321. other_map.TryGetValue(map_key, out map);
  11322. }
  11323. else
  11324. {
  11325. map = new Dictionary<string, int>();
  11326. map.Add("dayDev", 0);//当天出货
  11327. map.Add("dayTotal", 0);//下单总数
  11328. map.Add("payTotal", 0);//500以上
  11329. map.Add("today", 0);//当天出货数量
  11330. map.Add("unusua", 0);//异常数
  11331. other_map.Add(map_key, map);
  11332. other_map.TryGetValue(map_key, out map);
  11333. }
  11334. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11335. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11336. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11337. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11338. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11339. {
  11340. map["dayTotal"]++;
  11341. if (supplierId == 97)
  11342. {
  11343. supplierId = 97;
  11344. }
  11345. }
  11346. if (Convert.ToDecimal(row["payment"]) >= 500)
  11347. {
  11348. map["payTotal"]++;
  11349. }
  11350. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11351. {
  11352. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11353. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11354. {
  11355. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11356. {
  11357. map["today"]++;
  11358. }
  11359. }
  11360. else
  11361. {
  11362. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11363. {
  11364. map["today"]++;
  11365. }
  11366. else
  11367. {
  11368. if (supplierId == 119)
  11369. {
  11370. Debug.WriteLine(row["seller_memo"].ToString());
  11371. }
  11372. }
  11373. }
  11374. }
  11375. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11376. {
  11377. map["unusua"]++;
  11378. }
  11379. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11380. //GD-CYT-----64
  11381. DateTime two = palceTimeStart.AddHours(14);
  11382. DateTime three = palceTimeStart.AddHours(15);
  11383. DateTime four = palceTimeStart.AddHours(16);
  11384. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11385. {
  11386. //下午四点前 500-1000
  11387. string count = row["ProductCount"].ToString();
  11388. if (count != null && count.Length > 0)
  11389. {
  11390. int productCount = commonHelper.getPlaceProductCount(count);
  11391. if (productCount >= 500 && productCount <= 1000)
  11392. {
  11393. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11394. {
  11395. map["dayDev"]++;
  11396. }
  11397. }
  11398. }
  11399. }
  11400. //UV
  11401. else if ("uv".Equals(type))
  11402. {
  11403. //ZT----70
  11404. //ZHX----3
  11405. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11406. {
  11407. map["dayDev"]++;
  11408. }
  11409. //JK----97
  11410. //HZX----105
  11411. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11412. {
  11413. map["dayDev"]++;
  11414. if (supplierId == 97)
  11415. {
  11416. supplierId = 97;
  11417. }
  11418. }
  11419. }
  11420. //帆布---52|条幅---27
  11421. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11422. {
  11423. //LHCY-----98
  11424. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11425. {
  11426. map["dayDev"]++;
  11427. }
  11428. }
  11429. //条幅
  11430. else if ("条幅".Equals(type))
  11431. {
  11432. //XD-----90
  11433. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11434. {
  11435. map["dayDev"]++;
  11436. }
  11437. }
  11438. //桌布
  11439. else if ("桌布".Equals(type))
  11440. {
  11441. //XD-----90
  11442. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11443. {
  11444. map["dayDev"]++;
  11445. }
  11446. }
  11447. //DL---10
  11448. //AYTW---119
  11449. //FS-CYT-DY ----80
  11450. //JK----97
  11451. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11452. {
  11453. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11454. {
  11455. map["dayDev"]++;
  11456. }
  11457. }
  11458. }
  11459. DataTable dt = new DataTable();
  11460. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11461. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11462. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11463. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11464. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11465. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11466. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11467. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11468. other_map.Keys.ForEach(key =>
  11469. {
  11470. DataRow dr = dt.NewRow();
  11471. Dictionary<string, int> map = other_map[key];
  11472. string[] key_list = key.Split('_');
  11473. dr[0] = key_list[0];
  11474. dr[1] = key_list[1];
  11475. if (key_list.Length > 2)
  11476. {
  11477. dr[1] += "(" + key_list[2] + ")";
  11478. }
  11479. dr[2] = map["dayTotal"];
  11480. dr[3] = map["payTotal"];
  11481. dr[4] = map["today"];
  11482. dr[5] = map["unusua"];
  11483. dr[6] = map["dayDev"];
  11484. double rate = 0.00;
  11485. if (map["dayDev"] > 0)
  11486. {
  11487. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11488. }
  11489. dr[7] = rate.ToString();
  11490. dt.Rows.Add(dr);
  11491. });
  11492. DataView dv = new DataView(dt);
  11493. dv.Sort = "SupplierName";
  11494. //dv.Sort = "AllOrder desc";
  11495. DataTable dtNew = dv.ToTable();
  11496. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11497. }
  11498. public void check_order_desing_info()
  11499. {
  11500. string ctid = GetPostString("ctid");
  11501. if (!string.IsNullOrEmpty(ctid))
  11502. {
  11503. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11504. if (ceErpTradeCell != null)
  11505. {
  11506. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11507. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11508. return;
  11509. }
  11510. returnErrorMsg("找不到订单");
  11511. return;
  11512. }
  11513. returnErrorMsg("找不到订单");
  11514. }
  11515. public void get_timeout_detail()
  11516. {
  11517. string poscode = CurrentUser.UserPost.Post.Code;
  11518. DataStruct dStruct = GetPostStruct();
  11519. List<string> lw = new List<string>();
  11520. string id = GetPostString("id");
  11521. string pay_date1 = GetPostString("pay_date1");
  11522. string pay_date2 = GetPostString("pay_date2");
  11523. int type = GetPostInt("type");
  11524. if (type == 0)
  11525. {
  11526. if (pay_date1.Length > 0)
  11527. {
  11528. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11529. }
  11530. if (pay_date2.Length > 0)
  11531. {
  11532. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11533. }
  11534. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11535. }
  11536. if (type == 1)
  11537. {
  11538. if (pay_date1.Length > 0)
  11539. {
  11540. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11541. }
  11542. if (pay_date2.Length > 0)
  11543. {
  11544. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11545. }
  11546. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11547. }
  11548. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11549. DataTable dt = null;
  11550. dt = WebCache.GetData("view_orderlist", dStruct);
  11551. writeGridDataTableJson(dStruct.TotalCount, dt);
  11552. }
  11553. public void saveUrgentChargePrice()
  11554. {
  11555. string ctid = GetPostString("ctid");
  11556. if (!string.IsNullOrEmpty(ctid))
  11557. {
  11558. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11559. if (ceErpTradeCell != null)
  11560. {
  11561. double price = GetPostDouble("price");
  11562. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11563. if (ceErpTradeCellExtend == null)
  11564. {
  11565. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11566. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11567. }
  11568. ceErpTradeCellExtend.urgentCharge = price;
  11569. if (ceErpTradeCellExtend.ID > 0)
  11570. {
  11571. ceErpTradeCellExtend.Update();
  11572. }
  11573. else
  11574. {
  11575. ceErpTradeCellExtend.Save();
  11576. }
  11577. returnSuccessMsg("修改成功!");
  11578. return;
  11579. }
  11580. returnErrorMsg("找不到订单");
  11581. return;
  11582. }
  11583. returnErrorMsg("找不到订单");
  11584. }
  11585. public void finish_erp_order()
  11586. {
  11587. string ctid = GetPostString("ctid");
  11588. if (!string.IsNullOrEmpty(ctid))
  11589. {
  11590. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11591. {
  11592. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11593. if (ceErpTradeCell != null)
  11594. {
  11595. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11596. ceErpTradeCell.Update();
  11597. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11598. returnSuccessMsg("修改成功!");
  11599. return;
  11600. }
  11601. }
  11602. }
  11603. returnErrorMsg("找不到订单");
  11604. }
  11605. public void get_trade_order_list()
  11606. {
  11607. string tid = GetPostString("tid");
  11608. if (!string.IsNullOrEmpty(tid))
  11609. {
  11610. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11611. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11612. writeGridDataTableJson(data.Rows.Count, data);
  11613. return;
  11614. }
  11615. returnErrorMsg("找不到订单");
  11616. }
  11617. public void save_cell_spu()
  11618. {
  11619. string ctid = GetPostString("ctid");
  11620. string spu_id = GetPostString("spu_id");
  11621. if (!string.IsNullOrEmpty(ctid))
  11622. {
  11623. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11624. if (ceErpTradeCellExtend == null)
  11625. {
  11626. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11627. ceErpTradeCellExtend.ctid = ctid;
  11628. }
  11629. ceErpTradeCellExtend.spu_id = spu_id;
  11630. if (!string.IsNullOrEmpty(spu_id))
  11631. {
  11632. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11633. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  11634. ceErpTradeCellExtend.ToType = result;
  11635. List<int> products = new List<int>() { 4, 13, 19, 24, 28, 32, 40, 51, 57, 1971, 2319, 2377, 2521, 2524, 2533, 2538, 2542, 2554, 2556, 2557, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2568, 2569, 2570, 2571, 2572, 2619, 2625, 2634, 2636, 2637, 2638, 2645, 2646 };
  11636. List<int> shopIds = new List<int>() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 17, 18, 21, 23, 24, 27, 28, 31, 32, 56, 61, 63, 64, 66, 124, 126, 127, 128 };
  11637. if (products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  11638. {
  11639. ceErpTradeCellExtend.ToType = "外协";
  11640. }
  11641. if ((ceErpTradeCell.seller_memo.Contains("改稿") || ceErpTradeCell.OtherMemo.Contains("改稿")) && shopIds.Contains(ceErpTradeCell.ShopId))
  11642. {
  11643. ceErpTradeCellExtend.ToType = "内部";
  11644. }
  11645. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  11646. {
  11647. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  11648. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  11649. }
  11650. }
  11651. if (ceErpTradeCellExtend.ID == 0)
  11652. {
  11653. ceErpTradeCellExtend.Create();
  11654. }
  11655. else
  11656. {
  11657. ceErpTradeCellExtend.Update();
  11658. }
  11659. returnSuccessMsg("修改成功!");
  11660. return;
  11661. }
  11662. returnErrorMsg("找不到订单");
  11663. }
  11664. public void change_express_info()
  11665. {
  11666. string ctid = GetPostString("ctid");
  11667. string transNo = GetPostString("transNo");
  11668. string transCom = GetPostString("transCom");
  11669. if (!string.IsNullOrEmpty(ctid))
  11670. {
  11671. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11672. if (ceErpTradeCellExtend == null)
  11673. {
  11674. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11675. ceErpTradeCellExtend.ctid = ctid;
  11676. }
  11677. ceErpTradeCellExtend.modExpressNo = transNo;
  11678. ceErpTradeCellExtend.modExpressCom = transCom;
  11679. ceErpTradeCellExtend.readMod = 2;
  11680. if (ceErpTradeCellExtend.ID == 0)
  11681. {
  11682. ceErpTradeCellExtend.Create();
  11683. }
  11684. else
  11685. {
  11686. ceErpTradeCellExtend.Update();
  11687. }
  11688. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11689. returnSuccessMsg("修改成功!");
  11690. return;
  11691. }
  11692. returnErrorMsg("找不到订单");
  11693. }
  11694. public void get_change_express_list()
  11695. {
  11696. DataStruct dStruct = GetPostStruct();
  11697. List<string> lw = new List<string>();
  11698. int st = 2;
  11699. string tid = GetPostString("ctid");
  11700. if (tid.Length > 0)
  11701. {
  11702. string select_tid = getTidByCtid(tid);
  11703. lw.Add(string.Format("tid='{0}'", select_tid));
  11704. }
  11705. string shopname = GetPostString("shopname");
  11706. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11707. string buyernick = GetPostString("buyer_nick");
  11708. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11709. string sellermemo = GetPostString("seller_memo");
  11710. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11711. string supplier = GetPostString("supplier");
  11712. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11713. string customer = GetPostString("customer");
  11714. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11715. string design = GetPostString("design");
  11716. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11717. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11718. string poscode = CurrentUser.UserPost.Post.Code;
  11719. if (poscode != "SysAdmin")
  11720. {
  11721. string shopid = CurrentUser.User.pemShop;
  11722. lw.Add(string.Format("shopId in ({0})", shopid));
  11723. }
  11724. lw.Add("readMod = 2");
  11725. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11726. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11727. writeGridDataTableJson(dStruct.TotalCount, dt);
  11728. }
  11729. public void deal_express_complete()
  11730. {
  11731. string ctid = GetPostString("ctid");
  11732. if (!string.IsNullOrEmpty(ctid))
  11733. {
  11734. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11735. if (ceErpTradeCellExtend == null)
  11736. {
  11737. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11738. ceErpTradeCellExtend.ctid = ctid;
  11739. }
  11740. ceErpTradeCellExtend.readMod = 1;
  11741. if (ceErpTradeCellExtend.ID == 0)
  11742. {
  11743. ceErpTradeCellExtend.Create();
  11744. }
  11745. else
  11746. {
  11747. ceErpTradeCellExtend.Update();
  11748. }
  11749. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11750. returnSuccessMsg("修改成功!");
  11751. return;
  11752. }
  11753. returnErrorMsg("找不到订单");
  11754. }
  11755. public void aftersale_return_visit()
  11756. {
  11757. string ctid = GetPostString("ctid");
  11758. if (!string.IsNullOrEmpty(ctid))
  11759. {
  11760. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11761. if (ceErpTradeCellExtend == null)
  11762. {
  11763. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11764. ceErpTradeCellExtend.ctid = ctid;
  11765. }
  11766. ceErpTradeCellExtend.returnVisit = 1;
  11767. if (ceErpTradeCellExtend.ID == 0)
  11768. {
  11769. ceErpTradeCellExtend.Create();
  11770. }
  11771. else
  11772. {
  11773. ceErpTradeCellExtend.Update();
  11774. }
  11775. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11776. if (ceErpTradeAfterSaleExtend != null)
  11777. {
  11778. ceErpTradeAfterSaleExtend.TextResult = "";
  11779. ceErpTradeAfterSaleExtend.Update();
  11780. }
  11781. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11782. returnSuccessMsg("修改成功!");
  11783. return;
  11784. }
  11785. returnErrorMsg("找不到订单");
  11786. }
  11787. public void orderPlaceInfo()
  11788. {
  11789. string ctids = GetPostString("ctids");
  11790. string[] list = ctids.Split(',');
  11791. foreach (string ctid in list)
  11792. {
  11793. CeErpSukuraData.createInfo(ctid, 3);
  11794. }
  11795. StringBuilder sql = new StringBuilder();
  11796. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11797. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11798. designHelper.api_approveDesign(ctids); //approveDesign
  11799. returnSuccessMsg("");
  11800. }
  11801. public void get_issue_list()
  11802. {
  11803. DataStruct dStruct = GetPostStruct();
  11804. List<string> lw = new List<string>();
  11805. int st = 2;
  11806. string tid = GetPostString("ctid");
  11807. if (tid.Length > 0)
  11808. {
  11809. string select_tid = getTidByCtid(tid);
  11810. lw.Add(string.Format("tid='{0}'", select_tid));
  11811. }
  11812. string shopname = GetPostString("shopname");
  11813. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11814. string buyernick = GetPostString("buyer_nick");
  11815. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11816. string sellermemo = GetPostString("seller_memo");
  11817. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11818. string supplier = GetPostString("supplier");
  11819. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11820. string customer = GetPostString("customer");
  11821. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11822. string design = GetPostString("design");
  11823. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11824. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11825. string poscode = CurrentUser.UserPost.Post.Code;
  11826. if (poscode != "SysAdmin")
  11827. {
  11828. string shopid = CurrentUser.User.pemShop;
  11829. lw.Add(string.Format("shopId in ({0})", shopid));
  11830. }
  11831. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11832. {
  11833. lw.Add("IssueState = 1");
  11834. }
  11835. lw.Add("IssueState > 0");
  11836. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11837. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11838. writeGridDataTableJson(dStruct.TotalCount, dt);
  11839. }
  11840. public void saveIssueContent()
  11841. {
  11842. string ctid = GetPostString("ctid");
  11843. if (!string.IsNullOrEmpty(ctid))
  11844. {
  11845. string content = GetPostString("content");
  11846. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11847. if (ceErpTradeAfterSaleExtend == null)
  11848. {
  11849. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11850. ceErpTradeAfterSaleExtend.tid = ctid;
  11851. }
  11852. ceErpTradeAfterSaleExtend.IssueContent = content;
  11853. ceErpTradeAfterSaleExtend.IssueState = 1;
  11854. if (ceErpTradeAfterSaleExtend.ID > 0)
  11855. {
  11856. ceErpTradeAfterSaleExtend.Update();
  11857. }
  11858. else
  11859. {
  11860. ceErpTradeAfterSaleExtend.Create();
  11861. }
  11862. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11863. returnSuccessMsg("添加成功!");
  11864. return;
  11865. }
  11866. returnErrorMsg("找不到订单");
  11867. }
  11868. public void dealIssueContent()
  11869. {
  11870. string ctid = GetPostString("ctid");
  11871. if (!string.IsNullOrEmpty(ctid))
  11872. {
  11873. string content = GetPostString("content");
  11874. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11875. if (ceErpTradeAfterSaleExtend != null)
  11876. {
  11877. ceErpTradeAfterSaleExtend.IssueState = 2;
  11878. ceErpTradeAfterSaleExtend.Update();
  11879. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11880. returnSuccessMsg("修改完成!");
  11881. return;
  11882. }
  11883. }
  11884. returnErrorMsg("找不到订单");
  11885. }
  11886. public void set_tid_attachments()
  11887. {
  11888. string tid = GetPostString("tid");
  11889. string atta = GetPostString("atta");
  11890. if (!string.IsNullOrEmpty(tid))
  11891. {
  11892. if (string.IsNullOrEmpty(atta))
  11893. {
  11894. returnErrorMsg("文件地址为空");
  11895. return;
  11896. }
  11897. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11898. if (ceErpTradeCell != null)
  11899. {
  11900. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11901. if (ceErpTrade == null)
  11902. {
  11903. returnErrorMsg("找不到订单");
  11904. return;
  11905. }
  11906. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11907. bool isSend = false;
  11908. if (dt != null && dt.Rows.Count > 0)
  11909. {
  11910. foreach (DataRow row in dt.Rows)
  11911. {
  11912. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11913. {
  11914. isSend = true;
  11915. }
  11916. }
  11917. if (isSend)
  11918. {
  11919. returnErrorMsg("已发货无法修改");
  11920. return;
  11921. }
  11922. ceErpTrade.Attachments = atta;
  11923. ceErpTrade.Update();
  11924. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11925. returnSuccessMsg("上传成功!");
  11926. return;
  11927. }
  11928. }
  11929. }
  11930. returnErrorMsg("找不到订单");
  11931. }
  11932. public void get_tid_attachments()
  11933. {
  11934. string tid = GetPostString("tid");
  11935. if (!string.IsNullOrEmpty(tid))
  11936. {
  11937. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11938. if (ceErpTradeCell != null)
  11939. {
  11940. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11941. if (ceErpTrade == null)
  11942. {
  11943. returnErrorMsg("找不到订单");
  11944. return;
  11945. }
  11946. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11947. return;
  11948. }
  11949. }
  11950. returnErrorMsg("找不到订单");
  11951. }
  11952. public void check_erp_sameorders()
  11953. {
  11954. if (UrlPostParmsCheck("ctid"))
  11955. {
  11956. string eid = GetPostString("ctid");
  11957. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11958. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11959. if (entity != null && ceErpTrade != null)
  11960. {
  11961. if (entity.OrderState > 6)
  11962. {
  11963. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11964. return;
  11965. }
  11966. DataTable dt = getSameOrderList(entity, ceErpTrade);
  11967. List<string> ids = new List<string>();
  11968. if (dt != null && dt.Rows.Count > 1)
  11969. {
  11970. bool needhe = true;
  11971. foreach (DataRow dr in dt.Rows)
  11972. {
  11973. ids.Add("'" + dr["ctid"] + "'");
  11974. /* //备注有合包
  11975. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11976. {
  11977. needhe = true;
  11978. }
  11979. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11980. {
  11981. needhe = true;
  11982. }
  11983. //顺丰快递
  11984. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11985. {
  11986. needhe = true;
  11987. }*/
  11988. }
  11989. if (!needhe)
  11990. {
  11991. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11992. return;
  11993. }
  11994. StringBuilder sql = new StringBuilder();
  11995. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11996. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11997. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11998. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11999. foreach (DataRow dr in dt.Rows)
  12000. {
  12001. dr["dstate"] = 0;
  12002. dr["dnumber"] = 0;
  12003. foreach (DataRow row in dt1.Rows)
  12004. {
  12005. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12006. {
  12007. dr["dstate"] = 2;
  12008. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12009. }
  12010. }
  12011. if (eid.Equals(dr["ctid"].ToString()))
  12012. {
  12013. dr["dstate"] = 1;
  12014. }
  12015. }
  12016. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12017. return;
  12018. }
  12019. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12020. return;
  12021. }
  12022. returnErrorMsg("未找到订单");
  12023. return;
  12024. }
  12025. returnErrorMsg("缺少必要的参数");
  12026. }
  12027. private DataTable getSameOrderList(CeErpTradeCell entity, CeErpTrade ceErpTrade)
  12028. {
  12029. StringBuilder sql = new StringBuilder();
  12030. 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);
  12031. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12032. {
  12033. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12034. }
  12035. else
  12036. {
  12037. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12038. }
  12039. DataTable dt = null;
  12040. try
  12041. {
  12042. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12043. return dt;
  12044. StringBuilder timerSql = new StringBuilder();
  12045. timerSql.AppendFormat("SELECT * FROM CE_ErpSupplierProductTime WHERE supplierId={0}", entity.SupplierId);
  12046. DataTable timerTable = DbHelper.DbConn.ExecuteDataset(timerSql.ToString()).Tables[0];
  12047. //没有设置时间则不判断
  12048. if (timerTable == null || timerTable.Rows.Count == 0)
  12049. {
  12050. return dt;
  12051. }
  12052. foreach (DataRow dr in dt.Rows)
  12053. {
  12054. //当前订单
  12055. if (entity.ctid.Equals(dr["ctid"]))
  12056. {
  12057. continue;
  12058. }
  12059. //已经标记过发货
  12060. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(dr["ctid"].ToString());
  12061. if (ceErpDeliverMark != null)
  12062. {
  12063. continue;
  12064. }
  12065. string[] productIds = null;
  12066. string productId = dr["productId"].ToString();
  12067. string finishPlaceTime = dr["FinishPlaceTime"].ToString();
  12068. string sellmer_mome = dr["seller_memo"].ToString();
  12069. string txtCount = dr["ProductCount"].ToString();
  12070. DateTime placeTime = DateTime.Now;
  12071. //没有品类
  12072. if (string.IsNullOrEmpty(productId) || "0".Equals(productId))
  12073. {
  12074. dr.Delete();//标记删除
  12075. continue;
  12076. }
  12077. if (string.IsNullOrEmpty(finishPlaceTime))
  12078. {
  12079. dr.Delete();//标记删除
  12080. continue;
  12081. }
  12082. placeTime = DateTime.Parse(finishPlaceTime);
  12083. foreach (DataRow row in timerTable.Rows)
  12084. {
  12085. string txtIds = row["productId"].ToString();
  12086. string[] crafts = { };
  12087. int count = Convert.ToUInt16(row["quantity"]);
  12088. if (string.IsNullOrEmpty(txtIds))
  12089. {
  12090. continue;
  12091. }
  12092. if (count > 0)
  12093. {
  12094. int quantity = commonHelper.handleProductCount(txtCount, true);
  12095. //订单数量大于写入的数量则跳过
  12096. if (quantity > count)
  12097. {
  12098. continue;
  12099. }
  12100. }
  12101. productIds = txtIds.Split(',');
  12102. if (productIds.Contains(productId))
  12103. {
  12104. string textCraft = row["craft"].ToString();
  12105. textCraft = textCraft.Replace(",", ",");//统一格式
  12106. if (!string.IsNullOrEmpty(textCraft))
  12107. {
  12108. crafts = textCraft.Split(',');
  12109. }
  12110. if (crafts.Length > 0)
  12111. {
  12112. bool isinCraft = false;
  12113. for (int i = 0; i < crafts.Length; i++)
  12114. {
  12115. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12116. {
  12117. isinCraft = true;
  12118. break;
  12119. }
  12120. }
  12121. //有写工艺并且备注中没匹配中则跳过
  12122. if (!isinCraft)
  12123. {
  12124. continue;
  12125. }
  12126. }
  12127. DateTime deadLine = DateTime.Parse(row["deadLine"].ToString());
  12128. DateTime dayDeadLine = DateTime.Parse(row["dayDeadLine"].ToString());
  12129. int sendDay = Convert.ToInt16(row["sendDay"]);
  12130. //下单时间小于当日发货时间则不用判断
  12131. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12132. {
  12133. break;
  12134. }
  12135. //在截稿时间之前下单的可以减去一天时间
  12136. if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12137. {
  12138. sendDay = Math.Max(1, sendDay - 1);
  12139. }
  12140. DateTime sendtime = placeTime.AddDays(sendDay);
  12141. //判断有没有到发货日期
  12142. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) > 0)
  12143. {
  12144. dr.Delete();//标记删除
  12145. break;
  12146. }
  12147. }
  12148. }
  12149. }
  12150. dt.AcceptChanges();//把标记的都删除
  12151. }
  12152. catch (Exception ex)
  12153. {
  12154. }
  12155. return dt;
  12156. }
  12157. public void get_mark_number()
  12158. {
  12159. string eid = GetPostString("ctid");
  12160. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12161. if (entity != null)
  12162. {
  12163. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12164. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12165. int current = 1;
  12166. if (ceErpDeliverMark == null)
  12167. {
  12168. DataTable dt = getSameOrderList(entity, ceErpTrade);
  12169. List<string> ids = new List<string>();
  12170. if (dt != null && dt.Rows.Count > 1)
  12171. {
  12172. foreach (DataRow dr in dt.Rows)
  12173. {
  12174. ids.Add("'" + dr["ctid"] + "'");
  12175. }
  12176. //查询已有的编号
  12177. StringBuilder sql = new StringBuilder();
  12178. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12179. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12180. if (dt1 == null || dt1.Rows.Count == 0)
  12181. {
  12182. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12183. List<int> list_number = new List<int>();
  12184. foreach (DataRow row in numbers.Rows)
  12185. {
  12186. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12187. }
  12188. //查询空余编号
  12189. for (int i = 0; i < list_number.Count + 2; i++)
  12190. {
  12191. if (!list_number.Contains(current))
  12192. {
  12193. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12194. //防止查询过程中有新数据生成
  12195. if (ceErpDeliverMark1 == null)
  12196. {
  12197. break;
  12198. }
  12199. }
  12200. current++;
  12201. }
  12202. }
  12203. else
  12204. {
  12205. foreach (DataRow row in dt1.Rows)
  12206. {
  12207. current = Convert.ToInt32(row["markNumber"]);
  12208. }
  12209. }
  12210. ceErpDeliverMark = new CeErpDeliverMark();
  12211. ceErpDeliverMark.ctid = eid;
  12212. ceErpDeliverMark.createtime = DateTime.Now;
  12213. if (ceErpTrade != null)
  12214. {
  12215. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12216. }
  12217. ceErpDeliverMark.markNumber = current;
  12218. ceErpDeliverMark.Create();
  12219. }
  12220. }
  12221. else
  12222. {
  12223. current = ceErpDeliverMark.markNumber;
  12224. }
  12225. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12226. return;
  12227. }
  12228. }
  12229. public void aftersaleCytSend()
  12230. {
  12231. string ctid = GetPostString("ctid");
  12232. if (!string.IsNullOrEmpty(ctid))
  12233. {
  12234. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12235. if (ceErpTradeCell != null)
  12236. {
  12237. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12238. }
  12239. returnSuccessMsg("推送成功");
  12240. return;
  12241. }
  12242. returnErrorMsg("缺少必要的参数");
  12243. }
  12244. public void packOrderInfo()
  12245. {
  12246. string ctids = GetPostString("ctids");
  12247. if (!string.IsNullOrEmpty(ctids))
  12248. {
  12249. string[] ctid_list = ctids.Split(',');
  12250. if (ctid_list.Length > 20)
  12251. {
  12252. returnErrorMsg("单次下载次数不能超过20个");
  12253. return;
  12254. }
  12255. StringBuilder sql = new StringBuilder();
  12256. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  12257. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12258. int supplierId = 0;
  12259. StringBuilder insterSql = new StringBuilder();
  12260. for (int i = 0; i < dt.Rows.Count; i++)
  12261. {
  12262. DataRow row = dt.Rows[i];
  12263. if (i == 0)
  12264. {
  12265. supplierId = Convert.ToInt32(row["SupplierId"]);
  12266. }
  12267. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12268. {
  12269. returnErrorMsg("同车间的订单才能一起打包");
  12270. return;
  12271. }
  12272. int orderState = Convert.ToInt32(row["OrderState"]);
  12273. if (orderState != 5)
  12274. {
  12275. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12276. return;
  12277. }
  12278. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12279. }
  12280. CeErpPackData ceErpPackData = new CeErpPackData();
  12281. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip";
  12282. ceErpPackData.supplierId = supplierId;
  12283. ceErpPackData.createtime = DateTime.Now;
  12284. ceErpPackData.createBy = CurrentUser.UserID;
  12285. ceErpPackData.createName = CurrentUser.UserName;
  12286. ceErpPackData.Create();
  12287. if (ceErpPackData.ID > 0)
  12288. {
  12289. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12290. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12291. }
  12292. returnSuccessMsg("打包成功");
  12293. return;
  12294. }
  12295. returnErrorMsg("缺少必要的参数");
  12296. }
  12297. public void get_pack_list()
  12298. {
  12299. DataStruct dStruct = GetPostStruct();
  12300. List<string> lw = new List<string>();
  12301. string supplier = GetPostString("supplier");
  12302. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12303. string posTag = CurrentUser.UserPost.Post.Code;
  12304. if (posTag == "Supplier")
  12305. {
  12306. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12307. }
  12308. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12309. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12310. writeGridDataTableJson(dStruct.TotalCount, dt);
  12311. }
  12312. public void get_supplier_product_time_list()
  12313. {
  12314. DataStruct dStruct = GetPostStruct();
  12315. List<string> lw = new List<string>();
  12316. string supplier = GetPostString("supplier");
  12317. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12318. string posTag = CurrentUser.UserPost.Post.Code;
  12319. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12320. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12321. writeGridDataTableJson(dStruct.TotalCount, dt);
  12322. }
  12323. public void saveSupplierProductTime()
  12324. {
  12325. string productId = GetPostString("productId");
  12326. if (string.IsNullOrEmpty(productId))
  12327. {
  12328. returnErrorMsg("缺少必要的参数");
  12329. return;
  12330. }
  12331. string productName = GetPostString("productName");
  12332. int supplierId = GetPostInt("supplierId");
  12333. if (supplierId == 0)
  12334. {
  12335. returnErrorMsg("缺少必要的参数");
  12336. return;
  12337. }
  12338. int quantity = GetPostInt("quantity");
  12339. int sendDay = GetPostInt("sendTime");
  12340. string supplierName = GetPostString("supplierName");
  12341. string craft = GetPostString("craft");
  12342. string deadLine = GetPostString("deadLine");
  12343. string dayDeadLine = GetPostString("dayDeadLine");
  12344. try
  12345. {
  12346. int eid = GetPostInt("eid");
  12347. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12348. if (ceErpSupplierProductTime == null)
  12349. {
  12350. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12351. }
  12352. ceErpSupplierProductTime.productId = productId;
  12353. ceErpSupplierProductTime.productName = productName;
  12354. ceErpSupplierProductTime.supplierId = supplierId;
  12355. ceErpSupplierProductTime.supplierName = supplierName;
  12356. ceErpSupplierProductTime.craft = craft;
  12357. ceErpSupplierProductTime.sendDay = sendDay;
  12358. ceErpSupplierProductTime.quantity = quantity;
  12359. if (!string.IsNullOrEmpty(deadLine))
  12360. {
  12361. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12362. }
  12363. if (!string.IsNullOrEmpty(dayDeadLine))
  12364. {
  12365. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12366. }
  12367. if (ceErpSupplierProductTime.ID == 0)
  12368. {
  12369. ceErpSupplierProductTime.Save();
  12370. }
  12371. else
  12372. {
  12373. ceErpSupplierProductTime.Update();
  12374. }
  12375. }
  12376. catch (Exception e)
  12377. {
  12378. }
  12379. returnSuccessMsg("保存成功");
  12380. return;
  12381. }
  12382. public void delSupplierProductTime()
  12383. {
  12384. int eid = GetPostInt("eid");
  12385. if (eid > 0)
  12386. {
  12387. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12388. if (ceErpSupplierProductTime == null)
  12389. {
  12390. returnErrorMsg("查无数据");
  12391. return;
  12392. }
  12393. ceErpSupplierProductTime.Delete();
  12394. returnSuccessMsg("保存成功");
  12395. return;
  12396. }
  12397. returnErrorMsg("缺少必要的参数");
  12398. }
  12399. public void getExpressInfo()
  12400. {
  12401. string ctid = GetPostString("ctid");
  12402. if (!string.IsNullOrEmpty(ctid))
  12403. {
  12404. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12405. if (ceErpTradeCell != null)
  12406. {
  12407. string outSid = ceErpTradeCell.OutSid;
  12408. if (outSid.Length > 0)
  12409. {
  12410. 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);
  12411. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12412. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12413. return;
  12414. }
  12415. }
  12416. returnErrorMsg("查无记录");
  12417. return;
  12418. }
  12419. returnErrorMsg("缺少必要的参数");
  12420. }
  12421. public void getExpressPostData()
  12422. {
  12423. string express = GetPostString("express");
  12424. if (!string.IsNullOrEmpty(express))
  12425. {
  12426. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12427. if (ceErpExpressInfo != null)
  12428. {
  12429. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12430. return;
  12431. }
  12432. }
  12433. returnErrorMsg("缺少必要的参数");
  12434. }
  12435. }
  12436. }